	.file	"sum_full.c"
	.option nopic
	.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
	.attribute unaligned_access, 0
	.attribute stack_align, 16
	.text
	.align	1
	.globl	read_timer
	.type	read_timer, @function
read_timer:
	addi	sp,sp,-32
	sd	ra,24(sp)
	sd	s0,16(sp)
	addi	s0,sp,32
	addi	a5,s0,-32
	mv	a0,a5
	call	ftime
	ld	a5,-32(s0)
	fcvt.d.l	fa4,a5
	lhu	a5,-24(s0)
	fcvt.d.wu	fa3,a5
	lui	a5,%hi(.LC0)
	fld	fa5,%lo(.LC0)(a5)
	fdiv.d	fa5,fa3,fa5
	fadd.d	fa5,fa4,fa5
	fmv.d	fa0,fa5
	ld	ra,24(sp)
	ld	s0,16(sp)
	addi	sp,sp,32
	jr	ra
	.size	read_timer, .-read_timer
	.align	1
	.globl	read_timer_ms
	.type	read_timer_ms, @function
read_timer_ms:
	addi	sp,sp,-32
	sd	ra,24(sp)
	sd	s0,16(sp)
	addi	s0,sp,32
	addi	a5,s0,-32
	mv	a0,a5
	call	ftime
	ld	a5,-32(s0)
	fcvt.d.l	fa4,a5
	lui	a5,%hi(.LC0)
	fld	fa5,%lo(.LC0)(a5)
	fmul.d	fa4,fa4,fa5
	lhu	a5,-24(s0)
	fcvt.d.wu	fa5,a5
	fadd.d	fa5,fa4,fa5
	fmv.d	fa0,fa5
	ld	ra,24(sp)
	ld	s0,16(sp)
	addi	sp,sp,32
	jr	ra
	.size	read_timer_ms, .-read_timer_ms
	.align	1
	.globl	init
	.type	init, @function
init:
	addi	sp,sp,-48
	sd	ra,40(sp)
	sd	s0,32(sp)
	addi	s0,sp,48
	sd	a0,-40(s0)
	mv	a5,a1
	sw	a5,-44(s0)
	sw	zero,-20(s0)
	j	.L6
.L7:
	call	drand48
	fmv.d	fa5,fa0
	lw	a5,-20(s0)
	slli	a5,a5,2
	ld	a4,-40(s0)
	add	a5,a4,a5
	fcvt.s.d	fa5,fa5
	fsw	fa5,0(a5)
	lw	a5,-20(s0)
	addiw	a5,a5,1
	sw	a5,-20(s0)
.L6:
	lw	a4,-20(s0)
	lw	a5,-44(s0)
	sext.w	a4,a4
	sext.w	a5,a5
	blt	a4,a5,.L7
	nop
	nop
	ld	ra,40(sp)
	ld	s0,32(sp)
	addi	sp,sp,48
	jr	ra
	.size	init, .-init
	.align	1
	.globl	sum
	.type	sum, @function
sum:
	addi	sp,sp,-48
	sd	s0,40(sp)
	addi	s0,sp,48
	mv	a5,a0
	sd	a1,-48(s0)
	fsw	fa0,-40(s0)
	sw	a5,-36(s0)
	sw	zero,-24(s0)
	sw	zero,-20(s0)
	j	.L9
.L10:
	lw	a5,-20(s0)
	slli	a5,a5,2
	ld	a4,-48(s0)
	add	a5,a4,a5
	flw	fa4,0(a5)
	flw	fa5,-40(s0)
	fmul.s	fa5,fa4,fa5
	flw	fa4,-24(s0)
	fadd.s	fa5,fa4,fa5
	fsw	fa5,-24(s0)
	lw	a5,-20(s0)
	addiw	a5,a5,1
	sw	a5,-20(s0)
.L9:
	lw	a4,-20(s0)
	lw	a5,-36(s0)
	sext.w	a4,a4
	sext.w	a5,a5
	blt	a4,a5,.L10
	flw	fa5,-24(s0)
	fmv.s	fa0,fa5
	ld	s0,40(sp)
	addi	sp,sp,48
	jr	ra
	.size	sum, .-sum
	.section	.rodata
	.align	3
.LC1:
	.string	"Usage: sum <n> (default %d)\n"
	.align	3
.LC3:
	.string	"======================================================================================================"
	.align	3
.LC4:
	.string	"\tSum %d numbers\n"
	.align	3
.LC5:
	.string	"------------------------------------------------------------------------------------------------------"
	.align	3
.LC6:
	.string	"Performance:\t\tRuntime (ms)\t MFLOPS "
	.align	3
.LC8:
	.string	"Sum:\t\t\t%4f\t%4f\n"
	.text
	.align	1
	.globl	main
	.type	main, @function
main:
	addi	sp,sp,-80
	sd	ra,72(sp)
	sd	s0,64(sp)
	addi	s0,sp,80
	mv	a5,a0
	sd	a1,-80(s0)
	sw	a5,-68(s0)
	li	a5,102400
	sw	a5,-20(s0)
	lw	a5,-68(s0)
	sext.w	a4,a5
	li	a5,1
	bgt	a4,a5,.L13
	lui	a5,%hi(_impure_ptr)
	ld	a5,%lo(_impure_ptr)(a5)
	ld	a4,24(a5)
	lw	a5,-20(s0)
	mv	a2,a5
	lui	a5,%hi(.LC1)
	addi	a1,a5,%lo(.LC1)
	mv	a0,a4
	call	fprintf
	j	.L14
.L13:
	ld	a5,-80(s0)
	addi	a5,a5,8
	ld	a5,0(a5)
	mv	a0,a5
	call	atoi
	mv	a5,a0
	sw	a5,-20(s0)
.L14:
	lw	a5,-20(s0)
	slli	a5,a5,2
	mv	a0,a5
	call	malloc
	mv	a5,a0
	sd	a5,-32(s0)
	lw	a5,-20(s0)
	slli	a5,a5,2
	mv	a0,a5
	call	malloc
	mv	a5,a0
	sd	a5,-40(s0)
	li	a0,4096
	call	srand48
	lw	a5,-20(s0)
	mv	a1,a5
	ld	a0,-32(s0)
	call	init
	lw	a5,-20(s0)
	mv	a1,a5
	ld	a0,-40(s0)
	call	init
	lui	a5,%hi(.LC2)
	flw	fa5,%lo(.LC2)(a5)
	fsw	fa5,-44(s0)
	call	read_timer
	fsd	fa0,-56(s0)
	lw	a5,-20(s0)
	flw	fa0,-44(s0)
	ld	a1,-32(s0)
	mv	a0,a5
	call	sum
	fsw	fa0,-60(s0)
	call	read_timer
	fmv.d	fa4,fa0
	fld	fa5,-56(s0)
	fsub.d	fa5,fa4,fa5
	fsd	fa5,-56(s0)
	lui	a5,%hi(.LC3)
	addi	a0,a5,%lo(.LC3)
	call	puts
	lw	a5,-20(s0)
	mv	a1,a5
	lui	a5,%hi(.LC4)
	addi	a0,a5,%lo(.LC4)
	call	printf
	lui	a5,%hi(.LC5)
	addi	a0,a5,%lo(.LC5)
	call	puts
	lui	a5,%hi(.LC6)
	addi	a0,a5,%lo(.LC6)
	call	puts
	lui	a5,%hi(.LC5)
	addi	a0,a5,%lo(.LC5)
	call	puts
	fld	fa4,-56(s0)
	lui	a5,%hi(.LC0)
	fld	fa5,%lo(.LC0)(a5)
	fmul.d	fa2,fa4,fa5
	lw	a5,-20(s0)
	slliw	a5,a5,1
	sext.w	a5,a5
	fcvt.d.w	fa4,a5
	fld	fa3,-56(s0)
	lui	a5,%hi(.LC7)
	fld	fa5,%lo(.LC7)(a5)
	fmul.d	fa5,fa3,fa5
	fdiv.d	fa5,fa4,fa5
	fmv.x.d	a2,fa5
	fmv.x.d	a1,fa2
	lui	a5,%hi(.LC8)
	addi	a0,a5,%lo(.LC8)
	call	printf
	li	a5,0
	mv	a0,a5
	ld	ra,72(sp)
	ld	s0,64(sp)
	addi	sp,sp,80
	jr	ra
	.size	main, .-main
	.section	.rodata
	.align	3
.LC0:
	.word	0
	.word	1083129856
	.align	2
.LC2:
	.word	1039972644
	.align	3
.LC7:
	.word	0
	.word	1093567616
	.ident	"GCC: (GNU) 9.2.0"
