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>
typedef long long ll;

ll n;
char str[100005];

ll win, lose;
ll g, p;

int main()
{
	scanf("%s", str);

	n = strlen(str);
	for (ll i = 0; i < n; i++) {
		if (g == p) {
			g++;

			if (str[i] == 'p') {
				lose++;
			}

		} else {
			p++;

			if (str[i] == 'g') {
				win++;
			}
		}
	}

	printf("%lld\n", win - lose);

	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	str
	.align 32
	.type	str, @object
	.size	str, 100005
str:
	.zero	100005
	.globl	win
	.align 8
	.type	win, @object
	.size	win, 8
win:
	.zero	8
	.globl	lose
	.align 8
	.type	lose, @object
	.size	lose, 8
lose:
	.zero	8
	.globl	g
	.align 8
	.type	g, @object
	.size	g, 8
g:
	.zero	8
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"%lld\n"
	.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	$16, %rsp
	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, %rdi
	call	strlen@PLT
	movq	%rax, n(%rip)
	movq	$0, -8(%rbp)
	jmp	.L2
.L5:
	movq	g(%rip), %rdx
	movq	p(%rip), %rax
	cmpq	%rax, %rdx
	jne	.L3
	movq	g(%rip), %rax
	addq	$1, %rax
	movq	%rax, g(%rip)
	leaq	str(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$112, %al
	jne	.L4
	movq	lose(%rip), %rax
	addq	$1, %rax
	movq	%rax, lose(%rip)
	jmp	.L4
.L3:
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	leaq	str(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$103, %al
	jne	.L4
	movq	win(%rip), %rax
	addq	$1, %rax
	movq	%rax, win(%rip)
.L4:
	addq	$1, -8(%rbp)
.L2:
	movq	n(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jl	.L5
	movq	win(%rip), %rax
	movq	lose(%rip), %rdx
	subq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	str(%rip), %rbx
	movq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movq	%rbx, %rdi
	call	strlen@PLT
	movq	win(%rip), %rdx
	movq	%rax, n(%rip)
	testq	%rax, %rax
	je	.L3
	movq	win(%rip), %rdx
	movq	%rbx, %rcx
	addq	%rbx, %rax
	xorl	%r12d, %r12d
	movq	g(%rip), %r8
	xorl	%ebx, %ebx
	xorl	%r9d, %r9d
	xorl	%r11d, %r11d
	movq	p(%rip), %rsi
	movq	lose(%rip), %rbp
	movq	%rdx, %r10
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	addq	$1, %rsi
	movl	$1, %r9d
	cmpb	$103, %dil
	jne	.L5
	addq	$1, %r10
	movl	$1, %ebx
.L5:
	addq	$1, %rcx
	cmpq	%rcx, %rax
	je	.L28
.L6:
	movzbl	(%rcx), %edi
	cmpq	%rsi, %r8
	jne	.L4
	addq	$1, %r8
	movl	$1, %r11d
	cmpb	$112, %dil
	jne	.L5
	addq	$1, %rcx
	addq	$1, %rbp
	movl	$1, %r12d
	cmpq	%rcx, %rax
	jne	.L6
	.p2align 4,,10
	.p2align 3
.L28:
	testb	%bl, %bl
	je	.L7
	movq	%r10, win(%rip)
	movq	%r10, %rdx
.L7:
	testb	%r12b, %r12b
	je	.L8
	movq	%rbp, lose(%rip)
.L8:
	testb	%r9b, %r9b
	je	.L9
	movq	%rsi, p(%rip)
.L9:
	testb	%r11b, %r11b
	je	.L3
	movq	%r8, g(%rip)
.L3:
	subq	lose(%rip), %rdx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.globl	g
	.align 8
	.type	g, @object
	.size	g, 8
g:
	.zero	8
	.globl	lose
	.align 8
	.type	lose, @object
	.size	lose, 8
lose:
	.zero	8
	.globl	win
	.align 8
	.type	win, @object
	.size	win, 8
win:
	.zero	8
	.globl	str
	.align 32
	.type	str, @object
	.size	str, 100005
str:
	.zero	100005
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.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	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	str(%rip), %rbx
	movq	%rbx, %rsi
	call	__isoc99_scanf@PLT
	movq	%rbx, %rdi
	call	strlen@PLT
	movq	win(%rip), %rdx
	movq	%rax, n(%rip)
	testq	%rax, %rax
	je	.L3
	movq	win(%rip), %rdx
	movq	%rbx, %rcx
	addq	%rbx, %rax
	xorl	%r12d, %r12d
	movq	g(%rip), %r8
	xorl	%ebx, %ebx
	xorl	%r9d, %r9d
	xorl	%r11d, %r11d
	movq	p(%rip), %rsi
	movq	lose(%rip), %rbp
	movq	%rdx, %r10
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	addq	$1, %rsi
	movl	$1, %r9d
	cmpb	$103, %dil
	jne	.L5
	addq	$1, %r10
	movl	$1, %ebx
.L5:
	addq	$1, %rcx
	cmpq	%rcx, %rax
	je	.L28
.L6:
	movzbl	(%rcx), %edi
	cmpq	%rsi, %r8
	jne	.L4
	addq	$1, %r8
	movl	$1, %r11d
	cmpb	$112, %dil
	jne	.L5
	addq	$1, %rcx
	addq	$1, %rbp
	movl	$1, %r12d
	cmpq	%rcx, %rax
	jne	.L6
	.p2align 4,,10
	.p2align 3
.L28:
	testb	%bl, %bl
	je	.L7
	movq	%r10, win(%rip)
	movq	%r10, %rdx
.L7:
	testb	%r12b, %r12b
	je	.L8
	movq	%rbp, lose(%rip)
.L8:
	testb	%r9b, %r9b
	je	.L9
	movq	%rsi, p(%rip)
.L9:
	testb	%r11b, %r11b
	je	.L3
	movq	%r8, g(%rip)
.L3:
	subq	lose(%rip), %rdx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.globl	p
	.bss
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.globl	g
	.align 8
	.type	g, @object
	.size	g, 8
g:
	.zero	8
	.globl	lose
	.align 8
	.type	lose, @object
	.size	lose, 8
lose:
	.zero	8
	.globl	win
	.align 8
	.type	win, @object
	.size	win, 8
win:
	.zero	8
	.globl	str
	.align 32
	.type	str, @object
	.size	str, 100005
str:
	.zero	100005
	.globl	n
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.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>
typedef long long ll;

ll n;
char str[100005];

ll win, lose;
ll g, p;

int main()
{
	scanf("%s", str);

	n = strlen(str);
	for (ll i = 0; i < n; i++) {
		if (g == p) {
			g++;

			if (str[i] == 'p') {
				lose++;
			}

		} else {
			p++;

			if (str[i] == 'g') {
				win++;
			}
		}
	}

	printf("%lld\n", win - lose);

	return 0;
}

gpg

0

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>
typedef long long ll;

ll n;
char str[100005];

ll win, lose;
ll g, p;

int main()
{
	scanf("%s", str);

	n = strlen(str);
	for (ll i = 0; i < n; i++) {
		if (g == p) {
			g++;

			if (str[i] == 'p') {
				lose++;
			}

		} else {
			p++;

			if (str[i] == 'g') {
				win++;
			}
		}
	}

	printf("%lld\n", win - lose);

	return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	str
	.align 32
	.type	str, @object
	.size	str, 100005
str:
	.zero	100005
	.globl	win
	.align 8
	.type	win, @object
	.size	win, 8
win:
	.zero	8
	.globl	lose
	.align 8
	.type	lose, @object
	.size	lose, 8
lose:
	.zero	8
	.globl	g
	.align 8
	.type	g, @object
	.size	g, 8
g:
	.zero	8
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"%lld\n"
	.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	$16, %rsp
	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, %rdi
	call	strlen@PLT
	movq	%rax, n(%rip)
	movq	$0, -8(%rbp)
	jmp	.L2
.L5:
	movq	g(%rip), %rdx
	movq	p(%rip), %rax
	cmpq	%rax, %rdx
	jne	.L3
	movq	g(%rip), %rax
	addq	$1, %rax
	movq	%rax, g(%rip)
	leaq	str(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$112, %al
	jne	.L4
	movq	lose(%rip), %rax
	addq	$1, %rax
	movq	%rax, lose(%rip)
	jmp	.L4
.L3:
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	leaq	str(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$103, %al
	jne	.L4
	movq	win(%rip), %rax
	addq	$1, %rax
	movq	%rax, win(%rip)
.L4:
	addq	$1, -8(%rbp)
.L2:
	movq	n(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jl	.L5
	movq	win(%rip), %rax
	movq	lose(%rip), %rdx
	subq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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	n
	.bss
	.align 8
	.type	n, @object
	.size	n, 8
n:
	.zero	8
	.globl	str
	.align 32
	.type	str, @object
	.size	str, 100005
str:
	.zero	100005
	.globl	win
	.align 8
	.type	win, @object
	.size	win, 8
win:
	.zero	8
	.globl	lose
	.align 8
	.type	lose, @object
	.size	lose, 8
lose:
	.zero	8
	.globl	g
	.align 8
	.type	g, @object
	.size	g, 8
g:
	.zero	8
	.globl	p
	.align 8
	.type	p, @object
	.size	p, 8
p:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%s"
.LC1:
	.string	"%lld\n"
	.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	$16, %rsp
	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, %rdi
	call	strlen@PLT
	movq	%rax, n(%rip)
	movq	$0, -8(%rbp)
	jmp	.L2
.L5:
	movq	g(%rip), %rdx
	movq	p(%rip), %rax
	cmpq	%rax, %rdx
	jne	.L3
	movq	g(%rip), %rax
	addq	$1, %rax
	movq	%rax, g(%rip)
	leaq	str(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$112, %al
	jne	.L4
	movq	lose(%rip), %rax
	addq	$1, %rax
	movq	%rax, lose(%rip)
	jmp	.L4
.L3:
	movq	p(%rip), %rax
	addq	$1, %rax
	movq	%rax, p(%rip)
	leaq	str(%rip), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	cmpb	$103, %al
	jne	.L4
	movq	win(%rip), %rax
	addq	$1, %rax
	movq	%rax, win(%rip)
.L4:
	addq	$1, -8(%rbp)
.L2:
	movq	n(%rip), %rax
	cmpq	%rax, -8(%rbp)
	jl	.L5
	movq	win(%rip), %rax
	movq	lose(%rip), %rdx
	subq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	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:
