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>
#define slimit 1001    /*文字列数限界*/
#define climit 7    /*命令文字数限界*/

int main(void){
    /*宣言部*/
        /*input:加工対象文字列, command:命令文字列, buf:バッファ用文字列*/
    char input[slimit]={0}, command[climit]={0}, buf[slimit]={0};    
    int cnum, arg1, arg2, x, y;    /*cnum:命令数, arg1:1番目引数,
                                 arg2:2番目引数, x:ループ変数, y:ループ変数*/
    
    /*入力部*/
    scanf("%s\n%d", input, &cnum);    /*加工対象文字列と命令数を読み取る*/
        /*命令とそれに続く引数は受取・実行時に行う*/
        
    /*命令・引数受取・実行部*/
    for(x=0; cnum>x; x++){    /*命令数回ループ*/
        /*命令・引数受取部*/
            /*命令と2番目までの引数の読み取り*/
        scanf("%s %d %d", command, &arg1, &arg2);
        
        /*命令実行部*/
        if (0 == strcmp("print", command)){    /*print命令処理*/
                /*指定文字部分だけをバッファにコピー*/
            strncpy(buf, &input[arg1], (arg2-arg1)+1);
            printf("%s\n", buf);    /*バッファを表示*/
        
        }else if (0 == strcmp("reverse", command)){    /*reverse命令処理*/
            strncpy(buf, &input[arg1], (arg2-arg1)+1);
                /*指定文字部分だけをバッファにコピー*/
            for(y=0; (arg2-arg1)+1>y; y++){    /*バッファ文字数分ループ*/
                    /*バッファを後ろから順に読み込み
                        加工対象の指定された所から代入*/
                input[arg1+y] = buf[arg2-arg1-y];
            }
        }else if (0 == strcmp("replace", command)){    /*replace命令処理*/
            scanf("%s", &buf); /*入力バッファに残ってる3番目の引数を受け取る*/
        
            for(y=0; (arg2-arg1)+1>y; y++){    /*バッファ文字数分ループ*/
                    /*バッファを指定文字数分だけ加工対象の指定位置に代入*/
                input[arg1+y] = buf[y];
            }
        }
        
        strncpy(buf, "", slimit);    /*次の命令に影響を残さないために
                                        バッファをナル文字で埋める*/
    }
    
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s\n%d"
.LC1:
	.string	"%s %d %d"
.LC2:
	.string	"print"
.LC3:
	.string	"reverse"
.LC4:
	.string	"replace"
.LC5:
	.string	"%s"
.LC6:
	.string	""
	.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	$2064, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -2032(%rbp)
	movq	$0, -2024(%rbp)
	leaq	-2016(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movb	%al, (%rdx)
	addq	$1, %rdx
	movl	$0, -2039(%rbp)
	movw	$0, -2035(%rbp)
	movb	$0, -2033(%rbp)
	movq	$0, -1024(%rbp)
	movq	$0, -1016(%rbp)
	leaq	-1008(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movb	%al, (%rdx)
	addq	$1, %rdx
	leaq	-2060(%rbp), %rdx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2048(%rbp)
	jmp	.L2
.L10:
	leaq	-2052(%rbp), %rcx
	leaq	-2056(%rbp), %rdx
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L3
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-2056(%rbp), %eax
	leaq	-2032(%rbp), %rcx
	cltq
	addq	%rax, %rcx
	leaq	-1024(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	leaq	-1024(%rbp), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L4
.L3:
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L5
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-2056(%rbp), %eax
	leaq	-2032(%rbp), %rcx
	cltq
	addq	%rax, %rcx
	leaq	-1024(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	movl	$0, -2044(%rbp)
	jmp	.L6
.L7:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	subl	-2044(%rbp), %eax
	movl	-2056(%rbp), %ecx
	movl	-2044(%rbp), %edx
	addl	%edx, %ecx
	cltq
	movzbl	-1024(%rbp,%rax), %edx
	movslq	%ecx, %rax
	movb	%dl, -2032(%rbp,%rax)
	addl	$1, -2044(%rbp)
.L6:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	cmpl	%eax, -2044(%rbp)
	jle	.L7
	jmp	.L4
.L5:
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L4
	leaq	-1024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC5(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2044(%rbp)
	jmp	.L8
.L9:
	movl	-2056(%rbp), %edx
	movl	-2044(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-2044(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %edx
	movslq	%ecx, %rax
	movb	%dl, -2032(%rbp,%rax)
	addl	$1, -2044(%rbp)
.L8:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	cmpl	%eax, -2044(%rbp)
	jle	.L9
.L4:
	leaq	-1024(%rbp), %rax
	movl	$1001, %edx
	leaq	.LC6(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	addl	$1, -2048(%rbp)
.L2:
	movl	-2060(%rbp), %eax
	cmpl	%eax, -2048(%rbp)
	jl	.L10
	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	"%s\n%d"
.LC1:
	.string	"%s %d %d"
.LC2:
	.string	"print"
.LC3:
	.string	"reverse"
.LC4:
	.string	"replace"
.LC5:
	.string	"%s"
.LC6:
	.string	""
	.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
	movl	$123, %ecx
	xorl	%edx, %edx
	pxor	%xmm0, %xmm0
	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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$2104, %rsp
	.cfi_def_cfa_offset 2160
	movq	%fs:40, %rax
	movq	%rax, 2088(%rsp)
	xorl	%eax, %eax
	leaq	80(%rsp), %rdi
	movw	%dx, 61(%rsp)
	leaq	44(%rsp), %rdx
	movl	$0, 57(%rsp)
	movb	$0, 63(%rsp)
	movaps	%xmm0, 64(%rsp)
	movaps	%xmm0, 1072(%rsp)
	rep stosq
	movl	$123, %ecx
	movb	$0, (%rdi)
	leaq	1088(%rsp), %rdi
	rep stosq
	leaq	64(%rsp), %rax
	movq	%rax, (%rsp)
	movq	%rax, %rsi
	xorl	%eax, %eax
	movb	$0, (%rdi)
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L2
	leaq	1071(%rsp), %rax
	xorl	%ebp, %ebp
	leaq	52(%rsp), %r15
	movq	%rax, 16(%rsp)
	leaq	48(%rsp), %r14
	leaq	57(%rsp), %rbx
	leaq	.LC1(%rip), %r13
	leaq	1072(%rsp), %r12
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbx, %rsi
	leaq	.LC3(%rip), %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L14
	movq	%rbx, %rsi
	leaq	.LC4(%rip), %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L15
.L4:
	movl	$1001, %edx
	leaq	.LC6(%rip), %rsi
	movq	%r12, %rdi
	addl	$1, %ebp
	call	strncpy@PLT
	cmpl	%ebp, 44(%rsp)
	jle	.L2
.L8:
	movq	%rbx, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	movq	%r15, %rcx
	movq	%r14, %rdx
	call	__isoc99_scanf@PLT
	movq	%rbx, %rsi
	leaq	.LC2(%rip), %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L3
	movslq	48(%rsp), %rsi
	movl	52(%rsp), %edx
	movq	%r12, %rdi
	movl	$1001, %ecx
	subl	%esi, %edx
	addq	(%rsp), %rsi
	addl	$1, %edx
	movslq	%edx, %rdx
	call	__strncpy_chk@PLT
	movq	%r12, %rdi
	call	puts@PLT
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L2:
	movq	2088(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L16
	addq	$2104, %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
.L14:
	.cfi_restore_state
	movslq	48(%rsp), %rdx
	movl	52(%rsp), %r8d
	movl	$1001, %ecx
	movq	%r12, %rdi
	movq	(%rsp), %rax
	subl	%edx, %r8d
	leaq	(%rax,%rdx), %rsi
	leal	1(%r8), %edx
	movl	%r8d, 12(%rsp)
	movslq	%edx, %rdx
	movq	%rsi, 24(%rsp)
	call	__strncpy_chk@PLT
	movl	12(%rsp), %r8d
	testl	%r8d, %r8d
	js	.L4
	movslq	%r8d, %rax
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	addq	%r12, %rax
	.p2align 4,,10
	.p2align 3
.L7:
	movzbl	(%rax), %ecx
	subq	$1, %rax
	addq	$1, %rdx
	movb	%cl, -1(%rdx)
	cmpq	%rsi, %rax
	jne	.L7
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L15:
	leaq	.LC5(%rip), %rdi
	movq	%r12, %rsi
	call	__isoc99_scanf@PLT
	movslq	48(%rsp), %rdi
	movl	52(%rsp), %edx
	subl	%edi, %edx
	js	.L4
	movslq	%edx, %rdx
	addq	(%rsp), %rdi
	movq	%r12, %rsi
	addq	$1, %rdx
	call	memcpy@PLT
	jmp	.L4
.L16:
	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	"%s\n%d"
.LC1:
	.string	"%s %d %d"
.LC2:
	.string	"print"
.LC3:
	.string	"reverse"
.LC4:
	.string	"replace"
.LC5:
	.string	"%s"
.LC6:
	.string	""
	.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
	movl	$123, %ecx
	xorl	%edx, %edx
	pxor	%xmm0, %xmm0
	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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$2104, %rsp
	.cfi_def_cfa_offset 2160
	movq	%fs:40, %rax
	movq	%rax, 2088(%rsp)
	xorl	%eax, %eax
	leaq	80(%rsp), %rdi
	movw	%dx, 61(%rsp)
	leaq	44(%rsp), %rdx
	movl	$0, 57(%rsp)
	movb	$0, 63(%rsp)
	movaps	%xmm0, 64(%rsp)
	movaps	%xmm0, 1072(%rsp)
	rep stosq
	movl	$123, %ecx
	movb	$0, (%rdi)
	leaq	1088(%rsp), %rdi
	rep stosq
	leaq	64(%rsp), %rax
	movq	%rax, (%rsp)
	movq	%rax, %rsi
	xorl	%eax, %eax
	movb	$0, (%rdi)
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L2
	leaq	1071(%rsp), %rax
	xorl	%ebp, %ebp
	leaq	52(%rsp), %r15
	movq	%rax, 16(%rsp)
	leaq	48(%rsp), %r14
	leaq	57(%rsp), %rbx
	leaq	.LC1(%rip), %r13
	leaq	1072(%rsp), %r12
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rbx, %rsi
	leaq	.LC3(%rip), %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L14
	movq	%rbx, %rsi
	leaq	.LC4(%rip), %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L15
.L4:
	movl	$1001, %edx
	leaq	.LC6(%rip), %rsi
	movq	%r12, %rdi
	addl	$1, %ebp
	call	strncpy@PLT
	cmpl	%ebp, 44(%rsp)
	jle	.L2
.L8:
	movq	%rbx, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	movq	%r15, %rcx
	movq	%r14, %rdx
	call	__isoc99_scanf@PLT
	movq	%rbx, %rsi
	leaq	.LC2(%rip), %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L3
	movslq	48(%rsp), %rsi
	movl	52(%rsp), %edx
	movq	%r12, %rdi
	movl	$1001, %ecx
	subl	%esi, %edx
	addq	(%rsp), %rsi
	addl	$1, %edx
	movslq	%edx, %rdx
	call	__strncpy_chk@PLT
	movq	%r12, %rdi
	call	puts@PLT
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L2:
	movq	2088(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L16
	addq	$2104, %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
.L14:
	.cfi_restore_state
	movslq	48(%rsp), %rdx
	movl	52(%rsp), %r8d
	movl	$1001, %ecx
	movq	%r12, %rdi
	movq	(%rsp), %rax
	subl	%edx, %r8d
	leaq	(%rax,%rdx), %rsi
	leal	1(%r8), %edx
	movl	%r8d, 12(%rsp)
	movslq	%edx, %rdx
	movq	%rsi, 24(%rsp)
	call	__strncpy_chk@PLT
	movl	12(%rsp), %r8d
	testl	%r8d, %r8d
	js	.L4
	movslq	%r8d, %rax
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	addq	%r12, %rax
	.p2align 4,,10
	.p2align 3
.L7:
	movzbl	(%rax), %ecx
	subq	$1, %rax
	addq	$1, %rdx
	movb	%cl, -1(%rdx)
	cmpq	%rsi, %rax
	jne	.L7
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L15:
	leaq	.LC5(%rip), %rdi
	movq	%r12, %rsi
	call	__isoc99_scanf@PLT
	movslq	48(%rsp), %rdi
	movl	52(%rsp), %edx
	subl	%edi, %edx
	js	.L4
	movslq	%edx, %rdx
	addq	(%rsp), %rdi
	movq	%r12, %rsi
	addq	$1, %rdx
	call	memcpy@PLT
	jmp	.L4
.L16:
	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>
#define slimit 1001    /*文字列数限界*/
#define climit 7    /*命令文字数限界*/

int main(void){
    /*宣言部*/
        /*input:加工対象文字列, command:命令文字列, buf:バッファ用文字列*/
    char input[slimit]={0}, command[climit]={0}, buf[slimit]={0};    
    int cnum, arg1, arg2, x, y;    /*cnum:命令数, arg1:1番目引数,
                                 arg2:2番目引数, x:ループ変数, y:ループ変数*/
    
    /*入力部*/
    scanf("%s\n%d", input, &cnum);    /*加工対象文字列と命令数を読み取る*/
        /*命令とそれに続く引数は受取・実行時に行う*/
        
    /*命令・引数受取・実行部*/
    for(x=0; cnum>x; x++){    /*命令数回ループ*/
        /*命令・引数受取部*/
            /*命令と2番目までの引数の読み取り*/
        scanf("%s %d %d", command, &arg1, &arg2);
        
        /*命令実行部*/
        if (0 == strcmp("print", command)){    /*print命令処理*/
                /*指定文字部分だけをバッファにコピー*/
            strncpy(buf, &input[arg1], (arg2-arg1)+1);
            printf("%s\n", buf);    /*バッファを表示*/
        
        }else if (0 == strcmp("reverse", command)){    /*reverse命令処理*/
            strncpy(buf, &input[arg1], (arg2-arg1)+1);
                /*指定文字部分だけをバッファにコピー*/
            for(y=0; (arg2-arg1)+1>y; y++){    /*バッファ文字数分ループ*/
                    /*バッファを後ろから順に読み込み
                        加工対象の指定された所から代入*/
                input[arg1+y] = buf[arg2-arg1-y];
            }
        }else if (0 == strcmp("replace", command)){    /*replace命令処理*/
            scanf("%s", &buf); /*入力バッファに残ってる3番目の引数を受け取る*/
        
            for(y=0; (arg2-arg1)+1>y; y++){    /*バッファ文字数分ループ*/
                    /*バッファを指定文字数分だけ加工対象の指定位置に代入*/
                input[arg1+y] = buf[y];
            }
        }
        
        strncpy(buf, "", slimit);    /*次の命令に影響を残さないために
                                        バッファをナル文字で埋める*/
    }
    
    return 0;
}
abcde
3
replace 1 3 xy{
reverse 0 2
print 1 4
 xyz
3
print 0 2
replace 1 2 abc
print 0 2
 abcde
3
replace 1 3 xy{
reverse 0 2
print 1 2
 abcde
3
replace 1 3 yy{
reverse 0 2
print 1 2
 abcde
3
replace 1 3 yy{
reverse 0 2
print 1 1
 xyz
1
print 0 2
replace 0 2 abc
print 0 2
 abcde
3
replace 1 3 xy{
reverse 0 2
print 1 3
 xyz
3
print 0 1
replace 1 2 abc
print 0 2
 abcde
3
replace 1 3 yy{
reverse -1 2
print 1 2
 abcde
3
replace 1 3 xy{
reverse 0 2
print 1 1

xyz

 xyz
 xy


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>
#define slimit 1001    /*文字列数限界*/
#define climit 7    /*命令文字数限界*/

int main(void){
    /*宣言部*/
        /*input:加工対象文字列, command:命令文字列, buf:バッファ用文字列*/
    char input[slimit]={0}, command[climit]={0}, buf[slimit]={0};    
    int cnum, arg1, arg2, x, y;    /*cnum:命令数, arg1:1番目引数,
                                 arg2:2番目引数, x:ループ変数, y:ループ変数*/
    
    /*入力部*/
    scanf("%s\n%d", input, &cnum);    /*加工対象文字列と命令数を読み取る*/
        /*命令とそれに続く引数は受取・実行時に行う*/
        
    /*命令・引数受取・実行部*/
    for(x=0; cnum>x; x++){    /*命令数回ループ*/
        /*命令・引数受取部*/
            /*命令と2番目までの引数の読み取り*/
        scanf("%s %d %d", command, &arg1, &arg2);
        
        /*命令実行部*/
        if (0 == strcmp("print", command)){    /*print命令処理*/
                /*指定文字部分だけをバッファにコピー*/
            strncpy(buf, &input[arg1], (arg2-arg1)+1);
            printf("%s\n", buf);    /*バッファを表示*/
        
        }else if (0 == strcmp("reverse", command)){    /*reverse命令処理*/
            strncpy(buf, &input[arg1], (arg2-arg1)+1);
                /*指定文字部分だけをバッファにコピー*/
            for(y=0; (arg2-arg1)+1>y; y++){    /*バッファ文字数分ループ*/
                    /*バッファを後ろから順に読み込み
                        加工対象の指定された所から代入*/
                input[arg1+y] = buf[arg2-arg1-y];
            }
        }else if (0 == strcmp("replace", command)){    /*replace命令処理*/
            scanf("%s", &buf); /*入力バッファに残ってる3番目の引数を受け取る*/
        
            for(y=0; (arg2-arg1)+1>y; y++){    /*バッファ文字数分ループ*/
                    /*バッファを指定文字数分だけ加工対象の指定位置に代入*/
                input[arg1+y] = buf[y];
            }
        }
        
        strncpy(buf, "", slimit);    /*次の命令に影響を残さないために
                                        バッファをナル文字で埋める*/
    }
    
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s\n%d"
.LC1:
	.string	"%s %d %d"
.LC2:
	.string	"print"
.LC3:
	.string	"reverse"
.LC4:
	.string	"replace"
.LC5:
	.string	"%s"
.LC6:
	.string	""
	.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	$2064, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -2032(%rbp)
	movq	$0, -2024(%rbp)
	leaq	-2016(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movb	%al, (%rdx)
	addq	$1, %rdx
	movl	$0, -2039(%rbp)
	movw	$0, -2035(%rbp)
	movb	$0, -2033(%rbp)
	movq	$0, -1024(%rbp)
	movq	$0, -1016(%rbp)
	leaq	-1008(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movb	%al, (%rdx)
	addq	$1, %rdx
	leaq	-2060(%rbp), %rdx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2048(%rbp)
	jmp	.L2
.L10:
	leaq	-2052(%rbp), %rcx
	leaq	-2056(%rbp), %rdx
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L3
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-2056(%rbp), %eax
	leaq	-2032(%rbp), %rcx
	cltq
	addq	%rax, %rcx
	leaq	-1024(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	leaq	-1024(%rbp), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L4
.L3:
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L5
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-2056(%rbp), %eax
	leaq	-2032(%rbp), %rcx
	cltq
	addq	%rax, %rcx
	leaq	-1024(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	movl	$0, -2044(%rbp)
	jmp	.L6
.L7:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	subl	-2044(%rbp), %eax
	movl	-2056(%rbp), %ecx
	movl	-2044(%rbp), %edx
	addl	%edx, %ecx
	cltq
	movzbl	-1024(%rbp,%rax), %edx
	movslq	%ecx, %rax
	movb	%dl, -2032(%rbp,%rax)
	addl	$1, -2044(%rbp)
.L6:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	cmpl	%eax, -2044(%rbp)
	jle	.L7
	jmp	.L4
.L5:
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L4
	leaq	-1024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC5(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2044(%rbp)
	jmp	.L8
.L9:
	movl	-2056(%rbp), %edx
	movl	-2044(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-2044(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %edx
	movslq	%ecx, %rax
	movb	%dl, -2032(%rbp,%rax)
	addl	$1, -2044(%rbp)
.L8:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	cmpl	%eax, -2044(%rbp)
	jle	.L9
.L4:
	leaq	-1024(%rbp), %rax
	movl	$1001, %edx
	leaq	.LC6(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	addl	$1, -2048(%rbp)
.L2:
	movl	-2060(%rbp), %eax
	cmpl	%eax, -2048(%rbp)
	jl	.L10
	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	"%s\n%d"
.LC1:
	.string	"%s %d %d"
.LC2:
	.string	"print"
.LC3:
	.string	"reverse"
.LC4:
	.string	"replace"
.LC5:
	.string	"%s"
.LC6:
	.string	""
	.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	$2064, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -2032(%rbp)
	movq	$0, -2024(%rbp)
	leaq	-2016(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movb	%al, (%rdx)
	addq	$1, %rdx
	movl	$0, -2039(%rbp)
	movw	$0, -2035(%rbp)
	movb	$0, -2033(%rbp)
	movq	$0, -1024(%rbp)
	movq	$0, -1016(%rbp)
	leaq	-1008(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movb	%al, (%rdx)
	addq	$1, %rdx
	leaq	-2060(%rbp), %rdx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2048(%rbp)
	jmp	.L2
.L10:
	leaq	-2052(%rbp), %rcx
	leaq	-2056(%rbp), %rdx
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L3
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-2056(%rbp), %eax
	leaq	-2032(%rbp), %rcx
	cltq
	addq	%rax, %rcx
	leaq	-1024(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	leaq	-1024(%rbp), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L4
.L3:
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L5
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	addl	$1, %eax
	movslq	%eax, %rdx
	movl	-2056(%rbp), %eax
	leaq	-2032(%rbp), %rcx
	cltq
	addq	%rax, %rcx
	leaq	-1024(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	movl	$0, -2044(%rbp)
	jmp	.L6
.L7:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	subl	-2044(%rbp), %eax
	movl	-2056(%rbp), %ecx
	movl	-2044(%rbp), %edx
	addl	%edx, %ecx
	cltq
	movzbl	-1024(%rbp,%rax), %edx
	movslq	%ecx, %rax
	movb	%dl, -2032(%rbp,%rax)
	addl	$1, -2044(%rbp)
.L6:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	cmpl	%eax, -2044(%rbp)
	jle	.L7
	jmp	.L4
.L5:
	leaq	-2039(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC4(%rip), %rax
	movq	%rax, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L4
	leaq	-1024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC5(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -2044(%rbp)
	jmp	.L8
.L9:
	movl	-2056(%rbp), %edx
	movl	-2044(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-2044(%rbp), %eax
	cltq
	movzbl	-1024(%rbp,%rax), %edx
	movslq	%ecx, %rax
	movb	%dl, -2032(%rbp,%rax)
	addl	$1, -2044(%rbp)
.L8:
	movl	-2052(%rbp), %eax
	movl	-2056(%rbp), %edx
	subl	%edx, %eax
	cmpl	%eax, -2044(%rbp)
	jle	.L9
.L4:
	leaq	-1024(%rbp), %rax
	movl	$1001, %edx
	leaq	.LC6(%rip), %rcx
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	strncpy@PLT
	addl	$1, -2048(%rbp)
.L2:
	movl	-2060(%rbp), %eax
	cmpl	%eax, -2048(%rbp)
	jl	.L10
	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:
