// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/tests/integer.c
// Function: verify_mul_div
static void verify_mul_div(int count)
{
	printf("Mul & Div...\n");

	struct tt_int *a = tt_int_alloc();
	struct tt_int *b = tt_int_alloc();
	struct tt_int *q = tt_int_alloc();
	struct tt_int *r = tt_int_alloc();

	for (int i = 1; i <= count; i++) {
		if (i % 50 == 0) {
			tt_int_free(a);
			tt_int_free(b);
			tt_int_free(q);
			tt_int_free(r);

			a = tt_int_alloc();
			b = tt_int_alloc();
			q = tt_int_alloc();
			r = tt_int_alloc();
		}

		int ret, radix;
		char *str;

		/* Generate a, b */
		str = gen_int_str(&radix);
		tt_int_from_string(a, str);
		free(str);
		str = gen_int_str(&radix);
		tt_int_from_string(b, str);
		free(str);

		if (a->msb < b->msb) {
			void *t = a;
			a = b;
			b = t;
		}

		/* q = a / b, r = a % b */
#if 1
		ret = tt_int_div(q, r, a, b);
#else
		ret = tt_int_div(NULL, r, a, b);
		ret = tt_int_div(q, NULL, a, b);
#endif
		assert(ret == 0 && _tt_int_sanity(q) == 0 &&
				_tt_int_sanity(r) == 0);

		/* b = q * b + r */
		ret = tt_int_mul(b, q, b);
		assert(ret == 0 && _tt_int_sanity(b) == 0);
		ret = tt_int_add(b, b, r);

		/* a == b */
		if (tt_int_cmp(a, b)) {
			tt_error("mismatch");
			break;
		}
	}

	tt_int_free(a);
	tt_int_free(b);
	tt_int_free(q);
	tt_int_free(r);
}

// Assembly:
subq $0x48, %rsp
movl %edi, 0x44(%rsp)
leaq 0x10533(%rip), %rdi     # 0x13252
movb $0x0, %al
callq 0x20c0
callq 0x7a50
movq %rax, 0x38(%rsp)
callq 0x7a50
movq %rax, 0x30(%rsp)
callq 0x7a50
movq %rax, 0x28(%rsp)
callq 0x7a50
movq %rax, 0x20(%rsp)
movl $0x1, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x44(%rsp), %eax
jg 0x2f4c
movl 0x1c(%rsp), %eax
movl $0x32, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x2dc5
movq 0x38(%rsp), %rdi
callq 0x7b00
movq 0x30(%rsp), %rdi
callq 0x7b00
movq 0x28(%rsp), %rdi
callq 0x7b00
movq 0x20(%rsp), %rdi
callq 0x7b00
callq 0x7a50
movq %rax, 0x38(%rsp)
callq 0x7a50
movq %rax, 0x30(%rsp)
callq 0x7a50
movq %rax, 0x28(%rsp)
callq 0x7a50
movq %rax, 0x20(%rsp)
leaq 0x14(%rsp), %rdi
callq 0x2f80
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x82e0
movq 0x8(%rsp), %rdi
callq 0x2030
leaq 0x14(%rsp), %rdi
callq 0x2f80
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x82e0
movq 0x8(%rsp), %rdi
callq 0x2030
movq 0x38(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x30(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x2e43
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x38(%rsp)
movq (%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xbcd0
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x18(%rsp)
jne 0x2e87
movq 0x28(%rsp), %rdi
callq 0x7dc0
cmpl $0x0, %eax
jne 0x2e87
movq 0x20(%rsp), %rdi
callq 0x7dc0
cmpl $0x0, %eax
jne 0x2e87
jmp 0x2ea6
leaq 0x103d2(%rip), %rdi     # 0x13260
leaq 0x10275(%rip), %rsi     # 0x1310a
movl $0xe3, %edx
leaq 0x103fc(%rip), %rcx     # 0x1329d
callq 0x20e0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0xbb10
movl %eax, 0x18(%rsp)
cmpl $0x0, 0x18(%rsp)
jne 0x2ed6
movq 0x30(%rsp), %rdi
callq 0x7dc0
cmpl $0x0, %eax
jne 0x2ed6
jmp 0x2ef5
leaq 0x1033a(%rip), %rdi     # 0x13217
leaq 0x10226(%rip), %rsi     # 0x1310a
movl $0xe7, %edx
leaq 0x103ad(%rip), %rcx     # 0x1329d
callq 0x20e0
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0xb9a0
movl %eax, 0x18(%rsp)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0xc270
cmpl $0x0, %eax
je 0x2f3a
xorl %edi, %edi
leaq 0x1038c(%rip), %rsi     # 0x132b6
leaq 0x10318(%rip), %rdx     # 0x13249
movb $0x0, %al
callq 0xf260
jmp 0x2f4c
jmp 0x2f3c
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x2d56
movq 0x38(%rsp), %rdi
callq 0x7b00
movq 0x30(%rsp), %rdi
callq 0x7b00
movq 0x28(%rsp), %rdi
callq 0x7b00
movq 0x20(%rsp), %rdi
callq 0x7b00
addq $0x48, %rsp
retq
nopl (%rax)