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 rep(i,n) for(i=0;i<n;i++)
#define MAX 1000
const int QMAX = MAX*MAX;
typedef struct{unsigned short x,y;int h;char c;}P;
char Dx[]={1,0,-1,0},Dy[]={0,1,0,-1};
P q[MAX*MAX],p;
int main(void)
{
  int h,w,n,i,j,x,y,hp,tp,xx,yy,mc;
  char f[MAX][MAX],cost[MAX][MAX]={0};
  scanf("%d%d%d",&h,&w,&n);
  rep(i,h)rep(j,w){
    scanf(" %c",f[i]+j);
    if(f[i][j]=='S'){
      x=j; y=i;
    }
  }
  mc=1;hp=tp=0;q[tp++]=(P){x,y,0,1};
  while(hp!=tp){
    p=q[hp++];if(hp==QMAX)hp=0;
    if(mc>p.c)continue;
    if(p.c==n+1)break;
    rep(i,4){
      xx=p.x+Dx[i]; yy=p.y+Dy[i];
      if(xx>=0&&xx<w&&yy>=0&&yy<h&&cost[yy][xx]<p.c&&f[yy][xx]!='X'){
        cost[yy][xx]=p.c;
        if(f[yy][xx]-'0'==p.c){
          mc=p.c+1;
          q[tp++]=(P){xx,yy,p.h+1,p.c+1};
        }
        else{
          q[tp++]=(P){xx,yy,p.h+1,p.c};
        }
        if(tp==QMAX)tp=0;
      }
    }
  }
  printf("%d\n",p.h);
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	QMAX
	.section	.rodata
	.align 4
	.type	QMAX, @object
	.size	QMAX, 4
QMAX:
	.long	1000000
	.globl	Dx
	.data
	.type	Dx, @object
	.size	Dx, 4
Dx:
	.string	"\001"
	.string	"\377"
	.globl	Dy
	.type	Dy, @object
	.size	Dy, 4
Dy:
	.string	""
	.string	"\001"
	.ascii	"\377"
	.globl	q
	.bss
	.align 32
	.type	q, @object
	.size	q, 12000000
q:
	.zero	12000000
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 12
p:
	.zero	12
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	" %c"
.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	-1998848(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1232, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-1000016(%rbp), %rax
	movl	$1000000, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-2000028(%rbp), %rcx
	leaq	-2000068(%rbp), %rdx
	leaq	-2000072(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2000064(%rbp)
	jmp	.L2
.L6:
	movl	$0, -2000060(%rbp)
	jmp	.L3
.L5:
	leaq	-2000016(%rbp), %rdx
	movl	-2000064(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rax, %rdx
	movl	-2000060(%rbp), %eax
	cltq
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2000060(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000064(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	cmpb	$83, %al
	jne	.L4
	movl	-2000060(%rbp), %eax
	movl	%eax, -2000056(%rbp)
	movl	-2000064(%rbp), %eax
	movl	%eax, -2000052(%rbp)
.L4:
	addl	$1, -2000060(%rbp)
.L3:
	movl	-2000068(%rbp), %eax
	cmpl	%eax, -2000060(%rbp)
	jl	.L5
	addl	$1, -2000064(%rbp)
.L2:
	movl	-2000072(%rbp), %eax
	cmpl	%eax, -2000064(%rbp)
	jl	.L6
	movl	$1, -2000040(%rbp)
	movl	$0, -2000044(%rbp)
	movl	-2000044(%rbp), %eax
	movl	%eax, -2000048(%rbp)
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000056(%rbp), %eax
	movl	%eax, %edi
	movl	-2000052(%rbp), %eax
	movl	%eax, %esi
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	q(%rip), %rax
	movw	%di, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	2+q(%rip), %rax
	movw	%si, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	4+q(%rip), %rax
	movl	$0, (%rcx,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	$1, (%rdx,%rax)
	jmp	.L7
.L17:
	movl	-2000048(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -2000048(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	q(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	%rcx, p(%rip)
	movl	8(%rdx,%rax), %eax
	movl	%eax, 8+p(%rip)
	movl	$1000000, %eax
	cmpl	%eax, -2000048(%rbp)
	jne	.L8
	movl	$0, -2000048(%rbp)
.L8:
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	cmpl	%eax, -2000040(%rbp)
	jle	.L9
	jmp	.L7
.L9:
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	movl	-2000028(%rbp), %edx
	addl	$1, %edx
	cmpl	%edx, %eax
	je	.L20
	movl	$0, -2000064(%rbp)
	jmp	.L12
.L16:
	movzwl	p(%rip), %eax
	movzwl	%ax, %ecx
	movl	-2000064(%rbp), %eax
	cltq
	leaq	Dx(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	movl	%eax, -2000036(%rbp)
	movzwl	2+p(%rip), %eax
	movzwl	%ax, %ecx
	movl	-2000064(%rbp), %eax
	cltq
	leaq	Dy(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	movl	%eax, -2000032(%rbp)
	cmpl	$0, -2000036(%rbp)
	js	.L13
	movl	-2000068(%rbp), %eax
	cmpl	%eax, -2000036(%rbp)
	jge	.L13
	cmpl	$0, -2000032(%rbp)
	js	.L13
	movl	-2000072(%rbp), %eax
	cmpl	%eax, -2000032(%rbp)
	jge	.L13
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$1000016, %rax
	movzbl	(%rax), %edx
	movzbl	8+p(%rip), %eax
	cmpb	%al, %dl
	jge	.L13
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	cmpb	$88, %al
	je	.L13
	movzbl	8+p(%rip), %eax
	movl	-2000036(%rbp), %edx
	movslq	%edx, %rcx
	movl	-2000032(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$1000, %rdx, %rdx
	addq	%rbp, %rdx
	addq	%rcx, %rdx
	subq	$1000016, %rdx
	movb	%al, (%rdx)
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	leal	-48(%rax), %edx
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	cmpl	%eax, %edx
	jne	.L14
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	addl	$1, %eax
	movl	%eax, -2000040(%rbp)
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000036(%rbp), %eax
	movl	%eax, %r9d
	movl	-2000032(%rbp), %eax
	movl	%eax, %r8d
	movl	4+p(%rip), %eax
	leal	1(%rax), %esi
	movzbl	8+p(%rip), %eax
	addl	$1, %eax
	movl	%eax, %edi
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	q(%rip), %rax
	movw	%r9w, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	2+q(%rip), %rax
	movw	%r8w, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	4+q(%rip), %rax
	movl	%esi, (%rcx,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	%dil, (%rdx,%rax)
	jmp	.L15
.L14:
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000036(%rbp), %eax
	movl	%eax, %r9d
	movl	-2000032(%rbp), %eax
	movl	%eax, %r8d
	movl	4+p(%rip), %eax
	leal	1(%rax), %edi
	movzbl	8+p(%rip), %ecx
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	q(%rip), %rax
	movw	%r9w, (%rsi,%rax)
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	2+q(%rip), %rax
	movw	%r8w, (%rsi,%rax)
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	4+q(%rip), %rax
	movl	%edi, (%rsi,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	%cl, (%rdx,%rax)
.L15:
	movl	$1000000, %eax
	cmpl	%eax, -2000044(%rbp)
	jne	.L13
	movl	$0, -2000044(%rbp)
.L13:
	addl	$1, -2000064(%rbp)
.L12:
	cmpl	$3, -2000064(%rbp)
	jle	.L16
.L7:
	movl	-2000048(%rbp), %eax
	cmpl	-2000044(%rbp), %eax
	jne	.L17
	jmp	.L11
.L20:
	nop
.L11:
	movl	4+p(%rip), %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	.L19
	call	__stack_chk_fail@PLT
.L19:
	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%d%d"
.LC1:
	.string	" %c"
.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	-1998848(%rsp), %r11
	.cfi_def_cfa 11, 1998904
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1208, %rsp
	.cfi_def_cfa_offset 2000112
	movl	$1000000, %edx
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 2000040(%rsp)
	xorl	%eax, %eax
	leaq	1000032(%rsp), %rdi
	call	memset@PLT
	leaq	28(%rsp), %rcx
	xorl	%eax, %eax
	leaq	24(%rsp), %rdx
	leaq	20(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	20(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	movl	24(%rsp), %eax
	leaq	32(%rsp), %r15
	xorl	%r13d, %r13d
	leaq	.LC1(%rip), %r14
	testl	%eax, %eax
	jle	.L2
	.p2align 4,,10
	.p2align 3
.L24:
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L5:
	leaq	(%r15,%rbx), %rsi
	xorl	%eax, %eax
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	cmpb	$83, (%r15,%rbx)
	movl	24(%rsp), %eax
	cmove	%r13d, %r12d
	cmove	%ebx, %ebp
	addq	$1, %rbx
	cmpl	%ebx, %eax
	jg	.L5
	movl	20(%rsp), %r8d
	addl	$1, %r13d
	cmpl	%r8d, %r13d
	jge	.L2
	addq	$1000, %r15
	testl	%eax, %eax
	jg	.L24
.L2:
	sall	$16, %r12d
	movzwl	%bp, %ebp
	leaq	p(%rip), %r9
	xorl	%edx, %edx
	orl	%r12d, %ebp
	movb	$1, 8+q(%rip)
	leaq	8(%r9), %r12
	movl	$1, %r11d
	movl	%ebp, q(%rip)
	xorl	%r15d, %r15d
	movl	$1, %ebp
	leaq	q(%rip), %rbx
	movl	$0, 4+q(%rip)
	movl	%r8d, 4(%rsp)
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L8:
	cmpl	%r11d, %edx
	je	.L22
.L21:
	movslq	%edx, %rax
	leal	1(%rdx), %ecx
	cmpl	$999999, %edx
	leaq	(%rax,%rax,2), %rax
	movl	%ecx, %edx
	leaq	(%rbx,%rax,4), %rax
	cmove	%r15d, %edx
	movq	(%rax), %rsi
	movl	8(%rax), %eax
	movq	%rsi, (%r9)
	movsbl	%al, %esi
	movl	%eax, (%r12)
	cmpl	%ebp, %esi
	jl	.L8
	movl	28(%rsp), %ecx
	addl	$1, %ecx
	cmpl	%ecx, %esi
	je	.L22
	movzwl	(%r9), %ecx
	movsbl	Dx(%rip), %edi
	movzwl	2+p(%rip), %r8d
	addl	%ecx, %edi
	js	.L10
	movsbl	Dy(%rip), %r10d
	addl	%r8d, %r10d
	cmpl	24(%rsp), %edi
	movl	%r10d, %r13d
	setl	%r14b
	notl	%r13d
	shrl	$31, %r13d
	testb	%r13b, %r14b
	je	.L10
	cmpl	%r10d, 4(%rsp)
	jg	.L71
.L10:
	movsbl	1+Dx(%rip), %edi
	addl	%ecx, %edi
	js	.L13
	movsbl	1+Dy(%rip), %r10d
	addl	%r8d, %r10d
	cmpl	24(%rsp), %edi
	movl	%r10d, %r13d
	setl	%r14b
	notl	%r13d
	shrl	$31, %r13d
	testb	%r13b, %r14b
	je	.L13
	cmpl	%r10d, 4(%rsp)
	jg	.L72
.L13:
	movsbl	2+Dx(%rip), %edi
	addl	%ecx, %edi
	js	.L16
	movsbl	2+Dy(%rip), %r10d
	addl	%r8d, %r10d
	cmpl	24(%rsp), %edi
	movl	%r10d, %r13d
	setl	%r14b
	notl	%r13d
	shrl	$31, %r13d
	testb	%r13b, %r14b
	je	.L16
	cmpl	%r10d, 4(%rsp)
	jg	.L73
.L16:
	movsbl	3+Dx(%rip), %edi
	addl	%ecx, %edi
	js	.L8
	movsbl	3+Dy(%rip), %ecx
	addl	%r8d, %ecx
	cmpl	24(%rsp), %edi
	movl	%ecx, %r8d
	setl	%r10b
	notl	%r8d
	shrl	$31, %r8d
	testb	%r8b, %r10b
	je	.L8
	cmpl	%ecx, 4(%rsp)
	jle	.L8
	movslq	%ecx, %r10
	movslq	%edi, %r8
	imulq	$1000, %r10, %r10
	addq	$2000048, %r10
	addq	%rsp, %r10
	addq	%r8, %r10
	cmpb	-1000016(%r10), %al
	jle	.L8
	movsbl	-2000016(%r10), %r8d
	cmpb	$88, %r8b
	je	.L8
	movzwl	%di, %edi
	movb	%al, -1000016(%r10)
	sall	$16, %ecx
	leal	1(%r11), %r13d
	movl	4+p(%rip), %r10d
	orl	%edi, %ecx
	leal	-48(%r8), %edi
	addl	$1, %r10d
	cmpl	%edi, %esi
	jne	.L20
	leal	-47(%r8), %ebp
	addl	$1, %eax
.L20:
	movslq	%r11d, %rsi
	movslq	%r13d, %r11
	imulq	$12, %rsi, %rsi
	cmpl	$1000000, %r13d
	cmove	%r15, %r11
	movl	%ecx, (%rbx,%rsi)
	leaq	(%rbx,%rsi), %rcx
	movl	%r10d, 4(%rcx)
	movb	%al, 8(%rcx)
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L22:
	movl	4+p(%rip), %edx
	xorl	%eax, %eax
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	2000040(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L74
	addq	$2000056, %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
.L73:
	.cfi_restore_state
	movslq	%r10d, %r13
	movslq	%edi, %r14
	imulq	$1000, %r13, %r13
	addq	$2000048, %r13
	addq	%rsp, %r13
	addq	%r14, %r13
	cmpb	-1000016(%r13), %al
	jle	.L16
	movsbl	-2000016(%r13), %r14d
	cmpb	$88, %r14b
	je	.L16
	movb	%al, -1000016(%r13)
	sall	$16, %r10d
	movl	4+p(%rip), %r13d
	movzwl	%di, %edi
	orl	%r10d, %edi
	addl	$1, %r13d
	movl	%edi, 12(%rsp)
	leal	-48(%r14), %edi
	movl	%r13d, 8(%rsp)
	leal	1(%r11), %r13d
	cmpl	%edi, %esi
	je	.L17
	movl	%eax, %edi
.L18:
	movslq	%r11d, %r10
	movl	12(%rsp), %r11d
	imulq	$12, %r10, %r10
	movl	%r11d, (%rbx,%r10)
	movl	8(%rsp), %r11d
	addq	%rbx, %r10
	cmpl	$1000000, %r13d
	movb	%dil, 8(%r10)
	movl	%r11d, 4(%r10)
	movslq	%r13d, %r11
	cmove	%r15, %r11
	jmp	.L16
.L72:
	movslq	%r10d, %r13
	movslq	%edi, %r14
	imulq	$1000, %r13, %r13
	addq	$2000048, %r13
	addq	%rsp, %r13
	addq	%r14, %r13
	cmpb	-1000016(%r13), %al
	jle	.L13
	movsbl	-2000016(%r13), %r14d
	cmpb	$88, %r14b
	je	.L13
	movb	%al, -1000016(%r13)
	sall	$16, %r10d
	movl	4+p(%rip), %r13d
	movzwl	%di, %edi
	orl	%r10d, %edi
	addl	$1, %r13d
	movl	%edi, 12(%rsp)
	leal	-48(%r14), %edi
	movl	%r13d, 8(%rsp)
	leal	1(%r11), %r13d
	cmpl	%edi, %esi
	je	.L14
	movl	%eax, %edi
.L15:
	movslq	%r11d, %r10
	movl	12(%rsp), %r11d
	imulq	$12, %r10, %r10
	movl	%r11d, (%rbx,%r10)
	movl	8(%rsp), %r11d
	addq	%rbx, %r10
	cmpl	$1000000, %r13d
	movb	%dil, 8(%r10)
	movl	%r11d, 4(%r10)
	movslq	%r13d, %r11
	cmove	%r15, %r11
	jmp	.L13
.L71:
	movslq	%r10d, %r13
	movslq	%edi, %r14
	imulq	$1000, %r13, %r13
	addq	$2000048, %r13
	addq	%rsp, %r13
	addq	%r14, %r13
	cmpb	-1000016(%r13), %al
	jle	.L10
	movsbl	-2000016(%r13), %r14d
	cmpb	$88, %r14b
	je	.L10
	movzwl	%di, %edi
	sall	$16, %r10d
	movb	%al, -1000016(%r13)
	leal	1(%r11), %r13d
	orl	%edi, %r10d
	movl	4+p(%rip), %edi
	addl	$1, %edi
	movl	%edi, 8(%rsp)
	leal	-48(%r14), %edi
	cmpl	%edi, %esi
	je	.L11
	movl	%eax, %edi
.L12:
	imulq	$12, %r11, %r11
	movl	%r10d, (%rbx,%r11)
	movl	8(%rsp), %r10d
	addq	%rbx, %r11
	cmpl	$1000000, %r13d
	movb	%dil, 8(%r11)
	movl	%r10d, 4(%r11)
	movslq	%r13d, %r11
	cmove	%r15, %r11
	jmp	.L10
.L17:
	leal	-47(%r14), %ebp
	leal	1(%rax), %edi
	jmp	.L18
.L14:
	leal	-47(%r14), %ebp
	leal	1(%rax), %edi
	jmp	.L15
.L11:
	leal	-47(%r14), %ebp
	leal	1(%rax), %edi
	jmp	.L12
.L74:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 12
p:
	.zero	12
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 12000000
q:
	.zero	12000000
	.globl	Dy
	.data
	.type	Dy, @object
	.size	Dy, 4
Dy:
	.string	""
	.string	"\001"
	.ascii	"\377"
	.globl	Dx
	.type	Dx, @object
	.size	Dx, 4
Dx:
	.string	"\001"
	.string	"\377"
	.globl	QMAX
	.section	.rodata
	.align 4
	.type	QMAX, @object
	.size	QMAX, 4
QMAX:
	.long	1000000
	.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%d%d"
.LC1:
	.string	" %c"
.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	-1998848(%rsp), %r11
	.cfi_def_cfa 11, 1998904
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1208, %rsp
	.cfi_def_cfa_offset 2000112
	movl	$1000000, %edx
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 2000040(%rsp)
	xorl	%eax, %eax
	leaq	1000032(%rsp), %rdi
	call	memset@PLT
	leaq	28(%rsp), %rcx
	xorl	%eax, %eax
	leaq	24(%rsp), %rdx
	leaq	20(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	20(%rsp), %r8d
	testl	%r8d, %r8d
	jle	.L2
	movl	24(%rsp), %eax
	leaq	32(%rsp), %r15
	xorl	%r13d, %r13d
	leaq	.LC1(%rip), %r14
	testl	%eax, %eax
	jle	.L2
	.p2align 4,,10
	.p2align 3
.L24:
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L5:
	leaq	(%r15,%rbx), %rsi
	xorl	%eax, %eax
	movq	%r14, %rdi
	call	__isoc99_scanf@PLT
	cmpb	$83, (%r15,%rbx)
	movl	24(%rsp), %eax
	cmove	%r13d, %r12d
	cmove	%ebx, %ebp
	addq	$1, %rbx
	cmpl	%ebx, %eax
	jg	.L5
	movl	20(%rsp), %r8d
	addl	$1, %r13d
	cmpl	%r8d, %r13d
	jge	.L2
	addq	$1000, %r15
	testl	%eax, %eax
	jg	.L24
.L2:
	sall	$16, %r12d
	movzwl	%bp, %ebp
	leaq	p(%rip), %r9
	xorl	%edx, %edx
	orl	%r12d, %ebp
	movb	$1, 8+q(%rip)
	leaq	8(%r9), %r12
	movl	$1, %r11d
	movl	%ebp, q(%rip)
	xorl	%r15d, %r15d
	movl	$1, %ebp
	leaq	q(%rip), %rbx
	movl	$0, 4+q(%rip)
	movl	%r8d, 4(%rsp)
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L8:
	cmpl	%r11d, %edx
	je	.L22
.L21:
	movslq	%edx, %rax
	leal	1(%rdx), %ecx
	cmpl	$999999, %edx
	leaq	(%rax,%rax,2), %rax
	movl	%ecx, %edx
	leaq	(%rbx,%rax,4), %rax
	cmove	%r15d, %edx
	movq	(%rax), %rsi
	movl	8(%rax), %eax
	movq	%rsi, (%r9)
	movsbl	%al, %esi
	movl	%eax, (%r12)
	cmpl	%ebp, %esi
	jl	.L8
	movl	28(%rsp), %ecx
	addl	$1, %ecx
	cmpl	%ecx, %esi
	je	.L22
	movzwl	(%r9), %ecx
	movsbl	Dx(%rip), %edi
	movzwl	2+p(%rip), %r8d
	addl	%ecx, %edi
	js	.L10
	movsbl	Dy(%rip), %r10d
	addl	%r8d, %r10d
	cmpl	24(%rsp), %edi
	movl	%r10d, %r13d
	setl	%r14b
	notl	%r13d
	shrl	$31, %r13d
	testb	%r13b, %r14b
	je	.L10
	cmpl	%r10d, 4(%rsp)
	jg	.L71
.L10:
	movsbl	1+Dx(%rip), %edi
	addl	%ecx, %edi
	js	.L13
	movsbl	1+Dy(%rip), %r10d
	addl	%r8d, %r10d
	cmpl	24(%rsp), %edi
	movl	%r10d, %r13d
	setl	%r14b
	notl	%r13d
	shrl	$31, %r13d
	testb	%r13b, %r14b
	je	.L13
	cmpl	%r10d, 4(%rsp)
	jg	.L72
.L13:
	movsbl	2+Dx(%rip), %edi
	addl	%ecx, %edi
	js	.L16
	movsbl	2+Dy(%rip), %r10d
	addl	%r8d, %r10d
	cmpl	24(%rsp), %edi
	movl	%r10d, %r13d
	setl	%r14b
	notl	%r13d
	shrl	$31, %r13d
	testb	%r13b, %r14b
	je	.L16
	cmpl	%r10d, 4(%rsp)
	jg	.L73
.L16:
	movsbl	3+Dx(%rip), %edi
	addl	%ecx, %edi
	js	.L8
	movsbl	3+Dy(%rip), %ecx
	addl	%r8d, %ecx
	cmpl	24(%rsp), %edi
	movl	%ecx, %r8d
	setl	%r10b
	notl	%r8d
	shrl	$31, %r8d
	testb	%r8b, %r10b
	je	.L8
	cmpl	%ecx, 4(%rsp)
	jle	.L8
	movslq	%ecx, %r10
	movslq	%edi, %r8
	imulq	$1000, %r10, %r10
	addq	$2000048, %r10
	addq	%rsp, %r10
	addq	%r8, %r10
	cmpb	-1000016(%r10), %al
	jle	.L8
	movsbl	-2000016(%r10), %r8d
	cmpb	$88, %r8b
	je	.L8
	movzwl	%di, %edi
	movb	%al, -1000016(%r10)
	sall	$16, %ecx
	leal	1(%r11), %r13d
	movl	4+p(%rip), %r10d
	orl	%edi, %ecx
	leal	-48(%r8), %edi
	addl	$1, %r10d
	cmpl	%edi, %esi
	jne	.L20
	leal	-47(%r8), %ebp
	addl	$1, %eax
.L20:
	movslq	%r11d, %rsi
	movslq	%r13d, %r11
	imulq	$12, %rsi, %rsi
	cmpl	$1000000, %r13d
	cmove	%r15, %r11
	movl	%ecx, (%rbx,%rsi)
	leaq	(%rbx,%rsi), %rcx
	movl	%r10d, 4(%rcx)
	movb	%al, 8(%rcx)
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L22:
	movl	4+p(%rip), %edx
	xorl	%eax, %eax
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	2000040(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L74
	addq	$2000056, %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
.L73:
	.cfi_restore_state
	movslq	%r10d, %r13
	movslq	%edi, %r14
	imulq	$1000, %r13, %r13
	addq	$2000048, %r13
	addq	%rsp, %r13
	addq	%r14, %r13
	cmpb	-1000016(%r13), %al
	jle	.L16
	movsbl	-2000016(%r13), %r14d
	cmpb	$88, %r14b
	je	.L16
	movb	%al, -1000016(%r13)
	sall	$16, %r10d
	movl	4+p(%rip), %r13d
	movzwl	%di, %edi
	orl	%r10d, %edi
	addl	$1, %r13d
	movl	%edi, 12(%rsp)
	leal	-48(%r14), %edi
	movl	%r13d, 8(%rsp)
	leal	1(%r11), %r13d
	cmpl	%edi, %esi
	je	.L17
	movl	%eax, %edi
.L18:
	movslq	%r11d, %r10
	movl	12(%rsp), %r11d
	imulq	$12, %r10, %r10
	movl	%r11d, (%rbx,%r10)
	movl	8(%rsp), %r11d
	addq	%rbx, %r10
	cmpl	$1000000, %r13d
	movb	%dil, 8(%r10)
	movl	%r11d, 4(%r10)
	movslq	%r13d, %r11
	cmove	%r15, %r11
	jmp	.L16
.L72:
	movslq	%r10d, %r13
	movslq	%edi, %r14
	imulq	$1000, %r13, %r13
	addq	$2000048, %r13
	addq	%rsp, %r13
	addq	%r14, %r13
	cmpb	-1000016(%r13), %al
	jle	.L13
	movsbl	-2000016(%r13), %r14d
	cmpb	$88, %r14b
	je	.L13
	movb	%al, -1000016(%r13)
	sall	$16, %r10d
	movl	4+p(%rip), %r13d
	movzwl	%di, %edi
	orl	%r10d, %edi
	addl	$1, %r13d
	movl	%edi, 12(%rsp)
	leal	-48(%r14), %edi
	movl	%r13d, 8(%rsp)
	leal	1(%r11), %r13d
	cmpl	%edi, %esi
	je	.L14
	movl	%eax, %edi
.L15:
	movslq	%r11d, %r10
	movl	12(%rsp), %r11d
	imulq	$12, %r10, %r10
	movl	%r11d, (%rbx,%r10)
	movl	8(%rsp), %r11d
	addq	%rbx, %r10
	cmpl	$1000000, %r13d
	movb	%dil, 8(%r10)
	movl	%r11d, 4(%r10)
	movslq	%r13d, %r11
	cmove	%r15, %r11
	jmp	.L13
.L71:
	movslq	%r10d, %r13
	movslq	%edi, %r14
	imulq	$1000, %r13, %r13
	addq	$2000048, %r13
	addq	%rsp, %r13
	addq	%r14, %r13
	cmpb	-1000016(%r13), %al
	jle	.L10
	movsbl	-2000016(%r13), %r14d
	cmpb	$88, %r14b
	je	.L10
	movzwl	%di, %edi
	sall	$16, %r10d
	movb	%al, -1000016(%r13)
	leal	1(%r11), %r13d
	orl	%edi, %r10d
	movl	4+p(%rip), %edi
	addl	$1, %edi
	movl	%edi, 8(%rsp)
	leal	-48(%r14), %edi
	cmpl	%edi, %esi
	je	.L11
	movl	%eax, %edi
.L12:
	imulq	$12, %r11, %r11
	movl	%r10d, (%rbx,%r11)
	movl	8(%rsp), %r10d
	addq	%rbx, %r11
	cmpl	$1000000, %r13d
	movb	%dil, 8(%r11)
	movl	%r10d, 4(%r11)
	movslq	%r13d, %r11
	cmove	%r15, %r11
	jmp	.L10
.L17:
	leal	-47(%r14), %ebp
	leal	1(%rax), %edi
	jmp	.L18
.L14:
	leal	-47(%r14), %ebp
	leal	1(%rax), %edi
	jmp	.L15
.L11:
	leal	-47(%r14), %ebp
	leal	1(%rax), %edi
	jmp	.L12
.L74:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 12
p:
	.zero	12
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 12000000
q:
	.zero	12000000
	.globl	Dy
	.data
	.type	Dy, @object
	.size	Dy, 4
Dy:
	.string	""
	.string	"\001"
	.ascii	"\377"
	.globl	Dx
	.type	Dx, @object
	.size	Dx, 4
Dx:
	.string	"\001"
	.string	"\377"
	.globl	QMAX
	.section	.rodata
	.align 4
	.type	QMAX, @object
	.size	QMAX, 4
QMAX:
	.long	1000000
	.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 rep(i,n) for(i=0;i<n;i++)
#define MAX 1000
const int QMAX = MAX*MAX;
typedef struct{unsigned short x,y;int h;char c;}P;
char Dx[]={1,0,-1,0},Dy[]={0,1,0,-1};
P q[MAX*MAX],p;
int main(void)
{
  int h,w,n,i,j,x,y,hp,tp,xx,yy,mc;
  char f[MAX][MAX],cost[MAX][MAX]={0};
  scanf("%d%d%d",&h,&w,&n);
  rep(i,h)rep(j,w){
    scanf(" %c",f[i]+j);
    if(f[i][j]=='S'){
      x=j; y=i;
    }
  }
  mc=1;hp=tp=0;q[tp++]=(P){x,y,0,1};
  while(hp!=tp){
    p=q[hp++];if(hp==QMAX)hp=0;
    if(mc>p.c)continue;
    if(p.c==n+1)break;
    rep(i,4){
      xx=p.x+Dx[i]; yy=p.y+Dy[i];
      if(xx>=0&&xx<w&&yy>=0&&yy<h&&cost[yy][xx]<p.c&&f[yy][xx]!='X'){
        cost[yy][xx]=p.c;
        if(f[yy][xx]-'0'==p.c){
          mc=p.c+1;
          q[tp++]=(P){xx,yy,p.h+1,p.c+1};
        }
        else{
          q[tp++]=(P){xx,yy,p.h+1,p.c};
        }
        if(tp==QMAX)tp=0;
      }
    }
  }
  printf("%d\n",p.h);
  return 0;
}
3 3 1
S..
...
..1

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 rep(i,n) for(i=0;i<n;i++)
#define MAX 1000
const int QMAX = MAX*MAX;
typedef struct{unsigned short x,y;int h;char c;}P;
char Dx[]={1,0,-1,0},Dy[]={0,1,0,-1};
P q[MAX*MAX],p;
int main(void)
{
  int h,w,n,i,j,x,y,hp,tp,xx,yy,mc;
  char f[MAX][MAX],cost[MAX][MAX]={0};
  scanf("%d%d%d",&h,&w,&n);
  rep(i,h)rep(j,w){
    scanf(" %c",f[i]+j);
    if(f[i][j]=='S'){
      x=j; y=i;
    }
  }
  mc=1;hp=tp=0;q[tp++]=(P){x,y,0,1};
  while(hp!=tp){
    p=q[hp++];if(hp==QMAX)hp=0;
    if(mc>p.c)continue;
    if(p.c==n+1)break;
    rep(i,4){
      xx=p.x+Dx[i]; yy=p.y+Dy[i];
      if(xx>=0&&xx<w&&yy>=0&&yy<h&&cost[yy][xx]<p.c&&f[yy][xx]!='X'){
        cost[yy][xx]=p.c;
        if(f[yy][xx]-'0'==p.c){
          mc=p.c+1;
          q[tp++]=(P){xx,yy,p.h+1,p.c+1};
        }
        else{
          q[tp++]=(P){xx,yy,p.h+1,p.c};
        }
        if(tp==QMAX)tp=0;
      }
    }
  }
  printf("%d\n",p.h);
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	QMAX
	.section	.rodata
	.align 4
	.type	QMAX, @object
	.size	QMAX, 4
QMAX:
	.long	1000000
	.globl	Dx
	.data
	.type	Dx, @object
	.size	Dx, 4
Dx:
	.string	"\001"
	.string	"\377"
	.globl	Dy
	.type	Dy, @object
	.size	Dy, 4
Dy:
	.string	""
	.string	"\001"
	.ascii	"\377"
	.globl	q
	.bss
	.align 32
	.type	q, @object
	.size	q, 12000000
q:
	.zero	12000000
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 12
p:
	.zero	12
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	" %c"
.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	-1998848(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1232, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-1000016(%rbp), %rax
	movl	$1000000, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-2000028(%rbp), %rcx
	leaq	-2000068(%rbp), %rdx
	leaq	-2000072(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2000064(%rbp)
	jmp	.L2
.L6:
	movl	$0, -2000060(%rbp)
	jmp	.L3
.L5:
	leaq	-2000016(%rbp), %rdx
	movl	-2000064(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rax, %rdx
	movl	-2000060(%rbp), %eax
	cltq
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2000060(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000064(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	cmpb	$83, %al
	jne	.L4
	movl	-2000060(%rbp), %eax
	movl	%eax, -2000056(%rbp)
	movl	-2000064(%rbp), %eax
	movl	%eax, -2000052(%rbp)
.L4:
	addl	$1, -2000060(%rbp)
.L3:
	movl	-2000068(%rbp), %eax
	cmpl	%eax, -2000060(%rbp)
	jl	.L5
	addl	$1, -2000064(%rbp)
.L2:
	movl	-2000072(%rbp), %eax
	cmpl	%eax, -2000064(%rbp)
	jl	.L6
	movl	$1, -2000040(%rbp)
	movl	$0, -2000044(%rbp)
	movl	-2000044(%rbp), %eax
	movl	%eax, -2000048(%rbp)
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000056(%rbp), %eax
	movl	%eax, %edi
	movl	-2000052(%rbp), %eax
	movl	%eax, %esi
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	q(%rip), %rax
	movw	%di, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	2+q(%rip), %rax
	movw	%si, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	4+q(%rip), %rax
	movl	$0, (%rcx,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	$1, (%rdx,%rax)
	jmp	.L7
.L17:
	movl	-2000048(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -2000048(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	q(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	%rcx, p(%rip)
	movl	8(%rdx,%rax), %eax
	movl	%eax, 8+p(%rip)
	movl	$1000000, %eax
	cmpl	%eax, -2000048(%rbp)
	jne	.L8
	movl	$0, -2000048(%rbp)
.L8:
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	cmpl	%eax, -2000040(%rbp)
	jle	.L9
	jmp	.L7
.L9:
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	movl	-2000028(%rbp), %edx
	addl	$1, %edx
	cmpl	%edx, %eax
	je	.L20
	movl	$0, -2000064(%rbp)
	jmp	.L12
.L16:
	movzwl	p(%rip), %eax
	movzwl	%ax, %ecx
	movl	-2000064(%rbp), %eax
	cltq
	leaq	Dx(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	movl	%eax, -2000036(%rbp)
	movzwl	2+p(%rip), %eax
	movzwl	%ax, %ecx
	movl	-2000064(%rbp), %eax
	cltq
	leaq	Dy(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	movl	%eax, -2000032(%rbp)
	cmpl	$0, -2000036(%rbp)
	js	.L13
	movl	-2000068(%rbp), %eax
	cmpl	%eax, -2000036(%rbp)
	jge	.L13
	cmpl	$0, -2000032(%rbp)
	js	.L13
	movl	-2000072(%rbp), %eax
	cmpl	%eax, -2000032(%rbp)
	jge	.L13
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$1000016, %rax
	movzbl	(%rax), %edx
	movzbl	8+p(%rip), %eax
	cmpb	%al, %dl
	jge	.L13
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	cmpb	$88, %al
	je	.L13
	movzbl	8+p(%rip), %eax
	movl	-2000036(%rbp), %edx
	movslq	%edx, %rcx
	movl	-2000032(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$1000, %rdx, %rdx
	addq	%rbp, %rdx
	addq	%rcx, %rdx
	subq	$1000016, %rdx
	movb	%al, (%rdx)
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	leal	-48(%rax), %edx
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	cmpl	%eax, %edx
	jne	.L14
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	addl	$1, %eax
	movl	%eax, -2000040(%rbp)
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000036(%rbp), %eax
	movl	%eax, %r9d
	movl	-2000032(%rbp), %eax
	movl	%eax, %r8d
	movl	4+p(%rip), %eax
	leal	1(%rax), %esi
	movzbl	8+p(%rip), %eax
	addl	$1, %eax
	movl	%eax, %edi
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	q(%rip), %rax
	movw	%r9w, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	2+q(%rip), %rax
	movw	%r8w, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	4+q(%rip), %rax
	movl	%esi, (%rcx,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	%dil, (%rdx,%rax)
	jmp	.L15
.L14:
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000036(%rbp), %eax
	movl	%eax, %r9d
	movl	-2000032(%rbp), %eax
	movl	%eax, %r8d
	movl	4+p(%rip), %eax
	leal	1(%rax), %edi
	movzbl	8+p(%rip), %ecx
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	q(%rip), %rax
	movw	%r9w, (%rsi,%rax)
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	2+q(%rip), %rax
	movw	%r8w, (%rsi,%rax)
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	4+q(%rip), %rax
	movl	%edi, (%rsi,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	%cl, (%rdx,%rax)
.L15:
	movl	$1000000, %eax
	cmpl	%eax, -2000044(%rbp)
	jne	.L13
	movl	$0, -2000044(%rbp)
.L13:
	addl	$1, -2000064(%rbp)
.L12:
	cmpl	$3, -2000064(%rbp)
	jle	.L16
.L7:
	movl	-2000048(%rbp), %eax
	cmpl	-2000044(%rbp), %eax
	jne	.L17
	jmp	.L11
.L20:
	nop
.L11:
	movl	4+p(%rip), %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	.L19
	call	__stack_chk_fail@PLT
.L19:
	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
	.globl	QMAX
	.section	.rodata
	.align 4
	.type	QMAX, @object
	.size	QMAX, 4
QMAX:
	.long	1000000
	.globl	Dx
	.data
	.type	Dx, @object
	.size	Dx, 4
Dx:
	.string	"\001"
	.string	"\377"
	.globl	Dy
	.type	Dy, @object
	.size	Dy, 4
Dy:
	.string	""
	.string	"\001"
	.ascii	"\377"
	.globl	q
	.bss
	.align 32
	.type	q, @object
	.size	q, 12000000
q:
	.zero	12000000
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 12
p:
	.zero	12
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	" %c"
.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	-1998848(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1232, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-1000016(%rbp), %rax
	movl	$1000000, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-2000028(%rbp), %rcx
	leaq	-2000068(%rbp), %rdx
	leaq	-2000072(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2000064(%rbp)
	jmp	.L2
.L6:
	movl	$0, -2000060(%rbp)
	jmp	.L3
.L5:
	leaq	-2000016(%rbp), %rdx
	movl	-2000064(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rax, %rdx
	movl	-2000060(%rbp), %eax
	cltq
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-2000060(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000064(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	cmpb	$83, %al
	jne	.L4
	movl	-2000060(%rbp), %eax
	movl	%eax, -2000056(%rbp)
	movl	-2000064(%rbp), %eax
	movl	%eax, -2000052(%rbp)
.L4:
	addl	$1, -2000060(%rbp)
.L3:
	movl	-2000068(%rbp), %eax
	cmpl	%eax, -2000060(%rbp)
	jl	.L5
	addl	$1, -2000064(%rbp)
.L2:
	movl	-2000072(%rbp), %eax
	cmpl	%eax, -2000064(%rbp)
	jl	.L6
	movl	$1, -2000040(%rbp)
	movl	$0, -2000044(%rbp)
	movl	-2000044(%rbp), %eax
	movl	%eax, -2000048(%rbp)
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000056(%rbp), %eax
	movl	%eax, %edi
	movl	-2000052(%rbp), %eax
	movl	%eax, %esi
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	q(%rip), %rax
	movw	%di, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	2+q(%rip), %rax
	movw	%si, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	4+q(%rip), %rax
	movl	$0, (%rcx,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	$1, (%rdx,%rax)
	jmp	.L7
.L17:
	movl	-2000048(%rbp), %eax
	leal	1(%rax), %edx
	movl	%edx, -2000048(%rbp)
	movslq	%eax, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	q(%rip), %rax
	movq	(%rdx,%rax), %rcx
	movq	%rcx, p(%rip)
	movl	8(%rdx,%rax), %eax
	movl	%eax, 8+p(%rip)
	movl	$1000000, %eax
	cmpl	%eax, -2000048(%rbp)
	jne	.L8
	movl	$0, -2000048(%rbp)
.L8:
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	cmpl	%eax, -2000040(%rbp)
	jle	.L9
	jmp	.L7
.L9:
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	movl	-2000028(%rbp), %edx
	addl	$1, %edx
	cmpl	%edx, %eax
	je	.L20
	movl	$0, -2000064(%rbp)
	jmp	.L12
.L16:
	movzwl	p(%rip), %eax
	movzwl	%ax, %ecx
	movl	-2000064(%rbp), %eax
	cltq
	leaq	Dx(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	movl	%eax, -2000036(%rbp)
	movzwl	2+p(%rip), %eax
	movzwl	%ax, %ecx
	movl	-2000064(%rbp), %eax
	cltq
	leaq	Dy(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	addl	%ecx, %eax
	movl	%eax, -2000032(%rbp)
	cmpl	$0, -2000036(%rbp)
	js	.L13
	movl	-2000068(%rbp), %eax
	cmpl	%eax, -2000036(%rbp)
	jge	.L13
	cmpl	$0, -2000032(%rbp)
	js	.L13
	movl	-2000072(%rbp), %eax
	cmpl	%eax, -2000032(%rbp)
	jge	.L13
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$1000016, %rax
	movzbl	(%rax), %edx
	movzbl	8+p(%rip), %eax
	cmpb	%al, %dl
	jge	.L13
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	cmpb	$88, %al
	je	.L13
	movzbl	8+p(%rip), %eax
	movl	-2000036(%rbp), %edx
	movslq	%edx, %rcx
	movl	-2000032(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$1000, %rdx, %rdx
	addq	%rbp, %rdx
	addq	%rcx, %rdx
	subq	$1000016, %rdx
	movb	%al, (%rdx)
	movl	-2000036(%rbp), %eax
	movslq	%eax, %rdx
	movl	-2000032(%rbp), %eax
	cltq
	imulq	$1000, %rax, %rax
	addq	%rbp, %rax
	addq	%rdx, %rax
	subq	$2000016, %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	leal	-48(%rax), %edx
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	cmpl	%eax, %edx
	jne	.L14
	movzbl	8+p(%rip), %eax
	movsbl	%al, %eax
	addl	$1, %eax
	movl	%eax, -2000040(%rbp)
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000036(%rbp), %eax
	movl	%eax, %r9d
	movl	-2000032(%rbp), %eax
	movl	%eax, %r8d
	movl	4+p(%rip), %eax
	leal	1(%rax), %esi
	movzbl	8+p(%rip), %eax
	addl	$1, %eax
	movl	%eax, %edi
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	q(%rip), %rax
	movw	%r9w, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	2+q(%rip), %rax
	movw	%r8w, (%rcx,%rax)
	movslq	%edx, %rcx
	movq	%rcx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	salq	$2, %rax
	movq	%rax, %rcx
	leaq	4+q(%rip), %rax
	movl	%esi, (%rcx,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	%dil, (%rdx,%rax)
	jmp	.L15
.L14:
	movl	-2000044(%rbp), %edx
	leal	1(%rdx), %eax
	movl	%eax, -2000044(%rbp)
	movl	-2000036(%rbp), %eax
	movl	%eax, %r9d
	movl	-2000032(%rbp), %eax
	movl	%eax, %r8d
	movl	4+p(%rip), %eax
	leal	1(%rax), %edi
	movzbl	8+p(%rip), %ecx
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	q(%rip), %rax
	movw	%r9w, (%rsi,%rax)
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	2+q(%rip), %rax
	movw	%r8w, (%rsi,%rax)
	movslq	%edx, %rsi
	movq	%rsi, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	leaq	4+q(%rip), %rax
	movl	%edi, (%rsi,%rax)
	movslq	%edx, %rdx
	movq	%rdx, %rax
	addq	%rax, %rax
	addq	%rdx, %rax
	salq	$2, %rax
	movq	%rax, %rdx
	leaq	8+q(%rip), %rax
	movb	%cl, (%rdx,%rax)
.L15:
	movl	$1000000, %eax
	cmpl	%eax, -2000044(%rbp)
	jne	.L13
	movl	$0, -2000044(%rbp)
.L13:
	addl	$1, -2000064(%rbp)
.L12:
	cmpl	$3, -2000064(%rbp)
	jle	.L16
.L7:
	movl	-2000048(%rbp), %eax
	cmpl	-2000044(%rbp), %eax
	jne	.L17
	jmp	.L11
.L20:
	nop
.L11:
	movl	4+p(%rip), %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	.L19
	call	__stack_chk_fail@PLT
.L19:
	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:
