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

```c
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,i;
	long a[100000],x;
	long long ans=0;
	scanf("%d%ld",&n,&x);
	for(i=0;i<n;i++)scanf("%ld",&a[i]);
	for(i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			if(x-a[i]>=0){
				ans+=(a[i+1]-(x-a[i]));
				a[i+1]=x-a[i];
			}
			else {
				ans+=(a[i+1]+a[i]-x);
				a[i+1]=0;
				a[i]=x;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798752
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1312, %rsp
	.cfi_def_cfa_offset 800064
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %eax
	testl	%eax, %eax
	jle	.L9
	leaq	16(%rsp), %rbp
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %edx
	addq	$8, %rbp
	cmpl	%ebx, %edx
	jg	.L3
	cmpl	$1, %edx
	jle	.L9
	subl	$2, %edx
	movq	8(%rsp), %rdi
	leaq	24(%rsp), %rax
	xorl	%r8d, %r8d
	leaq	32(%rsp,%rdx,8), %r9
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%r10, (%rax)
	subq	%r10, %rcx
	addq	%rcx, %r8
.L4:
	addq	$8, %rax
	cmpq	%rax, %r9
	je	.L2
.L6:
	movq	-8(%rax), %rdx
	movq	(%rax), %rcx
	leaq	(%rdx,%rcx), %rsi
	cmpq	%rdi, %rsi
	jle	.L4
	movq	%rdi, %r10
	subq	%rdx, %r10
	jns	.L14
	movq	$0, (%rax)
	subq	%rdi, %rsi
	addq	$8, %rax
	movq	%rdi, -16(%rax)
	addq	%rsi, %r8
	cmpq	%rax, %r9
	jne	.L6
	.p2align 4,,10
	.p2align 3
.L2:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	addq	$800032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L9:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L2
.L15:
	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:
```

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.
Optimized Assembly Code:

user
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798752
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1312, %rsp
	.cfi_def_cfa_offset 800064
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %eax
	testl	%eax, %eax
	jle	.L9
	leaq	16(%rsp), %rbp
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %edx
	addq	$8, %rbp
	cmpl	%ebx, %edx
	jg	.L3
	cmpl	$1, %edx
	jle	.L9
	subl	$2, %edx
	movq	8(%rsp), %rdi
	leaq	24(%rsp), %rax
	xorl	%r8d, %r8d
	leaq	32(%rsp,%rdx,8), %r9
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%r10, (%rax)
	subq	%r10, %rcx
	addq	%rcx, %r8
.L4:
	addq	$8, %rax
	cmpq	%rax, %r9
	je	.L2
.L6:
	movq	-8(%rax), %rdx
	movq	(%rax), %rcx
	leaq	(%rdx,%rcx), %rsi
	cmpq	%rdi, %rsi
	jle	.L4
	movq	%rdi, %r10
	subq	%rdx, %r10
	jns	.L14
	movq	$0, (%rax)
	subq	%rdi, %rsi
	addq	$8, %rax
	movq	%rdi, -16(%rax)
	addq	%rsi, %r8
	cmpq	%rax, %r9
	jne	.L6
	.p2align 4,,10
	.p2align 3
.L2:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	addq	$800032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L9:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L2
.L15:
	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
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798752
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1312, %rsp
	.cfi_def_cfa_offset 800064
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %eax
	testl	%eax, %eax
	jle	.L9
	leaq	16(%rsp), %rbp
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %edx
	addq	$8, %rbp
	cmpl	%ebx, %edx
	jg	.L3
	cmpl	$1, %edx
	jle	.L9
	subl	$2, %edx
	movq	8(%rsp), %rdi
	leaq	24(%rsp), %rax
	xorl	%r8d, %r8d
	leaq	32(%rsp,%rdx,8), %r9
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%r10, (%rax)
	subq	%r10, %rcx
	addq	%rcx, %r8
.L4:
	addq	$8, %rax
	cmpq	%rax, %r9
	je	.L2
.L6:
	movq	-8(%rax), %rdx
	movq	(%rax), %rcx
	leaq	(%rdx,%rcx), %rsi
	cmpq	%rdi, %rsi
	jle	.L4
	movq	%rdi, %r10
	subq	%rdx, %r10
	jns	.L14
	movq	$0, (%rax)
	subq	%rdi, %rsi
	addq	$8, %rax
	movq	%rdi, -16(%rax)
	addq	%rsi, %r8
	cmpq	%rax, %r9
	jne	.L6
	.p2align 4,,10
	.p2align 3
.L2:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	addq	$800032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L9:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L2
.L15:
	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:
```
```c
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,i;
	long a[100000],x;
	long long ans=0;
	scanf("%d%ld",&n,&x);
	for(i=0;i<n;i++)scanf("%ld",&a[i]);
	for(i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			if(x-a[i]>=0){
				ans+=(a[i+1]-(x-a[i]));
				a[i+1]=x-a[i];
			}
			else {
				ans+=(a[i+1]+a[i]-x);
				a[i+1]=0;
				a[i]=x;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}```
Given the following C code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,i;
	long a[100000],x;
	long long ans=0;
	scanf("%d%ld",&n,&x);
	for(i=0;i<n;i++)scanf("%ld",&a[i]);
	for(i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			if(x-a[i]>=0){
				ans+=(a[i+1]-(x-a[i]));
				a[i+1]=x-a[i];
			}
			else {
				ans+=(a[i+1]+a[i]-x);
				a[i+1]=0;
				a[i]=x;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}```

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.
Optimized Assembly Code:

3 3
2 2 2

1

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

```c
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,i;
	long a[100000],x;
	long long ans=0;
	scanf("%d%ld",&n,&x);
	for(i=0;i<n;i++)scanf("%ld",&a[i]);
	for(i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			if(x-a[i]>=0){
				ans+=(a[i+1]-(x-a[i]));
				a[i+1]=x-a[i];
			}
			else {
				ans+=(a[i+1]+a[i]-x);
				a[i+1]=0;
				a[i]=x;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798752
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1312, %rsp
	.cfi_def_cfa_offset 800064
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %eax
	testl	%eax, %eax
	jle	.L9
	leaq	16(%rsp), %rbp
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %edx
	addq	$8, %rbp
	cmpl	%ebx, %edx
	jg	.L3
	cmpl	$1, %edx
	jle	.L9
	subl	$2, %edx
	movq	8(%rsp), %rdi
	leaq	24(%rsp), %rax
	xorl	%r8d, %r8d
	leaq	32(%rsp,%rdx,8), %r9
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%r10, (%rax)
	subq	%r10, %rcx
	addq	%rcx, %r8
.L4:
	addq	$8, %rax
	cmpq	%rax, %r9
	je	.L2
.L6:
	movq	-8(%rax), %rdx
	movq	(%rax), %rcx
	leaq	(%rdx,%rcx), %rsi
	cmpq	%rdi, %rsi
	jle	.L4
	movq	%rdi, %r10
	subq	%rdx, %r10
	jns	.L14
	movq	$0, (%rax)
	subq	%rdi, %rsi
	addq	$8, %rax
	movq	%rdi, -16(%rax)
	addq	%rsi, %r8
	cmpq	%rax, %r9
	jne	.L6
	.p2align 4,,10
	.p2align 3
.L2:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	addq	$800032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L9:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L2
.L15:
	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:
```

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.
Optimized Assembly Code:

train
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%ld"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798752
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1312, %rsp
	.cfi_def_cfa_offset 800064
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdx
	leaq	4(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %eax
	testl	%eax, %eax
	jle	.L9
	leaq	16(%rsp), %rbp
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %edx
	addq	$8, %rbp
	cmpl	%ebx, %edx
	jg	.L3
	cmpl	$1, %edx
	jle	.L9
	subl	$2, %edx
	movq	8(%rsp), %rdi
	leaq	24(%rsp), %rax
	xorl	%r8d, %r8d
	leaq	32(%rsp,%rdx,8), %r9
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L14:
	movq	%r10, (%rax)
	subq	%r10, %rcx
	addq	%rcx, %r8
.L4:
	addq	$8, %rax
	cmpq	%rax, %r9
	je	.L2
.L6:
	movq	-8(%rax), %rdx
	movq	(%rax), %rcx
	leaq	(%rdx,%rcx), %rsi
	cmpq	%rdi, %rsi
	jle	.L4
	movq	%rdi, %r10
	subq	%rdx, %r10
	jns	.L14
	movq	$0, (%rax)
	subq	%rdi, %rsi
	addq	$8, %rax
	movq	%rdi, -16(%rax)
	addq	%rsi, %r8
	cmpq	%rax, %r9
	jne	.L6
	.p2align 4,,10
	.p2align 3
.L2:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	addq	$800032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L9:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L2
.L15:
	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:
```