Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
char m[1001*1002];
v[1001*1002];
q[1001*1002],d,e;
h,w,p[10],x;
main(n,i,j,c,t){
	scanf("%d%d%d",&h,&w,&n);
	w++;
	for(i=0;i<h*w;i++){
		c=getchar();
		if(c>='1'&&c<='9')
			p[c-'0']=w+i,c='.';
		if(c=='S')
			p[0]=w+i,c='.';
		m[w+i]=c;
	}
	t=0;
	for(i=0;i<n;i++){
		memset(v,0,4*(h+2)*w);
		d=e=0;
		v[q[e++]=p[i]]=1;
		for(;!v[p[i+1]];){
			x=q[d++];
			if(m[x-1]=='.'&&v[x-1]==0)
				v[q[e++]=x-1]=v[x]+1;
			if(m[x+1]=='.'&&v[x+1]==0)
				v[q[e++]=x+1]=v[x]+1;
			if(m[x-w]=='.'&&v[x-w]==0)
				v[q[e++]=x-w]=v[x]+1;
			if(m[x+w]=='.'&&v[x+w]==0)
				v[q[e++]=x+w]=v[x]+1;
		}
		t+=v[p[i+1]]-1;
	}
	{int n;for(n=100000;n--;)getchar();}//delay(0.05s)
	x=!printf("%d\n",t);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	m
	.bss
	.align 32
	.type	m, @object
	.size	m, 1003002
m:
	.zero	1003002
	.globl	v
	.align 32
	.type	v, @object
	.size	v, 4012008
v:
	.zero	4012008
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4012008
q:
	.zero	4012008
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	e
	.align 4
	.type	e, @object
	.size	e, 4
e:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	p
	.align 32
	.type	p, @object
	.size	p, 40
p:
	.zero	40
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.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
	subq	$48, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	leaq	-20(%rbp), %rax
	movq	%rax, %rcx
	leaq	w(%rip), %rax
	movq	%rax, %rdx
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	w(%rip), %eax
	addl	$1, %eax
	movl	%eax, w(%rip)
	movl	$0, -24(%rbp)
	jmp	.L2
.L5:
	movl	$0, %eax
	call	getchar@PLT
	movl	%eax, -32(%rbp)
	cmpl	$48, -32(%rbp)
	jle	.L3
	cmpl	$57, -32(%rbp)
	jg	.L3
	movl	w(%rip), %ecx
	movl	-32(%rbp), %eax
	subl	$48, %eax
	movl	-24(%rbp), %edx
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$46, -32(%rbp)
.L3:
	cmpl	$83, -32(%rbp)
	jne	.L4
	movl	w(%rip), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, p(%rip)
	movl	$46, -32(%rbp)
.L4:
	movl	w(%rip), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	-32(%rbp), %edx
	movl	%edx, %ecx
	cltq
	leaq	m(%rip), %rdx
	movb	%cl, (%rax,%rdx)
	addl	$1, -24(%rbp)
.L2:
	movl	h(%rip), %edx
	movl	w(%rip), %eax
	imull	%edx, %eax
	cmpl	%eax, -24(%rbp)
	jl	.L5
	movl	$0, -36(%rbp)
	movl	$0, -24(%rbp)
	jmp	.L6
.L12:
	movl	h(%rip), %eax
	leal	2(%rax), %edx
	movl	w(%rip), %eax
	imull	%edx, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdx
	movl	$0, %esi
	leaq	v(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, e(%rip)
	movl	e(%rip), %eax
	movl	%eax, d(%rip)
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	p(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%eax, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	q(%rip), %rcx
	movl	%edx, (%rsi,%rcx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	$1, (%rdx,%rax)
	jmp	.L7
.L11:
	movl	d(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, d(%rip)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, x(%rip)
	movl	x(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L8
	movl	x(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L8
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	leal	-1(%rsi), %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L8:
	movl	x(%rip), %eax
	addl	$1, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L9
	movl	x(%rip), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	leal	1(%rsi), %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L9:
	movl	x(%rip), %eax
	movl	w(%rip), %edx
	subl	%edx, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L10
	movl	x(%rip), %eax
	movl	w(%rip), %edx
	subl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L10
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	w(%rip), %r8d
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	movl	%esi, %edi
	subl	%r8d, %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L10:
	movl	x(%rip), %edx
	movl	w(%rip), %eax
	addl	%edx, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L7
	movl	x(%rip), %edx
	movl	w(%rip), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L7
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %edi
	movl	w(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	addl	%esi, %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L7:
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L11
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	addl	%eax, -36(%rbp)
	addl	$1, -24(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L12
	movl	$100000, -4(%rbp)
	jmp	.L13
.L14:
	movl	$0, %eax
	call	getchar@PLT
.L13:
	movl	-4(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -4(%rbp)
	testl	%eax, %eax
	jne	.L14
	movl	-36(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, x(%rip)
	movl	$0, %eax
	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	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	w(%rip), %rdx
	leaq	h(%rip), %rsi
	xorl	%eax, %eax
	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
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	%edi, 28(%rsp)
	leaq	28(%rsp), %rcx
	leaq	.LC0(%rip), %rdi
	call	scanf@PLT
	movl	w(%rip), %eax
	leal	1(%rax), %r12d
	movl	h(%rip), %eax
	movl	%r12d, %edx
	movl	%r12d, w(%rip)
	imull	%eax, %edx
	testl	%edx, %edx
	jle	.L2
	xorl	%ebp, %ebp
	leaq	m(%rip), %rbx
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L27:
	subl	$48, %eax
	leaq	p(%rip), %rcx
	cltq
	movl	%edx, (%rcx,%rax,4)
	movl	$46, %eax
.L4:
	movslq	%edx, %rdx
	addl	$1, %ebp
	movb	%al, (%rbx,%rdx)
	movl	h(%rip), %eax
	movl	%eax, %edx
	imull	%r12d, %edx
	cmpl	%ebp, %edx
	jle	.L2
.L6:
	xorl	%eax, %eax
	call	getchar@PLT
	movl	w(%rip), %r12d
	leal	-49(%rax), %edx
	cmpl	$8, %edx
	leal	(%r12,%rbp), %edx
	jbe	.L27
	cmpl	$83, %eax
	jne	.L4
	movl	%edx, p(%rip)
	movl	$46, %eax
	jmp	.L4
.L2:
	movl	28(%rsp), %edx
	testl	%edx, %edx
	jle	.L18
	addl	$2, %eax
	leaq	p(%rip), %r14
	subl	$1, %edx
	xorl	%ebp, %ebp
	imull	%r12d, %eax
	leaq	v(%rip), %rcx
	leaq	q(%rip), %r13
	leaq	m(%rip), %rbx
	sall	$2, %eax
	cltq
	movq	%rax, 8(%rsp)
	leaq	4(%r14), %rax
	leaq	(%rax,%rdx,4), %rax
	movq	%rax, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L16:
	movq	8(%rsp), %rdx
	xorl	%esi, %esi
	movq	%rcx, %rdi
	call	memset@PLT
	movslq	(%r14), %rdx
	movslq	4(%r14), %r8
	movl	$0, d(%rip)
	movl	$1, e(%rip)
	movq	%rax, %rcx
	movl	$1, (%rcx,%rdx,4)
	movl	(%rcx,%r8,4), %esi
	movq	%rdx, %rax
	movl	%edx, 0(%r13)
	testl	%esi, %esi
	jne	.L8
	movl	$1, %edx
	xorl	%r10d, %r10d
	movl	$1, %edi
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L9:
	leal	1(%rax), %r11d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	je	.L28
.L10:
	movl	%eax, %r11d
	subl	%r12d, %r11d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	je	.L29
.L11:
	leal	(%r12,%rax), %r11d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	je	.L30
.L12:
	movl	(%rcx,%r8,4), %esi
	testl	%esi, %esi
	jne	.L13
.L31:
	movl	0(%r13,%rdx,4), %eax
	addq	$1, %rdx
.L14:
	leal	-1(%rax), %r11d
	movl	%edx, %r9d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	jne	.L9
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L9
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	leal	1(%rax), %r11d
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movslq	%r11d, %rsi
	movl	$1, %r10d
	cmpb	$46, (%rbx,%rsi)
	jne	.L10
	.p2align 4,,10
	.p2align 3
.L28:
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L10
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	movl	%eax, %r11d
	subl	%r12d, %r11d
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movslq	%r11d, %rsi
	movl	$1, %r10d
	cmpb	$46, (%rbx,%rsi)
	jne	.L11
	.p2align 4,,10
	.p2align 3
.L29:
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L11
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	leal	(%r12,%rax), %r11d
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movslq	%r11d, %rsi
	movl	$1, %r10d
	cmpb	$46, (%rbx,%rsi)
	jne	.L12
	.p2align 4,,10
	.p2align 3
.L30:
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L12
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movl	(%rcx,%r8,4), %esi
	movl	$1, %r10d
	testl	%esi, %esi
	je	.L31
	.p2align 4,,10
	.p2align 3
.L13:
	movl	%eax, x(%rip)
	movl	%r9d, d(%rip)
	testb	%r10b, %r10b
	je	.L8
	movl	%edi, e(%rip)
.L8:
	leal	-1(%rsi,%rbp), %ebp
	addq	$4, %r14
	cmpq	%r14, 16(%rsp)
	jne	.L16
.L7:
	movl	$100000, %ebx
	.p2align 4,,10
	.p2align 3
.L17:
	xorl	%eax, %eax
	call	getchar@PLT
	subl	$1, %ebx
	jne	.L17
	movl	%ebp, %esi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, x(%rip)
	addq	$40, %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
.L18:
	.cfi_restore_state
	xorl	%ebp, %ebp
	jmp	.L7
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	x
	.bss
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.globl	p
	.align 32
	.type	p, @object
	.size	p, 40
p:
	.zero	40
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	e
	.align 4
	.type	e, @object
	.size	e, 4
e:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4012008
q:
	.zero	4012008
	.globl	v
	.align 32
	.type	v, @object
	.size	v, 4012008
v:
	.zero	4012008
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 1003002
m:
	.zero	1003002
	.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	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	w(%rip), %rdx
	leaq	h(%rip), %rsi
	xorl	%eax, %eax
	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
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	%edi, 28(%rsp)
	leaq	28(%rsp), %rcx
	leaq	.LC0(%rip), %rdi
	call	scanf@PLT
	movl	w(%rip), %eax
	leal	1(%rax), %r12d
	movl	h(%rip), %eax
	movl	%r12d, %edx
	movl	%r12d, w(%rip)
	imull	%eax, %edx
	testl	%edx, %edx
	jle	.L2
	xorl	%ebp, %ebp
	leaq	m(%rip), %rbx
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L27:
	subl	$48, %eax
	leaq	p(%rip), %rcx
	cltq
	movl	%edx, (%rcx,%rax,4)
	movl	$46, %eax
.L4:
	movslq	%edx, %rdx
	addl	$1, %ebp
	movb	%al, (%rbx,%rdx)
	movl	h(%rip), %eax
	movl	%eax, %edx
	imull	%r12d, %edx
	cmpl	%ebp, %edx
	jle	.L2
.L6:
	xorl	%eax, %eax
	call	getchar@PLT
	movl	w(%rip), %r12d
	leal	-49(%rax), %edx
	cmpl	$8, %edx
	leal	(%r12,%rbp), %edx
	jbe	.L27
	cmpl	$83, %eax
	jne	.L4
	movl	%edx, p(%rip)
	movl	$46, %eax
	jmp	.L4
.L2:
	movl	28(%rsp), %edx
	testl	%edx, %edx
	jle	.L18
	addl	$2, %eax
	leaq	p(%rip), %r14
	subl	$1, %edx
	xorl	%ebp, %ebp
	imull	%r12d, %eax
	leaq	v(%rip), %rcx
	leaq	q(%rip), %r13
	leaq	m(%rip), %rbx
	sall	$2, %eax
	cltq
	movq	%rax, 8(%rsp)
	leaq	4(%r14), %rax
	leaq	(%rax,%rdx,4), %rax
	movq	%rax, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L16:
	movq	8(%rsp), %rdx
	xorl	%esi, %esi
	movq	%rcx, %rdi
	call	memset@PLT
	movslq	(%r14), %rdx
	movslq	4(%r14), %r8
	movl	$0, d(%rip)
	movl	$1, e(%rip)
	movq	%rax, %rcx
	movl	$1, (%rcx,%rdx,4)
	movl	(%rcx,%r8,4), %esi
	movq	%rdx, %rax
	movl	%edx, 0(%r13)
	testl	%esi, %esi
	jne	.L8
	movl	$1, %edx
	xorl	%r10d, %r10d
	movl	$1, %edi
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L9:
	leal	1(%rax), %r11d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	je	.L28
.L10:
	movl	%eax, %r11d
	subl	%r12d, %r11d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	je	.L29
.L11:
	leal	(%r12,%rax), %r11d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	je	.L30
.L12:
	movl	(%rcx,%r8,4), %esi
	testl	%esi, %esi
	jne	.L13
.L31:
	movl	0(%r13,%rdx,4), %eax
	addq	$1, %rdx
.L14:
	leal	-1(%rax), %r11d
	movl	%edx, %r9d
	movslq	%r11d, %rsi
	cmpb	$46, (%rbx,%rsi)
	jne	.L9
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L9
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	leal	1(%rax), %r11d
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movslq	%r11d, %rsi
	movl	$1, %r10d
	cmpb	$46, (%rbx,%rsi)
	jne	.L10
	.p2align 4,,10
	.p2align 3
.L28:
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L10
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	movl	%eax, %r11d
	subl	%r12d, %r11d
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movslq	%r11d, %rsi
	movl	$1, %r10d
	cmpb	$46, (%rbx,%rsi)
	jne	.L11
	.p2align 4,,10
	.p2align 3
.L29:
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L11
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	leal	(%r12,%rax), %r11d
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movslq	%r11d, %rsi
	movl	$1, %r10d
	cmpb	$46, (%rbx,%rsi)
	jne	.L12
	.p2align 4,,10
	.p2align 3
.L30:
	movl	(%rcx,%rsi,4), %r15d
	testl	%r15d, %r15d
	jne	.L12
	movslq	%eax, %r10
	movslq	%edi, %r15
	addl	$1, %edi
	movl	(%rcx,%r10,4), %r10d
	movl	%r11d, 0(%r13,%r15,4)
	addl	$1, %r10d
	movl	%r10d, (%rcx,%rsi,4)
	movl	(%rcx,%r8,4), %esi
	movl	$1, %r10d
	testl	%esi, %esi
	je	.L31
	.p2align 4,,10
	.p2align 3
.L13:
	movl	%eax, x(%rip)
	movl	%r9d, d(%rip)
	testb	%r10b, %r10b
	je	.L8
	movl	%edi, e(%rip)
.L8:
	leal	-1(%rsi,%rbp), %ebp
	addq	$4, %r14
	cmpq	%r14, 16(%rsp)
	jne	.L16
.L7:
	movl	$100000, %ebx
	.p2align 4,,10
	.p2align 3
.L17:
	xorl	%eax, %eax
	call	getchar@PLT
	subl	$1, %ebx
	jne	.L17
	movl	%ebp, %esi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, x(%rip)
	addq	$40, %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
.L18:
	.cfi_restore_state
	xorl	%ebp, %ebp
	jmp	.L7
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	x
	.bss
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.globl	p
	.align 32
	.type	p, @object
	.size	p, 40
p:
	.zero	40
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	e
	.align 4
	.type	e, @object
	.size	e, 4
e:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4012008
q:
	.zero	4012008
	.globl	v
	.align 32
	.type	v, @object
	.size	v, 4012008
v:
	.zero	4012008
	.globl	m
	.align 32
	.type	m, @object
	.size	m, 1003002
m:
	.zero	1003002
	.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:

char m[1001*1002];
v[1001*1002];
q[1001*1002],d,e;
h,w,p[10],x;
main(n,i,j,c,t){
	scanf("%d%d%d",&h,&w,&n);
	w++;
	for(i=0;i<h*w;i++){
		c=getchar();
		if(c>='1'&&c<='9')
			p[c-'0']=w+i,c='.';
		if(c=='S')
			p[0]=w+i,c='.';
		m[w+i]=c;
	}
	t=0;
	for(i=0;i<n;i++){
		memset(v,0,4*(h+2)*w);
		d=e=0;
		v[q[e++]=p[i]]=1;
		for(;!v[p[i+1]];){
			x=q[d++];
			if(m[x-1]=='.'&&v[x-1]==0)
				v[q[e++]=x-1]=v[x]+1;
			if(m[x+1]=='.'&&v[x+1]==0)
				v[q[e++]=x+1]=v[x]+1;
			if(m[x-w]=='.'&&v[x-w]==0)
				v[q[e++]=x-w]=v[x]+1;
			if(m[x+w]=='.'&&v[x+w]==0)
				v[q[e++]=x+w]=v[x]+1;
		}
		t+=v[p[i+1]]-1;
	}
	{int n;for(n=100000;n--;)getchar();}//delay(0.05s)
	x=!printf("%d\n",t);
}
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
char m[1001*1002];
v[1001*1002];
q[1001*1002],d,e;
h,w,p[10],x;
main(n,i,j,c,t){
	scanf("%d%d%d",&h,&w,&n);
	w++;
	for(i=0;i<h*w;i++){
		c=getchar();
		if(c>='1'&&c<='9')
			p[c-'0']=w+i,c='.';
		if(c=='S')
			p[0]=w+i,c='.';
		m[w+i]=c;
	}
	t=0;
	for(i=0;i<n;i++){
		memset(v,0,4*(h+2)*w);
		d=e=0;
		v[q[e++]=p[i]]=1;
		for(;!v[p[i+1]];){
			x=q[d++];
			if(m[x-1]=='.'&&v[x-1]==0)
				v[q[e++]=x-1]=v[x]+1;
			if(m[x+1]=='.'&&v[x+1]==0)
				v[q[e++]=x+1]=v[x]+1;
			if(m[x-w]=='.'&&v[x-w]==0)
				v[q[e++]=x-w]=v[x]+1;
			if(m[x+w]=='.'&&v[x+w]==0)
				v[q[e++]=x+w]=v[x]+1;
		}
		t+=v[p[i+1]]-1;
	}
	{int n;for(n=100000;n--;)getchar();}//delay(0.05s)
	x=!printf("%d\n",t);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	m
	.bss
	.align 32
	.type	m, @object
	.size	m, 1003002
m:
	.zero	1003002
	.globl	v
	.align 32
	.type	v, @object
	.size	v, 4012008
v:
	.zero	4012008
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4012008
q:
	.zero	4012008
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	e
	.align 4
	.type	e, @object
	.size	e, 4
e:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	p
	.align 32
	.type	p, @object
	.size	p, 40
p:
	.zero	40
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.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
	subq	$48, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	leaq	-20(%rbp), %rax
	movq	%rax, %rcx
	leaq	w(%rip), %rax
	movq	%rax, %rdx
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	w(%rip), %eax
	addl	$1, %eax
	movl	%eax, w(%rip)
	movl	$0, -24(%rbp)
	jmp	.L2
.L5:
	movl	$0, %eax
	call	getchar@PLT
	movl	%eax, -32(%rbp)
	cmpl	$48, -32(%rbp)
	jle	.L3
	cmpl	$57, -32(%rbp)
	jg	.L3
	movl	w(%rip), %ecx
	movl	-32(%rbp), %eax
	subl	$48, %eax
	movl	-24(%rbp), %edx
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$46, -32(%rbp)
.L3:
	cmpl	$83, -32(%rbp)
	jne	.L4
	movl	w(%rip), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, p(%rip)
	movl	$46, -32(%rbp)
.L4:
	movl	w(%rip), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	-32(%rbp), %edx
	movl	%edx, %ecx
	cltq
	leaq	m(%rip), %rdx
	movb	%cl, (%rax,%rdx)
	addl	$1, -24(%rbp)
.L2:
	movl	h(%rip), %edx
	movl	w(%rip), %eax
	imull	%edx, %eax
	cmpl	%eax, -24(%rbp)
	jl	.L5
	movl	$0, -36(%rbp)
	movl	$0, -24(%rbp)
	jmp	.L6
.L12:
	movl	h(%rip), %eax
	leal	2(%rax), %edx
	movl	w(%rip), %eax
	imull	%edx, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdx
	movl	$0, %esi
	leaq	v(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, e(%rip)
	movl	e(%rip), %eax
	movl	%eax, d(%rip)
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	p(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%eax, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	q(%rip), %rcx
	movl	%edx, (%rsi,%rcx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	$1, (%rdx,%rax)
	jmp	.L7
.L11:
	movl	d(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, d(%rip)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, x(%rip)
	movl	x(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L8
	movl	x(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L8
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	leal	-1(%rsi), %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L8:
	movl	x(%rip), %eax
	addl	$1, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L9
	movl	x(%rip), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	leal	1(%rsi), %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L9:
	movl	x(%rip), %eax
	movl	w(%rip), %edx
	subl	%edx, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L10
	movl	x(%rip), %eax
	movl	w(%rip), %edx
	subl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L10
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	w(%rip), %r8d
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	movl	%esi, %edi
	subl	%r8d, %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L10:
	movl	x(%rip), %edx
	movl	w(%rip), %eax
	addl	%edx, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L7
	movl	x(%rip), %edx
	movl	w(%rip), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L7
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %edi
	movl	w(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	addl	%esi, %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L7:
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L11
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	addl	%eax, -36(%rbp)
	addl	$1, -24(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L12
	movl	$100000, -4(%rbp)
	jmp	.L13
.L14:
	movl	$0, %eax
	call	getchar@PLT
.L13:
	movl	-4(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -4(%rbp)
	testl	%eax, %eax
	jne	.L14
	movl	-36(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, x(%rip)
	movl	$0, %eax
	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	m
	.bss
	.align 32
	.type	m, @object
	.size	m, 1003002
m:
	.zero	1003002
	.globl	v
	.align 32
	.type	v, @object
	.size	v, 4012008
v:
	.zero	4012008
	.globl	q
	.align 32
	.type	q, @object
	.size	q, 4012008
q:
	.zero	4012008
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	e
	.align 4
	.type	e, @object
	.size	e, 4
e:
	.zero	4
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	p
	.align 32
	.type	p, @object
	.size	p, 40
p:
	.zero	40
	.globl	x
	.align 4
	.type	x, @object
	.size	x, 4
x:
	.zero	4
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.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
	subq	$48, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	leaq	-20(%rbp), %rax
	movq	%rax, %rcx
	leaq	w(%rip), %rax
	movq	%rax, %rdx
	leaq	h(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	movl	w(%rip), %eax
	addl	$1, %eax
	movl	%eax, w(%rip)
	movl	$0, -24(%rbp)
	jmp	.L2
.L5:
	movl	$0, %eax
	call	getchar@PLT
	movl	%eax, -32(%rbp)
	cmpl	$48, -32(%rbp)
	jle	.L3
	cmpl	$57, -32(%rbp)
	jg	.L3
	movl	w(%rip), %ecx
	movl	-32(%rbp), %eax
	subl	$48, %eax
	movl	-24(%rbp), %edx
	addl	%edx, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	$46, -32(%rbp)
.L3:
	cmpl	$83, -32(%rbp)
	jne	.L4
	movl	w(%rip), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, p(%rip)
	movl	$46, -32(%rbp)
.L4:
	movl	w(%rip), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	-32(%rbp), %edx
	movl	%edx, %ecx
	cltq
	leaq	m(%rip), %rdx
	movb	%cl, (%rax,%rdx)
	addl	$1, -24(%rbp)
.L2:
	movl	h(%rip), %edx
	movl	w(%rip), %eax
	imull	%edx, %eax
	cmpl	%eax, -24(%rbp)
	jl	.L5
	movl	$0, -36(%rbp)
	movl	$0, -24(%rbp)
	jmp	.L6
.L12:
	movl	h(%rip), %eax
	leal	2(%rax), %edx
	movl	w(%rip), %eax
	imull	%edx, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rdx
	movl	$0, %esi
	leaq	v(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, e(%rip)
	movl	e(%rip), %eax
	movl	%eax, d(%rip)
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	p(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	movslq	%eax, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	q(%rip), %rcx
	movl	%edx, (%rsi,%rcx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	$1, (%rdx,%rax)
	jmp	.L7
.L11:
	movl	d(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, d(%rip)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, x(%rip)
	movl	x(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L8
	movl	x(%rip), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L8
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	leal	-1(%rsi), %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L8:
	movl	x(%rip), %eax
	addl	$1, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L9
	movl	x(%rip), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	leal	1(%rsi), %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L9:
	movl	x(%rip), %eax
	movl	w(%rip), %edx
	subl	%edx, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L10
	movl	x(%rip), %eax
	movl	w(%rip), %edx
	subl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L10
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %esi
	movl	w(%rip), %r8d
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	movl	%esi, %edi
	subl	%r8d, %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L10:
	movl	x(%rip), %edx
	movl	w(%rip), %eax
	addl	%edx, %eax
	cltq
	leaq	m(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$46, %al
	jne	.L7
	movl	x(%rip), %edx
	movl	w(%rip), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L7
	movl	x(%rip), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	x(%rip), %edi
	movl	w(%rip), %esi
	movl	e(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, e(%rip)
	addl	%esi, %edi
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rsi
	leaq	q(%rip), %rdx
	movl	%edi, (%rsi,%rdx)
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	q(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L7:
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	je	.L11
	movl	-24(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	v(%rip), %rax
	movl	(%rdx,%rax), %eax
	subl	$1, %eax
	addl	%eax, -36(%rbp)
	addl	$1, -24(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L12
	movl	$100000, -4(%rbp)
	jmp	.L13
.L14:
	movl	$0, %eax
	call	getchar@PLT
.L13:
	movl	-4(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -4(%rbp)
	testl	%eax, %eax
	jne	.L14
	movl	-36(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	testl	%eax, %eax
	sete	%al
	movzbl	%al, %eax
	movl	%eax, x(%rip)
	movl	$0, %eax
	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:
