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

```c
// AOJ 2952 Hokkaido University Easy
// 2019.8.8 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

#define ABS(x)    ((x)>=0?(x):-(x))

int H, W;
char a[32][32];

int main()
{
	int r, c, r2, c2, dr, dc, ans;
	
	H = in(), W = in();
	for (r = 0; r < H; r++) ins(a[r]);
	ans = 0;
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) if (a[r][c] == 'B') {
		for (r2 = H-1; r2 >= r; r2--) {
			dr = ABS(r2 - r);
			if (dr+W <= ans) goto next;
			for (c2 = W-1; c2 >= 0; c2--) if (a[r2][c2] == 'B') {
				dc = ABS(c2-c);
				if (dr + dc > ans) ans = dr + dc;
			}
		}
	next:;
	}
	printf("%d\n", ans);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.globl	ins
	.type	ins, @function
ins:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
.L5:
	call	getchar_unlocked@PLT
	movl	%eax, %edx
	movq	-8(%rbp), %rax
	movb	%dl, (%rax)
	movq	-8(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -8(%rbp)
	movzbl	(%rax), %eax
	cmpb	$32, %al
	jg	.L5
	movq	-8(%rbp), %rax
	subq	$1, %rax
	movb	$0, (%rax)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	ins, .-ins
	.globl	H
	.bss
	.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	a
	.align 32
	.type	a, @object
	.size	a, 1024
a:
	.zero	1024
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.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, %eax
	call	in
	movl	%eax, H(%rip)
	movl	$0, %eax
	call	in
	movl	%eax, W(%rip)
	movl	$0, -28(%rbp)
	jmp	.L7
.L8:
	movl	-28(%rbp), %eax
	cltq
	salq	$5, %rax
	movq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	call	ins
	addl	$1, -28(%rbp)
.L7:
	movl	H(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L8
	movl	$0, -12(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L9
.L20:
	movl	$0, -24(%rbp)
	jmp	.L10
.L19:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	salq	$5, %rax
	addq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$66, %al
	jne	.L11
	movl	H(%rip), %eax
	subl	$1, %eax
	movl	%eax, -20(%rbp)
	jmp	.L12
.L18:
	movl	-20(%rbp), %eax
	subl	-28(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	W(%rip), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jge	.L22
	movl	W(%rip), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L15
.L17:
	movl	-16(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$5, %rax
	addq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$66, %al
	jne	.L16
	movl	-16(%rbp), %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jge	.L16
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -12(%rbp)
.L16:
	subl	$1, -16(%rbp)
.L15:
	cmpl	$0, -16(%rbp)
	jns	.L17
	subl	$1, -20(%rbp)
.L12:
	movl	-20(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jge	.L18
	jmp	.L11
.L14:
.L22:
	nop
.L11:
	addl	$1, -24(%rbp)
.L10:
	movl	W(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L19
	addl	$1, -28(%rbp)
.L9:
	movl	H(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L20
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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	in
	.type	in, @function
in:
.LFB23:
	.cfi_startproc
	endbr64
	movq	stdin(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L11
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L3:
	xorl	%r12d, %r12d
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L1
.L5:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L7:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L4
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L1
	movq	stdin(%rip), %rdi
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L1:
	movl	%r12d, %eax
	popq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	in, .-in
	.p2align 4
	.globl	ins
	.type	ins, @function
ins:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L13:
	leaq	1(%rax), %rdx
	addq	$1, %rbx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jle	.L15
.L16:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	cmpq	16(%rdi), %rax
	jb	.L13
	call	__uflow@PLT
	addq	$1, %rbx
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jg	.L16
.L15:
	movb	$0, -1(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	ins, .-ins
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	call	in
	movl	%eax, H(%rip)
	xorl	%eax, %eax
	call	in
	movl	H(%rip), %edx
	movl	%eax, W(%rip)
	testl	%edx, %edx
	jle	.L19
	leaq	a(%rip), %rax
	xorl	%r12d, %r12d
	movq	%rax, 8(%rsp)
	movq	%rax, %r13
	movq	%rax, %rbp
	.p2align 4,,10
	.p2align 3
.L24:
	movq	%r13, %rbx
.L44:
	movq	stdin(%rip), %rdi
	jmp	.L23
	.p2align 4,,10
	.p2align 3
.L20:
	leaq	1(%rax), %rdx
	addq	$1, %rbx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jle	.L22
.L23:
	movq	8(%rdi), %rax
	cmpq	16(%rdi), %rax
	jb	.L20
	call	__uflow@PLT
	addq	$1, %rbx
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jg	.L44
	.p2align 4,,10
	.p2align 3
.L22:
	movl	H(%rip), %eax
	addl	$1, %r12d
	movb	$0, -1(%rbx)
	addq	$32, %r13
	cmpl	%r12d, %eax
	jg	.L24
	testl	%eax, %eax
	jle	.L19
	leal	-1(%rax), %edi
	movslq	W(%rip), %rcx
	xorl	%r8d, %r8d
	xorl	%ebx, %ebx
	movslq	%edi, %rdx
	movl	%edi, 4(%rsp)
	movl	$-1, %r15d
	salq	$5, %rdx
	leal	-1(%rax,%rcx), %eax
	movl	%ecx, (%rsp)
	movl	%ecx, %r14d
	addq	%rcx, %rdx
	movl	%eax, 28(%rsp)
	notl	%r14d
	leaq	0(%rbp,%rdx), %rdi
	movl	%ecx, %ebp
	movq	%rdi, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L25:
	movl	28(%rsp), %eax
	movq	8(%rsp), %r11
	movl	$-1, %esi
	leal	1(%r15), %r13d
	subl	%ebx, %eax
	movl	%eax, 24(%rsp)
	movl	(%rsp), %eax
	testl	%eax, %eax
	jg	.L31
	jmp	.L34
	.p2align 4,,10
	.p2align 3
.L26:
	subl	$1, %esi
	addq	$1, %r11
	cmpl	%r14d, %esi
	je	.L34
.L31:
	cmpb	$66, (%r11)
	jne	.L26
	cmpl	24(%rsp), %r8d
	jge	.L26
	movl	(%rsp), %eax
	movq	16(%rsp), %r10
	movl	4(%rsp), %edi
	leal	(%rsi,%rax), %r12d
	.p2align 4,,10
	.p2align 3
.L27:
	leal	0(%r13,%rdi), %r9d
	movl	%r12d, %eax
	movq	%r10, %rdx
	.p2align 4,,10
	.p2align 3
.L29:
	cmpb	$66, -1(%rdx)
	jne	.L28
	movl	%eax, %ecx
	negl	%ecx
	cmovs	%eax, %ecx
	addl	%r9d, %ecx
	cmpl	%ecx, %r8d
	cmovl	%ecx, %r8d
.L28:
	subl	$1, %eax
	subq	$1, %rdx
	cmpl	%esi, %eax
	jne	.L29
	subl	$1, %edi
	cmpl	%ebx, %edi
	jl	.L26
	leal	(%rdi,%rbp), %eax
	subq	$32, %r10
	cmpl	%eax, %r8d
	jl	.L27
	subl	$1, %esi
	addq	$1, %r11
	cmpl	%r14d, %esi
	jne	.L31
	.p2align 4,,10
	.p2align 3
.L34:
	addq	$32, 8(%rsp)
	addl	$1, %ebx
	subl	$1, %ebp
	subl	$1, %r15d
	cmpl	4(%rsp), %ebx
	jle	.L25
.L32:
	movl	%r8d, %edx
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	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
.L19:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L32
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 1024
a:
	.zero	1024
	.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
	.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	in
	.type	in, @function
in:
.LFB23:
	.cfi_startproc
	endbr64
	movq	stdin(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	8(%rdi), %rax
	movq	16(%rdi), %rcx
	cmpq	%rcx, %rax
	jnb	.L11
	leaq	1(%rax), %rdx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
.L3:
	xorl	%r12d, %r12d
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L4:
	leaq	1(%rdx), %rax
	movq	%rax, 8(%rdi)
	movzbl	(%rdx), %eax
	cmpl	$47, %eax
	jle	.L1
.L5:
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
.L7:
	leal	(%r12,%r12,4), %esi
	andl	$15, %eax
	leal	(%rax,%rsi,2), %r12d
	cmpq	%rcx, %rdx
	jb	.L4
	call	__uflow@PLT
	cmpl	$47, %eax
	jle	.L1
	movq	stdin(%rip), %rdi
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L1:
	movl	%r12d, %eax
	popq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	.cfi_restore_state
	call	__uflow@PLT
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rdx
	movq	16(%rdi), %rcx
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	in, .-in
	.p2align 4
	.globl	ins
	.type	ins, @function
ins:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L13:
	leaq	1(%rax), %rdx
	addq	$1, %rbx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jle	.L15
.L16:
	movq	stdin(%rip), %rdi
	movq	8(%rdi), %rax
	cmpq	16(%rdi), %rax
	jb	.L13
	call	__uflow@PLT
	addq	$1, %rbx
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jg	.L16
.L15:
	movb	$0, -1(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE24:
	.size	ins, .-ins
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	call	in
	movl	%eax, H(%rip)
	xorl	%eax, %eax
	call	in
	movl	H(%rip), %edx
	movl	%eax, W(%rip)
	testl	%edx, %edx
	jle	.L19
	leaq	a(%rip), %rax
	xorl	%r12d, %r12d
	movq	%rax, 8(%rsp)
	movq	%rax, %r13
	movq	%rax, %rbp
	.p2align 4,,10
	.p2align 3
.L24:
	movq	%r13, %rbx
.L44:
	movq	stdin(%rip), %rdi
	jmp	.L23
	.p2align 4,,10
	.p2align 3
.L20:
	leaq	1(%rax), %rdx
	addq	$1, %rbx
	movq	%rdx, 8(%rdi)
	movzbl	(%rax), %eax
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jle	.L22
.L23:
	movq	8(%rdi), %rax
	cmpq	16(%rdi), %rax
	jb	.L20
	call	__uflow@PLT
	addq	$1, %rbx
	movb	%al, -1(%rbx)
	cmpb	$32, %al
	jg	.L44
	.p2align 4,,10
	.p2align 3
.L22:
	movl	H(%rip), %eax
	addl	$1, %r12d
	movb	$0, -1(%rbx)
	addq	$32, %r13
	cmpl	%r12d, %eax
	jg	.L24
	testl	%eax, %eax
	jle	.L19
	leal	-1(%rax), %edi
	movslq	W(%rip), %rcx
	xorl	%r8d, %r8d
	xorl	%ebx, %ebx
	movslq	%edi, %rdx
	movl	%edi, 4(%rsp)
	movl	$-1, %r15d
	salq	$5, %rdx
	leal	-1(%rax,%rcx), %eax
	movl	%ecx, (%rsp)
	movl	%ecx, %r14d
	addq	%rcx, %rdx
	movl	%eax, 28(%rsp)
	notl	%r14d
	leaq	0(%rbp,%rdx), %rdi
	movl	%ecx, %ebp
	movq	%rdi, 16(%rsp)
	.p2align 4,,10
	.p2align 3
.L25:
	movl	28(%rsp), %eax
	movq	8(%rsp), %r11
	movl	$-1, %esi
	leal	1(%r15), %r13d
	subl	%ebx, %eax
	movl	%eax, 24(%rsp)
	movl	(%rsp), %eax
	testl	%eax, %eax
	jg	.L31
	jmp	.L34
	.p2align 4,,10
	.p2align 3
.L26:
	subl	$1, %esi
	addq	$1, %r11
	cmpl	%r14d, %esi
	je	.L34
.L31:
	cmpb	$66, (%r11)
	jne	.L26
	cmpl	24(%rsp), %r8d
	jge	.L26
	movl	(%rsp), %eax
	movq	16(%rsp), %r10
	movl	4(%rsp), %edi
	leal	(%rsi,%rax), %r12d
	.p2align 4,,10
	.p2align 3
.L27:
	leal	0(%r13,%rdi), %r9d
	movl	%r12d, %eax
	movq	%r10, %rdx
	.p2align 4,,10
	.p2align 3
.L29:
	cmpb	$66, -1(%rdx)
	jne	.L28
	movl	%eax, %ecx
	negl	%ecx
	cmovs	%eax, %ecx
	addl	%r9d, %ecx
	cmpl	%ecx, %r8d
	cmovl	%ecx, %r8d
.L28:
	subl	$1, %eax
	subq	$1, %rdx
	cmpl	%esi, %eax
	jne	.L29
	subl	$1, %edi
	cmpl	%ebx, %edi
	jl	.L26
	leal	(%rdi,%rbp), %eax
	subq	$32, %r10
	cmpl	%eax, %r8d
	jl	.L27
	subl	$1, %esi
	addq	$1, %r11
	cmpl	%r14d, %esi
	jne	.L31
	.p2align 4,,10
	.p2align 3
.L34:
	addq	$32, 8(%rsp)
	addl	$1, %ebx
	subl	$1, %ebp
	subl	$1, %r15d
	cmpl	4(%rsp), %ebx
	jle	.L25
.L32:
	movl	%r8d, %edx
	leaq	.LC0(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	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
.L19:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L32
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 1024
a:
	.zero	1024
	.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
	.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 2952 Hokkaido University Easy
// 2019.8.8 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

#define ABS(x)    ((x)>=0?(x):-(x))

int H, W;
char a[32][32];

int main()
{
	int r, c, r2, c2, dr, dc, ans;
	
	H = in(), W = in();
	for (r = 0; r < H; r++) ins(a[r]);
	ans = 0;
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) if (a[r][c] == 'B') {
		for (r2 = H-1; r2 >= r; r2--) {
			dr = ABS(r2 - r);
			if (dr+W <= ans) goto next;
			for (c2 = W-1; c2 >= 0; c2--) if (a[r2][c2] == 'B') {
				dc = ABS(c2-c);
				if (dr + dc > ans) ans = dr + dc;
			}
		}
	next:;
	}
	printf("%d\n", ans);
	return 0;
}

3 3
A.B
..B
.BB
 3 3
B.B
..B
-BB
 1 3
AB.
.B.
.BB
 3 3
A.B
A..
.CB
 3 3
A.B
..B
.AA
 3 3
A.B
B..
.BB
 3 3
B.B
B..
.BB
 3 3
A.B
.B.
.BB
 3 3
A.B
A..
.BB
 3 3
B.B
A..
.BB

3
 4
 0
 2
 1
 3
 4
 3
 3
 4

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

```c
// AOJ 2952 Hokkaido University Easy
// 2019.8.8 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

#define ABS(x)    ((x)>=0?(x):-(x))

int H, W;
char a[32][32];

int main()
{
	int r, c, r2, c2, dr, dc, ans;
	
	H = in(), W = in();
	for (r = 0; r < H; r++) ins(a[r]);
	ans = 0;
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) if (a[r][c] == 'B') {
		for (r2 = H-1; r2 >= r; r2--) {
			dr = ABS(r2 - r);
			if (dr+W <= ans) goto next;
			for (c2 = W-1; c2 >= 0; c2--) if (a[r2][c2] == 'B') {
				dc = ABS(c2-c);
				if (dr + dc > ans) ans = dr + dc;
			}
		}
	next:;
	}
	printf("%d\n", ans);
	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.globl	ins
	.type	ins, @function
ins:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
.L5:
	call	getchar_unlocked@PLT
	movl	%eax, %edx
	movq	-8(%rbp), %rax
	movb	%dl, (%rax)
	movq	-8(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -8(%rbp)
	movzbl	(%rax), %eax
	cmpb	$32, %al
	jg	.L5
	movq	-8(%rbp), %rax
	subq	$1, %rax
	movb	$0, (%rax)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	ins, .-ins
	.globl	H
	.bss
	.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	a
	.align 32
	.type	a, @object
	.size	a, 1024
a:
	.zero	1024
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.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, %eax
	call	in
	movl	%eax, H(%rip)
	movl	$0, %eax
	call	in
	movl	%eax, W(%rip)
	movl	$0, -28(%rbp)
	jmp	.L7
.L8:
	movl	-28(%rbp), %eax
	cltq
	salq	$5, %rax
	movq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	call	ins
	addl	$1, -28(%rbp)
.L7:
	movl	H(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L8
	movl	$0, -12(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L9
.L20:
	movl	$0, -24(%rbp)
	jmp	.L10
.L19:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	salq	$5, %rax
	addq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$66, %al
	jne	.L11
	movl	H(%rip), %eax
	subl	$1, %eax
	movl	%eax, -20(%rbp)
	jmp	.L12
.L18:
	movl	-20(%rbp), %eax
	subl	-28(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	W(%rip), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jge	.L22
	movl	W(%rip), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L15
.L17:
	movl	-16(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$5, %rax
	addq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$66, %al
	jne	.L16
	movl	-16(%rbp), %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jge	.L16
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -12(%rbp)
.L16:
	subl	$1, -16(%rbp)
.L15:
	cmpl	$0, -16(%rbp)
	jns	.L17
	subl	$1, -20(%rbp)
.L12:
	movl	-20(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jge	.L18
	jmp	.L11
.L14:
.L22:
	nop
.L11:
	addl	$1, -24(%rbp)
.L10:
	movl	W(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L19
	addl	$1, -28(%rbp)
.L9:
	movl	H(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L20
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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	in
	.type	in, @function
in:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	$0, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
.L2:
	movl	-8(%rbp), %edx
	movl	%edx, %eax
	sall	$2, %eax
	addl	%edx, %eax
	addl	%eax, %eax
	movl	%eax, %edx
	movl	-4(%rbp), %eax
	andl	$15, %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	call	getchar_unlocked@PLT
	movl	%eax, -4(%rbp)
	cmpl	$47, -4(%rbp)
	jg	.L2
	movl	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	in, .-in
	.globl	ins
	.type	ins, @function
ins:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movq	%rdi, -8(%rbp)
.L5:
	call	getchar_unlocked@PLT
	movl	%eax, %edx
	movq	-8(%rbp), %rax
	movb	%dl, (%rax)
	movq	-8(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -8(%rbp)
	movzbl	(%rax), %eax
	cmpb	$32, %al
	jg	.L5
	movq	-8(%rbp), %rax
	subq	$1, %rax
	movb	$0, (%rax)
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	ins, .-ins
	.globl	H
	.bss
	.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	a
	.align 32
	.type	a, @object
	.size	a, 1024
a:
	.zero	1024
	.section	.rodata
.LC0:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.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, %eax
	call	in
	movl	%eax, H(%rip)
	movl	$0, %eax
	call	in
	movl	%eax, W(%rip)
	movl	$0, -28(%rbp)
	jmp	.L7
.L8:
	movl	-28(%rbp), %eax
	cltq
	salq	$5, %rax
	movq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rdi
	call	ins
	addl	$1, -28(%rbp)
.L7:
	movl	H(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L8
	movl	$0, -12(%rbp)
	movl	$0, -28(%rbp)
	jmp	.L9
.L20:
	movl	$0, -24(%rbp)
	jmp	.L10
.L19:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-28(%rbp), %eax
	cltq
	salq	$5, %rax
	addq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$66, %al
	jne	.L11
	movl	H(%rip), %eax
	subl	$1, %eax
	movl	%eax, -20(%rbp)
	jmp	.L12
.L18:
	movl	-20(%rbp), %eax
	subl	-28(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	W(%rip), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jge	.L22
	movl	W(%rip), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L15
.L17:
	movl	-16(%rbp), %eax
	movslq	%eax, %rdx
	movl	-20(%rbp), %eax
	cltq
	salq	$5, %rax
	addq	%rax, %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$66, %al
	jne	.L16
	movl	-16(%rbp), %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jge	.L16
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -12(%rbp)
.L16:
	subl	$1, -16(%rbp)
.L15:
	cmpl	$0, -16(%rbp)
	jns	.L17
	subl	$1, -20(%rbp)
.L12:
	movl	-20(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jge	.L18
	jmp	.L11
.L14:
.L22:
	nop
.L11:
	addl	$1, -24(%rbp)
.L10:
	movl	W(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L19
	addl	$1, -28(%rbp)
.L9:
	movl	H(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L20
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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:
