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(void) {
  int i, N, OK = 0, max = 0;
  char S[300001] = {0};
  scanf("%d%s", &N, S);
  for (i=1; i < N ;i++) {
    if (S[i] == 'W') OK++;
  }
  if (OK+1 > max) max = OK+1;
  if (S[0] == 'E') OK++;

  for (i=1; i < N-1 ;i++) {
    if (S[i] == 'E') OK++;
    else OK--;
    if (S[i+1] == 'E') OK++;
    if (OK > max) max = OK;
    if (S[i+1] == 'E') OK--;
  }
  printf("%d\n", N - max);
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d%s"
.LC1:
	.string	"%d\n"
	.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
	leaq	-299008(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1024, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -300024(%rbp)
	movl	$0, -300020(%rbp)
	movq	$0, -300016(%rbp)
	movq	$0, -300008(%rbp)
	leaq	-300000(%rbp), %rax
	movl	$299985, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-300016(%rbp), %rdx
	leaq	-300032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -300028(%rbp)
	jmp	.L2
.L4:
	movl	-300028(%rbp), %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L3
	addl	$1, -300024(%rbp)
.L3:
	addl	$1, -300028(%rbp)
.L2:
	movl	-300032(%rbp), %eax
	cmpl	%eax, -300028(%rbp)
	jl	.L4
	movl	-300024(%rbp), %eax
	cmpl	-300020(%rbp), %eax
	jl	.L5
	movl	-300024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -300020(%rbp)
.L5:
	movzbl	-300016(%rbp), %eax
	cmpb	$69, %al
	jne	.L6
	addl	$1, -300024(%rbp)
.L6:
	movl	$1, -300028(%rbp)
	jmp	.L7
.L13:
	movl	-300028(%rbp), %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L8
	addl	$1, -300024(%rbp)
	jmp	.L9
.L8:
	subl	$1, -300024(%rbp)
.L9:
	movl	-300028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L10
	addl	$1, -300024(%rbp)
.L10:
	movl	-300024(%rbp), %eax
	cmpl	-300020(%rbp), %eax
	jle	.L11
	movl	-300024(%rbp), %eax
	movl	%eax, -300020(%rbp)
.L11:
	movl	-300028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L12
	subl	$1, -300024(%rbp)
.L12:
	addl	$1, -300028(%rbp)
.L7:
	movl	-300032(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -300028(%rbp)
	jl	.L13
	movl	-300032(%rbp), %eax
	subl	-300020(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	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	"%d%s"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	leaq	-299008(%rsp), %r11
	.cfi_def_cfa 11, 299016
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1032, %rsp
	.cfi_def_cfa_offset 300048
	pxor	%xmm0, %xmm0
	movl	$299985, %edx
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 300024(%rsp)
	xorl	%eax, %eax
	leaq	32(%rsp), %rdi
	movaps	%xmm0, 16(%rsp)
	call	memset@PLT
	leaq	16(%rsp), %rdx
	leaq	12(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edx
	cmpl	$1, %edx
	jle	.L31
	leal	-2(%rdx), %eax
	leal	-1(%rdx), %esi
	cmpl	$14, %eax
	jbe	.L32
	leaq	17(%rsp), %rax
	pxor	%xmm1, %xmm1
	pxor	%xmm5, %xmm5
	movl	%esi, %ecx
	shrl	$4, %ecx
	movdqa	.LC1(%rip), %xmm7
	movdqa	.LC2(%rip), %xmm6
	pxor	%xmm4, %xmm4
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	33(%rsp,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L4:
	movdqu	(%rax), %xmm0
	movdqa	%xmm5, %xmm3
	addq	$16, %rax
	pcmpeqb	%xmm7, %xmm0
	pand	%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	%esi, %edi
	psrldq	$8, %xmm0
	andl	$-16, %edi
	paddd	%xmm0, %xmm1
	leal	1(%rdi), %ecx
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %eax
	cmpl	%edi, %esi
	je	.L2
.L3:
	movslq	%ecx, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L7
	addl	$1, %eax
.L7:
	leal	1(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L37
.L8:
	leal	2(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L38
.L9:
	leal	3(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L39
.L10:
	leal	4(%rcx), %esi
	cmpl	%edx, %esi
	jge	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L40
.L11:
	leal	5(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L12
	addl	$1, %eax
.L12:
	leal	6(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L13
	addl	$1, %eax
.L13:
	leal	7(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L14
	addl	$1, %eax
.L14:
	leal	8(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L15
	addl	$1, %eax
.L15:
	leal	9(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L41
.L16:
	leal	10(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L42
.L17:
	leal	11(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L43
.L18:
	leal	12(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L44
.L19:
	leal	13(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L20
	addl	$1, %eax
.L20:
	addl	$14, %ecx
	cmpl	%ecx, %edx
	jle	.L2
	movslq	%ecx, %rcx
	cmpb	$87, 16(%rsp,%rcx)
	jne	.L2
	addl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L2:
	leal	1(%rax), %ecx
	cmpb	$69, 16(%rsp)
	cmove	%ecx, %eax
	cmpl	$2, %edx
	jle	.L24
	leal	-3(%rdx), %esi
	movzbl	17(%rsp), %r8d
	leaq	18(%rsp), %rdi
	leaq	19(%rsp,%rsi), %r9
	.p2align 4,,10
	.p2align 3
.L29:
	leal	1(%rax), %esi
	subl	$1, %eax
	cmpb	$69, %r8b
	movzbl	(%rdi), %r8d
	cmove	%esi, %eax
	leal	1(%rax), %esi
	cmpl	%esi, %ecx
	cmovge	%ecx, %esi
	cmpl	%eax, %ecx
	cmovl	%eax, %ecx
	cmpb	$69, %r8b
	cmove	%esi, %ecx
	addq	$1, %rdi
	cmpq	%rdi, %r9
	jne	.L29
.L24:
	subl	%ecx, %edx
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	300024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	xorl	%eax, %eax
	addq	$300040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L37:
	.cfi_restore_state
	addl	$1, %eax
	jmp	.L8
.L38:
	addl	$1, %eax
	jmp	.L9
.L39:
	addl	$1, %eax
	jmp	.L10
.L40:
	addl	$1, %eax
	jmp	.L11
.L41:
	addl	$1, %eax
	jmp	.L16
.L42:
	addl	$1, %eax
	jmp	.L17
.L43:
	addl	$1, %eax
	jmp	.L18
.L44:
	addl	$1, %eax
	jmp	.L19
.L31:
	xorl	%eax, %eax
	jmp	.L2
.L32:
	xorl	%eax, %eax
	movl	$1, %ecx
	jmp	.L3
.L45:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.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
.LC2:
	.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%s"
.LC3:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	leaq	-299008(%rsp), %r11
	.cfi_def_cfa 11, 299016
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1032, %rsp
	.cfi_def_cfa_offset 300048
	pxor	%xmm0, %xmm0
	movl	$299985, %edx
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 300024(%rsp)
	xorl	%eax, %eax
	leaq	32(%rsp), %rdi
	movaps	%xmm0, 16(%rsp)
	call	memset@PLT
	leaq	16(%rsp), %rdx
	leaq	12(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edx
	cmpl	$1, %edx
	jle	.L31
	leal	-2(%rdx), %eax
	leal	-1(%rdx), %esi
	cmpl	$14, %eax
	jbe	.L32
	leaq	17(%rsp), %rax
	pxor	%xmm1, %xmm1
	pxor	%xmm5, %xmm5
	movl	%esi, %ecx
	shrl	$4, %ecx
	movdqa	.LC1(%rip), %xmm7
	movdqa	.LC2(%rip), %xmm6
	pxor	%xmm4, %xmm4
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	33(%rsp,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L4:
	movdqu	(%rax), %xmm0
	movdqa	%xmm5, %xmm3
	addq	$16, %rax
	pcmpeqb	%xmm7, %xmm0
	pand	%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	%esi, %edi
	psrldq	$8, %xmm0
	andl	$-16, %edi
	paddd	%xmm0, %xmm1
	leal	1(%rdi), %ecx
	movdqa	%xmm1, %xmm0
	psrldq	$4, %xmm0
	paddd	%xmm0, %xmm1
	movd	%xmm1, %eax
	cmpl	%edi, %esi
	je	.L2
.L3:
	movslq	%ecx, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L7
	addl	$1, %eax
.L7:
	leal	1(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L37
.L8:
	leal	2(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L38
.L9:
	leal	3(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L39
.L10:
	leal	4(%rcx), %esi
	cmpl	%edx, %esi
	jge	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L40
.L11:
	leal	5(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L12
	addl	$1, %eax
.L12:
	leal	6(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L13
	addl	$1, %eax
.L13:
	leal	7(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L14
	addl	$1, %eax
.L14:
	leal	8(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L15
	addl	$1, %eax
.L15:
	leal	9(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L41
.L16:
	leal	10(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L42
.L17:
	leal	11(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L43
.L18:
	leal	12(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	je	.L44
.L19:
	leal	13(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L2
	movslq	%esi, %rsi
	cmpb	$87, 16(%rsp,%rsi)
	jne	.L20
	addl	$1, %eax
.L20:
	addl	$14, %ecx
	cmpl	%ecx, %edx
	jle	.L2
	movslq	%ecx, %rcx
	cmpb	$87, 16(%rsp,%rcx)
	jne	.L2
	addl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L2:
	leal	1(%rax), %ecx
	cmpb	$69, 16(%rsp)
	cmove	%ecx, %eax
	cmpl	$2, %edx
	jle	.L24
	leal	-3(%rdx), %esi
	movzbl	17(%rsp), %r8d
	leaq	18(%rsp), %rdi
	leaq	19(%rsp,%rsi), %r9
	.p2align 4,,10
	.p2align 3
.L29:
	leal	1(%rax), %esi
	subl	$1, %eax
	cmpb	$69, %r8b
	movzbl	(%rdi), %r8d
	cmove	%esi, %eax
	leal	1(%rax), %esi
	cmpl	%esi, %ecx
	cmovge	%ecx, %esi
	cmpl	%eax, %ecx
	cmovl	%eax, %ecx
	cmpb	$69, %r8b
	cmove	%esi, %ecx
	addq	$1, %rdi
	cmpq	%rdi, %r9
	jne	.L29
.L24:
	subl	%ecx, %edx
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	300024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	xorl	%eax, %eax
	addq	$300040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
.L37:
	.cfi_restore_state
	addl	$1, %eax
	jmp	.L8
.L38:
	addl	$1, %eax
	jmp	.L9
.L39:
	addl	$1, %eax
	jmp	.L10
.L40:
	addl	$1, %eax
	jmp	.L11
.L41:
	addl	$1, %eax
	jmp	.L16
.L42:
	addl	$1, %eax
	jmp	.L17
.L43:
	addl	$1, %eax
	jmp	.L18
.L44:
	addl	$1, %eax
	jmp	.L19
.L31:
	xorl	%eax, %eax
	jmp	.L2
.L32:
	xorl	%eax, %eax
	movl	$1, %ecx
	jmp	.L3
.L45:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.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
.LC2:
	.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>
#include <stdlib.h>

int main(void) {
  int i, N, OK = 0, max = 0;
  char S[300001] = {0};
  scanf("%d%s", &N, S);
  for (i=1; i < N ;i++) {
    if (S[i] == 'W') OK++;
  }
  if (OK+1 > max) max = OK+1;
  if (S[0] == 'E') OK++;

  for (i=1; i < N-1 ;i++) {
    if (S[i] == 'E') OK++;
    else OK--;
    if (S[i+1] == 'E') OK++;
    if (OK > max) max = OK;
    if (S[i+1] == 'E') OK--;
  }
  printf("%d\n", N - max);
  return 0;
}

5
WEEWW

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(void) {
  int i, N, OK = 0, max = 0;
  char S[300001] = {0};
  scanf("%d%s", &N, S);
  for (i=1; i < N ;i++) {
    if (S[i] == 'W') OK++;
  }
  if (OK+1 > max) max = OK+1;
  if (S[0] == 'E') OK++;

  for (i=1; i < N-1 ;i++) {
    if (S[i] == 'E') OK++;
    else OK--;
    if (S[i+1] == 'E') OK++;
    if (OK > max) max = OK;
    if (S[i+1] == 'E') OK--;
  }
  printf("%d\n", N - max);
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d%s"
.LC1:
	.string	"%d\n"
	.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
	leaq	-299008(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1024, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -300024(%rbp)
	movl	$0, -300020(%rbp)
	movq	$0, -300016(%rbp)
	movq	$0, -300008(%rbp)
	leaq	-300000(%rbp), %rax
	movl	$299985, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-300016(%rbp), %rdx
	leaq	-300032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -300028(%rbp)
	jmp	.L2
.L4:
	movl	-300028(%rbp), %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L3
	addl	$1, -300024(%rbp)
.L3:
	addl	$1, -300028(%rbp)
.L2:
	movl	-300032(%rbp), %eax
	cmpl	%eax, -300028(%rbp)
	jl	.L4
	movl	-300024(%rbp), %eax
	cmpl	-300020(%rbp), %eax
	jl	.L5
	movl	-300024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -300020(%rbp)
.L5:
	movzbl	-300016(%rbp), %eax
	cmpb	$69, %al
	jne	.L6
	addl	$1, -300024(%rbp)
.L6:
	movl	$1, -300028(%rbp)
	jmp	.L7
.L13:
	movl	-300028(%rbp), %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L8
	addl	$1, -300024(%rbp)
	jmp	.L9
.L8:
	subl	$1, -300024(%rbp)
.L9:
	movl	-300028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L10
	addl	$1, -300024(%rbp)
.L10:
	movl	-300024(%rbp), %eax
	cmpl	-300020(%rbp), %eax
	jle	.L11
	movl	-300024(%rbp), %eax
	movl	%eax, -300020(%rbp)
.L11:
	movl	-300028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L12
	subl	$1, -300024(%rbp)
.L12:
	addl	$1, -300028(%rbp)
.L7:
	movl	-300032(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -300028(%rbp)
	jl	.L13
	movl	-300032(%rbp), %eax
	subl	-300020(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	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	"%d%s"
.LC1:
	.string	"%d\n"
	.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
	leaq	-299008(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1024, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -300024(%rbp)
	movl	$0, -300020(%rbp)
	movq	$0, -300016(%rbp)
	movq	$0, -300008(%rbp)
	leaq	-300000(%rbp), %rax
	movl	$299985, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	leaq	-300016(%rbp), %rdx
	leaq	-300032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$1, -300028(%rbp)
	jmp	.L2
.L4:
	movl	-300028(%rbp), %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$87, %al
	jne	.L3
	addl	$1, -300024(%rbp)
.L3:
	addl	$1, -300028(%rbp)
.L2:
	movl	-300032(%rbp), %eax
	cmpl	%eax, -300028(%rbp)
	jl	.L4
	movl	-300024(%rbp), %eax
	cmpl	-300020(%rbp), %eax
	jl	.L5
	movl	-300024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -300020(%rbp)
.L5:
	movzbl	-300016(%rbp), %eax
	cmpb	$69, %al
	jne	.L6
	addl	$1, -300024(%rbp)
.L6:
	movl	$1, -300028(%rbp)
	jmp	.L7
.L13:
	movl	-300028(%rbp), %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L8
	addl	$1, -300024(%rbp)
	jmp	.L9
.L8:
	subl	$1, -300024(%rbp)
.L9:
	movl	-300028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L10
	addl	$1, -300024(%rbp)
.L10:
	movl	-300024(%rbp), %eax
	cmpl	-300020(%rbp), %eax
	jle	.L11
	movl	-300024(%rbp), %eax
	movl	%eax, -300020(%rbp)
.L11:
	movl	-300028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-300016(%rbp,%rax), %eax
	cmpb	$69, %al
	jne	.L12
	subl	$1, -300024(%rbp)
.L12:
	addl	$1, -300028(%rbp)
.L7:
	movl	-300032(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -300028(%rbp)
	jl	.L13
	movl	-300032(%rbp), %eax
	subl	-300020(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	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:
