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

```c
// AOJ 0560: Planetary Exploration
// 2017.9.30 bal4u@uu

#include <stdio.h>

int sum[3][1002][1002];
char buf[1002];
char tr['Z'];

int main()
{
	int m, n, k, i, r, c, r1, c1, r2, c2, ans;
	char *b;

	tr['J'] = 0, tr['O'] = 1, tr['I'] = 2;
	scanf("%d%d%d", &m, &n, &k);
	for (r = 1; r <= m; r++) {
		scanf("%s", buf);
		for (b = buf, c = 1; c <= n; c++, b++) {
			for (i = 0; i < 3; i++)
				sum[i][r][c] = sum[i][r-1][c] + (i == tr[*b]);
		}
	}
	while (k-- > 0) {
		scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
		for (i = 0; i < 3; i++) {
			if (i > 0) putchar(' ');
			for (ans = 0, c = c1; c <= c2; c++) 
				ans += sum[i][r2][c] - sum[i][r1-1][c];
			printf("%d", ans);
		}
		putchar('\n');
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	sum
	.bss
	.align 32
	.type	sum, @object
	.size	sum, 12048048
sum:
	.zero	12048048
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 1002
buf:
	.zero	1002
	.globl	tr
	.align 32
	.type	tr, @object
	.size	tr, 90
tr:
	.zero	90
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d%d%d%d"
.LC3:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movb	$0, 74+tr(%rip)
	movb	$1, 79+tr(%rip)
	movb	$2, 73+tr(%rip)
	leaq	-52(%rbp), %rcx
	leaq	-56(%rbp), %rdx
	leaq	-60(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -28(%rbp)
	jmp	.L2
.L7:
	leaq	buf(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	buf(%rip), %rax
	movq	%rax, -16(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L3
.L6:
	movl	$0, -32(%rbp)
	jmp	.L4
.L5:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rsi
	movl	-32(%rbp), %eax
	movslq	%eax, %rdx
	movslq	%ecx, %rax
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movq	-16(%rbp), %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	cltq
	leaq	tr(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	cmpl	%eax, -32(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rsi
	movl	-32(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -32(%rbp)
.L4:
	cmpl	$2, -32(%rbp)
	jle	.L5
	addl	$1, -24(%rbp)
	addq	$1, -16(%rbp)
.L3:
	movl	-56(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L6
	addl	$1, -28(%rbp)
.L2:
	movl	-60(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jle	.L7
	jmp	.L8
.L14:
	leaq	-36(%rbp), %rsi
	leaq	-40(%rbp), %rcx
	leaq	-44(%rbp), %rdx
	leaq	-48(%rbp), %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L9
.L13:
	cmpl	$0, -32(%rbp)
	jle	.L10
	movl	$32, %edi
	call	putchar@PLT
.L10:
	movl	$0, -20(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -24(%rbp)
	jmp	.L11
.L12:
	movl	-40(%rbp), %eax
	movl	-24(%rbp), %edx
	movslq	%edx, %rcx
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	cltq
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-48(%rbp), %edx
	leal	-1(%rdx), %esi
	movl	-24(%rbp), %edx
	movslq	%edx, %rdi
	movl	-32(%rbp), %edx
	movslq	%edx, %rcx
	movslq	%esi, %rdx
	imulq	$1004004, %rcx, %rcx
	imulq	$1002, %rdx, %rdx
	addq	%rcx, %rdx
	addq	%rdi, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	sum(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	addl	%eax, -20(%rbp)
	addl	$1, -24(%rbp)
.L11:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L12
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -32(%rbp)
.L9:
	cmpl	$2, -32(%rbp)
	jle	.L13
	movl	$10, %edi
	call	putchar@PLT
.L8:
	movl	-52(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -52(%rbp)
	testl	%eax, %eax
	jg	.L14
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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	"%s"
.LC2:
	.string	"%d%d%d%d"
.LC3:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$2, %edx
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	buf(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	$1, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	tr(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	4+sum(%rip), %rbx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rcx
	movw	%dx, 73+tr(%rip)
	leaq	28(%rsp), %rsi
	leaq	32(%rsp), %rdx
	movb	$1, 79+tr(%rip)
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L7
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%r14, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	32(%rsp), %r8
	leaq	4008(%rbx), %r9
	testl	%r8d, %r8d
	jle	.L9
	movq	%r9, %rdx
	addq	%r14, %r8
	leaq	buf(%rip), %rcx
	movq	%rbx, %rax
	.p2align 4,,10
	.p2align 3
.L8:
	movsbq	(%rcx), %rsi
	xorl	%edi, %edi
	movsbl	(%r12,%rsi), %esi
	testl	%esi, %esi
	sete	%dil
	addl	(%rax), %edi
	movl	%edi, (%rdx)
	xorl	%edi, %edi
	cmpl	$1, %esi
	sete	%dil
	addl	4016016(%rax), %edi
	cmpl	$2, %esi
	sete	%sil
	addq	$1, %rcx
	addq	$4, %rax
	addq	$4, %rdx
	movl	%edi, 4016012(%rdx)
	movzbl	%sil, %esi
	addl	8032028(%rax), %esi
	movl	%esi, 8032028(%rdx)
	cmpq	%r8, %rcx
	jne	.L8
.L9:
	addl	$1, %r13d
	movq	%r9, %rbx
	cmpl	%r13d, 28(%rsp)
	jge	.L6
.L7:
	movl	36(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 36(%rsp)
	testl	%eax, %eax
	jle	.L4
	leaq	44(%rsp), %rax
	leaq	52(%rsp), %r12
	movq	%rax, 8(%rsp)
	leaq	40(%rsp), %rax
	leaq	48(%rsp), %rbp
	movq	%rax, (%rsp)
	leaq	.LC3(%rip), %rbx
	leaq	sum(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L3:
	movq	8(%rsp), %rdx
	movq	(%rsp), %rsi
	movq	%r12, %r8
	movq	%rbp, %rcx
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	xorl	%r14d, %r14d
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ecx
	movl	52(%rsp), %r8d
	cmpl	%ecx, %r8d
	jl	.L18
.L32:
	movslq	40(%rsp), %rax
	movl	%r8d, %edx
	movslq	48(%rsp), %rsi
	subl	%ecx, %edx
	leal	-1(%rax), %edi
	leal	1(%rdx), %r9d
	cmpl	$2, %edx
	jbe	.L19
	imulq	$1002, %rsi, %rdx
	movslq	%ecx, %r10
	pxor	%xmm1, %xmm1
	imulq	$1002, %rax, %rax
	addq	%r10, %rdx
	addq	%r10, %rax
	movl	%r9d, %r10d
	addq	%r15, %rdx
	addq	%r15, %rax
	shrl	$2, %r10d
	leaq	0(%r13,%rdx,4), %rdx
	leaq	-4008(%r13,%rax,4), %r11
	salq	$4, %r10
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L13:
	movdqu	(%rdx,%rax), %xmm0
	movdqu	(%r11,%rax), %xmm2
	addq	$16, %rax
	psubd	%xmm2, %xmm0
	paddd	%xmm0, %xmm1
	cmpq	%rax, %r10
	jne	.L13
	movdqa	%xmm1, %xmm0
	movl	%r9d, %eax
	psrldq	$8, %xmm0
	andl	$-4, %eax
	paddd	%xmm0, %xmm1
	addl	%eax, %ecx
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %edx
	cmpl	%r9d, %eax
	je	.L11
.L12:
	movslq	%r14d, %rax
	imulq	$1002, %rsi, %rsi
	movslq	%edi, %rdi
	movslq	%ecx, %r9
	imulq	$1004004, %rax, %rax
	imulq	$1002, %rdi, %rdi
	addq	%rax, %rsi
	addq	%rdi, %rax
	leaq	(%rsi,%r9), %r10
	leal	1(%rcx), %edi
	addq	%rax, %r9
	addl	0(%r13,%r10,4), %edx
	subl	0(%r13,%r9,4), %edx
	cmpl	%edi, %r8d
	jl	.L11
	movslq	%edi, %rdi
	addl	$2, %ecx
	leaq	(%rsi,%rdi), %r9
	addq	%rax, %rdi
	addl	0(%r13,%r9,4), %edx
	subl	0(%r13,%rdi,4), %edx
	cmpl	%ecx, %r8d
	jl	.L11
	movslq	%ecx, %rcx
	addq	%rcx, %rsi
	addq	%rcx, %rax
	addl	0(%r13,%rsi,4), %edx
	subl	0(%r13,%rax,4), %edx
.L11:
	movq	%rbx, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__printf_chk@PLT
	addq	$1004004, %r15
	movq	stdout(%rip), %rsi
	cmpl	$3, %r14d
	je	.L31
	movl	$32, %edi
	call	putc@PLT
	movl	44(%rsp), %ecx
	movl	52(%rsp), %r8d
	cmpl	%ecx, %r8d
	jge	.L32
.L18:
	xorl	%edx, %edx
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L31:
	movl	$10, %edi
	call	putc@PLT
	movl	36(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 36(%rsp)
	testl	%eax, %eax
	jg	.L3
.L4:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L33
	addq	$72, %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
.L19:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L12
.L33:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	tr
	.bss
	.align 32
	.type	tr, @object
	.size	tr, 90
tr:
	.zero	90
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 1002
buf:
	.zero	1002
	.globl	sum
	.align 32
	.type	sum, @object
	.size	sum, 12048048
sum:
	.zero	12048048
	.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	"%s"
.LC2:
	.string	"%d%d%d%d"
.LC3:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$2, %edx
	leaq	.LC0(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	buf(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	$1, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	tr(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	.LC1(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	4+sum(%rip), %rbx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %rcx
	movw	%dx, 73+tr(%rip)
	leaq	28(%rsp), %rsi
	leaq	32(%rsp), %rdx
	movb	$1, 79+tr(%rip)
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L7
	.p2align 4,,10
	.p2align 3
.L6:
	movq	%r14, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	32(%rsp), %r8
	leaq	4008(%rbx), %r9
	testl	%r8d, %r8d
	jle	.L9
	movq	%r9, %rdx
	addq	%r14, %r8
	leaq	buf(%rip), %rcx
	movq	%rbx, %rax
	.p2align 4,,10
	.p2align 3
.L8:
	movsbq	(%rcx), %rsi
	xorl	%edi, %edi
	movsbl	(%r12,%rsi), %esi
	testl	%esi, %esi
	sete	%dil
	addl	(%rax), %edi
	movl	%edi, (%rdx)
	xorl	%edi, %edi
	cmpl	$1, %esi
	sete	%dil
	addl	4016016(%rax), %edi
	cmpl	$2, %esi
	sete	%sil
	addq	$1, %rcx
	addq	$4, %rax
	addq	$4, %rdx
	movl	%edi, 4016012(%rdx)
	movzbl	%sil, %esi
	addl	8032028(%rax), %esi
	movl	%esi, 8032028(%rdx)
	cmpq	%r8, %rcx
	jne	.L8
.L9:
	addl	$1, %r13d
	movq	%r9, %rbx
	cmpl	%r13d, 28(%rsp)
	jge	.L6
.L7:
	movl	36(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 36(%rsp)
	testl	%eax, %eax
	jle	.L4
	leaq	44(%rsp), %rax
	leaq	52(%rsp), %r12
	movq	%rax, 8(%rsp)
	leaq	40(%rsp), %rax
	leaq	48(%rsp), %rbp
	movq	%rax, (%rsp)
	leaq	.LC3(%rip), %rbx
	leaq	sum(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L3:
	movq	8(%rsp), %rdx
	movq	(%rsp), %rsi
	movq	%r12, %r8
	movq	%rbp, %rcx
	leaq	.LC2(%rip), %rdi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	xorl	%r14d, %r14d
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ecx
	movl	52(%rsp), %r8d
	cmpl	%ecx, %r8d
	jl	.L18
.L32:
	movslq	40(%rsp), %rax
	movl	%r8d, %edx
	movslq	48(%rsp), %rsi
	subl	%ecx, %edx
	leal	-1(%rax), %edi
	leal	1(%rdx), %r9d
	cmpl	$2, %edx
	jbe	.L19
	imulq	$1002, %rsi, %rdx
	movslq	%ecx, %r10
	pxor	%xmm1, %xmm1
	imulq	$1002, %rax, %rax
	addq	%r10, %rdx
	addq	%r10, %rax
	movl	%r9d, %r10d
	addq	%r15, %rdx
	addq	%r15, %rax
	shrl	$2, %r10d
	leaq	0(%r13,%rdx,4), %rdx
	leaq	-4008(%r13,%rax,4), %r11
	salq	$4, %r10
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L13:
	movdqu	(%rdx,%rax), %xmm0
	movdqu	(%r11,%rax), %xmm2
	addq	$16, %rax
	psubd	%xmm2, %xmm0
	paddd	%xmm0, %xmm1
	cmpq	%rax, %r10
	jne	.L13
	movdqa	%xmm1, %xmm0
	movl	%r9d, %eax
	psrldq	$8, %xmm0
	andl	$-4, %eax
	paddd	%xmm0, %xmm1
	addl	%eax, %ecx
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %edx
	cmpl	%r9d, %eax
	je	.L11
.L12:
	movslq	%r14d, %rax
	imulq	$1002, %rsi, %rsi
	movslq	%edi, %rdi
	movslq	%ecx, %r9
	imulq	$1004004, %rax, %rax
	imulq	$1002, %rdi, %rdi
	addq	%rax, %rsi
	addq	%rdi, %rax
	leaq	(%rsi,%r9), %r10
	leal	1(%rcx), %edi
	addq	%rax, %r9
	addl	0(%r13,%r10,4), %edx
	subl	0(%r13,%r9,4), %edx
	cmpl	%edi, %r8d
	jl	.L11
	movslq	%edi, %rdi
	addl	$2, %ecx
	leaq	(%rsi,%rdi), %r9
	addq	%rax, %rdi
	addl	0(%r13,%r9,4), %edx
	subl	0(%r13,%rdi,4), %edx
	cmpl	%ecx, %r8d
	jl	.L11
	movslq	%ecx, %rcx
	addq	%rcx, %rsi
	addq	%rcx, %rax
	addl	0(%r13,%rsi,4), %edx
	subl	0(%r13,%rax,4), %edx
.L11:
	movq	%rbx, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__printf_chk@PLT
	addq	$1004004, %r15
	movq	stdout(%rip), %rsi
	cmpl	$3, %r14d
	je	.L31
	movl	$32, %edi
	call	putc@PLT
	movl	44(%rsp), %ecx
	movl	52(%rsp), %r8d
	cmpl	%ecx, %r8d
	jge	.L32
.L18:
	xorl	%edx, %edx
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L31:
	movl	$10, %edi
	call	putc@PLT
	movl	36(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 36(%rsp)
	testl	%eax, %eax
	jg	.L3
.L4:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L33
	addq	$72, %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
.L19:
	.cfi_restore_state
	xorl	%edx, %edx
	jmp	.L12
.L33:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	tr
	.bss
	.align 32
	.type	tr, @object
	.size	tr, 90
tr:
	.zero	90
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 1002
buf:
	.zero	1002
	.globl	sum
	.align 32
	.type	sum, @object
	.size	sum, 12048048
sum:
	.zero	12048048
	.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 0560: Planetary Exploration
// 2017.9.30 bal4u@uu

#include <stdio.h>

int sum[3][1002][1002];
char buf[1002];
char tr['Z'];

int main()
{
	int m, n, k, i, r, c, r1, c1, r2, c2, ans;
	char *b;

	tr['J'] = 0, tr['O'] = 1, tr['I'] = 2;
	scanf("%d%d%d", &m, &n, &k);
	for (r = 1; r <= m; r++) {
		scanf("%s", buf);
		for (b = buf, c = 1; c <= n; c++, b++) {
			for (i = 0; i < 3; i++)
				sum[i][r][c] = sum[i][r-1][c] + (i == tr[*b]);
		}
	}
	while (k-- > 0) {
		scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
		for (i = 0; i < 3; i++) {
			if (i > 0) putchar(' ');
			for (ans = 0, c = c1; c <= c2; c++) 
				ans += sum[i][r2][c] - sum[i][r1-1][c];
			printf("%d", ans);
		}
		putchar('\n');
	}
	return 0;
}
4 7
4
JIOJOIJ
IOJOIJO
JOIJOOI
OOJJIJO
5 5 4 7
2 2 3 6
2 2 2 2
1 1 4 7
 4 7
4
JIOJOIJ
OJIOJOI
JOIJOOI
OOJJIJO
5 5 4 7
2 2 3 6
2 2 2 2
1 1 4 7
 4 7
4
JIOJOIJ
OJIOJOI
JOIJOOI
OOJJIJO
5 7 4 7
2 2 3 6
2 2 2 2
1 1 1 7
 4 7
4
JIOJOIJ
OJIOJOI
JOIJOOI
OOJJIJO
5 7 4 7
2 2 3 6
2 3 2 2
1 1 1 7
 4 7
4
JIOJOIJ
IOJOIJO
JOIJOOI
OOJJIJO
3 5 4 6
2 2 3 6
2 2 2 2
1 1 4 7
 4 7
4
JIOJOIJ
OJIOJOI
JOIJOOI
OOJJIJO
5 5 4 7
2 2 3 6
2 2 2 2
1 1 3 7
 4 7
4
JIOJOIJ
OJIOJOI
JOIJOOI
OOJJIJO
5 7 4 7
2 2 3 6
2 2 2 1
1 1 4 7
 4 7
4
JIOJOIJ
OIJOJOI
JOIJOOI
OOJJIJO
5 7 4 7
2 2 3 6
2 2 2 2
1 1 1 7
 4 7
4
JIOJOIJ
OJIOJOI
JOIJOOI
OOJJIJO
2 5 4 7
2 2 3 6
2 2 2 2
1 1 3 7
 4 7
4
JIOJOIJ
JIJOOOI
JOIJOOI
OOJJIJO
5 7 4 7
2 2 3 6
2 2 2 2
1 1 1 7

0 0 0
3 5 2
0 1 0
10 11 7
 0 0 0
3 5 2
1 0 0
10 11 7
 0 0 0
3 5 2
1 0 0
3 2 2
 0 0 0
3 5 2
0 0 0
3 2 2
 1 2 1
3 5 2
0 1 0
10 11 7
 0 0 0
3 5 2
1 0 0
7 8 6
 0 0 0
3 5 2
0 0 0
10 11 7
 0 0 0
3 5 2
0 0 1
3 2 2
 2 4 3
3 5 2
1 0 0
7 8 6
 0 0 0
2 6 2
0 0 1
3 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 0560: Planetary Exploration
// 2017.9.30 bal4u@uu

#include <stdio.h>

int sum[3][1002][1002];
char buf[1002];
char tr['Z'];

int main()
{
	int m, n, k, i, r, c, r1, c1, r2, c2, ans;
	char *b;

	tr['J'] = 0, tr['O'] = 1, tr['I'] = 2;
	scanf("%d%d%d", &m, &n, &k);
	for (r = 1; r <= m; r++) {
		scanf("%s", buf);
		for (b = buf, c = 1; c <= n; c++, b++) {
			for (i = 0; i < 3; i++)
				sum[i][r][c] = sum[i][r-1][c] + (i == tr[*b]);
		}
	}
	while (k-- > 0) {
		scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
		for (i = 0; i < 3; i++) {
			if (i > 0) putchar(' ');
			for (ans = 0, c = c1; c <= c2; c++) 
				ans += sum[i][r2][c] - sum[i][r1-1][c];
			printf("%d", ans);
		}
		putchar('\n');
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	sum
	.bss
	.align 32
	.type	sum, @object
	.size	sum, 12048048
sum:
	.zero	12048048
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 1002
buf:
	.zero	1002
	.globl	tr
	.align 32
	.type	tr, @object
	.size	tr, 90
tr:
	.zero	90
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d%d%d%d"
.LC3:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movb	$0, 74+tr(%rip)
	movb	$1, 79+tr(%rip)
	movb	$2, 73+tr(%rip)
	leaq	-52(%rbp), %rcx
	leaq	-56(%rbp), %rdx
	leaq	-60(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -28(%rbp)
	jmp	.L2
.L7:
	leaq	buf(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	buf(%rip), %rax
	movq	%rax, -16(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L3
.L6:
	movl	$0, -32(%rbp)
	jmp	.L4
.L5:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rsi
	movl	-32(%rbp), %eax
	movslq	%eax, %rdx
	movslq	%ecx, %rax
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movq	-16(%rbp), %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	cltq
	leaq	tr(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	cmpl	%eax, -32(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rsi
	movl	-32(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -32(%rbp)
.L4:
	cmpl	$2, -32(%rbp)
	jle	.L5
	addl	$1, -24(%rbp)
	addq	$1, -16(%rbp)
.L3:
	movl	-56(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L6
	addl	$1, -28(%rbp)
.L2:
	movl	-60(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jle	.L7
	jmp	.L8
.L14:
	leaq	-36(%rbp), %rsi
	leaq	-40(%rbp), %rcx
	leaq	-44(%rbp), %rdx
	leaq	-48(%rbp), %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L9
.L13:
	cmpl	$0, -32(%rbp)
	jle	.L10
	movl	$32, %edi
	call	putchar@PLT
.L10:
	movl	$0, -20(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -24(%rbp)
	jmp	.L11
.L12:
	movl	-40(%rbp), %eax
	movl	-24(%rbp), %edx
	movslq	%edx, %rcx
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	cltq
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-48(%rbp), %edx
	leal	-1(%rdx), %esi
	movl	-24(%rbp), %edx
	movslq	%edx, %rdi
	movl	-32(%rbp), %edx
	movslq	%edx, %rcx
	movslq	%esi, %rdx
	imulq	$1004004, %rcx, %rcx
	imulq	$1002, %rdx, %rdx
	addq	%rcx, %rdx
	addq	%rdi, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	sum(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	addl	%eax, -20(%rbp)
	addl	$1, -24(%rbp)
.L11:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L12
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -32(%rbp)
.L9:
	cmpl	$2, -32(%rbp)
	jle	.L13
	movl	$10, %edi
	call	putchar@PLT
.L8:
	movl	-52(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -52(%rbp)
	testl	%eax, %eax
	jg	.L14
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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	sum
	.bss
	.align 32
	.type	sum, @object
	.size	sum, 12048048
sum:
	.zero	12048048
	.globl	buf
	.align 32
	.type	buf, @object
	.size	buf, 1002
buf:
	.zero	1002
	.globl	tr
	.align 32
	.type	tr, @object
	.size	tr, 90
tr:
	.zero	90
	.section	.rodata
.LC0:
	.string	"%d%d%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d%d%d%d"
.LC3:
	.string	"%d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movb	$0, 74+tr(%rip)
	movb	$1, 79+tr(%rip)
	movb	$2, 73+tr(%rip)
	leaq	-52(%rbp), %rcx
	leaq	-56(%rbp), %rdx
	leaq	-60(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -28(%rbp)
	jmp	.L2
.L7:
	leaq	buf(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	buf(%rip), %rax
	movq	%rax, -16(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L3
.L6:
	movl	$0, -32(%rbp)
	jmp	.L4
.L5:
	movl	-28(%rbp), %eax
	leal	-1(%rax), %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rsi
	movl	-32(%rbp), %eax
	movslq	%eax, %rdx
	movslq	%ecx, %rax
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movq	-16(%rbp), %rax
	movzbl	(%rax), %eax
	movsbl	%al, %eax
	cltq
	leaq	tr(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %eax
	cmpl	%eax, -32(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, %ecx
	movl	-24(%rbp), %eax
	movslq	%eax, %rsi
	movl	-32(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rsi, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -32(%rbp)
.L4:
	cmpl	$2, -32(%rbp)
	jle	.L5
	addl	$1, -24(%rbp)
	addq	$1, -16(%rbp)
.L3:
	movl	-56(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L6
	addl	$1, -28(%rbp)
.L2:
	movl	-60(%rbp), %eax
	cmpl	%eax, -28(%rbp)
	jle	.L7
	jmp	.L8
.L14:
	leaq	-36(%rbp), %rsi
	leaq	-40(%rbp), %rcx
	leaq	-44(%rbp), %rdx
	leaq	-48(%rbp), %rax
	movq	%rsi, %r8
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L9
.L13:
	cmpl	$0, -32(%rbp)
	jle	.L10
	movl	$32, %edi
	call	putchar@PLT
.L10:
	movl	$0, -20(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -24(%rbp)
	jmp	.L11
.L12:
	movl	-40(%rbp), %eax
	movl	-24(%rbp), %edx
	movslq	%edx, %rcx
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	cltq
	imulq	$1004004, %rdx, %rdx
	imulq	$1002, %rax, %rax
	addq	%rdx, %rax
	addq	%rcx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	sum(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-48(%rbp), %edx
	leal	-1(%rdx), %esi
	movl	-24(%rbp), %edx
	movslq	%edx, %rdi
	movl	-32(%rbp), %edx
	movslq	%edx, %rcx
	movslq	%esi, %rdx
	imulq	$1004004, %rcx, %rcx
	imulq	$1002, %rdx, %rdx
	addq	%rcx, %rdx
	addq	%rdi, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	sum(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	addl	%eax, -20(%rbp)
	addl	$1, -24(%rbp)
.L11:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L12
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -32(%rbp)
.L9:
	cmpl	$2, -32(%rbp)
	jle	.L13
	movl	$10, %edi
	call	putchar@PLT
.L8:
	movl	-52(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -52(%rbp)
	testl	%eax, %eax
	jg	.L14
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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:
