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(void)
{
    int n;
    int now, min, max;
    int i, j;
    char input[2000];
    char train[1000];

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf("%s", input);

        now = 500;
        min = 500;
        max = 500;
        
        for (j = 0; ; j += 3){
            train[now] = input[j];
            
            if (input[j + 1] == '\0'){
                break;
            }
            
            if (input[j + 1] == '-'){
                now++;
            }
            else {
                now--;
            }

            if (now < min){
                min = now;
            }
            if (now > max){
                max = now;
            }
        }

        for (j = min; j <= max; j++){
            printf("%c", train[j]);
        }
        
        printf("\n");

    }

    return 0;
}
        ```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
	.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	$3056, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-3048(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -3032(%rbp)
	jmp	.L2
.L12:
	leaq	-2016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$500, -3044(%rbp)
	movl	$500, -3040(%rbp)
	movl	$500, -3036(%rbp)
	movl	$0, -3028(%rbp)
.L9:
	movl	-3028(%rbp), %eax
	cltq
	movzbl	-2016(%rbp,%rax), %edx
	movl	-3044(%rbp), %eax
	cltq
	movb	%dl, -3024(%rbp,%rax)
	movl	-3028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-2016(%rbp,%rax), %eax
	testb	%al, %al
	je	.L16
	movl	-3028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-2016(%rbp,%rax), %eax
	cmpb	$45, %al
	jne	.L5
	addl	$1, -3044(%rbp)
	jmp	.L6
.L5:
	subl	$1, -3044(%rbp)
.L6:
	movl	-3044(%rbp), %eax
	cmpl	-3040(%rbp), %eax
	jge	.L7
	movl	-3044(%rbp), %eax
	movl	%eax, -3040(%rbp)
.L7:
	movl	-3044(%rbp), %eax
	cmpl	-3036(%rbp), %eax
	jle	.L8
	movl	-3044(%rbp), %eax
	movl	%eax, -3036(%rbp)
.L8:
	addl	$3, -3028(%rbp)
	jmp	.L9
.L16:
	nop
	movl	-3040(%rbp), %eax
	movl	%eax, -3028(%rbp)
	jmp	.L10
.L11:
	movl	-3028(%rbp), %eax
	cltq
	movzbl	-3024(%rbp,%rax), %eax
	movsbl	%al, %eax
	movl	%eax, %edi
	call	putchar@PLT
	addl	$1, -3028(%rbp)
.L10:
	movl	-3028(%rbp), %eax
	cmpl	-3036(%rbp), %eax
	jle	.L11
	movl	$10, %edi
	call	putchar@PLT
	addl	$1, -3032(%rbp)
.L2:
	movl	-3048(%rbp), %eax
	cmpl	%eax, -3032(%rbp)
	jl	.L12
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	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"
	.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
	leaq	.LC0(%rip), %rdi
	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
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$3048, %rsp
	.cfi_def_cfa_offset 3104
	movq	%fs:40, %rax
	movq	%rax, 3032(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	1024(%rsp), %r13
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L2:
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movzbl	1024(%rsp), %eax
	movzbl	1025(%rsp), %ecx
	movb	%al, 516(%rsp)
	testb	%cl, %cl
	je	.L3
	movl	$500, %r14d
	movl	$500, %ebx
	movl	$500, %eax
	leaq	1027(%rsp), %rdx
	.p2align 4,,10
	.p2align 3
.L6:
	leal	1(%rax), %esi
	subl	$1, %eax
	cmpb	$45, %cl
	cmove	%esi, %eax
	movzbl	(%rdx), %esi
	cmpl	%eax, %ebx
	movslq	%eax, %rcx
	cmovg	%eax, %ebx
	cmpl	%eax, %r14d
	movb	%sil, 16(%rsp,%rcx)
	cmovl	%eax, %r14d
	movzbl	1(%rdx), %ecx
	addq	$3, %rdx
	testb	%cl, %cl
	jne	.L6
	movslq	%ebx, %rbx
	leaq	16(%rsp), %r15
	.p2align 4,,10
	.p2align 3
.L7:
	movsbl	(%r15,%rbx), %edi
	addq	$1, %rbx
	call	putchar@PLT
	cmpl	%ebx, %r14d
	jge	.L7
.L9:
	movl	$10, %edi
	addl	$1, %ebp
	call	putchar@PLT
	cmpl	%ebp, 12(%rsp)
	jg	.L2
.L8:
	movq	3032(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$3048, %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
	.p2align 4,,10
	.p2align 3
.L3:
	.cfi_restore_state
	movsbl	%al, %edi
	call	putchar@PLT
	jmp	.L9
.L20:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE35:
	.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"
	.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
	leaq	.LC0(%rip), %rdi
	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
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$3048, %rsp
	.cfi_def_cfa_offset 3104
	movq	%fs:40, %rax
	movq	%rax, 3032(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	1024(%rsp), %r13
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L2:
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movzbl	1024(%rsp), %eax
	movzbl	1025(%rsp), %ecx
	movb	%al, 516(%rsp)
	testb	%cl, %cl
	je	.L3
	movl	$500, %r14d
	movl	$500, %ebx
	movl	$500, %eax
	leaq	1027(%rsp), %rdx
	.p2align 4,,10
	.p2align 3
.L6:
	leal	1(%rax), %esi
	subl	$1, %eax
	cmpb	$45, %cl
	cmove	%esi, %eax
	movzbl	(%rdx), %esi
	cmpl	%eax, %ebx
	movslq	%eax, %rcx
	cmovg	%eax, %ebx
	cmpl	%eax, %r14d
	movb	%sil, 16(%rsp,%rcx)
	cmovl	%eax, %r14d
	movzbl	1(%rdx), %ecx
	addq	$3, %rdx
	testb	%cl, %cl
	jne	.L6
	movslq	%ebx, %rbx
	leaq	16(%rsp), %r15
	.p2align 4,,10
	.p2align 3
.L7:
	movsbl	(%r15,%rbx), %edi
	addq	$1, %rbx
	call	putchar@PLT
	cmpl	%ebx, %r14d
	jge	.L7
.L9:
	movl	$10, %edi
	addl	$1, %ebp
	call	putchar@PLT
	cmpl	%ebp, 12(%rsp)
	jg	.L2
.L8:
	movq	3032(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L20
	addq	$3048, %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
	.p2align 4,,10
	.p2align 3
.L3:
	.cfi_restore_state
	movsbl	%al, %edi
	call	putchar@PLT
	jmp	.L9
.L20:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE35:
	.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>
#include<string.h>

int main(void)
{
    int n;
    int now, min, max;
    int i, j;
    char input[2000];
    char train[1000];

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf("%s", input);

        now = 500;
        min = 500;
        max = 500;
        
        for (j = 0; ; j += 3){
            train[now] = input[j];
            
            if (input[j + 1] == '\0'){
                break;
            }
            
            if (input[j + 1] == '-'){
                now++;
            }
            else {
                now--;
            }

            if (now < min){
                min = now;
            }
            if (now > max){
                max = now;
            }
        }

        for (j = min; j <= max; j++){
            printf("%c", train[j]);
        }
        
        printf("\n");

    }

    return 0;
}
        
4
a->f->c->b->d
b
 4
a->e->c->b->d
a
 4
a->f->c->b->d
a
 4
a->f->c->b->d
`
 4
a->e->c->b->d
c
 4
a->f->c->b->d
c
 4
`->f->c->b->d
c
 4
`->f->c->b->d
d
 4
a->e->c->b->d
d
 4
a->e->c->b->d
`

afcbd
b
b
b
 aecbd
a
a
a
 afcbd
a
a
a
 afcbd
`
`
`
 aecbd
c
c
c
 afcbd
c
c
c
 `fcbd
c
c
c
 `fcbd
d
d
d
 aecbd
d
d
d
 aecbd
`
`
`

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(void)
{
    int n;
    int now, min, max;
    int i, j;
    char input[2000];
    char train[1000];

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        scanf("%s", input);

        now = 500;
        min = 500;
        max = 500;
        
        for (j = 0; ; j += 3){
            train[now] = input[j];
            
            if (input[j + 1] == '\0'){
                break;
            }
            
            if (input[j + 1] == '-'){
                now++;
            }
            else {
                now--;
            }

            if (now < min){
                min = now;
            }
            if (now > max){
                max = now;
            }
        }

        for (j = min; j <= max; j++){
            printf("%c", train[j]);
        }
        
        printf("\n");

    }

    return 0;
}
        ```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%s"
	.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	$3056, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-3048(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -3032(%rbp)
	jmp	.L2
.L12:
	leaq	-2016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$500, -3044(%rbp)
	movl	$500, -3040(%rbp)
	movl	$500, -3036(%rbp)
	movl	$0, -3028(%rbp)
.L9:
	movl	-3028(%rbp), %eax
	cltq
	movzbl	-2016(%rbp,%rax), %edx
	movl	-3044(%rbp), %eax
	cltq
	movb	%dl, -3024(%rbp,%rax)
	movl	-3028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-2016(%rbp,%rax), %eax
	testb	%al, %al
	je	.L16
	movl	-3028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-2016(%rbp,%rax), %eax
	cmpb	$45, %al
	jne	.L5
	addl	$1, -3044(%rbp)
	jmp	.L6
.L5:
	subl	$1, -3044(%rbp)
.L6:
	movl	-3044(%rbp), %eax
	cmpl	-3040(%rbp), %eax
	jge	.L7
	movl	-3044(%rbp), %eax
	movl	%eax, -3040(%rbp)
.L7:
	movl	-3044(%rbp), %eax
	cmpl	-3036(%rbp), %eax
	jle	.L8
	movl	-3044(%rbp), %eax
	movl	%eax, -3036(%rbp)
.L8:
	addl	$3, -3028(%rbp)
	jmp	.L9
.L16:
	nop
	movl	-3040(%rbp), %eax
	movl	%eax, -3028(%rbp)
	jmp	.L10
.L11:
	movl	-3028(%rbp), %eax
	cltq
	movzbl	-3024(%rbp,%rax), %eax
	movsbl	%al, %eax
	movl	%eax, %edi
	call	putchar@PLT
	addl	$1, -3028(%rbp)
.L10:
	movl	-3028(%rbp), %eax
	cmpl	-3036(%rbp), %eax
	jle	.L11
	movl	$10, %edi
	call	putchar@PLT
	addl	$1, -3032(%rbp)
.L2:
	movl	-3048(%rbp), %eax
	cmpl	%eax, -3032(%rbp)
	jl	.L12
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	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"
	.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	$3056, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-3048(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -3032(%rbp)
	jmp	.L2
.L12:
	leaq	-2016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$500, -3044(%rbp)
	movl	$500, -3040(%rbp)
	movl	$500, -3036(%rbp)
	movl	$0, -3028(%rbp)
.L9:
	movl	-3028(%rbp), %eax
	cltq
	movzbl	-2016(%rbp,%rax), %edx
	movl	-3044(%rbp), %eax
	cltq
	movb	%dl, -3024(%rbp,%rax)
	movl	-3028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-2016(%rbp,%rax), %eax
	testb	%al, %al
	je	.L16
	movl	-3028(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-2016(%rbp,%rax), %eax
	cmpb	$45, %al
	jne	.L5
	addl	$1, -3044(%rbp)
	jmp	.L6
.L5:
	subl	$1, -3044(%rbp)
.L6:
	movl	-3044(%rbp), %eax
	cmpl	-3040(%rbp), %eax
	jge	.L7
	movl	-3044(%rbp), %eax
	movl	%eax, -3040(%rbp)
.L7:
	movl	-3044(%rbp), %eax
	cmpl	-3036(%rbp), %eax
	jle	.L8
	movl	-3044(%rbp), %eax
	movl	%eax, -3036(%rbp)
.L8:
	addl	$3, -3028(%rbp)
	jmp	.L9
.L16:
	nop
	movl	-3040(%rbp), %eax
	movl	%eax, -3028(%rbp)
	jmp	.L10
.L11:
	movl	-3028(%rbp), %eax
	cltq
	movzbl	-3024(%rbp,%rax), %eax
	movsbl	%al, %eax
	movl	%eax, %edi
	call	putchar@PLT
	addl	$1, -3028(%rbp)
.L10:
	movl	-3028(%rbp), %eax
	cmpl	-3036(%rbp), %eax
	jle	.L11
	movl	$10, %edi
	call	putchar@PLT
	addl	$1, -3032(%rbp)
.L2:
	movl	-3048(%rbp), %eax
	cmpl	%eax, -3032(%rbp)
	jl	.L12
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	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:
