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 <stdlib.h>
#include <string.h>
int main(void)
{
    char S[1000]={};
    char S2[2000]={};
    unsigned long K=0;
    unsigned long renzoku=0;
    unsigned long result=0;
    
    scanf("%s",S);
    scanf("%ld",&K);
    int sw=0;
    unsigned long temp_renzoku=0;
    unsigned long renzoku2=0;

    for(unsigned long i=0;i<strlen(S)-1;i++){
        if(S[i]!=S[i+1]){
            sw=1;
            break;
        }
    }
    if(sw==0){
        printf("%ld\n",(strlen(S)*K)/2);
        return 0;
    }
    sw=0;
    for(unsigned long i=0;i<strlen(S)-1;i++){
        if(S[i]==S[i+1]&&sw==0){
            temp_renzoku=2;
            sw=1;
            if(i+1==strlen(S)-1){
                renzoku+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
            
        }
        else if(S[i]==S[i+1]&&sw==1){
            temp_renzoku+=1;
            if(i+1==strlen(S)-1){
                renzoku+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
        }
        else{
            renzoku+=temp_renzoku/2;
            temp_renzoku=0;
            sw=0;
        }
    }
    // printf("%ld\n",renzoku);
    sprintf(S2,"%s%s",S,S);
    
    for(unsigned long i=0;i<strlen(S2)-1;i++){
        if(S2[i]==S2[i+1]&&sw==0){
            temp_renzoku=2;
            sw=1;
            if(i+1==strlen(S2)-1){
                renzoku2+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
            
        }
        else if(S2[i]==S2[i+1]&&sw==1){
            temp_renzoku+=1;
            if(i+1==strlen(S2)-1){
                renzoku2+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
        }
        else{
            renzoku2+=temp_renzoku/2;
            temp_renzoku=0;
            sw=0;
        }
    }
    //printf("%ld %ld\n",renzoku,renzoku2);
    result=renzoku+(renzoku2-renzoku)*(K-1);
    printf("%ld\n",result);
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
.LC3:
	.string	"%s%s"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$3112, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	movq	$0, -3040(%rbp)
	movq	$0, -3032(%rbp)
	leaq	-3024(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	$0, -2032(%rbp)
	movq	$0, -2024(%rbp)
	leaq	-2016(%rbp), %rdx
	movl	$0, %eax
	movl	$248, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	$0, -3104(%rbp)
	movq	$0, -3096(%rbp)
	movq	$0, -3048(%rbp)
	leaq	-3040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-3104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -3108(%rbp)
	movq	$0, -3088(%rbp)
	movq	$0, -3080(%rbp)
	movq	$0, -3072(%rbp)
	jmp	.L2
.L5:
	leaq	-3040(%rbp), %rdx
	movq	-3072(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3072(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	je	.L3
	movl	$1, -3108(%rbp)
	jmp	.L4
.L3:
	addq	$1, -3072(%rbp)
.L2:
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3072(%rbp)
	jb	.L5
.L4:
	cmpl	$0, -3108(%rbp)
	jne	.L6
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movq	-3104(%rbp), %rdx
	imulq	%rdx, %rax
	shrq	%rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L22
.L6:
	movl	$0, -3108(%rbp)
	movq	$0, -3064(%rbp)
	jmp	.L8
.L14:
	leaq	-3040(%rbp), %rdx
	movq	-3064(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3064(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L9
	cmpl	$0, -3108(%rbp)
	jne	.L9
	movq	$2, -3088(%rbp)
	movl	$1, -3108(%rbp)
	movq	-3064(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L11
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L11
.L9:
	leaq	-3040(%rbp), %rdx
	movq	-3064(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3064(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L12
	cmpl	$1, -3108(%rbp)
	jne	.L12
	addq	$1, -3088(%rbp)
	movq	-3064(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L11
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L11
.L12:
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
.L11:
	addq	$1, -3064(%rbp)
.L8:
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3064(%rbp)
	jb	.L14
	leaq	-3040(%rbp), %rcx
	leaq	-3040(%rbp), %rdx
	leaq	-2032(%rbp), %rax
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	sprintf@PLT
	movq	$0, -3056(%rbp)
	jmp	.L15
.L21:
	leaq	-2032(%rbp), %rdx
	movq	-3056(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3056(%rbp), %rax
	addq	$1, %rax
	movzbl	-2032(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L16
	cmpl	$0, -3108(%rbp)
	jne	.L16
	movq	$2, -3088(%rbp)
	movl	$1, -3108(%rbp)
	movq	-3056(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L18
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L18
.L16:
	leaq	-2032(%rbp), %rdx
	movq	-3056(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3056(%rbp), %rax
	addq	$1, %rax
	movzbl	-2032(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L19
	cmpl	$1, -3108(%rbp)
	jne	.L19
	addq	$1, -3088(%rbp)
	movq	-3056(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L18
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L18
.L19:
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
.L18:
	addq	$1, -3056(%rbp)
.L15:
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3056(%rbp)
	jb	.L21
	movq	-3080(%rbp), %rax
	subq	-3096(%rbp), %rax
	movq	-3104(%rbp), %rdx
	subq	$1, %rdx
	imulq	%rax, %rdx
	movq	-3096(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -3048(%rbp)
	movq	-3048(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L22:
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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	"%ld"
.LC2:
	.string	"%s%s"
.LC3:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$123, %ecx
	pxor	%xmm0, %xmm0
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$3040, %rsp
	.cfi_def_cfa_offset 3072
	movq	%fs:40, %rax
	movq	%rax, 3032(%rsp)
	xorl	%eax, %eax
	leaq	32(%rsp), %rdi
	leaq	16(%rsp), %rbp
	movaps	%xmm0, 16(%rsp)
	movq	%rbp, %rsi
	movaps	%xmm0, 1024(%rsp)
	movq	$0, 8(%rsp)
	rep stosq
	leaq	1040(%rsp), %rdi
	movl	$248, %ecx
	rep stosq
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	leaq	8(%rsp), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	%rbp, %rdi
	call	strlen@PLT
	movzbl	16(%rsp), %esi
	leaq	17(%rsp), %rcx
	leaq	-1(%rax), %r9
	leaq	0(%rbp,%rax), %r8
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L4:
	movzbl	(%rcx), %edi
	addq	$1, %rcx
	cmpb	%sil, %dil
	jne	.L21
.L2:
	cmpq	%r8, %rcx
	jne	.L4
	imulq	8(%rsp), %rax
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	shrq	%rax
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L17:
	movq	3032(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	addq	$3040, %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
.L21:
	.cfi_restore_state
	xorl	%eax, %eax
	xorl	%edx, %edx
	xorl	%edi, %edi
	xorl	%ebx, %ebx
	addq	$1, %rax
	movzbl	0(%rbp,%rax), %ecx
	cmpb	%sil, %cl
	je	.L30
	.p2align 4,,10
	.p2align 3
.L6:
	shrq	%rdx
	addq	%rdx, %rbx
	cmpq	%rax, %r9
	je	.L10
	xorl	%edx, %edx
	xorl	%edi, %edi
	movl	%ecx, %esi
.L33:
	addq	$1, %rax
	movzbl	0(%rbp,%rax), %ecx
	cmpb	%sil, %cl
	jne	.L6
.L30:
	testl	%edi, %edi
	je	.L31
	addq	$1, %rdx
	cmpq	%rax, %r9
	je	.L32
.L8:
	movl	$1, %edi
	movl	%ecx, %esi
	jmp	.L33
	.p2align 4,,10
	.p2align 3
.L31:
	cmpq	%rax, %r9
	je	.L34
	movl	$2, %edx
	jmp	.L8
.L34:
	addq	$1, %rbx
.L10:
	leaq	1024(%rsp), %r12
	xorl	%eax, %eax
	movq	%rbp, %r9
	movq	%rbp, %r8
	movq	%r12, %rdi
	movl	$2000, %edx
	movl	$1, %esi
	leaq	.LC2(%rip), %rcx
	call	__sprintf_chk@PLT
	movq	%r12, %rdi
	call	strlen@PLT
	subq	$1, %rax
	je	.L23
	movzbl	1024(%rsp), %r8d
	xorl	%edx, %edx
	xorl	%edi, %edi
	xorl	%ecx, %ecx
	xorl	%r9d, %r9d
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L12:
	shrq	%rcx
	addq	%rcx, %rdi
	cmpq	%rax, %rdx
	je	.L11
	xorl	%r9d, %r9d
	xorl	%ecx, %ecx
.L18:
	movl	%esi, %r8d
.L16:
	addq	$1, %rdx
	movzbl	(%r12,%rdx), %esi
	cmpb	%r8b, %sil
	jne	.L12
	testl	%r9d, %r9d
	je	.L35
	addq	$1, %rcx
	cmpq	%rax, %rdx
	je	.L36
.L14:
	movl	$1, %r9d
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L35:
	cmpq	%rax, %rdx
	je	.L37
	movl	$2, %ecx
	jmp	.L14
.L37:
	addq	$1, %rdi
.L11:
	movq	8(%rsp), %rax
	subq	%rbx, %rdi
	leaq	.LC3(%rip), %rsi
	leaq	-1(%rax), %rdx
	xorl	%eax, %eax
	imulq	%rdi, %rdx
	movl	$1, %edi
	addq	%rbx, %rdx
	call	__printf_chk@PLT
	jmp	.L17
.L36:
	shrq	%rcx
	addq	%rcx, %rdi
	jmp	.L11
.L32:
	shrq	%rdx
	addq	%rdx, %rbx
	jmp	.L10
.L23:
	xorl	%edi, %edi
	jmp	.L11
.L29:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.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	"%ld"
.LC2:
	.string	"%s%s"
.LC3:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB51:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$123, %ecx
	pxor	%xmm0, %xmm0
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$3040, %rsp
	.cfi_def_cfa_offset 3072
	movq	%fs:40, %rax
	movq	%rax, 3032(%rsp)
	xorl	%eax, %eax
	leaq	32(%rsp), %rdi
	leaq	16(%rsp), %rbp
	movaps	%xmm0, 16(%rsp)
	movq	%rbp, %rsi
	movaps	%xmm0, 1024(%rsp)
	movq	$0, 8(%rsp)
	rep stosq
	leaq	1040(%rsp), %rdi
	movl	$248, %ecx
	rep stosq
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	leaq	8(%rsp), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	%rbp, %rdi
	call	strlen@PLT
	movzbl	16(%rsp), %esi
	leaq	17(%rsp), %rcx
	leaq	-1(%rax), %r9
	leaq	0(%rbp,%rax), %r8
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L4:
	movzbl	(%rcx), %edi
	addq	$1, %rcx
	cmpb	%sil, %dil
	jne	.L21
.L2:
	cmpq	%r8, %rcx
	jne	.L4
	imulq	8(%rsp), %rax
	leaq	.LC3(%rip), %rsi
	movl	$1, %edi
	shrq	%rax
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L17:
	movq	3032(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	addq	$3040, %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
.L21:
	.cfi_restore_state
	xorl	%eax, %eax
	xorl	%edx, %edx
	xorl	%edi, %edi
	xorl	%ebx, %ebx
	addq	$1, %rax
	movzbl	0(%rbp,%rax), %ecx
	cmpb	%sil, %cl
	je	.L30
	.p2align 4,,10
	.p2align 3
.L6:
	shrq	%rdx
	addq	%rdx, %rbx
	cmpq	%rax, %r9
	je	.L10
	xorl	%edx, %edx
	xorl	%edi, %edi
	movl	%ecx, %esi
.L33:
	addq	$1, %rax
	movzbl	0(%rbp,%rax), %ecx
	cmpb	%sil, %cl
	jne	.L6
.L30:
	testl	%edi, %edi
	je	.L31
	addq	$1, %rdx
	cmpq	%rax, %r9
	je	.L32
.L8:
	movl	$1, %edi
	movl	%ecx, %esi
	jmp	.L33
	.p2align 4,,10
	.p2align 3
.L31:
	cmpq	%rax, %r9
	je	.L34
	movl	$2, %edx
	jmp	.L8
.L34:
	addq	$1, %rbx
.L10:
	leaq	1024(%rsp), %r12
	xorl	%eax, %eax
	movq	%rbp, %r9
	movq	%rbp, %r8
	movq	%r12, %rdi
	movl	$2000, %edx
	movl	$1, %esi
	leaq	.LC2(%rip), %rcx
	call	__sprintf_chk@PLT
	movq	%r12, %rdi
	call	strlen@PLT
	subq	$1, %rax
	je	.L23
	movzbl	1024(%rsp), %r8d
	xorl	%edx, %edx
	xorl	%edi, %edi
	xorl	%ecx, %ecx
	xorl	%r9d, %r9d
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L12:
	shrq	%rcx
	addq	%rcx, %rdi
	cmpq	%rax, %rdx
	je	.L11
	xorl	%r9d, %r9d
	xorl	%ecx, %ecx
.L18:
	movl	%esi, %r8d
.L16:
	addq	$1, %rdx
	movzbl	(%r12,%rdx), %esi
	cmpb	%r8b, %sil
	jne	.L12
	testl	%r9d, %r9d
	je	.L35
	addq	$1, %rcx
	cmpq	%rax, %rdx
	je	.L36
.L14:
	movl	$1, %r9d
	jmp	.L18
	.p2align 4,,10
	.p2align 3
.L35:
	cmpq	%rax, %rdx
	je	.L37
	movl	$2, %ecx
	jmp	.L14
.L37:
	addq	$1, %rdi
.L11:
	movq	8(%rsp), %rax
	subq	%rbx, %rdi
	leaq	.LC3(%rip), %rsi
	leaq	-1(%rax), %rdx
	xorl	%eax, %eax
	imulq	%rdi, %rdx
	movl	$1, %edi
	addq	%rbx, %rdx
	call	__printf_chk@PLT
	jmp	.L17
.L36:
	shrq	%rcx
	addq	%rcx, %rdi
	jmp	.L11
.L32:
	shrq	%rdx
	addq	%rdx, %rbx
	jmp	.L10
.L23:
	xorl	%edi, %edi
	jmp	.L11
.L29:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.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 <stdlib.h>
#include <string.h>
int main(void)
{
    char S[1000]={};
    char S2[2000]={};
    unsigned long K=0;
    unsigned long renzoku=0;
    unsigned long result=0;
    
    scanf("%s",S);
    scanf("%ld",&K);
    int sw=0;
    unsigned long temp_renzoku=0;
    unsigned long renzoku2=0;

    for(unsigned long i=0;i<strlen(S)-1;i++){
        if(S[i]!=S[i+1]){
            sw=1;
            break;
        }
    }
    if(sw==0){
        printf("%ld\n",(strlen(S)*K)/2);
        return 0;
    }
    sw=0;
    for(unsigned long i=0;i<strlen(S)-1;i++){
        if(S[i]==S[i+1]&&sw==0){
            temp_renzoku=2;
            sw=1;
            if(i+1==strlen(S)-1){
                renzoku+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
            
        }
        else if(S[i]==S[i+1]&&sw==1){
            temp_renzoku+=1;
            if(i+1==strlen(S)-1){
                renzoku+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
        }
        else{
            renzoku+=temp_renzoku/2;
            temp_renzoku=0;
            sw=0;
        }
    }
    // printf("%ld\n",renzoku);
    sprintf(S2,"%s%s",S,S);
    
    for(unsigned long i=0;i<strlen(S2)-1;i++){
        if(S2[i]==S2[i+1]&&sw==0){
            temp_renzoku=2;
            sw=1;
            if(i+1==strlen(S2)-1){
                renzoku2+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
            
        }
        else if(S2[i]==S2[i+1]&&sw==1){
            temp_renzoku+=1;
            if(i+1==strlen(S2)-1){
                renzoku2+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
        }
        else{
            renzoku2+=temp_renzoku/2;
            temp_renzoku=0;
            sw=0;
        }
    }
    //printf("%ld %ld\n",renzoku,renzoku2);
    result=renzoku+(renzoku2-renzoku)*(K-1);
    printf("%ld\n",result);
    return 0;
}
cooooooooonteeeeeeeedest
999993333
 issih
2
 rq
81
 hssih
2
 cooooooooonteeeeeeeedest
1894324309
 hssih
3
 hssih
6
 tsedeeeeeeeetnoooooonooc
54816478
 tsedeeeeeeeetnoooooonooc
93364260
 rr
552

7999946664
 2
 0
 3
 15154594472
 5
 11
 438531824
 746914080
 552

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 <stdlib.h>
#include <string.h>
int main(void)
{
    char S[1000]={};
    char S2[2000]={};
    unsigned long K=0;
    unsigned long renzoku=0;
    unsigned long result=0;
    
    scanf("%s",S);
    scanf("%ld",&K);
    int sw=0;
    unsigned long temp_renzoku=0;
    unsigned long renzoku2=0;

    for(unsigned long i=0;i<strlen(S)-1;i++){
        if(S[i]!=S[i+1]){
            sw=1;
            break;
        }
    }
    if(sw==0){
        printf("%ld\n",(strlen(S)*K)/2);
        return 0;
    }
    sw=0;
    for(unsigned long i=0;i<strlen(S)-1;i++){
        if(S[i]==S[i+1]&&sw==0){
            temp_renzoku=2;
            sw=1;
            if(i+1==strlen(S)-1){
                renzoku+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
            
        }
        else if(S[i]==S[i+1]&&sw==1){
            temp_renzoku+=1;
            if(i+1==strlen(S)-1){
                renzoku+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
        }
        else{
            renzoku+=temp_renzoku/2;
            temp_renzoku=0;
            sw=0;
        }
    }
    // printf("%ld\n",renzoku);
    sprintf(S2,"%s%s",S,S);
    
    for(unsigned long i=0;i<strlen(S2)-1;i++){
        if(S2[i]==S2[i+1]&&sw==0){
            temp_renzoku=2;
            sw=1;
            if(i+1==strlen(S2)-1){
                renzoku2+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
            
        }
        else if(S2[i]==S2[i+1]&&sw==1){
            temp_renzoku+=1;
            if(i+1==strlen(S2)-1){
                renzoku2+=temp_renzoku/2;
                temp_renzoku=0;
                sw=0;
            }
        }
        else{
            renzoku2+=temp_renzoku/2;
            temp_renzoku=0;
            sw=0;
        }
    }
    //printf("%ld %ld\n",renzoku,renzoku2);
    result=renzoku+(renzoku2-renzoku)*(K-1);
    printf("%ld\n",result);
    return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"%ld"
.LC2:
	.string	"%ld\n"
.LC3:
	.string	"%s%s"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$3112, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	movq	$0, -3040(%rbp)
	movq	$0, -3032(%rbp)
	leaq	-3024(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	$0, -2032(%rbp)
	movq	$0, -2024(%rbp)
	leaq	-2016(%rbp), %rdx
	movl	$0, %eax
	movl	$248, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	$0, -3104(%rbp)
	movq	$0, -3096(%rbp)
	movq	$0, -3048(%rbp)
	leaq	-3040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-3104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -3108(%rbp)
	movq	$0, -3088(%rbp)
	movq	$0, -3080(%rbp)
	movq	$0, -3072(%rbp)
	jmp	.L2
.L5:
	leaq	-3040(%rbp), %rdx
	movq	-3072(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3072(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	je	.L3
	movl	$1, -3108(%rbp)
	jmp	.L4
.L3:
	addq	$1, -3072(%rbp)
.L2:
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3072(%rbp)
	jb	.L5
.L4:
	cmpl	$0, -3108(%rbp)
	jne	.L6
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movq	-3104(%rbp), %rdx
	imulq	%rdx, %rax
	shrq	%rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L22
.L6:
	movl	$0, -3108(%rbp)
	movq	$0, -3064(%rbp)
	jmp	.L8
.L14:
	leaq	-3040(%rbp), %rdx
	movq	-3064(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3064(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L9
	cmpl	$0, -3108(%rbp)
	jne	.L9
	movq	$2, -3088(%rbp)
	movl	$1, -3108(%rbp)
	movq	-3064(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L11
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L11
.L9:
	leaq	-3040(%rbp), %rdx
	movq	-3064(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3064(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L12
	cmpl	$1, -3108(%rbp)
	jne	.L12
	addq	$1, -3088(%rbp)
	movq	-3064(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L11
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L11
.L12:
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
.L11:
	addq	$1, -3064(%rbp)
.L8:
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3064(%rbp)
	jb	.L14
	leaq	-3040(%rbp), %rcx
	leaq	-3040(%rbp), %rdx
	leaq	-2032(%rbp), %rax
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	sprintf@PLT
	movq	$0, -3056(%rbp)
	jmp	.L15
.L21:
	leaq	-2032(%rbp), %rdx
	movq	-3056(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3056(%rbp), %rax
	addq	$1, %rax
	movzbl	-2032(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L16
	cmpl	$0, -3108(%rbp)
	jne	.L16
	movq	$2, -3088(%rbp)
	movl	$1, -3108(%rbp)
	movq	-3056(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L18
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L18
.L16:
	leaq	-2032(%rbp), %rdx
	movq	-3056(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3056(%rbp), %rax
	addq	$1, %rax
	movzbl	-2032(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L19
	cmpl	$1, -3108(%rbp)
	jne	.L19
	addq	$1, -3088(%rbp)
	movq	-3056(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L18
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L18
.L19:
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
.L18:
	addq	$1, -3056(%rbp)
.L15:
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3056(%rbp)
	jb	.L21
	movq	-3080(%rbp), %rax
	subq	-3096(%rbp), %rax
	movq	-3104(%rbp), %rdx
	subq	$1, %rdx
	imulq	%rax, %rdx
	movq	-3096(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -3048(%rbp)
	movq	-3048(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L22:
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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	"%ld"
.LC2:
	.string	"%ld\n"
.LC3:
	.string	"%s%s"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	subq	$3112, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	movq	$0, -3040(%rbp)
	movq	$0, -3032(%rbp)
	leaq	-3024(%rbp), %rdx
	movl	$0, %eax
	movl	$123, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	$0, -2032(%rbp)
	movq	$0, -2024(%rbp)
	leaq	-2016(%rbp), %rdx
	movl	$0, %eax
	movl	$248, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	$0, -3104(%rbp)
	movq	$0, -3096(%rbp)
	movq	$0, -3048(%rbp)
	leaq	-3040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-3104(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -3108(%rbp)
	movq	$0, -3088(%rbp)
	movq	$0, -3080(%rbp)
	movq	$0, -3072(%rbp)
	jmp	.L2
.L5:
	leaq	-3040(%rbp), %rdx
	movq	-3072(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3072(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	je	.L3
	movl	$1, -3108(%rbp)
	jmp	.L4
.L3:
	addq	$1, -3072(%rbp)
.L2:
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3072(%rbp)
	jb	.L5
.L4:
	cmpl	$0, -3108(%rbp)
	jne	.L6
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	movq	-3104(%rbp), %rdx
	imulq	%rdx, %rax
	shrq	%rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	jmp	.L22
.L6:
	movl	$0, -3108(%rbp)
	movq	$0, -3064(%rbp)
	jmp	.L8
.L14:
	leaq	-3040(%rbp), %rdx
	movq	-3064(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3064(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L9
	cmpl	$0, -3108(%rbp)
	jne	.L9
	movq	$2, -3088(%rbp)
	movl	$1, -3108(%rbp)
	movq	-3064(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L11
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L11
.L9:
	leaq	-3040(%rbp), %rdx
	movq	-3064(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3064(%rbp), %rax
	addq	$1, %rax
	movzbl	-3040(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L12
	cmpl	$1, -3108(%rbp)
	jne	.L12
	addq	$1, -3088(%rbp)
	movq	-3064(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L11
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L11
.L12:
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3096(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
.L11:
	addq	$1, -3064(%rbp)
.L8:
	leaq	-3040(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3064(%rbp)
	jb	.L14
	leaq	-3040(%rbp), %rcx
	leaq	-3040(%rbp), %rdx
	leaq	-2032(%rbp), %rax
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	movl	$0, %eax
	call	sprintf@PLT
	movq	$0, -3056(%rbp)
	jmp	.L15
.L21:
	leaq	-2032(%rbp), %rdx
	movq	-3056(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3056(%rbp), %rax
	addq	$1, %rax
	movzbl	-2032(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L16
	cmpl	$0, -3108(%rbp)
	jne	.L16
	movq	$2, -3088(%rbp)
	movl	$1, -3108(%rbp)
	movq	-3056(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L18
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L18
.L16:
	leaq	-2032(%rbp), %rdx
	movq	-3056(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %edx
	movq	-3056(%rbp), %rax
	addq	$1, %rax
	movzbl	-2032(%rbp,%rax), %eax
	cmpb	%al, %dl
	jne	.L19
	cmpl	$1, -3108(%rbp)
	jne	.L19
	addq	$1, -3088(%rbp)
	movq	-3056(%rbp), %rax
	leaq	1(%rax), %rbx
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, %rbx
	jne	.L18
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
	jmp	.L18
.L19:
	movq	-3088(%rbp), %rax
	shrq	%rax
	addq	%rax, -3080(%rbp)
	movq	$0, -3088(%rbp)
	movl	$0, -3108(%rbp)
.L18:
	addq	$1, -3056(%rbp)
.L15:
	leaq	-2032(%rbp), %rax
	movq	%rax, %rdi
	call	strlen@PLT
	subq	$1, %rax
	cmpq	%rax, -3056(%rbp)
	jb	.L21
	movq	-3080(%rbp), %rax
	subq	-3096(%rbp), %rax
	movq	-3104(%rbp), %rdx
	subq	$1, %rdx
	imulq	%rax, %rdx
	movq	-3096(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, -3048(%rbp)
	movq	-3048(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
.L22:
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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:
