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>
#include <stdlib.h>

int main()
{
	long long N;
	scanf("%lld", &N);
	
	long long n;
	for (n = 1; n * n < N; n *= 2);
	if (n * n - N > N - (n-1) * (n-1)) {
		for (n /= 2; n * n < N; n++);
		for (; N % n != 0; n--);
	} else {
		for (; n * n > N; n--);
		for (; N % n != 0; n--);
	}	
	
	printf("%lld\n", n + N / n - 2);
	fflush(stdout);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$1, -16(%rbp)
	jmp	.L2
.L3:
	salq	-16(%rbp)
.L2:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jl	.L3
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	-24(%rbp), %rdx
	subq	%rdx, %rax
	movq	%rax, %rcx
	movq	-24(%rbp), %rax
	movq	-16(%rbp), %rdx
	leaq	-1(%rdx), %rsi
	movq	-16(%rbp), %rdx
	subq	$1, %rdx
	imulq	%rsi, %rdx
	subq	%rdx, %rax
	cmpq	%rax, %rcx
	jle	.L10
	movq	-16(%rbp), %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -16(%rbp)
	jmp	.L5
.L6:
	addq	$1, -16(%rbp)
.L5:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jl	.L6
	jmp	.L7
.L8:
	subq	$1, -16(%rbp)
.L7:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L8
	jmp	.L9
.L11:
	subq	$1, -16(%rbp)
.L10:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jg	.L11
	jmp	.L12
.L13:
	subq	$1, -16(%rbp)
.L12:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L13
.L9:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	subq	$2, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	stdout(%rip), %rax
	movq	%rax, %rdi
	call	fflush@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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	"%lld"
.LC1:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movq	(%rsp), %rsi
	movl	$1, %ecx
	cmpq	$1, %rsi
	jle	.L13
	.p2align 4,,10
	.p2align 3
.L3:
	addq	%rcx, %rcx
	movq	%rcx, %rdx
	imulq	%rcx, %rdx
	cmpq	%rsi, %rdx
	jl	.L3
.L2:
	leaq	-1(%rcx), %rax
	movq	%rsi, %rdi
	subq	%rsi, %rdx
	movq	%rax, %r8
	imulq	%rax, %r8
	subq	%r8, %rdi
	cmpq	%rdi, %rdx
	jg	.L4
	movq	%rcx, %rdx
	imulq	%rcx, %rdx
	cmpq	%rsi, %rdx
	jg	.L5
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L29:
	subq	$1, %rcx
.L6:
	movq	%rsi, %rax
	cqto
	idivq	%rcx
	testq	%rdx, %rdx
	jne	.L29
.L9:
	movq	%rsi, %rax
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	cqto
	idivq	%rcx
	leaq	-2(%rcx,%rax), %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L30
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore_state
	subq	$1, %rax
.L5:
	movq	%rax, %rdx
	movq	%rax, %rcx
	imulq	%rax, %rdx
	cmpq	%rsi, %rdx
	jg	.L31
	jmp	.L6
.L4:
	sarq	%rcx
	movq	%rcx, %rax
	imulq	%rcx, %rax
	cmpq	%rsi, %rax
	jge	.L7
.L8:
	addq	$1, %rcx
	movq	%rcx, %rax
	imulq	%rcx, %rax
	cmpq	%rsi, %rax
	jge	.L7
	addq	$1, %rcx
	movq	%rcx, %rax
	imulq	%rcx, %rax
	cmpq	%rsi, %rax
	jl	.L8
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L32:
	subq	$1, %rcx
.L7:
	movq	%rsi, %rax
	cqto
	idivq	%rcx
	testq	%rdx, %rdx
	jne	.L32
	jmp	.L9
.L13:
	movl	$1, %edx
	jmp	.L2
.L30:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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	"%lld"
.LC1:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movq	(%rsp), %rsi
	movl	$1, %ecx
	cmpq	$1, %rsi
	jle	.L13
	.p2align 4,,10
	.p2align 3
.L3:
	addq	%rcx, %rcx
	movq	%rcx, %rdx
	imulq	%rcx, %rdx
	cmpq	%rsi, %rdx
	jl	.L3
.L2:
	leaq	-1(%rcx), %rax
	movq	%rsi, %rdi
	subq	%rsi, %rdx
	movq	%rax, %r8
	imulq	%rax, %r8
	subq	%r8, %rdi
	cmpq	%rdi, %rdx
	jg	.L4
	movq	%rcx, %rdx
	imulq	%rcx, %rdx
	cmpq	%rsi, %rdx
	jg	.L5
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L29:
	subq	$1, %rcx
.L6:
	movq	%rsi, %rax
	cqto
	idivq	%rcx
	testq	%rdx, %rdx
	jne	.L29
.L9:
	movq	%rsi, %rax
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	cqto
	idivq	%rcx
	leaq	-2(%rcx,%rax), %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L30
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore_state
	subq	$1, %rax
.L5:
	movq	%rax, %rdx
	movq	%rax, %rcx
	imulq	%rax, %rdx
	cmpq	%rsi, %rdx
	jg	.L31
	jmp	.L6
.L4:
	sarq	%rcx
	movq	%rcx, %rax
	imulq	%rcx, %rax
	cmpq	%rsi, %rax
	jge	.L7
.L8:
	addq	$1, %rcx
	movq	%rcx, %rax
	imulq	%rcx, %rax
	cmpq	%rsi, %rax
	jge	.L7
	addq	$1, %rcx
	movq	%rcx, %rax
	imulq	%rcx, %rax
	cmpq	%rsi, %rax
	jl	.L8
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L32:
	subq	$1, %rcx
.L7:
	movq	%rsi, %rax
	cqto
	idivq	%rcx
	testq	%rdx, %rdx
	jne	.L32
	jmp	.L9
.L13:
	movl	$1, %edx
	jmp	.L2
.L30:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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>
#include <stdlib.h>

int main()
{
	long long N;
	scanf("%lld", &N);
	
	long long n;
	for (n = 1; n * n < N; n *= 2);
	if (n * n - N > N - (n-1) * (n-1)) {
		for (n /= 2; n * n < N; n++);
		for (; N % n != 0; n--);
	} else {
		for (; n * n > N; n--);
		for (; N % n != 0; n--);
	}	
	
	printf("%lld\n", n + N / n - 2);
	fflush(stdout);
	return 0;
}
6069423871
 83
 19
 605667865
 72
 33
 927082247
 40
 5
 223605823

23434326
 82
 18
 82100
 15
 12
 61750
 11
 4
 31934

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>
#include <stdlib.h>

int main()
{
	long long N;
	scanf("%lld", &N);
	
	long long n;
	for (n = 1; n * n < N; n *= 2);
	if (n * n - N > N - (n-1) * (n-1)) {
		for (n /= 2; n * n < N; n++);
		for (; N % n != 0; n--);
	} else {
		for (; n * n > N; n--);
		for (; N % n != 0; n--);
	}	
	
	printf("%lld\n", n + N / n - 2);
	fflush(stdout);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$1, -16(%rbp)
	jmp	.L2
.L3:
	salq	-16(%rbp)
.L2:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jl	.L3
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	-24(%rbp), %rdx
	subq	%rdx, %rax
	movq	%rax, %rcx
	movq	-24(%rbp), %rax
	movq	-16(%rbp), %rdx
	leaq	-1(%rdx), %rsi
	movq	-16(%rbp), %rdx
	subq	$1, %rdx
	imulq	%rsi, %rdx
	subq	%rdx, %rax
	cmpq	%rax, %rcx
	jle	.L10
	movq	-16(%rbp), %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -16(%rbp)
	jmp	.L5
.L6:
	addq	$1, -16(%rbp)
.L5:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jl	.L6
	jmp	.L7
.L8:
	subq	$1, -16(%rbp)
.L7:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L8
	jmp	.L9
.L11:
	subq	$1, -16(%rbp)
.L10:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jg	.L11
	jmp	.L12
.L13:
	subq	$1, -16(%rbp)
.L12:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L13
.L9:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	subq	$2, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	stdout(%rip), %rax
	movq	%rax, %rdi
	call	fflush@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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	"%lld"
.LC1:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$1, -16(%rbp)
	jmp	.L2
.L3:
	salq	-16(%rbp)
.L2:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jl	.L3
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	-24(%rbp), %rdx
	subq	%rdx, %rax
	movq	%rax, %rcx
	movq	-24(%rbp), %rax
	movq	-16(%rbp), %rdx
	leaq	-1(%rdx), %rsi
	movq	-16(%rbp), %rdx
	subq	$1, %rdx
	imulq	%rsi, %rdx
	subq	%rdx, %rax
	cmpq	%rax, %rcx
	jle	.L10
	movq	-16(%rbp), %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -16(%rbp)
	jmp	.L5
.L6:
	addq	$1, -16(%rbp)
.L5:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jl	.L6
	jmp	.L7
.L8:
	subq	$1, -16(%rbp)
.L7:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L8
	jmp	.L9
.L11:
	subq	$1, -16(%rbp)
.L10:
	movq	-16(%rbp), %rax
	imulq	%rax, %rax
	movq	%rax, %rdx
	movq	-24(%rbp), %rax
	cmpq	%rax, %rdx
	jg	.L11
	jmp	.L12
.L13:
	subq	$1, -16(%rbp)
.L12:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rdx, %rax
	testq	%rax, %rax
	jne	.L13
.L9:
	movq	-24(%rbp), %rax
	cqto
	idivq	-16(%rbp)
	movq	%rax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	subq	$2, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	stdout(%rip), %rax
	movq	%rax, %rdi
	call	fflush@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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:
