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>
int N,M,Y,P,F,FEE,i,res,tmp;
double RATE;

int h(int m,int y)
{
	if(y==Y)
		return m;
	else
		return h(m+m*RATE-FEE,y+1);
}

int t(int m,int y)
{
	if(y==Y)
		return 0;
	return t(m-FEE,y+1)+m*RATE;
}

int main()
{
	for(scanf("%d",&N);N--;)
	{
		scanf("%d%d%d",&M,&Y,&P);
		for(res=0;P--;)
		{
			scanf("%d%lf%d",&F,&RATE,&FEE);
			tmp=F?h(M,0):M-Y*FEE+t(M,0);
			res=res<tmp?tmp:res;
		}
		printf("%d\n",res);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	Y
	.align 4
	.type	Y, @object
	.size	Y, 4
Y:
	.zero	4
	.globl	P
	.align 4
	.type	P, @object
	.size	P, 4
P:
	.zero	4
	.globl	F
	.align 4
	.type	F, @object
	.size	F, 4
F:
	.zero	4
	.globl	FEE
	.align 4
	.type	FEE, @object
	.size	FEE, 4
FEE:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	res
	.align 4
	.type	res, @object
	.size	res, 4
res:
	.zero	4
	.globl	tmp
	.align 4
	.type	tmp, @object
	.size	tmp, 4
tmp:
	.zero	4
	.globl	RATE
	.align 8
	.type	RATE, @object
	.size	RATE, 8
RATE:
	.zero	8
	.text
	.globl	h
	.type	h, @function
h:
.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)
	movl	Y(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	pxor	%xmm1, %xmm1
	cvtsi2sdl	-4(%rbp), %xmm1
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4(%rbp), %xmm2
	movsd	RATE(%rip), %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	movl	FEE(%rip), %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	subsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	h
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	h, .-h
	.globl	t
	.type	t, @function
t:
.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	Y(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jne	.L5
	movl	$0, %eax
	jmp	.L6
.L5:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	movl	FEE(%rip), %ecx
	movl	-4(%rbp), %eax
	subl	%ecx, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	t
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4(%rbp), %xmm2
	movsd	RATE(%rip), %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	t, .-t
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d%d"
.LC2:
	.string	"%d%lf%d"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.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	$8, %rsp
	.cfi_offset 3, -24
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L8
.L13:
	leaq	P(%rip), %rax
	movq	%rax, %rcx
	leaq	Y(%rip), %rax
	movq	%rax, %rdx
	leaq	M(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, res(%rip)
	jmp	.L9
.L12:
	leaq	FEE(%rip), %rax
	movq	%rax, %rcx
	leaq	RATE(%rip), %rax
	movq	%rax, %rdx
	leaq	F(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	F(%rip), %eax
	testl	%eax, %eax
	je	.L10
	movl	M(%rip), %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	h
	jmp	.L11
.L10:
	movl	M(%rip), %eax
	movl	Y(%rip), %ecx
	movl	FEE(%rip), %edx
	imull	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, %ebx
	movl	M(%rip), %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	t
	addl	%ebx, %eax
.L11:
	movl	%eax, tmp(%rip)
	movl	res(%rip), %edx
	movl	tmp(%rip), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, res(%rip)
.L9:
	movl	P(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, P(%rip)
	testl	%eax, %eax
	jne	.L12
	movl	res(%rip), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L8:
	movl	N(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, N(%rip)
	testl	%eax, %eax
	jne	.L13
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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	t.part.0, @function
t.part.0:
.LFB26:
	.cfi_startproc
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leal	1(%rsi), %edx
	pxor	%xmm1, %xmm1
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	%edi, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movl	Y(%rip), %eax
	movsd	RATE(%rip), %xmm2
	cmpl	%eax, %edx
	je	.L2
	movl	FEE(%rip), %edx
	movl	%edi, %ebp
	leal	2(%rsi), %ecx
	movapd	%xmm1, %xmm3
	subl	%edx, %ebp
	cmpl	%ecx, %eax
	je	.L3
	movl	%ebp, %r12d
	leal	3(%rsi), %ecx
	subl	%edx, %r12d
	cmpl	%ecx, %eax
	je	.L4
	movl	%r12d, %r13d
	leal	4(%rsi), %ecx
	subl	%edx, %r13d
	cmpl	%ecx, %eax
	je	.L5
	movl	%r13d, %r14d
	addl	$5, %esi
	subl	%edx, %r14d
	cmpl	%esi, %eax
	je	.L6
	movl	%r14d, %edi
	movsd	%xmm2, 8(%rsp)
	subl	%edx, %edi
	call	t.part.0
	pxor	%xmm1, %xmm1
	movsd	8(%rsp), %xmm2
	cvtsi2sdl	%eax, %xmm1
.L6:
	pxor	%xmm0, %xmm0
	pxor	%xmm3, %xmm3
	cvtsi2sdl	%r14d, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm3
.L5:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r13d, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	pxor	%xmm3, %xmm3
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm3
.L4:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r12d, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	pxor	%xmm3, %xmm3
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm3
.L3:
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%ebp, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L2:
	pxor	%xmm0, %xmm0
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	cvtsi2sdl	%ebx, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	ret
	.cfi_endproc
.LFE26:
	.size	t.part.0, .-t.part.0
	.p2align 4
	.globl	h
	.type	h, @function
h:
.LFB23:
	.cfi_startproc
	endbr64
	movl	Y(%rip), %edx
	movl	%edi, %eax
	cmpl	%edx, %esi
	je	.L14
	pxor	%xmm2, %xmm2
	movsd	RATE(%rip), %xmm3
	cvtsi2sdl	FEE(%rip), %xmm2
	.p2align 4,,10
	.p2align 3
.L17:
	pxor	%xmm1, %xmm1
	addl	$1, %esi
	cvtsi2sdl	%eax, %xmm1
	movapd	%xmm1, %xmm0
	mulsd	%xmm3, %xmm0
	addsd	%xmm1, %xmm0
	subsd	%xmm2, %xmm0
	cvttsd2sil	%xmm0, %eax
	cmpl	%edx, %esi
	jne	.L17
.L14:
	ret
	.cfi_endproc
.LFE23:
	.size	h, .-h
	.p2align 4
	.globl	t
	.type	t, @function
t:
.LFB24:
	.cfi_startproc
	endbr64
	movl	Y(%rip), %eax
	cmpl	%esi, %eax
	je	.L31
	leal	1(%rsi), %edx
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movsd	RATE(%rip), %xmm4
	movl	%edi, %r8d
	pxor	%xmm1, %xmm1
	cmpl	%edx, %eax
	je	.L20
	movl	FEE(%rip), %edx
	movl	%edi, %r9d
	leal	2(%rsi), %ecx
	movapd	%xmm1, %xmm2
	subl	%edx, %r9d
	cmpl	%ecx, %eax
	je	.L21
	movl	%r9d, %r10d
	leal	3(%rsi), %ecx
	subl	%edx, %r10d
	cmpl	%ecx, %eax
	je	.L22
	movl	%r10d, %r11d
	leal	4(%rsi), %ecx
	subl	%edx, %r11d
	cmpl	%ecx, %eax
	je	.L23
	movl	%r11d, %ebx
	addl	$5, %esi
	subl	%edx, %ebx
	cmpl	%esi, %eax
	je	.L24
	movl	%ebx, %edi
	subl	%edx, %edi
	call	t.part.0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
.L24:
	pxor	%xmm0, %xmm0
	pxor	%xmm2, %xmm2
	cvtsi2sdl	%ebx, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm2
.L23:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r11d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm2, %xmm0
	pxor	%xmm2, %xmm2
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm2
.L22:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r10d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm2, %xmm0
	pxor	%xmm2, %xmm2
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm2
.L21:
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%r9d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm2, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L20:
	pxor	%xmm0, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 8
	cvtsi2sdl	%r8d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %r9d
	movl	%r9d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore 3
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	t, .-t
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d%d%d"
.LC3:
	.string	"%d%lf%d"
.LC4:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	N(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %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	$40, %rsp
	.cfi_def_cfa_offset 96
	call	__isoc99_scanf@PLT
	movl	N(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, N(%rip)
	testl	%eax, %eax
	je	.L76
	leaq	FEE(%rip), %r15
	leaq	RATE(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L37:
	leaq	Y(%rip), %rdx
	leaq	P(%rip), %rcx
	xorl	%eax, %eax
	leaq	M(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	P(%rip), %edx
	movl	$0, res(%rip)
	leal	-1(%rdx), %eax
	movl	%eax, P(%rip)
	testl	%edx, %edx
	je	.L38
	leaq	F(%rip), %rbp
	leaq	.LC3(%rip), %rbx
	jmp	.L49
	.p2align 4,,10
	.p2align 3
.L39:
	movl	Y(%rip), %eax
	movl	FEE(%rip), %esi
	movl	M(%rip), %r13d
	movl	%eax, %edx
	imull	%esi, %edx
	movl	%r13d, %r12d
	subl	%edx, %r12d
	testl	%eax, %eax
	je	.L40
	movsd	RATE(%rip), %xmm5
	pxor	%xmm1, %xmm1
	cmpl	$1, %eax
	je	.L43
	movl	%r13d, %edx
	pxor	%xmm1, %xmm1
	subl	%esi, %edx
	cmpl	$2, %eax
	je	.L44
	movl	%edx, %ecx
	subl	%esi, %ecx
	cmpl	$3, %eax
	je	.L45
	movl	%ecx, %r8d
	subl	%esi, %r8d
	cmpl	$4, %eax
	je	.L46
	movl	%r8d, %r9d
	pxor	%xmm1, %xmm1
	subl	%esi, %r9d
	cmpl	$5, %eax
	je	.L47
	movl	%r9d, %r10d
	subl	%esi, %r10d
	cmpl	$6, %eax
	je	.L48
	movl	%r10d, %r11d
	movl	%r9d, 28(%rsp)
	subl	%esi, %r11d
	movl	%r8d, 24(%rsp)
	movl	%r11d, %edi
	movl	%ecx, 20(%rsp)
	subl	%esi, %edi
	movl	$7, %esi
	movl	%edx, 16(%rsp)
	movl	%r10d, 12(%rsp)
	movl	%r11d, 8(%rsp)
	call	t
	movl	8(%rsp), %r11d
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	movl	28(%rsp), %r9d
	movl	24(%rsp), %r8d
	cvtsi2sdl	%r11d, %xmm0
	movl	20(%rsp), %ecx
	movl	16(%rsp), %edx
	movl	12(%rsp), %r10d
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L48:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r10d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm0, %xmm1
	cvttsd2sil	%xmm1, %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
.L47:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r9d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L46:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r8d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L45:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%ecx, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L44:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%edx, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L43:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r13d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	addl	%eax, %r12d
.L40:
	movl	res(%rip), %eax
	movl	%r12d, tmp(%rip)
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	movl	P(%rip), %eax
	leal	-1(%rax), %edx
	movl	%r12d, res(%rip)
	movl	%edx, P(%rip)
	testl	%eax, %eax
	je	.L78
.L49:
	movq	%r15, %rcx
	movq	%r14, %rdx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	F(%rip), %eax
	testl	%eax, %eax
	je	.L39
	movl	Y(%rip), %edx
	movl	M(%rip), %r12d
	testl	%edx, %edx
	je	.L40
	pxor	%xmm2, %xmm2
	movsd	RATE(%rip), %xmm3
	xorl	%eax, %eax
	cvtsi2sdl	FEE(%rip), %xmm2
	.p2align 4,,10
	.p2align 3
.L41:
	pxor	%xmm1, %xmm1
	addl	$1, %eax
	cvtsi2sdl	%r12d, %xmm1
	movapd	%xmm1, %xmm0
	mulsd	%xmm3, %xmm0
	addsd	%xmm1, %xmm0
	subsd	%xmm2, %xmm0
	cvttsd2sil	%xmm0, %r12d
	cmpl	%edx, %eax
	jne	.L41
	jmp	.L40
	.p2align 4,,10
	.p2align 3
.L78:
	movl	%r12d, %edx
.L38:
	leaq	.LC4(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	N(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, N(%rip)
	testl	%eax, %eax
	jne	.L37
.L76:
	addq	$40, %rsp
	.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
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	RATE
	.bss
	.align 8
	.type	RATE, @object
	.size	RATE, 8
RATE:
	.zero	8
	.globl	tmp
	.align 4
	.type	tmp, @object
	.size	tmp, 4
tmp:
	.zero	4
	.globl	res
	.align 4
	.type	res, @object
	.size	res, 4
res:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	FEE
	.align 4
	.type	FEE, @object
	.size	FEE, 4
FEE:
	.zero	4
	.globl	F
	.align 4
	.type	F, @object
	.size	F, 4
F:
	.zero	4
	.globl	P
	.align 4
	.type	P, @object
	.size	P, 4
P:
	.zero	4
	.globl	Y
	.align 4
	.type	Y, @object
	.size	Y, 4
Y:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.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	t.part.0, @function
t.part.0:
.LFB26:
	.cfi_startproc
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leal	1(%rsi), %edx
	pxor	%xmm1, %xmm1
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	%edi, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movl	Y(%rip), %eax
	movsd	RATE(%rip), %xmm2
	cmpl	%eax, %edx
	je	.L2
	movl	FEE(%rip), %edx
	movl	%edi, %ebp
	leal	2(%rsi), %ecx
	movapd	%xmm1, %xmm3
	subl	%edx, %ebp
	cmpl	%ecx, %eax
	je	.L3
	movl	%ebp, %r12d
	leal	3(%rsi), %ecx
	subl	%edx, %r12d
	cmpl	%ecx, %eax
	je	.L4
	movl	%r12d, %r13d
	leal	4(%rsi), %ecx
	subl	%edx, %r13d
	cmpl	%ecx, %eax
	je	.L5
	movl	%r13d, %r14d
	addl	$5, %esi
	subl	%edx, %r14d
	cmpl	%esi, %eax
	je	.L6
	movl	%r14d, %edi
	movsd	%xmm2, 8(%rsp)
	subl	%edx, %edi
	call	t.part.0
	pxor	%xmm1, %xmm1
	movsd	8(%rsp), %xmm2
	cvtsi2sdl	%eax, %xmm1
.L6:
	pxor	%xmm0, %xmm0
	pxor	%xmm3, %xmm3
	cvtsi2sdl	%r14d, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm3
.L5:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r13d, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	pxor	%xmm3, %xmm3
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm3
.L4:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r12d, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	pxor	%xmm3, %xmm3
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm3
.L3:
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%ebp, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm3, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L2:
	pxor	%xmm0, %xmm0
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	cvtsi2sdl	%ebx, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	ret
	.cfi_endproc
.LFE26:
	.size	t.part.0, .-t.part.0
	.p2align 4
	.globl	h
	.type	h, @function
h:
.LFB23:
	.cfi_startproc
	endbr64
	movl	Y(%rip), %edx
	movl	%edi, %eax
	cmpl	%edx, %esi
	je	.L14
	pxor	%xmm2, %xmm2
	movsd	RATE(%rip), %xmm3
	cvtsi2sdl	FEE(%rip), %xmm2
	.p2align 4,,10
	.p2align 3
.L17:
	pxor	%xmm1, %xmm1
	addl	$1, %esi
	cvtsi2sdl	%eax, %xmm1
	movapd	%xmm1, %xmm0
	mulsd	%xmm3, %xmm0
	addsd	%xmm1, %xmm0
	subsd	%xmm2, %xmm0
	cvttsd2sil	%xmm0, %eax
	cmpl	%edx, %esi
	jne	.L17
.L14:
	ret
	.cfi_endproc
.LFE23:
	.size	h, .-h
	.p2align 4
	.globl	t
	.type	t, @function
t:
.LFB24:
	.cfi_startproc
	endbr64
	movl	Y(%rip), %eax
	cmpl	%esi, %eax
	je	.L31
	leal	1(%rsi), %edx
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movsd	RATE(%rip), %xmm4
	movl	%edi, %r8d
	pxor	%xmm1, %xmm1
	cmpl	%edx, %eax
	je	.L20
	movl	FEE(%rip), %edx
	movl	%edi, %r9d
	leal	2(%rsi), %ecx
	movapd	%xmm1, %xmm2
	subl	%edx, %r9d
	cmpl	%ecx, %eax
	je	.L21
	movl	%r9d, %r10d
	leal	3(%rsi), %ecx
	subl	%edx, %r10d
	cmpl	%ecx, %eax
	je	.L22
	movl	%r10d, %r11d
	leal	4(%rsi), %ecx
	subl	%edx, %r11d
	cmpl	%ecx, %eax
	je	.L23
	movl	%r11d, %ebx
	addl	$5, %esi
	subl	%edx, %ebx
	cmpl	%esi, %eax
	je	.L24
	movl	%ebx, %edi
	subl	%edx, %edi
	call	t.part.0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
.L24:
	pxor	%xmm0, %xmm0
	pxor	%xmm2, %xmm2
	cvtsi2sdl	%ebx, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm2
.L23:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r11d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm2, %xmm0
	pxor	%xmm2, %xmm2
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm2
.L22:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r10d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm2, %xmm0
	pxor	%xmm2, %xmm2
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm2
.L21:
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%r9d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm2, %xmm0
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L20:
	pxor	%xmm0, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 8
	cvtsi2sdl	%r8d, %xmm0
	mulsd	%xmm4, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %r9d
	movl	%r9d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L31:
	.cfi_restore 3
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	t, .-t
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"%d"
.LC2:
	.string	"%d%d%d"
.LC3:
	.string	"%d%lf%d"
.LC4:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	N(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	xorl	%eax, %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	$40, %rsp
	.cfi_def_cfa_offset 96
	call	__isoc99_scanf@PLT
	movl	N(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, N(%rip)
	testl	%eax, %eax
	je	.L76
	leaq	FEE(%rip), %r15
	leaq	RATE(%rip), %r14
	.p2align 4,,10
	.p2align 3
.L37:
	leaq	Y(%rip), %rdx
	leaq	P(%rip), %rcx
	xorl	%eax, %eax
	leaq	M(%rip), %rsi
	leaq	.LC2(%rip), %rdi
	call	__isoc99_scanf@PLT
	movl	P(%rip), %edx
	movl	$0, res(%rip)
	leal	-1(%rdx), %eax
	movl	%eax, P(%rip)
	testl	%edx, %edx
	je	.L38
	leaq	F(%rip), %rbp
	leaq	.LC3(%rip), %rbx
	jmp	.L49
	.p2align 4,,10
	.p2align 3
.L39:
	movl	Y(%rip), %eax
	movl	FEE(%rip), %esi
	movl	M(%rip), %r13d
	movl	%eax, %edx
	imull	%esi, %edx
	movl	%r13d, %r12d
	subl	%edx, %r12d
	testl	%eax, %eax
	je	.L40
	movsd	RATE(%rip), %xmm5
	pxor	%xmm1, %xmm1
	cmpl	$1, %eax
	je	.L43
	movl	%r13d, %edx
	pxor	%xmm1, %xmm1
	subl	%esi, %edx
	cmpl	$2, %eax
	je	.L44
	movl	%edx, %ecx
	subl	%esi, %ecx
	cmpl	$3, %eax
	je	.L45
	movl	%ecx, %r8d
	subl	%esi, %r8d
	cmpl	$4, %eax
	je	.L46
	movl	%r8d, %r9d
	pxor	%xmm1, %xmm1
	subl	%esi, %r9d
	cmpl	$5, %eax
	je	.L47
	movl	%r9d, %r10d
	subl	%esi, %r10d
	cmpl	$6, %eax
	je	.L48
	movl	%r10d, %r11d
	movl	%r9d, 28(%rsp)
	subl	%esi, %r11d
	movl	%r8d, 24(%rsp)
	movl	%r11d, %edi
	movl	%ecx, 20(%rsp)
	subl	%esi, %edi
	movl	$7, %esi
	movl	%edx, 16(%rsp)
	movl	%r10d, 12(%rsp)
	movl	%r11d, 8(%rsp)
	call	t
	movl	8(%rsp), %r11d
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	movl	28(%rsp), %r9d
	movl	24(%rsp), %r8d
	cvtsi2sdl	%r11d, %xmm0
	movl	20(%rsp), %ecx
	movl	16(%rsp), %edx
	movl	12(%rsp), %r10d
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L48:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r10d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm0, %xmm1
	cvttsd2sil	%xmm1, %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
.L47:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r9d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L46:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r8d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L45:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%ecx, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L44:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%edx, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	pxor	%xmm1, %xmm1
	cvttsd2sil	%xmm0, %eax
	cvtsi2sdl	%eax, %xmm1
.L43:
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%r13d, %xmm0
	mulsd	%xmm5, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	addl	%eax, %r12d
.L40:
	movl	res(%rip), %eax
	movl	%r12d, tmp(%rip)
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	movl	P(%rip), %eax
	leal	-1(%rax), %edx
	movl	%r12d, res(%rip)
	movl	%edx, P(%rip)
	testl	%eax, %eax
	je	.L78
.L49:
	movq	%r15, %rcx
	movq	%r14, %rdx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	F(%rip), %eax
	testl	%eax, %eax
	je	.L39
	movl	Y(%rip), %edx
	movl	M(%rip), %r12d
	testl	%edx, %edx
	je	.L40
	pxor	%xmm2, %xmm2
	movsd	RATE(%rip), %xmm3
	xorl	%eax, %eax
	cvtsi2sdl	FEE(%rip), %xmm2
	.p2align 4,,10
	.p2align 3
.L41:
	pxor	%xmm1, %xmm1
	addl	$1, %eax
	cvtsi2sdl	%r12d, %xmm1
	movapd	%xmm1, %xmm0
	mulsd	%xmm3, %xmm0
	addsd	%xmm1, %xmm0
	subsd	%xmm2, %xmm0
	cvttsd2sil	%xmm0, %r12d
	cmpl	%edx, %eax
	jne	.L41
	jmp	.L40
	.p2align 4,,10
	.p2align 3
.L78:
	movl	%r12d, %edx
.L38:
	leaq	.LC4(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	N(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, N(%rip)
	testl	%eax, %eax
	jne	.L37
.L76:
	addq	$40, %rsp
	.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
	.cfi_endproc
.LFE25:
	.size	main, .-main
	.globl	RATE
	.bss
	.align 8
	.type	RATE, @object
	.size	RATE, 8
RATE:
	.zero	8
	.globl	tmp
	.align 4
	.type	tmp, @object
	.size	tmp, 4
tmp:
	.zero	4
	.globl	res
	.align 4
	.type	res, @object
	.size	res, 4
res:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	FEE
	.align 4
	.type	FEE, @object
	.size	FEE, 4
FEE:
	.zero	4
	.globl	F
	.align 4
	.type	F, @object
	.size	F, 4
F:
	.zero	4
	.globl	P
	.align 4
	.type	P, @object
	.size	P, 4
P:
	.zero	4
	.globl	Y
	.align 4
	.type	Y, @object
	.size	Y, 4
Y:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.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>
int N,M,Y,P,F,FEE,i,res,tmp;
double RATE;

int h(int m,int y)
{
	if(y==Y)
		return m;
	else
		return h(m+m*RATE-FEE,y+1);
}

int t(int m,int y)
{
	if(y==Y)
		return 0;
	return t(m-FEE,y+1)+m*RATE;
}

int main()
{
	for(scanf("%d",&N);N--;)
	{
		scanf("%d%d%d",&M,&Y,&P);
		for(res=0;P--;)
		{
			scanf("%d%lf%d",&F,&RATE,&FEE);
			tmp=F?h(M,0):M-Y*FEE+t(M,0);
			res=res<tmp?tmp:res;
		}
		printf("%d\n",res);
	}
	return 0;
}
4
1000000
5
2
0 0.03125 3000
1 0.03125 3000
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
39677000
4
4
0 0.0709228515625 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 98193
0 0.0887451171875 78966
 4
1000000
5
2
0 0.03125 3000
1 0.03125 3000
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
39677000
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 98193
0 0.0887451171875 78966
 4
1000000
5
2
0 0.03125 3000
1 0.03125 3825
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
39677000
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 98193
0 0.0887451171875 78966
 4
1000000
5
2
0 0.03125 3000
1 0.03125 3825
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
56271855
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 98193
0 0.0887451171875 78966
 4
1000000
5
2
0 0.03125 3000
1 0.17615020446016216 3825
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
56271855
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 44107
0 0.0887451171875 78966
 4
1000000
5
2
0 0.03125 3000
1 0.17615020446016216 3825
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
56271855
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 44107
0 0.3973222802879146 78966
 4
1000000
5
2
0 0.03125 3000
1 0.17615020446016216 3825
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
56271855
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.583712682805818 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 44107
0 0.3973222802879146 78966
 4
1000000
5
2
0 0.03125 3000
1 0.17615020446016216 3825
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
56271855
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
1 0.583712682805818 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 44107
0 0.3973222802879146 78966
 4
1000000
5
2
0 0.03125 4950
1 0.03125 3000
6620000
7
2
0 0.0732421875 42307
1 0.0740966796875 40942
39677000
4
4
0 0.0709228515625 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 0.0496826171875 98193
0 0.0887451171875 78966
 4
1000000
5
2
0 0.03125 3000
1 0.03125 3825
6620000
7
2
0 0.0732421875 42307
0 0.0740966796875 40942
56271855
4
4
0 0.19624457693261887 30754
1 0.00634765625 26165
0 0.03662109375 79468
0 0.0679931640625 10932
10585000
6
4
1 0.0054931640625 59759
1 0.12353515625 56464
0 1.0362451886969601 44107
0 0.0887451171875 78966

1150357
9703337
50796918
20829397
 1150357
9703337
70663355
20829397
 1145966
9703337
70663355
20829397
 1145966
9703337
100284811
20829397
 2223521
9703337
100284811
20829397
 2223521
9703337
100284811
34874515
 2223521
9703337
187576221
34874515
 2223521
9703337
353895649
34874515
 1150357
10559683
50796918
20829397
 1145966
9703337
100284811
75446701

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>
int N,M,Y,P,F,FEE,i,res,tmp;
double RATE;

int h(int m,int y)
{
	if(y==Y)
		return m;
	else
		return h(m+m*RATE-FEE,y+1);
}

int t(int m,int y)
{
	if(y==Y)
		return 0;
	return t(m-FEE,y+1)+m*RATE;
}

int main()
{
	for(scanf("%d",&N);N--;)
	{
		scanf("%d%d%d",&M,&Y,&P);
		for(res=0;P--;)
		{
			scanf("%d%lf%d",&F,&RATE,&FEE);
			tmp=F?h(M,0):M-Y*FEE+t(M,0);
			res=res<tmp?tmp:res;
		}
		printf("%d\n",res);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	N
	.bss
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	Y
	.align 4
	.type	Y, @object
	.size	Y, 4
Y:
	.zero	4
	.globl	P
	.align 4
	.type	P, @object
	.size	P, 4
P:
	.zero	4
	.globl	F
	.align 4
	.type	F, @object
	.size	F, 4
F:
	.zero	4
	.globl	FEE
	.align 4
	.type	FEE, @object
	.size	FEE, 4
FEE:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	res
	.align 4
	.type	res, @object
	.size	res, 4
res:
	.zero	4
	.globl	tmp
	.align 4
	.type	tmp, @object
	.size	tmp, 4
tmp:
	.zero	4
	.globl	RATE
	.align 8
	.type	RATE, @object
	.size	RATE, 8
RATE:
	.zero	8
	.text
	.globl	h
	.type	h, @function
h:
.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)
	movl	Y(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	pxor	%xmm1, %xmm1
	cvtsi2sdl	-4(%rbp), %xmm1
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4(%rbp), %xmm2
	movsd	RATE(%rip), %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	movl	FEE(%rip), %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	subsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	h
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	h, .-h
	.globl	t
	.type	t, @function
t:
.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	Y(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jne	.L5
	movl	$0, %eax
	jmp	.L6
.L5:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	movl	FEE(%rip), %ecx
	movl	-4(%rbp), %eax
	subl	%ecx, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	t
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4(%rbp), %xmm2
	movsd	RATE(%rip), %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	t, .-t
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d%d"
.LC2:
	.string	"%d%lf%d"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.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	$8, %rsp
	.cfi_offset 3, -24
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L8
.L13:
	leaq	P(%rip), %rax
	movq	%rax, %rcx
	leaq	Y(%rip), %rax
	movq	%rax, %rdx
	leaq	M(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, res(%rip)
	jmp	.L9
.L12:
	leaq	FEE(%rip), %rax
	movq	%rax, %rcx
	leaq	RATE(%rip), %rax
	movq	%rax, %rdx
	leaq	F(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	F(%rip), %eax
	testl	%eax, %eax
	je	.L10
	movl	M(%rip), %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	h
	jmp	.L11
.L10:
	movl	M(%rip), %eax
	movl	Y(%rip), %ecx
	movl	FEE(%rip), %edx
	imull	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, %ebx
	movl	M(%rip), %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	t
	addl	%ebx, %eax
.L11:
	movl	%eax, tmp(%rip)
	movl	res(%rip), %edx
	movl	tmp(%rip), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, res(%rip)
.L9:
	movl	P(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, P(%rip)
	testl	%eax, %eax
	jne	.L12
	movl	res(%rip), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L8:
	movl	N(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, N(%rip)
	testl	%eax, %eax
	jne	.L13
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.globl	M
	.align 4
	.type	M, @object
	.size	M, 4
M:
	.zero	4
	.globl	Y
	.align 4
	.type	Y, @object
	.size	Y, 4
Y:
	.zero	4
	.globl	P
	.align 4
	.type	P, @object
	.size	P, 4
P:
	.zero	4
	.globl	F
	.align 4
	.type	F, @object
	.size	F, 4
F:
	.zero	4
	.globl	FEE
	.align 4
	.type	FEE, @object
	.size	FEE, 4
FEE:
	.zero	4
	.globl	i
	.align 4
	.type	i, @object
	.size	i, 4
i:
	.zero	4
	.globl	res
	.align 4
	.type	res, @object
	.size	res, 4
res:
	.zero	4
	.globl	tmp
	.align 4
	.type	tmp, @object
	.size	tmp, 4
tmp:
	.zero	4
	.globl	RATE
	.align 8
	.type	RATE, @object
	.size	RATE, 8
RATE:
	.zero	8
	.text
	.globl	h
	.type	h, @function
h:
.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)
	movl	Y(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jne	.L2
	movl	-4(%rbp), %eax
	jmp	.L3
.L2:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	pxor	%xmm1, %xmm1
	cvtsi2sdl	-4(%rbp), %xmm1
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4(%rbp), %xmm2
	movsd	RATE(%rip), %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	movl	FEE(%rip), %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	subsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	h
.L3:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	h, .-h
	.globl	t
	.type	t, @function
t:
.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	Y(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jne	.L5
	movl	$0, %eax
	jmp	.L6
.L5:
	movl	-8(%rbp), %eax
	leal	1(%rax), %edx
	movl	FEE(%rip), %ecx
	movl	-4(%rbp), %eax
	subl	%ecx, %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	t
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4(%rbp), %xmm2
	movsd	RATE(%rip), %xmm0
	mulsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	t, .-t
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d%d%d"
.LC2:
	.string	"%d%lf%d"
.LC3:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.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	$8, %rsp
	.cfi_offset 3, -24
	leaq	N(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L8
.L13:
	leaq	P(%rip), %rax
	movq	%rax, %rcx
	leaq	Y(%rip), %rax
	movq	%rax, %rdx
	leaq	M(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, res(%rip)
	jmp	.L9
.L12:
	leaq	FEE(%rip), %rax
	movq	%rax, %rcx
	leaq	RATE(%rip), %rax
	movq	%rax, %rdx
	leaq	F(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	F(%rip), %eax
	testl	%eax, %eax
	je	.L10
	movl	M(%rip), %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	h
	jmp	.L11
.L10:
	movl	M(%rip), %eax
	movl	Y(%rip), %ecx
	movl	FEE(%rip), %edx
	imull	%ecx, %edx
	subl	%edx, %eax
	movl	%eax, %ebx
	movl	M(%rip), %eax
	movl	$0, %esi
	movl	%eax, %edi
	call	t
	addl	%ebx, %eax
.L11:
	movl	%eax, tmp(%rip)
	movl	res(%rip), %edx
	movl	tmp(%rip), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%eax, res(%rip)
.L9:
	movl	P(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, P(%rip)
	testl	%eax, %eax
	jne	.L12
	movl	res(%rip), %eax
	movl	%eax, %esi
	leaq	.LC3(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L8:
	movl	N(%rip), %eax
	leal	-1(%rax), %edx
	movl	%edx, N(%rip)
	testl	%eax, %eax
	jne	.L13
	movl	$0, %eax
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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:
