// File: /workspace/github_c_makefile_star2_O0/983[P]bigint/bigint.c
// Function: bigint_write_base
char* bigint_write_base(
    char *dst,
    int *n_dst,
    const bigint *a,
    bigint_word base,
    int zero_terminate
){
    int i = 0, n = *n_dst;
    static const char *table = "0123456789abcdefghijklmnopqrstuvwxyz";
    BIGINT_ASSERT(base, >=, 2);
    BIGINT_ASSERT(base, <=, 36);

    if (zero_terminate) if (i < n) dst[i++] = '\0';

    if (a->size == 0){
        if (i < n) dst[i++] = '0';
    }else{
        bigint tmp[1];
        bigint_init(tmp);
        bigint_cpy(tmp, a);

        while (tmp->size > 0){
            bigint_word remainder;
            /* TODO extract as many digits as fit into bigint_word at once */
            /* tricky with leading zeros */
            bigint_div_mod_half_word(tmp, &remainder, base);
            if (i < n) dst[i++] = table[remainder];
        }

        bigint_free(tmp);
    }

    if (a->neg) if (i < n) dst[i++] = '-';
    BIGINT_REVERSE(char, dst, i);
    *n_dst = i;

    return dst;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movl %ecx, 0x3c(%rsp)
movl %r8d, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x30(%rsp)
cmpl $0x2, 0x3c(%rsp)
jb 0x5038
jmp 0x5057
leaq 0x1683(%rip), %rdi      # 0x66c2
leaq 0x12dd(%rip), %rsi      # 0x6323
movl $0x3de, %edx            # imm = 0x3DE
leaq 0x167e(%rip), %rcx      # 0x66d0
callq 0x1070
cmpl $0x24, 0x3c(%rsp)
ja 0x5060
jmp 0x507f
leaq 0x16b2(%rip), %rdi      # 0x6719
leaq 0x12b5(%rip), %rsi      # 0x6323
movl $0x3df, %edx            # imm = 0x3DF
leaq 0x1656(%rip), %rcx      # 0x66d0
callq 0x1070
cmpl $0x0, 0x38(%rsp)
je 0x50ab
movl 0x34(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x50a9
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x34(%rsp)
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x50ab
movq 0x40(%rsp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x50db
movl 0x34(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x50d9
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x34(%rsp)
movslq %ecx, %rcx
movb $0x30, (%rax,%rcx)
jmp 0x514a
leaq 0x10(%rsp), %rdi
callq 0x20a0
leaq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x2580
cmpl $0x0, 0x1c(%rsp)
jle 0x5140
leaq 0x10(%rsp), %rdi
movl 0x3c(%rsp), %edx
leaq 0xc(%rsp), %rsi
callq 0x4960
movl 0x34(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x513e
movq 0x3f79(%rip), %rax      # 0x9098
movl 0xc(%rsp), %ecx
movb (%rax,%rcx), %dl
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x34(%rsp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x50f4
leaq 0x10(%rsp), %rdi
callq 0x21b0
movq 0x40(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0x517a
movl 0x34(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x5178
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x34(%rsp)
movslq %ecx, %rcx
movb $0x2d, (%rax,%rcx)
jmp 0x517a
jmp 0x517c
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, (%rsp)
movl 0x34(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl (%rsp), %eax
cmpl %ecx, %eax
jge 0x51ff
jmp 0x51a2
movq 0x50(%rsp), %rax
movslq 0x8(%rsp), %rcx
movb (%rax,%rcx), %al
movb %al, 0x7(%rsp)
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
subl 0x8(%rsp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq 0x50(%rsp), %rax
movslq 0x8(%rsp), %rcx
movb %dl, (%rax,%rcx)
movb 0x7(%rsp), %dl
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
subl 0x8(%rsp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0x51f2
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x5184
jmp 0x5201
movl 0x34(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, (%rax)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)