---
# System prepended metadata

title: 'Homework2: RISC-V Toolchain'
tags: [2022 computer architecture]

---

# Homework2: RISC-V Toolchain
###### tags: `2022 computer architecture`

[toc]

## -O0 assembly code
```assembly=
000101d0 <heapify>:
   101d0:       fd010113                addi    sp,sp,-48
   101d4:       02812623                sw      s0,44(sp)
   101d8:       03010413                addi    s0,sp,48
   101dc:       fca42e23                sw      a0,-36(s0)
   101e0:       fcb42c23                sw      a1,-40(s0)
   101e4:       fcc42a23                sw      a2,-44(s0)
   101e8:       fd842783                lw      a5,-40(s0)
   101ec:       00279793                slli    a5,a5,0x2
   101f0:       fdc42703                lw      a4,-36(s0)
   101f4:       00f707b3                add     a5,a4,a5
   101f8:       0007a783                lw      a5,0(a5)
   101fc:       fef42223                sw      a5,-28(s0)
   10200:       fd842783                lw      a5,-40(s0)
   10204:       00179793                slli    a5,a5,0x1
   10208:       00178793                addi    a5,a5,1
   1020c:       fef42623                sw      a5,-20(s0)
   10210:       0e00006f                j       102f0 <heapify+0x120>
   10214:       fd442783                lw      a5,-44(s0)
   10218:       fff78793                addi    a5,a5,-1
   1021c:       fec42703                lw      a4,-20(s0)
   10220:       04f75063                bge     a4,a5,10260 <heapify+0x90>
   10224:       fec42783                lw      a5,-20(s0)
   10228:       00279793                slli    a5,a5,0x2
   1022c:       fdc42703                lw      a4,-36(s0)
   10230:       00f707b3                add     a5,a4,a5
   10234:       0007a703                lw      a4,0(a5)
   10238:       fec42783                lw      a5,-20(s0)
   1023c:       00178793                addi    a5,a5,1
   10240:       00279793                slli    a5,a5,0x2
   10244:       fdc42683                lw      a3,-36(s0)
   10248:       00f687b3                add     a5,a3,a5
   1024c:       0007a783                lw      a5,0(a5)
   10250:       00f75863                bge     a4,a5,10260 <heapify+0x90>
   10254:       fec42783                lw      a5,-20(s0)
   10258:       00178793                addi    a5,a5,1
   1025c:       fef42623                sw      a5,-20(s0)
   10260:       fec42783                lw      a5,-20(s0)
   10264:       00279793                slli    a5,a5,0x2
   10268:       fdc42703                lw      a4,-36(s0)
   1026c:       00f707b3                add     a5,a4,a5
   10270:       0007a783                lw      a5,0(a5)
   10274:       fe442703                lw      a4,-28(s0)
   10278:       08f75463                bge     a4,a5,10300 <heapify+0x130>
   1027c:       fec42783                lw      a5,-20(s0)
   10280:       0017f793                andi    a5,a5,1
   10284:       02079063                bnez    a5,102a4 <heapify+0xd4>
   10288:       fec42783                lw      a5,-20(s0)
   1028c:       01f7d713                srli    a4,a5,0x1f
   10290:       00f707b3                add     a5,a4,a5
   10294:       4017d793                srai    a5,a5,0x1
   10298:       fff78793                addi    a5,a5,-1
   1029c:       fef42423                sw      a5,-24(s0)
   102a0:       0180006f                j       102b8 <heapify+0xe8>
   102a4:       fec42783                lw      a5,-20(s0)
   102a8:       01f7d713                srli    a4,a5,0x1f
   102ac:       00f707b3                add     a5,a4,a5
   102b0:       4017d793                srai    a5,a5,0x1
   102b4:       fef42423                sw      a5,-24(s0)
   102b8:       fec42783                lw      a5,-20(s0)
   102bc:       00279793                slli    a5,a5,0x2
   102c0:       fdc42703                lw      a4,-36(s0)
   102c4:       00f70733                add     a4,a4,a5
   102c8:       fe842783                lw      a5,-24(s0)
   102cc:       00279793                slli    a5,a5,0x2
   102d0:       fdc42683                lw      a3,-36(s0)
   102d4:       00f687b3                add     a5,a3,a5
   102d8:       00072703                lw      a4,0(a4)
   102dc:       00e7a023                sw      a4,0(a5)
   102e0:       fec42783                lw      a5,-20(s0)
   102e4:       00179793                slli    a5,a5,0x1
   102e8:       00178793                addi    a5,a5,1
   102ec:       fef42623                sw      a5,-20(s0)
   102f0:       fec42703                lw      a4,-20(s0)
   102f4:       fd442783                lw      a5,-44(s0)
   102f8:       f0f74ee3                blt     a4,a5,10214 <heapify+0x44>
   102fc:       0080006f                j       10304 <heapify+0x134>
   10300:       00000013                nop
   10304:       fec42783                lw      a5,-20(s0)
   10308:       0017f793                andi    a5,a5,1
   1030c:       02079063                bnez    a5,1032c <heapify+0x15c>
   10310:       fec42783                lw      a5,-20(s0)
   10314:       01f7d713                srli    a4,a5,0x1f
   10318:       00f707b3                add     a5,a4,a5
   1031c:       4017d793                srai    a5,a5,0x1
   10320:       fff78793                addi    a5,a5,-1
   10324:       fef42423                sw      a5,-24(s0)
   10328:       0180006f                j       10340 <heapify+0x170>
   1032c:       fec42783                lw      a5,-20(s0)
   10330:       01f7d713                srli    a4,a5,0x1f
   10334:       00f707b3                add     a5,a4,a5
   10338:       4017d793                srai    a5,a5,0x1
   1033c:       fef42423                sw      a5,-24(s0)
   10340:       fe842783                lw      a5,-24(s0)
   10344:       00279793                slli    a5,a5,0x2
   10348:       fdc42703                lw      a4,-36(s0)
   1034c:       00f707b3                add     a5,a4,a5
   10350:       fe442703                lw      a4,-28(s0)
   10354:       00e7a023                sw      a4,0(a5)
   10358:       00000013                nop
   1035c:       02c12403                lw      s0,44(sp)
   10360:       03010113                addi    sp,sp,48
   10364:       00008067                ret
  +++++++++++
  
  
  
  
   
   00010368 <heapSort>:
   10368:       fd010113                addi    sp,sp,-48
   1036c:       02112623                sw      ra,44(sp)
   10370:       02812423                sw      s0,40(sp)
   10374:       03010413                addi    s0,sp,48
   10378:       fca42e23                sw      a0,-36(s0)
   1037c:       fcb42c23                sw      a1,-40(s0)
   10380:       fd842783                lw      a5,-40(s0)
   10384:       01f7d713                srli    a4,a5,0x1f
   10388:       00f707b3                add     a5,a4,a5
   1038c:       4017d793                srai    a5,a5,0x1
   10390:       fff78793                addi    a5,a5,-1
   10394:       fef42623                sw      a5,-20(s0)
   10398:       0200006f                j       103b8 <heapSort+0x50>
   1039c:       fd842603                lw      a2,-40(s0)
   103a0:       fec42583                lw      a1,-20(s0)
   103a4:       fdc42503                lw      a0,-36(s0)
   103a8:       e29ff0ef                jal     ra,101d0 <heapify>
   103ac:       fec42783                lw      a5,-20(s0)
   103b0:       fff78793                addi    a5,a5,-1
   103b4:       fef42623                sw      a5,-20(s0)
   103b8:       fec42783                lw      a5,-20(s0)
   103bc:       fe07d0e3                bgez    a5,1039c <heapSort+0x34>
   103c0:       fd842783                lw      a5,-40(s0)
   103c4:       fff78793                addi    a5,a5,-1
   103c8:       fef42423                sw      a5,-24(s0)
   103cc:       03c0006f                j       10408 <heapSort+0xa0>
   103d0:       fe842783                lw      a5,-24(s0)
   103d4:       00279793                slli    a5,a5,0x2
   103d8:       fdc42703                lw      a4,-36(s0)
   103dc:       00f707b3                add     a5,a4,a5
   103e0:       00078593                mv      a1,a5
   103e4:       fdc42503                lw      a0,-36(s0)
   103e8:       d9dff0ef                jal     ra,10184 <swap>
   103ec:       fe842603                lw      a2,-24(s0)
   103f0:       00000593                li      a1,0
   103f4:       fdc42503                lw      a0,-36(s0)
   103f8:       dd9ff0ef                jal     ra,101d0 <heapify>
   103fc:       fe842783                lw      a5,-24(s0)
   10400:       fff78793                addi    a5,a5,-1
   10404:       fef42423                sw      a5,-24(s0)
   10408:       fe842783                lw      a5,-24(s0)
   1040c:       fc07d2e3                bgez    a5,103d0 <heapSort+0x68>
   10410:       00000013                nop
   10414:       00000013                nop
   10418:       02c12083                lw      ra,44(sp)
   1041c:       02812403                lw      s0,40(sp)
   10420:       03010113                addi    sp,sp,48
   10424:       00008067                ret
   
   00010428 <containsDuplicate>:
   10428:       fd010113                addi    sp,sp,-48
   1042c:       02112623                sw      ra,44(sp)
   10430:       02812423                sw      s0,40(sp)
   10434:       03010413                addi    s0,sp,48
   10438:       fca42e23                sw      a0,-36(s0)
   1043c:       fcb42c23                sw      a1,-40(s0)
   10440:       fd842583                lw      a1,-40(s0)
   10444:       fdc42503                lw      a0,-36(s0)
   10448:       f21ff0ef                jal     ra,10368 <heapSort>
   1044c:       fe042623                sw      zero,-20(s0)
   10450:       0480006f                j       10498 <containsDuplicate+0x70>
   10454:       fec42783                lw      a5,-20(s0)
   10458:       00279793                slli    a5,a5,0x2
   1045c:       fdc42703                lw      a4,-36(s0)
   10460:       00f707b3                add     a5,a4,a5
   10464:       0007a703                lw      a4,0(a5)
   10468:       fec42783                lw      a5,-20(s0)
   1046c:       00178793                addi    a5,a5,1
   10470:       00279793                slli    a5,a5,0x2
   10474:       fdc42683                lw      a3,-36(s0)
   10478:       00f687b3                add     a5,a3,a5
   1047c:       0007a783                lw      a5,0(a5)
   10480:       00f71663                bne     a4,a5,1048c <containsDuplicate+0x64>
   10484:       00100793                li      a5,1
   10488:       0240006f                j       104ac <containsDuplicate+0x84>
   1048c:       fec42783                lw      a5,-20(s0)
   10490:       00178793                addi    a5,a5,1
   10494:       fef42623                sw      a5,-20(s0)
   10498:       fd842783                lw      a5,-40(s0)
   1049c:       fff78793                addi    a5,a5,-1
   104a0:       fec42703                lw      a4,-20(s0)
   104a4:       faf748e3                blt     a4,a5,10454 <containsDuplicate+0x2c>
   104a8:       00000793                li      a5,0
   104ac:       00078513                mv      a0,a5
   104b0:       02c12083                lw      ra,44(sp)
   104b4:       02812403                lw      s0,40(sp)
   104b8:       03010113                addi    sp,sp,48
   104bc:       00008067                ret

```

## -O1 Assembly Code
```assembly=
00010198 <heapify>:
   10198:	00259793          	slli	a5,a1,0x2
   1019c:	00f507b3          	add	a5,a0,a5
   101a0:	0007a803          	lw	a6,0(a5)
   101a4:	00159593          	slli	a1,a1,0x1
   101a8:	00158793          	addi	a5,a1,1
   101ac:	06c7dc63          	bge	a5,a2,10224 <heapify+0x8c>
   101b0:	fff60593          	addi	a1,a2,-1
   101b4:	0280006f          	j	101dc <heapify+0x44>
   101b8:	01f7d713          	srli	a4,a5,0x1f
   101bc:	00f70733          	add	a4,a4,a5
   101c0:	40175713          	srai	a4,a4,0x1
   101c4:	00271713          	slli	a4,a4,0x2
   101c8:	00e50733          	add	a4,a0,a4
   101cc:	00d72023          	sw	a3,0(a4)
   101d0:	00179793          	slli	a5,a5,0x1
   101d4:	00178793          	addi	a5,a5,1
   101d8:	04c7d663          	bge	a5,a2,10224 <heapify+0x8c>
   101dc:	00b7de63          	bge	a5,a1,101f8 <heapify+0x60>
   101e0:	00279713          	slli	a4,a5,0x2
   101e4:	00e50733          	add	a4,a0,a4
   101e8:	00072683          	lw	a3,0(a4)
   101ec:	00472703          	lw	a4,4(a4)
   101f0:	00e6a733          	slt	a4,a3,a4
   101f4:	00e787b3          	add	a5,a5,a4
   101f8:	00279713          	slli	a4,a5,0x2
   101fc:	00e50733          	add	a4,a0,a4
   10200:	00072683          	lw	a3,0(a4)
   10204:	02d85063          	bge	a6,a3,10224 <heapify+0x8c>
   10208:	0017f713          	andi	a4,a5,1
   1020c:	fa0716e3          	bnez	a4,101b8 <heapify+0x20>
   10210:	01f7d713          	srli	a4,a5,0x1f
   10214:	00f70733          	add	a4,a4,a5
   10218:	40175713          	srai	a4,a4,0x1
   1021c:	fff70713          	addi	a4,a4,-1
   10220:	fa5ff06f          	j	101c4 <heapify+0x2c>
   10224:	0017f713          	andi	a4,a5,1
   10228:	02071263          	bnez	a4,1024c <heapify+0xb4>
   1022c:	01f7d713          	srli	a4,a5,0x1f
   10230:	00f707b3          	add	a5,a4,a5
   10234:	4017d793          	srai	a5,a5,0x1
   10238:	fff78793          	addi	a5,a5,-1
   1023c:	00279793          	slli	a5,a5,0x2
   10240:	00f50533          	add	a0,a0,a5
   10244:	01052023          	sw	a6,0(a0)
   10248:	00008067          	ret
   1024c:	01f7d713          	srli	a4,a5,0x1f
   10250:	00f707b3          	add	a5,a4,a5
   10254:	4017d793          	srai	a5,a5,0x1
   10258:	fe5ff06f          	j	1023c <heapify+0xa4>
   
0001025c <heapSort>:
   1025c:	fe010113          	addi	sp,sp,-32
   10260:	00112e23          	sw	ra,28(sp)
   10264:	00812c23          	sw	s0,24(sp)
   10268:	00912a23          	sw	s1,20(sp)
   1026c:	01212823          	sw	s2,16(sp)
   10270:	01312623          	sw	s3,12(sp)
   10274:	00050913          	mv	s2,a0
   10278:	00058413          	mv	s0,a1
   1027c:	01f5d493          	srli	s1,a1,0x1f
   10280:	00b484b3          	add	s1,s1,a1
   10284:	4014d493          	srai	s1,s1,0x1
   10288:	fff48493          	addi	s1,s1,-1
   1028c:	0204c063          	bltz	s1,102ac <heapSort+0x50>
   10290:	fff00993          	li	s3,-1
   10294:	00040613          	mv	a2,s0
   10298:	00048593          	mv	a1,s1
   1029c:	00090513          	mv	a0,s2
   102a0:	ef9ff0ef          	jal	ra,10198 <heapify>
   102a4:	fff48493          	addi	s1,s1,-1
   102a8:	ff3496e3          	bne	s1,s3,10294 <heapSort+0x38>
   102ac:	fff40493          	addi	s1,s0,-1
   102b0:	0204ce63          	bltz	s1,102ec <heapSort+0x90>
   102b4:	00241413          	slli	s0,s0,0x2
   102b8:	00890433          	add	s0,s2,s0
   102bc:	fff00993          	li	s3,-1
   102c0:	00092783          	lw	a5,0(s2)
   102c4:	ffc42703          	lw	a4,-4(s0)
   102c8:	00e92023          	sw	a4,0(s2)
   102cc:	fef42e23          	sw	a5,-4(s0)
   102d0:	00048613          	mv	a2,s1
   102d4:	00000593          	li	a1,0
   102d8:	00090513          	mv	a0,s2
   102dc:	ebdff0ef          	jal	ra,10198 <heapify>
   102e0:	fff48493          	addi	s1,s1,-1
   102e4:	ffc40413          	addi	s0,s0,-4
   102e8:	fd349ce3          	bne	s1,s3,102c0 <heapSort+0x64>
   102ec:	01c12083          	lw	ra,28(sp)
   102f0:	01812403          	lw	s0,24(sp)
   102f4:	01412483          	lw	s1,20(sp)
   102f8:	01012903          	lw	s2,16(sp)
   102fc:	00c12983          	lw	s3,12(sp)
   10300:	02010113          	addi	sp,sp,32
   10304:	00008067          	ret
   
   
   
```
## -O2 Assembly Code
```assembly=
000102f8 <heapify>:
   102f8:	00259793          	slli	a5,a1,0x2
   102fc:	00159593          	slli	a1,a1,0x1
   10300:	00f507b3          	add	a5,a0,a5
   10304:	00158713          	addi	a4,a1,1
   10308:	0007ae03          	lw	t3,0(a5)
   1030c:	fff60e93          	addi	t4,a2,-1
   10310:	00c74a63          	blt	a4,a2,10324 <heapify+0x2c>
   10314:	0780006f          	j	1038c <heapify+0x94>
   10318:	00130713          	addi	a4,t1,1 # 102d9 <frame_dummy+0x15>
   1031c:	00d7a023          	sw	a3,0(a5)
   10320:	06c75663          	bge	a4,a2,1038c <heapify+0x94>
   10324:	00271793          	slli	a5,a4,0x2
   10328:	00f507b3          	add	a5,a0,a5
   1032c:	0007a683          	lw	a3,0(a5)
   10330:	01d75a63          	bge	a4,t4,10344 <heapify+0x4c>
   10334:	0047a783          	lw	a5,4(a5)
   10338:	00f6d663          	bge	a3,a5,10344 <heapify+0x4c>
   1033c:	00170713          	addi	a4,a4,1
   10340:	00078693          	mv	a3,a5
   10344:	01f75593          	srli	a1,a4,0x1f
   10348:	00e587b3          	add	a5,a1,a4
   1034c:	00177813          	andi	a6,a4,1
   10350:	00183893          	seqz	a7,a6
   10354:	4017d793          	srai	a5,a5,0x1
   10358:	411787b3          	sub	a5,a5,a7
   1035c:	00279793          	slli	a5,a5,0x2
   10360:	00171313          	slli	t1,a4,0x1
   10364:	00f507b3          	add	a5,a0,a5
   10368:	fade48e3          	blt	t3,a3,10318 <heapify+0x20>
   1036c:	00e585b3          	add	a1,a1,a4
   10370:	4015d593          	srai	a1,a1,0x1
   10374:	00183813          	seqz	a6,a6
   10378:	410585b3          	sub	a1,a1,a6
   1037c:	00259593          	slli	a1,a1,0x2
   10380:	00b50533          	add	a0,a0,a1
   10384:	01c52023          	sw	t3,0(a0)
   10388:	00008067          	ret
   1038c:	01f75593          	srli	a1,a4,0x1f
   10390:	00177813          	andi	a6,a4,1
   10394:	00e585b3          	add	a1,a1,a4
   10398:	4015d593          	srai	a1,a1,0x1
   1039c:	00183813          	seqz	a6,a6
   103a0:	410585b3          	sub	a1,a1,a6
   103a4:	00259593          	slli	a1,a1,0x2
   103a8:	00b50533          	add	a0,a0,a1
   103ac:	01c52023          	sw	t3,0(a0)
   103b0:	00008067          	ret

000103b4 <heapSort>:
   103b4:	fe010113          	addi	sp,sp,-32
   103b8:	00912a23          	sw	s1,20(sp)
   103bc:	01f5d493          	srli	s1,a1,0x1f
   103c0:	00b484b3          	add	s1,s1,a1
   103c4:	4014d493          	srai	s1,s1,0x1
   103c8:	00812c23          	sw	s0,24(sp)
   103cc:	01212823          	sw	s2,16(sp)
   103d0:	00112e23          	sw	ra,28(sp)
   103d4:	01312623          	sw	s3,12(sp)
   103d8:	fff48493          	addi	s1,s1,-1
   103dc:	00058413          	mv	s0,a1
   103e0:	00050913          	mv	s2,a0
   103e4:	0204c063          	bltz	s1,10404 <heapSort+0x50>
   103e8:	fff00993          	li	s3,-1
   103ec:	00048593          	mv	a1,s1
   103f0:	00040613          	mv	a2,s0
   103f4:	fff48493          	addi	s1,s1,-1
   103f8:	00090513          	mv	a0,s2
   103fc:	efdff0ef          	jal	ra,102f8 <heapify>
   10400:	ff3496e3          	bne	s1,s3,103ec <heapSort+0x38>
   10404:	fff40493          	addi	s1,s0,-1
   10408:	0204ce63          	bltz	s1,10444 <heapSort+0x90>
   1040c:	00241413          	slli	s0,s0,0x2
   10410:	00890433          	add	s0,s2,s0
   10414:	fff00993          	li	s3,-1
   10418:	ffc42703          	lw	a4,-4(s0)
   1041c:	00092783          	lw	a5,0(s2)
   10420:	00048613          	mv	a2,s1
   10424:	00e92023          	sw	a4,0(s2)
   10428:	fef42e23          	sw	a5,-4(s0)
   1042c:	00000593          	li	a1,0
   10430:	00090513          	mv	a0,s2
   10434:	fff48493          	addi	s1,s1,-1
   10438:	ec1ff0ef          	jal	ra,102f8 <heapify>
   1043c:	ffc40413          	addi	s0,s0,-4
   10440:	fd349ce3          	bne	s1,s3,10418 <heapSort+0x64>
   10444:	01c12083          	lw	ra,28(sp)
   10448:	01812403          	lw	s0,24(sp)
   1044c:	01412483          	lw	s1,20(sp)
   10450:	01012903          	lw	s2,16(sp)
   10454:	00c12983          	lw	s3,12(sp)
   10458:	02010113          	addi	sp,sp,32
   1045c:	00008067          	ret

00010460 <containsDuplicate>:
   10460:	ff010113          	addi	sp,sp,-16
   10464:	00812423          	sw	s0,8(sp)
   10468:	00912223          	sw	s1,4(sp)
   1046c:	00112623          	sw	ra,12(sp)
   10470:	00058493          	mv	s1,a1
   10474:	00050413          	mv	s0,a0
   10478:	f3dff0ef          	jal	ra,103b4 <heapSort>
   1047c:	00100793          	li	a5,1
   10480:	0497d463          	bge	a5,s1,104c8 <containsDuplicate+0x68>
   10484:	00042783          	lw	a5,0(s0)
   10488:	fff48613          	addi	a2,s1,-1
   1048c:	00440513          	addi	a0,s0,4
   10490:	00000713          	li	a4,0
   10494:	0080006f          	j	1049c <containsDuplicate+0x3c>
   10498:	02c70863          	beq	a4,a2,104c8 <containsDuplicate+0x68>
   1049c:	00078693          	mv	a3,a5
   104a0:	00052783          	lw	a5,0(a0)
   104a4:	00170713          	addi	a4,a4,1
   104a8:	00450513          	addi	a0,a0,4
   104ac:	fed796e3          	bne	a5,a3,10498 <containsDuplicate+0x38>
   104b0:	00c12083          	lw	ra,12(sp)
   104b4:	00812403          	lw	s0,8(sp)
   104b8:	00412483          	lw	s1,4(sp)
   104bc:	00100513          	li	a0,1
   104c0:	01010113          	addi	sp,sp,16
   104c4:	00008067          	ret
   104c8:	00c12083          	lw	ra,12(sp)
   104cc:	00812403          	lw	s0,8(sp)
   104d0:	00412483          	lw	s1,4(sp)
   104d4:	00000513          	li	a0,0
   104d8:	01010113          	addi	sp,sp,16
   104dc:	00008067          	ret


```
## -O3 Assembly Code
```assembly=
000102f8 <heapify>:
   102f8:	00259793          	slli	a5,a1,0x2
   102fc:	00159593          	slli	a1,a1,0x1
   10300:	00f507b3          	add	a5,a0,a5
   10304:	00158713          	addi	a4,a1,1
   10308:	0007ae03          	lw	t3,0(a5)
   1030c:	fff60e93          	addi	t4,a2,-1
   10310:	00c74a63          	blt	a4,a2,10324 <heapify+0x2c>
   10314:	0780006f          	j	1038c <heapify+0x94>
   10318:	00130713          	addi	a4,t1,1 # 102d9 <frame_dummy+0x15>
   1031c:	00d7a023          	sw	a3,0(a5)
   10320:	06c75663          	bge	a4,a2,1038c <heapify+0x94>
   10324:	00271793          	slli	a5,a4,0x2
   10328:	00f507b3          	add	a5,a0,a5
   1032c:	0007a683          	lw	a3,0(a5)
   10330:	01d75a63          	bge	a4,t4,10344 <heapify+0x4c>
   10334:	0047a783          	lw	a5,4(a5)
   10338:	00f6d663          	bge	a3,a5,10344 <heapify+0x4c>
   1033c:	00170713          	addi	a4,a4,1
   10340:	00078693          	mv	a3,a5
   10344:	01f75593          	srli	a1,a4,0x1f
   10348:	00e587b3          	add	a5,a1,a4
   1034c:	00177813          	andi	a6,a4,1
   10350:	00183893          	seqz	a7,a6
   10354:	4017d793          	srai	a5,a5,0x1
   10358:	411787b3          	sub	a5,a5,a7
   1035c:	00279793          	slli	a5,a5,0x2
   10360:	00171313          	slli	t1,a4,0x1
   10364:	00f507b3          	add	a5,a0,a5
   10368:	fade48e3          	blt	t3,a3,10318 <heapify+0x20>
   1036c:	00e585b3          	add	a1,a1,a4
   10370:	4015d593          	srai	a1,a1,0x1
   10374:	00183813          	seqz	a6,a6
   10378:	410585b3          	sub	a1,a1,a6
   1037c:	00259593          	slli	a1,a1,0x2
   10380:	00b50533          	add	a0,a0,a1
   10384:	01c52023          	sw	t3,0(a0)
   10388:	00008067          	ret
   1038c:	01f75593          	srli	a1,a4,0x1f
   10390:	00177813          	andi	a6,a4,1
   10394:	00e585b3          	add	a1,a1,a4
   10398:	4015d593          	srai	a1,a1,0x1
   1039c:	00183813          	seqz	a6,a6
   103a0:	410585b3          	sub	a1,a1,a6
   103a4:	00259593          	slli	a1,a1,0x2
   103a8:	00b50533          	add	a0,a0,a1
   103ac:	01c52023          	sw	t3,0(a0)
   103b0:	00008067          	ret

000103b4 <heapSort>:
   103b4:	fe010113          	addi	sp,sp,-32
   103b8:	01212823          	sw	s2,16(sp)
   103bc:	01f5d913          	srli	s2,a1,0x1f
   103c0:	00b90933          	add	s2,s2,a1
   103c4:	40195913          	srai	s2,s2,0x1
   103c8:	00812c23          	sw	s0,24(sp)
   103cc:	00912a23          	sw	s1,20(sp)
   103d0:	01312623          	sw	s3,12(sp)
   103d4:	00112e23          	sw	ra,28(sp)
   103d8:	fff90913          	addi	s2,s2,-1
   103dc:	00058493          	mv	s1,a1
   103e0:	00050413          	mv	s0,a0
   103e4:	fff00993          	li	s3,-1
   103e8:	00094e63          	bltz	s2,10404 <heapSort+0x50>
   103ec:	00090593          	mv	a1,s2
   103f0:	00048613          	mv	a2,s1
   103f4:	fff90913          	addi	s2,s2,-1
   103f8:	00040513          	mv	a0,s0
   103fc:	efdff0ef          	jal	ra,102f8 <heapify>
   10400:	ff3916e3          	bne	s2,s3,103ec <heapSort+0x38>
   10404:	fff48813          	addi	a6,s1,-1
   10408:	0c084e63          	bltz	a6,104e4 <heapSort+0x130>
   1040c:	00100793          	li	a5,1
   10410:	0b07d463          	bge	a5,a6,104b8 <heapSort+0x104>
   10414:	00249e13          	slli	t3,s1,0x2
   10418:	00080313          	mv	t1,a6
   1041c:	01c40e33          	add	t3,s0,t3
   10420:	00100e93          	li	t4,1
   10424:	ffce2703          	lw	a4,-4(t3)
   10428:	00042783          	lw	a5,0(s0)
   1042c:	fff80813          	addi	a6,a6,-1
   10430:	00e42023          	sw	a4,0(s0)
   10434:	fefe2e23          	sw	a5,-4(t3)
   10438:	00042883          	lw	a7,0(s0)
   1043c:	00100713          	li	a4,1
   10440:	00c0006f          	j	1044c <heapSort+0x98>
   10444:	00d7a023          	sw	a3,0(a5)
   10448:	0a675c63          	bge	a4,t1,10500 <heapSort+0x14c>
   1044c:	00271793          	slli	a5,a4,0x2
   10450:	00f407b3          	add	a5,s0,a5
   10454:	0007a683          	lw	a3,0(a5)
   10458:	01075a63          	bge	a4,a6,1046c <heapSort+0xb8>
   1045c:	0047a783          	lw	a5,4(a5)
   10460:	00f6d663          	bge	a3,a5,1046c <heapSort+0xb8>
   10464:	00170713          	addi	a4,a4,1
   10468:	00078693          	mv	a3,a5
   1046c:	00177613          	andi	a2,a4,1
   10470:	40175793          	srai	a5,a4,0x1
   10474:	00171513          	slli	a0,a4,0x1
   10478:	00163593          	seqz	a1,a2
   1047c:	00150713          	addi	a4,a0,1
   10480:	00078513          	mv	a0,a5
   10484:	40b787b3          	sub	a5,a5,a1
   10488:	00279793          	slli	a5,a5,0x2
   1048c:	00f407b3          	add	a5,s0,a5
   10490:	fad8cae3          	blt	a7,a3,10444 <heapSort+0x90>
   10494:	02061a63          	bnez	a2,104c8 <heapSort+0x114>
   10498:	fff50793          	addi	a5,a0,-1
   1049c:	00279793          	slli	a5,a5,0x2
   104a0:	00f407b3          	add	a5,s0,a5
   104a4:	0117a023          	sw	a7,0(a5)
   104a8:	fff30313          	addi	t1,t1,-1
   104ac:	ffce0e13          	addi	t3,t3,-4
   104b0:	f70ecae3          	blt	t4,a6,10424 <heapSort+0x70>
   104b4:	02084863          	bltz	a6,104e4 <heapSort+0x130>
   104b8:	00281793          	slli	a5,a6,0x2
   104bc:	00f407b3          	add	a5,s0,a5
   104c0:	00100613          	li	a2,1
   104c4:	04c0006f          	j	10510 <heapSort+0x15c>
   104c8:	00251513          	slli	a0,a0,0x2
   104cc:	00a40533          	add	a0,s0,a0
   104d0:	01152023          	sw	a7,0(a0)
   104d4:	fff30313          	addi	t1,t1,-1
   104d8:	ffce0e13          	addi	t3,t3,-4
   104dc:	f50ec4e3          	blt	t4,a6,10424 <heapSort+0x70>
   104e0:	fc085ce3          	bgez	a6,104b8 <heapSort+0x104>
   104e4:	01c12083          	lw	ra,28(sp)
   104e8:	01812403          	lw	s0,24(sp)
   104ec:	01412483          	lw	s1,20(sp)
   104f0:	01012903          	lw	s2,16(sp)
   104f4:	00c12983          	lw	s3,12(sp)
   104f8:	02010113          	addi	sp,sp,32
   104fc:	00008067          	ret
   10500:	00177613          	andi	a2,a4,1
   10504:	40175513          	srai	a0,a4,0x1
   10508:	f8dff06f          	j	10494 <heapSort+0xe0>
   1050c:	00000813          	li	a6,0
   10510:	0007a683          	lw	a3,0(a5)
   10514:	00042703          	lw	a4,0(s0)
   10518:	ffc78793          	addi	a5,a5,-4
   1051c:	00d42023          	sw	a3,0(s0)
   10520:	00e7a223          	sw	a4,4(a5)
   10524:	fec804e3          	beq	a6,a2,1050c <heapSort+0x158>
   10528:	fbdff06f          	j	104e4 <heapSort+0x130>
   
0001052c <containsDuplicate>:
   1052c:	ff010113          	addi	sp,sp,-16
   10530:	00812423          	sw	s0,8(sp)
   10534:	00912223          	sw	s1,4(sp)
   10538:	00112623          	sw	ra,12(sp)
   1053c:	00058493          	mv	s1,a1
   10540:	00050413          	mv	s0,a0
   10544:	e71ff0ef          	jal	ra,103b4 <heapSort>
   10548:	00100793          	li	a5,1
   1054c:	0497d463          	bge	a5,s1,10594 <containsDuplicate+0x68>
   10550:	00042783          	lw	a5,0(s0)
   10554:	fff48613          	addi	a2,s1,-1
   10558:	00440513          	addi	a0,s0,4
   1055c:	00000713          	li	a4,0
   10560:	0080006f          	j	10568 <containsDuplicate+0x3c>
   10564:	02c70863          	beq	a4,a2,10594 <containsDuplicate+0x68>
   10568:	00078693          	mv	a3,a5
   1056c:	00052783          	lw	a5,0(a0)
   10570:	00170713          	addi	a4,a4,1
   10574:	00450513          	addi	a0,a0,4
   10578:	fed796e3          	bne	a5,a3,10564 <containsDuplicate+0x38>
   1057c:	00c12083          	lw	ra,12(sp)
   10580:	00812403          	lw	s0,8(sp)
   10584:	00412483          	lw	s1,4(sp)
   10588:	00100513          	li	a0,1
   1058c:	01010113          	addi	sp,sp,16
   10590:	00008067          	ret
   10594:	00c12083          	lw	ra,12(sp)
   10598:	00812403          	lw	s0,8(sp)
   1059c:	00412483          	lw	s1,4(sp)
   105a0:	00000513          	li	a0,0
   105a4:	01010113          	addi	sp,sp,16
   105a8:	00008067          	ret

```
## -Os Assembly Code
```assembly=
00010294 <heapify>:
   10294:	00259793          	slli	a5,a1,0x2
   10298:	00f507b3          	add	a5,a0,a5
   1029c:	0007a703          	lw	a4,0(a5)
   102a0:	00159593          	slli	a1,a1,0x1
   102a4:	00158593          	addi	a1,a1,1
   102a8:	fff60813          	addi	a6,a2,-1
   102ac:	02c5c663          	blt	a1,a2,102d8 <heapify+0x44>
   102b0:	01f5d793          	srli	a5,a1,0x1f
   102b4:	00b787b3          	add	a5,a5,a1
   102b8:	0015f593          	andi	a1,a1,1
   102bc:	4017d793          	srai	a5,a5,0x1
   102c0:	00059463          	bnez	a1,102c8 <heapify+0x34>
   102c4:	fff78793          	addi	a5,a5,-1
   102c8:	00279793          	slli	a5,a5,0x2
   102cc:	00f50533          	add	a0,a0,a5
   102d0:	00e52023          	sw	a4,0(a0)
   102d4:	00008067          	ret
   102d8:	00259793          	slli	a5,a1,0x2
   102dc:	00f507b3          	add	a5,a0,a5
   102e0:	0007a683          	lw	a3,0(a5)
   102e4:	0105d863          	bge	a1,a6,102f4 <heapify+0x60>
   102e8:	0047a783          	lw	a5,4(a5)
   102ec:	00f6d463          	bge	a3,a5,102f4 <heapify+0x60>
   102f0:	00158593          	addi	a1,a1,1
   102f4:	00259793          	slli	a5,a1,0x2
   102f8:	00f507b3          	add	a5,a0,a5
   102fc:	0007a683          	lw	a3,0(a5)
   10300:	01f5d793          	srli	a5,a1,0x1f
   10304:	00b787b3          	add	a5,a5,a1
   10308:	4017d793          	srai	a5,a5,0x1
   1030c:	0015f893          	andi	a7,a1,1
   10310:	fad750e3          	bge	a4,a3,102b0 <heapify+0x1c>
   10314:	00089463          	bnez	a7,1031c <heapify+0x88>
   10318:	fff78793          	addi	a5,a5,-1
   1031c:	00279793          	slli	a5,a5,0x2
   10320:	00f507b3          	add	a5,a0,a5
   10324:	00159593          	slli	a1,a1,0x1
   10328:	00d7a023          	sw	a3,0(a5)
   1032c:	00158593          	addi	a1,a1,1
   10330:	f7dff06f          	j	102ac <heapify+0x18>
   
00010334 <heapSort>:
   10334:	ff010113          	addi	sp,sp,-16
   10338:	00912223          	sw	s1,4(sp)
   1033c:	01f5d493          	srli	s1,a1,0x1f
   10340:	00b484b3          	add	s1,s1,a1
   10344:	00812423          	sw	s0,8(sp)
   10348:	01212023          	sw	s2,0(sp)
   1034c:	00112623          	sw	ra,12(sp)
   10350:	00050913          	mv	s2,a0
   10354:	00058413          	mv	s0,a1
   10358:	4014d493          	srai	s1,s1,0x1
   1035c:	fff48493          	addi	s1,s1,-1
   10360:	0204d863          	bgez	s1,10390 <heapSort+0x5c>
   10364:	fff40493          	addi	s1,s0,-1
   10368:	00241413          	slli	s0,s0,0x2
   1036c:	00890433          	add	s0,s2,s0
   10370:	ffc40413          	addi	s0,s0,-4
   10374:	0204d863          	bgez	s1,103a4 <heapSort+0x70>
   10378:	00c12083          	lw	ra,12(sp)
   1037c:	00812403          	lw	s0,8(sp)
   10380:	00412483          	lw	s1,4(sp)
   10384:	00012903          	lw	s2,0(sp)
   10388:	01010113          	addi	sp,sp,16
   1038c:	00008067          	ret
   10390:	00040613          	mv	a2,s0
   10394:	00048593          	mv	a1,s1
   10398:	00090513          	mv	a0,s2
   1039c:	ef9ff0ef          	jal	ra,10294 <heapify>
   103a0:	fbdff06f          	j	1035c <heapSort+0x28>
   103a4:	00042703          	lw	a4,0(s0)
   103a8:	00092783          	lw	a5,0(s2)
   103ac:	00048613          	mv	a2,s1
   103b0:	00e92023          	sw	a4,0(s2)
   103b4:	00f42023          	sw	a5,0(s0)
   103b8:	00000593          	li	a1,0
   103bc:	00090513          	mv	a0,s2
   103c0:	ed5ff0ef          	jal	ra,10294 <heapify>
   103c4:	fff48493          	addi	s1,s1,-1
   103c8:	fa9ff06f          	j	10370 <heapSort+0x3c>

000103cc <containsDuplicate>:
   103cc:	ff010113          	addi	sp,sp,-16
   103d0:	00812423          	sw	s0,8(sp)
   103d4:	00912223          	sw	s1,4(sp)
   103d8:	00050413          	mv	s0,a0
   103dc:	00058493          	mv	s1,a1
   103e0:	00112623          	sw	ra,12(sp)
   103e4:	f51ff0ef          	jal	ra,10334 <heapSort>
   103e8:	00040513          	mv	a0,s0
   103ec:	00000793          	li	a5,0
   103f0:	fff48493          	addi	s1,s1,-1
   103f4:	0097ce63          	blt	a5,s1,10410 <containsDuplicate+0x44>
   103f8:	00000513          	li	a0,0
   103fc:	00c12083          	lw	ra,12(sp)
   10400:	00812403          	lw	s0,8(sp)
   10404:	00412483          	lw	s1,4(sp)
   10408:	01010113          	addi	sp,sp,16
   1040c:	00008067          	ret
   10410:	00052683          	lw	a3,0(a0)
   10414:	00450513          	addi	a0,a0,4
   10418:	00052703          	lw	a4,0(a0)
   1041c:	00e68663          	beq	a3,a4,10428 <containsDuplicate+0x5c>
   10420:	00178793          	addi	a5,a5,1
   10424:	fd1ff06f          	j	103f4 <containsDuplicate+0x28>
   10428:	00100513          	li	a0,1
   1042c:	fd1ff06f          	j	103fc <containsDuplicate+0x30>
```
## -Ofast Assembly Code
```assembly=
000102f8 <heapify>:
   102f8:	00259793          	slli	a5,a1,0x2
   102fc:	00159593          	slli	a1,a1,0x1
   10300:	00f507b3          	add	a5,a0,a5
   10304:	00158713          	addi	a4,a1,1
   10308:	0007ae03          	lw	t3,0(a5)
   1030c:	fff60e93          	addi	t4,a2,-1
   10310:	00c74a63          	blt	a4,a2,10324 <heapify+0x2c>
   10314:	0780006f          	j	1038c <heapify+0x94>
   10318:	00130713          	addi	a4,t1,1 # 102d9 <frame_dummy+0x15>
   1031c:	00d7a023          	sw	a3,0(a5)
   10320:	06c75663          	bge	a4,a2,1038c <heapify+0x94>
   10324:	00271793          	slli	a5,a4,0x2
   10328:	00f507b3          	add	a5,a0,a5
   1032c:	0007a683          	lw	a3,0(a5)
   10330:	01d75a63          	bge	a4,t4,10344 <heapify+0x4c>
   10334:	0047a783          	lw	a5,4(a5)
   10338:	00f6d663          	bge	a3,a5,10344 <heapify+0x4c>
   1033c:	00170713          	addi	a4,a4,1
   10340:	00078693          	mv	a3,a5
   10344:	01f75593          	srli	a1,a4,0x1f
   10348:	00e587b3          	add	a5,a1,a4
   1034c:	00177813          	andi	a6,a4,1
   10350:	00183893          	seqz	a7,a6
   10354:	4017d793          	srai	a5,a5,0x1
   10358:	411787b3          	sub	a5,a5,a7
   1035c:	00279793          	slli	a5,a5,0x2
   10360:	00171313          	slli	t1,a4,0x1
   10364:	00f507b3          	add	a5,a0,a5
   10368:	fade48e3          	blt	t3,a3,10318 <heapify+0x20>
   1036c:	00e585b3          	add	a1,a1,a4
   10370:	4015d593          	srai	a1,a1,0x1
   10374:	00183813          	seqz	a6,a6
   10378:	410585b3          	sub	a1,a1,a6
   1037c:	00259593          	slli	a1,a1,0x2
   10380:	00b50533          	add	a0,a0,a1
   10384:	01c52023          	sw	t3,0(a0)
   10388:	00008067          	ret
   1038c:	01f75593          	srli	a1,a4,0x1f
   10390:	00177813          	andi	a6,a4,1
   10394:	00e585b3          	add	a1,a1,a4
   10398:	4015d593          	srai	a1,a1,0x1
   1039c:	00183813          	seqz	a6,a6
   103a0:	410585b3          	sub	a1,a1,a6
   103a4:	00259593          	slli	a1,a1,0x2
   103a8:	00b50533          	add	a0,a0,a1
   103ac:	01c52023          	sw	t3,0(a0)
   103b0:	00008067          	ret

000103b4 <heapSort>:
   103b4:	fe010113          	addi	sp,sp,-32
   103b8:	01212823          	sw	s2,16(sp)
   103bc:	01f5d913          	srli	s2,a1,0x1f
   103c0:	00b90933          	add	s2,s2,a1
   103c4:	40195913          	srai	s2,s2,0x1
   103c8:	00812c23          	sw	s0,24(sp)
   103cc:	00912a23          	sw	s1,20(sp)
   103d0:	01312623          	sw	s3,12(sp)
   103d4:	00112e23          	sw	ra,28(sp)
   103d8:	fff90913          	addi	s2,s2,-1
   103dc:	00058493          	mv	s1,a1
   103e0:	00050413          	mv	s0,a0
   103e4:	fff00993          	li	s3,-1
   103e8:	00094e63          	bltz	s2,10404 <heapSort+0x50>
   103ec:	00090593          	mv	a1,s2
   103f0:	00048613          	mv	a2,s1
   103f4:	fff90913          	addi	s2,s2,-1
   103f8:	00040513          	mv	a0,s0
   103fc:	efdff0ef          	jal	ra,102f8 <heapify>
   10400:	ff3916e3          	bne	s2,s3,103ec <heapSort+0x38>
   10404:	fff48813          	addi	a6,s1,-1
   10408:	0c084e63          	bltz	a6,104e4 <heapSort+0x130>
   1040c:	00100793          	li	a5,1
   10410:	0b07d463          	bge	a5,a6,104b8 <heapSort+0x104>
   10414:	00249e13          	slli	t3,s1,0x2
   10418:	00080313          	mv	t1,a6
   1041c:	01c40e33          	add	t3,s0,t3
   10420:	00100e93          	li	t4,1
   10424:	ffce2703          	lw	a4,-4(t3)
   10428:	00042783          	lw	a5,0(s0)
   1042c:	fff80813          	addi	a6,a6,-1
   10430:	00e42023          	sw	a4,0(s0)
   10434:	fefe2e23          	sw	a5,-4(t3)
   10438:	00042883          	lw	a7,0(s0)
   1043c:	00100713          	li	a4,1
   10440:	00c0006f          	j	1044c <heapSort+0x98>
   10444:	00d7a023          	sw	a3,0(a5)
   10448:	0a675c63          	bge	a4,t1,10500 <heapSort+0x14c>
   1044c:	00271793          	slli	a5,a4,0x2
   10450:	00f407b3          	add	a5,s0,a5
   10454:	0007a683          	lw	a3,0(a5)
   10458:	01075a63          	bge	a4,a6,1046c <heapSort+0xb8>
   1045c:	0047a783          	lw	a5,4(a5)
   10460:	00f6d663          	bge	a3,a5,1046c <heapSort+0xb8>
   10464:	00170713          	addi	a4,a4,1
   10468:	00078693          	mv	a3,a5
   1046c:	00177613          	andi	a2,a4,1
   10470:	40175793          	srai	a5,a4,0x1
   10474:	00171513          	slli	a0,a4,0x1
   10478:	00163593          	seqz	a1,a2
   1047c:	00150713          	addi	a4,a0,1
   10480:	00078513          	mv	a0,a5
   10484:	40b787b3          	sub	a5,a5,a1
   10488:	00279793          	slli	a5,a5,0x2
   1048c:	00f407b3          	add	a5,s0,a5
   10490:	fad8cae3          	blt	a7,a3,10444 <heapSort+0x90>
   10494:	02061a63          	bnez	a2,104c8 <heapSort+0x114>
   10498:	fff50793          	addi	a5,a0,-1
   1049c:	00279793          	slli	a5,a5,0x2
   104a0:	00f407b3          	add	a5,s0,a5
   104a4:	0117a023          	sw	a7,0(a5)
   104a8:	fff30313          	addi	t1,t1,-1
   104ac:	ffce0e13          	addi	t3,t3,-4
   104b0:	f70ecae3          	blt	t4,a6,10424 <heapSort+0x70>
   104b4:	02084863          	bltz	a6,104e4 <heapSort+0x130>
   104b8:	00281793          	slli	a5,a6,0x2
   104bc:	00f407b3          	add	a5,s0,a5
   104c0:	00100613          	li	a2,1
   104c4:	04c0006f          	j	10510 <heapSort+0x15c>
   104c8:	00251513          	slli	a0,a0,0x2
   104cc:	00a40533          	add	a0,s0,a0
   104d0:	01152023          	sw	a7,0(a0)
   104d4:	fff30313          	addi	t1,t1,-1
   104d8:	ffce0e13          	addi	t3,t3,-4
   104dc:	f50ec4e3          	blt	t4,a6,10424 <heapSort+0x70>
   104e0:	fc085ce3          	bgez	a6,104b8 <heapSort+0x104>
   104e4:	01c12083          	lw	ra,28(sp)
   104e8:	01812403          	lw	s0,24(sp)
   104ec:	01412483          	lw	s1,20(sp)
   104f0:	01012903          	lw	s2,16(sp)
   104f4:	00c12983          	lw	s3,12(sp)
   104f8:	02010113          	addi	sp,sp,32
   104fc:	00008067          	ret
   10500:	00177613          	andi	a2,a4,1
   10504:	40175513          	srai	a0,a4,0x1
   10508:	f8dff06f          	j	10494 <heapSort+0xe0>
   1050c:	00000813          	li	a6,0
   10510:	0007a683          	lw	a3,0(a5)
   10514:	00042703          	lw	a4,0(s0)
   10518:	ffc78793          	addi	a5,a5,-4
   1051c:	00d42023          	sw	a3,0(s0)
   10520:	00e7a223          	sw	a4,4(a5)
   10524:	fec804e3          	beq	a6,a2,1050c <heapSort+0x158>
   10528:	fbdff06f          	j	104e4 <heapSort+0x130>
```