Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>

int main(void)
{
    long n, i, j, cusum=0, total=0;
    long a[200000];
    long mod = 1000000007;

    scanf("%ld", &n);
    for(i=0; i<n; i++){
        scanf("%ld", &a[i]); 
        cusum=(cusum+a[i]) % mod;   //累積和
    }

    for(i=0; i<n; i++){
        cusum -= a[i];
        if(cusum < 0) cusum += mod;
        
        total += a[i]*cusum;
        total %= mod;
    }

    printf("%ld", total);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1597440(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2624, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -1600040(%rbp)
	movq	$0, -1600032(%rbp)
	movq	$1000000007, -1600024(%rbp)
	leaq	-1600056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1600048(%rbp)
	jmp	.L2
.L3:
	leaq	-1600016(%rbp), %rdx
	movq	-1600048(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rdx
	movq	-1600040(%rbp), %rax
	addq	%rdx, %rax
	cqto
	idivq	-1600024(%rbp)
	movq	%rdx, -1600040(%rbp)
	addq	$1, -1600048(%rbp)
.L2:
	movq	-1600056(%rbp), %rax
	cmpq	%rax, -1600048(%rbp)
	jl	.L3
	movq	$0, -1600048(%rbp)
	jmp	.L4
.L6:
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rax
	subq	%rax, -1600040(%rbp)
	cmpq	$0, -1600040(%rbp)
	jns	.L5
	movq	-1600024(%rbp), %rax
	addq	%rax, -1600040(%rbp)
.L5:
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rax
	imulq	-1600040(%rbp), %rax
	addq	%rax, -1600032(%rbp)
	movq	-1600032(%rbp), %rax
	cqto
	idivq	-1600024(%rbp)
	movq	%rdx, -1600032(%rbp)
	addq	$1, -1600048(%rbp)
.L4:
	movq	-1600056(%rbp), %rax
	cmpq	%rax, -1600048(%rbp)
	jl	.L6
	movq	-1600032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1597440(%rsp), %r11
	.cfi_def_cfa 11, 1597496
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2600, %rsp
	.cfi_def_cfa_offset 1600096
	leaq	.LC0(%rip), %r13
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 1600024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, 8(%rsp)
	jle	.L2
	xorl	%ebx, %ebx
	xorl	%r15d, %r15d
	leaq	16(%rsp), %r12
	movabsq	$-8543223828751151131, %r14
	.p2align 4,,10
	.p2align 3
.L3:
	leaq	(%r12,%r15,8), %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	movq	%r12, %rbp
	call	__isoc99_scanf@PLT
	addq	(%r12,%r15,8), %rbx
	addq	$1, %r15
	movq	%rbx, %rax
	movq	%rbx, %rcx
	imulq	%r14
	movq	%rcx, %rax
	sarq	$63, %rax
	leaq	(%rdx,%rbx), %rbx
	sarq	$29, %rbx
	subq	%rax, %rbx
	imulq	$1000000007, %rbx, %rax
	subq	%rax, %rcx
	movq	8(%rsp), %rax
	movq	%rcx, %rbx
	cmpq	%r15, %rax
	jg	.L3
	testq	%rax, %rax
	jle	.L2
	movabsq	$-8543223828751151131, %rsi
	leaq	(%r12,%rax,8), %rdi
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L5:
	movq	0(%rbp), %rcx
	subq	%rcx, %rbx
	leaq	1000000007(%rbx), %rax
	cmovs	%rax, %rbx
	addq	$8, %rbp
	imulq	%rbx, %rcx
	addq	%rdx, %rcx
	movq	%rcx, %rax
	imulq	%rsi
	movq	%rcx, %rax
	sarq	$63, %rax
	addq	%rcx, %rdx
	sarq	$29, %rdx
	subq	%rax, %rdx
	imulq	$1000000007, %rdx, %rax
	movq	%rcx, %rdx
	subq	%rax, %rdx
	cmpq	%rbp, %rdi
	jne	.L5
.L6:
	xorl	%eax, %eax
	movq	%r13, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	1600024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$1600040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L2:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L6
.L12:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1597440(%rsp), %r11
	.cfi_def_cfa 11, 1597496
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2600, %rsp
	.cfi_def_cfa_offset 1600096
	leaq	.LC0(%rip), %r13
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 1600024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpq	$0, 8(%rsp)
	jle	.L2
	xorl	%ebx, %ebx
	xorl	%r15d, %r15d
	leaq	16(%rsp), %r12
	movabsq	$-8543223828751151131, %r14
	.p2align 4,,10
	.p2align 3
.L3:
	leaq	(%r12,%r15,8), %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	movq	%r12, %rbp
	call	__isoc99_scanf@PLT
	addq	(%r12,%r15,8), %rbx
	addq	$1, %r15
	movq	%rbx, %rax
	movq	%rbx, %rcx
	imulq	%r14
	movq	%rcx, %rax
	sarq	$63, %rax
	leaq	(%rdx,%rbx), %rbx
	sarq	$29, %rbx
	subq	%rax, %rbx
	imulq	$1000000007, %rbx, %rax
	subq	%rax, %rcx
	movq	8(%rsp), %rax
	movq	%rcx, %rbx
	cmpq	%r15, %rax
	jg	.L3
	testq	%rax, %rax
	jle	.L2
	movabsq	$-8543223828751151131, %rsi
	leaq	(%r12,%rax,8), %rdi
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L5:
	movq	0(%rbp), %rcx
	subq	%rcx, %rbx
	leaq	1000000007(%rbx), %rax
	cmovs	%rax, %rbx
	addq	$8, %rbp
	imulq	%rbx, %rcx
	addq	%rdx, %rcx
	movq	%rcx, %rax
	imulq	%rsi
	movq	%rcx, %rax
	sarq	$63, %rax
	addq	%rcx, %rdx
	sarq	$29, %rdx
	subq	%rax, %rdx
	imulq	$1000000007, %rdx, %rax
	movq	%rcx, %rdx
	subq	%rax, %rdx
	cmpq	%rbp, %rdi
	jne	.L5
.L6:
	xorl	%eax, %eax
	movq	%r13, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	1600024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$1600040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L2:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L6
.L12:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>

int main(void)
{
    long n, i, j, cusum=0, total=0;
    long a[200000];
    long mod = 1000000007;

    scanf("%ld", &n);
    for(i=0; i<n; i++){
        scanf("%ld", &a[i]); 
        cusum=(cusum+a[i]) % mod;   //累積和
    }

    for(i=0; i<n; i++){
        cusum -= a[i];
        if(cusum < 0) cusum += mod;
        
        total += a[i]*cusum;
        total %= mod;
    }

    printf("%ld", total);
}
3
0 2 3
 4
141421356 17320508 22360679 176612
 3
0 2 0
 4
141421356 17320508 44188846 176612
 4
141421356 15438004 44188846 176612
 4
141421356 15438004 10545868 176612
 4
141421356 22198551 10545868 176612
 4
141421356 22198551 4405286 176612
 4
141421356 5143928 4405286 176612
 4
141421356 1512598 4405286 176612

6 432841470 0 442072669 24018621 309796111 856634378 907440962 471127930 478491412
Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>

int main(void)
{
    long n, i, j, cusum=0, total=0;
    long a[200000];
    long mod = 1000000007;

    scanf("%ld", &n);
    for(i=0; i<n; i++){
        scanf("%ld", &a[i]); 
        cusum=(cusum+a[i]) % mod;   //累積和
    }

    for(i=0; i<n; i++){
        cusum -= a[i];
        if(cusum < 0) cusum += mod;
        
        total += a[i]*cusum;
        total %= mod;
    }

    printf("%ld", total);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1597440(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2624, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -1600040(%rbp)
	movq	$0, -1600032(%rbp)
	movq	$1000000007, -1600024(%rbp)
	leaq	-1600056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1600048(%rbp)
	jmp	.L2
.L3:
	leaq	-1600016(%rbp), %rdx
	movq	-1600048(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rdx
	movq	-1600040(%rbp), %rax
	addq	%rdx, %rax
	cqto
	idivq	-1600024(%rbp)
	movq	%rdx, -1600040(%rbp)
	addq	$1, -1600048(%rbp)
.L2:
	movq	-1600056(%rbp), %rax
	cmpq	%rax, -1600048(%rbp)
	jl	.L3
	movq	$0, -1600048(%rbp)
	jmp	.L4
.L6:
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rax
	subq	%rax, -1600040(%rbp)
	cmpq	$0, -1600040(%rbp)
	jns	.L5
	movq	-1600024(%rbp), %rax
	addq	%rax, -1600040(%rbp)
.L5:
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rax
	imulq	-1600040(%rbp), %rax
	addq	%rax, -1600032(%rbp)
	movq	-1600032(%rbp), %rax
	cqto
	idivq	-1600024(%rbp)
	movq	%rdx, -1600032(%rbp)
	addq	$1, -1600048(%rbp)
.L4:
	movq	-1600056(%rbp), %rax
	cmpq	%rax, -1600048(%rbp)
	jl	.L6
	movq	-1600032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%ld"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1597440(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2624, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -1600040(%rbp)
	movq	$0, -1600032(%rbp)
	movq	$1000000007, -1600024(%rbp)
	leaq	-1600056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -1600048(%rbp)
	jmp	.L2
.L3:
	leaq	-1600016(%rbp), %rdx
	movq	-1600048(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rdx
	movq	-1600040(%rbp), %rax
	addq	%rdx, %rax
	cqto
	idivq	-1600024(%rbp)
	movq	%rdx, -1600040(%rbp)
	addq	$1, -1600048(%rbp)
.L2:
	movq	-1600056(%rbp), %rax
	cmpq	%rax, -1600048(%rbp)
	jl	.L3
	movq	$0, -1600048(%rbp)
	jmp	.L4
.L6:
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rax
	subq	%rax, -1600040(%rbp)
	cmpq	$0, -1600040(%rbp)
	jns	.L5
	movq	-1600024(%rbp), %rax
	addq	%rax, -1600040(%rbp)
.L5:
	movq	-1600048(%rbp), %rax
	movq	-1600016(%rbp,%rax,8), %rax
	imulq	-1600040(%rbp), %rax
	addq	%rax, -1600032(%rbp)
	movq	-1600032(%rbp), %rax
	cqto
	idivq	-1600024(%rbp)
	movq	%rdx, -1600032(%rbp)
	addq	$1, -1600048(%rbp)
.L4:
	movq	-1600056(%rbp), %rax
	cmpq	%rax, -1600048(%rbp)
	jl	.L6
	movq	-1600032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
