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>

char str[21];
char az[21];
char*sp,*azp;
short i;

int main(void){
scanf("%s",str);
sp = str;
azp = az;
while(*sp){
if(i){
if(*sp == 'Z'){
	i = 0;
	*azp = 'A';
	azp++;
	*azp = 'Z';
	azp++;
}
}else
if(*sp == 'A')i = 1;
sp++;
}
if(*az)printf("%s\n",az);
else printf("-1\n");
return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	str
	.bss
	.align 16
	.type	str, @object
	.size	str, 21
str:
	.zero	21
	.globl	az
	.align 16
	.type	az, @object
	.size	az, 21
az:
	.zero	21
	.globl	sp
	.align 8
	.type	sp, @object
	.size	sp, 8
sp:
	.zero	8
	.globl	azp
	.align 8
	.type	azp, @object
	.size	azp, 8
azp:
	.zero	8
	.globl	i
	.align 2
	.type	i, @object
	.size	i, 2
i:
	.zero	2
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"-1"
	.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	str(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	str(%rip), %rax
	movq	%rax, sp(%rip)
	leaq	az(%rip), %rax
	movq	%rax, azp(%rip)
	jmp	.L2
.L5:
	movzwl	i(%rip), %eax
	testw	%ax, %ax
	je	.L3
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$90, %al
	jne	.L4
	movw	$0, i(%rip)
	movq	azp(%rip), %rax
	movb	$65, (%rax)
	movq	azp(%rip), %rax
	addq	$1, %rax
	movq	%rax, azp(%rip)
	movq	azp(%rip), %rax
	movb	$90, (%rax)
	movq	azp(%rip), %rax
	addq	$1, %rax
	movq	%rax, azp(%rip)
	jmp	.L4
.L3:
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$65, %al
	jne	.L4
	movw	$1, i(%rip)
.L4:
	movq	sp(%rip), %rax
	addq	$1, %rax
	movq	%rax, sp(%rip)
.L2:
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L5
	movzbl	az(%rip), %eax
	testb	%al, %al
	je	.L6
	leaq	az(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L7
.L6:
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	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	"-1"
	.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	str(%rip), %rbx
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	movq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movzbl	str(%rip), %edx
	leaq	az(%rip), %rdi
	movq	%rbx, %rax
	movq	%rbx, sp(%rip)
	movq	%rdi, azp(%rip)
	testb	%dl, %dl
	jne	.L2
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L19:
	cmpb	$90, %dl
	jne	.L6
	movq	azp(%rip), %rax
	xorl	%edx, %edx
	movw	%dx, i(%rip)
	movb	$65, (%rax)
	movq	azp(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, azp(%rip)
	movb	$90, 1(%rax)
	movq	sp(%rip), %rcx
	addq	$1, azp(%rip)
	.p2align 4,,10
	.p2align 3
.L6:
	leaq	1(%rcx), %rax
	movq	%rax, sp(%rip)
	movzbl	1(%rcx), %edx
	testb	%dl, %dl
	je	.L7
.L2:
	cmpw	$0, i(%rip)
	movq	%rax, %rcx
	jne	.L19
	cmpb	$65, %dl
	jne	.L6
	movl	$1, %eax
	movw	%ax, i(%rip)
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	cmpb	$0, az(%rip)
	jne	.L17
	leaq	.LC1(%rip), %rdi
.L17:
	call	puts@PLT
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	i
	.bss
	.align 2
	.type	i, @object
	.size	i, 2
i:
	.zero	2
	.globl	azp
	.align 8
	.type	azp, @object
	.size	azp, 8
azp:
	.zero	8
	.globl	sp
	.align 8
	.type	sp, @object
	.size	sp, 8
sp:
	.zero	8
	.globl	az
	.align 16
	.type	az, @object
	.size	az, 21
az:
	.zero	21
	.globl	str
	.align 16
	.type	str, @object
	.size	str, 21
str:
	.zero	21
	.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	"-1"
	.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	str(%rip), %rbx
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	movq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movzbl	str(%rip), %edx
	leaq	az(%rip), %rdi
	movq	%rbx, %rax
	movq	%rbx, sp(%rip)
	movq	%rdi, azp(%rip)
	testb	%dl, %dl
	jne	.L2
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L19:
	cmpb	$90, %dl
	jne	.L6
	movq	azp(%rip), %rax
	xorl	%edx, %edx
	movw	%dx, i(%rip)
	movb	$65, (%rax)
	movq	azp(%rip), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, azp(%rip)
	movb	$90, 1(%rax)
	movq	sp(%rip), %rcx
	addq	$1, azp(%rip)
	.p2align 4,,10
	.p2align 3
.L6:
	leaq	1(%rcx), %rax
	movq	%rax, sp(%rip)
	movzbl	1(%rcx), %edx
	testb	%dl, %dl
	je	.L7
.L2:
	cmpw	$0, i(%rip)
	movq	%rax, %rcx
	jne	.L19
	cmpb	$65, %dl
	jne	.L6
	movl	$1, %eax
	movw	%ax, i(%rip)
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	cmpb	$0, az(%rip)
	jne	.L17
	leaq	.LC1(%rip), %rdi
.L17:
	call	puts@PLT
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	i
	.bss
	.align 2
	.type	i, @object
	.size	i, 2
i:
	.zero	2
	.globl	azp
	.align 8
	.type	azp, @object
	.size	azp, 8
azp:
	.zero	8
	.globl	sp
	.align 8
	.type	sp, @object
	.size	sp, 8
sp:
	.zero	8
	.globl	az
	.align 16
	.type	az, @object
	.size	az, 21
az:
	.zero	21
	.globl	str
	.align 16
	.type	str, @object
	.size	str, 21
str:
	.zero	21
	.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>

char str[21];
char az[21];
char*sp,*azp;
short i;

int main(void){
scanf("%s",str);
sp = str;
azp = az;
while(*sp){
if(i){
if(*sp == 'Z'){
	i = 0;
	*azp = 'A';
	azp++;
	*azp = 'Z';
	azp++;
}
}else
if(*sp == 'A')i = 1;
sp++;
}
if(*az)printf("%s\n",az);
else printf("-1\n");
return 0;
}
AOZUNYANPERIPERO
 OREQIRMQEAYNUYOA
 OREPIREPNAYNUZOA
 OREPIRNPEAYNUZOA
 OREQIRNPEAYNUZOA
 OREQIRMPEAYNUZOA
 AOZUNYAEPMRIQERO
 OREQIRMQEAYNUZOA
 ORFQIRMQEAYNUYOA
 OREQIRNQEAYNUYOA

AZ
 -1
 AZ
 AZ
 AZ
 AZ
 AZ
 AZ
 -1
 -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>

char str[21];
char az[21];
char*sp,*azp;
short i;

int main(void){
scanf("%s",str);
sp = str;
azp = az;
while(*sp){
if(i){
if(*sp == 'Z'){
	i = 0;
	*azp = 'A';
	azp++;
	*azp = 'Z';
	azp++;
}
}else
if(*sp == 'A')i = 1;
sp++;
}
if(*az)printf("%s\n",az);
else printf("-1\n");
return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	str
	.bss
	.align 16
	.type	str, @object
	.size	str, 21
str:
	.zero	21
	.globl	az
	.align 16
	.type	az, @object
	.size	az, 21
az:
	.zero	21
	.globl	sp
	.align 8
	.type	sp, @object
	.size	sp, 8
sp:
	.zero	8
	.globl	azp
	.align 8
	.type	azp, @object
	.size	azp, 8
azp:
	.zero	8
	.globl	i
	.align 2
	.type	i, @object
	.size	i, 2
i:
	.zero	2
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"-1"
	.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	str(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	str(%rip), %rax
	movq	%rax, sp(%rip)
	leaq	az(%rip), %rax
	movq	%rax, azp(%rip)
	jmp	.L2
.L5:
	movzwl	i(%rip), %eax
	testw	%ax, %ax
	je	.L3
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$90, %al
	jne	.L4
	movw	$0, i(%rip)
	movq	azp(%rip), %rax
	movb	$65, (%rax)
	movq	azp(%rip), %rax
	addq	$1, %rax
	movq	%rax, azp(%rip)
	movq	azp(%rip), %rax
	movb	$90, (%rax)
	movq	azp(%rip), %rax
	addq	$1, %rax
	movq	%rax, azp(%rip)
	jmp	.L4
.L3:
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$65, %al
	jne	.L4
	movw	$1, i(%rip)
.L4:
	movq	sp(%rip), %rax
	addq	$1, %rax
	movq	%rax, sp(%rip)
.L2:
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L5
	movzbl	az(%rip), %eax
	testb	%al, %al
	je	.L6
	leaq	az(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L7
.L6:
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	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	str
	.bss
	.align 16
	.type	str, @object
	.size	str, 21
str:
	.zero	21
	.globl	az
	.align 16
	.type	az, @object
	.size	az, 21
az:
	.zero	21
	.globl	sp
	.align 8
	.type	sp, @object
	.size	sp, 8
sp:
	.zero	8
	.globl	azp
	.align 8
	.type	azp, @object
	.size	azp, 8
azp:
	.zero	8
	.globl	i
	.align 2
	.type	i, @object
	.size	i, 2
i:
	.zero	2
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"-1"
	.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	str(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	str(%rip), %rax
	movq	%rax, sp(%rip)
	leaq	az(%rip), %rax
	movq	%rax, azp(%rip)
	jmp	.L2
.L5:
	movzwl	i(%rip), %eax
	testw	%ax, %ax
	je	.L3
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$90, %al
	jne	.L4
	movw	$0, i(%rip)
	movq	azp(%rip), %rax
	movb	$65, (%rax)
	movq	azp(%rip), %rax
	addq	$1, %rax
	movq	%rax, azp(%rip)
	movq	azp(%rip), %rax
	movb	$90, (%rax)
	movq	azp(%rip), %rax
	addq	$1, %rax
	movq	%rax, azp(%rip)
	jmp	.L4
.L3:
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	cmpb	$65, %al
	jne	.L4
	movw	$1, i(%rip)
.L4:
	movq	sp(%rip), %rax
	addq	$1, %rax
	movq	%rax, sp(%rip)
.L2:
	movq	sp(%rip), %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	jne	.L5
	movzbl	az(%rip), %eax
	testb	%al, %al
	je	.L6
	leaq	az(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	jmp	.L7
.L6:
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
.L7:
	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:
