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,friend[100010]={0},a,b,i,ans;
	scanf("%d",&N);
	
	for(i=1;i<=N;i++){
		scanf("%d %d",&a,&b);
		friend[a]+=1;
		friend[b+1]-=1;
	}
	
	for(i=0;i<=N+1;i++){
		friend[i]+=friend[i-1];	
		if(i-1<=friend[i])
			ans=i-1;
	}
	
	printf("%d\n",ans);
	
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.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
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2768, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400048(%rbp), %rax
	movl	$400040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-400068(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -400056(%rbp)
	jmp	.L2
.L3:
	leaq	-400060(%rbp), %rdx
	leaq	-400064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-400064(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	-400064(%rbp), %eax
	addl	$1, %edx
	cltq
	movl	%edx, -400048(%rbp,%rax,4)
	movl	-400060(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	-400060(%rbp), %edx
	leal	1(%rdx), %ecx
	leal	-1(%rax), %edx
	movslq	%ecx, %rax
	movl	%edx, -400048(%rbp,%rax,4)
	addl	$1, -400056(%rbp)
.L2:
	movl	-400068(%rbp), %eax
	cmpl	%eax, -400056(%rbp)
	jle	.L3
	movl	$0, -400056(%rbp)
	jmp	.L4
.L6:
	movl	-400056(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	-400056(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	addl	%eax, %edx
	movl	-400056(%rbp), %eax
	cltq
	movl	%edx, -400048(%rbp,%rax,4)
	movl	-400056(%rbp), %eax
	leal	-1(%rax), %edx
	movl	-400056(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jg	.L5
	movl	-400056(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400052(%rbp)
.L5:
	addl	$1, -400056(%rbp)
.L4:
	movl	-400068(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -400056(%rbp)
	jle	.L6
	movl	-400052(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%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	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d\n"
	.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	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397368
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2760, %rsp
	.cfi_def_cfa_offset 400128
	movl	$400040, %edx
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 400056(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	call	memset@PLT
	leaq	4(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L2
	movl	$1, %r15d
	leaq	12(%rsp), %r14
	leaq	8(%rsp), %r13
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r14, %rdx
	movq	%r13, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	8(%rsp), %rax
	movl	4(%rsp), %ecx
	addl	$1, %r15d
	addl	$1, 16(%rsp,%rax,4)
	movl	12(%rsp), %eax
	addl	$1, %eax
	cltq
	subl	$1, 16(%rsp,%rax,4)
	cmpl	%r15d, %ecx
	jge	.L3
.L2:
	cmpl	$-1, %ecx
	jl	.L4
	movl	12(%rsp), %edx
	movl	$-1, %eax
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%esi, %eax
.L6:
	addl	(%rbx), %edx
	leal	1(%rax), %esi
	cmpl	%eax, %edx
	movl	%edx, (%rbx)
	cmovge	%eax, %r12d
	addq	$4, %rbx
	cmpl	%ecx, %eax
	jne	.L9
.L4:
	xorl	%eax, %eax
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	400056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L13
	addq	$400072, %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
.L13:
	.cfi_restore_state
	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 %d"
.LC2:
	.string	"%d\n"
	.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	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397368
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2760, %rsp
	.cfi_def_cfa_offset 400128
	movl	$400040, %edx
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 400056(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	call	memset@PLT
	leaq	4(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L2
	movl	$1, %r15d
	leaq	12(%rsp), %r14
	leaq	8(%rsp), %r13
	leaq	.LC1(%rip), %rbp
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r14, %rdx
	movq	%r13, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	8(%rsp), %rax
	movl	4(%rsp), %ecx
	addl	$1, %r15d
	addl	$1, 16(%rsp,%rax,4)
	movl	12(%rsp), %eax
	addl	$1, %eax
	cltq
	subl	$1, 16(%rsp,%rax,4)
	cmpl	%r15d, %ecx
	jge	.L3
.L2:
	cmpl	$-1, %ecx
	jl	.L4
	movl	12(%rsp), %edx
	movl	$-1, %eax
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L9:
	movl	%esi, %eax
.L6:
	addl	(%rbx), %edx
	leal	1(%rax), %esi
	cmpl	%eax, %edx
	movl	%edx, (%rbx)
	cmovge	%eax, %r12d
	addq	$4, %rbx
	cmpl	%ecx, %eax
	jne	.L9
.L4:
	xorl	%eax, %eax
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	400056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L13
	addq	$400072, %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
.L13:
	.cfi_restore_state
	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,friend[100010]={0},a,b,i,ans;
	scanf("%d",&N);
	
	for(i=1;i<=N;i++){
		scanf("%d %d",&a,&b);
		friend[a]+=1;
		friend[b+1]-=1;
	}
	
	for(i=0;i<=N+1;i++){
		friend[i]+=friend[i-1];	
		if(i-1<=friend[i])
			ans=i-1;
	}
	
	printf("%d\n",ans);
	
	return 0;
}
5
8 100001
14 100001
12 100001
8 100001
3 100001
 4
2 5
4 7
2 4
5 6
 6
2 9
4 8
6 7
6 6
5 4
2 100001
 4
2 1
4 7
2 4
5 6
 5
8 100001
7 100001
12 100001
3 100001
3 100001
 6
2 9
2 8
6 7
6 6
5 4
2 100001
 6
4 9
2 8
6 7
6 6
5 4
2 100001
 5
6 100001
7 100001
12 100001
8 100001
3 100001
 4
2 2
4 7
2 4
3 6
 4
2 6
4 7
2 4
5 6

0
 3
 5
 1
 2
 5
 5
 0
 3
 3

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,friend[100010]={0},a,b,i,ans;
	scanf("%d",&N);
	
	for(i=1;i<=N;i++){
		scanf("%d %d",&a,&b);
		friend[a]+=1;
		friend[b+1]-=1;
	}
	
	for(i=0;i<=N+1;i++){
		friend[i]+=friend[i-1];	
		if(i-1<=friend[i])
			ans=i-1;
	}
	
	printf("%d\n",ans);
	
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.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
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2768, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400048(%rbp), %rax
	movl	$400040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-400068(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -400056(%rbp)
	jmp	.L2
.L3:
	leaq	-400060(%rbp), %rdx
	leaq	-400064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-400064(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	-400064(%rbp), %eax
	addl	$1, %edx
	cltq
	movl	%edx, -400048(%rbp,%rax,4)
	movl	-400060(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	-400060(%rbp), %edx
	leal	1(%rdx), %ecx
	leal	-1(%rax), %edx
	movslq	%ecx, %rax
	movl	%edx, -400048(%rbp,%rax,4)
	addl	$1, -400056(%rbp)
.L2:
	movl	-400068(%rbp), %eax
	cmpl	%eax, -400056(%rbp)
	jle	.L3
	movl	$0, -400056(%rbp)
	jmp	.L4
.L6:
	movl	-400056(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	-400056(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	addl	%eax, %edx
	movl	-400056(%rbp), %eax
	cltq
	movl	%edx, -400048(%rbp,%rax,4)
	movl	-400056(%rbp), %eax
	leal	-1(%rax), %edx
	movl	-400056(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jg	.L5
	movl	-400056(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400052(%rbp)
.L5:
	addl	$1, -400056(%rbp)
.L4:
	movl	-400068(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -400056(%rbp)
	jle	.L6
	movl	-400052(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%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	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.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
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2768, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400048(%rbp), %rax
	movl	$400040, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-400068(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -400056(%rbp)
	jmp	.L2
.L3:
	leaq	-400060(%rbp), %rdx
	leaq	-400064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-400064(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	-400064(%rbp), %eax
	addl	$1, %edx
	cltq
	movl	%edx, -400048(%rbp,%rax,4)
	movl	-400060(%rbp), %eax
	addl	$1, %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	-400060(%rbp), %edx
	leal	1(%rdx), %ecx
	leal	-1(%rax), %edx
	movslq	%ecx, %rax
	movl	%edx, -400048(%rbp,%rax,4)
	addl	$1, -400056(%rbp)
.L2:
	movl	-400068(%rbp), %eax
	cmpl	%eax, -400056(%rbp)
	jle	.L3
	movl	$0, -400056(%rbp)
	jmp	.L4
.L6:
	movl	-400056(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	-400056(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	addl	%eax, %edx
	movl	-400056(%rbp), %eax
	cltq
	movl	%edx, -400048(%rbp,%rax,4)
	movl	-400056(%rbp), %eax
	leal	-1(%rax), %edx
	movl	-400056(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jg	.L5
	movl	-400056(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -400052(%rbp)
.L5:
	addl	$1, -400056(%rbp)
.L4:
	movl	-400068(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -400056(%rbp)
	jle	.L6
	movl	-400052(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%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:
