// File: /workspace/github_cpp_makefile_star2_O1/tenup-coin[P]seeder/util.cpp
// Function: DecodeBase32(char const*, bool*)
vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
{
    static const int decode32_table[256] =
    {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
        -1, -1, -1, -1, -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1,  0,  1,  2,
         3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
        23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
    };

    if (pfInvalid)
        *pfInvalid = false;

    vector<unsigned char> vchRet;
    vchRet.reserve((strlen(p))*5/8);

    int mode = 0;
    int left = 0;

    while (1)
    {
         int dec = decode32_table[(unsigned char)*p];
         if (dec == -1) break;
         p++;
         switch (mode)
         {
             case 0: // we have no bits and get 5
                 left = dec;
                 mode = 1;
                 break;

              case 1: // we have 5 bits and keep 2
                  vchRet.push_back((left<<3) | (dec>>2));
                  left = dec & 3;
                  mode = 2;
                  break;

             case 2: // we have 2 bits and keep 7
                 left = left << 5 | dec;
                 mode = 3;
                 break;

             case 3: // we have 7 bits and keep 4
                 vchRet.push_back((left<<1) | (dec>>4));
                 left = dec & 15;
                 mode = 4;
                 break;

             case 4: // we have 4 bits, and keep 1
                 vchRet.push_back((left<<4) | (dec>>1));
                 left = dec & 1;
                 mode = 5;
                 break;

             case 5: // we have 1 bit, and keep 6
                 left = left << 5 | dec;
                 mode = 6;
                 break;

             case 6: // we have 6 bits, and keep 3
                 vchRet.push_back((left<<2) | (dec>>3));
                 left = dec & 7;
                 mode = 7;
                 break;

             case 7: // we have 3 bits, and keep 0
                 vchRet.push_back((left<<5) | dec);
                 mode = 0;
                 break;
         }
    }

    if (pfInvalid)
        switch (mode)
        {
            case 0: // 8n base32 characters processed: ok
                break;

            case 1: // 8n+1 base32 characters processed: impossible
            case 3: //   +3
            case 6: //   +6
                *pfInvalid = true;
                break;

            case 2: // 8n+2 base32 characters processed: require '======'
                if (left || p[0] != '=' || p[1] != '=' || p[2] != '=' || p[3] != '=' || p[4] != '=' || p[5] != '=' || decode32_table[(unsigned char)p[6]] != -1)
                    *pfInvalid = true;
                break;

            case 4: // 8n+4 base32 characters processed: require '===='
                if (left || p[0] != '=' || p[1] != '=' || p[2] != '=' || p[3] != '=' || decode32_table[(unsigned char)p[4]] != -1)
                    *pfInvalid = true;
                break;

            case 5: // 8n+5 base32 characters processed: require '==='
                if (left || p[0] != '=' || p[1] != '=' || p[2] != '=' || decode32_table[(unsigned char)p[3]] != -1)
                    *pfInvalid = true;
                break;

            case 7: // 8n+7 base32 characters processed: require '='
                if (left || p[0] != '=' || decode32_table[(unsigned char)p[1]] != -1)
                    *pfInvalid = true;
                break;
        }

    return vchRet;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
testq %rdx, %rdx
je 0x12a92
movb $0x0, (%rdx)
movq %rdx, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq %r15, %rdi
callq 0x31c0
leaq (%rax,%rax,4), %rsi
shrq $0x3, %rsi
movq %rbx, %rdi
callq 0x12dde
xorl %eax, %eax
leaq 0x183a(%rip), %rbp      # 0x14300
leaq 0x17d7(%rip), %r12      # 0x142a4
xorl %r14d, %r14d
movzbl (%r15), %ecx
movl (%rbp,%rcx,4), %r13d
cmpl $-0x1, %r13d
je 0x12c69
incq %r15
cmpl $0x7, %eax
ja 0x12c69
movl %eax, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, %eax
movl %r13d, %r14d
jmp 0x12c69
shll $0x4, %r14d
movl %r13d, %eax
shrl %eax
orl %r14d, %eax
movb %al, 0xd(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x12bee
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x12bfb
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x3, %eax
jmp 0x12c69
addl %r14d, %r14d
movl %r13d, %eax
shrl $0x4, %eax
orl %r14d, %eax
movb %al, 0xe(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x12c09
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x12c16
movl %r14d, %eax
shll $0x5, %eax
orl %r13d, %eax
movb %al, 0xb(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x12c24
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x12c31
shll $0x3, %r14d
movl %r13d, %eax
shrl $0x2, %eax
orl %r14d, %eax
movb %al, 0xf(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x12c35
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x12c42
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x6, %eax
jmp 0x12c69
shll $0x2, %r14d
movl %r13d, %eax
shrl $0x3, %eax
orl %r14d, %eax
movb %al, 0xc(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x12c50
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x12c5d
movq %rbx, %rdi
leaq 0xd(%rsp), %rdx
callq 0xa968
movl %r13d, %r14d
andl $0x1, %r14d
movl $0x5, %eax
jmp 0x12c69
movq %rbx, %rdi
leaq 0xe(%rsp), %rdx
callq 0xa968
movl %r13d, %r14d
andl $0xf, %r14d
movl $0x4, %eax
jmp 0x12c69
movq %rbx, %rdi
leaq 0xb(%rsp), %rdx
callq 0xa968
xorl %eax, %eax
jmp 0x12c69
movq %rbx, %rdi
leaq 0xf(%rsp), %rdx
callq 0xa968
movl %r13d, %r14d
andl $0x3, %r14d
movl $0x2, %eax
jmp 0x12c69
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
callq 0xa968
movl %r13d, %r14d
andl $0x7, %r14d
movl $0x7, %eax
cmpl $-0x1, %r13d
jne 0x12ad0
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0x12c97
decl %eax
cmpl $0x6, %eax
ja 0x12c97
leaq 0x1639(%rip), %rcx      # 0x142c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x1, (%rdx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r14d, %r14d
jne 0x12c94
cmpb $0x3d, (%r15)
jne 0x12c94
cmpb $0x3d, 0x1(%r15)
jne 0x12c94
cmpb $0x3d, 0x2(%r15)
jne 0x12c94
cmpb $0x3d, 0x3(%r15)
jne 0x12c94
cmpb $0x3d, 0x4(%r15)
jne 0x12c94
cmpb $0x3d, 0x5(%r15)
jne 0x12c94
movzbl 0x6(%r15), %eax
jmp 0x12d0e
testl %r14d, %r14d
jne 0x12c94
cmpb $0x3d, (%r15)
jne 0x12c94
cmpb $0x3d, 0x1(%r15)
jne 0x12c94
cmpb $0x3d, 0x2(%r15)
jne 0x12c94
movzbl 0x3(%r15), %eax
jmp 0x12d0e
testl %r14d, %r14d
jne 0x12c94
cmpb $0x3d, (%r15)
jne 0x12c94
movzbl 0x1(%r15), %eax
cmpl $-0x1, (%rbp,%rax,4)
jne 0x12c94
jmp 0x12c97
testl %r14d, %r14d
jne 0x12c94
cmpb $0x3d, (%r15)
jne 0x12c94
cmpb $0x3d, 0x1(%r15)
jne 0x12c94
cmpb $0x3d, 0x2(%r15)
jne 0x12c94
cmpb $0x3d, 0x3(%r15)
jne 0x12c94
movzbl 0x4(%r15), %eax
jmp 0x12d0e
jmp 0x12d63
jmp 0x12d63
jmp 0x12d63
jmp 0x12d63
jmp 0x12d63
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x12d73
callq 0x33d0
movq %r14, %rdi
callq 0x3650