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(){
	char S[100000];
	scanf("%s",S);

	int length = strlen(S);
	int K = strlen(S);
	
	for ( int i=0; i<length-1 ; i++ ) {
		if ( S[i+1] != S[i] ) {
			if( 2*(i+1) < length && length -(i+1) < K) {
				K = length - (i+1) ;
			} else if ( i+1<K ) {
				K = i+1;
			}
		}
	}
	printf("%d",K); 
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"%d"
	.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	-98304(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1728, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-100016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-100016(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movl	%eax, -100020(%rbp)
	leaq	-100016(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movl	%eax, -100028(%rbp)
	movl	$0, -100024(%rbp)
	jmp	.L2
.L5:
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-100016(%rbp,%rax), %edx
	movl	-100024(%rbp), %eax
	cltq
	movzbl	-100016(%rbp,%rax), %eax
	cmpb	%al, %dl
	je	.L3
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	addl	%eax, %eax
	cmpl	%eax, -100020(%rbp)
	jle	.L4
	movl	-100024(%rbp), %eax
	leal	1(%rax), %edx
	movl	-100020(%rbp), %eax
	subl	%edx, %eax
	cmpl	%eax, -100028(%rbp)
	jle	.L4
	movl	-100024(%rbp), %eax
	leal	1(%rax), %edx
	movl	-100020(%rbp), %eax
	subl	%edx, %eax
	movl	%eax, -100028(%rbp)
	jmp	.L3
.L4:
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -100028(%rbp)
	jle	.L3
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -100028(%rbp)
.L3:
	addl	$1, -100024(%rbp)
.L2:
	movl	-100020(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -100024(%rbp)
	jl	.L5
	movl	-100028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-98304(%rsp), %r11
	.cfi_def_cfa 11, 98344
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1720, %rsp
	.cfi_def_cfa_offset 100064
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 100008(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	movq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movq	%rbx, %rdi
	call	strlen@PLT
	leal	-1(%rax), %edi
	movq	%rax, %r8
	testl	%edi, %edi
	jle	.L2
	movl	%eax, %r9d
	leal	-2(%rax), %eax
	cmpq	$3, %r8
	jbe	.L16
	leal	-8(%r8,%r8), %ecx
	movzbl	(%rsp), %ebp
	movl	%r8d, %r12d
	movl	%edi, %r11d
	andl	$-4, %ecx
	leaq	1(%rsp), %r10
	movl	$2, %esi
	addl	$6, %ecx
.L9:
	movzbl	(%r10), %r13d
	movl	%r12d, %edx
	subl	%r11d, %edx
	cmpb	%r13b, %bpl
	je	.L4
	cmpl	%esi, %r9d
	jle	.L6
	cmpl	%r11d, %r8d
	jle	.L6
	movl	%r11d, %r8d
.L4:
	movzbl	1(%r10), %ebp
	movl	%r12d, %edx
	subl	%eax, %edx
	cmpb	%bpl, %r13b
	je	.L7
	leal	2(%rsi), %r13d
	cmpl	%r13d, %r9d
	jle	.L8
	cmpl	%eax, %r8d
	jle	.L8
	movl	%eax, %r8d
.L7:
	addl	$4, %esi
	addq	$2, %r10
	subl	$2, %eax
	subl	$2, %r11d
	cmpl	%ecx, %esi
	jne	.L9
.L3:
	movslq	%edx, %rax
	leaq	(%rbx,%rax), %rcx
	movl	%edi, %eax
	subl	%edx, %eax
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L11:
	cmpl	%eax, %r8d
	jle	.L12
	movl	%eax, %r8d
.L10:
	addq	$1, %rcx
	subl	$1, %eax
	cmpl	%edi, %edx
	jge	.L2
.L13:
	movzbl	(%rcx), %ebx
	addl	$1, %edx
	cmpb	%bl, 1(%rcx)
	je	.L10
	leal	(%rdx,%rdx), %esi
	cmpl	%esi, %r9d
	jg	.L11
.L12:
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	addq	$1, %rcx
	subl	$1, %eax
	cmpl	%edi, %edx
	jl	.L13
.L2:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	100008(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L22
	addq	$100024, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L6:
	.cfi_restore_state
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	jmp	.L4
.L8:
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	jmp	.L7
.L16:
	xorl	%edx, %edx
	jmp	.L3
.L22:
	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"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-98304(%rsp), %r11
	.cfi_def_cfa 11, 98344
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1720, %rsp
	.cfi_def_cfa_offset 100064
	leaq	.LC0(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 100008(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	movq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movq	%rbx, %rdi
	call	strlen@PLT
	leal	-1(%rax), %edi
	movq	%rax, %r8
	testl	%edi, %edi
	jle	.L2
	movl	%eax, %r9d
	leal	-2(%rax), %eax
	cmpq	$3, %r8
	jbe	.L16
	leal	-8(%r8,%r8), %ecx
	movzbl	(%rsp), %ebp
	movl	%r8d, %r12d
	movl	%edi, %r11d
	andl	$-4, %ecx
	leaq	1(%rsp), %r10
	movl	$2, %esi
	addl	$6, %ecx
.L9:
	movzbl	(%r10), %r13d
	movl	%r12d, %edx
	subl	%r11d, %edx
	cmpb	%r13b, %bpl
	je	.L4
	cmpl	%esi, %r9d
	jle	.L6
	cmpl	%r11d, %r8d
	jle	.L6
	movl	%r11d, %r8d
.L4:
	movzbl	1(%r10), %ebp
	movl	%r12d, %edx
	subl	%eax, %edx
	cmpb	%bpl, %r13b
	je	.L7
	leal	2(%rsi), %r13d
	cmpl	%r13d, %r9d
	jle	.L8
	cmpl	%eax, %r8d
	jle	.L8
	movl	%eax, %r8d
.L7:
	addl	$4, %esi
	addq	$2, %r10
	subl	$2, %eax
	subl	$2, %r11d
	cmpl	%ecx, %esi
	jne	.L9
.L3:
	movslq	%edx, %rax
	leaq	(%rbx,%rax), %rcx
	movl	%edi, %eax
	subl	%edx, %eax
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L11:
	cmpl	%eax, %r8d
	jle	.L12
	movl	%eax, %r8d
.L10:
	addq	$1, %rcx
	subl	$1, %eax
	cmpl	%edi, %edx
	jge	.L2
.L13:
	movzbl	(%rcx), %ebx
	addl	$1, %edx
	cmpb	%bl, 1(%rcx)
	je	.L10
	leal	(%rdx,%rdx), %esi
	cmpl	%esi, %r9d
	jg	.L11
.L12:
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	addq	$1, %rcx
	subl	$1, %eax
	cmpl	%edi, %edx
	jl	.L13
.L2:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	100008(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L22
	addq	$100024, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L6:
	.cfi_restore_state
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	jmp	.L4
.L8:
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	jmp	.L7
.L16:
	xorl	%edx, %edx
	jmp	.L3
.L22:
	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(){
	char S[100000];
	scanf("%s",S);

	int length = strlen(S);
	int K = strlen(S);
	
	for ( int i=0; i<length-1 ; i++ ) {
		if ( S[i+1] != S[i] ) {
			if( 2*(i+1) < length && length -(i+1) < K) {
				K = length - (i+1) ;
			} else if ( i+1<K ) {
				K = i+1;
			}
		}
	}
	printf("%d",K); 
}
100000010
 011
 00001101
 111
 00011101
 100000101
 11111111
 000000000
 100000011
 100001011

7 2 4 3 5 6 8 9 7 5
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(){
	char S[100000];
	scanf("%s",S);

	int length = strlen(S);
	int K = strlen(S);
	
	for ( int i=0; i<length-1 ; i++ ) {
		if ( S[i+1] != S[i] ) {
			if( 2*(i+1) < length && length -(i+1) < K) {
				K = length - (i+1) ;
			} else if ( i+1<K ) {
				K = i+1;
			}
		}
	}
	printf("%d",K); 
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"%d"
	.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	-98304(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1728, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-100016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-100016(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movl	%eax, -100020(%rbp)
	leaq	-100016(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movl	%eax, -100028(%rbp)
	movl	$0, -100024(%rbp)
	jmp	.L2
.L5:
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-100016(%rbp,%rax), %edx
	movl	-100024(%rbp), %eax
	cltq
	movzbl	-100016(%rbp,%rax), %eax
	cmpb	%al, %dl
	je	.L3
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	addl	%eax, %eax
	cmpl	%eax, -100020(%rbp)
	jle	.L4
	movl	-100024(%rbp), %eax
	leal	1(%rax), %edx
	movl	-100020(%rbp), %eax
	subl	%edx, %eax
	cmpl	%eax, -100028(%rbp)
	jle	.L4
	movl	-100024(%rbp), %eax
	leal	1(%rax), %edx
	movl	-100020(%rbp), %eax
	subl	%edx, %eax
	movl	%eax, -100028(%rbp)
	jmp	.L3
.L4:
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -100028(%rbp)
	jle	.L3
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -100028(%rbp)
.L3:
	addl	$1, -100024(%rbp)
.L2:
	movl	-100020(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -100024(%rbp)
	jl	.L5
	movl	-100028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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"
.LC1:
	.string	"%d"
	.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	-98304(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1728, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-100016(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-100016(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movl	%eax, -100020(%rbp)
	leaq	-100016(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movl	%eax, -100028(%rbp)
	movl	$0, -100024(%rbp)
	jmp	.L2
.L5:
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	cltq
	movzbl	-100016(%rbp,%rax), %edx
	movl	-100024(%rbp), %eax
	cltq
	movzbl	-100016(%rbp,%rax), %eax
	cmpb	%al, %dl
	je	.L3
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	addl	%eax, %eax
	cmpl	%eax, -100020(%rbp)
	jle	.L4
	movl	-100024(%rbp), %eax
	leal	1(%rax), %edx
	movl	-100020(%rbp), %eax
	subl	%edx, %eax
	cmpl	%eax, -100028(%rbp)
	jle	.L4
	movl	-100024(%rbp), %eax
	leal	1(%rax), %edx
	movl	-100020(%rbp), %eax
	subl	%edx, %eax
	movl	%eax, -100028(%rbp)
	jmp	.L3
.L4:
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -100028(%rbp)
	jle	.L3
	movl	-100024(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -100028(%rbp)
.L3:
	addl	$1, -100024(%rbp)
.L2:
	movl	-100020(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, -100024(%rbp)
	jl	.L5
	movl	-100028(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	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:
