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>

//入力したマスbが、-1にたどり着くなら-1, nにたどり着くなら1を返す
int simulate(char *s, char *t, char *d, int n, int q, int b){
    int i;
    for(i = 0; i < q; ++i) {
        if(s[b] == t[i]) {
            b += ((d[i] == 'R') ? 1 : -1);
            if(b < 0)   { return -1; }
            if(b > n-1) { return  1; }
        }
    }
    return 0;
}

int main()
{
    int n, q, i, a, b, b_prev, c, l, r;
    char s[200000], t[200000], d[200000];
    scanf("%d %d", &n, &q);
    scanf("%s", s);
    for(i = 0; i < q; ++i) {
        scanf("\n %c %c", &t[i], &d[i]);
    }

    //二部探索
    //aには「-1にたどり着くマスの中で最も右にあるもの」が最終的に入る
    a = 0; b_prev = -1; c = n-1;
    while(1) {
        b = (a + c + 1)/2;
        //printf("a:%d b:%d c:%d\n", a, b, c);
        if(b == b_prev) { break; }
        if(simulate(s, t, d, n, q, b) < 0) { a = b; }
        else { c = b; }
        b_prev = b;
        //printf("a:%d c:%d\n", a, c);
    }
    l = a;
    //printf("\n");

    //二部探索
    //aには「nにたどり着かないマスの中で最も右にあるもの」が最終的に入る
    a = 0; b_prev = -1; c = n-1;
    while(1) {
        b = (a + c + 1)/2;
        //printf("a:%d b:%d c:%d\n", a, b, c);
        if(b == b_prev) { break; }
        if(simulate(s, t, d,n, q, b) > 0) { c = b; }
        else { a = b; }
        b_prev = b;
        //printf("a:%d c:%d\n", a, c);
    }
    r = a;
    //printf("\n");
    //printf("r: %d l: %d\n", r, l);
    printf("%d\n", r - l);
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB0:
	.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	%rsi, -32(%rbp)
	movq	%rdx, -40(%rbp)
	movl	%ecx, -44(%rbp)
	movl	%r8d, -48(%rbp)
	movl	%r9d, -52(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L8:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movl	-4(%rbp), %eax
	movslq	%eax, %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movzbl	(%rax), %eax
	cmpb	%al, %dl
	jne	.L3
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L4
	movl	$1, %eax
	jmp	.L5
.L4:
	movl	$-1, %eax
.L5:
	addl	%eax, -52(%rbp)
	cmpl	$0, -52(%rbp)
	jns	.L6
	movl	$-1, %eax
	jmp	.L7
.L6:
	movl	-44(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jg	.L3
	movl	$1, %eax
	jmp	.L7
.L3:
	addl	$1, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jl	.L8
	movl	$0, %eax
.L7:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	simulate, .-simulate
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"\n %c %c"
.LC3:
	.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
	leaq	-598016(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2048, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-600048(%rbp), %rdx
	leaq	-600052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-600016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -600044(%rbp)
	jmp	.L10
.L11:
	leaq	-200016(%rbp), %rdx
	movl	-600044(%rbp), %eax
	cltq
	addq	%rax, %rdx
	leaq	-400016(%rbp), %rcx
	movl	-600044(%rbp), %eax
	cltq
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -600044(%rbp)
.L10:
	movl	-600048(%rbp), %eax
	cmpl	%eax, -600044(%rbp)
	jl	.L11
	movl	$0, -600040(%rbp)
	movl	$-1, -600036(%rbp)
	movl	-600052(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -600032(%rbp)
.L16:
	movl	-600040(%rbp), %edx
	movl	-600032(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -600028(%rbp)
	movl	-600028(%rbp), %eax
	cmpl	-600036(%rbp), %eax
	je	.L26
	movl	-600048(%rbp), %edi
	movl	-600052(%rbp), %ecx
	movl	-600028(%rbp), %r8d
	leaq	-200016(%rbp), %rdx
	leaq	-400016(%rbp), %rsi
	leaq	-600016(%rbp), %rax
	movl	%r8d, %r9d
	movl	%edi, %r8d
	movq	%rax, %rdi
	call	simulate
	testl	%eax, %eax
	jns	.L14
	movl	-600028(%rbp), %eax
	movl	%eax, -600040(%rbp)
	jmp	.L15
.L14:
	movl	-600028(%rbp), %eax
	movl	%eax, -600032(%rbp)
.L15:
	movl	-600028(%rbp), %eax
	movl	%eax, -600036(%rbp)
	jmp	.L16
.L26:
	nop
	movl	-600040(%rbp), %eax
	movl	%eax, -600024(%rbp)
	movl	$0, -600040(%rbp)
	movl	$-1, -600036(%rbp)
	movl	-600052(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -600032(%rbp)
.L21:
	movl	-600040(%rbp), %edx
	movl	-600032(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -600028(%rbp)
	movl	-600028(%rbp), %eax
	cmpl	-600036(%rbp), %eax
	je	.L27
	movl	-600048(%rbp), %edi
	movl	-600052(%rbp), %ecx
	movl	-600028(%rbp), %r8d
	leaq	-200016(%rbp), %rdx
	leaq	-400016(%rbp), %rsi
	leaq	-600016(%rbp), %rax
	movl	%r8d, %r9d
	movl	%edi, %r8d
	movq	%rax, %rdi
	call	simulate
	testl	%eax, %eax
	jle	.L19
	movl	-600028(%rbp), %eax
	movl	%eax, -600032(%rbp)
	jmp	.L20
.L19:
	movl	-600028(%rbp), %eax
	movl	%eax, -600040(%rbp)
.L20:
	movl	-600028(%rbp), %eax
	movl	%eax, -600036(%rbp)
	jmp	.L21
.L27:
	nop
	movl	-600040(%rbp), %eax
	movl	%eax, -600020(%rbp)
	movl	-600020(%rbp), %eax
	subl	-600024(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	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	simulate
	.type	simulate, @function
simulate:
.LFB23:
	.cfi_startproc
	endbr64
	movq	%rsi, %r10
	movq	%rdx, %r11
	testl	%r8d, %r8d
	jle	.L6
	movslq	%r8d, %rsi
	xorl	%eax, %eax
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L3:
	addq	$1, %rax
	cmpq	%rax, %rsi
	je	.L6
.L5:
	movslq	%r9d, %rdx
	movzbl	(%r10,%rax), %r8d
	cmpb	%r8b, (%rdi,%rdx)
	jne	.L3
	xorl	%edx, %edx
	cmpb	$82, (%r11,%rax)
	sete	%dl
	leal	-1(%r9,%rdx,2), %r9d
	testl	%r9d, %r9d
	js	.L8
	cmpl	%ecx, %r9d
	jl	.L3
	movl	$1, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%eax, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L8:
	movl	$-1, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	simulate, .-simulate
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"\n %c %c"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	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
	leaq	-598016(%rsp), %r11
	.cfi_def_cfa 11, 598064
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2016, %rsp
	.cfi_def_cfa_offset 600080
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 600024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdx
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	leaq	16(%rsp), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r10d
	testl	%r10d, %r10d
	jle	.L13
	xorl	%ebp, %ebp
	leaq	400016(%rsp), %r13
	leaq	200016(%rsp), %rbx
	leaq	.LC2(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L14:
	leaq	0(%r13,%rbp), %rdx
	leaq	(%rbx,%rbp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r10d
	addq	$1, %rbp
	cmpl	%ebp, %r10d
	jg	.L14
.L13:
	movl	8(%rsp), %r8d
	movl	%r8d, %r9d
	leal	-1(%r8), %ebp
	shrl	$31, %r9d
	addl	%r8d, %r9d
	sarl	%r9d
	cmpl	$-1, %r9d
	je	.L27
	movl	%r9d, %r12d
	movl	%ebp, %r13d
	xorl	%r11d, %r11d
	movslq	%r10d, %rsi
	leaq	400016(%rsp), %rdi
	.p2align 4,,10
	.p2align 3
.L16:
	testl	%r10d, %r10d
	jle	.L32
	movl	%r12d, %edx
	xorl	%eax, %eax
	leaq	200016(%rsp), %rbx
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L19:
	addq	$1, %rax
	cmpq	%rax, %rsi
	je	.L32
.L21:
	movslq	%edx, %rcx
	movzbl	(%rbx,%rax), %r14d
	cmpb	%r14b, 16(%rsp,%rcx)
	jne	.L19
	xorl	%ecx, %ecx
	cmpb	$82, (%rax,%rdi)
	sete	%cl
	leal	-1(%rdx,%rcx,2), %edx
	testl	%edx, %edx
	js	.L31
	cmpl	%edx, %r8d
	jg	.L19
.L32:
	movl	%r12d, %r13d
.L18:
	leal	1(%r11,%r13), %edx
	movl	%edx, %eax
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	cmpl	%r12d, %eax
	je	.L28
	movl	%eax, %r12d
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L31:
	movl	%r12d, %r11d
	jmp	.L18
.L28:
	xorl	%r12d, %r12d
	movslq	%r10d, %rdi
	leaq	400016(%rsp), %rdx
	testl	%r10d, %r10d
	jle	.L41
	.p2align 4,,10
	.p2align 3
.L42:
	movl	%r9d, %ecx
	xorl	%eax, %eax
	leaq	200016(%rsp), %rbx
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L23:
	addq	$1, %rax
	cmpq	%rax, %rdi
	je	.L41
.L25:
	movslq	%ecx, %rsi
	movzbl	(%rbx,%rax), %r14d
	cmpb	%r14b, 16(%rsp,%rsi)
	jne	.L23
	xorl	%esi, %esi
	cmpb	$82, (%rax,%rdx)
	sete	%sil
	leal	-1(%rcx,%rsi,2), %ecx
	testl	%ecx, %ecx
	js	.L41
	cmpl	%ecx, %r8d
	jg	.L23
	movl	%r9d, %ebp
	.p2align 4,,10
	.p2align 3
.L22:
	leal	1(%r12,%rbp), %ecx
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	cmpl	%r9d, %eax
	je	.L15
	movl	%eax, %r9d
	testl	%r10d, %r10d
	jg	.L42
	.p2align 4,,10
	.p2align 3
.L41:
	movl	%r9d, %r12d
	jmp	.L22
.L27:
	xorl	%r11d, %r11d
	xorl	%r12d, %r12d
.L15:
	movl	%r12d, %edx
	xorl	%eax, %eax
	movl	$1, %edi
	subl	%r11d, %edx
	leaq	.LC3(%rip), %rsi
	call	__printf_chk@PLT
	movq	600024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L43
	addq	$600032, %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
.L43:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB23:
	.cfi_startproc
	endbr64
	movq	%rsi, %r10
	movq	%rdx, %r11
	testl	%r8d, %r8d
	jle	.L6
	movslq	%r8d, %rsi
	xorl	%eax, %eax
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L3:
	addq	$1, %rax
	cmpq	%rax, %rsi
	je	.L6
.L5:
	movslq	%r9d, %rdx
	movzbl	(%r10,%rax), %r8d
	cmpb	%r8b, (%rdi,%rdx)
	jne	.L3
	xorl	%edx, %edx
	cmpb	$82, (%r11,%rax)
	sete	%dl
	leal	-1(%r9,%rdx,2), %r9d
	testl	%r9d, %r9d
	js	.L8
	cmpl	%ecx, %r9d
	jl	.L3
	movl	$1, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%eax, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L8:
	movl	$-1, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	simulate, .-simulate
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"\n %c %c"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	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
	leaq	-598016(%rsp), %r11
	.cfi_def_cfa 11, 598064
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2016, %rsp
	.cfi_def_cfa_offset 600080
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 600024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdx
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	leaq	16(%rsp), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r10d
	testl	%r10d, %r10d
	jle	.L13
	xorl	%ebp, %ebp
	leaq	400016(%rsp), %r13
	leaq	200016(%rsp), %rbx
	leaq	.LC2(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L14:
	leaq	0(%r13,%rbp), %rdx
	leaq	(%rbx,%rbp), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %r10d
	addq	$1, %rbp
	cmpl	%ebp, %r10d
	jg	.L14
.L13:
	movl	8(%rsp), %r8d
	movl	%r8d, %r9d
	leal	-1(%r8), %ebp
	shrl	$31, %r9d
	addl	%r8d, %r9d
	sarl	%r9d
	cmpl	$-1, %r9d
	je	.L27
	movl	%r9d, %r12d
	movl	%ebp, %r13d
	xorl	%r11d, %r11d
	movslq	%r10d, %rsi
	leaq	400016(%rsp), %rdi
	.p2align 4,,10
	.p2align 3
.L16:
	testl	%r10d, %r10d
	jle	.L32
	movl	%r12d, %edx
	xorl	%eax, %eax
	leaq	200016(%rsp), %rbx
	jmp	.L21
	.p2align 4,,10
	.p2align 3
.L19:
	addq	$1, %rax
	cmpq	%rax, %rsi
	je	.L32
.L21:
	movslq	%edx, %rcx
	movzbl	(%rbx,%rax), %r14d
	cmpb	%r14b, 16(%rsp,%rcx)
	jne	.L19
	xorl	%ecx, %ecx
	cmpb	$82, (%rax,%rdi)
	sete	%cl
	leal	-1(%rdx,%rcx,2), %edx
	testl	%edx, %edx
	js	.L31
	cmpl	%edx, %r8d
	jg	.L19
.L32:
	movl	%r12d, %r13d
.L18:
	leal	1(%r11,%r13), %edx
	movl	%edx, %eax
	shrl	$31, %eax
	addl	%edx, %eax
	sarl	%eax
	cmpl	%r12d, %eax
	je	.L28
	movl	%eax, %r12d
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L31:
	movl	%r12d, %r11d
	jmp	.L18
.L28:
	xorl	%r12d, %r12d
	movslq	%r10d, %rdi
	leaq	400016(%rsp), %rdx
	testl	%r10d, %r10d
	jle	.L41
	.p2align 4,,10
	.p2align 3
.L42:
	movl	%r9d, %ecx
	xorl	%eax, %eax
	leaq	200016(%rsp), %rbx
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L23:
	addq	$1, %rax
	cmpq	%rax, %rdi
	je	.L41
.L25:
	movslq	%ecx, %rsi
	movzbl	(%rbx,%rax), %r14d
	cmpb	%r14b, 16(%rsp,%rsi)
	jne	.L23
	xorl	%esi, %esi
	cmpb	$82, (%rax,%rdx)
	sete	%sil
	leal	-1(%rcx,%rsi,2), %ecx
	testl	%ecx, %ecx
	js	.L41
	cmpl	%ecx, %r8d
	jg	.L23
	movl	%r9d, %ebp
	.p2align 4,,10
	.p2align 3
.L22:
	leal	1(%r12,%rbp), %ecx
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	cmpl	%r9d, %eax
	je	.L15
	movl	%eax, %r9d
	testl	%r10d, %r10d
	jg	.L42
	.p2align 4,,10
	.p2align 3
.L41:
	movl	%r9d, %r12d
	jmp	.L22
.L27:
	xorl	%r11d, %r11d
	xorl	%r12d, %r12d
.L15:
	movl	%r12d, %edx
	xorl	%eax, %eax
	movl	$1, %edi
	subl	%r11d, %edx
	leaq	.LC3(%rip), %rsi
	call	__printf_chk@PLT
	movq	600024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L43
	addq	$600032, %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
.L43:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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:

#include <stdio.h>

//入力したマスbが、-1にたどり着くなら-1, nにたどり着くなら1を返す
int simulate(char *s, char *t, char *d, int n, int q, int b){
    int i;
    for(i = 0; i < q; ++i) {
        if(s[b] == t[i]) {
            b += ((d[i] == 'R') ? 1 : -1);
            if(b < 0)   { return -1; }
            if(b > n-1) { return  1; }
        }
    }
    return 0;
}

int main()
{
    int n, q, i, a, b, b_prev, c, l, r;
    char s[200000], t[200000], d[200000];
    scanf("%d %d", &n, &q);
    scanf("%s", s);
    for(i = 0; i < q; ++i) {
        scanf("\n %c %c", &t[i], &d[i]);
    }

    //二部探索
    //aには「-1にたどり着くマスの中で最も右にあるもの」が最終的に入る
    a = 0; b_prev = -1; c = n-1;
    while(1) {
        b = (a + c + 1)/2;
        //printf("a:%d b:%d c:%d\n", a, b, c);
        if(b == b_prev) { break; }
        if(simulate(s, t, d, n, q, b) < 0) { a = b; }
        else { c = b; }
        b_prev = b;
        //printf("a:%d c:%d\n", a, c);
    }
    l = a;
    //printf("\n");

    //二部探索
    //aには「nにたどり着かないマスの中で最も右にあるもの」が最終的に入る
    a = 0; b_prev = -1; c = n-1;
    while(1) {
        b = (a + c + 1)/2;
        //printf("a:%d b:%d c:%d\n", a, b, c);
        if(b == b_prev) { break; }
        if(simulate(s, t, d,n, q, b) > 0) { c = b; }
        else { a = b; }
        b_prev = b;
        //printf("a:%d c:%d\n", a, c);
    }
    r = a;
    //printf("\n");
    //printf("r: %d l: %d\n", r, l);
    printf("%d\n", r - l);
    return 0;
}
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

6
 2
 5
 2
 1
 7
 5
 8
 9
 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>

//入力したマスbが、-1にたどり着くなら-1, nにたどり着くなら1を返す
int simulate(char *s, char *t, char *d, int n, int q, int b){
    int i;
    for(i = 0; i < q; ++i) {
        if(s[b] == t[i]) {
            b += ((d[i] == 'R') ? 1 : -1);
            if(b < 0)   { return -1; }
            if(b > n-1) { return  1; }
        }
    }
    return 0;
}

int main()
{
    int n, q, i, a, b, b_prev, c, l, r;
    char s[200000], t[200000], d[200000];
    scanf("%d %d", &n, &q);
    scanf("%s", s);
    for(i = 0; i < q; ++i) {
        scanf("\n %c %c", &t[i], &d[i]);
    }

    //二部探索
    //aには「-1にたどり着くマスの中で最も右にあるもの」が最終的に入る
    a = 0; b_prev = -1; c = n-1;
    while(1) {
        b = (a + c + 1)/2;
        //printf("a:%d b:%d c:%d\n", a, b, c);
        if(b == b_prev) { break; }
        if(simulate(s, t, d, n, q, b) < 0) { a = b; }
        else { c = b; }
        b_prev = b;
        //printf("a:%d c:%d\n", a, c);
    }
    l = a;
    //printf("\n");

    //二部探索
    //aには「nにたどり着かないマスの中で最も右にあるもの」が最終的に入る
    a = 0; b_prev = -1; c = n-1;
    while(1) {
        b = (a + c + 1)/2;
        //printf("a:%d b:%d c:%d\n", a, b, c);
        if(b == b_prev) { break; }
        if(simulate(s, t, d,n, q, b) > 0) { c = b; }
        else { a = b; }
        b_prev = b;
        //printf("a:%d c:%d\n", a, c);
    }
    r = a;
    //printf("\n");
    //printf("r: %d l: %d\n", r, l);
    printf("%d\n", r - l);
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	simulate
	.type	simulate, @function
simulate:
.LFB0:
	.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	%rsi, -32(%rbp)
	movq	%rdx, -40(%rbp)
	movl	%ecx, -44(%rbp)
	movl	%r8d, -48(%rbp)
	movl	%r9d, -52(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L8:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movl	-4(%rbp), %eax
	movslq	%eax, %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movzbl	(%rax), %eax
	cmpb	%al, %dl
	jne	.L3
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L4
	movl	$1, %eax
	jmp	.L5
.L4:
	movl	$-1, %eax
.L5:
	addl	%eax, -52(%rbp)
	cmpl	$0, -52(%rbp)
	jns	.L6
	movl	$-1, %eax
	jmp	.L7
.L6:
	movl	-44(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jg	.L3
	movl	$1, %eax
	jmp	.L7
.L3:
	addl	$1, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jl	.L8
	movl	$0, %eax
.L7:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	simulate, .-simulate
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"\n %c %c"
.LC3:
	.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
	leaq	-598016(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2048, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-600048(%rbp), %rdx
	leaq	-600052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-600016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -600044(%rbp)
	jmp	.L10
.L11:
	leaq	-200016(%rbp), %rdx
	movl	-600044(%rbp), %eax
	cltq
	addq	%rax, %rdx
	leaq	-400016(%rbp), %rcx
	movl	-600044(%rbp), %eax
	cltq
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -600044(%rbp)
.L10:
	movl	-600048(%rbp), %eax
	cmpl	%eax, -600044(%rbp)
	jl	.L11
	movl	$0, -600040(%rbp)
	movl	$-1, -600036(%rbp)
	movl	-600052(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -600032(%rbp)
.L16:
	movl	-600040(%rbp), %edx
	movl	-600032(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -600028(%rbp)
	movl	-600028(%rbp), %eax
	cmpl	-600036(%rbp), %eax
	je	.L26
	movl	-600048(%rbp), %edi
	movl	-600052(%rbp), %ecx
	movl	-600028(%rbp), %r8d
	leaq	-200016(%rbp), %rdx
	leaq	-400016(%rbp), %rsi
	leaq	-600016(%rbp), %rax
	movl	%r8d, %r9d
	movl	%edi, %r8d
	movq	%rax, %rdi
	call	simulate
	testl	%eax, %eax
	jns	.L14
	movl	-600028(%rbp), %eax
	movl	%eax, -600040(%rbp)
	jmp	.L15
.L14:
	movl	-600028(%rbp), %eax
	movl	%eax, -600032(%rbp)
.L15:
	movl	-600028(%rbp), %eax
	movl	%eax, -600036(%rbp)
	jmp	.L16
.L26:
	nop
	movl	-600040(%rbp), %eax
	movl	%eax, -600024(%rbp)
	movl	$0, -600040(%rbp)
	movl	$-1, -600036(%rbp)
	movl	-600052(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -600032(%rbp)
.L21:
	movl	-600040(%rbp), %edx
	movl	-600032(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -600028(%rbp)
	movl	-600028(%rbp), %eax
	cmpl	-600036(%rbp), %eax
	je	.L27
	movl	-600048(%rbp), %edi
	movl	-600052(%rbp), %ecx
	movl	-600028(%rbp), %r8d
	leaq	-200016(%rbp), %rdx
	leaq	-400016(%rbp), %rsi
	leaq	-600016(%rbp), %rax
	movl	%r8d, %r9d
	movl	%edi, %r8d
	movq	%rax, %rdi
	call	simulate
	testl	%eax, %eax
	jle	.L19
	movl	-600028(%rbp), %eax
	movl	%eax, -600032(%rbp)
	jmp	.L20
.L19:
	movl	-600028(%rbp), %eax
	movl	%eax, -600040(%rbp)
.L20:
	movl	-600028(%rbp), %eax
	movl	%eax, -600036(%rbp)
	jmp	.L21
.L27:
	nop
	movl	-600040(%rbp), %eax
	movl	%eax, -600020(%rbp)
	movl	-600020(%rbp), %eax
	subl	-600024(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	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	simulate
	.type	simulate, @function
simulate:
.LFB0:
	.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	%rsi, -32(%rbp)
	movq	%rdx, -40(%rbp)
	movl	%ecx, -44(%rbp)
	movl	%r8d, -48(%rbp)
	movl	%r9d, -52(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L8:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movl	-4(%rbp), %eax
	movslq	%eax, %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movzbl	(%rax), %eax
	cmpb	%al, %dl
	jne	.L3
	movl	-4(%rbp), %eax
	movslq	%eax, %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L4
	movl	$1, %eax
	jmp	.L5
.L4:
	movl	$-1, %eax
.L5:
	addl	%eax, -52(%rbp)
	cmpl	$0, -52(%rbp)
	jns	.L6
	movl	$-1, %eax
	jmp	.L7
.L6:
	movl	-44(%rbp), %eax
	cmpl	-52(%rbp), %eax
	jg	.L3
	movl	$1, %eax
	jmp	.L7
.L3:
	addl	$1, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jl	.L8
	movl	$0, %eax
.L7:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	simulate, .-simulate
	.section	.rodata
.LC0:
	.string	"%d %d"
.LC1:
	.string	"%s"
.LC2:
	.string	"\n %c %c"
.LC3:
	.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
	leaq	-598016(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2048, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-600048(%rbp), %rdx
	leaq	-600052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-600016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -600044(%rbp)
	jmp	.L10
.L11:
	leaq	-200016(%rbp), %rdx
	movl	-600044(%rbp), %eax
	cltq
	addq	%rax, %rdx
	leaq	-400016(%rbp), %rcx
	movl	-600044(%rbp), %eax
	cltq
	addq	%rcx, %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -600044(%rbp)
.L10:
	movl	-600048(%rbp), %eax
	cmpl	%eax, -600044(%rbp)
	jl	.L11
	movl	$0, -600040(%rbp)
	movl	$-1, -600036(%rbp)
	movl	-600052(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -600032(%rbp)
.L16:
	movl	-600040(%rbp), %edx
	movl	-600032(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -600028(%rbp)
	movl	-600028(%rbp), %eax
	cmpl	-600036(%rbp), %eax
	je	.L26
	movl	-600048(%rbp), %edi
	movl	-600052(%rbp), %ecx
	movl	-600028(%rbp), %r8d
	leaq	-200016(%rbp), %rdx
	leaq	-400016(%rbp), %rsi
	leaq	-600016(%rbp), %rax
	movl	%r8d, %r9d
	movl	%edi, %r8d
	movq	%rax, %rdi
	call	simulate
	testl	%eax, %eax
	jns	.L14
	movl	-600028(%rbp), %eax
	movl	%eax, -600040(%rbp)
	jmp	.L15
.L14:
	movl	-600028(%rbp), %eax
	movl	%eax, -600032(%rbp)
.L15:
	movl	-600028(%rbp), %eax
	movl	%eax, -600036(%rbp)
	jmp	.L16
.L26:
	nop
	movl	-600040(%rbp), %eax
	movl	%eax, -600024(%rbp)
	movl	$0, -600040(%rbp)
	movl	$-1, -600036(%rbp)
	movl	-600052(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -600032(%rbp)
.L21:
	movl	-600040(%rbp), %edx
	movl	-600032(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -600028(%rbp)
	movl	-600028(%rbp), %eax
	cmpl	-600036(%rbp), %eax
	je	.L27
	movl	-600048(%rbp), %edi
	movl	-600052(%rbp), %ecx
	movl	-600028(%rbp), %r8d
	leaq	-200016(%rbp), %rdx
	leaq	-400016(%rbp), %rsi
	leaq	-600016(%rbp), %rax
	movl	%r8d, %r9d
	movl	%edi, %r8d
	movq	%rax, %rdi
	call	simulate
	testl	%eax, %eax
	jle	.L19
	movl	-600028(%rbp), %eax
	movl	%eax, -600032(%rbp)
	jmp	.L20
.L19:
	movl	-600028(%rbp), %eax
	movl	%eax, -600040(%rbp)
.L20:
	movl	-600028(%rbp), %eax
	movl	%eax, -600036(%rbp)
	jmp	.L21
.L27:
	nop
	movl	-600040(%rbp), %eax
	movl	%eax, -600020(%rbp)
	movl	-600020(%rbp), %eax
	subl	-600024(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	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:
