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) {
  int n,a[100],i,j,count,ans = 0;
  scanf("%d",&n);
  for (i = 0;i < n;i++) {
    scanf("%d",&a[i]);
  }
  for (i = 0;i < n - 1;i++) {
    if (a[i] == a[i + 1]) {
      count = 2;
      for (j = i + 2;j < n;j++) {
        if (a[i] == a[j]) {
          count++;
        } else {
          break;
        }
      }
      ans += count / 2;
      i = j - 1;
    }
  }
  printf("%d\n",ans);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.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	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -420(%rbp)
	leaq	-436(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -432(%rbp)
	jmp	.L2
.L3:
	leaq	-416(%rbp), %rdx
	movl	-432(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -432(%rbp)
.L2:
	movl	-436(%rbp), %eax
	cmpl	%eax, -432(%rbp)
	jl	.L3
	movl	$0, -432(%rbp)
	jmp	.L4
.L11:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %edx
	movl	-432(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jne	.L5
	movl	$2, -424(%rbp)
	movl	-432(%rbp), %eax
	addl	$2, %eax
	movl	%eax, -428(%rbp)
	jmp	.L6
.L10:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %edx
	movl	-428(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jne	.L14
	addl	$1, -424(%rbp)
	addl	$1, -428(%rbp)
.L6:
	movl	-436(%rbp), %eax
	cmpl	%eax, -428(%rbp)
	jl	.L10
	jmp	.L9
.L14:
	nop
.L9:
	movl	-424(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	%eax, -420(%rbp)
	movl	-428(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
.L5:
	addl	$1, -432(%rbp)
.L4:
	movl	-436(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -432(%rbp)
	jl	.L11
	movl	-420(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$432, %rsp
	.cfi_def_cfa_offset 464
	movq	%fs:40, %rax
	movq	%rax, 424(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	leaq	16(%rsp), %rbp
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	addq	$4, %rbp
	cmpl	%ebx, %r8d
	jg	.L3
.L2:
	leal	-1(%r8), %r10d
	xorl	%r11d, %r11d
	testl	%r10d, %r10d
	jle	.L4
	xorl	%edx, %edx
	leaq	16(%rsp), %rbx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%eax, %edx
	cmpl	%edx, %r10d
	jle	.L4
.L8:
	leal	1(%rdx), %eax
	movslq	%edx, %rcx
	movslq	%eax, %rdi
	movl	16(%rsp,%rcx,4), %esi
	cmpl	16(%rsp,%rdi,4), %esi
	jne	.L11
	leal	2(%rdx), %edi
	cmpl	%r8d, %edi
	jge	.L12
	movl	%r8d, %r9d
	leaq	8(%rbx,%rcx,4), %rcx
	movl	$2, %eax
	subl	%edx, %r9d
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L19:
	addl	$1, %eax
	addl	$1, %edi
	addq	$4, %rcx
	cmpl	%eax, %r9d
	je	.L13
.L7:
	cmpl	(%rcx), %esi
	je	.L19
.L13:
	movl	%edi, %edx
.L6:
	sarl	%eax
	addl	%eax, %r11d
	cmpl	%edx, %r10d
	jg	.L8
	.p2align 4,,10
	.p2align 3
.L4:
	xorl	%eax, %eax
	movl	%r11d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	424(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$432, %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
.L12:
	.cfi_restore_state
	movl	%edi, %edx
	movl	$2, %eax
	jmp	.L6
.L20:
	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	"%d"
.LC1:
	.string	"%d\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
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$432, %rsp
	.cfi_def_cfa_offset 464
	movq	%fs:40, %rax
	movq	%rax, 424(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	leaq	16(%rsp), %rbp
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r8d
	addq	$4, %rbp
	cmpl	%ebx, %r8d
	jg	.L3
.L2:
	leal	-1(%r8), %r10d
	xorl	%r11d, %r11d
	testl	%r10d, %r10d
	jle	.L4
	xorl	%edx, %edx
	leaq	16(%rsp), %rbx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%eax, %edx
	cmpl	%edx, %r10d
	jle	.L4
.L8:
	leal	1(%rdx), %eax
	movslq	%edx, %rcx
	movslq	%eax, %rdi
	movl	16(%rsp,%rcx,4), %esi
	cmpl	16(%rsp,%rdi,4), %esi
	jne	.L11
	leal	2(%rdx), %edi
	cmpl	%r8d, %edi
	jge	.L12
	movl	%r8d, %r9d
	leaq	8(%rbx,%rcx,4), %rcx
	movl	$2, %eax
	subl	%edx, %r9d
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L19:
	addl	$1, %eax
	addl	$1, %edi
	addq	$4, %rcx
	cmpl	%eax, %r9d
	je	.L13
.L7:
	cmpl	(%rcx), %esi
	je	.L19
.L13:
	movl	%edi, %edx
.L6:
	sarl	%eax
	addl	%eax, %r11d
	cmpl	%edx, %r10d
	jg	.L8
	.p2align 4,,10
	.p2align 3
.L4:
	xorl	%eax, %eax
	movl	%r11d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	424(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$432, %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
.L12:
	.cfi_restore_state
	movl	%edi, %edx
	movl	$2, %eax
	jmp	.L6
.L20:
	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) {
  int n,a[100],i,j,count,ans = 0;
  scanf("%d",&n);
  for (i = 0;i < n;i++) {
    scanf("%d",&a[i]);
  }
  for (i = 0;i < n - 1;i++) {
    if (a[i] == a[i + 1]) {
      count = 2;
      for (j = i + 2;j < n;j++) {
        if (a[i] == a[j]) {
          count++;
        } else {
          break;
        }
      }
      ans += count / 2;
      i = j - 1;
    }
  }
  printf("%d\n",ans);
}

5
1 1 3 2 2
 3
0 2 1
 14
1 1 2 3 3 3 4 4 4 4 1 2 3 4
 3
1 2 2
 14
1 1 3 3 3 3 4 4 4 4 1 2 3 4
 14
1 1 3 3 3 4 3 4 4 4 1 2 3 4
 5
1 1 1 1 0
 5
1 1 6 2 2
 5
1 2 1 1 0
 5
1 1 9 2 2

2
 0
 4
 1
 5
 3
 2
 2
 1
 2

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) {
  int n,a[100],i,j,count,ans = 0;
  scanf("%d",&n);
  for (i = 0;i < n;i++) {
    scanf("%d",&a[i]);
  }
  for (i = 0;i < n - 1;i++) {
    if (a[i] == a[i + 1]) {
      count = 2;
      for (j = i + 2;j < n;j++) {
        if (a[i] == a[j]) {
          count++;
        } else {
          break;
        }
      }
      ans += count / 2;
      i = j - 1;
    }
  }
  printf("%d\n",ans);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.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	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -420(%rbp)
	leaq	-436(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -432(%rbp)
	jmp	.L2
.L3:
	leaq	-416(%rbp), %rdx
	movl	-432(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -432(%rbp)
.L2:
	movl	-436(%rbp), %eax
	cmpl	%eax, -432(%rbp)
	jl	.L3
	movl	$0, -432(%rbp)
	jmp	.L4
.L11:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %edx
	movl	-432(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jne	.L5
	movl	$2, -424(%rbp)
	movl	-432(%rbp), %eax
	addl	$2, %eax
	movl	%eax, -428(%rbp)
	jmp	.L6
.L10:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %edx
	movl	-428(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jne	.L14
	addl	$1, -424(%rbp)
	addl	$1, -428(%rbp)
.L6:
	movl	-436(%rbp), %eax
	cmpl	%eax, -428(%rbp)
	jl	.L10
	jmp	.L9
.L14:
	nop
.L9:
	movl	-424(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	%eax, -420(%rbp)
	movl	-428(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
.L5:
	addl	$1, -432(%rbp)
.L4:
	movl	-436(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -432(%rbp)
	jl	.L11
	movl	-420(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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	"%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	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -420(%rbp)
	leaq	-436(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -432(%rbp)
	jmp	.L2
.L3:
	leaq	-416(%rbp), %rdx
	movl	-432(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -432(%rbp)
.L2:
	movl	-436(%rbp), %eax
	cmpl	%eax, -432(%rbp)
	jl	.L3
	movl	$0, -432(%rbp)
	jmp	.L4
.L11:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %edx
	movl	-432(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jne	.L5
	movl	$2, -424(%rbp)
	movl	-432(%rbp), %eax
	addl	$2, %eax
	movl	%eax, -428(%rbp)
	jmp	.L6
.L10:
	movl	-432(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %edx
	movl	-428(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jne	.L14
	addl	$1, -424(%rbp)
	addl	$1, -428(%rbp)
.L6:
	movl	-436(%rbp), %eax
	cmpl	%eax, -428(%rbp)
	jl	.L10
	jmp	.L9
.L14:
	nop
.L9:
	movl	-424(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	%eax, -420(%rbp)
	movl	-428(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
.L5:
	addl	$1, -432(%rbp)
.L4:
	movl	-436(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -432(%rbp)
	jl	.L11
	movl	-420(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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:
