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>
int main()
{
    char* a = (char*)malloc(sizeof(char));
    scanf("%c",&a[0]);
    int i = 0;
    while((int)a[i]!=10)
    {
        i++;
        a = (char*)realloc(a,(i + 1)*sizeof(char));
        scanf("%c",&a[i]);
    }
    int max = 0,mediator = 0,j = 0;
    while(j < i + 1)
    {
        if(a[j] == 'R') {
            mediator++;
        }
        else{
            if (mediator > max){
                max = mediator;
                mediator = 0;
            } 
        }
        j++;
    }
    printf("\n%d",max);
    free(a);
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%c"
.LC1:
	.string	"\n%d"
	.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
	subq	$32, %rsp
	movl	$1, %edi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -24(%rbp)
	jmp	.L2
.L3:
	addl	$1, -24(%rbp)
	movl	-24(%rbp), %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	realloc@PLT
	movq	%rax, -8(%rbp)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
.L2:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$10, %al
	jne	.L3
	movl	$0, -20(%rbp)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L4
.L7:
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L5
	addl	$1, -16(%rbp)
	jmp	.L6
.L5:
	movl	-16(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L6
	movl	-16(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	$0, -16(%rbp)
.L6:
	addl	$1, -12(%rbp)
.L4:
	movl	-24(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L7
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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	"%c"
.LC1:
	.string	"\n%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$1, %edi
	leaq	.LC0(%rip), %r14
	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
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %rbp
	movq	%rax, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	cmpb	$10, 0(%rbp)
	je	.L7
	movl	$1, %ebx
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbx, %r12
	movslq	%ebx, %r13
	addq	$1, %rbx
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	call	realloc@PLT
	movq	%r14, %rdi
	addq	%rax, %r12
	movq	%rax, %rbp
	xorl	%eax, %eax
	movq	%r12, %rsi
	call	__isoc99_scanf@PLT
	cmpb	$10, (%r12)
	jne	.L3
.L2:
	movq	%rbp, %rax
	leaq	1(%rbp,%r13), %rcx
	xorl	%edx, %edx
	xorl	%r8d, %r8d
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	cmpl	%edx, %r8d
	jge	.L5
	movl	%edx, %r8d
	xorl	%edx, %edx
.L5:
	addq	$1, %rax
	cmpq	%rax, %rcx
	je	.L13
.L6:
	cmpb	$82, (%rax)
	jne	.L4
	addq	$1, %rax
	addl	$1, %edx
	cmpq	%rax, %rcx
	jne	.L6
.L13:
	movl	%r8d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.L7:
	.cfi_restore_state
	xorl	%r13d, %r13d
	jmp	.L2
	.cfi_endproc
.LFE39:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%c"
.LC1:
	.string	"\n%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$1, %edi
	leaq	.LC0(%rip), %r14
	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
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %rbp
	movq	%rax, %rsi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	cmpb	$10, 0(%rbp)
	je	.L7
	movl	$1, %ebx
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbx, %r12
	movslq	%ebx, %r13
	addq	$1, %rbx
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	call	realloc@PLT
	movq	%r14, %rdi
	addq	%rax, %r12
	movq	%rax, %rbp
	xorl	%eax, %eax
	movq	%r12, %rsi
	call	__isoc99_scanf@PLT
	cmpb	$10, (%r12)
	jne	.L3
.L2:
	movq	%rbp, %rax
	leaq	1(%rbp,%r13), %rcx
	xorl	%edx, %edx
	xorl	%r8d, %r8d
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	cmpl	%edx, %r8d
	jge	.L5
	movl	%edx, %r8d
	xorl	%edx, %edx
.L5:
	addq	$1, %rax
	cmpq	%rax, %rcx
	je	.L13
.L6:
	cmpb	$82, (%rax)
	jne	.L4
	addq	$1, %rax
	addl	$1, %edx
	cmpq	%rax, %rcx
	jne	.L6
.L13:
	movl	%r8d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.L7:
	.cfi_restore_state
	xorl	%r13d, %r13d
	jmp	.L2
	.cfi_endproc
.LFE39:
	.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>
#include <stdlib.h>
int main()
{
    char* a = (char*)malloc(sizeof(char));
    scanf("%c",&a[0]);
    int i = 0;
    while((int)a[i]!=10)
    {
        i++;
        a = (char*)realloc(a,(i + 1)*sizeof(char));
        scanf("%c",&a[i]);
    }
    int max = 0,mediator = 0,j = 0;
    while(j < i + 1)
    {
        if(a[j] == 'R') {
            mediator++;
        }
        else{
            if (mediator > max){
                max = mediator;
                mediator = 0;
            } 
        }
        j++;
    }
    printf("\n%d",max);
    free(a);
    return 0;
}

SRR
 RRR
 RSS
 SSR
 RST
 SRS
 TSR
 USR
 RSQ
 QSR


2 
3 
1 
1 
1 
1 
1 
1 
1 
1
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>
int main()
{
    char* a = (char*)malloc(sizeof(char));
    scanf("%c",&a[0]);
    int i = 0;
    while((int)a[i]!=10)
    {
        i++;
        a = (char*)realloc(a,(i + 1)*sizeof(char));
        scanf("%c",&a[i]);
    }
    int max = 0,mediator = 0,j = 0;
    while(j < i + 1)
    {
        if(a[j] == 'R') {
            mediator++;
        }
        else{
            if (mediator > max){
                max = mediator;
                mediator = 0;
            } 
        }
        j++;
    }
    printf("\n%d",max);
    free(a);
    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%c"
.LC1:
	.string	"\n%d"
	.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
	subq	$32, %rsp
	movl	$1, %edi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -24(%rbp)
	jmp	.L2
.L3:
	addl	$1, -24(%rbp)
	movl	-24(%rbp), %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	realloc@PLT
	movq	%rax, -8(%rbp)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
.L2:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$10, %al
	jne	.L3
	movl	$0, -20(%rbp)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L4
.L7:
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L5
	addl	$1, -16(%rbp)
	jmp	.L6
.L5:
	movl	-16(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L6
	movl	-16(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	$0, -16(%rbp)
.L6:
	addl	$1, -12(%rbp)
.L4:
	movl	-24(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L7
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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
	.section	.rodata
.LC0:
	.string	"%c"
.LC1:
	.string	"\n%d"
	.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
	subq	$32, %rsp
	movl	$1, %edi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -24(%rbp)
	jmp	.L2
.L3:
	addl	$1, -24(%rbp)
	movl	-24(%rbp), %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	realloc@PLT
	movq	%rax, -8(%rbp)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
.L2:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$10, %al
	jne	.L3
	movl	$0, -20(%rbp)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L4
.L7:
	movl	-12(%rbp), %eax
	movslq	%eax, %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L5
	addl	$1, -16(%rbp)
	jmp	.L6
.L5:
	movl	-16(%rbp), %eax
	cmpl	-20(%rbp), %eax
	jle	.L6
	movl	-16(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	$0, -16(%rbp)
.L6:
	addl	$1, -12(%rbp)
.L4:
	movl	-24(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L7
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movq	-8(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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:
