// File: /workspace/github_cpp_makefile_star2_O3/theuni[P]libbtcnet/src/base32.cpp
// Function: DecodeBase32(char const*, bool*)
std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
{
    static constexpr std::array<int, 256> decode32_table{
        {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -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 != nullptr)
        *pfInvalid = false;

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

    int mode = 0;
    int left = 0;

    while (true) {
        int dec = decode32_table.at(static_cast<unsigned char>(p[0]));
        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 != nullptr)
        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 != 0 || p[0] != '=' || p[1] != '=' || p[2] != '=' || p[3] != '=' || p[4] != '=' || p[5] != '=' || decode32_table.at(static_cast<unsigned char>(p[6])) != -1)
                *pfInvalid = true;
            break;

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

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

        case 7: // 8n+7 base32 characters processed: require '='
            if (left != 0 || p[0] != '=' || decode32_table.at(static_cast<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 0x7aa8
movb $0x0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq %r15, %rdi
callq 0x4190
leaq (%rax,%rax,4), %rsi
shrq $0x3, %rsi
movq %rbx, %rdi
callq 0x7e1c
movzbl (%r15), %ecx
leaq 0xa897(%rip), %rbp      # 0x12370
movl (%rbp,%rcx,4), %r13d
cmpl $-0x1, %r13d
je 0x7c95
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0xa829(%rip), %r12      # 0x12320
xorl %eax, %eax
cmpl $0x7, %eax
ja 0x7c72
movl %eax, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, %eax
jmp 0x7c6f
shll $0x4, %r14d
movl %r13d, %eax
shrl %eax
orl %r14d, %eax
movb %al, 0xd(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7c00
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7c0d
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x3, %eax
jmp 0x7c72
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 0x7c18
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7c25
movl %r14d, %eax
shll $0x5, %eax
orl %eax, %r13d
movb %r13b, 0xb(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7c30
movb %r13b, (%rsi)
incq 0x8(%rbx)
jmp 0x7c3d
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 0x7c41
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7c4e
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x6, %eax
jmp 0x7c72
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 0x7c59
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7c66
movq %rbx, %rdi
leaq 0xd(%rsp), %rdx
callq 0x7ea6
andl $0x1, %r13d
movl $0x5, %eax
jmp 0x7c6f
movq %rbx, %rdi
leaq 0xe(%rsp), %rdx
callq 0x7ea6
andl $0xf, %r13d
movl $0x4, %eax
jmp 0x7c6f
movq %rbx, %rdi
leaq 0xb(%rsp), %rdx
callq 0x7ea6
xorl %eax, %eax
jmp 0x7c72
movq %rbx, %rdi
leaq 0xf(%rsp), %rdx
callq 0x7ea6
andl $0x3, %r13d
movl $0x2, %eax
jmp 0x7c6f
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
callq 0x7ea6
andl $0x7, %r13d
movl $0x7, %eax
movl %r13d, %r14d
incq %r15
movzbl (%r15), %ecx
movl (%rbp,%rcx,4), %r13d
cmpl $-0x1, %r13d
jne 0x7af9
testl %r14d, %r14d
sete %dl
movq 0x10(%rsp), %r14
jmp 0x7c99
movb $0x1, %dl
xorl %eax, %eax
testq %r14, %r14
je 0x7cb9
decl %eax
cmpl $0x6, %eax
ja 0x7cb9
leaq 0xa694(%rip), %rsi      # 0x12340
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 0x7cb5
cmpb $0x3d, 0x1(%r15)
jne 0x7cb5
cmpb $0x3d, 0x2(%r15)
jne 0x7cb5
cmpb $0x3d, 0x3(%r15)
jne 0x7cb5
cmpb $0x3d, 0x4(%r15)
jne 0x7cb5
cmpb $0x3d, 0x5(%r15)
jne 0x7cb5
movzbl 0x6(%r15), %eax
jmp 0x7d36
cmpb $0x3d, %cl
setne %al
xorb $0x1, %dl
orb %al, %dl
jne 0x7cb5
cmpb $0x3d, 0x1(%r15)
jne 0x7cb5
cmpb $0x3d, 0x2(%r15)
jne 0x7cb5
movzbl 0x3(%r15), %eax
jmp 0x7d36
cmpb $0x3d, %cl
setne %al
xorb $0x1, %dl
orb %al, %dl
jne 0x7cb5
movzbl 0x1(%r15), %eax
cmpl $-0x1, (%rbp,%rax,4)
jne 0x7cb5
jmp 0x7cb9
cmpb $0x3d, %cl
setne %al
xorb $0x1, %dl
orb %al, %dl
jne 0x7cb5
cmpb $0x3d, 0x1(%r15)
jne 0x7cb5
cmpb $0x3d, 0x2(%r15)
jne 0x7cb5
cmpb $0x3d, 0x3(%r15)
jne 0x7cb5
movzbl 0x4(%r15), %eax
jmp 0x7d36
jmp 0x7d89
jmp 0x7d89
jmp 0x7d89
jmp 0x7d89
jmp 0x7d89
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x7d99
callq 0x4340
movq %r14, %rdi
callq 0x4640