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(){
  int n;
  scanf("%d",&n);
  
  int p[n];
  for(int i=0; i<n; i++){
    scanf("%d",&p[i]);
  }
  
  int count = 0;
  for(int j=1; j<n-1; j++){
    if(p[j] != max(p[j-1],p[j],p[j+1]) && p[j] != min(p[j-1],p[j],p[j+1])) count++;
  }
  printf("%d",count);
}

int max(int a, int b, int c){
  int d = a;
  if(d<b) d = b;
  if(d<c) d = c;
  return d;
}

int min(int a, int b, int c){
  int d = a;
  if(d>b) d = b;
  if(d>c) d = c;
  return d;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r12
	pushq	%rbx
	subq	$64, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r12
	leaq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-72(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -56(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, -96(%rbp)
	movq	$0, -88(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %ebx
	movl	$0, %edx
	divq	%rbx
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -68(%rbp)
	jmp	.L5
.L6:
	movl	-68(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -68(%rbp)
.L5:
	movl	-72(%rbp), %eax
	cmpl	%eax, -68(%rbp)
	jl	.L6
	movl	$0, -64(%rbp)
	movl	$1, -60(%rbp)
	jmp	.L7
.L9:
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movq	-48(%rbp), %rax
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %ecx
	movslq	%ecx, %rcx
	movl	(%rax,%rcx,4), %ecx
	movl	-60(%rbp), %eax
	leal	-1(%rax), %esi
	movq	-48(%rbp), %rax
	movslq	%esi, %rsi
	movl	(%rax,%rsi,4), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	max
	cmpl	%eax, %ebx
	je	.L8
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movq	-48(%rbp), %rax
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %ecx
	movslq	%ecx, %rcx
	movl	(%rax,%rcx,4), %ecx
	movl	-60(%rbp), %eax
	leal	-1(%rax), %esi
	movq	-48(%rbp), %rax
	movslq	%esi, %rsi
	movl	(%rax,%rsi,4), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	min
	cmpl	%eax, %ebx
	je	.L8
	addl	$1, -64(%rbp)
.L8:
	addl	$1, -60(%rbp)
.L7:
	movl	-72(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -60(%rbp)
	jl	.L9
	movl	-64(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	%r12, %rsp
	movl	$0, %eax
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	max
	.type	max, @function
max:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jge	.L13
	movl	-24(%rbp), %eax
	movl	%eax, -4(%rbp)
.L13:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jge	.L14
	movl	-28(%rbp), %eax
	movl	%eax, -4(%rbp)
.L14:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	max, .-max
	.globl	min
	.type	min, @function
min:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L17
	movl	-24(%rbp), %eax
	movl	%eax, -4(%rbp)
.L17:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jle	.L18
	movl	-28(%rbp), %eax
	movl	%eax, -4(%rbp)
.L18:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	min, .-min
	.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"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r14
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %r14
	pushq	%r13
	leaq	-44(%rbp), %rsi
	movq	%r14, %rdi
	pushq	%r12
	pushq	%rbx
	subq	$16, %rsp
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	-44(%rbp), %rax
	movq	%rsp, %rsi
	movq	%rax, %rdx
	leaq	15(,%rax,4), %rax
	movq	%rax, %rcx
	andq	$-4096, %rax
	subq	%rax, %rsi
	andq	$-16, %rcx
	cmpq	%rsi, %rsp
	je	.L3
.L39:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rsi, %rsp
	jne	.L39
.L3:
	andl	$4095, %ecx
	subq	%rcx, %rsp
	testq	%rcx, %rcx
	jne	.L40
.L4:
	movq	%rsp, %r13
	testl	%edx, %edx
	jle	.L5
	movq	%r13, %r12
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %edx
	addq	$4, %r12
	cmpl	%ebx, %edx
	jg	.L6
.L5:
	leal	-1(%rdx), %r9d
	cmpl	$1, %r9d
	jle	.L23
	leal	-3(%rdx), %r10d
	leal	-2(%rdx), %edi
	cmpl	$2, %r10d
	jbe	.L24
	movl	%edi, %ecx
	leaq	4(%r13), %rax
	pxor	%xmm4, %xmm4
	shrl	$2, %ecx
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	20(%r13,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L9:
	movdqu	4(%rax), %xmm3
	movdqu	-4(%rax), %xmm2
	addq	$16, %rax
	movdqu	-16(%rax), %xmm6
	movdqa	%xmm3, %xmm0
	movdqa	%xmm3, %xmm5
	pcmpgtd	%xmm2, %xmm0
	movdqa	%xmm0, %xmm1
	pand	%xmm0, %xmm5
	pandn	%xmm2, %xmm1
	pand	%xmm0, %xmm2
	pandn	%xmm3, %xmm0
	por	%xmm2, %xmm0
	por	%xmm5, %xmm1
	movdqa	%xmm6, %xmm2
	pcmpgtd	%xmm6, %xmm1
	pcmpgtd	%xmm0, %xmm2
	pand	%xmm2, %xmm1
	psubd	%xmm1, %xmm4
	cmpq	%rcx, %rax
	jne	.L9
	movdqa	%xmm4, %xmm0
	movl	%edi, %eax
	psrldq	$8, %xmm0
	andl	$-4, %eax
	paddd	%xmm0, %xmm4
	leal	1(%rax), %esi
	movdqa	%xmm4, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm4
	movd	%xmm4, %r8d
	cmpl	%eax, %edi
	je	.L7
.L8:
	movslq	%esi, %rdi
	leal	1(%rsi), %ecx
	leaq	0(,%rdi,4), %rax
	leaq	-4(%r13,%rax), %r11
	addq	%r13, %rax
	cmpl	%r10d, %ecx
	jge	.L12
	cmpl	$-2147483645, %edx
	jl	.L12
	leal	3(%rsi), %edi
	movl	(%r11), %edx
	movl	(%rax), %eax
	movslq	%edi, %rdi
.L17:
	movl	-8(%r13,%rdi,4), %ecx
	cmpl	%ecx, %edx
	movl	%ecx, %esi
	cmovge	%edx, %esi
	cmpl	%eax, %esi
	jle	.L14
	cmpl	%ecx, %edx
	cmovg	%ecx, %edx
	cmpl	%eax, %edx
	jge	.L14
	addl	$1, %r8d
.L14:
	movl	-4(%r13,%rdi,4), %edx
	cmpl	%edx, %eax
	movl	%edx, %esi
	cmovge	%eax, %esi
	cmpl	%esi, %ecx
	jge	.L15
	cmpl	%edx, %eax
	cmovg	%edx, %eax
	cmpl	%eax, %ecx
	jle	.L15
	addl	$1, %r8d
.L15:
	movl	0(%r13,%rdi,4), %eax
	movl	%edi, %esi
	cmpl	%eax, %ecx
	movl	%eax, %r11d
	cmovge	%ecx, %r11d
	cmpl	%r11d, %edx
	jge	.L16
	cmpl	%eax, %ecx
	cmovg	%eax, %ecx
	cmpl	%ecx, %edx
	jle	.L16
	addl	$1, %r8d
.L16:
	addq	$3, %rdi
	leal	-2(%rdi), %ecx
	cmpl	%r10d, %ecx
	jl	.L17
	movslq	%esi, %rdi
	leal	1(%rsi), %ecx
.L12:
	leaq	0(%r13,%rdi,4), %r11
	movl	4(%r11), %r10d
	movl	-4(%r11), %edx
	movl	(%r11), %eax
	cmpl	%r10d, %edx
	movl	%r10d, %edi
	cmovge	%edx, %edi
	cmpl	%eax, %edi
	jle	.L18
	cmpl	%r10d, %edx
	cmovg	%r10d, %edx
	cmpl	%eax, %edx
	jge	.L18
	addl	$1, %r8d
.L18:
	cmpl	%ecx, %r9d
	jle	.L7
	movl	8(%r11), %edx
	addl	$2, %esi
	movl	%edx, %ecx
	cmpl	%edx, %eax
	cmovge	%eax, %ecx
	cmpl	%ecx, %r10d
	jge	.L19
	cmpl	%edx, %eax
	cmovg	%edx, %eax
	cmpl	%eax, %r10d
	jle	.L19
	addl	$1, %r8d
.L19:
	cmpl	%esi, %r9d
	jle	.L7
	movl	12(%r11), %eax
	movl	%r10d, %ecx
	cmpl	%r10d, %eax
	cmovge	%eax, %ecx
	cmpl	%edx, %ecx
	jle	.L7
	cmpl	%r10d, %eax
	cmovg	%r10d, %eax
	cmpl	%edx, %eax
	jge	.L7
	addl	$1, %r8d
.L7:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movq	%r14, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	-40(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L41
	leaq	-32(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L40:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rcx)
	jmp	.L4
.L23:
	xorl	%r8d, %r8d
	jmp	.L7
.L24:
	movl	$1, %esi
	xorl	%r8d, %r8d
	jmp	.L8
.L41:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	max
	.type	max, @function
max:
.LFB24:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	movl	%edi, %eax
	cmovl	%edx, %esi
	cmpl	%edi, %esi
	cmovge	%esi, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	max, .-max
	.p2align 4
	.globl	min
	.type	min, @function
min:
.LFB25:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	movl	%edi, %eax
	cmovg	%edx, %esi
	cmpl	%edi, %esi
	cmovle	%esi, %eax
	ret
	.cfi_endproc
.LFE25:
	.size	min, .-min
	.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"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r14
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %r14
	pushq	%r13
	leaq	-44(%rbp), %rsi
	movq	%r14, %rdi
	pushq	%r12
	pushq	%rbx
	subq	$16, %rsp
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	-44(%rbp), %rax
	movq	%rsp, %rsi
	movq	%rax, %rdx
	leaq	15(,%rax,4), %rax
	movq	%rax, %rcx
	andq	$-4096, %rax
	subq	%rax, %rsi
	andq	$-16, %rcx
	cmpq	%rsi, %rsp
	je	.L3
.L39:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rsi, %rsp
	jne	.L39
.L3:
	andl	$4095, %ecx
	subq	%rcx, %rsp
	testq	%rcx, %rcx
	jne	.L40
.L4:
	movq	%rsp, %r13
	testl	%edx, %edx
	jle	.L5
	movq	%r13, %r12
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	-44(%rbp), %edx
	addq	$4, %r12
	cmpl	%ebx, %edx
	jg	.L6
.L5:
	leal	-1(%rdx), %r9d
	cmpl	$1, %r9d
	jle	.L23
	leal	-3(%rdx), %r10d
	leal	-2(%rdx), %edi
	cmpl	$2, %r10d
	jbe	.L24
	movl	%edi, %ecx
	leaq	4(%r13), %rax
	pxor	%xmm4, %xmm4
	shrl	$2, %ecx
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	20(%r13,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L9:
	movdqu	4(%rax), %xmm3
	movdqu	-4(%rax), %xmm2
	addq	$16, %rax
	movdqu	-16(%rax), %xmm6
	movdqa	%xmm3, %xmm0
	movdqa	%xmm3, %xmm5
	pcmpgtd	%xmm2, %xmm0
	movdqa	%xmm0, %xmm1
	pand	%xmm0, %xmm5
	pandn	%xmm2, %xmm1
	pand	%xmm0, %xmm2
	pandn	%xmm3, %xmm0
	por	%xmm2, %xmm0
	por	%xmm5, %xmm1
	movdqa	%xmm6, %xmm2
	pcmpgtd	%xmm6, %xmm1
	pcmpgtd	%xmm0, %xmm2
	pand	%xmm2, %xmm1
	psubd	%xmm1, %xmm4
	cmpq	%rcx, %rax
	jne	.L9
	movdqa	%xmm4, %xmm0
	movl	%edi, %eax
	psrldq	$8, %xmm0
	andl	$-4, %eax
	paddd	%xmm0, %xmm4
	leal	1(%rax), %esi
	movdqa	%xmm4, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm4
	movd	%xmm4, %r8d
	cmpl	%eax, %edi
	je	.L7
.L8:
	movslq	%esi, %rdi
	leal	1(%rsi), %ecx
	leaq	0(,%rdi,4), %rax
	leaq	-4(%r13,%rax), %r11
	addq	%r13, %rax
	cmpl	%r10d, %ecx
	jge	.L12
	cmpl	$-2147483645, %edx
	jl	.L12
	leal	3(%rsi), %edi
	movl	(%r11), %edx
	movl	(%rax), %eax
	movslq	%edi, %rdi
.L17:
	movl	-8(%r13,%rdi,4), %ecx
	cmpl	%ecx, %edx
	movl	%ecx, %esi
	cmovge	%edx, %esi
	cmpl	%eax, %esi
	jle	.L14
	cmpl	%ecx, %edx
	cmovg	%ecx, %edx
	cmpl	%eax, %edx
	jge	.L14
	addl	$1, %r8d
.L14:
	movl	-4(%r13,%rdi,4), %edx
	cmpl	%edx, %eax
	movl	%edx, %esi
	cmovge	%eax, %esi
	cmpl	%esi, %ecx
	jge	.L15
	cmpl	%edx, %eax
	cmovg	%edx, %eax
	cmpl	%eax, %ecx
	jle	.L15
	addl	$1, %r8d
.L15:
	movl	0(%r13,%rdi,4), %eax
	movl	%edi, %esi
	cmpl	%eax, %ecx
	movl	%eax, %r11d
	cmovge	%ecx, %r11d
	cmpl	%r11d, %edx
	jge	.L16
	cmpl	%eax, %ecx
	cmovg	%eax, %ecx
	cmpl	%ecx, %edx
	jle	.L16
	addl	$1, %r8d
.L16:
	addq	$3, %rdi
	leal	-2(%rdi), %ecx
	cmpl	%r10d, %ecx
	jl	.L17
	movslq	%esi, %rdi
	leal	1(%rsi), %ecx
.L12:
	leaq	0(%r13,%rdi,4), %r11
	movl	4(%r11), %r10d
	movl	-4(%r11), %edx
	movl	(%r11), %eax
	cmpl	%r10d, %edx
	movl	%r10d, %edi
	cmovge	%edx, %edi
	cmpl	%eax, %edi
	jle	.L18
	cmpl	%r10d, %edx
	cmovg	%r10d, %edx
	cmpl	%eax, %edx
	jge	.L18
	addl	$1, %r8d
.L18:
	cmpl	%ecx, %r9d
	jle	.L7
	movl	8(%r11), %edx
	addl	$2, %esi
	movl	%edx, %ecx
	cmpl	%edx, %eax
	cmovge	%eax, %ecx
	cmpl	%ecx, %r10d
	jge	.L19
	cmpl	%edx, %eax
	cmovg	%edx, %eax
	cmpl	%eax, %r10d
	jle	.L19
	addl	$1, %r8d
.L19:
	cmpl	%esi, %r9d
	jle	.L7
	movl	12(%r11), %eax
	movl	%r10d, %ecx
	cmpl	%r10d, %eax
	cmovge	%eax, %ecx
	cmpl	%edx, %ecx
	jle	.L7
	cmpl	%r10d, %eax
	cmovg	%r10d, %eax
	cmpl	%edx, %eax
	jge	.L7
	addl	$1, %r8d
.L7:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movq	%r14, %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	-40(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L41
	leaq	-32(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L40:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rcx)
	jmp	.L4
.L23:
	xorl	%r8d, %r8d
	jmp	.L7
.L24:
	movl	$1, %esi
	xorl	%r8d, %r8d
	jmp	.L8
.L41:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	max
	.type	max, @function
max:
.LFB24:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	movl	%edi, %eax
	cmovl	%edx, %esi
	cmpl	%edi, %esi
	cmovge	%esi, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	max, .-max
	.p2align 4
	.globl	min
	.type	min, @function
min:
.LFB25:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	movl	%edi, %eax
	cmovg	%edx, %esi
	cmpl	%edi, %esi
	cmovle	%esi, %eax
	ret
	.cfi_endproc
.LFE25:
	.size	min, .-min
	.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(){
  int n;
  scanf("%d",&n);
  
  int p[n];
  for(int i=0; i<n; i++){
    scanf("%d",&p[i]);
  }
  
  int count = 0;
  for(int j=1; j<n-1; j++){
    if(p[j] != max(p[j-1],p[j],p[j+1]) && p[j] != min(p[j-1],p[j],p[j+1])) count++;
  }
  printf("%d",count);
}

int max(int a, int b, int c){
  int d = a;
  if(d<b) d = b;
  if(d<c) d = c;
  return d;
}

int min(int a, int b, int c){
  int d = a;
  if(d>b) d = b;
  if(d>c) d = c;
  return d;
}
9
9 6 3 2 5 14 7 4 1
 5
2 3 5 4 2
 9
14 17 3 4 5 25 7 4 0
 5
2 1 5 4 2
 9
14 12 3 2 9 14 1 4 0
 5
2 6 4 8 3
 9
14 6 3 2 5 14 7 4 1
 9
14 6 3 2 5 14 7 4 0
 9
14 12 3 2 5 14 7 4 0
 9
14 12 3 2 5 14 7 4 -1

5 2 4 1 3 0 5 5 5 5
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(){
  int n;
  scanf("%d",&n);
  
  int p[n];
  for(int i=0; i<n; i++){
    scanf("%d",&p[i]);
  }
  
  int count = 0;
  for(int j=1; j<n-1; j++){
    if(p[j] != max(p[j-1],p[j],p[j+1]) && p[j] != min(p[j-1],p[j],p[j+1])) count++;
  }
  printf("%d",count);
}

int max(int a, int b, int c){
  int d = a;
  if(d<b) d = b;
  if(d<c) d = c;
  return d;
}

int min(int a, int b, int c){
  int d = a;
  if(d>b) d = b;
  if(d>c) d = c;
  return d;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r12
	pushq	%rbx
	subq	$64, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r12
	leaq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-72(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -56(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, -96(%rbp)
	movq	$0, -88(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %ebx
	movl	$0, %edx
	divq	%rbx
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -68(%rbp)
	jmp	.L5
.L6:
	movl	-68(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -68(%rbp)
.L5:
	movl	-72(%rbp), %eax
	cmpl	%eax, -68(%rbp)
	jl	.L6
	movl	$0, -64(%rbp)
	movl	$1, -60(%rbp)
	jmp	.L7
.L9:
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movq	-48(%rbp), %rax
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %ecx
	movslq	%ecx, %rcx
	movl	(%rax,%rcx,4), %ecx
	movl	-60(%rbp), %eax
	leal	-1(%rax), %esi
	movq	-48(%rbp), %rax
	movslq	%esi, %rsi
	movl	(%rax,%rsi,4), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	max
	cmpl	%eax, %ebx
	je	.L8
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movq	-48(%rbp), %rax
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %ecx
	movslq	%ecx, %rcx
	movl	(%rax,%rcx,4), %ecx
	movl	-60(%rbp), %eax
	leal	-1(%rax), %esi
	movq	-48(%rbp), %rax
	movslq	%esi, %rsi
	movl	(%rax,%rsi,4), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	min
	cmpl	%eax, %ebx
	je	.L8
	addl	$1, -64(%rbp)
.L8:
	addl	$1, -60(%rbp)
.L7:
	movl	-72(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -60(%rbp)
	jl	.L9
	movl	-64(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	%r12, %rsp
	movl	$0, %eax
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	max
	.type	max, @function
max:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jge	.L13
	movl	-24(%rbp), %eax
	movl	%eax, -4(%rbp)
.L13:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jge	.L14
	movl	-28(%rbp), %eax
	movl	%eax, -4(%rbp)
.L14:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	max, .-max
	.globl	min
	.type	min, @function
min:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L17
	movl	-24(%rbp), %eax
	movl	%eax, -4(%rbp)
.L17:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jle	.L18
	movl	-28(%rbp), %eax
	movl	%eax, -4(%rbp)
.L18:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	min, .-min
	.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"
	.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
	pushq	%r15
	pushq	%r14
	pushq	%r12
	pushq	%rbx
	subq	$64, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r12
	leaq	-72(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-72(%rbp), %eax
	movslq	%eax, %rdx
	subq	$1, %rdx
	movq	%rdx, -56(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, -96(%rbp)
	movq	$0, -88(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %ebx
	movl	$0, %edx
	divq	%rbx
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L2:
	cmpq	%rdx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L4
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -68(%rbp)
	jmp	.L5
.L6:
	movl	-68(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -68(%rbp)
.L5:
	movl	-72(%rbp), %eax
	cmpl	%eax, -68(%rbp)
	jl	.L6
	movl	$0, -64(%rbp)
	movl	$1, -60(%rbp)
	jmp	.L7
.L9:
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movq	-48(%rbp), %rax
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %ecx
	movslq	%ecx, %rcx
	movl	(%rax,%rcx,4), %ecx
	movl	-60(%rbp), %eax
	leal	-1(%rax), %esi
	movq	-48(%rbp), %rax
	movslq	%esi, %rsi
	movl	(%rax,%rsi,4), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	max
	cmpl	%eax, %ebx
	je	.L8
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %ebx
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movq	-48(%rbp), %rax
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-48(%rbp), %rax
	movl	-60(%rbp), %ecx
	movslq	%ecx, %rcx
	movl	(%rax,%rcx,4), %ecx
	movl	-60(%rbp), %eax
	leal	-1(%rax), %esi
	movq	-48(%rbp), %rax
	movslq	%esi, %rsi
	movl	(%rax,%rsi,4), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	movl	$0, %eax
	call	min
	cmpl	%eax, %ebx
	je	.L8
	addl	$1, -64(%rbp)
.L8:
	addl	$1, -60(%rbp)
.L7:
	movl	-72(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -60(%rbp)
	jl	.L9
	movl	-64(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	%r12, %rsp
	movl	$0, %eax
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	max
	.type	max, @function
max:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jge	.L13
	movl	-24(%rbp), %eax
	movl	%eax, -4(%rbp)
.L13:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jge	.L14
	movl	-28(%rbp), %eax
	movl	%eax, -4(%rbp)
.L14:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	max, .-max
	.globl	min
	.type	min, @function
min:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jle	.L17
	movl	-24(%rbp), %eax
	movl	%eax, -4(%rbp)
.L17:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jle	.L18
	movl	-28(%rbp), %eax
	movl	%eax, -4(%rbp)
.L18:
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	min, .-min
	.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:
