// File: /workspace/github_c_makefile_star2_O0/983[P]bigint/tests.c
// Function: main
int main(){
    int i, j;
    char buf[65536];
    bigint a[1], b[1], c[1], d[1], e[20];
    const char *text = "123456790123456790120987654320987654321";

    bigint_init(a);
    bigint_init(b);
    bigint_init(c);
    bigint_init(d);

    for (i = 0; i < 20; i++) bigint_init(e + i);

    bigint_from_str(a, text);
    bigint_from_str(b, "11111111111111111111");
    bigint_sqrt(c, a);
    assert(bigint_cmp(b, c) == 0);

    bigint_from_str(a, "1");
    bigint_from_word(b, 1);
    bigint_shift_left(a, a, 1 << 10);

    bigint_mul(c, a, a);
    bigint_sub(c, c, a);
    bigint_sub(c, c, a);
    bigint_add(c, c, b);

    bigint_sub(a, a, b);
    bigint_mul(d, a, a);

    assert(bigint_cmp(c, d) == 0);

    bigint_from_str_base(a, text, 10);

    i = strcmp(text, bigint_write(buf, sizeof(buf), a));
    assert(i == 0);

    bigint_from_int(a, INT_MIN);
    assert(bigint_double(a) == INT_MIN);

    /* max integer value that fits into double without loss of precision */
    /* pow(2, 53) = 9007199254740992 */
    bigint_from_str(a, "-9007199254740992");
    assert(bigint_double(a) == -9007199254740992.0);

    bigint_from_int(a, 0);
    assert(bigint_double(a) == 0.0);
    bigint_from_int(a, +1);
    assert(bigint_double(a) == +1);
    bigint_from_int(a, -1);
    assert(bigint_double(a) == -1);

    bigint_from_str(a, "");
    bigint_from_str(b, "0");
    bigint_from_str(c, "-0");
    assert(bigint_cmp(a, b) == 0);
    assert(bigint_cmp(a, c) == 0);

    for (i = 0; i < 12345; i++){
        int x = rand() % 12345;
        int y = rand() % 12345;
        int shift = rand() % 1234;
        if (rand() & 1) x = -x;
        if (rand() & 1) y = -y;

        bigint_from_int(a, x);
        bigint_from_int(b, y);
        bigint_from_int(e + 0, x + y);
        bigint_from_int(e + 1, x - y);
        bigint_from_int(e + 2, x * y);

        if (y != 0){
            bigint_from_int(e + 3, x / y);
            bigint_from_int(e + 4, x % y);
        }

        bigint_from_int(e + 5, sqrt(x > 0 ? x : -x));
        bigint_from_int(e + 6, bigint_int_gcd(x, y));

        bigint_cpy(c, a);
        bigint_shift_left(a, a, shift);
        bigint_shift_right(a, a, shift);

        assert(bigint_cmp(a, c) == 0);

        bigint_add(e + 10, a, b);
        bigint_sub(e + 11, a, b);
        bigint_mul(e + 12, a, b);
        bigint_div(e + 13, a, b);
        bigint_mod(e + 14, a, b);
        bigint_sqrt(e + 15, a);
        bigint_gcd(e + 16, a, b);

        for (j = 0; j < 7; j++){
            if (y == 0 && (j == 3 || j == 4)) continue;
            if (bigint_cmp(e + j, e + j + 10) != 0){
                printf("i %i, j %i failed for bigints %i, %i\n", i, j, x, y);
            }
            assert(bigint_cmp(e + j, e + j + 10) == 0);
        }
    }

    bigint_free(a);
    bigint_free(b);
    bigint_free(c);
    bigint_free(d);

    for (i = 0; i < 20; i++) bigint_free(e + i);

    puts("tests passed");

    return 0;
}

// Assembly:
subq $0x102b8, %rsp          # imm = 0x102B8
movl $0x0, 0x102b4(%rsp)
leaq 0x4dff(%rip), %rax      # 0x6028
movq %rax, 0x38(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x20a0
leaq 0x260(%rsp), %rdi
callq 0x20a0
leaq 0x240(%rsp), %rdi
callq 0x20a0
leaq 0x220(%rsp), %rdi
callq 0x20a0
movl $0x0, 0x102b0(%rsp)
cmpl $0x14, 0x102b0(%rsp)
jge 0x12a3
leaq 0x40(%rsp), %rdi
movslq 0x102b0(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x20a0
movl 0x102b0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x102b0(%rsp)
jmp 0x126d
leaq 0x280(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3990
leaq 0x260(%rsp), %rdi
leaq 0x4d8c(%rip), %rsi      # 0x6050
callq 0x3990
leaq 0x240(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x4e40
leaq 0x260(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x12fa
jmp 0x1319
leaq 0x4d64(%rip), %rdi      # 0x6065
leaq 0x4d73(%rip), %rsi      # 0x607b
movl $0x19, %edx
leaq 0x4d6f(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
leaq 0x4e06(%rip), %rsi      # 0x612e
callq 0x3990
leaq 0x260(%rsp), %rdi
movl $0x1, %esi
callq 0x3a60
leaq 0x280(%rsp), %rdi
leaq 0x280(%rsp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x44d0
leaq 0x240(%rsp), %rdi
leaq 0x280(%rsp), %rsi
leaq 0x280(%rsp), %rdx
callq 0x3680
leaq 0x240(%rsp), %rdi
leaq 0x240(%rsp), %rsi
leaq 0x280(%rsp), %rdx
callq 0x3de0
leaq 0x240(%rsp), %rdi
leaq 0x240(%rsp), %rsi
leaq 0x280(%rsp), %rdx
callq 0x3de0
leaq 0x240(%rsp), %rdi
leaq 0x240(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x3da0
leaq 0x280(%rsp), %rdi
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x3de0
leaq 0x220(%rsp), %rdi
leaq 0x280(%rsp), %rsi
leaq 0x280(%rsp), %rdx
callq 0x3680
leaq 0x240(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x1423
jmp 0x1442
leaq 0x4c64(%rip), %rdi      # 0x608e
leaq 0x4c4a(%rip), %rsi      # 0x607b
movl $0x27, %edx
leaq 0x4c46(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0xa, %edx
callq 0x38c0
movq 0x38(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x2a0(%rsp), %rdi
leaq 0x280(%rsp), %rdx
movl $0x10000, %esi          # imm = 0x10000
callq 0x5220
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x10a0
movl %eax, 0x102b0(%rsp)
cmpl $0x0, 0x102b0(%rsp)
jne 0x149d
jmp 0x14bc
leaq 0x4c00(%rip), %rdi      # 0x60a4
leaq 0x4bd0(%rip), %rsi      # 0x607b
movl $0x2c, %edx
leaq 0x4bcc(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
movl $0x80000000, %esi       # imm = 0x80000000
callq 0x39c0
leaq 0x280(%rsp), %rdi
callq 0x59b0
movsd 0x4b25(%rip), %xmm1     # 0x6008
ucomisd %xmm1, %xmm0
jne 0x14ed
jp 0x14ed
jmp 0x150c
leaq 0x4bb7(%rip), %rdi      # 0x60ab
leaq 0x4b80(%rip), %rsi      # 0x607b
movl $0x2f, %edx
leaq 0x4b7c(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
leaq 0x4bac(%rip), %rsi      # 0x60c7
callq 0x3990
leaq 0x280(%rsp), %rdi
callq 0x59b0
movsd 0x4adb(%rip), %xmm1     # 0x6010
ucomisd %xmm1, %xmm0
jne 0x153f
jp 0x153f
jmp 0x155e
leaq 0x4b93(%rip), %rdi      # 0x60d9
leaq 0x4b2e(%rip), %rsi      # 0x607b
movl $0x34, %edx
leaq 0x4b2a(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
xorl %esi, %esi
callq 0x39c0
leaq 0x280(%rsp), %rdi
callq 0x59b0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1587
jp 0x1587
jmp 0x15a6
leaq 0x4b73(%rip), %rdi      # 0x6101
leaq 0x4ae6(%rip), %rsi      # 0x607b
movl $0x37, %edx
leaq 0x4ae2(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
movl $0x1, %esi
callq 0x39c0
leaq 0x280(%rsp), %rdi
callq 0x59b0
movsd 0x4a4b(%rip), %xmm1     # 0x6018
ucomisd %xmm1, %xmm0
jne 0x15d7
jp 0x15d7
jmp 0x15f6
leaq 0x4b3b(%rip), %rdi      # 0x6119
leaq 0x4a96(%rip), %rsi      # 0x607b
movl $0x39, %edx
leaq 0x4a92(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x39c0
leaq 0x280(%rsp), %rdi
callq 0x59b0
movsd 0x4a03(%rip), %xmm1     # 0x6020
ucomisd %xmm1, %xmm0
jne 0x1627
jp 0x1627
jmp 0x1646
leaq 0x4b02(%rip), %rdi      # 0x6130
leaq 0x4a46(%rip), %rsi      # 0x607b
movl $0x3b, %edx
leaq 0x4a42(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
leaq 0x4b46(%rip), %rsi      # 0x619b
callq 0x3990
leaq 0x260(%rsp), %rdi
leaq 0x4b54(%rip), %rsi      # 0x61bd
callq 0x3990
leaq 0x240(%rsp), %rdi
leaq 0x4aca(%rip), %rsi      # 0x6147
callq 0x3990
leaq 0x280(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x169e
jmp 0x16bd
leaq 0x4aa5(%rip), %rdi      # 0x614a
leaq 0x49cf(%rip), %rsi      # 0x607b
movl $0x40, %edx
leaq 0x49cb(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x280(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x16d9
jmp 0x16f8
leaq 0x4a80(%rip), %rdi      # 0x6160
leaq 0x4994(%rip), %rsi      # 0x607b
movl $0x41, %edx
leaq 0x4990(%rip), %rcx      # 0x6083
callq 0x1070
movl $0x0, 0x102b0(%rsp)
cmpl $0x3039, 0x102b0(%rsp) # imm = 0x3039
jge 0x1afe
callq 0x1100
movl $0x3039, %ecx           # imm = 0x3039
cltd
idivl %ecx
movl %edx, 0x34(%rsp)
callq 0x1100
movl $0x3039, %ecx           # imm = 0x3039
cltd
idivl %ecx
movl %edx, 0x30(%rsp)
callq 0x1100
movl $0x4d2, %ecx            # imm = 0x4D2
cltd
idivl %ecx
movl %edx, 0x2c(%rsp)
callq 0x1100
andl $0x1, %eax
cmpl $0x0, %eax
je 0x175e
xorl %eax, %eax
subl 0x34(%rsp), %eax
movl %eax, 0x34(%rsp)
callq 0x1100
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1775
xorl %eax, %eax
subl 0x30(%rsp), %eax
movl %eax, 0x30(%rsp)
leaq 0x280(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x39c0
leaq 0x260(%rsp), %rdi
movl 0x30(%rsp), %esi
callq 0x39c0
leaq 0x40(%rsp), %rdi
movl 0x34(%rsp), %esi
addl 0x30(%rsp), %esi
callq 0x39c0
leaq 0x40(%rsp), %rdi
addq $0x18, %rdi
movl 0x34(%rsp), %esi
subl 0x30(%rsp), %esi
callq 0x39c0
leaq 0x40(%rsp), %rdi
addq $0x30, %rdi
movl 0x34(%rsp), %esi
imull 0x30(%rsp), %esi
callq 0x39c0
cmpl $0x0, 0x30(%rsp)
je 0x180f
leaq 0x40(%rsp), %rdi
addq $0x48, %rdi
movl 0x34(%rsp), %eax
cltd
idivl 0x30(%rsp)
movl %eax, %esi
callq 0x39c0
leaq 0x40(%rsp), %rdi
addq $0x60, %rdi
movl 0x34(%rsp), %eax
cltd
idivl 0x30(%rsp)
movl %edx, %esi
callq 0x39c0
leaq 0x40(%rsp), %rax
addq $0x78, %rax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x34(%rsp)
jle 0x182e
movl 0x34(%rsp), %eax
movl %eax, 0x14(%rsp)
jmp 0x1838
xorl %eax, %eax
subl 0x34(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
cvtsi2sd %eax, %xmm0
callq 0x10e0
movq 0x18(%rsp), %rdi
cvttsd2si %xmm0, %esi
callq 0x39c0
leaq 0x40(%rsp), %rax
addq $0x90, %rax
movq %rax, 0x8(%rsp)
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
callq 0x2040
movq 0x8(%rsp), %rdi
movl %eax, %esi
callq 0x39c0
leaq 0x240(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x2580
leaq 0x280(%rsp), %rdi
leaq 0x280(%rsp), %rsi
movl 0x2c(%rsp), %edx
callq 0x44d0
leaq 0x280(%rsp), %rdi
leaq 0x280(%rsp), %rsi
movl 0x2c(%rsp), %edx
callq 0x4570
leaq 0x280(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x18df
jmp 0x18fe
leaq 0x487a(%rip), %rdi      # 0x6160
leaq 0x478e(%rip), %rsi      # 0x607b
movl $0x5c, %edx
leaq 0x478a(%rip), %rcx      # 0x6083
callq 0x1070
leaq 0x40(%rsp), %rdi
addq $0xf0, %rdi
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x3da0
leaq 0x40(%rsp), %rdi
addq $0x108, %rdi            # imm = 0x108
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x3de0
leaq 0x40(%rsp), %rdi
addq $0x120, %rdi            # imm = 0x120
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x3680
leaq 0x40(%rsp), %rdi
addq $0x138, %rdi            # imm = 0x138
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x4af0
leaq 0x40(%rsp), %rdi
addq $0x150, %rdi            # imm = 0x150
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x4b40
leaq 0x40(%rsp), %rdi
addq $0x168, %rdi            # imm = 0x168
leaq 0x280(%rsp), %rsi
callq 0x4e40
leaq 0x40(%rsp), %rdi
addq $0x180, %rdi            # imm = 0x180
leaq 0x280(%rsp), %rsi
leaq 0x260(%rsp), %rdx
callq 0x4b90
movl $0x0, 0x102ac(%rsp)
cmpl $0x7, 0x102ac(%rsp)
jge 0x1ae6
cmpl $0x0, 0x30(%rsp)
jne 0x1a16
cmpl $0x3, 0x102ac(%rsp)
je 0x1a11
cmpl $0x4, 0x102ac(%rsp)
jne 0x1a16
jmp 0x1ad0
leaq 0x40(%rsp), %rdi
movslq 0x102ac(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x40(%rsp), %rsi
movslq 0x102ac(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
addq $0xf0, %rsi
callq 0x23d0
cmpl $0x0, %eax
je 0x1a74
movl 0x102b0(%rsp), %esi
movl 0x102ac(%rsp), %edx
movl 0x34(%rsp), %ecx
movl 0x30(%rsp), %r8d
leaq 0x4709(%rip), %rdi      # 0x6176
movb $0x0, %al
callq 0x1060
leaq 0x40(%rsp), %rdi
movslq 0x102ac(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq 0x40(%rsp), %rsi
movslq 0x102ac(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
addq $0xf0, %rsi
callq 0x23d0
cmpl $0x0, %eax
jne 0x1aaf
jmp 0x1ace
leaq 0x46e6(%rip), %rdi      # 0x619c
leaq 0x45be(%rip), %rsi      # 0x607b
movl $0x6b, %edx
leaq 0x45ba(%rip), %rcx      # 0x6083
callq 0x1070
jmp 0x1ad0
movl 0x102ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x102ac(%rsp)
jmp 0x19e8
jmp 0x1ae8
movl 0x102b0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x102b0(%rsp)
jmp 0x1703
leaq 0x280(%rsp), %rdi
callq 0x21b0
leaq 0x260(%rsp), %rdi
callq 0x21b0
leaq 0x240(%rsp), %rdi
callq 0x21b0
leaq 0x220(%rsp), %rdi
callq 0x21b0
movl $0x0, 0x102b0(%rsp)
cmpl $0x14, 0x102b0(%rsp)
jge 0x1b73
leaq 0x40(%rsp), %rdi
movslq 0x102b0(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x21b0
movl 0x102b0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x102b0(%rsp)
jmp 0x1b3d
leaq 0x4645(%rip), %rdi      # 0x61bf
callq 0x1040
xorl %eax, %eax
addq $0x102b8, %rsp          # imm = 0x102B8
retq
nopl (%rax)