// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/tests/decimal.c
// Function: verify_add
static void verify_add(int count)
{
	bool fail = false;
	char s[1024];
	struct tt_dec *dec1, *dec2, *dec3;

	int old_level = tt_log_set_level(TT_LOG_WARN);

	/* Special case */
	dec1 = tt_dec_alloc(0);
	dec2 = tt_dec_alloc(0);
	dec3 = tt_dec_alloc(0);
	const struct {
		const char *add1, *add2, *result;
	} cases[] = {
		{ "0", "0", "0", },
		{ "0E-10", "0", "0E-10" },
		{ "0E-2000", "0", "0E-2000" },
		{ "0E-20", "0E-10", "0E-20" },
		{ "0E-20", "0E-1000", "0E-1000" },
		{ "-0", "0", "-0", },
		{ "0E-10", "-0", "-0E-10" },
		{ "-0E-2000", "0", "0E-2000" },
		{ "0E-20", "-0E-10", "-0E-20" },
		{ "-0E-20", "0E-1000", "-0E-1000" },
	};
	for (int i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) {
		tt_dec_from_string(dec1, cases[i].add1);
		tt_dec_from_string(dec2, cases[i].add2);
		tt_dec_add(dec3, dec1, dec2);
		tt_dec_to_string(dec3, s, 360);
		if (_tt_dec_sanity(dec3)) {
			tt_error("Sanity error");
			fail = true;
			break;
		}
		if (strcmp(s, cases[i].result)) {
			tt_error("%s + %s => %s",
					cases[i].add1, cases[i].add2, s);
			fail = true;
			break;
		}
	}
	tt_dec_free(dec1);
	tt_dec_free(dec2);
	tt_dec_free(dec3);
	if (fail)
		return;

	/* Big number */
	printf("Add big number...\n");
	dec1 = tt_dec_alloc(30);
	dec2 = tt_dec_alloc(50);
	dec3 = tt_dec_alloc(40);
	for (int i = 0; i < count; i++) {
		double d1, d2;
		long double ld;
		char s1[128], s2[128];
		ld = get_num(s1, 1, 100);
		tt_dec_from_string(dec1, s1);
		ld += get_num(s2, 1, 100);
		tt_dec_from_string(dec2, s2);
		double prec = 1E-15;
		if (dec1->_sign != dec2->_sign)
			prec = 1E-14;
		tt_dec_add(dec3, dec2, dec1);
		tt_dec_add(dec2, dec1, dec2);
		tt_dec_to_float(dec3, &d1);
		tt_dec_to_float(dec2, &d2);

		if (_tt_dec_sanity(dec1) || _tt_dec_sanity(dec2) ||
				_tt_dec_sanity(dec3)) {
			tt_error("Sanity error");
			fail = true;
			break;
		}

		if (!deq(ld, d1, prec) || !deq(ld, d2, prec)) {
			tt_warn("Num add mismatch: %s + %s\nMach: %.18LE\n"
					"DEC:  %.18E\nDEC:  %.18E",
					s1, s2, ld, d1, d2);
		}
	}

	tt_dec_free(dec1);
	tt_dec_free(dec2);
	tt_dec_free(dec3);
	if (fail)
		return;

#ifdef __STDC_IEC_559__
	/* Random float */
	printf("Add float...\n");
	dec1 = tt_dec_alloc(0);
	dec2 = tt_dec_alloc(0);
	dec3 = tt_dec_alloc(0);

	for (int i = 0; i < count; i++) {
		double d1 = gen_float(307);
		double d2 = gen_float(307);
		double prec = 1E-15;
		if (signbit(d1) != signbit(d2))
			prec = 1E-14;

		tt_dec_from_float(dec1, d1);
		tt_dec_from_float(dec2, d2);

		tt_dec_add(dec3, dec1, dec2);
		tt_dec_add(dec1, dec2, dec1);

		if (_tt_dec_sanity(dec1) || _tt_dec_sanity(dec2) ||
				_tt_dec_sanity(dec3)) {
			tt_error("Sanity error");
			fail = true;
			break;
		}

		double vd1, vd2;
		tt_dec_to_float(dec3, &vd1);
		tt_dec_to_float(dec1, &vd2);

		double ds = d1 + d2;
		if (!deq(vd1, ds, prec) || !deq(vd2, ds, prec)) {
			tt_warn("Float add mismatch: %.18E + %.18E\n"
					"Mach: %.18E\nDEC:  %.18E\nDEC:  %.18E",
					d1, d2, ds, vd1, vd2);
		}
	}
	tt_dec_free(dec1);
	tt_dec_free(dec2);
	tt_dec_free(dec3);
#endif

	tt_log_set_level(old_level);
}

// Assembly:
subq $0x6b8, %rsp            # imm = 0x6B8
movl %edi, 0x6b4(%rsp)
movb $0x0, 0x6b3(%rsp)
movl $0x1, %edi
callq 0x10ac0
movl %eax, 0x294(%rsp)
xorl %edi, %edi
callq 0x4660
movq %rax, 0x2a8(%rsp)
xorl %edi, %edi
callq 0x4660
movq %rax, 0x2a0(%rsp)
xorl %edi, %edi
callq 0x4660
movq %rax, 0x298(%rsp)
leaq 0x1a0(%rsp), %rdi
leaq 0x2264d(%rip), %rsi     # 0x24af0
movl $0xf0, %edx
callq 0x2150
movl $0x0, 0x19c(%rsp)
movslq 0x19c(%rsp), %rax
cmpq $0xa, %rax
jae 0x2629
movq 0x2a8(%rsp), %rdi
movslq 0x19c(%rsp), %rcx
leaq 0x1a0(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x5690
movq 0x2a0(%rsp), %rdi
movslq 0x19c(%rsp), %rcx
leaq 0x1a0(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x5690
movq 0x298(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
movq 0x2a0(%rsp), %rdx
callq 0x6250
movq 0x298(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
movl $0x168, %edx            # imm = 0x168
callq 0x5dc0
movq 0x298(%rsp), %rdi
callq 0x4850
cmpl $0x0, %eax
je 0x2586
xorl %edi, %edi
leaq 0x12b08(%rip), %rsi     # 0x15073
leaq 0x12b0c(%rip), %rdx     # 0x1507e
movb $0x0, %al
callq 0x10770
movb $0x1, 0x6b3(%rsp)
jmp 0x2629
leaq 0x2b0(%rsp), %rdi
movslq 0x19c(%rsp), %rcx
leaq 0x1a0(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
callq 0x2120
cmpl $0x0, %eax
je 0x2611
movslq 0x19c(%rsp), %rcx
leaq 0x1a0(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movslq 0x19c(%rsp), %rdx
leaq 0x1a0(%rsp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq 0x8(%rax), %r8
leaq 0x2b0(%rsp), %r9
xorl %edi, %edi
leaq 0x12a7a(%rip), %rsi     # 0x15073
leaq 0x12a8b(%rip), %rdx     # 0x1508b
movb $0x0, %al
callq 0x10770
movb $0x1, 0x6b3(%rsp)
jmp 0x2629
jmp 0x2613
movl 0x19c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x19c(%rsp)
jmp 0x24b8
movq 0x2a8(%rsp), %rdi
callq 0x47e0
movq 0x2a0(%rsp), %rdi
callq 0x47e0
movq 0x298(%rsp), %rdi
callq 0x47e0
testb $0x1, 0x6b3(%rsp)
je 0x265f
jmp 0x2b76
leaq 0x12a33(%rip), %rdi     # 0x15099
movb $0x0, %al
callq 0x20c0
movl $0x1e, %edi
callq 0x4660
movq %rax, 0x2a8(%rsp)
movl $0x32, %edi
callq 0x4660
movq %rax, 0x2a0(%rsp)
movl $0x28, %edi
callq 0x4660
movq %rax, 0x298(%rsp)
movl $0x0, 0x198(%rsp)
movl 0x198(%rsp), %eax
cmpl 0x6b4(%rsp), %eax
jge 0x28d8
leaq 0xf0(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movl $0x1, %esi
movl %esi, 0x18(%rsp)
movl $0x64, %edx
movl %edx, 0x1c(%rsp)
callq 0x4230
movq 0x10(%rsp), %rsi
fstpt 0x170(%rsp)
movq 0x2a8(%rsp), %rdi
callq 0x5690
movl 0x18(%rsp), %esi
movl 0x1c(%rsp), %edx
leaq 0x70(%rsp), %rdi
callq 0x4230
fldt 0x170(%rsp)
faddp %st, %st(1)
fstpt 0x170(%rsp)
movq 0x2a0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x5690
movsd 0x128cd(%rip), %xmm0    # 0x15008
movsd %xmm0, 0x68(%rsp)
movq 0x2a8(%rsp), %rax
movswl (%rax), %eax
movq 0x2a0(%rsp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
je 0x2769
movsd 0x128ad(%rip), %xmm0    # 0x15010
movsd %xmm0, 0x68(%rsp)
movq 0x298(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
movq 0x2a8(%rsp), %rdx
callq 0x6250
movq 0x2a0(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
movq 0x2a0(%rsp), %rdx
callq 0x6250
movq 0x298(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x52a0
movq 0x2a0(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x52a0
movq 0x2a8(%rsp), %rdi
callq 0x4850
cmpl $0x0, %eax
jne 0x2803
movq 0x2a0(%rsp), %rdi
callq 0x4850
cmpl $0x0, %eax
jne 0x2803
movq 0x298(%rsp), %rdi
callq 0x4850
cmpl $0x0, %eax
je 0x2827
xorl %edi, %edi
leaq 0x12867(%rip), %rsi     # 0x15073
leaq 0x1286b(%rip), %rdx     # 0x1507e
movb $0x0, %al
callq 0x10770
movb $0x1, 0x6b3(%rsp)
jmp 0x28d8
fldt 0x170(%rsp)
fstpl 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x190(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
callq 0x4360
testb $0x1, %al
jne 0x2852
jmp 0x287b
fldt 0x170(%rsp)
fstpl 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd 0x188(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
callq 0x4360
testb $0x1, %al
jne 0x28c0
leaq 0xf0(%rsp), %rcx
leaq 0x70(%rsp), %r8
fldt 0x170(%rsp)
movsd 0x190(%rsp), %xmm0
movsd 0x188(%rsp), %xmm1
movq %rsp, %rax
fstpt (%rax)
leaq 0x127c6(%rip), %rsi     # 0x15073
leaq 0x127f8(%rip), %rdx     # 0x150ac
movl $0x1, %edi
movb $0x2, %al
callq 0x10770
jmp 0x28c2
movl 0x198(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x198(%rsp)
jmp 0x26ae
movq 0x2a8(%rsp), %rdi
callq 0x47e0
movq 0x2a0(%rsp), %rdi
callq 0x47e0
movq 0x298(%rsp), %rdi
callq 0x47e0
testb $0x1, 0x6b3(%rsp)
je 0x290e
jmp 0x2b76
leaq 0x127d6(%rip), %rdi     # 0x150eb
movb $0x0, %al
callq 0x20c0
xorl %edi, %edi
callq 0x4660
movq %rax, 0x2a8(%rsp)
xorl %edi, %edi
callq 0x4660
movq %rax, 0x2a0(%rsp)
xorl %edi, %edi
callq 0x4660
movq %rax, 0x298(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x6b4(%rsp), %eax
jge 0x2b43
movl $0x133, %edi            # imm = 0x133
callq 0x44f0
movsd %xmm0, 0x58(%rsp)
movl $0x133, %edi            # imm = 0x133
callq 0x44f0
movsd %xmm0, 0x50(%rsp)
movsd 0x1267e(%rip), %xmm0    # 0x15008
movsd %xmm0, 0x48(%rsp)
movsd 0x58(%rsp), %xmm0
movq %xmm0, %rax
cmpq $0x0, %rax
setl %al
andb $0x1, %al
movzbl %al, %eax
movsd 0x50(%rsp), %xmm0
movq %xmm0, %rcx
cmpq $0x0, %rcx
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x29d1
movsd 0x12645(%rip), %xmm0    # 0x15010
movsd %xmm0, 0x48(%rsp)
movq 0x2a8(%rsp), %rdi
movsd 0x58(%rsp), %xmm0
callq 0x4e10
movq 0x2a0(%rsp), %rdi
movsd 0x50(%rsp), %xmm0
callq 0x4e10
movq 0x298(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
movq 0x2a0(%rsp), %rdx
callq 0x6250
movq 0x2a8(%rsp), %rdi
movq 0x2a0(%rsp), %rsi
movq 0x2a8(%rsp), %rdx
callq 0x6250
movq 0x2a8(%rsp), %rdi
callq 0x4850
cmpl $0x0, %eax
jne 0x2a67
movq 0x2a0(%rsp), %rdi
callq 0x4850
cmpl $0x0, %eax
jne 0x2a67
movq 0x298(%rsp), %rdi
callq 0x4850
cmpl $0x0, %eax
je 0x2a8b
xorl %edi, %edi
leaq 0x12603(%rip), %rsi     # 0x15073
leaq 0x12607(%rip), %rdx     # 0x1507e
movb $0x0, %al
callq 0x10770
movb $0x1, 0x6b3(%rsp)
jmp 0x2b43
movq 0x298(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x52a0
movq 0x2a8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x52a0
movsd 0x58(%rsp), %xmm0
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
callq 0x4360
testb $0x1, %al
jne 0x2ade
jmp 0x2af9
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
callq 0x4360
testb $0x1, %al
jne 0x2b31
movsd 0x58(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
movl $0x1, %edi
leaq 0x12550(%rip), %rsi     # 0x15073
leaq 0x125cf(%rip), %rdx     # 0x150f9
movb $0x5, %al
callq 0x10770
jmp 0x2b33
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x2951
movq 0x2a8(%rsp), %rdi
callq 0x47e0
movq 0x2a0(%rsp), %rdi
callq 0x47e0
movq 0x298(%rsp), %rdi
callq 0x47e0
movl 0x294(%rsp), %edi
callq 0x10ac0
addq $0x6b8, %rsp            # imm = 0x6B8
retq
nop