// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
testq %rdx, %rdx
je 0x12806
movb $0x0, (%r14)
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 0x12b62
movzbl (%r15), %ecx
leaq 0x1ad9(%rip), %rbp      # 0x14310
movl (%rbp,%rcx,4), %r13d
cmpl $-0x1, %r13d
je 0x129f3
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x1a5b(%rip), %r12      # 0x142b0
xorl %eax, %eax
cmpl $0x7, %eax
ja 0x129d0
movl %eax, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, %eax
jmp 0x129cd
shll $0x4, %r14d
movl %r13d, %eax
shrl %eax
orl %r14d, %eax
movb %al, 0xd(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1295e
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x1296b
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x3, %eax
jmp 0x129d0
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 0x12976
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x12983
movl %r14d, %eax
shll $0x5, %eax
orl %eax, %r13d
movb %r13b, 0xb(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1298e
movb %r13b, (%rsi)
incq 0x8(%rbx)
jmp 0x1299b
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 0x1299f
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x129ac
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x6, %eax
jmp 0x129d0
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 0x129b7
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x129c4
movq %rbx, %rdi
leaq 0xd(%rsp), %rdx
callq 0xa7f8
andl $0x1, %r13d
movl $0x5, %eax
jmp 0x129cd
movq %rbx, %rdi
leaq 0xe(%rsp), %rdx
callq 0xa7f8
andl $0xf, %r13d
movl $0x4, %eax
jmp 0x129cd
movq %rbx, %rdi
leaq 0xb(%rsp), %rdx
callq 0xa7f8
xorl %eax, %eax
jmp 0x129d0
movq %rbx, %rdi
leaq 0xf(%rsp), %rdx
callq 0xa7f8
andl $0x3, %r13d
movl $0x2, %eax
jmp 0x129cd
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
callq 0xa7f8
andl $0x7, %r13d
movl $0x7, %eax
movl %r13d, %r14d
incq %r15
movzbl (%r15), %ecx
movl (%rbp,%rcx,4), %r13d
cmpl $-0x1, %r13d
jne 0x12857
testl %r14d, %r14d
sete %dl
movq 0x10(%rsp), %r14
jmp 0x129f7
movb $0x1, %dl
xorl %eax, %eax
testq %r14, %r14
je 0x12a17
decl %eax
cmpl $0x6, %eax
ja 0x12a17
leaq 0x18c6(%rip), %rsi      # 0x142d0
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
movb $0x1, (%r14)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x3d, %cl
setne %al
xorb $0x1, %dl
orb %al, %dl
jne 0x12a13
cmpb $0x3d, 0x1(%r15)
jne 0x12a13
cmpb $0x3d, 0x2(%r15)
jne 0x12a13
cmpb $0x3d, 0x3(%r15)
jne 0x12a13
cmpb $0x3d, 0x4(%r15)
jne 0x12a13
cmpb $0x3d, 0x5(%r15)
jne 0x12a13
movzbl 0x6(%r15), %eax
jmp 0x12a94
cmpb $0x3d, %cl
setne %al
xorb $0x1, %dl
orb %al, %dl
jne 0x12a13
cmpb $0x3d, 0x1(%r15)
jne 0x12a13
cmpb $0x3d, 0x2(%r15)
jne 0x12a13
movzbl 0x3(%r15), %eax
jmp 0x12a94
cmpb $0x3d, %cl
setne %al
xorb $0x1, %dl
orb %al, %dl
jne 0x12a13
movzbl 0x1(%r15), %eax
cmpl $-0x1, (%rbp,%rax,4)
jne 0x12a13
jmp 0x12a17
cmpb $0x3d, %cl
setne %al
xorb $0x1, %dl
orb %al, %dl
jne 0x12a13
cmpb $0x3d, 0x1(%r15)
jne 0x12a13
cmpb $0x3d, 0x2(%r15)
jne 0x12a13
cmpb $0x3d, 0x3(%r15)
jne 0x12a13
movzbl 0x4(%r15), %eax
jmp 0x12a94
jmp 0x12ae7
jmp 0x12ae7
jmp 0x12ae7
jmp 0x12ae7
jmp 0x12ae7
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x12af7
callq 0x33d0
movq %r14, %rdi
callq 0x3650