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

```c
// AOJ 2299:   Tiles are Colorful
// 2017.12.10

#include <stdio.h>
#include <string.h>

int m, n;
char map[501][503];
int mv[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};
int rpos['Z'+1], cpos['Z'+1];
int sr[501], sc[501];

int calc()
{
	int r, c, i, r2, c2, a, ans = 0;
	for (r = 0; r < m; r++) for (c = 0; c < n; c++) 
		if ((sr[c] + sc[r]) && map[r][c] == '.' ) {
			memset(rpos, -1, sizeof(rpos));

		    for (i = 0; i < 4; i++) {
				if (!sr[c]) { if (i < 2) continue; }
				if (!sc[r]) { if (i > 2) continue; }

				r2 = r, c2 = c;
				while (1) {
					r2 += mv[i][0], c2 += mv[i][1];
					if (r2 < 0 || r2 >= m || c2 < 0 || c2 >= n) break;
					if (map[r2][c2] == '.') continue;

	                a = map[r2][c2];
					if (rpos[a] >= 0) {
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
						r2 = rpos[a], c2 = cpos[a];
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
	                    ans += 2;
					} else rpos[a] = r2, cpos[a] = c2;
					break;
				}
            }
        }

	return ans;
}

int main()
{
	int r, c, t, k, ans;
	char buf[10];

    fgets(buf, 10, stdin);
	sscanf(buf, "%d%d", &m, &n);
	for (k = 0, r = 0; r < m; r++) {
		fgets(map[r], 503, stdin);
		for (c = 0; c < n; c++) {
			if (map[r][c] != '.') k++, sr[c]++, sc[r]++;
		}
	}
	ans = 0;
	while (1) {
		if (!(t = calc())) break;
		ans += t, k -= t;
		if (!k) break;
	}
	printf("%d\n", ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	m
	.bss
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 252003
map:
	.zero	252003
	.globl	mv
	.data
	.align 32
	.type	mv, @object
	.size	mv, 32
mv:
	.long	-1
	.long	0
	.long	1
	.long	0
	.long	0
	.long	1
	.long	0
	.long	-1
	.globl	rpos
	.bss
	.align 32
	.type	rpos, @object
	.size	rpos, 364
rpos:
	.zero	364
	.globl	cpos
	.align 32
	.type	cpos, @object
	.size	cpos, 364
cpos:
	.zero	364
	.globl	sr
	.align 32
	.type	sr, @object
	.size	sr, 2004
sr:
	.zero	2004
	.globl	sc
	.align 32
	.type	sc, @object
	.size	sc, 2004
sc:
	.zero	2004
	.text
	.globl	calc
	.type	calc, @function
calc:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	$0, -8(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L2
.L16:
	movl	$0, -24(%rbp)
	jmp	.L3
.L15:
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	testl	%eax, %eax
	je	.L4
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	jne	.L4
	movl	$364, %edx
	movl	$-1, %esi
	leaq	rpos(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, -20(%rbp)
	jmp	.L5
.L14:
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L6
	cmpl	$1, -20(%rbp)
	jle	.L19
.L6:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L8
	cmpl	$2, -20(%rbp)
	jg	.L20
.L8:
	movl	-28(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
.L13:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	mv(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -16(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	4+mv(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -12(%rbp)
	cmpl	$0, -16(%rbp)
	js	.L7
	movl	m(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jge	.L7
	cmpl	$0, -12(%rbp)
	js	.L7
	movl	n(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L7
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	je	.L21
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	rpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	js	.L11
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movb	$46, (%rax)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	rpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movb	$46, (%rax)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$2, -8(%rbp)
	jmp	.L7
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	rpos(%rip), %rdx
	movl	-16(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cpos(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	jmp	.L7
.L21:
	nop
	jmp	.L13
.L19:
	nop
	jmp	.L7
.L20:
	nop
.L7:
	addl	$1, -20(%rbp)
.L5:
	cmpl	$3, -20(%rbp)
	jle	.L14
.L4:
	addl	$1, -24(%rbp)
.L3:
	movl	n(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L15
	addl	$1, -28(%rbp)
.L2:
	movl	m(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L16
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rdx
	leaq	-18(%rbp), %rax
	movl	$10, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	leaq	-18(%rbp), %rax
	leaq	n(%rip), %rdx
	movq	%rdx, %rcx
	leaq	m(%rip), %rdx
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_sscanf@PLT
	movl	$0, -32(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L23
.L27:
	movq	stdin(%rip), %rax
	movl	-40(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$503, %rdx, %rdx
	leaq	map(%rip), %rcx
	addq	%rdx, %rcx
	movq	%rax, %rdx
	movl	$503, %esi
	movq	%rcx, %rdi
	call	fgets@PLT
	movl	$0, -36(%rbp)
	jmp	.L24
.L26:
	movl	-36(%rbp), %eax
	movslq	%eax, %rdx
	movl	-40(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	je	.L25
	addl	$1, -32(%rbp)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L25:
	addl	$1, -36(%rbp)
.L24:
	movl	n(%rip), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L26
	addl	$1, -40(%rbp)
.L23:
	movl	m(%rip), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L27
	movl	$0, -28(%rbp)
.L31:
	movl	$0, %eax
	call	calc
	movl	%eax, -24(%rbp)
	cmpl	$0, -24(%rbp)
	je	.L34
	movl	-24(%rbp), %eax
	addl	%eax, -28(%rbp)
	movl	-24(%rbp), %eax
	subl	%eax, -32(%rbp)
	cmpl	$0, -32(%rbp)
	je	.L35
	jmp	.L31
.L34:
	nop
	jmp	.L29
.L35:
	nop
.L29:
	movl	-28(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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
	.p2align 4
	.globl	calc
	.type	calc, @function
calc:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	m(%rip), %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
	movl	%eax, -32(%rsp)
	testl	%eax, %eax
	jle	.L17
	movl	n(%rip), %eax
	movl	$0, -16(%rsp)
	leaq	sc(%rip), %r14
	leaq	map(%rip), %rbx
	movl	$0, -36(%rsp)
	movq	%r14, %r12
	leaq	sr(%rip), %r15
	movq	%rbx, %r14
	movl	%eax, -28(%rsp)
	.p2align 4,,10
	.p2align 3
.L3:
	movslq	-28(%rsp), %r13
	xorl	%edx, %edx
	testl	%r13d, %r13d
	jle	.L16
	.p2align 4,,10
	.p2align 3
.L14:
	movl	(%r15,%rdx,4), %r9d
	movl	%edx, %r8d
	leaq	1(%rdx), %rsi
	movl	%r9d, %eax
	addl	(%r12), %eax
	je	.L4
	cmpb	$46, (%r14,%rdx)
	je	.L49
.L4:
	movq	%rsi, %rdx
	cmpq	%r13, %rsi
	jne	.L14
.L16:
	addl	$1, -36(%rsp)
	addq	$4, %r12
	movl	-36(%rsp), %eax
	addq	$503, %r14
	cmpl	-32(%rsp), %eax
	jne	.L3
	movl	-16(%rsp), %eax
	popq	%rbx
	.cfi_remember_state
	.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
	.p2align 4,,10
	.p2align 3
.L49:
	.cfi_restore_state
	movq	$-1, %rax
	movl	$45, %ecx
	leaq	rpos(%rip), %rdi
	xorl	%ebp, %ebp
	rep stosq
	movq	%r13, -24(%rsp)
	movl	%ebp, %eax
	movl	$-1, (%rdi)
	testl	%r9d, %r9d
	jne	.L18
.L51:
	cmpl	$1, %ebp
	jle	.L5
.L18:
	movl	(%r12), %ecx
	testl	%ecx, %ecx
	jne	.L19
	cmpl	$3, %eax
	je	.L45
.L19:
	leaq	mv(%rip), %rax
	movl	(%rax,%rbp,8), %r11d
	addq	$4, %rax
	movl	(%rax,%rbp,8), %eax
	cmpl	$1, %eax
	jne	.L50
	movl	-36(%rsp), %ecx
	movslq	%r11d, %r10
	leaq	map(%rip), %rdi
	imulq	$503, %r10, %r10
	leal	(%r11,%rcx), %eax
	cltq
	imulq	$503, %rax, %rax
	leaq	1(%r10), %rbx
	negq	%r10
	addq	%rsi, %rax
	addq	%rdi, %rax
	movl	%r8d, %edi
.L11:
	addl	%r11d, %ecx
	addl	$1, %edi
	cmpl	%edi, -28(%rsp)
	setle	%r9b
	cmpl	%ecx, -32(%rsp)
	setle	%r13b
	orb	%r13b, %r9b
	jne	.L5
	testl	%ecx, %ecx
	js	.L5
	addq	%rbx, %rax
	movsbq	-1(%rax,%r10), %r9
	cmpb	$46, %r9b
	je	.L11
.L10:
	leaq	rpos(%rip), %rax
	movslq	(%rax,%r9,4), %rax
	testl	%eax, %eax
	js	.L12
	movslq	%ecx, %rcx
	movslq	%edi, %rdi
	leaq	map(%rip), %rbx
	addl	$2, -16(%rsp)
	imulq	$503, %rcx, %r10
	subl	$1, (%r15,%rdi,4)
	leaq	sc(%rip), %r11
	subl	$1, (%r11,%rcx,4)
	subl	$1, (%r11,%rax,4)
	addq	%rbx, %r10
	movb	$46, (%r10,%rdi)
	leaq	cpos(%rip), %rdi
	movslq	(%rdi,%r9,4), %rcx
	imulq	$503, %rax, %rdi
	subl	$1, (%r15,%rcx,4)
	addq	%rbx, %rdi
	movb	$46, (%rdi,%rcx)
.L5:
	addq	$1, %rbp
	cmpq	$4, %rbp
	je	.L45
	movl	(%r15,%rdx,4), %r9d
	movl	%ebp, %eax
	testl	%r9d, %r9d
	je	.L51
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L45:
	movq	-24(%rsp), %r13
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L12:
	leaq	rpos(%rip), %rax
	movl	%ecx, (%rax,%r9,4)
	leaq	cpos(%rip), %rax
	movl	%edi, (%rax,%r9,4)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L50:
	movl	-36(%rsp), %r9d
	movslq	%r11d, %rcx
	movslq	%eax, %rbx
	imulq	$503, %rcx, %r13
	leal	(%rax,%r8), %ecx
	leal	(%r11,%r9), %r10d
	movslq	%ecx, %rcx
	movslq	%r10d, %r10
	imulq	$503, %r10, %r10
	leaq	0(%r13,%rbx), %rdi
	negq	%rbx
	movq	%rdi, -8(%rsp)
	leaq	map(%rip), %rdi
	addq	%rcx, %r10
	movl	%r9d, %ecx
	addq	%rdi, %r10
	movl	%r8d, %edi
.L9:
	addl	%r11d, %ecx
	addl	%eax, %edi
	movl	%ecx, %r9d
	orl	%edi, %r9d
	shrl	$31, %r9d
	cmpl	-32(%rsp), %ecx
	setge	-9(%rsp)
	orb	-9(%rsp), %r9b
	jne	.L5
	cmpl	-28(%rsp), %edi
	jge	.L5
	addq	-8(%rsp), %r10
	movq	%r10, %r9
	subq	%r13, %r9
	movsbq	(%r9,%rbx), %r9
	cmpb	$46, %r9b
	jne	.L10
	jmp	.L9
.L17:
	movl	$0, -16(%rsp)
	movl	-16(%rsp), %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
	.cfi_endproc
.LFE35:
	.size	calc, .-calc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB36:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$10, %esi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	stdin(%rip), %rdx
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	14(%rsp), %rbp
	movq	%rbp, %rdi
	call	fgets@PLT
	leaq	n(%rip), %rcx
	movq	%rbp, %rdi
	xorl	%eax, %eax
	leaq	m(%rip), %rdx
	leaq	.LC0(%rip), %rsi
	call	__isoc99_sscanf@PLT
	movl	m(%rip), %eax
	testl	%eax, %eax
	jle	.L61
	leaq	map(%rip), %r13
	leaq	sc(%rip), %rbp
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
	leaq	4+sr(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L57:
	movq	stdin(%rip), %rdx
	movl	$503, %esi
	movq	%r13, %rdi
	call	fgets@PLT
	movl	n(%rip), %edx
	testl	%edx, %edx
	jle	.L54
	subl	$1, %edx
	leaq	sr(%rip), %rax
	leaq	(%r12,%rdx,4), %rcx
	movq	%r13, %rdx
	.p2align 4,,10
	.p2align 3
.L56:
	cmpb	$46, (%rdx)
	je	.L55
	addl	$1, (%rax)
	addl	$1, %ebx
	addl	$1, 0(%rbp)
.L55:
	addq	$4, %rax
	addq	$1, %rdx
	cmpq	%rcx, %rax
	jne	.L56
.L54:
	addl	$1, %r14d
	addq	$503, %r13
	addq	$4, %rbp
	cmpl	%r14d, m(%rip)
	jg	.L57
.L53:
	xorl	%r12d, %r12d
	jmp	.L59
	.p2align 4,,10
	.p2align 3
.L69:
	addl	%eax, %r12d
	subl	%eax, %ebx
	je	.L58
.L59:
	xorl	%eax, %eax
	call	calc
	testl	%eax, %eax
	jne	.L69
.L58:
	xorl	%eax, %eax
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L70
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L61:
	.cfi_restore_state
	xorl	%ebx, %ebx
	jmp	.L53
.L70:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE36:
	.size	main, .-main
	.globl	sc
	.bss
	.align 32
	.type	sc, @object
	.size	sc, 2004
sc:
	.zero	2004
	.globl	sr
	.align 32
	.type	sr, @object
	.size	sr, 2004
sr:
	.zero	2004
	.globl	cpos
	.align 32
	.type	cpos, @object
	.size	cpos, 364
cpos:
	.zero	364
	.globl	rpos
	.align 32
	.type	rpos, @object
	.size	rpos, 364
rpos:
	.zero	364
	.globl	mv
	.data
	.align 32
	.type	mv, @object
	.size	mv, 32
mv:
	.long	-1
	.long	0
	.long	1
	.long	0
	.long	0
	.long	1
	.long	0
	.long	-1
	.globl	map
	.bss
	.align 32
	.type	map, @object
	.size	map, 252003
map:
	.zero	252003
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.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
	.p2align 4
	.globl	calc
	.type	calc, @function
calc:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	m(%rip), %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
	movl	%eax, -32(%rsp)
	testl	%eax, %eax
	jle	.L17
	movl	n(%rip), %eax
	movl	$0, -16(%rsp)
	leaq	sc(%rip), %r14
	leaq	map(%rip), %rbx
	movl	$0, -36(%rsp)
	movq	%r14, %r12
	leaq	sr(%rip), %r15
	movq	%rbx, %r14
	movl	%eax, -28(%rsp)
	.p2align 4,,10
	.p2align 3
.L3:
	movslq	-28(%rsp), %r13
	xorl	%edx, %edx
	testl	%r13d, %r13d
	jle	.L16
	.p2align 4,,10
	.p2align 3
.L14:
	movl	(%r15,%rdx,4), %r9d
	movl	%edx, %r8d
	leaq	1(%rdx), %rsi
	movl	%r9d, %eax
	addl	(%r12), %eax
	je	.L4
	cmpb	$46, (%r14,%rdx)
	je	.L49
.L4:
	movq	%rsi, %rdx
	cmpq	%r13, %rsi
	jne	.L14
.L16:
	addl	$1, -36(%rsp)
	addq	$4, %r12
	movl	-36(%rsp), %eax
	addq	$503, %r14
	cmpl	-32(%rsp), %eax
	jne	.L3
	movl	-16(%rsp), %eax
	popq	%rbx
	.cfi_remember_state
	.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
	.p2align 4,,10
	.p2align 3
.L49:
	.cfi_restore_state
	movq	$-1, %rax
	movl	$45, %ecx
	leaq	rpos(%rip), %rdi
	xorl	%ebp, %ebp
	rep stosq
	movq	%r13, -24(%rsp)
	movl	%ebp, %eax
	movl	$-1, (%rdi)
	testl	%r9d, %r9d
	jne	.L18
.L51:
	cmpl	$1, %ebp
	jle	.L5
.L18:
	movl	(%r12), %ecx
	testl	%ecx, %ecx
	jne	.L19
	cmpl	$3, %eax
	je	.L45
.L19:
	leaq	mv(%rip), %rax
	movl	(%rax,%rbp,8), %r11d
	addq	$4, %rax
	movl	(%rax,%rbp,8), %eax
	cmpl	$1, %eax
	jne	.L50
	movl	-36(%rsp), %ecx
	movslq	%r11d, %r10
	leaq	map(%rip), %rdi
	imulq	$503, %r10, %r10
	leal	(%r11,%rcx), %eax
	cltq
	imulq	$503, %rax, %rax
	leaq	1(%r10), %rbx
	negq	%r10
	addq	%rsi, %rax
	addq	%rdi, %rax
	movl	%r8d, %edi
.L11:
	addl	%r11d, %ecx
	addl	$1, %edi
	cmpl	%edi, -28(%rsp)
	setle	%r9b
	cmpl	%ecx, -32(%rsp)
	setle	%r13b
	orb	%r13b, %r9b
	jne	.L5
	testl	%ecx, %ecx
	js	.L5
	addq	%rbx, %rax
	movsbq	-1(%rax,%r10), %r9
	cmpb	$46, %r9b
	je	.L11
.L10:
	leaq	rpos(%rip), %rax
	movslq	(%rax,%r9,4), %rax
	testl	%eax, %eax
	js	.L12
	movslq	%ecx, %rcx
	movslq	%edi, %rdi
	leaq	map(%rip), %rbx
	addl	$2, -16(%rsp)
	imulq	$503, %rcx, %r10
	subl	$1, (%r15,%rdi,4)
	leaq	sc(%rip), %r11
	subl	$1, (%r11,%rcx,4)
	subl	$1, (%r11,%rax,4)
	addq	%rbx, %r10
	movb	$46, (%r10,%rdi)
	leaq	cpos(%rip), %rdi
	movslq	(%rdi,%r9,4), %rcx
	imulq	$503, %rax, %rdi
	subl	$1, (%r15,%rcx,4)
	addq	%rbx, %rdi
	movb	$46, (%rdi,%rcx)
.L5:
	addq	$1, %rbp
	cmpq	$4, %rbp
	je	.L45
	movl	(%r15,%rdx,4), %r9d
	movl	%ebp, %eax
	testl	%r9d, %r9d
	je	.L51
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L45:
	movq	-24(%rsp), %r13
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L12:
	leaq	rpos(%rip), %rax
	movl	%ecx, (%rax,%r9,4)
	leaq	cpos(%rip), %rax
	movl	%edi, (%rax,%r9,4)
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L50:
	movl	-36(%rsp), %r9d
	movslq	%r11d, %rcx
	movslq	%eax, %rbx
	imulq	$503, %rcx, %r13
	leal	(%rax,%r8), %ecx
	leal	(%r11,%r9), %r10d
	movslq	%ecx, %rcx
	movslq	%r10d, %r10
	imulq	$503, %r10, %r10
	leaq	0(%r13,%rbx), %rdi
	negq	%rbx
	movq	%rdi, -8(%rsp)
	leaq	map(%rip), %rdi
	addq	%rcx, %r10
	movl	%r9d, %ecx
	addq	%rdi, %r10
	movl	%r8d, %edi
.L9:
	addl	%r11d, %ecx
	addl	%eax, %edi
	movl	%ecx, %r9d
	orl	%edi, %r9d
	shrl	$31, %r9d
	cmpl	-32(%rsp), %ecx
	setge	-9(%rsp)
	orb	-9(%rsp), %r9b
	jne	.L5
	cmpl	-28(%rsp), %edi
	jge	.L5
	addq	-8(%rsp), %r10
	movq	%r10, %r9
	subq	%r13, %r9
	movsbq	(%r9,%rbx), %r9
	cmpb	$46, %r9b
	jne	.L10
	jmp	.L9
.L17:
	movl	$0, -16(%rsp)
	movl	-16(%rsp), %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
	.cfi_endproc
.LFE35:
	.size	calc, .-calc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB36:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$10, %esi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	stdin(%rip), %rdx
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	14(%rsp), %rbp
	movq	%rbp, %rdi
	call	fgets@PLT
	leaq	n(%rip), %rcx
	movq	%rbp, %rdi
	xorl	%eax, %eax
	leaq	m(%rip), %rdx
	leaq	.LC0(%rip), %rsi
	call	__isoc99_sscanf@PLT
	movl	m(%rip), %eax
	testl	%eax, %eax
	jle	.L61
	leaq	map(%rip), %r13
	leaq	sc(%rip), %rbp
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
	leaq	4+sr(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L57:
	movq	stdin(%rip), %rdx
	movl	$503, %esi
	movq	%r13, %rdi
	call	fgets@PLT
	movl	n(%rip), %edx
	testl	%edx, %edx
	jle	.L54
	subl	$1, %edx
	leaq	sr(%rip), %rax
	leaq	(%r12,%rdx,4), %rcx
	movq	%r13, %rdx
	.p2align 4,,10
	.p2align 3
.L56:
	cmpb	$46, (%rdx)
	je	.L55
	addl	$1, (%rax)
	addl	$1, %ebx
	addl	$1, 0(%rbp)
.L55:
	addq	$4, %rax
	addq	$1, %rdx
	cmpq	%rcx, %rax
	jne	.L56
.L54:
	addl	$1, %r14d
	addq	$503, %r13
	addq	$4, %rbp
	cmpl	%r14d, m(%rip)
	jg	.L57
.L53:
	xorl	%r12d, %r12d
	jmp	.L59
	.p2align 4,,10
	.p2align 3
.L69:
	addl	%eax, %r12d
	subl	%eax, %ebx
	je	.L58
.L59:
	xorl	%eax, %eax
	call	calc
	testl	%eax, %eax
	jne	.L69
.L58:
	xorl	%eax, %eax
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L70
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L61:
	.cfi_restore_state
	xorl	%ebx, %ebx
	jmp	.L53
.L70:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE36:
	.size	main, .-main
	.globl	sc
	.bss
	.align 32
	.type	sc, @object
	.size	sc, 2004
sc:
	.zero	2004
	.globl	sr
	.align 32
	.type	sr, @object
	.size	sr, 2004
sr:
	.zero	2004
	.globl	cpos
	.align 32
	.type	cpos, @object
	.size	cpos, 364
cpos:
	.zero	364
	.globl	rpos
	.align 32
	.type	rpos, @object
	.size	rpos, 364
rpos:
	.zero	364
	.globl	mv
	.data
	.align 32
	.type	mv, @object
	.size	mv, 32
mv:
	.long	-1
	.long	0
	.long	1
	.long	0
	.long	0
	.long	1
	.long	0
	.long	-1
	.globl	map
	.bss
	.align 32
	.type	map, @object
	.size	map, 252003
map:
	.zero	252003
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.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:

// AOJ 2299:   Tiles are Colorful
// 2017.12.10

#include <stdio.h>
#include <string.h>

int m, n;
char map[501][503];
int mv[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};
int rpos['Z'+1], cpos['Z'+1];
int sr[501], sc[501];

int calc()
{
	int r, c, i, r2, c2, a, ans = 0;
	for (r = 0; r < m; r++) for (c = 0; c < n; c++) 
		if ((sr[c] + sc[r]) && map[r][c] == '.' ) {
			memset(rpos, -1, sizeof(rpos));

		    for (i = 0; i < 4; i++) {
				if (!sr[c]) { if (i < 2) continue; }
				if (!sc[r]) { if (i > 2) continue; }

				r2 = r, c2 = c;
				while (1) {
					r2 += mv[i][0], c2 += mv[i][1];
					if (r2 < 0 || r2 >= m || c2 < 0 || c2 >= n) break;
					if (map[r2][c2] == '.') continue;

	                a = map[r2][c2];
					if (rpos[a] >= 0) {
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
						r2 = rpos[a], c2 = cpos[a];
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
	                    ans += 2;
					} else rpos[a] = r2, cpos[a] = c2;
					break;
				}
            }
        }

	return ans;
}

int main()
{
	int r, c, t, k, ans;
	char buf[10];

    fgets(buf, 10, stdin);
	sscanf(buf, "%d%d", &m, &n);
	for (k = 0, r = 0; r < m; r++) {
		fgets(map[r], 503, stdin);
		for (c = 0; c < n; c++) {
			if (map[r][c] != '.') k++, sr[c]++, sc[r]++;
		}
	}
	ans = 0;
	while (1) {
		if (!(t = calc())) break;
		ans += t, k -= t;
		if (!k) break;
	}
	printf("%d\n", ans);
	return 0;
}
5 7
NBTUUOR
QT.SZRQ
SANAGIP
LMDGZBM
KLKIODP
 5 0
NBTUUOR
QT.SZRQ
PIGANAS
LMDGZBM
PDOIKKL
 5 7
OUTUBOR
QT.SZRQ
SANAGIP
LMDGZBM
KLKIODP
 5 7
NBTUUOR
QT.SZSQ
ASNAGIP
MBYGDML
KKLIODP
 3 7
NUTUBOR
RT.SZQQ
RANCGIP
MLZGDMB
LDOIKPK
 5 7
NUTUBOR
QT.SZRQ
SANAGIP
LMDGZBM
LKKIODP
 5 7
NUTUBOR
QT.SZRQ
TANAGIP
LMDGZBM
LKKIODP
 3 7
NUTUBOR
ST.SZQQ
RANCGIP
MLZGDMB
LCOIKPK
 5 7
NBTUUOR
QT.SZRQ
SANAGIP
LMDGZBM
LKKIODP
 5 3
NBTUUOR
QT.SZRQ
SANAGIP
LMDGZBM
LKKIODP

2
 0
 4
 14
 6
 30
 26
 8
 2
 2

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

```c
// AOJ 2299:   Tiles are Colorful
// 2017.12.10

#include <stdio.h>
#include <string.h>

int m, n;
char map[501][503];
int mv[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};
int rpos['Z'+1], cpos['Z'+1];
int sr[501], sc[501];

int calc()
{
	int r, c, i, r2, c2, a, ans = 0;
	for (r = 0; r < m; r++) for (c = 0; c < n; c++) 
		if ((sr[c] + sc[r]) && map[r][c] == '.' ) {
			memset(rpos, -1, sizeof(rpos));

		    for (i = 0; i < 4; i++) {
				if (!sr[c]) { if (i < 2) continue; }
				if (!sc[r]) { if (i > 2) continue; }

				r2 = r, c2 = c;
				while (1) {
					r2 += mv[i][0], c2 += mv[i][1];
					if (r2 < 0 || r2 >= m || c2 < 0 || c2 >= n) break;
					if (map[r2][c2] == '.') continue;

	                a = map[r2][c2];
					if (rpos[a] >= 0) {
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
						r2 = rpos[a], c2 = cpos[a];
	                    map[r2][c2] = '.', sr[c2]--, sc[r2]--;
	                    ans += 2;
					} else rpos[a] = r2, cpos[a] = c2;
					break;
				}
            }
        }

	return ans;
}

int main()
{
	int r, c, t, k, ans;
	char buf[10];

    fgets(buf, 10, stdin);
	sscanf(buf, "%d%d", &m, &n);
	for (k = 0, r = 0; r < m; r++) {
		fgets(map[r], 503, stdin);
		for (c = 0; c < n; c++) {
			if (map[r][c] != '.') k++, sr[c]++, sc[r]++;
		}
	}
	ans = 0;
	while (1) {
		if (!(t = calc())) break;
		ans += t, k -= t;
		if (!k) break;
	}
	printf("%d\n", ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	m
	.bss
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 252003
map:
	.zero	252003
	.globl	mv
	.data
	.align 32
	.type	mv, @object
	.size	mv, 32
mv:
	.long	-1
	.long	0
	.long	1
	.long	0
	.long	0
	.long	1
	.long	0
	.long	-1
	.globl	rpos
	.bss
	.align 32
	.type	rpos, @object
	.size	rpos, 364
rpos:
	.zero	364
	.globl	cpos
	.align 32
	.type	cpos, @object
	.size	cpos, 364
cpos:
	.zero	364
	.globl	sr
	.align 32
	.type	sr, @object
	.size	sr, 2004
sr:
	.zero	2004
	.globl	sc
	.align 32
	.type	sc, @object
	.size	sc, 2004
sc:
	.zero	2004
	.text
	.globl	calc
	.type	calc, @function
calc:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	$0, -8(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L2
.L16:
	movl	$0, -24(%rbp)
	jmp	.L3
.L15:
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	testl	%eax, %eax
	je	.L4
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	jne	.L4
	movl	$364, %edx
	movl	$-1, %esi
	leaq	rpos(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, -20(%rbp)
	jmp	.L5
.L14:
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L6
	cmpl	$1, -20(%rbp)
	jle	.L19
.L6:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L8
	cmpl	$2, -20(%rbp)
	jg	.L20
.L8:
	movl	-28(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
.L13:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	mv(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -16(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	4+mv(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -12(%rbp)
	cmpl	$0, -16(%rbp)
	js	.L7
	movl	m(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jge	.L7
	cmpl	$0, -12(%rbp)
	js	.L7
	movl	n(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L7
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	je	.L21
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	rpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	js	.L11
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movb	$46, (%rax)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	rpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movb	$46, (%rax)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$2, -8(%rbp)
	jmp	.L7
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	rpos(%rip), %rdx
	movl	-16(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cpos(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	jmp	.L7
.L21:
	nop
	jmp	.L13
.L19:
	nop
	jmp	.L7
.L20:
	nop
.L7:
	addl	$1, -20(%rbp)
.L5:
	cmpl	$3, -20(%rbp)
	jle	.L14
.L4:
	addl	$1, -24(%rbp)
.L3:
	movl	n(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L15
	addl	$1, -28(%rbp)
.L2:
	movl	m(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L16
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rdx
	leaq	-18(%rbp), %rax
	movl	$10, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	leaq	-18(%rbp), %rax
	leaq	n(%rip), %rdx
	movq	%rdx, %rcx
	leaq	m(%rip), %rdx
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_sscanf@PLT
	movl	$0, -32(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L23
.L27:
	movq	stdin(%rip), %rax
	movl	-40(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$503, %rdx, %rdx
	leaq	map(%rip), %rcx
	addq	%rdx, %rcx
	movq	%rax, %rdx
	movl	$503, %esi
	movq	%rcx, %rdi
	call	fgets@PLT
	movl	$0, -36(%rbp)
	jmp	.L24
.L26:
	movl	-36(%rbp), %eax
	movslq	%eax, %rdx
	movl	-40(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	je	.L25
	addl	$1, -32(%rbp)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L25:
	addl	$1, -36(%rbp)
.L24:
	movl	n(%rip), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L26
	addl	$1, -40(%rbp)
.L23:
	movl	m(%rip), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L27
	movl	$0, -28(%rbp)
.L31:
	movl	$0, %eax
	call	calc
	movl	%eax, -24(%rbp)
	cmpl	$0, -24(%rbp)
	je	.L34
	movl	-24(%rbp), %eax
	addl	%eax, -28(%rbp)
	movl	-24(%rbp), %eax
	subl	%eax, -32(%rbp)
	cmpl	$0, -32(%rbp)
	je	.L35
	jmp	.L31
.L34:
	nop
	jmp	.L29
.L35:
	nop
.L29:
	movl	-28(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	map
	.align 32
	.type	map, @object
	.size	map, 252003
map:
	.zero	252003
	.globl	mv
	.data
	.align 32
	.type	mv, @object
	.size	mv, 32
mv:
	.long	-1
	.long	0
	.long	1
	.long	0
	.long	0
	.long	1
	.long	0
	.long	-1
	.globl	rpos
	.bss
	.align 32
	.type	rpos, @object
	.size	rpos, 364
rpos:
	.zero	364
	.globl	cpos
	.align 32
	.type	cpos, @object
	.size	cpos, 364
cpos:
	.zero	364
	.globl	sr
	.align 32
	.type	sr, @object
	.size	sr, 2004
sr:
	.zero	2004
	.globl	sc
	.align 32
	.type	sc, @object
	.size	sc, 2004
sc:
	.zero	2004
	.text
	.globl	calc
	.type	calc, @function
calc:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movl	$0, -8(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L2
.L16:
	movl	$0, -24(%rbp)
	jmp	.L3
.L15:
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	testl	%eax, %eax
	je	.L4
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	jne	.L4
	movl	$364, %edx
	movl	$-1, %esi
	leaq	rpos(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$0, -20(%rbp)
	jmp	.L5
.L14:
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L6
	cmpl	$1, -20(%rbp)
	jle	.L19
.L6:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L8
	cmpl	$2, -20(%rbp)
	jg	.L20
.L8:
	movl	-28(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
.L13:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	mv(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -16(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,8), %rdx
	leaq	4+mv(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -12(%rbp)
	cmpl	$0, -16(%rbp)
	js	.L7
	movl	m(%rip), %eax
	cmpl	%eax, -16(%rbp)
	jge	.L7
	cmpl	$0, -12(%rbp)
	js	.L7
	movl	n(%rip), %eax
	cmpl	%eax, -12(%rbp)
	jge	.L7
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	je	.L21
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	rpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	js	.L11
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movb	$46, (%rax)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	rpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	cpos(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movl	-16(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movb	$46, (%rax)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	-1(%rax), %ecx
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$2, -8(%rbp)
	jmp	.L7
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	rpos(%rip), %rdx
	movl	-16(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	cpos(%rip), %rdx
	movl	-12(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	jmp	.L7
.L21:
	nop
	jmp	.L13
.L19:
	nop
	jmp	.L7
.L20:
	nop
.L7:
	addl	$1, -20(%rbp)
.L5:
	cmpl	$3, -20(%rbp)
	jle	.L14
.L4:
	addl	$1, -24(%rbp)
.L3:
	movl	n(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L15
	addl	$1, -28(%rbp)
.L2:
	movl	m(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L16
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	calc, .-calc
	.section	.rodata
.LC0:
	.string	"%d%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB1:
	.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
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rdx
	leaq	-18(%rbp), %rax
	movl	$10, %esi
	movq	%rax, %rdi
	call	fgets@PLT
	leaq	-18(%rbp), %rax
	leaq	n(%rip), %rdx
	movq	%rdx, %rcx
	leaq	m(%rip), %rdx
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_sscanf@PLT
	movl	$0, -32(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L23
.L27:
	movq	stdin(%rip), %rax
	movl	-40(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$503, %rdx, %rdx
	leaq	map(%rip), %rcx
	addq	%rdx, %rcx
	movq	%rax, %rdx
	movl	$503, %esi
	movq	%rcx, %rdi
	call	fgets@PLT
	movl	$0, -36(%rbp)
	jmp	.L24
.L26:
	movl	-36(%rbp), %eax
	movslq	%eax, %rdx
	movl	-40(%rbp), %eax
	cltq
	imulq	$503, %rax, %rax
	addq	%rax, %rdx
	leaq	map(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$46, %al
	je	.L25
	addl	$1, -32(%rbp)
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sr(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	(%rdx,%rax), %eax
	leal	1(%rax), %ecx
	movl	-40(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	sc(%rip), %rax
	movl	%ecx, (%rdx,%rax)
.L25:
	addl	$1, -36(%rbp)
.L24:
	movl	n(%rip), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L26
	addl	$1, -40(%rbp)
.L23:
	movl	m(%rip), %eax
	cmpl	%eax, -40(%rbp)
	jl	.L27
	movl	$0, -28(%rbp)
.L31:
	movl	$0, %eax
	call	calc
	movl	%eax, -24(%rbp)
	cmpl	$0, -24(%rbp)
	je	.L34
	movl	-24(%rbp), %eax
	addl	%eax, -28(%rbp)
	movl	-24(%rbp), %eax
	subl	%eax, -32(%rbp)
	cmpl	$0, -32(%rbp)
	je	.L35
	jmp	.L31
.L34:
	nop
	jmp	.L29
.L35:
	nop
.L29:
	movl	-28(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.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:
