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

```c
a,b,c,d,s,x,y;main(n){for(scanf("%d",&n);d<n;){
scanf("%d",&x);
if(x==y)a=b,b=c,c=d;
else y=x;
if(s<++d-a)s=d-a;
}s=!printf("%d\n",s);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.globl	y
	.align 4
	.type	y, @object
	.size	y, 4
y:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	jmp	.L2
.L5:
	leaq	x(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	x(%rip), %edx
	movl	y(%rip), %eax
	cmpl	%eax, %edx
	jne	.L3
	movl	b(%rip), %eax
	movl	%eax, a(%rip)
	movl	c(%rip), %eax
	movl	%eax, b(%rip)
	movl	d(%rip), %eax
	movl	%eax, c(%rip)
	jmp	.L4
.L3:
	movl	x(%rip), %eax
	movl	%eax, y(%rip)
.L4:
	movl	d(%rip), %eax
	addl	$1, %eax
	movl	%eax, d(%rip)
	movl	d(%rip), %eax
	movl	a(%rip), %ecx
	subl	%ecx, %eax
	movl	%eax, %edx
	movl	s(%rip), %eax
	cmpl	%eax, %edx
	jle	.L2
	movl	d(%rip), %eax
	movl	a(%rip), %edx
	subl	%edx, %eax
	movl	%eax, s(%rip)
.L2:
	movl	d(%rip), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L5
	movl	s(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, s(%rip)
	movl	$0, %eax
	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	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%eax, %eax
	leaq	x(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edi, 12(%rsp)
	leaq	12(%rsp), %rsi
	movq	%rbx, %rdi
	call	scanf@PLT
	movl	d(%rip), %eax
	.p2align 4,,10
	.p2align 3
.L6:
	cmpl	%eax, 12(%rsp)
	jle	.L10
.L7:
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	scanf@PLT
	movl	x(%rip), %eax
	cmpl	y(%rip), %eax
	je	.L11
	movl	%eax, y(%rip)
	movl	d(%rip), %eax
	addl	$1, %eax
	movl	%eax, %edx
	subl	a(%rip), %edx
	cmpl	s(%rip), %edx
	movl	%eax, d(%rip)
	jle	.L6
.L4:
	movl	%edx, s(%rip)
	cmpl	%eax, 12(%rsp)
	jg	.L7
.L10:
	movl	s(%rip), %esi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, s(%rip)
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	movl	c(%rip), %eax
	movl	b(%rip), %ecx
	movl	%eax, b(%rip)
	movl	d(%rip), %eax
	movl	%ecx, a(%rip)
	movl	%eax, c(%rip)
	addl	$1, %eax
	movl	%eax, %edx
	movl	%eax, d(%rip)
	subl	%ecx, %edx
	cmpl	s(%rip), %edx
	jle	.L6
	jmp	.L4
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	y
	.bss
	.align 4
	.type	y, @object
	.size	y, 4
y:
	.zero	4
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.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	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%eax, %eax
	leaq	x(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edi, 12(%rsp)
	leaq	12(%rsp), %rsi
	movq	%rbx, %rdi
	call	scanf@PLT
	movl	d(%rip), %eax
	.p2align 4,,10
	.p2align 3
.L6:
	cmpl	%eax, 12(%rsp)
	jle	.L10
.L7:
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	scanf@PLT
	movl	x(%rip), %eax
	cmpl	y(%rip), %eax
	je	.L11
	movl	%eax, y(%rip)
	movl	d(%rip), %eax
	addl	$1, %eax
	movl	%eax, %edx
	subl	a(%rip), %edx
	cmpl	s(%rip), %edx
	movl	%eax, d(%rip)
	jle	.L6
.L4:
	movl	%edx, s(%rip)
	cmpl	%eax, 12(%rsp)
	jg	.L7
.L10:
	movl	s(%rip), %esi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, s(%rip)
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	movl	c(%rip), %eax
	movl	b(%rip), %ecx
	movl	%eax, b(%rip)
	movl	d(%rip), %eax
	movl	%ecx, a(%rip)
	movl	%eax, c(%rip)
	addl	$1, %eax
	movl	%eax, %edx
	movl	%eax, d(%rip)
	subl	%ecx, %edx
	cmpl	s(%rip), %edx
	jle	.L6
	jmp	.L4
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	y
	.bss
	.align 4
	.type	y, @object
	.size	y, 4
y:
	.zero	4
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.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:

a,b,c,d,s,x,y;main(n){for(scanf("%d",&n);d<n;){
scanf("%d",&x);
if(x==y)a=b,b=c,c=d;
else y=x;
if(s<++d-a)s=d-a;
}s=!printf("%d\n",s);}
10
1 1 0 0 0 0 1 1 1 0
 10
1 1 0 0 0 0 1 1 1 1
 10
1 1 0 0 0 0 1 2 1 1
 10
1 1 0 0 -1 0 1 2 1 1
 10
1 1 0 0 -1 1 1 2 1 1
 10
1 1 0 0 -1 2 1 2 1 2
 10
-1 1 1 1 1 -1 -21 1 1 15
 10
1 1 0 0 -1 1 1 2 1 2
 10
1 1 0 0 -1 2 1 4 1 2
 10
0 1 0 0 -1 2 1 4 1 2

5
 4
 6
 9
 8
 10
 7
 9
 10
 10

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

```c
a,b,c,d,s,x,y;main(n){for(scanf("%d",&n);d<n;){
scanf("%d",&x);
if(x==y)a=b,b=c,c=d;
else y=x;
if(s<++d-a)s=d-a;
}s=!printf("%d\n",s);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.globl	y
	.align 4
	.type	y, @object
	.size	y, 4
y:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	jmp	.L2
.L5:
	leaq	x(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	x(%rip), %edx
	movl	y(%rip), %eax
	cmpl	%eax, %edx
	jne	.L3
	movl	b(%rip), %eax
	movl	%eax, a(%rip)
	movl	c(%rip), %eax
	movl	%eax, b(%rip)
	movl	d(%rip), %eax
	movl	%eax, c(%rip)
	jmp	.L4
.L3:
	movl	x(%rip), %eax
	movl	%eax, y(%rip)
.L4:
	movl	d(%rip), %eax
	addl	$1, %eax
	movl	%eax, d(%rip)
	movl	d(%rip), %eax
	movl	a(%rip), %ecx
	subl	%ecx, %eax
	movl	%eax, %edx
	movl	s(%rip), %eax
	cmpl	%eax, %edx
	jle	.L2
	movl	d(%rip), %eax
	movl	a(%rip), %edx
	subl	%edx, %eax
	movl	%eax, s(%rip)
.L2:
	movl	d(%rip), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L5
	movl	s(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, s(%rip)
	movl	$0, %eax
	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
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	c
	.align 4
	.type	c, @object
	.size	c, 4
c:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.globl	y
	.align 4
	.type	y, @object
	.size	y, 4
y:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	jmp	.L2
.L5:
	leaq	x(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	x(%rip), %edx
	movl	y(%rip), %eax
	cmpl	%eax, %edx
	jne	.L3
	movl	b(%rip), %eax
	movl	%eax, a(%rip)
	movl	c(%rip), %eax
	movl	%eax, b(%rip)
	movl	d(%rip), %eax
	movl	%eax, c(%rip)
	jmp	.L4
.L3:
	movl	x(%rip), %eax
	movl	%eax, y(%rip)
.L4:
	movl	d(%rip), %eax
	addl	$1, %eax
	movl	%eax, d(%rip)
	movl	d(%rip), %eax
	movl	a(%rip), %ecx
	subl	%ecx, %eax
	movl	%eax, %edx
	movl	s(%rip), %eax
	cmpl	%eax, %edx
	jle	.L2
	movl	d(%rip), %eax
	movl	a(%rip), %edx
	subl	%edx, %eax
	movl	%eax, s(%rip)
.L2:
	movl	d(%rip), %edx
	movl	-4(%rbp), %eax
	cmpl	%eax, %edx
	jl	.L5
	movl	s(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, s(%rip)
	movl	$0, %eax
	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:
