Given the following C code and assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>

int main(void) {

  long n,k;
	scanf("%ld %ld", &n, &k);
  char s[n+1];
  scanf("%s", s);
  char head = s[0];
  long count_other = 0;
  for (long i = 1; i < n; i++) {
    if (s[i-1] == head && s[i] != head) {
      count_other++;
    }
  }
  long happy;
  if (s[n-1] == head) {
    happy = n-1-(count_other)*2;
  } else {
    happy = n-(count_other)*2;
  }
  if (count_other <= k) {
    happy = n-1;
  } else {
    happy += k*2;
  }
  printf("%ld\n", happy);

  return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rsi
	subq	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	movq	%rsp, %rcx
	addq	$16, %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L3
.L19:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L19
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L20
.L4:
	movq	%rsp, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	movq	%rsp, %rbx
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %r8
	movzbl	(%rsp), %edx
	cmpq	$1, %r8
	jle	.L12
	leaq	-1(%r8), %r9
	movq	%rsp, %rax
	xorl	%esi, %esi
	leaq	(%rsp,%r9), %rcx
	.p2align 4,,10
	.p2align 3
.L7:
	cmpb	%dl, (%rax)
	jne	.L6
	xorl	%edi, %edi
	cmpb	%dl, 1(%rax)
	setne	%dil
	addq	%rdi, %rsi
.L6:
	addq	$1, %rax
	cmpq	%rcx, %rax
	jne	.L7
.L5:
	leaq	(%rsi,%rsi), %rax
	movq	%r8, %rcx
	subq	%rax, %rcx
	cmpb	%dl, -1(%rbx,%r8)
	jne	.L9
	movq	%r9, %rcx
	subq	%rax, %rcx
.L9:
	movq	-32(%rbp), %rax
	movl	$1, %edi
	cmpq	%rsi, %rax
	leaq	(%rcx,%rax,2), %rdx
	leaq	.LC2(%rip), %rsi
	cmovge	%r9, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L21
	movq	-8(%rbp), %rbx
	xorl	%eax, %eax
	leave
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L20:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L12:
	xorl	%esi, %esi
	leaq	-1(%r8), %r9
	jmp	.L5
.L21:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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.
Optimized Assembly Code:

user
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rsi
	subq	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	movq	%rsp, %rcx
	addq	$16, %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L3
.L19:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L19
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L20
.L4:
	movq	%rsp, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	movq	%rsp, %rbx
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %r8
	movzbl	(%rsp), %edx
	cmpq	$1, %r8
	jle	.L12
	leaq	-1(%r8), %r9
	movq	%rsp, %rax
	xorl	%esi, %esi
	leaq	(%rsp,%r9), %rcx
	.p2align 4,,10
	.p2align 3
.L7:
	cmpb	%dl, (%rax)
	jne	.L6
	xorl	%edi, %edi
	cmpb	%dl, 1(%rax)
	setne	%dil
	addq	%rdi, %rsi
.L6:
	addq	$1, %rax
	cmpq	%rcx, %rax
	jne	.L7
.L5:
	leaq	(%rsi,%rsi), %rax
	movq	%r8, %rcx
	subq	%rax, %rcx
	cmpb	%dl, -1(%rbx,%r8)
	jne	.L9
	movq	%r9, %rcx
	subq	%rax, %rcx
.L9:
	movq	-32(%rbp), %rax
	movl	$1, %edi
	cmpq	%rsi, %rax
	leaq	(%rcx,%rax,2), %rdx
	leaq	.LC2(%rip), %rsi
	cmovge	%r9, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L21
	movq	-8(%rbp), %rbx
	xorl	%eax, %eax
	leave
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L20:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L12:
	xorl	%esi, %esi
	leaq	-1(%r8), %r9
	jmp	.L5
.L21:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rsi
	subq	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	movq	%rsp, %rcx
	addq	$16, %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L3
.L19:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L19
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L20
.L4:
	movq	%rsp, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	movq	%rsp, %rbx
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %r8
	movzbl	(%rsp), %edx
	cmpq	$1, %r8
	jle	.L12
	leaq	-1(%r8), %r9
	movq	%rsp, %rax
	xorl	%esi, %esi
	leaq	(%rsp,%r9), %rcx
	.p2align 4,,10
	.p2align 3
.L7:
	cmpb	%dl, (%rax)
	jne	.L6
	xorl	%edi, %edi
	cmpb	%dl, 1(%rax)
	setne	%dil
	addq	%rdi, %rsi
.L6:
	addq	$1, %rax
	cmpq	%rcx, %rax
	jne	.L7
.L5:
	leaq	(%rsi,%rsi), %rax
	movq	%r8, %rcx
	subq	%rax, %rcx
	cmpb	%dl, -1(%rbx,%r8)
	jne	.L9
	movq	%r9, %rcx
	subq	%rax, %rcx
.L9:
	movq	-32(%rbp), %rax
	movl	$1, %edi
	cmpq	%rsi, %rax
	leaq	(%rcx,%rax,2), %rdx
	leaq	.LC2(%rip), %rsi
	cmovge	%r9, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L21
	movq	-8(%rbp), %rbx
	xorl	%eax, %eax
	leave
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L20:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L12:
	xorl	%esi, %esi
	leaq	-1(%r8), %r9
	jmp	.L5
.L21:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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:
```
```c
#include <stdio.h>

int main(void) {

  long n,k;
	scanf("%ld %ld", &n, &k);
  char s[n+1];
  scanf("%s", s);
  char head = s[0];
  long count_other = 0;
  for (long i = 1; i < n; i++) {
    if (s[i-1] == head && s[i] != head) {
      count_other++;
    }
  }
  long happy;
  if (s[n-1] == head) {
    happy = n-1-(count_other)*2;
  } else {
    happy = n-(count_other)*2;
  }
  if (count_other <= k) {
    happy = n-1;
  } else {
    happy += k*2;
  }
  printf("%ld\n", happy);

  return 0;
}```
Given the following C code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>

int main(void) {

  long n,k;
	scanf("%ld %ld", &n, &k);
  char s[n+1];
  scanf("%s", s);
  char head = s[0];
  long count_other = 0;
  for (long i = 1; i < n; i++) {
    if (s[i-1] == head && s[i] != head) {
      count_other++;
    }
  }
  long happy;
  if (s[n-1] == head) {
    happy = n-1-(count_other)*2;
  } else {
    happy = n-(count_other)*2;
  }
  if (count_other <= k) {
    happy = n-1;
  } else {
    happy += k*2;
  }
  printf("%ld\n", happy);

  return 0;
}```

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.
Optimized Assembly Code:

6 2
LRLRRL
 9 3
RRRLRLRLL
 9 0
RRRLRLRLL
 6 0
LRRLRL
 9 1
RRRRLLRLL
 9 1
RLRRLLLRR
 6 1
RRLLRL
 10 2
LLLLLRRRRR
 13 4
LRRLRLRRLRLLR
 13 8
LRRLRLRRLRLLR

5
 8
 3
 1
 7
 6
 4
 9
 11
 12

Given the following C code and assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>

int main(void) {

  long n,k;
	scanf("%ld %ld", &n, &k);
  char s[n+1];
  scanf("%s", s);
  char head = s[0];
  long count_other = 0;
  for (long i = 1; i < n; i++) {
    if (s[i-1] == head && s[i] != head) {
      count_other++;
    }
  }
  long happy;
  if (s[n-1] == head) {
    happy = n-1-(count_other)*2;
  } else {
    happy = n-(count_other)*2;
  }
  if (count_other <= k) {
    happy = n-1;
  } else {
    happy += k*2;
  }
  printf("%ld\n", happy);

  return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rsi
	subq	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	movq	%rsp, %rcx
	addq	$16, %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L3
.L19:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L19
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L20
.L4:
	movq	%rsp, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	movq	%rsp, %rbx
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %r8
	movzbl	(%rsp), %edx
	cmpq	$1, %r8
	jle	.L12
	leaq	-1(%r8), %r9
	movq	%rsp, %rax
	xorl	%esi, %esi
	leaq	(%rsp,%r9), %rcx
	.p2align 4,,10
	.p2align 3
.L7:
	cmpb	%dl, (%rax)
	jne	.L6
	xorl	%edi, %edi
	cmpb	%dl, 1(%rax)
	setne	%dil
	addq	%rdi, %rsi
.L6:
	addq	$1, %rax
	cmpq	%rcx, %rax
	jne	.L7
.L5:
	leaq	(%rsi,%rsi), %rax
	movq	%r8, %rcx
	subq	%rax, %rcx
	cmpb	%dl, -1(%rbx,%r8)
	jne	.L9
	movq	%r9, %rcx
	subq	%rax, %rcx
.L9:
	movq	-32(%rbp), %rax
	movl	$1, %edi
	cmpq	%rsi, %rax
	leaq	(%rcx,%rax,2), %rdx
	leaq	.LC2(%rip), %rsi
	cmovge	%r9, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L21
	movq	-8(%rbp), %rbx
	xorl	%eax, %eax
	leave
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L20:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L12:
	xorl	%esi, %esi
	leaq	-1(%r8), %r9
	jmp	.L5
.L21:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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.
Optimized Assembly Code:

train
```assembly
	.file	"temp.c"
	.text
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld %ld"
.LC1:
	.string	"%s"
.LC2:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-32(%rbp), %rdx
	leaq	-40(%rbp), %rsi
	subq	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %rax
	movq	%rsp, %rcx
	addq	$16, %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L3
.L19:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L19
.L3:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L20
.L4:
	movq	%rsp, %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %eax
	movq	%rsp, %rbx
	call	__isoc99_scanf@PLT
	movq	-40(%rbp), %r8
	movzbl	(%rsp), %edx
	cmpq	$1, %r8
	jle	.L12
	leaq	-1(%r8), %r9
	movq	%rsp, %rax
	xorl	%esi, %esi
	leaq	(%rsp,%r9), %rcx
	.p2align 4,,10
	.p2align 3
.L7:
	cmpb	%dl, (%rax)
	jne	.L6
	xorl	%edi, %edi
	cmpb	%dl, 1(%rax)
	setne	%dil
	addq	%rdi, %rsi
.L6:
	addq	$1, %rax
	cmpq	%rcx, %rax
	jne	.L7
.L5:
	leaq	(%rsi,%rsi), %rax
	movq	%r8, %rcx
	subq	%rax, %rcx
	cmpb	%dl, -1(%rbx,%r8)
	jne	.L9
	movq	%r9, %rcx
	subq	%rax, %rcx
.L9:
	movq	-32(%rbp), %rax
	movl	$1, %edi
	cmpq	%rsi, %rax
	leaq	(%rcx,%rax,2), %rdx
	leaq	.LC2(%rip), %rsi
	cmovge	%r9, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	-24(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L21
	movq	-8(%rbp), %rbx
	xorl	%eax, %eax
	leave
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L20:
	.cfi_restore_state
	orq	$0, -8(%rsp,%rdx)
	jmp	.L4
.L12:
	xorl	%esi, %esi
	leaq	-1(%r8), %r9
	jmp	.L5
.L21:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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:
```