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>

#define rep(i, N) for (int i = 0; i < N; i++)

//int dxy[5] = {0, 1, 0, -1, 0};
// 01Trie BIT CHT DFT FFT avl cmd cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination ppuf segtree st tmp topcoder uf vi 

//最大公約数
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int ans[1000];
int ptr, a;

int solve(int p, int q, int denom, int max_denom, int n)
{
    if (!p || !n) return 0;
    int ret = 0;
    for (int i = max_denom; i * denom <= a; i++) {
        if (p * i < q) continue;
        //int tmp = lcm(i, q);
        int tmp = i * q;
        int s = p * (tmp/q) - tmp / i;
        ret += !s;
        ret += solve(s, tmp, denom * i, i, n-1);
    }
    return ret;
}

signed main()
{
    int p, q, n;
    while (1) {
        scanf("%d %d %d %d", &p, &q, &a, &n);
        if (!q) break;
        ans[ptr++] = solve(p, q, 1, 1, n);
    }

    for (int i = 0; i < ptr; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	gcd
	.type	gcd, @function
gcd:
.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
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	cmpl	$0, -8(%rbp)
	je	.L2
	movl	-4(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	-8(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	jmp	.L4
.L2:
	movl	-4(%rbp), %eax
.L4:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	gcd, .-gcd
	.globl	lcm
	.type	lcm, @function
lcm:
.LFB1:
	.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
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, %ecx
	movl	-4(%rbp), %eax
	cltd
	idivl	%ecx
	imull	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	lcm, .-lcm
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 4000
ans:
	.zero	4000
	.globl	ptr
	.align 4
	.type	ptr, @object
	.size	ptr, 4
ptr:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	cmpl	$0, -20(%rbp)
	je	.L8
	cmpl	$0, -36(%rbp)
	jne	.L9
.L8:
	movl	$0, %eax
	jmp	.L10
.L9:
	movl	$0, -16(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L11
.L14:
	movl	-20(%rbp), %eax
	imull	-12(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jg	.L15
	movl	-12(%rbp), %eax
	imull	-24(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	imull	-20(%rbp), %eax
	movl	%eax, %ecx
	movl	-8(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	movl	%eax, %edx
	movl	%ecx, %eax
	subl	%edx, %eax
	movl	%eax, -4(%rbp)
	cmpl	$0, -4(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, -16(%rbp)
	movl	-36(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-28(%rbp), %eax
	imull	-12(%rbp), %eax
	movl	%eax, %edx
	movl	-12(%rbp), %ecx
	movl	-8(%rbp), %esi
	movl	-4(%rbp), %eax
	movl	%edi, %r8d
	movl	%eax, %edi
	call	solve
	addl	%eax, -16(%rbp)
	jmp	.L13
.L15:
	nop
.L13:
	addl	$1, -12(%rbp)
.L11:
	movl	-12(%rbp), %eax
	imull	-28(%rbp), %eax
	movl	%eax, %edx
	movl	a(%rip), %eax
	cmpl	%eax, %edx
	jle	.L14
	movl	-16(%rbp), %eax
.L10:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d %d %d %d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.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	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
.L19:
	leaq	-32(%rbp), %rcx
	leaq	-36(%rbp), %rdx
	leaq	-40(%rbp), %rax
	movq	%rcx, %r8
	leaq	a(%rip), %rcx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	je	.L25
	movl	-32(%rbp), %ecx
	movl	-36(%rbp), %esi
	movl	-40(%rbp), %eax
	movl	ptr(%rip), %ebx
	leal	1(%rbx), %edx
	movl	%edx, ptr(%rip)
	movl	%ecx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	%eax, %edi
	call	solve
	movslq	%ebx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ans(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	jmp	.L19
.L25:
	nop
	movl	$0, -28(%rbp)
	jmp	.L20
.L21:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -28(%rbp)
.L20:
	movl	ptr(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L21
	movl	$0, %eax
	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
.LFE3:
	.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
	.p2align 4
	.type	solve.part.0, @function
solve.part.0:
.LFB27:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edx, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movl	a(%rip), %r11d
	movl	%edx, 92(%rsp)
	imull	%ecx, %edx
	movl	%edi, 88(%rsp)
	movl	%esi, 52(%rsp)
	movl	%r8d, 28(%rsp)
	movl	%edx, 32(%rsp)
	movl	$0, 84(%rsp)
	cmpl	%r11d, %edx
	jg	.L1
	addl	%edx, %eax
	movl	%eax, 56(%rsp)
	movl	%edi, %eax
	imull	%ecx, %eax
	subl	%esi, %eax
	imull	%ecx, %esi
	movl	%eax, 12(%rsp)
	leal	-5(%r8), %eax
	movl	%eax, 96(%rsp)
	movl	%esi, %r10d
.L17:
	movl	12(%rsp), %edx
	movl	52(%rsp), %ebx
	leal	1(%rcx), %esi
	movl	%esi, 60(%rsp)
	movl	%edx, %eax
	addl	%ebx, %eax
	cmpl	%eax, %ebx
	jg	.L3
	testl	%edx, %edx
	movl	%edx, %ebx
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 84(%rsp)
	cmpl	$1, 28(%rsp)
	je	.L3
	testb	%dl, %dl
	jne	.L3
	movl	32(%rsp), %eax
	movl	%eax, %edx
	imull	%ecx, %edx
	movl	%edx, 16(%rsp)
	cmpl	%edx, %r11d
	jl	.L3
	imull	%eax, %esi
	movl	%ebx, %eax
	movl	%r10d, %r15d
	movl	$0, 80(%rsp)
	imull	%ecx, %eax
	movl	%r10d, 24(%rsp)
	movl	%r11d, %r9d
	imull	%ecx, %r15d
	movl	%esi, 40(%rsp)
	subl	%r10d, %eax
	movl	%eax, %r11d
.L16:
	movl	24(%rsp), %esi
	leal	1(%rcx), %edi
	movl	%edi, 44(%rsp)
	leal	(%r11,%rsi), %eax
	cmpl	%eax, %esi
	jg	.L5
	testl	%r11d, %r11d
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 80(%rsp)
	cmpl	$2, 28(%rsp)
	je	.L5
	testb	%dl, %dl
	jne	.L5
	movl	16(%rsp), %eax
	movl	%eax, %r13d
	imull	%ecx, %r13d
	cmpl	%r13d, %r9d
	jl	.L5
	imull	%eax, %edi
	movl	%r11d, %eax
	movl	%r15d, %r10d
	movl	%r11d, 64(%rsp)
	imull	%ecx, %eax
	movl	$0, 76(%rsp)
	movl	%r13d, %r11d
	imull	%ecx, %r10d
	movl	%edi, 20(%rsp)
	subl	%r15d, %eax
	movl	%r10d, %r12d
	movl	%eax, %r14d
	movl	%r15d, %r10d
.L15:
	leal	1(%rcx), %r15d
	leal	(%r14,%r10), %eax
	movl	%r15d, 36(%rsp)
	cmpl	%r10d, %eax
	jl	.L7
	testl	%r14d, %r14d
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 76(%rsp)
	cmpl	$3, 28(%rsp)
	je	.L7
	testb	%dl, %dl
	jne	.L7
	movl	%r11d, %r13d
	imull	%ecx, %r13d
	cmpl	%r13d, %r9d
	jl	.L7
	movl	%ecx, %ebp
	imull	%r11d, %r15d
	movl	%r12d, %ebx
	movl	%r14d, 48(%rsp)
	imull	%r14d, %ebp
	movl	$0, 72(%rsp)
	imull	%ecx, %ebx
	movl	%r11d, 68(%rsp)
	movl	%r10d, 100(%rsp)
	subl	%r12d, %ebp
.L14:
	leal	(%r12,%rbp), %eax
	leal	1(%rcx), %r10d
	cmpl	%eax, %r12d
	jg	.L9
	testl	%ebp, %ebp
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 72(%rsp)
	cmpl	$4, 28(%rsp)
	je	.L9
	testb	%dl, %dl
	jne	.L9
	movl	%ecx, %edx
	imull	%r13d, %edx
	cmpl	%r9d, %edx
	jg	.L9
	movl	%ecx, %edi
	movl	%ecx, %esi
	xorl	%r11d, %r11d
	movl	%r15d, %eax
	imull	%ebp, %edi
	movl	%r10d, %r14d
	movl	%r12d, %r15d
	movl	%ebp, %r12d
	imull	%ebx, %esi
	movl	%r13d, %ebp
	imull	%r13d, %r14d
	movl	%r11d, %r13d
	movl	%eax, %r11d
	subl	%ebx, %edi
.L13:
	leal	(%rbx,%rdi), %eax
	cmpl	%eax, %ebx
	jg	.L11
	testl	%edi, %edi
	sete	%al
	sete	%r8b
	movzbl	%al, %eax
	addl	%eax, %r13d
	movl	96(%rsp), %eax
	testl	%eax, %eax
	je	.L11
	testb	%r8b, %r8b
	jne	.L11
	movl	%eax, %r8d
	movl	%r10d, 124(%rsp)
	movl	%r11d, 120(%rsp)
	movl	%r9d, 116(%rsp)
	movl	%ecx, 112(%rsp)
	movl	%esi, 108(%rsp)
	movl	%edi, 104(%rsp)
	call	solve.part.0
	movl	124(%rsp), %r10d
	movl	120(%rsp), %r11d
	movl	116(%rsp), %r9d
	movl	112(%rsp), %ecx
	addl	%eax, %r13d
	movl	108(%rsp), %esi
	movl	104(%rsp), %edi
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%r14d, %edx
	addl	$1, %ecx
	addl	%ebp, %r14d
	addl	%r12d, %edi
	addl	%ebx, %esi
	cmpl	%edx, %r9d
	jge	.L13
	addl	%r13d, 72(%rsp)
	movl	%r12d, %ebp
	movl	%r15d, %r12d
	movl	%r11d, %r15d
.L9:
	movl	%r15d, %r13d
	movl	%r10d, %ecx
	addl	68(%rsp), %r15d
	addl	48(%rsp), %ebp
	addl	%r12d, %ebx
	cmpl	%r13d, %r9d
	jge	.L14
	movl	72(%rsp), %ecx
	addl	%ecx, 76(%rsp)
	movl	48(%rsp), %r14d
	movl	100(%rsp), %r10d
.L7:
	movl	20(%rsp), %eax
	movl	16(%rsp), %edx
	addl	%r10d, %r12d
	movl	36(%rsp), %ecx
	addl	64(%rsp), %r14d
	movl	%eax, %r11d
	addl	%edx, %eax
	movl	%eax, 20(%rsp)
	cmpl	%r11d, %r9d
	jge	.L15
	movl	76(%rsp), %ecx
	addl	%ecx, 80(%rsp)
	movl	%r10d, %r15d
	movl	64(%rsp), %r11d
.L5:
	movl	40(%rsp), %esi
	movl	32(%rsp), %ebx
	movl	44(%rsp), %ecx
	addl	12(%rsp), %r11d
	movl	%esi, 16(%rsp)
	movl	%esi, %eax
	addl	%ebx, %esi
	addl	24(%rsp), %r15d
	movl	%esi, 40(%rsp)
	cmpl	%r9d, %eax
	jle	.L16
	movl	80(%rsp), %ecx
	addl	%ecx, 84(%rsp)
	movl	%r9d, %r11d
	movl	24(%rsp), %r10d
.L3:
	movl	56(%rsp), %edi
	movl	92(%rsp), %ebx
	movl	60(%rsp), %ecx
	addl	52(%rsp), %r10d
	movl	%edi, 32(%rsp)
	movl	%edi, %eax
	addl	%ebx, %edi
	movl	%edi, 56(%rsp)
	movl	88(%rsp), %edi
	addl	%edi, 12(%rsp)
	cmpl	%r11d, %eax
	jle	.L17
.L1:
	movl	84(%rsp), %eax
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE27:
	.size	solve.part.0, .-solve.part.0
	.p2align 4
	.globl	gcd
	.type	gcd, @function
gcd:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	movl	%esi, %r8d
	testl	%esi, %esi
	jne	.L44
	jmp	.L47
	.p2align 4,,10
	.p2align 3
.L46:
	movl	%edx, %r8d
.L44:
	cltd
	idivl	%r8d
	movl	%r8d, %eax
	testl	%edx, %edx
	jne	.L46
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L47:
	movl	%edi, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	gcd, .-gcd
	.p2align 4
	.globl	lcm
	.type	lcm, @function
lcm:
.LFB24:
	.cfi_startproc
	endbr64
	testl	%esi, %esi
	je	.L51
	movl	%edi, %eax
	movl	%esi, %ecx
	jmp	.L50
	.p2align 4,,10
	.p2align 3
.L52:
	movl	%edx, %ecx
.L50:
	cltd
	idivl	%ecx
	movl	%ecx, %eax
	testl	%edx, %edx
	jne	.L52
	movl	%edi, %eax
	cltd
	idivl	%ecx
	imull	%esi, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L51:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	lcm, .-lcm
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB25:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L54
	testl	%r8d, %r8d
	je	.L54
	jmp	solve.part.0
	.p2align 4,,10
	.p2align 3
.L54:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE25:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d %d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB26:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	84(%rsp), %rax
	movq	%rax, 32(%rsp)
	leaq	80(%rsp), %rax
	movq	%rax, 24(%rsp)
	leaq	76(%rsp), %rax
	movq	%rax, 40(%rsp)
	.p2align 4,,10
	.p2align 3
.L64:
	movq	32(%rsp), %r8
	movq	24(%rsp), %rdx
	xorl	%eax, %eax
	leaq	a(%rip), %rcx
	movq	40(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	80(%rsp), %r13d
	testl	%r13d, %r13d
	je	.L81
	movl	ptr(%rip), %eax
	movl	84(%rsp), %edi
	movl	76(%rsp), %r11d
	movl	%eax, 20(%rsp)
	addl	$1, %eax
	movl	%edi, 16(%rsp)
	movl	%eax, ptr(%rip)
	testl	%r11d, %r11d
	je	.L68
	movl	%edi, %eax
	testl	%edi, %edi
	je	.L68
	movl	a(%rip), %r9d
	xorl	%r15d, %r15d
	testl	%r9d, %r9d
	jle	.L58
	subl	$2, %eax
	movl	%r11d, %r12d
	movl	%r11d, (%rsp)
	movl	%r13d, %ebx
	movl	%eax, 48(%rsp)
	subl	%r13d, %r12d
	movl	$1, %ebp
	movl	%r15d, %r11d
.L63:
	leal	(%r12,%r13), %eax
	leal	1(%rbp), %r10d
	cmpl	%eax, %r13d
	jg	.L59
	testl	%r12d, %r12d
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, %r11d
	cmpl	$1, 16(%rsp)
	je	.L59
	testb	%dl, %dl
	jne	.L59
	movl	%ebp, %edx
	imull	%ebp, %edx
	cmpl	%edx, %r9d
	jl	.L59
	movl	%r12d, %edi
	movl	%r10d, 60(%rsp)
	movl	%r10d, %r14d
	movl	%ebx, %esi
	imull	%ebp, %edi
	movl	%r13d, 52(%rsp)
	movl	%ebp, %ecx
	xorl	%r15d, %r15d
	imull	%ebp, %r14d
	movl	%r11d, 56(%rsp)
	movl	%r9d, %r13d
	movl	%r12d, %r11d
	imull	%ebp, %esi
	movl	%ebp, %r12d
	subl	%ebx, %edi
	movl	%edi, %ebp
.L62:
	leal	0(%rbp,%rbx), %eax
	cmpl	%ebx, %eax
	jl	.L61
	movl	48(%rsp), %r8d
	cmpl	$1, %ebp
	movl	%ebp, %edi
	movl	%r11d, 12(%rsp)
	movl	%ecx, 8(%rsp)
	adcl	$0, %r15d
	movl	%esi, 4(%rsp)
	call	solve
	movl	12(%rsp), %r11d
	movl	8(%rsp), %ecx
	movl	4(%rsp), %esi
	addl	%eax, %r15d
.L61:
	movl	%r14d, %edx
	addl	$1, %ecx
	addl	%r12d, %r14d
	addl	%r11d, %ebp
	addl	%ebx, %esi
	cmpl	%edx, %r13d
	jge	.L62
	movl	%r11d, %r12d
	movl	56(%rsp), %r11d
	movl	%r13d, %r9d
	movl	60(%rsp), %r10d
	movl	52(%rsp), %r13d
	addl	%r15d, %r11d
.L59:
	movl	%r10d, %ebp
	addl	(%rsp), %r12d
	addl	%r13d, %ebx
	cmpl	%r9d, %r10d
	jle	.L63
	movl	%r11d, %r15d
.L58:
	movslq	20(%rsp), %rax
	leaq	ans(%rip), %rdi
	movl	%r15d, (%rdi,%rax,4)
	jmp	.L64
	.p2align 4,,10
	.p2align 3
.L68:
	xorl	%r15d, %r15d
	jmp	.L58
	.p2align 4,,10
	.p2align 3
.L81:
	movl	ptr(%rip), %eax
	xorl	%ebx, %ebx
	leaq	ans(%rip), %r12
	leaq	.LC1(%rip), %rbp
	testl	%eax, %eax
	jle	.L65
	.p2align 4,,10
	.p2align 3
.L57:
	movl	(%r12,%rbx,4), %edx
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movl	$1, %edi
	addq	$1, %rbx
	call	__printf_chk@PLT
	cmpl	%ebx, ptr(%rip)
	jg	.L57
.L65:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L82
	addq	$104, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L82:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE26:
	.size	main, .-main
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	ptr
	.align 4
	.type	ptr, @object
	.size	ptr, 4
ptr:
	.zero	4
	.globl	ans
	.align 32
	.type	ans, @object
	.size	ans, 4000
ans:
	.zero	4000
	.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
	.p2align 4
	.type	solve.part.0, @function
solve.part.0:
.LFB27:
	.cfi_startproc
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edx, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movl	a(%rip), %r11d
	movl	%edx, 92(%rsp)
	imull	%ecx, %edx
	movl	%edi, 88(%rsp)
	movl	%esi, 52(%rsp)
	movl	%r8d, 28(%rsp)
	movl	%edx, 32(%rsp)
	movl	$0, 84(%rsp)
	cmpl	%r11d, %edx
	jg	.L1
	addl	%edx, %eax
	movl	%eax, 56(%rsp)
	movl	%edi, %eax
	imull	%ecx, %eax
	subl	%esi, %eax
	imull	%ecx, %esi
	movl	%eax, 12(%rsp)
	leal	-5(%r8), %eax
	movl	%eax, 96(%rsp)
	movl	%esi, %r10d
.L17:
	movl	12(%rsp), %edx
	movl	52(%rsp), %ebx
	leal	1(%rcx), %esi
	movl	%esi, 60(%rsp)
	movl	%edx, %eax
	addl	%ebx, %eax
	cmpl	%eax, %ebx
	jg	.L3
	testl	%edx, %edx
	movl	%edx, %ebx
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 84(%rsp)
	cmpl	$1, 28(%rsp)
	je	.L3
	testb	%dl, %dl
	jne	.L3
	movl	32(%rsp), %eax
	movl	%eax, %edx
	imull	%ecx, %edx
	movl	%edx, 16(%rsp)
	cmpl	%edx, %r11d
	jl	.L3
	imull	%eax, %esi
	movl	%ebx, %eax
	movl	%r10d, %r15d
	movl	$0, 80(%rsp)
	imull	%ecx, %eax
	movl	%r10d, 24(%rsp)
	movl	%r11d, %r9d
	imull	%ecx, %r15d
	movl	%esi, 40(%rsp)
	subl	%r10d, %eax
	movl	%eax, %r11d
.L16:
	movl	24(%rsp), %esi
	leal	1(%rcx), %edi
	movl	%edi, 44(%rsp)
	leal	(%r11,%rsi), %eax
	cmpl	%eax, %esi
	jg	.L5
	testl	%r11d, %r11d
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 80(%rsp)
	cmpl	$2, 28(%rsp)
	je	.L5
	testb	%dl, %dl
	jne	.L5
	movl	16(%rsp), %eax
	movl	%eax, %r13d
	imull	%ecx, %r13d
	cmpl	%r13d, %r9d
	jl	.L5
	imull	%eax, %edi
	movl	%r11d, %eax
	movl	%r15d, %r10d
	movl	%r11d, 64(%rsp)
	imull	%ecx, %eax
	movl	$0, 76(%rsp)
	movl	%r13d, %r11d
	imull	%ecx, %r10d
	movl	%edi, 20(%rsp)
	subl	%r15d, %eax
	movl	%r10d, %r12d
	movl	%eax, %r14d
	movl	%r15d, %r10d
.L15:
	leal	1(%rcx), %r15d
	leal	(%r14,%r10), %eax
	movl	%r15d, 36(%rsp)
	cmpl	%r10d, %eax
	jl	.L7
	testl	%r14d, %r14d
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 76(%rsp)
	cmpl	$3, 28(%rsp)
	je	.L7
	testb	%dl, %dl
	jne	.L7
	movl	%r11d, %r13d
	imull	%ecx, %r13d
	cmpl	%r13d, %r9d
	jl	.L7
	movl	%ecx, %ebp
	imull	%r11d, %r15d
	movl	%r12d, %ebx
	movl	%r14d, 48(%rsp)
	imull	%r14d, %ebp
	movl	$0, 72(%rsp)
	imull	%ecx, %ebx
	movl	%r11d, 68(%rsp)
	movl	%r10d, 100(%rsp)
	subl	%r12d, %ebp
.L14:
	leal	(%r12,%rbp), %eax
	leal	1(%rcx), %r10d
	cmpl	%eax, %r12d
	jg	.L9
	testl	%ebp, %ebp
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, 72(%rsp)
	cmpl	$4, 28(%rsp)
	je	.L9
	testb	%dl, %dl
	jne	.L9
	movl	%ecx, %edx
	imull	%r13d, %edx
	cmpl	%r9d, %edx
	jg	.L9
	movl	%ecx, %edi
	movl	%ecx, %esi
	xorl	%r11d, %r11d
	movl	%r15d, %eax
	imull	%ebp, %edi
	movl	%r10d, %r14d
	movl	%r12d, %r15d
	movl	%ebp, %r12d
	imull	%ebx, %esi
	movl	%r13d, %ebp
	imull	%r13d, %r14d
	movl	%r11d, %r13d
	movl	%eax, %r11d
	subl	%ebx, %edi
.L13:
	leal	(%rbx,%rdi), %eax
	cmpl	%eax, %ebx
	jg	.L11
	testl	%edi, %edi
	sete	%al
	sete	%r8b
	movzbl	%al, %eax
	addl	%eax, %r13d
	movl	96(%rsp), %eax
	testl	%eax, %eax
	je	.L11
	testb	%r8b, %r8b
	jne	.L11
	movl	%eax, %r8d
	movl	%r10d, 124(%rsp)
	movl	%r11d, 120(%rsp)
	movl	%r9d, 116(%rsp)
	movl	%ecx, 112(%rsp)
	movl	%esi, 108(%rsp)
	movl	%edi, 104(%rsp)
	call	solve.part.0
	movl	124(%rsp), %r10d
	movl	120(%rsp), %r11d
	movl	116(%rsp), %r9d
	movl	112(%rsp), %ecx
	addl	%eax, %r13d
	movl	108(%rsp), %esi
	movl	104(%rsp), %edi
	.p2align 4,,10
	.p2align 3
.L11:
	movl	%r14d, %edx
	addl	$1, %ecx
	addl	%ebp, %r14d
	addl	%r12d, %edi
	addl	%ebx, %esi
	cmpl	%edx, %r9d
	jge	.L13
	addl	%r13d, 72(%rsp)
	movl	%r12d, %ebp
	movl	%r15d, %r12d
	movl	%r11d, %r15d
.L9:
	movl	%r15d, %r13d
	movl	%r10d, %ecx
	addl	68(%rsp), %r15d
	addl	48(%rsp), %ebp
	addl	%r12d, %ebx
	cmpl	%r13d, %r9d
	jge	.L14
	movl	72(%rsp), %ecx
	addl	%ecx, 76(%rsp)
	movl	48(%rsp), %r14d
	movl	100(%rsp), %r10d
.L7:
	movl	20(%rsp), %eax
	movl	16(%rsp), %edx
	addl	%r10d, %r12d
	movl	36(%rsp), %ecx
	addl	64(%rsp), %r14d
	movl	%eax, %r11d
	addl	%edx, %eax
	movl	%eax, 20(%rsp)
	cmpl	%r11d, %r9d
	jge	.L15
	movl	76(%rsp), %ecx
	addl	%ecx, 80(%rsp)
	movl	%r10d, %r15d
	movl	64(%rsp), %r11d
.L5:
	movl	40(%rsp), %esi
	movl	32(%rsp), %ebx
	movl	44(%rsp), %ecx
	addl	12(%rsp), %r11d
	movl	%esi, 16(%rsp)
	movl	%esi, %eax
	addl	%ebx, %esi
	addl	24(%rsp), %r15d
	movl	%esi, 40(%rsp)
	cmpl	%r9d, %eax
	jle	.L16
	movl	80(%rsp), %ecx
	addl	%ecx, 84(%rsp)
	movl	%r9d, %r11d
	movl	24(%rsp), %r10d
.L3:
	movl	56(%rsp), %edi
	movl	92(%rsp), %ebx
	movl	60(%rsp), %ecx
	addl	52(%rsp), %r10d
	movl	%edi, 32(%rsp)
	movl	%edi, %eax
	addl	%ebx, %edi
	movl	%edi, 56(%rsp)
	movl	88(%rsp), %edi
	addl	%edi, 12(%rsp)
	cmpl	%r11d, %eax
	jle	.L17
.L1:
	movl	84(%rsp), %eax
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE27:
	.size	solve.part.0, .-solve.part.0
	.p2align 4
	.globl	gcd
	.type	gcd, @function
gcd:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	movl	%esi, %r8d
	testl	%esi, %esi
	jne	.L44
	jmp	.L47
	.p2align 4,,10
	.p2align 3
.L46:
	movl	%edx, %r8d
.L44:
	cltd
	idivl	%r8d
	movl	%r8d, %eax
	testl	%edx, %edx
	jne	.L46
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L47:
	movl	%edi, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	gcd, .-gcd
	.p2align 4
	.globl	lcm
	.type	lcm, @function
lcm:
.LFB24:
	.cfi_startproc
	endbr64
	testl	%esi, %esi
	je	.L51
	movl	%edi, %eax
	movl	%esi, %ecx
	jmp	.L50
	.p2align 4,,10
	.p2align 3
.L52:
	movl	%edx, %ecx
.L50:
	cltd
	idivl	%ecx
	movl	%ecx, %eax
	testl	%edx, %edx
	jne	.L52
	movl	%edi, %eax
	cltd
	idivl	%ecx
	imull	%esi, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L51:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	lcm, .-lcm
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB25:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L54
	testl	%r8d, %r8d
	je	.L54
	jmp	solve.part.0
	.p2align 4,,10
	.p2align 3
.L54:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE25:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d %d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB26:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	84(%rsp), %rax
	movq	%rax, 32(%rsp)
	leaq	80(%rsp), %rax
	movq	%rax, 24(%rsp)
	leaq	76(%rsp), %rax
	movq	%rax, 40(%rsp)
	.p2align 4,,10
	.p2align 3
.L64:
	movq	32(%rsp), %r8
	movq	24(%rsp), %rdx
	xorl	%eax, %eax
	leaq	a(%rip), %rcx
	movq	40(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	80(%rsp), %r13d
	testl	%r13d, %r13d
	je	.L81
	movl	ptr(%rip), %eax
	movl	84(%rsp), %edi
	movl	76(%rsp), %r11d
	movl	%eax, 20(%rsp)
	addl	$1, %eax
	movl	%edi, 16(%rsp)
	movl	%eax, ptr(%rip)
	testl	%r11d, %r11d
	je	.L68
	movl	%edi, %eax
	testl	%edi, %edi
	je	.L68
	movl	a(%rip), %r9d
	xorl	%r15d, %r15d
	testl	%r9d, %r9d
	jle	.L58
	subl	$2, %eax
	movl	%r11d, %r12d
	movl	%r11d, (%rsp)
	movl	%r13d, %ebx
	movl	%eax, 48(%rsp)
	subl	%r13d, %r12d
	movl	$1, %ebp
	movl	%r15d, %r11d
.L63:
	leal	(%r12,%r13), %eax
	leal	1(%rbp), %r10d
	cmpl	%eax, %r13d
	jg	.L59
	testl	%r12d, %r12d
	sete	%al
	sete	%dl
	movzbl	%al, %eax
	addl	%eax, %r11d
	cmpl	$1, 16(%rsp)
	je	.L59
	testb	%dl, %dl
	jne	.L59
	movl	%ebp, %edx
	imull	%ebp, %edx
	cmpl	%edx, %r9d
	jl	.L59
	movl	%r12d, %edi
	movl	%r10d, 60(%rsp)
	movl	%r10d, %r14d
	movl	%ebx, %esi
	imull	%ebp, %edi
	movl	%r13d, 52(%rsp)
	movl	%ebp, %ecx
	xorl	%r15d, %r15d
	imull	%ebp, %r14d
	movl	%r11d, 56(%rsp)
	movl	%r9d, %r13d
	movl	%r12d, %r11d
	imull	%ebp, %esi
	movl	%ebp, %r12d
	subl	%ebx, %edi
	movl	%edi, %ebp
.L62:
	leal	0(%rbp,%rbx), %eax
	cmpl	%ebx, %eax
	jl	.L61
	movl	48(%rsp), %r8d
	cmpl	$1, %ebp
	movl	%ebp, %edi
	movl	%r11d, 12(%rsp)
	movl	%ecx, 8(%rsp)
	adcl	$0, %r15d
	movl	%esi, 4(%rsp)
	call	solve
	movl	12(%rsp), %r11d
	movl	8(%rsp), %ecx
	movl	4(%rsp), %esi
	addl	%eax, %r15d
.L61:
	movl	%r14d, %edx
	addl	$1, %ecx
	addl	%r12d, %r14d
	addl	%r11d, %ebp
	addl	%ebx, %esi
	cmpl	%edx, %r13d
	jge	.L62
	movl	%r11d, %r12d
	movl	56(%rsp), %r11d
	movl	%r13d, %r9d
	movl	60(%rsp), %r10d
	movl	52(%rsp), %r13d
	addl	%r15d, %r11d
.L59:
	movl	%r10d, %ebp
	addl	(%rsp), %r12d
	addl	%r13d, %ebx
	cmpl	%r9d, %r10d
	jle	.L63
	movl	%r11d, %r15d
.L58:
	movslq	20(%rsp), %rax
	leaq	ans(%rip), %rdi
	movl	%r15d, (%rdi,%rax,4)
	jmp	.L64
	.p2align 4,,10
	.p2align 3
.L68:
	xorl	%r15d, %r15d
	jmp	.L58
	.p2align 4,,10
	.p2align 3
.L81:
	movl	ptr(%rip), %eax
	xorl	%ebx, %ebx
	leaq	ans(%rip), %r12
	leaq	.LC1(%rip), %rbp
	testl	%eax, %eax
	jle	.L65
	.p2align 4,,10
	.p2align 3
.L57:
	movl	(%r12,%rbx,4), %edx
	xorl	%eax, %eax
	movq	%rbp, %rsi
	movl	$1, %edi
	addq	$1, %rbx
	call	__printf_chk@PLT
	cmpl	%ebx, ptr(%rip)
	jg	.L57
.L65:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L82
	addq	$104, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L82:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE26:
	.size	main, .-main
	.globl	a
	.bss
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.globl	ptr
	.align 4
	.type	ptr, @object
	.size	ptr, 4
ptr:
	.zero	4
	.globl	ans
	.align 32
	.type	ans, @object
	.size	ans, 4000
ans:
	.zero	4000
	.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>

#define rep(i, N) for (int i = 0; i < N; i++)

//int dxy[5] = {0, 1, 0, -1, 0};
// 01Trie BIT CHT DFT FFT avl cmd cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination ppuf segtree st tmp topcoder uf vi 

//最大公約数
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int ans[1000];
int ptr, a;

int solve(int p, int q, int denom, int max_denom, int n)
{
    if (!p || !n) return 0;
    int ret = 0;
    for (int i = max_denom; i * denom <= a; i++) {
        if (p * i < q) continue;
        //int tmp = lcm(i, q);
        int tmp = i * q;
        int s = p * (tmp/q) - tmp / i;
        ret += !s;
        ret += solve(s, tmp, denom * i, i, n-1);
    }
    return ret;
}

signed main()
{
    int p, q, n;
    while (1) {
        scanf("%d %d %d %d", &p, &q, &a, &n);
        if (!q) break;
        ans[ptr++] = solve(p, q, 1, 1, n);
    }

    for (int i = 0; i < ptr; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}


2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 3
2 3 12000 7
54 795 12000 7
2 4 300 1
2 1 200 5
2 4 54 2
0 0 0 0
 2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 2
2 3 12000 7
54 795 12000 7
2 4 300 1
2 1 16 5
2 4 54 2
0 0 0 0
 2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 2
2 3 12000 7
54 795 12000 7
2 4 300 1
2 1 8 5
2 4 54 2
0 0 0 0
 2 6 120 3
2 3 300 3
2 3 299 3
2 3 12 2
2 3 12000 7
54 795 12000 7
2 4 300 1
2 1 8 5
2 4 54 2
0 0 0 0
 2 6 120 5
2 3 300 3
2 3 299 3
2 3 12 2
2 0 12000 7
54 795 22620 7
2 4 300 1
2 1 8 5
2 4 54 2
0 0 0 0
 2 6 120 5
2 3 300 3
3 3 299 3
2 3 12 2
2 0 12000 7
54 795 22620 7
2 4 300 1
2 1 8 5
2 4 54 2
0 0 0 0
 2 6 120 5
2 3 300 3
3 3 299 3
2 3 7 2
2 0 12000 7
54 795 22620 7
2 4 300 1
2 1 8 5
2 4 54 2
0 0 0 0
 2 6 120 5
2 3 300 3
3 3 299 3
2 3 7 2
2 0 12000 7
54 781 35092 7
2 4 300 1
2 1 8 5
2 4 54 2
0 0 0 0
 2 3 120 3
2 3 300 3
2 3 299 3
2 3 12 3
2 3 12000 7
54 795 12000 7
2 3 300 1
2 1 200 5
2 6 54 2
0 0 0 0
 2 3 120 3
2 3 300 3
2 1 299 3
2 3 12 3
2 3 12000 7
54 795 12000 7
2 4 300 1
2 1 200 5
2 4 54 2
0 0 0 0

4
7
6
2
42
1
1
9
3
 4
7
6
2
42
1
1
3
3
 4
7
6
2
42
1
1
2
3
 3
7
6
2
42
1
1
2
3
 3
7
6
2
 3
7
5
2
 3
7
5
0
 3
7
5
0
 4
7
6
2
42
1
0
9
3
 4
7
2
2
42
1
1
9
3

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>

#define rep(i, N) for (int i = 0; i < N; i++)

//int dxy[5] = {0, 1, 0, -1, 0};
// 01Trie BIT CHT DFT FFT avl cmd cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination ppuf segtree st tmp topcoder uf vi 

//最大公約数
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int ans[1000];
int ptr, a;

int solve(int p, int q, int denom, int max_denom, int n)
{
    if (!p || !n) return 0;
    int ret = 0;
    for (int i = max_denom; i * denom <= a; i++) {
        if (p * i < q) continue;
        //int tmp = lcm(i, q);
        int tmp = i * q;
        int s = p * (tmp/q) - tmp / i;
        ret += !s;
        ret += solve(s, tmp, denom * i, i, n-1);
    }
    return ret;
}

signed main()
{
    int p, q, n;
    while (1) {
        scanf("%d %d %d %d", &p, &q, &a, &n);
        if (!q) break;
        ans[ptr++] = solve(p, q, 1, 1, n);
    }

    for (int i = 0; i < ptr; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	gcd
	.type	gcd, @function
gcd:
.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
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	cmpl	$0, -8(%rbp)
	je	.L2
	movl	-4(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	-8(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	jmp	.L4
.L2:
	movl	-4(%rbp), %eax
.L4:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	gcd, .-gcd
	.globl	lcm
	.type	lcm, @function
lcm:
.LFB1:
	.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
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, %ecx
	movl	-4(%rbp), %eax
	cltd
	idivl	%ecx
	imull	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	lcm, .-lcm
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 4000
ans:
	.zero	4000
	.globl	ptr
	.align 4
	.type	ptr, @object
	.size	ptr, 4
ptr:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	cmpl	$0, -20(%rbp)
	je	.L8
	cmpl	$0, -36(%rbp)
	jne	.L9
.L8:
	movl	$0, %eax
	jmp	.L10
.L9:
	movl	$0, -16(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L11
.L14:
	movl	-20(%rbp), %eax
	imull	-12(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jg	.L15
	movl	-12(%rbp), %eax
	imull	-24(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	imull	-20(%rbp), %eax
	movl	%eax, %ecx
	movl	-8(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	movl	%eax, %edx
	movl	%ecx, %eax
	subl	%edx, %eax
	movl	%eax, -4(%rbp)
	cmpl	$0, -4(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, -16(%rbp)
	movl	-36(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-28(%rbp), %eax
	imull	-12(%rbp), %eax
	movl	%eax, %edx
	movl	-12(%rbp), %ecx
	movl	-8(%rbp), %esi
	movl	-4(%rbp), %eax
	movl	%edi, %r8d
	movl	%eax, %edi
	call	solve
	addl	%eax, -16(%rbp)
	jmp	.L13
.L15:
	nop
.L13:
	addl	$1, -12(%rbp)
.L11:
	movl	-12(%rbp), %eax
	imull	-28(%rbp), %eax
	movl	%eax, %edx
	movl	a(%rip), %eax
	cmpl	%eax, %edx
	jle	.L14
	movl	-16(%rbp), %eax
.L10:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d %d %d %d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.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	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
.L19:
	leaq	-32(%rbp), %rcx
	leaq	-36(%rbp), %rdx
	leaq	-40(%rbp), %rax
	movq	%rcx, %r8
	leaq	a(%rip), %rcx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	je	.L25
	movl	-32(%rbp), %ecx
	movl	-36(%rbp), %esi
	movl	-40(%rbp), %eax
	movl	ptr(%rip), %ebx
	leal	1(%rbx), %edx
	movl	%edx, ptr(%rip)
	movl	%ecx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	%eax, %edi
	call	solve
	movslq	%ebx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ans(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	jmp	.L19
.L25:
	nop
	movl	$0, -28(%rbp)
	jmp	.L20
.L21:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -28(%rbp)
.L20:
	movl	ptr(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L21
	movl	$0, %eax
	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
.LFE3:
	.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	gcd
	.type	gcd, @function
gcd:
.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
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	cmpl	$0, -8(%rbp)
	je	.L2
	movl	-4(%rbp), %eax
	cltd
	idivl	-8(%rbp)
	movl	-8(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	jmp	.L4
.L2:
	movl	-4(%rbp), %eax
.L4:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	gcd, .-gcd
	.globl	lcm
	.type	lcm, @function
lcm:
.LFB1:
	.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
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	gcd
	movl	%eax, %ecx
	movl	-4(%rbp), %eax
	cltd
	idivl	%ecx
	imull	-8(%rbp), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	lcm, .-lcm
	.globl	ans
	.bss
	.align 32
	.type	ans, @object
	.size	ans, 4000
ans:
	.zero	4000
	.globl	ptr
	.align 4
	.type	ptr, @object
	.size	ptr, 4
ptr:
	.zero	4
	.globl	a
	.align 4
	.type	a, @object
	.size	a, 4
a:
	.zero	4
	.text
	.globl	solve
	.type	solve, @function
solve:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movl	%r8d, -36(%rbp)
	cmpl	$0, -20(%rbp)
	je	.L8
	cmpl	$0, -36(%rbp)
	jne	.L9
.L8:
	movl	$0, %eax
	jmp	.L10
.L9:
	movl	$0, -16(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L11
.L14:
	movl	-20(%rbp), %eax
	imull	-12(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jg	.L15
	movl	-12(%rbp), %eax
	imull	-24(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	imull	-20(%rbp), %eax
	movl	%eax, %ecx
	movl	-8(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	movl	%eax, %edx
	movl	%ecx, %eax
	subl	%edx, %eax
	movl	%eax, -4(%rbp)
	cmpl	$0, -4(%rbp)
	sete	%al
	movzbl	%al, %eax
	addl	%eax, -16(%rbp)
	movl	-36(%rbp), %eax
	leal	-1(%rax), %edi
	movl	-28(%rbp), %eax
	imull	-12(%rbp), %eax
	movl	%eax, %edx
	movl	-12(%rbp), %ecx
	movl	-8(%rbp), %esi
	movl	-4(%rbp), %eax
	movl	%edi, %r8d
	movl	%eax, %edi
	call	solve
	addl	%eax, -16(%rbp)
	jmp	.L13
.L15:
	nop
.L13:
	addl	$1, -12(%rbp)
.L11:
	movl	-12(%rbp), %eax
	imull	-28(%rbp), %eax
	movl	%eax, %edx
	movl	a(%rip), %eax
	cmpl	%eax, %edx
	jle	.L14
	movl	-16(%rbp), %eax
.L10:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d %d %d %d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.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	$40, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
.L19:
	leaq	-32(%rbp), %rcx
	leaq	-36(%rbp), %rdx
	leaq	-40(%rbp), %rax
	movq	%rcx, %r8
	leaq	a(%rip), %rcx
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	testl	%eax, %eax
	je	.L25
	movl	-32(%rbp), %ecx
	movl	-36(%rbp), %esi
	movl	-40(%rbp), %eax
	movl	ptr(%rip), %ebx
	leal	1(%rbx), %edx
	movl	%edx, ptr(%rip)
	movl	%ecx, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	movl	%eax, %edi
	call	solve
	movslq	%ebx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ans(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	jmp	.L19
.L25:
	nop
	movl	$0, -28(%rbp)
	jmp	.L20
.L21:
	movl	-28(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ans(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -28(%rbp)
.L20:
	movl	ptr(%rip), %eax
	cmpl	%eax, -28(%rbp)
	jl	.L21
	movl	$0, %eax
	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
.LFE3:
	.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:
