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 n, i;
int a, b;
char s[200001], c;
int main(void){
  while((c=getchar())!=10){s[n++]=c;}
  scanf("%s",&s);
  for(i=0; i<n; i++){
    if(b>0){
      if(s[i]=='S'){
        b++;
      }else{
        b--;
      }
    }else{
      if(s[i]=='T'){
        a++;
      }else{
        b++;
      }
    }
  }
  printf("%d\n", a*2);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	s
	.align 32
	.type	s, @object
	.size	s, 200001
s:
	.zero	200001
	.globl	c
	.type	c, @object
	.size	c, 1
c:
	.zero	1
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.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
	jmp	.L2
.L3:
	movl	n(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, n(%rip)
	movzbl	c(%rip), %edx
	cltq
	leaq	s(%rip), %rcx
	movb	%dl, (%rax,%rcx)
.L2:
	call	getchar@PLT
	movb	%al, c(%rip)
	movzbl	c(%rip), %eax
	cmpb	$10, %al
	jne	.L3
	leaq	s(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, i(%rip)
	jmp	.L4
.L9:
	movl	b(%rip), %eax
	testl	%eax, %eax
	jle	.L5
	movl	i(%rip), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$83, %al
	jne	.L6
	movl	b(%rip), %eax
	addl	$1, %eax
	movl	%eax, b(%rip)
	jmp	.L7
.L6:
	movl	b(%rip), %eax
	subl	$1, %eax
	movl	%eax, b(%rip)
	jmp	.L7
.L5:
	movl	i(%rip), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$84, %al
	jne	.L8
	movl	a(%rip), %eax
	addl	$1, %eax
	movl	%eax, a(%rip)
	jmp	.L7
.L8:
	movl	b(%rip), %eax
	addl	$1, %eax
	movl	%eax, b(%rip)
.L7:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L4:
	movl	i(%rip), %edx
	movl	n(%rip), %eax
	cmpl	%eax, %edx
	jl	.L9
	movl	a(%rip), %eax
	addl	%eax, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	popq	%rbp
	.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	"%s"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	s(%rip), %rbp
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	movslq	n(%rip), %rdx
	leal	1(%rdx), %ecx
	movb	%al, 0(%rbp,%rdx)
	movl	%ecx, n(%rip)
.L2:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	movb	%al, c(%rip)
	cmpb	$10, %al
	jne	.L3
	movq	%rbp, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %r10d
	movl	$0, i(%rip)
	movl	a(%rip), %edx
	testl	%r10d, %r10d
	jle	.L5
	leaq	s(%rip), %rax
	movl	%edx, %r9d
	xorl	%r11d, %r11d
	xorl	%r8d, %r8d
	leal	-1(%r10), %esi
	leaq	1(%rax), %rdi
	movl	b(%rip), %ecx
	addq	%rsi, %rdi
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L23:
	cmpb	$83, %sil
	je	.L9
	subl	$1, %ecx
	movl	$1, %r8d
.L8:
	addq	$1, %rax
	cmpq	%rax, %rdi
	je	.L22
.L10:
	movzbl	(%rax), %esi
	testl	%ecx, %ecx
	jg	.L23
	cmpb	$84, %sil
	je	.L24
.L9:
	addq	$1, %rax
	addl	$1, %ecx
	movl	$1, %r8d
	cmpq	%rax, %rdi
	jne	.L10
.L22:
	movl	%r10d, i(%rip)
	testb	%r11b, %r11b
	je	.L11
	movl	%r9d, a(%rip)
	movl	%r9d, %edx
.L11:
	testb	%r8b, %r8b
	je	.L5
	movl	%ecx, b(%rip)
.L5:
	addl	%edx, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L24:
	.cfi_restore_state
	addl	$1, %r9d
	movl	$1, %r11d
	jmp	.L8
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	c
	.bss
	.type	c, @object
	.size	c, 1
c:
	.zero	1
	.globl	s
	.align 32
	.type	s, @object
	.size	s, 200001
s:
	.zero	200001
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.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	"%s"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	s(%rip), %rbp
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L3:
	movslq	n(%rip), %rdx
	leal	1(%rdx), %ecx
	movb	%al, 0(%rbp,%rdx)
	movl	%ecx, n(%rip)
.L2:
	movq	stdin(%rip), %rdi
	call	getc@PLT
	movb	%al, c(%rip)
	cmpb	$10, %al
	jne	.L3
	movq	%rbp, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	n(%rip), %r10d
	movl	$0, i(%rip)
	movl	a(%rip), %edx
	testl	%r10d, %r10d
	jle	.L5
	leaq	s(%rip), %rax
	movl	%edx, %r9d
	xorl	%r11d, %r11d
	xorl	%r8d, %r8d
	leal	-1(%r10), %esi
	leaq	1(%rax), %rdi
	movl	b(%rip), %ecx
	addq	%rsi, %rdi
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L23:
	cmpb	$83, %sil
	je	.L9
	subl	$1, %ecx
	movl	$1, %r8d
.L8:
	addq	$1, %rax
	cmpq	%rax, %rdi
	je	.L22
.L10:
	movzbl	(%rax), %esi
	testl	%ecx, %ecx
	jg	.L23
	cmpb	$84, %sil
	je	.L24
.L9:
	addq	$1, %rax
	addl	$1, %ecx
	movl	$1, %r8d
	cmpq	%rax, %rdi
	jne	.L10
.L22:
	movl	%r10d, i(%rip)
	testb	%r11b, %r11b
	je	.L11
	movl	%r9d, a(%rip)
	movl	%r9d, %edx
.L11:
	testb	%r8b, %r8b
	je	.L5
	movl	%ecx, b(%rip)
.L5:
	addl	%edx, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L24:
	.cfi_restore_state
	addl	$1, %r9d
	movl	$1, %r11d
	jmp	.L8
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	c
	.bss
	.type	c, @object
	.size	c, 1
c:
	.zero	1
	.globl	s
	.align 32
	.type	s, @object
	.size	s, 200001
s:
	.zero	200001
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.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 n, i;
int a, b;
char s[200001], c;
int main(void){
  while((c=getchar())!=10){s[n++]=c;}
  scanf("%s",&s);
  for(i=0; i<n; i++){
    if(b>0){
      if(s[i]=='S'){
        b++;
      }else{
        b--;
      }
    }else{
      if(s[i]=='T'){
        a++;
      }else{
        b++;
      }
    }
  }
  printf("%d\n", a*2);
}

SSTTTSST
 STTTSS
 SSSTTT
 TTTSSS
 TTTTSSSS
 TSTSST
 SSTTTS
 TSSTST
 STTSST
 TSSSTT

2
 4
 0
 6
 8
 2
 2
 2
 2
 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>
int n, i;
int a, b;
char s[200001], c;
int main(void){
  while((c=getchar())!=10){s[n++]=c;}
  scanf("%s",&s);
  for(i=0; i<n; i++){
    if(b>0){
      if(s[i]=='S'){
        b++;
      }else{
        b--;
      }
    }else{
      if(s[i]=='T'){
        a++;
      }else{
        b++;
      }
    }
  }
  printf("%d\n", a*2);
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	s
	.align 32
	.type	s, @object
	.size	s, 200001
s:
	.zero	200001
	.globl	c
	.type	c, @object
	.size	c, 1
c:
	.zero	1
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.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
	jmp	.L2
.L3:
	movl	n(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, n(%rip)
	movzbl	c(%rip), %edx
	cltq
	leaq	s(%rip), %rcx
	movb	%dl, (%rax,%rcx)
.L2:
	call	getchar@PLT
	movb	%al, c(%rip)
	movzbl	c(%rip), %eax
	cmpb	$10, %al
	jne	.L3
	leaq	s(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, i(%rip)
	jmp	.L4
.L9:
	movl	b(%rip), %eax
	testl	%eax, %eax
	jle	.L5
	movl	i(%rip), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$83, %al
	jne	.L6
	movl	b(%rip), %eax
	addl	$1, %eax
	movl	%eax, b(%rip)
	jmp	.L7
.L6:
	movl	b(%rip), %eax
	subl	$1, %eax
	movl	%eax, b(%rip)
	jmp	.L7
.L5:
	movl	i(%rip), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$84, %al
	jne	.L8
	movl	a(%rip), %eax
	addl	$1, %eax
	movl	%eax, a(%rip)
	jmp	.L7
.L8:
	movl	b(%rip), %eax
	addl	$1, %eax
	movl	%eax, b(%rip)
.L7:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L4:
	movl	i(%rip), %edx
	movl	n(%rip), %eax
	cmpl	%eax, %edx
	jl	.L9
	movl	a(%rip), %eax
	addl	%eax, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	popq	%rbp
	.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
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	b
	.align 4
	.type	b, @object
	.size	b, 4
b:
	.zero	4
	.globl	s
	.align 32
	.type	s, @object
	.size	s, 200001
s:
	.zero	200001
	.globl	c
	.type	c, @object
	.size	c, 1
c:
	.zero	1
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.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
	jmp	.L2
.L3:
	movl	n(%rip), %eax
	leal	1(%rax), %edx
	movl	%edx, n(%rip)
	movzbl	c(%rip), %edx
	cltq
	leaq	s(%rip), %rcx
	movb	%dl, (%rax,%rcx)
.L2:
	call	getchar@PLT
	movb	%al, c(%rip)
	movzbl	c(%rip), %eax
	cmpb	$10, %al
	jne	.L3
	leaq	s(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, i(%rip)
	jmp	.L4
.L9:
	movl	b(%rip), %eax
	testl	%eax, %eax
	jle	.L5
	movl	i(%rip), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$83, %al
	jne	.L6
	movl	b(%rip), %eax
	addl	$1, %eax
	movl	%eax, b(%rip)
	jmp	.L7
.L6:
	movl	b(%rip), %eax
	subl	$1, %eax
	movl	%eax, b(%rip)
	jmp	.L7
.L5:
	movl	i(%rip), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$84, %al
	jne	.L8
	movl	a(%rip), %eax
	addl	$1, %eax
	movl	%eax, a(%rip)
	jmp	.L7
.L8:
	movl	b(%rip), %eax
	addl	$1, %eax
	movl	%eax, b(%rip)
.L7:
	movl	i(%rip), %eax
	addl	$1, %eax
	movl	%eax, i(%rip)
.L4:
	movl	i(%rip), %edx
	movl	n(%rip), %eax
	cmpl	%eax, %edx
	jl	.L9
	movl	a(%rip), %eax
	addl	%eax, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	popq	%rbp
	.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:
