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 s[1010];
int a[1010];
int main(){
	int n,d;
	scanf("%d %s %d",&n,s,&d);
	for(int i=0;i<n;i++)if(d>0&&s[i]=='0')a[i]=1,d--;
	for(int i=n-1;i>=0;i--)if(d>0&&s[i]=='1')a[i]=1,d--;
	for(int i=0;i<n;i++)putchar(s[i]^a[i]);
	puts("");
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	s
	.bss
	.align 32
	.type	s, @object
	.size	s, 1010
s:
	.zero	1010
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 4040
a:
	.zero	4040
	.section	.rodata
.LC0:
	.string	"%d %s %d"
.LC1:
	.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	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rdx
	leaq	-28(%rbp), %rax
	movq	%rdx, %rcx
	leaq	s(%rip), %rdx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L2
.L4:
	movl	-24(%rbp), %eax
	testl	%eax, %eax
	jle	.L3
	movl	-20(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$48, %al
	jne	.L3
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-24(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -24(%rbp)
.L3:
	addl	$1, -20(%rbp)
.L2:
	movl	-28(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L4
	movl	-28(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L5
.L7:
	movl	-24(%rbp), %eax
	testl	%eax, %eax
	jle	.L6
	movl	-16(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$49, %al
	jne	.L6
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-24(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -24(%rbp)
.L6:
	subl	$1, -16(%rbp)
.L5:
	cmpl	$0, -16(%rbp)
	jns	.L7
	movl	$0, -12(%rbp)
	jmp	.L8
.L9:
	movl	-12(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	xorl	%ecx, %eax
	movl	%eax, %edi
	call	putchar@PLT
	addl	$1, -12(%rbp)
.L8:
	movl	-28(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L9
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	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 %s %d"
.LC1:
	.string	""
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	s(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rbp, %rdx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rcx
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	movl	4(%rsp), %ecx
	movslq	%eax, %r8
	movl	$1, %edx
	xorl	%r9d, %r9d
	leaq	-1(%rbp), %rdi
	leaq	-4+a(%rip), %r10
	movl	%ecx, %esi
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L25:
	cmpb	$48, (%rdx,%rdi)
	jne	.L4
	movl	$1, (%r10,%rdx,4)
	subl	$1, %esi
	movl	$1, %r9d
.L4:
	cmpq	%r8, %rdx
	je	.L3
	addq	$1, %rdx
.L12:
	testl	%esi, %esi
	jg	.L25
.L3:
	testb	%r9b, %r9b
	je	.L9
	movl	%esi, 4(%rsp)
	movl	%esi, %ecx
.L9:
	subl	$2, %eax
	movl	%ecx, %edx
	leaq	4+a(%rip), %rdi
	xorl	%esi, %esi
	cltq
	leaq	1+s(%rip), %rcx
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L26:
	cmpb	$49, (%rax,%rcx)
	jne	.L6
	movl	$1, (%rdi,%rax,4)
	subl	$1, %edx
	movl	$1, %esi
.L6:
	testl	%eax, %eax
	js	.L5
	subq	$1, %rax
.L10:
	testl	%edx, %edx
	jg	.L26
.L5:
	testb	%sil, %sil
	je	.L7
	movl	%edx, 4(%rsp)
.L7:
	xorl	%ebx, %ebx
	leaq	a(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L8:
	movq	stdout(%rip), %rsi
	movsbl	0(%rbp,%rbx), %edi
	xorl	(%r12,%rbx,4), %edi
	addq	$1, %rbx
	call	putc@PLT
	cmpl	%ebx, (%rsp)
	jg	.L8
.L2:
	leaq	.LC1(%rip), %rdi
	call	puts@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L27
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L27:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 4040
a:
	.zero	4040
	.globl	s
	.align 32
	.type	s, @object
	.size	s, 1010
s:
	.zero	1010
	.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 %d"
.LC1:
	.string	""
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	s(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rbp, %rdx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rcx
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	jle	.L2
	movl	4(%rsp), %ecx
	movslq	%eax, %r8
	movl	$1, %edx
	xorl	%r9d, %r9d
	leaq	-1(%rbp), %rdi
	leaq	-4+a(%rip), %r10
	movl	%ecx, %esi
	jmp	.L12
	.p2align 4,,10
	.p2align 3
.L25:
	cmpb	$48, (%rdx,%rdi)
	jne	.L4
	movl	$1, (%r10,%rdx,4)
	subl	$1, %esi
	movl	$1, %r9d
.L4:
	cmpq	%r8, %rdx
	je	.L3
	addq	$1, %rdx
.L12:
	testl	%esi, %esi
	jg	.L25
.L3:
	testb	%r9b, %r9b
	je	.L9
	movl	%esi, 4(%rsp)
	movl	%esi, %ecx
.L9:
	subl	$2, %eax
	movl	%ecx, %edx
	leaq	4+a(%rip), %rdi
	xorl	%esi, %esi
	cltq
	leaq	1+s(%rip), %rcx
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L26:
	cmpb	$49, (%rax,%rcx)
	jne	.L6
	movl	$1, (%rdi,%rax,4)
	subl	$1, %edx
	movl	$1, %esi
.L6:
	testl	%eax, %eax
	js	.L5
	subq	$1, %rax
.L10:
	testl	%edx, %edx
	jg	.L26
.L5:
	testb	%sil, %sil
	je	.L7
	movl	%edx, 4(%rsp)
.L7:
	xorl	%ebx, %ebx
	leaq	a(%rip), %r12
	.p2align 4,,10
	.p2align 3
.L8:
	movq	stdout(%rip), %rsi
	movsbl	0(%rbp,%rbx), %edi
	xorl	(%r12,%rbx,4), %edi
	addq	$1, %rbx
	call	putc@PLT
	cmpl	%ebx, (%rsp)
	jg	.L8
.L2:
	leaq	.LC1(%rip), %rdi
	call	puts@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L27
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L27:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 4040
a:
	.zero	4040
	.globl	s
	.align 32
	.type	s, @object
	.size	s, 1010
s:
	.zero	1010
	.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 s[1010];
int a[1010];
int main(){
	int n,d;
	scanf("%d %s %d",&n,s,&d);
	for(int i=0;i<n;i++)if(d>0&&s[i]=='0')a[i]=1,d--;
	for(int i=n-1;i>=0;i--)if(d>0&&s[i]=='1')a[i]=1,d--;
	for(int i=0;i<n;i++)putchar(s[i]^a[i]);
	puts("");
}

5
00001
4
 5
00000
3
 5
00001
1
 5
10001
1
 5
10001
2
 5
10001
4
 5
10000
1
 5
00010
1
 5
00001
0
 5
00010
0

11111
 11100
 10001
 11001
 11101
 11110
 11000
 10010
 00001
 00010

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 s[1010];
int a[1010];
int main(){
	int n,d;
	scanf("%d %s %d",&n,s,&d);
	for(int i=0;i<n;i++)if(d>0&&s[i]=='0')a[i]=1,d--;
	for(int i=n-1;i>=0;i--)if(d>0&&s[i]=='1')a[i]=1,d--;
	for(int i=0;i<n;i++)putchar(s[i]^a[i]);
	puts("");
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	s
	.bss
	.align 32
	.type	s, @object
	.size	s, 1010
s:
	.zero	1010
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 4040
a:
	.zero	4040
	.section	.rodata
.LC0:
	.string	"%d %s %d"
.LC1:
	.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	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rdx
	leaq	-28(%rbp), %rax
	movq	%rdx, %rcx
	leaq	s(%rip), %rdx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L2
.L4:
	movl	-24(%rbp), %eax
	testl	%eax, %eax
	jle	.L3
	movl	-20(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$48, %al
	jne	.L3
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-24(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -24(%rbp)
.L3:
	addl	$1, -20(%rbp)
.L2:
	movl	-28(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L4
	movl	-28(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L5
.L7:
	movl	-24(%rbp), %eax
	testl	%eax, %eax
	jle	.L6
	movl	-16(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$49, %al
	jne	.L6
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-24(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -24(%rbp)
.L6:
	subl	$1, -16(%rbp)
.L5:
	cmpl	$0, -16(%rbp)
	jns	.L7
	movl	$0, -12(%rbp)
	jmp	.L8
.L9:
	movl	-12(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	xorl	%ecx, %eax
	movl	%eax, %edi
	call	putchar@PLT
	addl	$1, -12(%rbp)
.L8:
	movl	-28(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L9
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	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
	.globl	s
	.bss
	.align 32
	.type	s, @object
	.size	s, 1010
s:
	.zero	1010
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 4040
a:
	.zero	4040
	.section	.rodata
.LC0:
	.string	"%d %s %d"
.LC1:
	.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	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-24(%rbp), %rdx
	leaq	-28(%rbp), %rax
	movq	%rdx, %rcx
	leaq	s(%rip), %rdx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -20(%rbp)
	jmp	.L2
.L4:
	movl	-24(%rbp), %eax
	testl	%eax, %eax
	jle	.L3
	movl	-20(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$48, %al
	jne	.L3
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-24(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -24(%rbp)
.L3:
	addl	$1, -20(%rbp)
.L2:
	movl	-28(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L4
	movl	-28(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	jmp	.L5
.L7:
	movl	-24(%rbp), %eax
	testl	%eax, %eax
	jle	.L6
	movl	-16(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	cmpb	$49, %al
	jne	.L6
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-24(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -24(%rbp)
.L6:
	subl	$1, -16(%rbp)
.L5:
	cmpl	$0, -16(%rbp)
	jns	.L7
	movl	$0, -12(%rbp)
	jmp	.L8
.L9:
	movl	-12(%rbp), %eax
	cltq
	leaq	s(%rip), %rdx
	movzbl	(%rax,%rdx), %eax
	movsbl	%al, %ecx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	xorl	%ecx, %eax
	movl	%eax, %edi
	call	putchar@PLT
	addl	$1, -12(%rbp)
.L8:
	movl	-28(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L9
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	call	puts@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	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:
