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>

#define MAX 9

int main(void)
{
	int n, cnt, limit;
	int x, y, v;
	int result[MAX][MAX];
	int test_cnt;
	test_cnt = 0;

	while(scanf("%d", &n), n)
	{
		limit = n - 1;
		cnt = 1;
		x = y = 0;
		result[0][0] = cnt;
		while(n != 1)
		{
			if(x == limit) {
				v = -1;
				result[++y][x] = ++cnt;
			}
			else if(y == 0) {
				v = -1;
				result[y][++x] = ++cnt;
			}
			else if(y == limit) {
				v = 1;
				result[y][++x] = ++cnt;
			}
			else if(x == 0) {
				v = 1;
				result[++y][x] = ++cnt;
			}
			if((x == limit) && (y == limit)) break;
			y+= -v; x+= v;
			result[y][x] = ++cnt;
		}

		printf("Case %d:\n", ++test_cnt);
		for(y=0; y < n; y++) {
			for(x=0; x < n; x++) {
				printf("%3d", result[y][x]);
			}
			printf("\n");
		}
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"Case %d:\n"
.LC1:
	.string	"%3d"
.LC2:
	.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
	subq	$368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -344(%rbp)
	jmp	.L2
.L15:
	movl	-364(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -340(%rbp)
	movl	$1, -360(%rbp)
	movl	$0, -352(%rbp)
	movl	-352(%rbp), %eax
	movl	%eax, -356(%rbp)
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp)
	jmp	.L3
.L10:
	movl	-356(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L4
	movl	$-1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -352(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L4:
	cmpl	$0, -352(%rbp)
	jne	.L6
	movl	$-1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -356(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L6:
	movl	-352(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L7
	movl	$1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -356(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L7:
	cmpl	$0, -356(%rbp)
	jne	.L5
	movl	$1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -352(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
.L5:
	movl	-356(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L8
	movl	-352(%rbp), %eax
	cmpl	-340(%rbp), %eax
	je	.L18
.L8:
	movl	-348(%rbp), %eax
	subl	%eax, -352(%rbp)
	movl	-348(%rbp), %eax
	addl	%eax, -356(%rbp)
	addl	$1, -360(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
.L3:
	movl	-364(%rbp), %eax
	cmpl	$1, %eax
	jne	.L10
	jmp	.L9
.L18:
	nop
.L9:
	addl	$1, -344(%rbp)
	movl	-344(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, -352(%rbp)
	jmp	.L11
.L14:
	movl	$0, -356(%rbp)
	jmp	.L12
.L13:
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	movl	-336(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -356(%rbp)
.L12:
	movl	-364(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L13
	movl	$10, %edi
	call	putchar@PLT
	addl	$1, -352(%rbp)
.L11:
	movl	-364(%rbp), %eax
	cmpl	%eax, -352(%rbp)
	jl	.L14
.L2:
	leaq	-364(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-364(%rbp), %eax
	testl	%eax, %eax
	jne	.L15
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	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	"Case %d:\n"
.LC1:
	.string	"%3d"
.LC2:
	.string	"%d"
	.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
	xorl	%r14d, %r14d
	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
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$376, %rsp
	.cfi_def_cfa_offset 432
	movq	%fs:40, %rax
	movq	%rax, 360(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L2:
	movq	8(%rsp), %rsi
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L27
	movl	$1, 32(%rsp)
	leal	-1(%rax), %r8d
	cmpl	$1, %eax
	je	.L3
	movslq	%r8d, %r9
	xorl	%eax, %eax
	xorl	%edx, %edx
	movl	$1, %edi
	leaq	(%r9,%r9,8), %r10
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L4:
	testl	%eax, %eax
	jne	.L6
	leal	1(%rdx), %eax
	movl	$-1, %r13d
	cltq
	movl	%ecx, 32(%rsp,%rax,4)
	movl	$1, %eax
.L7:
	leal	1(%rcx), %edi
	movslq	%eax, %rcx
	movslq	%edx, %rsi
	leaq	(%rcx,%rcx,8), %rcx
	addq	%rsi, %rcx
	movl	%edi, 32(%rsp,%rcx,4)
.L11:
	leal	1(%rdi), %ecx
	cmpl	%edx, %r8d
	jne	.L4
	addl	$1, %eax
	movl	$-1, %r13d
	movslq	%eax, %rsi
	leaq	(%rsi,%rsi,8), %rsi
	addq	%r9, %rsi
	movl	%ecx, 32(%rsp,%rsi,4)
.L5:
	cmpl	%r8d, %edx
	jne	.L17
	cmpl	%r8d, %eax
	je	.L3
.L17:
	subl	%r13d, %eax
	addl	%r13d, %edx
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L6:
	cmpl	%eax, %r8d
	je	.L28
	testl	%edx, %edx
	je	.L9
	subl	%r13d, %eax
	addl	%r13d, %edx
	movl	%edi, %ecx
	jmp	.L7
.L3:
	addl	$1, %r14d
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	movl	%r14d, %edx
	call	__printf_chk@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	leaq	32(%rsp), %rbx
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L13:
	xorl	%r15d, %r15d
	.p2align 4,,10
	.p2align 3
.L14:
	movl	(%rbx,%r15,4), %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$1, %r15
	call	__printf_chk@PLT
	cmpl	%r15d, 28(%rsp)
	jg	.L14
	movl	$10, %edi
	addl	$1, %r12d
	addq	$36, %rbx
	call	putchar@PLT
	cmpl	%r12d, 28(%rsp)
	jg	.L13
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L28:
	addl	$1, %edx
	movl	$1, %r13d
	movslq	%edx, %rsi
	addq	%r10, %rsi
	movl	%ecx, 32(%rsp,%rsi,4)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L9:
	leal	1(%rax), %edx
	movl	$1, %r13d
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,8), %rdx
	movl	%ecx, 32(%rsp,%rdx,4)
	movl	$1, %edx
	jmp	.L7
.L27:
	movq	360(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	addq	$376, %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
.L29:
	.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	"Case %d:\n"
.LC1:
	.string	"%3d"
.LC2:
	.string	"%d"
	.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
	xorl	%r14d, %r14d
	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
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$376, %rsp
	.cfi_def_cfa_offset 432
	movq	%fs:40, %rax
	movq	%rax, 360(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L2:
	movq	8(%rsp), %rsi
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L27
	movl	$1, 32(%rsp)
	leal	-1(%rax), %r8d
	cmpl	$1, %eax
	je	.L3
	movslq	%r8d, %r9
	xorl	%eax, %eax
	xorl	%edx, %edx
	movl	$1, %edi
	leaq	(%r9,%r9,8), %r10
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L4:
	testl	%eax, %eax
	jne	.L6
	leal	1(%rdx), %eax
	movl	$-1, %r13d
	cltq
	movl	%ecx, 32(%rsp,%rax,4)
	movl	$1, %eax
.L7:
	leal	1(%rcx), %edi
	movslq	%eax, %rcx
	movslq	%edx, %rsi
	leaq	(%rcx,%rcx,8), %rcx
	addq	%rsi, %rcx
	movl	%edi, 32(%rsp,%rcx,4)
.L11:
	leal	1(%rdi), %ecx
	cmpl	%edx, %r8d
	jne	.L4
	addl	$1, %eax
	movl	$-1, %r13d
	movslq	%eax, %rsi
	leaq	(%rsi,%rsi,8), %rsi
	addq	%r9, %rsi
	movl	%ecx, 32(%rsp,%rsi,4)
.L5:
	cmpl	%r8d, %edx
	jne	.L17
	cmpl	%r8d, %eax
	je	.L3
.L17:
	subl	%r13d, %eax
	addl	%r13d, %edx
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L6:
	cmpl	%eax, %r8d
	je	.L28
	testl	%edx, %edx
	je	.L9
	subl	%r13d, %eax
	addl	%r13d, %edx
	movl	%edi, %ecx
	jmp	.L7
.L3:
	addl	$1, %r14d
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	movl	%r14d, %edx
	call	__printf_chk@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	leaq	32(%rsp), %rbx
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L13:
	xorl	%r15d, %r15d
	.p2align 4,,10
	.p2align 3
.L14:
	movl	(%rbx,%r15,4), %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$1, %r15
	call	__printf_chk@PLT
	cmpl	%r15d, 28(%rsp)
	jg	.L14
	movl	$10, %edi
	addl	$1, %r12d
	addq	$36, %rbx
	call	putchar@PLT
	cmpl	%r12d, 28(%rsp)
	jg	.L13
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L28:
	addl	$1, %edx
	movl	$1, %r13d
	movslq	%edx, %rsi
	addq	%r10, %rsi
	movl	%ecx, 32(%rsp,%rsi,4)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L9:
	leal	1(%rax), %edx
	movl	$1, %r13d
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,8), %rdx
	movl	%ecx, 32(%rsp,%rdx,4)
	movl	$1, %edx
	jmp	.L7
.L27:
	movq	360(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	addq	$376, %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
.L29:
	.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>

#define MAX 9

int main(void)
{
	int n, cnt, limit;
	int x, y, v;
	int result[MAX][MAX];
	int test_cnt;
	test_cnt = 0;

	while(scanf("%d", &n), n)
	{
		limit = n - 1;
		cnt = 1;
		x = y = 0;
		result[0][0] = cnt;
		while(n != 1)
		{
			if(x == limit) {
				v = -1;
				result[++y][x] = ++cnt;
			}
			else if(y == 0) {
				v = -1;
				result[y][++x] = ++cnt;
			}
			else if(y == limit) {
				v = 1;
				result[y][++x] = ++cnt;
			}
			else if(x == 0) {
				v = 1;
				result[++y][x] = ++cnt;
			}
			if((x == limit) && (y == limit)) break;
			y+= -v; x+= v;
			result[y][x] = ++cnt;
		}

		printf("Case %d:\n", ++test_cnt);
		for(y=0; y < n; y++) {
			for(x=0; x < n; x++) {
				printf("%3d", result[y][x]);
			}
			printf("\n");
		}
	}
	return 0;
}
3
7
0
 3
3
0
 3
0
0
 3
1
0
 3
2
0

Case 1:
  1  2  6
  3  5  7
  4  8  9
Case 2:
  1  2  6  7 15 16 28
  3  5  8 14 17 27 29
  4  9 13 18 26 30 39
 10 12 19 25 31 38 40
 11 20 24 32 37 41 46
 21 23 33 36 42 45 47
 22 34 35 43 44 48 49
 Case 1:
  1  2  6
  3  5  7
  4  8  9
Case 2:
  1  2  6
  3  5  7
  4  8  9
 Case 1:
  1  2  6
  3  5  7
  4  8  9
 Case 1:
  1  2  6
  3  5  7
  4  8  9
Case 2:
  1
 Case 1:
  1  2  6
  3  5  7
  4  8  9
Case 2:
  1  2
  3  4

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>

#define MAX 9

int main(void)
{
	int n, cnt, limit;
	int x, y, v;
	int result[MAX][MAX];
	int test_cnt;
	test_cnt = 0;

	while(scanf("%d", &n), n)
	{
		limit = n - 1;
		cnt = 1;
		x = y = 0;
		result[0][0] = cnt;
		while(n != 1)
		{
			if(x == limit) {
				v = -1;
				result[++y][x] = ++cnt;
			}
			else if(y == 0) {
				v = -1;
				result[y][++x] = ++cnt;
			}
			else if(y == limit) {
				v = 1;
				result[y][++x] = ++cnt;
			}
			else if(x == 0) {
				v = 1;
				result[++y][x] = ++cnt;
			}
			if((x == limit) && (y == limit)) break;
			y+= -v; x+= v;
			result[y][x] = ++cnt;
		}

		printf("Case %d:\n", ++test_cnt);
		for(y=0; y < n; y++) {
			for(x=0; x < n; x++) {
				printf("%3d", result[y][x]);
			}
			printf("\n");
		}
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"Case %d:\n"
.LC1:
	.string	"%3d"
.LC2:
	.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
	subq	$368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -344(%rbp)
	jmp	.L2
.L15:
	movl	-364(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -340(%rbp)
	movl	$1, -360(%rbp)
	movl	$0, -352(%rbp)
	movl	-352(%rbp), %eax
	movl	%eax, -356(%rbp)
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp)
	jmp	.L3
.L10:
	movl	-356(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L4
	movl	$-1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -352(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L4:
	cmpl	$0, -352(%rbp)
	jne	.L6
	movl	$-1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -356(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L6:
	movl	-352(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L7
	movl	$1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -356(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L7:
	cmpl	$0, -356(%rbp)
	jne	.L5
	movl	$1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -352(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
.L5:
	movl	-356(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L8
	movl	-352(%rbp), %eax
	cmpl	-340(%rbp), %eax
	je	.L18
.L8:
	movl	-348(%rbp), %eax
	subl	%eax, -352(%rbp)
	movl	-348(%rbp), %eax
	addl	%eax, -356(%rbp)
	addl	$1, -360(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
.L3:
	movl	-364(%rbp), %eax
	cmpl	$1, %eax
	jne	.L10
	jmp	.L9
.L18:
	nop
.L9:
	addl	$1, -344(%rbp)
	movl	-344(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, -352(%rbp)
	jmp	.L11
.L14:
	movl	$0, -356(%rbp)
	jmp	.L12
.L13:
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	movl	-336(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -356(%rbp)
.L12:
	movl	-364(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L13
	movl	$10, %edi
	call	putchar@PLT
	addl	$1, -352(%rbp)
.L11:
	movl	-364(%rbp), %eax
	cmpl	%eax, -352(%rbp)
	jl	.L14
.L2:
	leaq	-364(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-364(%rbp), %eax
	testl	%eax, %eax
	jne	.L15
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	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	"Case %d:\n"
.LC1:
	.string	"%3d"
.LC2:
	.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
	subq	$368, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -344(%rbp)
	jmp	.L2
.L15:
	movl	-364(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -340(%rbp)
	movl	$1, -360(%rbp)
	movl	$0, -352(%rbp)
	movl	-352(%rbp), %eax
	movl	%eax, -356(%rbp)
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp)
	jmp	.L3
.L10:
	movl	-356(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L4
	movl	$-1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -352(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L4:
	cmpl	$0, -352(%rbp)
	jne	.L6
	movl	$-1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -356(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L6:
	movl	-352(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L7
	movl	$1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -356(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
	jmp	.L5
.L7:
	cmpl	$0, -356(%rbp)
	jne	.L5
	movl	$1, -348(%rbp)
	addl	$1, -360(%rbp)
	addl	$1, -352(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
.L5:
	movl	-356(%rbp), %eax
	cmpl	-340(%rbp), %eax
	jne	.L8
	movl	-352(%rbp), %eax
	cmpl	-340(%rbp), %eax
	je	.L18
.L8:
	movl	-348(%rbp), %eax
	subl	%eax, -352(%rbp)
	movl	-348(%rbp), %eax
	addl	%eax, -356(%rbp)
	addl	$1, -360(%rbp)
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-360(%rbp), %eax
	movl	%eax, -336(%rbp,%rdx,4)
.L3:
	movl	-364(%rbp), %eax
	cmpl	$1, %eax
	jne	.L10
	jmp	.L9
.L18:
	nop
.L9:
	addl	$1, -344(%rbp)
	movl	-344(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, -352(%rbp)
	jmp	.L11
.L14:
	movl	$0, -356(%rbp)
	jmp	.L12
.L13:
	movl	-356(%rbp), %eax
	movslq	%eax, %rcx
	movl	-352(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	movl	-336(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -356(%rbp)
.L12:
	movl	-364(%rbp), %eax
	cmpl	%eax, -356(%rbp)
	jl	.L13
	movl	$10, %edi
	call	putchar@PLT
	addl	$1, -352(%rbp)
.L11:
	movl	-364(%rbp), %eax
	cmpl	%eax, -352(%rbp)
	jl	.L14
.L2:
	leaq	-364(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-364(%rbp), %eax
	testl	%eax, %eax
	jne	.L15
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	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:
