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>
typedef struct left_{
    int w;
    int e;
}left_t;
typedef struct right_{
    int w;
    int e;
}right_t;

int main(){
    int n;
    char str[500000];
    left_t left;
    right_t right;
    left.w=left.e=0;
    right.w=right.e=0;

    scanf("%d",&n);
    scanf("%s",str);
    for(int i=0;i<n;i++){
        if(str[i]=='W'){
            right.w++;
        }else{
            right.e++;
        }
    }
    int cnt=0;
    int min=99999999;
    for(int i=0;i<n;i++){
        cnt=0;
        //printf("right e:%d w:%d\n",right.e,right.w);
        //printf("left  e:%d w:%d\n",left.e,left.w);
        if(str[i]=='W'){
            right.w--;
            cnt+=right.e;
            cnt+=left.w;
            left.w++;
        }else{
            right.e--;
            cnt+=right.e;
            cnt+=left.w;
            left.e++;
        }
        if(min>cnt){
            min=cnt;
        }
        //printf("%d\n",min);
    }
    printf("%d\n",min);
    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
	leaq	-499712(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$352, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -500028(%rbp)
	movl	-500028(%rbp), %eax
	movl	%eax, -500032(%rbp)
	movl	$0, -500020(%rbp)
	movl	-500020(%rbp), %eax
	movl	%eax, -500024(%rbp)
	leaq	-500052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-500016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -500048(%rbp)
	jmp	.L2
.L5:
	movl	-500048(%rbp), %eax
	cltq
	movzbl	-500016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L3
	movl	-500024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500024(%rbp)
	jmp	.L4
.L3:
	movl	-500020(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500020(%rbp)
.L4:
	addl	$1, -500048(%rbp)
.L2:
	movl	-500052(%rbp), %eax
	cmpl	%eax, -500048(%rbp)
	jl	.L5
	movl	$0, -500044(%rbp)
	movl	$99999999, -500040(%rbp)
	movl	$0, -500036(%rbp)
	jmp	.L6
.L10:
	movl	$0, -500044(%rbp)
	movl	-500036(%rbp), %eax
	cltq
	movzbl	-500016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L7
	movl	-500024(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -500024(%rbp)
	movl	-500020(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500032(%rbp)
	jmp	.L8
.L7:
	movl	-500020(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -500020(%rbp)
	movl	-500020(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500028(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500028(%rbp)
.L8:
	movl	-500040(%rbp), %eax
	cmpl	-500044(%rbp), %eax
	jle	.L9
	movl	-500044(%rbp), %eax
	movl	%eax, -500040(%rbp)
.L9:
	addl	$1, -500036(%rbp)
.L6:
	movl	-500052(%rbp), %eax
	cmpl	%eax, -500036(%rbp)
	jl	.L10
	movl	-500040(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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"
.LC4:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	-499712(%rsp), %r11
	.cfi_def_cfa 11, 499728
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$320, %rsp
	.cfi_def_cfa_offset 500048
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 500024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	16(%rsp), %rbx
	call	__isoc99_scanf@PLT
	movq	%rbx, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edx
	testl	%edx, %edx
	jle	.L26
	leal	-1(%rdx), %esi
	cmpl	$14, %esi
	jbe	.L27
	movl	%edx, %ecx
	pxor	%xmm1, %xmm1
	pxor	%xmm5, %xmm5
	movq	%rbx, %rax
	shrl	$4, %ecx
	movdqa	.LC2(%rip), %xmm7
	movdqa	.LC3(%rip), %xmm6
	pxor	%xmm4, %xmm4
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	32(%rsp,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L4:
	movdqa	%xmm7, %xmm0
	movdqa	%xmm5, %xmm3
	addq	$16, %rax
	pcmpeqb	-16(%rax), %xmm0
	pandn	%xmm6, %xmm0
	pcmpgtb	%xmm0, %xmm3
	movdqa	%xmm0, %xmm2
	punpcklbw	%xmm3, %xmm2
	punpckhbw	%xmm3, %xmm0
	movdqa	%xmm4, %xmm3
	pcmpgtw	%xmm2, %xmm3
	movdqa	%xmm2, %xmm8
	punpcklwd	%xmm3, %xmm8
	punpckhwd	%xmm3, %xmm2
	movdqa	%xmm0, %xmm3
	paddd	%xmm8, %xmm1
	paddd	%xmm2, %xmm1
	movdqa	%xmm4, %xmm2
	pcmpgtw	%xmm0, %xmm2
	punpcklwd	%xmm2, %xmm3
	punpckhwd	%xmm2, %xmm0
	paddd	%xmm3, %xmm1
	paddd	%xmm0, %xmm1
	cmpq	%rcx, %rax
	jne	.L4
	movdqa	%xmm1, %xmm0
	movl	%edx, %ecx
	psrldq	$8, %xmm0
	andl	$-16, %ecx
	paddd	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %eax
	testb	$15, %dl
	je	.L5
.L3:
	movslq	%ecx, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L6
	addl	$1, %eax
.L6:
	leal	1(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L7
	addl	$1, %eax
.L7:
	leal	2(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L8
	addl	$1, %eax
.L8:
	leal	3(%rcx), %edi
	cmpl	%edx, %edi
	jge	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L9
	addl	$1, %eax
.L9:
	leal	4(%rcx), %edi
	cmpl	%edx, %edi
	jge	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L10
	addl	$1, %eax
.L10:
	leal	5(%rcx), %edi
	cmpl	%edx, %edi
	jge	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L11
	addl	$1, %eax
.L11:
	leal	6(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L12
	addl	$1, %eax
.L12:
	leal	7(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L13
	addl	$1, %eax
.L13:
	leal	8(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L14
	addl	$1, %eax
.L14:
	leal	9(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L15
	addl	$1, %eax
.L15:
	leal	10(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L16
	addl	$1, %eax
.L16:
	leal	11(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L17
	addl	$1, %eax
.L17:
	leal	12(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L18
	addl	$1, %eax
.L18:
	leal	13(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L19
	addl	$1, %eax
.L19:
	addl	$14, %ecx
	cmpl	%ecx, %edx
	jle	.L5
	movslq	%ecx, %rcx
	cmpb	$87, 16(%rsp,%rcx)
	je	.L5
	addl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L5:
	leaq	17(%rsp,%rsi), %rdi
	movq	%rbx, %rdx
	xorl	%esi, %esi
	movl	$99999999, %r8d
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L22:
	subl	$1, %eax
	leal	(%rax,%rsi), %ecx
	cmpl	%ecx, %r8d
	cmovg	%ecx, %r8d
	addq	$1, %rdx
	cmpq	%rdx, %rdi
	je	.L2
.L24:
	cmpb	$87, (%rdx)
	jne	.L22
	leal	(%rax,%rsi), %ecx
	addl	$1, %esi
	cmpl	%ecx, %r8d
	cmovg	%ecx, %r8d
	addq	$1, %rdx
	cmpq	%rdx, %rdi
	jne	.L24
.L2:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC4(%rip), %rsi
	call	__printf_chk@PLT
	movq	500024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L32
	addq	$500032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
.L26:
	.cfi_restore_state
	movl	$99999999, %r8d
	jmp	.L2
.L27:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	jmp	.L3
.L32:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.align 16
.LC3:
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.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"
.LC4:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	-499712(%rsp), %r11
	.cfi_def_cfa 11, 499728
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$320, %rsp
	.cfi_def_cfa_offset 500048
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 500024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	16(%rsp), %rbx
	call	__isoc99_scanf@PLT
	movq	%rbx, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edx
	testl	%edx, %edx
	jle	.L26
	leal	-1(%rdx), %esi
	cmpl	$14, %esi
	jbe	.L27
	movl	%edx, %ecx
	pxor	%xmm1, %xmm1
	pxor	%xmm5, %xmm5
	movq	%rbx, %rax
	shrl	$4, %ecx
	movdqa	.LC2(%rip), %xmm7
	movdqa	.LC3(%rip), %xmm6
	pxor	%xmm4, %xmm4
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	32(%rsp,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L4:
	movdqa	%xmm7, %xmm0
	movdqa	%xmm5, %xmm3
	addq	$16, %rax
	pcmpeqb	-16(%rax), %xmm0
	pandn	%xmm6, %xmm0
	pcmpgtb	%xmm0, %xmm3
	movdqa	%xmm0, %xmm2
	punpcklbw	%xmm3, %xmm2
	punpckhbw	%xmm3, %xmm0
	movdqa	%xmm4, %xmm3
	pcmpgtw	%xmm2, %xmm3
	movdqa	%xmm2, %xmm8
	punpcklwd	%xmm3, %xmm8
	punpckhwd	%xmm3, %xmm2
	movdqa	%xmm0, %xmm3
	paddd	%xmm8, %xmm1
	paddd	%xmm2, %xmm1
	movdqa	%xmm4, %xmm2
	pcmpgtw	%xmm0, %xmm2
	punpcklwd	%xmm2, %xmm3
	punpckhwd	%xmm2, %xmm0
	paddd	%xmm3, %xmm1
	paddd	%xmm0, %xmm1
	cmpq	%rcx, %rax
	jne	.L4
	movdqa	%xmm1, %xmm0
	movl	%edx, %ecx
	psrldq	$8, %xmm0
	andl	$-16, %ecx
	paddd	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %eax
	testb	$15, %dl
	je	.L5
.L3:
	movslq	%ecx, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L6
	addl	$1, %eax
.L6:
	leal	1(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L7
	addl	$1, %eax
.L7:
	leal	2(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L8
	addl	$1, %eax
.L8:
	leal	3(%rcx), %edi
	cmpl	%edx, %edi
	jge	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L9
	addl	$1, %eax
.L9:
	leal	4(%rcx), %edi
	cmpl	%edx, %edi
	jge	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L10
	addl	$1, %eax
.L10:
	leal	5(%rcx), %edi
	cmpl	%edx, %edi
	jge	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L11
	addl	$1, %eax
.L11:
	leal	6(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L12
	addl	$1, %eax
.L12:
	leal	7(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L13
	addl	$1, %eax
.L13:
	leal	8(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L14
	addl	$1, %eax
.L14:
	leal	9(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L15
	addl	$1, %eax
.L15:
	leal	10(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L16
	addl	$1, %eax
.L16:
	leal	11(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L17
	addl	$1, %eax
.L17:
	leal	12(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L18
	addl	$1, %eax
.L18:
	leal	13(%rcx), %edi
	cmpl	%edi, %edx
	jle	.L5
	movslq	%edi, %rdi
	cmpb	$87, 16(%rsp,%rdi)
	je	.L19
	addl	$1, %eax
.L19:
	addl	$14, %ecx
	cmpl	%ecx, %edx
	jle	.L5
	movslq	%ecx, %rcx
	cmpb	$87, 16(%rsp,%rcx)
	je	.L5
	addl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L5:
	leaq	17(%rsp,%rsi), %rdi
	movq	%rbx, %rdx
	xorl	%esi, %esi
	movl	$99999999, %r8d
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L22:
	subl	$1, %eax
	leal	(%rax,%rsi), %ecx
	cmpl	%ecx, %r8d
	cmovg	%ecx, %r8d
	addq	$1, %rdx
	cmpq	%rdx, %rdi
	je	.L2
.L24:
	cmpb	$87, (%rdx)
	jne	.L22
	leal	(%rax,%rsi), %ecx
	addl	$1, %esi
	cmpl	%ecx, %r8d
	cmovg	%ecx, %r8d
	addq	$1, %rdx
	cmpq	%rdx, %rdi
	jne	.L24
.L2:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC4(%rip), %rsi
	call	__printf_chk@PLT
	movq	500024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L32
	addq	$500032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
.L26:
	.cfi_restore_state
	movl	$99999999, %r8d
	jmp	.L2
.L27:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	jmp	.L3
.L32:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.byte	87
	.align 16
.LC3:
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.byte	1
	.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>
typedef struct left_{
    int w;
    int e;
}left_t;
typedef struct right_{
    int w;
    int e;
}right_t;

int main(){
    int n;
    char str[500000];
    left_t left;
    right_t right;
    left.w=left.e=0;
    right.w=right.e=0;

    scanf("%d",&n);
    scanf("%s",str);
    for(int i=0;i<n;i++){
        if(str[i]=='W'){
            right.w++;
        }else{
            right.e++;
        }
    }
    int cnt=0;
    int min=99999999;
    for(int i=0;i<n;i++){
        cnt=0;
        //printf("right e:%d w:%d\n",right.e,right.w);
        //printf("left  e:%d w:%d\n",left.e,left.w);
        if(str[i]=='W'){
            right.w--;
            cnt+=right.e;
            cnt+=left.w;
            left.w++;
        }else{
            right.e--;
            cnt+=right.e;
            cnt+=left.w;
            left.e++;
        }
        if(min>cnt){
            min=cnt;
        }
        //printf("%d\n",min);
    }
    printf("%d\n",min);
    return 0;

}
12
EWWWEEEWEWEW
 5
WWEEW
 12
WWWWEEEWEWEE
 8
WEWWWEWE
 8
EEEWWWWW
 5
EWEWW
 12
EWWEWEEEWWWE
 5
WWEWE
 12
WEWWEEWWEWEE
 5
WEWEW

5
 2
 6
 3
 0
 1
 4
 2
 6
 2

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>
typedef struct left_{
    int w;
    int e;
}left_t;
typedef struct right_{
    int w;
    int e;
}right_t;

int main(){
    int n;
    char str[500000];
    left_t left;
    right_t right;
    left.w=left.e=0;
    right.w=right.e=0;

    scanf("%d",&n);
    scanf("%s",str);
    for(int i=0;i<n;i++){
        if(str[i]=='W'){
            right.w++;
        }else{
            right.e++;
        }
    }
    int cnt=0;
    int min=99999999;
    for(int i=0;i<n;i++){
        cnt=0;
        //printf("right e:%d w:%d\n",right.e,right.w);
        //printf("left  e:%d w:%d\n",left.e,left.w);
        if(str[i]=='W'){
            right.w--;
            cnt+=right.e;
            cnt+=left.w;
            left.w++;
        }else{
            right.e--;
            cnt+=right.e;
            cnt+=left.w;
            left.e++;
        }
        if(min>cnt){
            min=cnt;
        }
        //printf("%d\n",min);
    }
    printf("%d\n",min);
    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
	leaq	-499712(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$352, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -500028(%rbp)
	movl	-500028(%rbp), %eax
	movl	%eax, -500032(%rbp)
	movl	$0, -500020(%rbp)
	movl	-500020(%rbp), %eax
	movl	%eax, -500024(%rbp)
	leaq	-500052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-500016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -500048(%rbp)
	jmp	.L2
.L5:
	movl	-500048(%rbp), %eax
	cltq
	movzbl	-500016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L3
	movl	-500024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500024(%rbp)
	jmp	.L4
.L3:
	movl	-500020(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500020(%rbp)
.L4:
	addl	$1, -500048(%rbp)
.L2:
	movl	-500052(%rbp), %eax
	cmpl	%eax, -500048(%rbp)
	jl	.L5
	movl	$0, -500044(%rbp)
	movl	$99999999, -500040(%rbp)
	movl	$0, -500036(%rbp)
	jmp	.L6
.L10:
	movl	$0, -500044(%rbp)
	movl	-500036(%rbp), %eax
	cltq
	movzbl	-500016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L7
	movl	-500024(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -500024(%rbp)
	movl	-500020(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500032(%rbp)
	jmp	.L8
.L7:
	movl	-500020(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -500020(%rbp)
	movl	-500020(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500028(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500028(%rbp)
.L8:
	movl	-500040(%rbp), %eax
	cmpl	-500044(%rbp), %eax
	jle	.L9
	movl	-500044(%rbp), %eax
	movl	%eax, -500040(%rbp)
.L9:
	addl	$1, -500036(%rbp)
.L6:
	movl	-500052(%rbp), %eax
	cmpl	%eax, -500036(%rbp)
	jl	.L10
	movl	-500040(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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
	leaq	-499712(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$352, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -500028(%rbp)
	movl	-500028(%rbp), %eax
	movl	%eax, -500032(%rbp)
	movl	$0, -500020(%rbp)
	movl	-500020(%rbp), %eax
	movl	%eax, -500024(%rbp)
	leaq	-500052(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-500016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -500048(%rbp)
	jmp	.L2
.L5:
	movl	-500048(%rbp), %eax
	cltq
	movzbl	-500016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L3
	movl	-500024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500024(%rbp)
	jmp	.L4
.L3:
	movl	-500020(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500020(%rbp)
.L4:
	addl	$1, -500048(%rbp)
.L2:
	movl	-500052(%rbp), %eax
	cmpl	%eax, -500048(%rbp)
	jl	.L5
	movl	$0, -500044(%rbp)
	movl	$99999999, -500040(%rbp)
	movl	$0, -500036(%rbp)
	jmp	.L6
.L10:
	movl	$0, -500044(%rbp)
	movl	-500036(%rbp), %eax
	cltq
	movzbl	-500016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L7
	movl	-500024(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -500024(%rbp)
	movl	-500020(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500032(%rbp)
	jmp	.L8
.L7:
	movl	-500020(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -500020(%rbp)
	movl	-500020(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500032(%rbp), %eax
	addl	%eax, -500044(%rbp)
	movl	-500028(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -500028(%rbp)
.L8:
	movl	-500040(%rbp), %eax
	cmpl	-500044(%rbp), %eax
	jle	.L9
	movl	-500044(%rbp), %eax
	movl	%eax, -500040(%rbp)
.L9:
	addl	$1, -500036(%rbp)
.L6:
	movl	-500052(%rbp), %eax
	cmpl	%eax, -500036(%rbp)
	jl	.L10
	movl	-500040(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	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:
