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 <string.h>
#include <stdlib.h>

int	max(int a, int b)
{
  if (a > b)
    return (a);
  else
    return (b);
}

int	main(void)
{
  int	n;
  char	*s;
  int	i;
  int	nR;
  int	nW;
  char	*cR;
  char	*cW;
  char	*tmp;
  int	count;
  int	m;
  
  if (scanf("%d", &n) == EOF)
    return (-1);
  if (!(s = (char *)malloc((n + 1) * sizeof(char))))
    return (-1);
  s[n] = '\0';
  if (scanf("%s", s) == EOF)
  {
    free(s);
    return (-1);
  }
  i = 0;
  nR = 0;
  nW = 0;
  while (s[i])
  {
    if (s[i] == 'R')
      nR++;
    else if (s[i] == 'W')
      nW++;
    i++;
  }
  if (nR == 0 || nW == 0)
    printf("0\n");
  else
  {
    m = max(nR, nW);
    count = 0;
    while (count < m)
    {
	  	cW = strchr(s, 'W');
      	cR = strrchr(s, 'R');
      	if (cW > cR)
          break ;
      	else
        {
          *cW = 'R';
          *cR = 'W';
          count++;
        }
    }
    printf("%d\n", count);
  }
  free(s);
  return (0);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-8(%rbp), %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	max, .-max
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"0"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	jne	.L5
	movl	$-1, %eax
	jmp	.L20
.L5:
	movl	-56(%rbp), %eax
	addl	$1, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	cmpq	$0, -32(%rbp)
	jne	.L7
	movl	$-1, %eax
	jmp	.L20
.L7:
	movl	-56(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movb	$0, (%rax)
	movq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	jne	.L8
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$-1, %eax
	jmp	.L20
.L8:
	movl	$0, -52(%rbp)
	movl	$0, -48(%rbp)
	movl	$0, -44(%rbp)
	jmp	.L9
.L12:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L10
	addl	$1, -48(%rbp)
	jmp	.L11
.L10:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$87, %al
	jne	.L11
	addl	$1, -44(%rbp)
.L11:
	addl	$1, -52(%rbp)
.L9:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L12
	cmpl	$0, -48(%rbp)
	je	.L13
	cmpl	$0, -44(%rbp)
	jne	.L14
.L13:
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L15
.L14:
	movl	-44(%rbp), %edx
	movl	-48(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	max
	movl	%eax, -36(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L16
.L19:
	movq	-32(%rbp), %rax
	movl	$87, %esi
	movq	%rax, %rdi
	call	strchr@PLT
	movq	%rax, -24(%rbp)
	movq	-32(%rbp), %rax
	movl	$82, %esi
	movq	%rax, %rdi
	call	strrchr@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	cmpq	-16(%rbp), %rax
	ja	.L22
	movq	-24(%rbp), %rax
	movb	$82, (%rax)
	movq	-16(%rbp), %rax
	movb	$87, (%rax)
	addl	$1, -40(%rbp)
.L16:
	movl	-40(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L19
	jmp	.L18
.L22:
	nop
.L18:
	movl	-40(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L15:
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L20:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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	max
	.type	max, @function
max:
.LFB51:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovge	%edi, %eax
	ret
	.cfi_endproc
.LFE51:
	.size	max, .-max
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"0"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB52:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	je	.L6
	movslq	20(%rsp), %rbx
	leal	1(%rbx), %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	je	.L6
	movb	$0, (%rax,%rbx)
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	je	.L7
	movzbl	0(%rbp), %eax
	leaq	1(%rbp), %rdx
	xorl	%ecx, %ecx
	xorl	%r12d, %r12d
	testb	%al, %al
	jne	.L12
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L10:
	cmpb	$87, %al
	sete	%al
	addq	$1, %rdx
	movzbl	%al, %eax
	addl	%eax, %ecx
	movzbl	-1(%rdx), %eax
	testb	%al, %al
	je	.L28
.L12:
	cmpb	$82, %al
	jne	.L10
	movzbl	(%rdx), %eax
	addq	$1, %rdx
	addl	$1, %r12d
	testb	%al, %al
	jne	.L12
.L28:
	testl	%r12d, %r12d
	je	.L9
	testl	%ecx, %ecx
	sete	%al
	cmpl	%ecx, %r12d
	cmovl	%ecx, %r12d
	xorl	%r13d, %r13d
	testb	%al, %al
	jne	.L9
	.p2align 4,,10
	.p2align 3
.L17:
	movl	$87, %esi
	movq	%rbp, %rdi
	call	strchr@PLT
	movl	$82, %esi
	movq	%rbp, %rdi
	movq	%rax, %rbx
	call	strrchr@PLT
	cmpq	%rax, %rbx
	ja	.L16
	addl	$1, %r13d
	movb	$82, (%rbx)
	movb	$87, (%rax)
	cmpl	%r13d, %r12d
	jne	.L17
.L16:
	movl	%r13d, %edx
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L15:
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L3:
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L29
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L9:
	.cfi_restore_state
	leaq	.LC2(%rip), %rdi
	call	puts@PLT
	jmp	.L15
.L6:
	orl	$-1, %eax
	jmp	.L3
.L7:
	movq	%rbp, %rdi
	movl	%eax, 12(%rsp)
	call	free@PLT
	movl	12(%rsp), %eax
	jmp	.L3
.L29:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE52:
	.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	max
	.type	max, @function
max:
.LFB51:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovge	%edi, %eax
	ret
	.cfi_endproc
.LFE51:
	.size	max, .-max
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"0"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB52:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rsi
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	je	.L6
	movslq	20(%rsp), %rbx
	leal	1(%rbx), %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	je	.L6
	movb	$0, (%rax,%rbx)
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	je	.L7
	movzbl	0(%rbp), %eax
	leaq	1(%rbp), %rdx
	xorl	%ecx, %ecx
	xorl	%r12d, %r12d
	testb	%al, %al
	jne	.L12
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L10:
	cmpb	$87, %al
	sete	%al
	addq	$1, %rdx
	movzbl	%al, %eax
	addl	%eax, %ecx
	movzbl	-1(%rdx), %eax
	testb	%al, %al
	je	.L28
.L12:
	cmpb	$82, %al
	jne	.L10
	movzbl	(%rdx), %eax
	addq	$1, %rdx
	addl	$1, %r12d
	testb	%al, %al
	jne	.L12
.L28:
	testl	%r12d, %r12d
	je	.L9
	testl	%ecx, %ecx
	sete	%al
	cmpl	%ecx, %r12d
	cmovl	%ecx, %r12d
	xorl	%r13d, %r13d
	testb	%al, %al
	jne	.L9
	.p2align 4,,10
	.p2align 3
.L17:
	movl	$87, %esi
	movq	%rbp, %rdi
	call	strchr@PLT
	movl	$82, %esi
	movq	%rbp, %rdi
	movq	%rax, %rbx
	call	strrchr@PLT
	cmpq	%rax, %rbx
	ja	.L16
	addl	$1, %r13d
	movb	$82, (%rbx)
	movb	$87, (%rax)
	cmpl	%r13d, %r12d
	jne	.L17
.L16:
	movl	%r13d, %edx
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L15:
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L3:
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	jne	.L29
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L9:
	.cfi_restore_state
	leaq	.LC2(%rip), %rdi
	call	puts@PLT
	jmp	.L15
.L6:
	orl	$-1, %eax
	jmp	.L3
.L7:
	movq	%rbp, %rdi
	movl	%eax, 12(%rsp)
	call	free@PLT
	movl	12(%rsp), %eax
	jmp	.L3
.L29:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE52:
	.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 <string.h>
#include <stdlib.h>

int	max(int a, int b)
{
  if (a > b)
    return (a);
  else
    return (b);
}

int	main(void)
{
  int	n;
  char	*s;
  int	i;
  int	nR;
  int	nW;
  char	*cR;
  char	*cW;
  char	*tmp;
  int	count;
  int	m;
  
  if (scanf("%d", &n) == EOF)
    return (-1);
  if (!(s = (char *)malloc((n + 1) * sizeof(char))))
    return (-1);
  s[n] = '\0';
  if (scanf("%s", s) == EOF)
  {
    free(s);
    return (-1);
  }
  i = 0;
  nR = 0;
  nW = 0;
  while (s[i])
  {
    if (s[i] == 'R')
      nR++;
    else if (s[i] == 'W')
      nW++;
    i++;
  }
  if (nR == 0 || nW == 0)
    printf("0\n");
  else
  {
    m = max(nR, nW);
    count = 0;
    while (count < m)
    {
	  	cW = strchr(s, 'W');
      	cR = strrchr(s, 'R');
      	if (cW > cR)
          break ;
      	else
        {
          *cW = 'R';
          *cR = 'W';
          count++;
        }
    }
    printf("%d\n", count);
  }
  free(s);
  return (0);
}
8
RRWRWWRW
 2
RQ
 8
RRWWWRRW
 8
WRWWWRRR
 8
WWWWRRRR
 8
RRWRVWRW
 4
RRWW
 4
RWWR
 2
RS
 4
RRVW

1
 0
 2
 3
 4
 1
 0
 1
 0
 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 <string.h>
#include <stdlib.h>

int	max(int a, int b)
{
  if (a > b)
    return (a);
  else
    return (b);
}

int	main(void)
{
  int	n;
  char	*s;
  int	i;
  int	nR;
  int	nW;
  char	*cR;
  char	*cW;
  char	*tmp;
  int	count;
  int	m;
  
  if (scanf("%d", &n) == EOF)
    return (-1);
  if (!(s = (char *)malloc((n + 1) * sizeof(char))))
    return (-1);
  s[n] = '\0';
  if (scanf("%s", s) == EOF)
  {
    free(s);
    return (-1);
  }
  i = 0;
  nR = 0;
  nW = 0;
  while (s[i])
  {
    if (s[i] == 'R')
      nR++;
    else if (s[i] == 'W')
      nW++;
    i++;
  }
  if (nR == 0 || nW == 0)
    printf("0\n");
  else
  {
    m = max(nR, nW);
    count = 0;
    while (count < m)
    {
	  	cW = strchr(s, 'W');
      	cR = strrchr(s, 'R');
      	if (cW > cR)
          break ;
      	else
        {
          *cW = 'R';
          *cR = 'W';
          count++;
        }
    }
    printf("%d\n", count);
  }
  free(s);
  return (0);
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-8(%rbp), %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	max, .-max
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"0"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	jne	.L5
	movl	$-1, %eax
	jmp	.L20
.L5:
	movl	-56(%rbp), %eax
	addl	$1, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	cmpq	$0, -32(%rbp)
	jne	.L7
	movl	$-1, %eax
	jmp	.L20
.L7:
	movl	-56(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movb	$0, (%rax)
	movq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	jne	.L8
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$-1, %eax
	jmp	.L20
.L8:
	movl	$0, -52(%rbp)
	movl	$0, -48(%rbp)
	movl	$0, -44(%rbp)
	jmp	.L9
.L12:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L10
	addl	$1, -48(%rbp)
	jmp	.L11
.L10:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$87, %al
	jne	.L11
	addl	$1, -44(%rbp)
.L11:
	addl	$1, -52(%rbp)
.L9:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L12
	cmpl	$0, -48(%rbp)
	je	.L13
	cmpl	$0, -44(%rbp)
	jne	.L14
.L13:
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L15
.L14:
	movl	-44(%rbp), %edx
	movl	-48(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	max
	movl	%eax, -36(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L16
.L19:
	movq	-32(%rbp), %rax
	movl	$87, %esi
	movq	%rax, %rdi
	call	strchr@PLT
	movq	%rax, -24(%rbp)
	movq	-32(%rbp), %rax
	movl	$82, %esi
	movq	%rax, %rdi
	call	strrchr@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	cmpq	-16(%rbp), %rax
	ja	.L22
	movq	-24(%rbp), %rax
	movb	$82, (%rax)
	movq	-16(%rbp), %rax
	movb	$87, (%rax)
	addl	$1, -40(%rbp)
.L16:
	movl	-40(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L19
	jmp	.L18
.L22:
	nop
.L18:
	movl	-40(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L15:
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L20:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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	max
	.type	max, @function
max:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jle	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-8(%rbp), %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	max, .-max
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"0"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	jne	.L5
	movl	$-1, %eax
	jmp	.L20
.L5:
	movl	-56(%rbp), %eax
	addl	$1, %eax
	cltq
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	cmpq	$0, -32(%rbp)
	jne	.L7
	movl	$-1, %eax
	jmp	.L20
.L7:
	movl	-56(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movb	$0, (%rax)
	movq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	cmpl	$-1, %eax
	jne	.L8
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$-1, %eax
	jmp	.L20
.L8:
	movl	$0, -52(%rbp)
	movl	$0, -48(%rbp)
	movl	$0, -44(%rbp)
	jmp	.L9
.L12:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$82, %al
	jne	.L10
	addl	$1, -48(%rbp)
	jmp	.L11
.L10:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$87, %al
	jne	.L11
	addl	$1, -44(%rbp)
.L11:
	addl	$1, -52(%rbp)
.L9:
	movl	-52(%rbp), %eax
	movslq	%eax, %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L12
	cmpl	$0, -48(%rbp)
	je	.L13
	cmpl	$0, -44(%rbp)
	jne	.L14
.L13:
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L15
.L14:
	movl	-44(%rbp), %edx
	movl	-48(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	max
	movl	%eax, -36(%rbp)
	movl	$0, -40(%rbp)
	jmp	.L16
.L19:
	movq	-32(%rbp), %rax
	movl	$87, %esi
	movq	%rax, %rdi
	call	strchr@PLT
	movq	%rax, -24(%rbp)
	movq	-32(%rbp), %rax
	movl	$82, %esi
	movq	%rax, %rdi
	call	strrchr@PLT
	movq	%rax, -16(%rbp)
	movq	-24(%rbp), %rax
	cmpq	-16(%rbp), %rax
	ja	.L22
	movq	-24(%rbp), %rax
	movb	$82, (%rax)
	movq	-16(%rbp), %rax
	movb	$87, (%rax)
	addl	$1, -40(%rbp)
.L16:
	movl	-40(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L19
	jmp	.L18
.L22:
	nop
.L18:
	movl	-40(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L15:
	movq	-32(%rbp), %rax
	movq	%rax, %rdi
	call	free@PLT
	movl	$0, %eax
.L20:
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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:
