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

```c
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

typedef long long ll;
typedef struct {
	char t, d;
} Query;

ll n, q;
char grid[200005];
Query query[200005];
char buff[200005];

//初期位置を引数に取り、最終的位置を返す。n + 1のとき右に落ち、0のとき左に落ちる
ll simulate(ll position);
ll bin_search(char mode);

//VSのscanf()使わせてくれないやつ嫌い！！
ll input(const char* format, ...);

int main()
{
	ll left, right;

	input("%lld %lld", &n, &q);
	input("%s", grid + 1);
	for (ll i = 0; i < q; i++) {
		input("%c %c", &query[i].t, &query[i].d);
	}

	//printf("%lld : %lld\n", bin_search('L'), bin_search('R'));
	printf("%lld\n", bin_search('R') - bin_search('L') - 1);

	return EXIT_SUCCESS;
}

ll simulate(ll position)
{
	ll i = 0;
	while (i < q && position >= 1 && position <= n) {
		if (query[i].t == grid[position]) {
			if (query[i].d == 'L') {
				position--;
			}
			else if (query[i].d == 'R') {
				position++;
			}
		}

		i++;
	}

	if (position > n) {
		position = n + 1;
	}
	else if (position < 1) {
		position = 0;
	}

	return position;
}

ll bin_search(char mode)
{
	ll valid, invalid;
	ll mid;

	valid = (mode == 'L' ? 0 : n + 1);
	invalid = (mode == 'L' ? n + 1: 0);

	while (llabs(invalid - valid) > 1) {
		mid = (invalid + valid) / 2;

		if (simulate(mid) == (mode == 'L' ? 0 : n + 1)) {
			valid = mid;
		}
		else {
			invalid = mid;
		}
	}

	return valid;
}

ll input(const char* format, ...)
{
	va_list args;
	ll ret_val;

	fgets(buff, sizeof(buff) - 1, stdin);

	va_start(args, format);
	ret_val = vsscanf(buff, format, args);
	va_end(args);

	return ret_val;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	grid
	.align 32
	.type	grid, @object
	.size	grid, 200005
grid:
	.zero	200005
	.globl	query
	.align 32
	.type	query, @object
	.size	query, 400010
query:
	.zero	400010
	.globl	buff
	.align 32
	.type	buff, @object
	.size	buff, 200005
buff:
	.zero	200005
	.section	.rodata
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%c %c"
.LC3:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	leaq	q(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	leaq	1+grid(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	movq	$0, -24(%rbp)
	jmp	.L2
.L3:
	movq	-24(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	query(%rip), %rax
	addq	%rdx, %rax
	leaq	1(%rax), %rdx
	movq	-24(%rbp), %rax
	leaq	(%rax,%rax), %rcx
	leaq	query(%rip), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	addq	$1, -24(%rbp)
.L2:
	movq	q(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jl	.L3
	movl	$82, %edi
	call	bin_search
	movq	%rax, %rbx
	movl	$76, %edi
	call	bin_search
	movq	%rax, %rdx
	movq	%rbx, %rax
	subq	%rdx, %rax
	subq	$1, %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	$0, -8(%rbp)
	jmp	.L6
.L10:
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	query(%rip), %rax
	movzbl	(%rdx,%rax), %edx
	leaq	grid(%rip), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movzbl	(%rax), %eax
	cmpb	%al, %dl
	jne	.L7
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	1+query(%rip), %rax
	movzbl	(%rdx,%rax), %eax
	cmpb	$76, %al
	jne	.L8
	subq	$1, -24(%rbp)
	jmp	.L7
.L8:
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	1+query(%rip), %rax
	movzbl	(%rdx,%rax), %eax
	cmpb	$82, %al
	jne	.L7
	addq	$1, -24(%rbp)
.L7:
	addq	$1, -8(%rbp)
.L6:
	movq	q(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L9
	cmpq	$0, -24(%rbp)
	jle	.L9
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L10
.L9:
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L11
	movq	n(%rip), %rax
	addq	$1, %rax
	movq	%rax, -24(%rbp)
	jmp	.L12
.L11:
	cmpq	$0, -24(%rbp)
	jg	.L12
	movq	$0, -24(%rbp)
.L12:
	movq	-24(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	simulate, .-simulate
	.globl	bin_search
	.type	bin_search, @function
bin_search:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$40, %rsp
	movl	%edi, %eax
	movb	%al, -36(%rbp)
	cmpb	$76, -36(%rbp)
	je	.L15
	movq	n(%rip), %rax
	addq	$1, %rax
	jmp	.L16
.L15:
	movl	$0, %eax
.L16:
	movq	%rax, -24(%rbp)
	cmpb	$76, -36(%rbp)
	jne	.L17
	movq	n(%rip), %rax
	addq	$1, %rax
	jmp	.L18
.L17:
	movl	$0, %eax
.L18:
	movq	%rax, -16(%rbp)
	jmp	.L19
.L23:
	movq	-16(%rbp), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	simulate
	cmpb	$76, -36(%rbp)
	je	.L20
	movq	n(%rip), %rdx
	addq	$1, %rdx
	jmp	.L21
.L20:
	movl	$0, %edx
.L21:
	cmpq	%rax, %rdx
	jne	.L22
	movq	-8(%rbp), %rax
	movq	%rax, -24(%rbp)
	jmp	.L19
.L22:
	movq	-8(%rbp), %rax
	movq	%rax, -16(%rbp)
.L19:
	movq	-16(%rbp), %rax
	subq	-24(%rbp), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	cmpq	$1, %rax
	jg	.L23
	movq	-24(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	bin_search, .-bin_search
	.globl	input
	.type	input, @function
input:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$240, %rsp
	movq	%rdi, -232(%rbp)
	movq	%rsi, -168(%rbp)
	movq	%rdx, -160(%rbp)
	movq	%rcx, -152(%rbp)
	movq	%r8, -144(%rbp)
	movq	%r9, -136(%rbp)
	testb	%al, %al
	je	.L26
	movaps	%xmm0, -128(%rbp)
	movaps	%xmm1, -112(%rbp)
	movaps	%xmm2, -96(%rbp)
	movaps	%xmm3, -80(%rbp)
	movaps	%xmm4, -64(%rbp)
	movaps	%xmm5, -48(%rbp)
	movaps	%xmm6, -32(%rbp)
	movaps	%xmm7, -16(%rbp)
.L26:
	movq	%fs:40, %rax
	movq	%rax, -184(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rax
	movq	%rax, %rdx
	movl	$200004, %esi
	leaq	buff(%rip), %rax
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$8, -208(%rbp)
	movl	$48, -204(%rbp)
	leaq	16(%rbp), %rax
	movq	%rax, -200(%rbp)
	leaq	-176(%rbp), %rax
	movq	%rax, -192(%rbp)
	leaq	-208(%rbp), %rdx
	movq	-232(%rbp), %rax
	movq	%rax, %rsi
	leaq	buff(%rip), %rax
	movq	%rax, %rdi
	call	__isoc99_vsscanf@PLT
	cltq
	movq	%rax, -216(%rbp)
	movq	-216(%rbp), %rax
	movq	-184(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	input, .-input
	.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	"%c %c"
	.text
	.p2align 4
	.type	input.constprop.0, @function
input.constprop.0:
.LFB43:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	subq	$208, %rsp
	.cfi_def_cfa_offset 224
	movq	%rsi, 40(%rsp)
	movq	%rdx, 48(%rsp)
	movq	%rcx, 56(%rsp)
	movq	%r8, 64(%rsp)
	movq	%r9, 72(%rsp)
	testb	%al, %al
	je	.L2
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.L2:
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rdx
	leaq	buff(%rip), %rbp
	movl	$200004, %esi
	movq	%rbp, %rdi
	call	fgets@PLT
	leaq	224(%rsp), %rax
	movq	%rsp, %rdx
	movq	%rbp, %rdi
	movq	%rax, 8(%rsp)
	leaq	.LC0(%rip), %rsi
	leaq	32(%rsp), %rax
	movl	$8, (%rsp)
	movl	$48, 4(%rsp)
	movq	%rax, 16(%rsp)
	call	__isoc99_vsscanf@PLT
	cltq
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L6
	addq	$208, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L6:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE43:
	.size	input.constprop.0, .-input.constprop.0
	.p2align 4
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB40:
	.cfi_startproc
	endbr64
	movq	q(%rip), %rcx
	movq	n(%rip), %rdx
	testq	%rcx, %rcx
	jle	.L10
	leaq	query(%rip), %r8
	xorl	%eax, %eax
	leaq	grid(%rip), %rsi
	leaq	1(%r8), %r10
	testq	%rdi, %rdi
	jg	.L8
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L11:
	addq	$1, %rax
	testq	%rdi, %rdi
	jle	.L10
.L29:
	cmpq	%rcx, %rax
	jge	.L10
.L8:
	cmpq	%rdx, %rdi
	jg	.L14
	movzbl	(%rsi,%rdi), %r11d
	cmpb	%r11b, (%r8,%rax,2)
	jne	.L11
	movzbl	(%r10,%rax,2), %r9d
	cmpb	$76, %r9b
	je	.L28
	cmpb	$82, %r9b
	sete	%r9b
	addq	$1, %rax
	movzbl	%r9b, %r9d
	addq	%r9, %rdi
	testq	%rdi, %rdi
	jg	.L29
	.p2align 4,,10
	.p2align 3
.L10:
	xorl	%eax, %eax
	testq	%rdi, %rdi
	cmovns	%rdi, %rax
	cmpq	%rdx, %rdi
	jg	.L14
	ret
	.p2align 4,,10
	.p2align 3
.L28:
	subq	$1, %rdi
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L14:
	leaq	1(%rdx), %rax
	ret
	.cfi_endproc
.LFE40:
	.size	simulate, .-simulate
	.p2align 4
	.globl	bin_search
	.type	bin_search, @function
bin_search:
.LFB41:
	.cfi_startproc
	endbr64
	movq	n(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	query(%rip), %r8
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	q(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	leaq	1(%rcx), %r13
	leaq	1(%r8), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	cmpb	$76, %dil
	leaq	grid(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %rbx
	cmovne	%r13, %rbp
	cmove	%r13, %rbx
	testq	%rsi, %rsi
	setg	%r14b
	movq	%rbp, %r11
	.p2align 4,,10
	.p2align 3
.L40:
	movq	%rbx, %rdx
	subq	%r11, %rdx
	movq	%rdx, %rax
	negq	%rax
	cmovs	%rdx, %rax
	cmpq	$1, %rax
	jle	.L58
	leaq	(%r11,%rbx), %rax
	movq	%rax, %r9
	shrq	$63, %r9
	addq	%rax, %r9
	sarq	%r9
	cmpq	$1, %rax
	jle	.L46
	movq	%r9, %rdx
	xorl	%eax, %eax
	testb	%r14b, %r14b
	jne	.L33
	jmp	.L46
	.p2align 4,,10
	.p2align 3
.L36:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jle	.L35
.L61:
	testq	%rdx, %rdx
	jle	.L35
.L33:
	cmpq	%rcx, %rdx
	jg	.L59
	movzbl	(%rdi,%rdx), %r10d
	cmpb	%r10b, (%r8,%rax,2)
	jne	.L36
	movzbl	(%r12,%rax,2), %r10d
	cmpb	$76, %r10b
	je	.L60
	cmpb	$82, %r10b
	sete	%r10b
	addq	$1, %rax
	movzbl	%r10b, %r10d
	addq	%r10, %rdx
	cmpq	%rax, %rsi
	jg	.L61
	.p2align 4,,10
	.p2align 3
.L35:
	xorl	%eax, %eax
	testq	%rdx, %rdx
	cmovns	%rdx, %rax
	cmpq	%rcx, %rdx
	cmovg	%r13, %rax
.L39:
	cmpq	%rax, %rbp
	cmovne	%r9, %rbx
	cmove	%r9, %r11
	jmp	.L40
	.p2align 4,,10
	.p2align 3
.L60:
	subq	$1, %rdx
	jmp	.L36
	.p2align 4,,10
	.p2align 3
.L59:
	movq	%r13, %rax
	jmp	.L39
.L46:
	movq	%r9, %rdx
	jmp	.L35
.L58:
	popq	%rbx
	.cfi_def_cfa_offset 40
	movq	%r11, %rax
	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
	.cfi_endproc
.LFE41:
	.size	bin_search, .-bin_search
	.p2align 4
	.globl	input
	.type	input, @function
input:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	subq	$216, %rsp
	.cfi_def_cfa_offset 240
	movq	%rsi, 40(%rsp)
	movq	%rdx, 48(%rsp)
	movq	%rcx, 56(%rsp)
	movq	%r8, 64(%rsp)
	movq	%r9, 72(%rsp)
	testb	%al, %al
	je	.L63
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.L63:
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rdx
	leaq	buff(%rip), %r12
	movl	$200004, %esi
	movq	%r12, %rdi
	call	fgets@PLT
	movq	%rsp, %rdx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	leaq	240(%rsp), %rax
	movl	$8, (%rsp)
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %rax
	movl	$48, 4(%rsp)
	movq	%rax, 16(%rsp)
	call	__isoc99_vsscanf@PLT
	cltq
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L66
	addq	$216, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L66:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.size	input, .-input
	.section	.rodata.str1.1
.LC1:
	.string	"%lld %lld"
.LC2:
	.string	"%s"
.LC3:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	q(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC1(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	input
	xorl	%eax, %eax
	leaq	1+grid(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	input
	cmpq	$0, q(%rip)
	jle	.L70
	leaq	query(%rip), %rbx
	xorl	%ebp, %ebp
	leaq	.LC0(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L69:
	leaq	1(%rbx), %rdx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movq	%r12, %rdi
	call	input.constprop.0
	addq	$1, %rbp
	addq	$2, %rbx
	cmpq	%rbp, q(%rip)
	jg	.L69
.L70:
	movl	$82, %edi
	call	bin_search
	movl	$76, %edi
	movq	%rax, %rbx
	call	bin_search
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	subq	%rax, %rbx
	xorl	%eax, %eax
	leaq	-1(%rbx), %rdx
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.globl	buff
	.bss
	.align 32
	.type	buff, @object
	.size	buff, 200005
buff:
	.zero	200005
	.globl	query
	.align 32
	.type	query, @object
	.size	query, 400010
query:
	.zero	400010
	.globl	grid
	.align 32
	.type	grid, @object
	.size	grid, 200005
grid:
	.zero	200005
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.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	"%c %c"
	.text
	.p2align 4
	.type	input.constprop.0, @function
input.constprop.0:
.LFB43:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	subq	$208, %rsp
	.cfi_def_cfa_offset 224
	movq	%rsi, 40(%rsp)
	movq	%rdx, 48(%rsp)
	movq	%rcx, 56(%rsp)
	movq	%r8, 64(%rsp)
	movq	%r9, 72(%rsp)
	testb	%al, %al
	je	.L2
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.L2:
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rdx
	leaq	buff(%rip), %rbp
	movl	$200004, %esi
	movq	%rbp, %rdi
	call	fgets@PLT
	leaq	224(%rsp), %rax
	movq	%rsp, %rdx
	movq	%rbp, %rdi
	movq	%rax, 8(%rsp)
	leaq	.LC0(%rip), %rsi
	leaq	32(%rsp), %rax
	movl	$8, (%rsp)
	movl	$48, 4(%rsp)
	movq	%rax, 16(%rsp)
	call	__isoc99_vsscanf@PLT
	cltq
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L6
	addq	$208, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L6:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE43:
	.size	input.constprop.0, .-input.constprop.0
	.p2align 4
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB40:
	.cfi_startproc
	endbr64
	movq	q(%rip), %rcx
	movq	n(%rip), %rdx
	testq	%rcx, %rcx
	jle	.L10
	leaq	query(%rip), %r8
	xorl	%eax, %eax
	leaq	grid(%rip), %rsi
	leaq	1(%r8), %r10
	testq	%rdi, %rdi
	jg	.L8
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L11:
	addq	$1, %rax
	testq	%rdi, %rdi
	jle	.L10
.L29:
	cmpq	%rcx, %rax
	jge	.L10
.L8:
	cmpq	%rdx, %rdi
	jg	.L14
	movzbl	(%rsi,%rdi), %r11d
	cmpb	%r11b, (%r8,%rax,2)
	jne	.L11
	movzbl	(%r10,%rax,2), %r9d
	cmpb	$76, %r9b
	je	.L28
	cmpb	$82, %r9b
	sete	%r9b
	addq	$1, %rax
	movzbl	%r9b, %r9d
	addq	%r9, %rdi
	testq	%rdi, %rdi
	jg	.L29
	.p2align 4,,10
	.p2align 3
.L10:
	xorl	%eax, %eax
	testq	%rdi, %rdi
	cmovns	%rdi, %rax
	cmpq	%rdx, %rdi
	jg	.L14
	ret
	.p2align 4,,10
	.p2align 3
.L28:
	subq	$1, %rdi
	jmp	.L11
	.p2align 4,,10
	.p2align 3
.L14:
	leaq	1(%rdx), %rax
	ret
	.cfi_endproc
.LFE40:
	.size	simulate, .-simulate
	.p2align 4
	.globl	bin_search
	.type	bin_search, @function
bin_search:
.LFB41:
	.cfi_startproc
	endbr64
	movq	n(%rip), %rcx
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	query(%rip), %r8
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	q(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	leaq	1(%rcx), %r13
	leaq	1(%r8), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	cmpb	$76, %dil
	leaq	grid(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %rbx
	cmovne	%r13, %rbp
	cmove	%r13, %rbx
	testq	%rsi, %rsi
	setg	%r14b
	movq	%rbp, %r11
	.p2align 4,,10
	.p2align 3
.L40:
	movq	%rbx, %rdx
	subq	%r11, %rdx
	movq	%rdx, %rax
	negq	%rax
	cmovs	%rdx, %rax
	cmpq	$1, %rax
	jle	.L58
	leaq	(%r11,%rbx), %rax
	movq	%rax, %r9
	shrq	$63, %r9
	addq	%rax, %r9
	sarq	%r9
	cmpq	$1, %rax
	jle	.L46
	movq	%r9, %rdx
	xorl	%eax, %eax
	testb	%r14b, %r14b
	jne	.L33
	jmp	.L46
	.p2align 4,,10
	.p2align 3
.L36:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jle	.L35
.L61:
	testq	%rdx, %rdx
	jle	.L35
.L33:
	cmpq	%rcx, %rdx
	jg	.L59
	movzbl	(%rdi,%rdx), %r10d
	cmpb	%r10b, (%r8,%rax,2)
	jne	.L36
	movzbl	(%r12,%rax,2), %r10d
	cmpb	$76, %r10b
	je	.L60
	cmpb	$82, %r10b
	sete	%r10b
	addq	$1, %rax
	movzbl	%r10b, %r10d
	addq	%r10, %rdx
	cmpq	%rax, %rsi
	jg	.L61
	.p2align 4,,10
	.p2align 3
.L35:
	xorl	%eax, %eax
	testq	%rdx, %rdx
	cmovns	%rdx, %rax
	cmpq	%rcx, %rdx
	cmovg	%r13, %rax
.L39:
	cmpq	%rax, %rbp
	cmovne	%r9, %rbx
	cmove	%r9, %r11
	jmp	.L40
	.p2align 4,,10
	.p2align 3
.L60:
	subq	$1, %rdx
	jmp	.L36
	.p2align 4,,10
	.p2align 3
.L59:
	movq	%r13, %rax
	jmp	.L39
.L46:
	movq	%r9, %rdx
	jmp	.L35
.L58:
	popq	%rbx
	.cfi_def_cfa_offset 40
	movq	%r11, %rax
	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
	.cfi_endproc
.LFE41:
	.size	bin_search, .-bin_search
	.p2align 4
	.globl	input
	.type	input, @function
input:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	subq	$216, %rsp
	.cfi_def_cfa_offset 240
	movq	%rsi, 40(%rsp)
	movq	%rdx, 48(%rsp)
	movq	%rcx, 56(%rsp)
	movq	%r8, 64(%rsp)
	movq	%r9, 72(%rsp)
	testb	%al, %al
	je	.L63
	movaps	%xmm0, 80(%rsp)
	movaps	%xmm1, 96(%rsp)
	movaps	%xmm2, 112(%rsp)
	movaps	%xmm3, 128(%rsp)
	movaps	%xmm4, 144(%rsp)
	movaps	%xmm5, 160(%rsp)
	movaps	%xmm6, 176(%rsp)
	movaps	%xmm7, 192(%rsp)
.L63:
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rdx
	leaq	buff(%rip), %r12
	movl	$200004, %esi
	movq	%r12, %rdi
	call	fgets@PLT
	movq	%rsp, %rdx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	leaq	240(%rsp), %rax
	movl	$8, (%rsp)
	movq	%rax, 8(%rsp)
	leaq	32(%rsp), %rax
	movl	$48, 4(%rsp)
	movq	%rax, 16(%rsp)
	call	__isoc99_vsscanf@PLT
	cltq
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L66
	addq	$216, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L66:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.size	input, .-input
	.section	.rodata.str1.1
.LC1:
	.string	"%lld %lld"
.LC2:
	.string	"%s"
.LC3:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	q(%rip), %rdx
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC1(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	input
	xorl	%eax, %eax
	leaq	1+grid(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	input
	cmpq	$0, q(%rip)
	jle	.L70
	leaq	query(%rip), %rbx
	xorl	%ebp, %ebp
	leaq	.LC0(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L69:
	leaq	1(%rbx), %rdx
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movq	%r12, %rdi
	call	input.constprop.0
	addq	$1, %rbp
	addq	$2, %rbx
	cmpq	%rbp, q(%rip)
	jg	.L69
.L70:
	movl	$82, %edi
	call	bin_search
	movl	$76, %edi
	movq	%rax, %rbx
	call	bin_search
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	subq	%rax, %rbx
	xorl	%eax, %eax
	leaq	-1(%rbx), %rdx
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.globl	buff
	.bss
	.align 32
	.type	buff, @object
	.size	buff, 200005
buff:
	.zero	200005
	.globl	query
	.align 32
	.type	query, @object
	.size	query, 400010
query:
	.zero	400010
	.globl	grid
	.align 32
	.type	grid, @object
	.size	grid, 200005
grid:
	.zero	200005
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

typedef long long ll;
typedef struct {
	char t, d;
} Query;

ll n, q;
char grid[200005];
Query query[200005];
char buff[200005];

//初期位置を引数に取り、最終的位置を返す。n + 1のとき右に落ち、0のとき左に落ちる
ll simulate(ll position);
ll bin_search(char mode);

//VSのscanf()使わせてくれないやつ嫌い！！
ll input(const char* format, ...);

int main()
{
	ll left, right;

	input("%lld %lld", &n, &q);
	input("%s", grid + 1);
	for (ll i = 0; i < q; i++) {
		input("%c %c", &query[i].t, &query[i].d);
	}

	//printf("%lld : %lld\n", bin_search('L'), bin_search('R'));
	printf("%lld\n", bin_search('R') - bin_search('L') - 1);

	return EXIT_SUCCESS;
}

ll simulate(ll position)
{
	ll i = 0;
	while (i < q && position >= 1 && position <= n) {
		if (query[i].t == grid[position]) {
			if (query[i].d == 'L') {
				position--;
			}
			else if (query[i].d == 'R') {
				position++;
			}
		}

		i++;
	}

	if (position > n) {
		position = n + 1;
	}
	else if (position < 1) {
		position = 0;
	}

	return position;
}

ll bin_search(char mode)
{
	ll valid, invalid;
	ll mid;

	valid = (mode == 'L' ? 0 : n + 1);
	invalid = (mode == 'L' ? n + 1: 0);

	while (llabs(invalid - valid) > 1) {
		mid = (invalid + valid) / 2;

		if (simulate(mid) == (mode == 'L' ? 0 : n + 1)) {
			valid = mid;
		}
		else {
			invalid = mid;
		}
	}

	return valid;
}

ll input(const char* format, ...)
{
	va_list args;
	ll ret_val;

	fgets(buff, sizeof(buff) - 1, stdin);

	va_start(args, format);
	ret_val = vsscanf(buff, format, args);
	va_end(args);

	return ret_val;
}
10 15
SNCZWRCEWB
B R
R R
E R
W R
Z L
S R
Q L
W L
B R
C L
A L
N L
E R
Z L
R L
 3 4
ACB
A L
B L
B R
A R
 8 3
AABBBDBA
A L
B R
A R
 3 3
ACB
B L
B L
A R
@ S
 3 3
BCA
B L
B L
A R
@ S
 8 0
AABCBDBA
A L
B R
@ S
 8 3
AABCBDBA
C L
B R
A R
 10 15
BWECRWZCNS
B R
R R
E R
W R
Z L
S R
Q L
W L
B R
C L
A L
N L
E R
Z L
R L
 10 0
SNCZWRCEWB
B R
R R
E R
X R
Z L
S R
Q L
W L
B R
C L
B L
N L
E R
Z L
S L
 3 4
CBB
A L
C L
B R
B R

7
 2
 5
 3
 1
 8
 6
 9
 10
 0

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

```c
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

typedef long long ll;
typedef struct {
	char t, d;
} Query;

ll n, q;
char grid[200005];
Query query[200005];
char buff[200005];

//初期位置を引数に取り、最終的位置を返す。n + 1のとき右に落ち、0のとき左に落ちる
ll simulate(ll position);
ll bin_search(char mode);

//VSのscanf()使わせてくれないやつ嫌い！！
ll input(const char* format, ...);

int main()
{
	ll left, right;

	input("%lld %lld", &n, &q);
	input("%s", grid + 1);
	for (ll i = 0; i < q; i++) {
		input("%c %c", &query[i].t, &query[i].d);
	}

	//printf("%lld : %lld\n", bin_search('L'), bin_search('R'));
	printf("%lld\n", bin_search('R') - bin_search('L') - 1);

	return EXIT_SUCCESS;
}

ll simulate(ll position)
{
	ll i = 0;
	while (i < q && position >= 1 && position <= n) {
		if (query[i].t == grid[position]) {
			if (query[i].d == 'L') {
				position--;
			}
			else if (query[i].d == 'R') {
				position++;
			}
		}

		i++;
	}

	if (position > n) {
		position = n + 1;
	}
	else if (position < 1) {
		position = 0;
	}

	return position;
}

ll bin_search(char mode)
{
	ll valid, invalid;
	ll mid;

	valid = (mode == 'L' ? 0 : n + 1);
	invalid = (mode == 'L' ? n + 1: 0);

	while (llabs(invalid - valid) > 1) {
		mid = (invalid + valid) / 2;

		if (simulate(mid) == (mode == 'L' ? 0 : n + 1)) {
			valid = mid;
		}
		else {
			invalid = mid;
		}
	}

	return valid;
}

ll input(const char* format, ...)
{
	va_list args;
	ll ret_val;

	fgets(buff, sizeof(buff) - 1, stdin);

	va_start(args, format);
	ret_val = vsscanf(buff, format, args);
	va_end(args);

	return ret_val;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	grid
	.align 32
	.type	grid, @object
	.size	grid, 200005
grid:
	.zero	200005
	.globl	query
	.align 32
	.type	query, @object
	.size	query, 400010
query:
	.zero	400010
	.globl	buff
	.align 32
	.type	buff, @object
	.size	buff, 200005
buff:
	.zero	200005
	.section	.rodata
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%c %c"
.LC3:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	leaq	q(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	leaq	1+grid(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	movq	$0, -24(%rbp)
	jmp	.L2
.L3:
	movq	-24(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	query(%rip), %rax
	addq	%rdx, %rax
	leaq	1(%rax), %rdx
	movq	-24(%rbp), %rax
	leaq	(%rax,%rax), %rcx
	leaq	query(%rip), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	addq	$1, -24(%rbp)
.L2:
	movq	q(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jl	.L3
	movl	$82, %edi
	call	bin_search
	movq	%rax, %rbx
	movl	$76, %edi
	call	bin_search
	movq	%rax, %rdx
	movq	%rbx, %rax
	subq	%rdx, %rax
	subq	$1, %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	$0, -8(%rbp)
	jmp	.L6
.L10:
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	query(%rip), %rax
	movzbl	(%rdx,%rax), %edx
	leaq	grid(%rip), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movzbl	(%rax), %eax
	cmpb	%al, %dl
	jne	.L7
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	1+query(%rip), %rax
	movzbl	(%rdx,%rax), %eax
	cmpb	$76, %al
	jne	.L8
	subq	$1, -24(%rbp)
	jmp	.L7
.L8:
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	1+query(%rip), %rax
	movzbl	(%rdx,%rax), %eax
	cmpb	$82, %al
	jne	.L7
	addq	$1, -24(%rbp)
.L7:
	addq	$1, -8(%rbp)
.L6:
	movq	q(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L9
	cmpq	$0, -24(%rbp)
	jle	.L9
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L10
.L9:
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L11
	movq	n(%rip), %rax
	addq	$1, %rax
	movq	%rax, -24(%rbp)
	jmp	.L12
.L11:
	cmpq	$0, -24(%rbp)
	jg	.L12
	movq	$0, -24(%rbp)
.L12:
	movq	-24(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	simulate, .-simulate
	.globl	bin_search
	.type	bin_search, @function
bin_search:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$40, %rsp
	movl	%edi, %eax
	movb	%al, -36(%rbp)
	cmpb	$76, -36(%rbp)
	je	.L15
	movq	n(%rip), %rax
	addq	$1, %rax
	jmp	.L16
.L15:
	movl	$0, %eax
.L16:
	movq	%rax, -24(%rbp)
	cmpb	$76, -36(%rbp)
	jne	.L17
	movq	n(%rip), %rax
	addq	$1, %rax
	jmp	.L18
.L17:
	movl	$0, %eax
.L18:
	movq	%rax, -16(%rbp)
	jmp	.L19
.L23:
	movq	-16(%rbp), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	simulate
	cmpb	$76, -36(%rbp)
	je	.L20
	movq	n(%rip), %rdx
	addq	$1, %rdx
	jmp	.L21
.L20:
	movl	$0, %edx
.L21:
	cmpq	%rax, %rdx
	jne	.L22
	movq	-8(%rbp), %rax
	movq	%rax, -24(%rbp)
	jmp	.L19
.L22:
	movq	-8(%rbp), %rax
	movq	%rax, -16(%rbp)
.L19:
	movq	-16(%rbp), %rax
	subq	-24(%rbp), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	cmpq	$1, %rax
	jg	.L23
	movq	-24(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	bin_search, .-bin_search
	.globl	input
	.type	input, @function
input:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$240, %rsp
	movq	%rdi, -232(%rbp)
	movq	%rsi, -168(%rbp)
	movq	%rdx, -160(%rbp)
	movq	%rcx, -152(%rbp)
	movq	%r8, -144(%rbp)
	movq	%r9, -136(%rbp)
	testb	%al, %al
	je	.L26
	movaps	%xmm0, -128(%rbp)
	movaps	%xmm1, -112(%rbp)
	movaps	%xmm2, -96(%rbp)
	movaps	%xmm3, -80(%rbp)
	movaps	%xmm4, -64(%rbp)
	movaps	%xmm5, -48(%rbp)
	movaps	%xmm6, -32(%rbp)
	movaps	%xmm7, -16(%rbp)
.L26:
	movq	%fs:40, %rax
	movq	%rax, -184(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rax
	movq	%rax, %rdx
	movl	$200004, %esi
	leaq	buff(%rip), %rax
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$8, -208(%rbp)
	movl	$48, -204(%rbp)
	leaq	16(%rbp), %rax
	movq	%rax, -200(%rbp)
	leaq	-176(%rbp), %rax
	movq	%rax, -192(%rbp)
	leaq	-208(%rbp), %rdx
	movq	-232(%rbp), %rax
	movq	%rax, %rsi
	leaq	buff(%rip), %rax
	movq	%rax, %rdi
	call	__isoc99_vsscanf@PLT
	cltq
	movq	%rax, -216(%rbp)
	movq	-216(%rbp), %rax
	movq	-184(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	input, .-input
	.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	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	q
	.align 8
	.type	q, @object
	.size	q, 8
q:
	.zero	8
	.globl	grid
	.align 32
	.type	grid, @object
	.size	grid, 200005
grid:
	.zero	200005
	.globl	query
	.align 32
	.type	query, @object
	.size	query, 400010
query:
	.zero	400010
	.globl	buff
	.align 32
	.type	buff, @object
	.size	buff, 200005
buff:
	.zero	200005
	.section	.rodata
.LC0:
	.string	"%lld %lld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%c %c"
.LC3:
	.string	"%lld\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 3, -24
	leaq	q(%rip), %rax
	movq	%rax, %rdx
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	leaq	1+grid(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	movq	$0, -24(%rbp)
	jmp	.L2
.L3:
	movq	-24(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	query(%rip), %rax
	addq	%rdx, %rax
	leaq	1(%rax), %rdx
	movq	-24(%rbp), %rax
	leaq	(%rax,%rax), %rcx
	leaq	query(%rip), %rax
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	input
	addq	$1, -24(%rbp)
.L2:
	movq	q(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jl	.L3
	movl	$82, %edi
	call	bin_search
	movq	%rax, %rbx
	movl	$76, %edi
	call	bin_search
	movq	%rax, %rdx
	movq	%rbx, %rax
	subq	%rdx, %rax
	subq	$1, %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movq	$0, -8(%rbp)
	jmp	.L6
.L10:
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	query(%rip), %rax
	movzbl	(%rdx,%rax), %edx
	leaq	grid(%rip), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movzbl	(%rax), %eax
	cmpb	%al, %dl
	jne	.L7
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	1+query(%rip), %rax
	movzbl	(%rdx,%rax), %eax
	cmpb	$76, %al
	jne	.L8
	subq	$1, -24(%rbp)
	jmp	.L7
.L8:
	movq	-8(%rbp), %rax
	leaq	(%rax,%rax), %rdx
	leaq	1+query(%rip), %rax
	movzbl	(%rdx,%rax), %eax
	cmpb	$82, %al
	jne	.L7
	addq	$1, -24(%rbp)
.L7:
	addq	$1, -8(%rbp)
.L6:
	movq	q(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jge	.L9
	cmpq	$0, -24(%rbp)
	jle	.L9
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L10
.L9:
	movq	n(%rip), %rax
	cmpq	%rax, -24(%rbp)
	jle	.L11
	movq	n(%rip), %rax
	addq	$1, %rax
	movq	%rax, -24(%rbp)
	jmp	.L12
.L11:
	cmpq	$0, -24(%rbp)
	jg	.L12
	movq	$0, -24(%rbp)
.L12:
	movq	-24(%rbp), %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	simulate, .-simulate
	.globl	bin_search
	.type	bin_search, @function
bin_search:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$40, %rsp
	movl	%edi, %eax
	movb	%al, -36(%rbp)
	cmpb	$76, -36(%rbp)
	je	.L15
	movq	n(%rip), %rax
	addq	$1, %rax
	jmp	.L16
.L15:
	movl	$0, %eax
.L16:
	movq	%rax, -24(%rbp)
	cmpb	$76, -36(%rbp)
	jne	.L17
	movq	n(%rip), %rax
	addq	$1, %rax
	jmp	.L18
.L17:
	movl	$0, %eax
.L18:
	movq	%rax, -16(%rbp)
	jmp	.L19
.L23:
	movq	-16(%rbp), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	simulate
	cmpb	$76, -36(%rbp)
	je	.L20
	movq	n(%rip), %rdx
	addq	$1, %rdx
	jmp	.L21
.L20:
	movl	$0, %edx
.L21:
	cmpq	%rax, %rdx
	jne	.L22
	movq	-8(%rbp), %rax
	movq	%rax, -24(%rbp)
	jmp	.L19
.L22:
	movq	-8(%rbp), %rax
	movq	%rax, -16(%rbp)
.L19:
	movq	-16(%rbp), %rax
	subq	-24(%rbp), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	cmpq	$1, %rax
	jg	.L23
	movq	-24(%rbp), %rax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	bin_search, .-bin_search
	.globl	input
	.type	input, @function
input:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$240, %rsp
	movq	%rdi, -232(%rbp)
	movq	%rsi, -168(%rbp)
	movq	%rdx, -160(%rbp)
	movq	%rcx, -152(%rbp)
	movq	%r8, -144(%rbp)
	movq	%r9, -136(%rbp)
	testb	%al, %al
	je	.L26
	movaps	%xmm0, -128(%rbp)
	movaps	%xmm1, -112(%rbp)
	movaps	%xmm2, -96(%rbp)
	movaps	%xmm3, -80(%rbp)
	movaps	%xmm4, -64(%rbp)
	movaps	%xmm5, -48(%rbp)
	movaps	%xmm6, -32(%rbp)
	movaps	%xmm7, -16(%rbp)
.L26:
	movq	%fs:40, %rax
	movq	%rax, -184(%rbp)
	xorl	%eax, %eax
	movq	stdin(%rip), %rax
	movq	%rax, %rdx
	movl	$200004, %esi
	leaq	buff(%rip), %rax
	movq	%rax, %rdi
	call	fgets@PLT
	movl	$8, -208(%rbp)
	movl	$48, -204(%rbp)
	leaq	16(%rbp), %rax
	movq	%rax, -200(%rbp)
	leaq	-176(%rbp), %rax
	movq	%rax, -192(%rbp)
	leaq	-208(%rbp), %rdx
	movq	-232(%rbp), %rax
	movq	%rax, %rsi
	leaq	buff(%rip), %rax
	movq	%rax, %rdi
	call	__isoc99_vsscanf@PLT
	cltq
	movq	%rax, -216(%rbp)
	movq	-216(%rbp), %rax
	movq	-184(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	input, .-input
	.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:
