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>
int main(){
  int r[6][4]={
    {0,1,5,4},
    {0,3,5,2},
    {0,2,5,3},
    {0,4,5,1},
    {1,2,4,3},
    {1,3,4,2}
  };
  char W[6][7]={"North","East","West","South","Right","Left"};
  int n,s,i,j,k,t;
  char w[7];
  while(1){
    scanf("%d",&n);
    if(!n)break;
    int D[]={1,2,3,4,5,6};
    s=1;
    for(i=0;i<n;i++){
      scanf("%s",w);
      for(j=0;j<7;j++){
	if(strcmp(W[j],w)==0)break;
      }
      t=D[r[j][0]];
      for(k=0;k<3;k++)D[r[j][k]]=D[r[j][k+1]];
      D[r[j][3]]=t;
      s+=D[0];
      /*printf(" %d\n",D[2]);
      printf("%d%d%d%d\n",D[0],D[1],D[5],D[4]);
      printf(" %d\n",D[3]);*/
    }
    printf("%d\n",s);
  }
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$224, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -112(%rbp)
	movl	$1, -108(%rbp)
	movl	$5, -104(%rbp)
	movl	$4, -100(%rbp)
	movl	$0, -96(%rbp)
	movl	$3, -92(%rbp)
	movl	$5, -88(%rbp)
	movl	$2, -84(%rbp)
	movl	$0, -80(%rbp)
	movl	$2, -76(%rbp)
	movl	$5, -72(%rbp)
	movl	$3, -68(%rbp)
	movl	$0, -64(%rbp)
	movl	$4, -60(%rbp)
	movl	$5, -56(%rbp)
	movl	$1, -52(%rbp)
	movl	$1, -48(%rbp)
	movl	$2, -44(%rbp)
	movl	$4, -40(%rbp)
	movl	$3, -36(%rbp)
	movl	$1, -32(%rbp)
	movl	$3, -28(%rbp)
	movl	$4, -24(%rbp)
	movl	$2, -20(%rbp)
	movl	$1953656654, -160(%rbp)
	movw	$104, -156(%rbp)
	movb	$0, -154(%rbp)
	movl	$1953718597, -153(%rbp)
	movw	$0, -149(%rbp)
	movb	$0, -147(%rbp)
	movl	$1953719639, -146(%rbp)
	movw	$0, -142(%rbp)
	movb	$0, -140(%rbp)
	movl	$1953853267, -139(%rbp)
	movw	$104, -135(%rbp)
	movb	$0, -133(%rbp)
	movl	$1751607634, -132(%rbp)
	movw	$116, -128(%rbp)
	movb	$0, -126(%rbp)
	movl	$1952867660, -125(%rbp)
	movw	$0, -121(%rbp)
	movb	$0, -119(%rbp)
.L12:
	leaq	-216(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-216(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	jmp	.L14
.L2:
	movl	$1, -192(%rbp)
	movl	$2, -188(%rbp)
	movl	$3, -184(%rbp)
	movl	$4, -180(%rbp)
	movl	$5, -176(%rbp)
	movl	$6, -172(%rbp)
	movl	$1, -212(%rbp)
	movl	$0, -208(%rbp)
	jmp	.L4
.L11:
	leaq	-15(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -204(%rbp)
	jmp	.L5
.L8:
	leaq	-160(%rbp), %rcx
	movl	-204(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	subq	%rdx, %rax
	leaq	(%rcx,%rax), %rdx
	leaq	-15(%rbp), %rax
	movq	%rax, %rsi
	movq	%rdx, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L15
	addl	$1, -204(%rbp)
.L5:
	cmpl	$6, -204(%rbp)
	jle	.L8
	jmp	.L7
.L15:
	nop
.L7:
	movl	-204(%rbp), %eax
	cltq
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$112, %rax
	movl	(%rax), %eax
	cltq
	movl	-192(%rbp,%rax,4), %eax
	movl	%eax, -196(%rbp)
	movl	$0, -200(%rbp)
	jmp	.L9
.L10:
	movl	-200(%rbp), %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-204(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	-112(%rbp,%rax,4), %eax
	movl	-200(%rbp), %edx
	movslq	%edx, %rcx
	movl	-204(%rbp), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	addq	%rcx, %rdx
	movl	-112(%rbp,%rdx,4), %ecx
	cltq
	movl	-192(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -192(%rbp,%rax,4)
	addl	$1, -200(%rbp)
.L9:
	cmpl	$2, -200(%rbp)
	jle	.L10
	movl	-204(%rbp), %eax
	cltq
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$100, %rax
	movl	(%rax), %eax
	cltq
	movl	-196(%rbp), %edx
	movl	%edx, -192(%rbp,%rax,4)
	movl	-192(%rbp), %eax
	addl	%eax, -212(%rbp)
	addl	$1, -208(%rbp)
.L4:
	movl	-216(%rbp), %eax
	cmpl	%eax, -208(%rbp)
	jl	.L11
	movl	-212(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L12
.L14:
	call	__stack_chk_fail@PLT
.L13:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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
.LC6:
	.string	"%d"
.LC9:
	.string	"%s"
.LC10:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%edx, %edx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$232, %rsp
	.cfi_def_cfa_offset 288
	movdqa	.LC0(%rip), %xmm0
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	movw	%dx, 104(%rsp)
	leaq	106(%rsp), %r14
	movabsq	$32763682551234676, %rax
	movaps	%xmm0, 112(%rsp)
	movdqa	.LC1(%rip), %xmm0
	movq	%rax, 96(%rsp)
	leaq	28(%rsp), %rax
	movaps	%xmm0, 128(%rsp)
	movdqa	.LC2(%rip), %xmm0
	movq	%rax, 8(%rsp)
	movaps	%xmm0, 144(%rsp)
	movdqa	.LC3(%rip), %xmm0
	movaps	%xmm0, 160(%rsp)
	movdqa	.LC4(%rip), %xmm0
	movaps	%xmm0, 176(%rsp)
	movdqa	.LC5(%rip), %xmm0
	movaps	%xmm0, 192(%rsp)
	movdqa	.LC11(%rip), %xmm0
	movaps	%xmm0, 64(%rsp)
	movdqa	.LC12(%rip), %xmm0
	movaps	%xmm0, 80(%rsp)
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rsi
	leaq	.LC6(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L2
	movdqa	.LC7(%rip), %xmm1
	movq	.LC8(%rip), %rax
	movaps	%xmm1, 32(%rsp)
	movq	%rax, 48(%rsp)
	jle	.L21
	xorl	%ebx, %ebx
	movl	$1, %r12d
	leaq	209(%rsp), %r15
	leaq	.LC9(%rip), %r13
	leaq	64(%rsp), %rbp
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L4:
	movl	(%r15), %eax
	cmpl	%eax, 71(%rsp)
	je	.L32
.L7:
	movl	(%r15), %eax
	cmpl	%eax, 78(%rsp)
	je	.L33
.L9:
	movl	(%r15), %eax
	cmpl	%eax, 85(%rsp)
	je	.L34
.L11:
	movl	(%r15), %eax
	cmpl	%eax, 92(%rsp)
	je	.L35
.L13:
	movl	(%r15), %eax
	cmpl	%eax, 99(%rsp)
	je	.L36
.L15:
	movq	%r15, %rsi
	movq	%r14, %rdi
	call	strcmp@PLT
	cmpl	$1, %eax
	movl	$6, %eax
	sbbl	$-1, %eax
.L17:
	cltq
	addl	$1, %ebx
	salq	$4, %rax
	movslq	116(%rsp,%rax), %rsi
	movslq	112(%rsp,%rax), %rcx
	movl	32(%rsp,%rsi,4), %r8d
	movl	32(%rsp,%rcx,4), %edi
	movl	%r8d, 32(%rsp,%rcx,4)
	movslq	120(%rsp,%rax), %rcx
	movslq	124(%rsp,%rax), %rax
	movl	32(%rsp,%rcx,4), %r8d
	movl	%r8d, 32(%rsp,%rsi,4)
	movl	32(%rsp,%rax,4), %esi
	movl	%esi, 32(%rsp,%rcx,4)
	movl	%edi, 32(%rsp,%rax,4)
	addl	32(%rsp), %r12d
	cmpl	%ebx, 28(%rsp)
	jle	.L3
.L18:
	movq	%r15, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	(%r15), %eax
	cmpl	%eax, 0(%rbp)
	jne	.L4
	movzwl	4(%r15), %eax
	cmpw	%ax, 4(%rbp)
	jne	.L4
	xorl	%eax, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L32:
	movzbl	4(%r15), %eax
	cmpb	%al, 75(%rsp)
	jne	.L7
	movl	$1, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L33:
	movzbl	4(%r15), %eax
	cmpb	%al, 82(%rsp)
	jne	.L9
	movl	$2, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L34:
	movzwl	4(%r15), %eax
	cmpw	%ax, 89(%rsp)
	jne	.L11
	movl	$3, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L35:
	movzwl	4(%r15), %eax
	cmpw	%ax, 96(%rsp)
	jne	.L13
	movl	$4, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L36:
	movzbl	4(%r15), %eax
	cmpb	%al, 103(%rsp)
	jne	.L15
	movl	$5, %eax
	jmp	.L17
.L21:
	movl	$1, %r12d
	.p2align 4,,10
	.p2align 3
.L3:
	movl	%r12d, %edx
	leaq	.LC10(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L19
.L2:
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L37
	addq	$232, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L37:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	0
	.long	1
	.long	5
	.long	4
	.align 16
.LC1:
	.long	0
	.long	3
	.long	5
	.long	2
	.align 16
.LC2:
	.long	0
	.long	2
	.long	5
	.long	3
	.align 16
.LC3:
	.long	0
	.long	4
	.long	5
	.long	1
	.align 16
.LC4:
	.long	1
	.long	2
	.long	4
	.long	3
	.align 16
.LC5:
	.long	1
	.long	3
	.long	4
	.long	2
	.align 16
.LC7:
	.long	1
	.long	2
	.long	3
	.long	4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC8:
	.long	5
	.long	6
	.section	.rodata.cst16
	.align 16
.LC11:
	.quad	4971974437247283022
	.quad	7302305320812180321
	.align 16
.LC12:
	.quad	8462073484317586547
	.quad	7523097503453964404
	.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
.LC6:
	.string	"%d"
.LC9:
	.string	"%s"
.LC10:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%edx, %edx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$232, %rsp
	.cfi_def_cfa_offset 288
	movdqa	.LC0(%rip), %xmm0
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	movw	%dx, 104(%rsp)
	leaq	106(%rsp), %r14
	movabsq	$32763682551234676, %rax
	movaps	%xmm0, 112(%rsp)
	movdqa	.LC1(%rip), %xmm0
	movq	%rax, 96(%rsp)
	leaq	28(%rsp), %rax
	movaps	%xmm0, 128(%rsp)
	movdqa	.LC2(%rip), %xmm0
	movq	%rax, 8(%rsp)
	movaps	%xmm0, 144(%rsp)
	movdqa	.LC3(%rip), %xmm0
	movaps	%xmm0, 160(%rsp)
	movdqa	.LC4(%rip), %xmm0
	movaps	%xmm0, 176(%rsp)
	movdqa	.LC5(%rip), %xmm0
	movaps	%xmm0, 192(%rsp)
	movdqa	.LC11(%rip), %xmm0
	movaps	%xmm0, 64(%rsp)
	movdqa	.LC12(%rip), %xmm0
	movaps	%xmm0, 80(%rsp)
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rsi
	leaq	.LC6(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	testl	%eax, %eax
	je	.L2
	movdqa	.LC7(%rip), %xmm1
	movq	.LC8(%rip), %rax
	movaps	%xmm1, 32(%rsp)
	movq	%rax, 48(%rsp)
	jle	.L21
	xorl	%ebx, %ebx
	movl	$1, %r12d
	leaq	209(%rsp), %r15
	leaq	.LC9(%rip), %r13
	leaq	64(%rsp), %rbp
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L4:
	movl	(%r15), %eax
	cmpl	%eax, 71(%rsp)
	je	.L32
.L7:
	movl	(%r15), %eax
	cmpl	%eax, 78(%rsp)
	je	.L33
.L9:
	movl	(%r15), %eax
	cmpl	%eax, 85(%rsp)
	je	.L34
.L11:
	movl	(%r15), %eax
	cmpl	%eax, 92(%rsp)
	je	.L35
.L13:
	movl	(%r15), %eax
	cmpl	%eax, 99(%rsp)
	je	.L36
.L15:
	movq	%r15, %rsi
	movq	%r14, %rdi
	call	strcmp@PLT
	cmpl	$1, %eax
	movl	$6, %eax
	sbbl	$-1, %eax
.L17:
	cltq
	addl	$1, %ebx
	salq	$4, %rax
	movslq	116(%rsp,%rax), %rsi
	movslq	112(%rsp,%rax), %rcx
	movl	32(%rsp,%rsi,4), %r8d
	movl	32(%rsp,%rcx,4), %edi
	movl	%r8d, 32(%rsp,%rcx,4)
	movslq	120(%rsp,%rax), %rcx
	movslq	124(%rsp,%rax), %rax
	movl	32(%rsp,%rcx,4), %r8d
	movl	%r8d, 32(%rsp,%rsi,4)
	movl	32(%rsp,%rax,4), %esi
	movl	%esi, 32(%rsp,%rcx,4)
	movl	%edi, 32(%rsp,%rax,4)
	addl	32(%rsp), %r12d
	cmpl	%ebx, 28(%rsp)
	jle	.L3
.L18:
	movq	%r15, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	(%r15), %eax
	cmpl	%eax, 0(%rbp)
	jne	.L4
	movzwl	4(%r15), %eax
	cmpw	%ax, 4(%rbp)
	jne	.L4
	xorl	%eax, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L32:
	movzbl	4(%r15), %eax
	cmpb	%al, 75(%rsp)
	jne	.L7
	movl	$1, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L33:
	movzbl	4(%r15), %eax
	cmpb	%al, 82(%rsp)
	jne	.L9
	movl	$2, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L34:
	movzwl	4(%r15), %eax
	cmpw	%ax, 89(%rsp)
	jne	.L11
	movl	$3, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L35:
	movzwl	4(%r15), %eax
	cmpw	%ax, 96(%rsp)
	jne	.L13
	movl	$4, %eax
	jmp	.L17
	.p2align 4,,10
	.p2align 3
.L36:
	movzbl	4(%r15), %eax
	cmpb	%al, 103(%rsp)
	jne	.L15
	movl	$5, %eax
	jmp	.L17
.L21:
	movl	$1, %r12d
	.p2align 4,,10
	.p2align 3
.L3:
	movl	%r12d, %edx
	leaq	.LC10(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L19
.L2:
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L37
	addq	$232, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L37:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	0
	.long	1
	.long	5
	.long	4
	.align 16
.LC1:
	.long	0
	.long	3
	.long	5
	.long	2
	.align 16
.LC2:
	.long	0
	.long	2
	.long	5
	.long	3
	.align 16
.LC3:
	.long	0
	.long	4
	.long	5
	.long	1
	.align 16
.LC4:
	.long	1
	.long	2
	.long	4
	.long	3
	.align 16
.LC5:
	.long	1
	.long	3
	.long	4
	.long	2
	.align 16
.LC7:
	.long	1
	.long	2
	.long	3
	.long	4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC8:
	.long	5
	.long	6
	.section	.rodata.cst16
	.align 16
.LC11:
	.quad	4971974437247283022
	.quad	7302305320812180321
	.align 16
.LC12:
	.quad	8462073484317586547
	.quad	7523097503453964404
	.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>
int main(){
  int r[6][4]={
    {0,1,5,4},
    {0,3,5,2},
    {0,2,5,3},
    {0,4,5,1},
    {1,2,4,3},
    {1,3,4,2}
  };
  char W[6][7]={"North","East","West","South","Right","Left"};
  int n,s,i,j,k,t;
  char w[7];
  while(1){
    scanf("%d",&n);
    if(!n)break;
    int D[]={1,2,3,4,5,6};
    s=1;
    for(i=0;i<n;i++){
      scanf("%s",w);
      for(j=0;j<7;j++){
	if(strcmp(W[j],w)==0)break;
      }
      t=D[r[j][0]];
      for(k=0;k<3;k++)D[r[j][k]]=D[r[j][k+1]];
      D[r[j][3]]=t;
      s+=D[0];
      /*printf(" %d\n",D[2]);
      printf("%d%d%d%d\n",D[0],D[1],D[5],D[4]);
      printf(" %d\n",D[3]);*/
    }
    printf("%d\n",s);
  }
  return 0;
}
5
North
North
East
South
West
8
West
North
Left
South
Right
North
Left
East
0
 5
North
North
East
South
West
8
West
North
Left
South
Right
North
Left
East
0

21
34
 21
34

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>
int main(){
  int r[6][4]={
    {0,1,5,4},
    {0,3,5,2},
    {0,2,5,3},
    {0,4,5,1},
    {1,2,4,3},
    {1,3,4,2}
  };
  char W[6][7]={"North","East","West","South","Right","Left"};
  int n,s,i,j,k,t;
  char w[7];
  while(1){
    scanf("%d",&n);
    if(!n)break;
    int D[]={1,2,3,4,5,6};
    s=1;
    for(i=0;i<n;i++){
      scanf("%s",w);
      for(j=0;j<7;j++){
	if(strcmp(W[j],w)==0)break;
      }
      t=D[r[j][0]];
      for(k=0;k<3;k++)D[r[j][k]]=D[r[j][k+1]];
      D[r[j][3]]=t;
      s+=D[0];
      /*printf(" %d\n",D[2]);
      printf("%d%d%d%d\n",D[0],D[1],D[5],D[4]);
      printf(" %d\n",D[3]);*/
    }
    printf("%d\n",s);
  }
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$224, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -112(%rbp)
	movl	$1, -108(%rbp)
	movl	$5, -104(%rbp)
	movl	$4, -100(%rbp)
	movl	$0, -96(%rbp)
	movl	$3, -92(%rbp)
	movl	$5, -88(%rbp)
	movl	$2, -84(%rbp)
	movl	$0, -80(%rbp)
	movl	$2, -76(%rbp)
	movl	$5, -72(%rbp)
	movl	$3, -68(%rbp)
	movl	$0, -64(%rbp)
	movl	$4, -60(%rbp)
	movl	$5, -56(%rbp)
	movl	$1, -52(%rbp)
	movl	$1, -48(%rbp)
	movl	$2, -44(%rbp)
	movl	$4, -40(%rbp)
	movl	$3, -36(%rbp)
	movl	$1, -32(%rbp)
	movl	$3, -28(%rbp)
	movl	$4, -24(%rbp)
	movl	$2, -20(%rbp)
	movl	$1953656654, -160(%rbp)
	movw	$104, -156(%rbp)
	movb	$0, -154(%rbp)
	movl	$1953718597, -153(%rbp)
	movw	$0, -149(%rbp)
	movb	$0, -147(%rbp)
	movl	$1953719639, -146(%rbp)
	movw	$0, -142(%rbp)
	movb	$0, -140(%rbp)
	movl	$1953853267, -139(%rbp)
	movw	$104, -135(%rbp)
	movb	$0, -133(%rbp)
	movl	$1751607634, -132(%rbp)
	movw	$116, -128(%rbp)
	movb	$0, -126(%rbp)
	movl	$1952867660, -125(%rbp)
	movw	$0, -121(%rbp)
	movb	$0, -119(%rbp)
.L12:
	leaq	-216(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-216(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	jmp	.L14
.L2:
	movl	$1, -192(%rbp)
	movl	$2, -188(%rbp)
	movl	$3, -184(%rbp)
	movl	$4, -180(%rbp)
	movl	$5, -176(%rbp)
	movl	$6, -172(%rbp)
	movl	$1, -212(%rbp)
	movl	$0, -208(%rbp)
	jmp	.L4
.L11:
	leaq	-15(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -204(%rbp)
	jmp	.L5
.L8:
	leaq	-160(%rbp), %rcx
	movl	-204(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	subq	%rdx, %rax
	leaq	(%rcx,%rax), %rdx
	leaq	-15(%rbp), %rax
	movq	%rax, %rsi
	movq	%rdx, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L15
	addl	$1, -204(%rbp)
.L5:
	cmpl	$6, -204(%rbp)
	jle	.L8
	jmp	.L7
.L15:
	nop
.L7:
	movl	-204(%rbp), %eax
	cltq
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$112, %rax
	movl	(%rax), %eax
	cltq
	movl	-192(%rbp,%rax,4), %eax
	movl	%eax, -196(%rbp)
	movl	$0, -200(%rbp)
	jmp	.L9
.L10:
	movl	-200(%rbp), %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-204(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	-112(%rbp,%rax,4), %eax
	movl	-200(%rbp), %edx
	movslq	%edx, %rcx
	movl	-204(%rbp), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	addq	%rcx, %rdx
	movl	-112(%rbp,%rdx,4), %ecx
	cltq
	movl	-192(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -192(%rbp,%rax,4)
	addl	$1, -200(%rbp)
.L9:
	cmpl	$2, -200(%rbp)
	jle	.L10
	movl	-204(%rbp), %eax
	cltq
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$100, %rax
	movl	(%rax), %eax
	cltq
	movl	-196(%rbp), %edx
	movl	%edx, -192(%rbp,%rax,4)
	movl	-192(%rbp), %eax
	addl	%eax, -212(%rbp)
	addl	$1, -208(%rbp)
.L4:
	movl	-216(%rbp), %eax
	cmpl	%eax, -208(%rbp)
	jl	.L11
	movl	-212(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L12
.L14:
	call	__stack_chk_fail@PLT
.L13:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$224, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -112(%rbp)
	movl	$1, -108(%rbp)
	movl	$5, -104(%rbp)
	movl	$4, -100(%rbp)
	movl	$0, -96(%rbp)
	movl	$3, -92(%rbp)
	movl	$5, -88(%rbp)
	movl	$2, -84(%rbp)
	movl	$0, -80(%rbp)
	movl	$2, -76(%rbp)
	movl	$5, -72(%rbp)
	movl	$3, -68(%rbp)
	movl	$0, -64(%rbp)
	movl	$4, -60(%rbp)
	movl	$5, -56(%rbp)
	movl	$1, -52(%rbp)
	movl	$1, -48(%rbp)
	movl	$2, -44(%rbp)
	movl	$4, -40(%rbp)
	movl	$3, -36(%rbp)
	movl	$1, -32(%rbp)
	movl	$3, -28(%rbp)
	movl	$4, -24(%rbp)
	movl	$2, -20(%rbp)
	movl	$1953656654, -160(%rbp)
	movw	$104, -156(%rbp)
	movb	$0, -154(%rbp)
	movl	$1953718597, -153(%rbp)
	movw	$0, -149(%rbp)
	movb	$0, -147(%rbp)
	movl	$1953719639, -146(%rbp)
	movw	$0, -142(%rbp)
	movb	$0, -140(%rbp)
	movl	$1953853267, -139(%rbp)
	movw	$104, -135(%rbp)
	movb	$0, -133(%rbp)
	movl	$1751607634, -132(%rbp)
	movw	$116, -128(%rbp)
	movb	$0, -126(%rbp)
	movl	$1952867660, -125(%rbp)
	movw	$0, -121(%rbp)
	movb	$0, -119(%rbp)
.L12:
	leaq	-216(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-216(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	jmp	.L14
.L2:
	movl	$1, -192(%rbp)
	movl	$2, -188(%rbp)
	movl	$3, -184(%rbp)
	movl	$4, -180(%rbp)
	movl	$5, -176(%rbp)
	movl	$6, -172(%rbp)
	movl	$1, -212(%rbp)
	movl	$0, -208(%rbp)
	jmp	.L4
.L11:
	leaq	-15(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -204(%rbp)
	jmp	.L5
.L8:
	leaq	-160(%rbp), %rcx
	movl	-204(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$3, %rax
	subq	%rdx, %rax
	leaq	(%rcx,%rax), %rdx
	leaq	-15(%rbp), %rax
	movq	%rax, %rsi
	movq	%rdx, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L15
	addl	$1, -204(%rbp)
.L5:
	cmpl	$6, -204(%rbp)
	jle	.L8
	jmp	.L7
.L15:
	nop
.L7:
	movl	-204(%rbp), %eax
	cltq
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$112, %rax
	movl	(%rax), %eax
	cltq
	movl	-192(%rbp,%rax,4), %eax
	movl	%eax, -196(%rbp)
	movl	$0, -200(%rbp)
	jmp	.L9
.L10:
	movl	-200(%rbp), %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-204(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movl	-112(%rbp,%rax,4), %eax
	movl	-200(%rbp), %edx
	movslq	%edx, %rcx
	movl	-204(%rbp), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	addq	%rcx, %rdx
	movl	-112(%rbp,%rdx,4), %ecx
	cltq
	movl	-192(%rbp,%rax,4), %edx
	movslq	%ecx, %rax
	movl	%edx, -192(%rbp,%rax,4)
	addl	$1, -200(%rbp)
.L9:
	cmpl	$2, -200(%rbp)
	jle	.L10
	movl	-204(%rbp), %eax
	cltq
	salq	$4, %rax
	addq	%rbp, %rax
	subq	$100, %rax
	movl	(%rax), %eax
	cltq
	movl	-196(%rbp), %edx
	movl	%edx, -192(%rbp,%rax,4)
	movl	-192(%rbp), %eax
	addl	%eax, -212(%rbp)
	addl	$1, -208(%rbp)
.L4:
	movl	-216(%rbp), %eax
	cmpl	%eax, -208(%rbp)
	jl	.L11
	movl	-212(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L12
.L14:
	call	__stack_chk_fail@PLT
.L13:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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:
