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>
int main(){
    while(1){
        int n, i, dice[6], sum = 1;
        for(i=0; i<6; i++)
            dice[i] = i+1;
        scanf("%d", &n);
        if (n == 0)
            return 0;
        for (i=0; i<n; i++){
            //char *str = NULL;
            char str[8];
            int tmp;
            scanf("%s", str);
            switch(str[0]){
                case 'N':
                    tmp = dice[0];
                    dice[0] = dice[1];
                    dice[1] = dice[5];
                    dice[5] = dice[4];
                    dice[4] = tmp;
                    break;
                case 'E':
                    tmp = dice[0];
                    dice[0] = dice[3];
                    dice[3] = dice[5];
                    dice[5] = dice[2];
                    dice[2] = tmp;
                    break;
                case 'W':
                    tmp = dice[0];
                    dice[0] = dice[2];
                    dice[2] = dice[5];
                    dice[5] = dice[3];
                    dice[3] = tmp;
                    break;
                case 'S':
                    tmp = dice[0];
                    dice[0] = dice[4];
                    dice[4] = dice[5];
                    dice[5] = dice[1];
                    dice[1] = tmp;
                    break;
                case 'R':
                    tmp = dice[1];
                    dice[1] = dice[2];
                    dice[2] = dice[4];
                    dice[4] = dice[3];
                    dice[3] = tmp;
                    break;
                case 'L':
                    tmp = dice[1];
                    dice[1] = dice[3];
                    dice[3] = dice[4];
                    dice[4] = dice[2];
                    dice[2] = tmp;
                    break;
            }
            sum += dice[0];
        }
        printf("%d\n", sum);
    }
}```

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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L16:
	movl	$1, -56(%rbp)
	movl	$0, -60(%rbp)
	jmp	.L2
.L3:
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movl	-60(%rbp), %eax
	cltq
	movl	%edx, -48(%rbp,%rax,4)
	addl	$1, -60(%rbp)
.L2:
	cmpl	$5, -60(%rbp)
	jle	.L3
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %eax
	testl	%eax, %eax
	jne	.L4
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	jmp	.L18
.L4:
	movl	$0, -60(%rbp)
	jmp	.L6
.L15:
	leaq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movzbl	-16(%rbp), %eax
	movsbl	%al, %eax
	subl	$69, %eax
	cmpl	$18, %eax
	ja	.L7
	movl	%eax, %eax
	leaq	0(,%rax,4), %rdx
	leaq	.L9(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	.L9(%rip), %rdx
	addq	%rdx, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L9:
	.long	.L14-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L13-.L9
	.long	.L7-.L9
	.long	.L12-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L11-.L9
	.long	.L10-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L8-.L9
	.text
.L12:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -32(%rbp)
	jmp	.L7
.L14:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -36(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -40(%rbp)
	jmp	.L7
.L8:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -40(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L10:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -44(%rbp)
	jmp	.L7
.L11:
	movl	-44(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -40(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L13:
	movl	-44(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -36(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -40(%rbp)
	nop
.L7:
	movl	-48(%rbp), %eax
	addl	%eax, -56(%rbp)
	addl	$1, -60(%rbp)
.L6:
	movl	-64(%rbp), %eax
	cmpl	%eax, -60(%rbp)
	jl	.L15
	movl	-56(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L16
.L18:
	call	__stack_chk_fail@PLT
.L17:
	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
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC1(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.L7(%rip), %r14
	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	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movq	%rax, 24(%rsp)
	.p2align 4,,10
	.p2align 3
.L13:
	movq	24(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %eax
	testl	%eax, %eax
	je	.L2
	movl	$1, %r12d
	jle	.L4
	movl	$6, 20(%rsp)
	movl	$1, %ebx
	xorl	%ebp, %ebp
	movl	$1, %r12d
	movl	$5, 16(%rsp)
	leaq	48(%rsp), %r13
	movl	$4, 8(%rsp)
	movl	$3, 4(%rsp)
	movl	$2, 12(%rsp)
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r13, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movzbl	48(%rsp), %eax
	subl	$69, %eax
	cmpb	$18, %al
	ja	.L5
	movzbl	%al, %eax
	movslq	(%r14,%rax,4), %rax
	addq	%r14, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L7:
	.long	.L12-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L11-.L7
	.long	.L5-.L7
	.long	.L10-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L9-.L7
	.long	.L8-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L6-.L7
	.section	.text.startup
	.p2align 4,,10
	.p2align 3
.L12:
	movl	20(%rsp), %ecx
	movl	4(%rsp), %edx
	movl	%ebx, %eax
	movl	%eax, 4(%rsp)
	movl	8(%rsp), %ebx
	movl	%edx, 20(%rsp)
	movl	%ecx, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L5:
	addl	%ebx, %r12d
	addl	$1, %ebp
	cmpl	%ebp, 44(%rsp)
	jg	.L3
.L4:
	movl	%r12d, %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L6:
	movl	20(%rsp), %ecx
	movl	8(%rsp), %edx
	movl	%ebx, %eax
	addl	$1, %ebp
	movl	4(%rsp), %ebx
	movl	%eax, 8(%rsp)
	movl	%ecx, 4(%rsp)
	movl	%edx, 20(%rsp)
	addl	%ebx, %r12d
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L8:
	movl	20(%rsp), %ecx
	movl	12(%rsp), %edx
	movl	%ebx, %eax
	addl	$1, %ebp
	movl	16(%rsp), %ebx
	movl	%eax, 12(%rsp)
	movl	%ecx, 16(%rsp)
	movl	%edx, 20(%rsp)
	addl	%ebx, %r12d
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L9:
	movl	4(%rsp), %ecx
	movl	12(%rsp), %eax
	addl	%ebx, %r12d
	addl	$1, %ebp
	movl	16(%rsp), %edx
	movl	%ecx, 12(%rsp)
	movl	8(%rsp), %ecx
	movl	%edx, 4(%rsp)
	movl	%ecx, 16(%rsp)
	movl	%eax, 8(%rsp)
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L11:
	movl	12(%rsp), %eax
	movl	8(%rsp), %esi
	addl	%ebx, %r12d
	addl	$1, %ebp
	movl	16(%rsp), %edi
	movl	4(%rsp), %edx
	movl	%esi, 12(%rsp)
	movl	%edi, 8(%rsp)
	movl	%edx, 16(%rsp)
	movl	%eax, 4(%rsp)
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L10:
	movl	20(%rsp), %ecx
	movl	%ebx, %eax
	movl	12(%rsp), %ebx
	addl	$1, %ebp
	movl	%ecx, 12(%rsp)
	movl	16(%rsp), %ecx
	addl	%ebx, %r12d
	movl	%eax, 16(%rsp)
	movl	%ecx, 20(%rsp)
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L2:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$72, %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
.L20:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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	"%d"
.LC1:
	.string	"%s"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC1(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.L7(%rip), %r14
	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	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movq	%rax, 24(%rsp)
	.p2align 4,,10
	.p2align 3
.L13:
	movq	24(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %eax
	testl	%eax, %eax
	je	.L2
	movl	$1, %r12d
	jle	.L4
	movl	$6, 20(%rsp)
	movl	$1, %ebx
	xorl	%ebp, %ebp
	movl	$1, %r12d
	movl	$5, 16(%rsp)
	leaq	48(%rsp), %r13
	movl	$4, 8(%rsp)
	movl	$3, 4(%rsp)
	movl	$2, 12(%rsp)
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%r13, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movzbl	48(%rsp), %eax
	subl	$69, %eax
	cmpb	$18, %al
	ja	.L5
	movzbl	%al, %eax
	movslq	(%r14,%rax,4), %rax
	addq	%r14, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L7:
	.long	.L12-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L11-.L7
	.long	.L5-.L7
	.long	.L10-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L9-.L7
	.long	.L8-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L5-.L7
	.long	.L6-.L7
	.section	.text.startup
	.p2align 4,,10
	.p2align 3
.L12:
	movl	20(%rsp), %ecx
	movl	4(%rsp), %edx
	movl	%ebx, %eax
	movl	%eax, 4(%rsp)
	movl	8(%rsp), %ebx
	movl	%edx, 20(%rsp)
	movl	%ecx, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L5:
	addl	%ebx, %r12d
	addl	$1, %ebp
	cmpl	%ebp, 44(%rsp)
	jg	.L3
.L4:
	movl	%r12d, %edx
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L6:
	movl	20(%rsp), %ecx
	movl	8(%rsp), %edx
	movl	%ebx, %eax
	addl	$1, %ebp
	movl	4(%rsp), %ebx
	movl	%eax, 8(%rsp)
	movl	%ecx, 4(%rsp)
	movl	%edx, 20(%rsp)
	addl	%ebx, %r12d
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L8:
	movl	20(%rsp), %ecx
	movl	12(%rsp), %edx
	movl	%ebx, %eax
	addl	$1, %ebp
	movl	16(%rsp), %ebx
	movl	%eax, 12(%rsp)
	movl	%ecx, 16(%rsp)
	movl	%edx, 20(%rsp)
	addl	%ebx, %r12d
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L9:
	movl	4(%rsp), %ecx
	movl	12(%rsp), %eax
	addl	%ebx, %r12d
	addl	$1, %ebp
	movl	16(%rsp), %edx
	movl	%ecx, 12(%rsp)
	movl	8(%rsp), %ecx
	movl	%edx, 4(%rsp)
	movl	%ecx, 16(%rsp)
	movl	%eax, 8(%rsp)
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L11:
	movl	12(%rsp), %eax
	movl	8(%rsp), %esi
	addl	%ebx, %r12d
	addl	$1, %ebp
	movl	16(%rsp), %edi
	movl	4(%rsp), %edx
	movl	%esi, 12(%rsp)
	movl	%edi, 8(%rsp)
	movl	%edx, 16(%rsp)
	movl	%eax, 4(%rsp)
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L10:
	movl	20(%rsp), %ecx
	movl	%ebx, %eax
	movl	12(%rsp), %ebx
	addl	$1, %ebp
	movl	%ecx, 12(%rsp)
	movl	16(%rsp), %ecx
	addl	%ebx, %r12d
	movl	%eax, 16(%rsp)
	movl	%ecx, 20(%rsp)
	cmpl	%ebp, 44(%rsp)
	jg	.L3
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L2:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$72, %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
.L20:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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>
int main(){
    while(1){
        int n, i, dice[6], sum = 1;
        for(i=0; i<6; i++)
            dice[i] = i+1;
        scanf("%d", &n);
        if (n == 0)
            return 0;
        for (i=0; i<n; i++){
            //char *str = NULL;
            char str[8];
            int tmp;
            scanf("%s", str);
            switch(str[0]){
                case 'N':
                    tmp = dice[0];
                    dice[0] = dice[1];
                    dice[1] = dice[5];
                    dice[5] = dice[4];
                    dice[4] = tmp;
                    break;
                case 'E':
                    tmp = dice[0];
                    dice[0] = dice[3];
                    dice[3] = dice[5];
                    dice[5] = dice[2];
                    dice[2] = tmp;
                    break;
                case 'W':
                    tmp = dice[0];
                    dice[0] = dice[2];
                    dice[2] = dice[5];
                    dice[5] = dice[3];
                    dice[3] = tmp;
                    break;
                case 'S':
                    tmp = dice[0];
                    dice[0] = dice[4];
                    dice[4] = dice[5];
                    dice[5] = dice[1];
                    dice[1] = tmp;
                    break;
                case 'R':
                    tmp = dice[1];
                    dice[1] = dice[2];
                    dice[2] = dice[4];
                    dice[4] = dice[3];
                    dice[3] = tmp;
                    break;
                case 'L':
                    tmp = dice[1];
                    dice[1] = dice[3];
                    dice[3] = dice[4];
                    dice[4] = dice[2];
                    dice[2] = tmp;
                    break;
            }
            sum += dice[0];
        }
        printf("%d\n", sum);
    }
}
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>
int main(){
    while(1){
        int n, i, dice[6], sum = 1;
        for(i=0; i<6; i++)
            dice[i] = i+1;
        scanf("%d", &n);
        if (n == 0)
            return 0;
        for (i=0; i<n; i++){
            //char *str = NULL;
            char str[8];
            int tmp;
            scanf("%s", str);
            switch(str[0]){
                case 'N':
                    tmp = dice[0];
                    dice[0] = dice[1];
                    dice[1] = dice[5];
                    dice[5] = dice[4];
                    dice[4] = tmp;
                    break;
                case 'E':
                    tmp = dice[0];
                    dice[0] = dice[3];
                    dice[3] = dice[5];
                    dice[5] = dice[2];
                    dice[2] = tmp;
                    break;
                case 'W':
                    tmp = dice[0];
                    dice[0] = dice[2];
                    dice[2] = dice[5];
                    dice[5] = dice[3];
                    dice[3] = tmp;
                    break;
                case 'S':
                    tmp = dice[0];
                    dice[0] = dice[4];
                    dice[4] = dice[5];
                    dice[5] = dice[1];
                    dice[1] = tmp;
                    break;
                case 'R':
                    tmp = dice[1];
                    dice[1] = dice[2];
                    dice[2] = dice[4];
                    dice[4] = dice[3];
                    dice[3] = tmp;
                    break;
                case 'L':
                    tmp = dice[1];
                    dice[1] = dice[3];
                    dice[3] = dice[4];
                    dice[4] = dice[2];
                    dice[2] = tmp;
                    break;
            }
            sum += dice[0];
        }
        printf("%d\n", sum);
    }
}```

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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L16:
	movl	$1, -56(%rbp)
	movl	$0, -60(%rbp)
	jmp	.L2
.L3:
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movl	-60(%rbp), %eax
	cltq
	movl	%edx, -48(%rbp,%rax,4)
	addl	$1, -60(%rbp)
.L2:
	cmpl	$5, -60(%rbp)
	jle	.L3
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %eax
	testl	%eax, %eax
	jne	.L4
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	jmp	.L18
.L4:
	movl	$0, -60(%rbp)
	jmp	.L6
.L15:
	leaq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movzbl	-16(%rbp), %eax
	movsbl	%al, %eax
	subl	$69, %eax
	cmpl	$18, %eax
	ja	.L7
	movl	%eax, %eax
	leaq	0(,%rax,4), %rdx
	leaq	.L9(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	.L9(%rip), %rdx
	addq	%rdx, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L9:
	.long	.L14-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L13-.L9
	.long	.L7-.L9
	.long	.L12-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L11-.L9
	.long	.L10-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L8-.L9
	.text
.L12:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -32(%rbp)
	jmp	.L7
.L14:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -36(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -40(%rbp)
	jmp	.L7
.L8:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -40(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L10:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -44(%rbp)
	jmp	.L7
.L11:
	movl	-44(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -40(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L13:
	movl	-44(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -36(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -40(%rbp)
	nop
.L7:
	movl	-48(%rbp), %eax
	addl	%eax, -56(%rbp)
	addl	$1, -60(%rbp)
.L6:
	movl	-64(%rbp), %eax
	cmpl	%eax, -60(%rbp)
	jl	.L15
	movl	-56(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L16
.L18:
	call	__stack_chk_fail@PLT
.L17:
	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	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L16:
	movl	$1, -56(%rbp)
	movl	$0, -60(%rbp)
	jmp	.L2
.L3:
	movl	-60(%rbp), %eax
	leal	1(%rax), %edx
	movl	-60(%rbp), %eax
	cltq
	movl	%edx, -48(%rbp,%rax,4)
	addl	$1, -60(%rbp)
.L2:
	cmpl	$5, -60(%rbp)
	jle	.L3
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %eax
	testl	%eax, %eax
	jne	.L4
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L17
	jmp	.L18
.L4:
	movl	$0, -60(%rbp)
	jmp	.L6
.L15:
	leaq	-16(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movzbl	-16(%rbp), %eax
	movsbl	%al, %eax
	subl	$69, %eax
	cmpl	$18, %eax
	ja	.L7
	movl	%eax, %eax
	leaq	0(,%rax,4), %rdx
	leaq	.L9(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	.L9(%rip), %rdx
	addq	%rdx, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L9:
	.long	.L14-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L13-.L9
	.long	.L7-.L9
	.long	.L12-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L11-.L9
	.long	.L10-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L7-.L9
	.long	.L8-.L9
	.text
.L12:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -32(%rbp)
	jmp	.L7
.L14:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -36(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -40(%rbp)
	jmp	.L7
.L8:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -40(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L10:
	movl	-48(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -28(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -44(%rbp)
	jmp	.L7
.L11:
	movl	-44(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -40(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L13:
	movl	-44(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -44(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -36(%rbp)
	movl	-40(%rbp), %eax
	movl	%eax, -32(%rbp)
	movl	-52(%rbp), %eax
	movl	%eax, -40(%rbp)
	nop
.L7:
	movl	-48(%rbp), %eax
	addl	%eax, -56(%rbp)
	addl	$1, -60(%rbp)
.L6:
	movl	-64(%rbp), %eax
	cmpl	%eax, -60(%rbp)
	jl	.L15
	movl	-56(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L16
.L18:
	call	__stack_chk_fail@PLT
.L17:
	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:
