// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, %r15
movq %rdi, %rbx
testq %rdx, %rdx
je 0x7b1d
movb $0x0, (%rdx)
movq %rdx, 0x10(%rsp)
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 0x7e7e
xorl %eax, %eax
leaq 0xa823(%rip), %rbp      # 0x12374
leaq 0xa7cc(%rip), %r12      # 0x12324
xorl %r14d, %r14d
movzbl (%r15), %ecx
movl (%rbp,%rcx,4), %r13d
cmpl $-0x1, %r13d
je 0x7cf4
incq %r15
cmpl $0x7, %eax
ja 0x7cf4
movl %eax, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, %eax
movl %r13d, %r14d
jmp 0x7cf4
shll $0x4, %r14d
movl %r13d, %eax
shrl %eax
orl %r14d, %eax
movb %al, 0xd(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7c79
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7c86
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x3, %eax
jmp 0x7cf4
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 0x7c94
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7ca1
movl %r14d, %eax
shll $0x5, %eax
orl %r13d, %eax
movb %al, 0xb(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7caf
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7cbc
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 0x7cc0
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7ccd
shll $0x5, %r14d
orl %r13d, %r14d
movl $0x6, %eax
jmp 0x7cf4
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 0x7cdb
movb %al, (%rsi)
incq 0x8(%rbx)
jmp 0x7ce8
movq %rbx, %rdi
leaq 0xd(%rsp), %rdx
callq 0x7f08
movl %r13d, %r14d
andl $0x1, %r14d
movl $0x5, %eax
jmp 0x7cf4
movq %rbx, %rdi
leaq 0xe(%rsp), %rdx
callq 0x7f08
movl %r13d, %r14d
andl $0xf, %r14d
movl $0x4, %eax
jmp 0x7cf4
movq %rbx, %rdi
leaq 0xb(%rsp), %rdx
callq 0x7f08
xorl %eax, %eax
jmp 0x7cf4
movq %rbx, %rdi
leaq 0xf(%rsp), %rdx
callq 0x7f08
movl %r13d, %r14d
andl $0x3, %r14d
movl $0x2, %eax
jmp 0x7cf4
movq %rbx, %rdi
leaq 0xc(%rsp), %rdx
callq 0x7f08
movl %r13d, %r14d
andl $0x7, %r14d
movl $0x7, %eax
cmpl $-0x1, %r13d
jne 0x7b5b
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0x7d22
decl %eax
cmpl $0x6, %eax
ja 0x7d22
leaq 0xa62e(%rip), %rcx      # 0x12344
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 0x7d1f
cmpb $0x3d, (%r15)
jne 0x7d1f
cmpb $0x3d, 0x1(%r15)
jne 0x7d1f
cmpb $0x3d, 0x2(%r15)
jne 0x7d1f
cmpb $0x3d, 0x3(%r15)
jne 0x7d1f
cmpb $0x3d, 0x4(%r15)
jne 0x7d1f
cmpb $0x3d, 0x5(%r15)
jne 0x7d1f
movzbl 0x6(%r15), %eax
jmp 0x7d99
testl %r14d, %r14d
jne 0x7d1f
cmpb $0x3d, (%r15)
jne 0x7d1f
cmpb $0x3d, 0x1(%r15)
jne 0x7d1f
cmpb $0x3d, 0x2(%r15)
jne 0x7d1f
movzbl 0x3(%r15), %eax
jmp 0x7d99
testl %r14d, %r14d
jne 0x7d1f
cmpb $0x3d, (%r15)
jne 0x7d1f
movzbl 0x1(%r15), %eax
cmpl $-0x1, (%rbp,%rax,4)
jne 0x7d1f
jmp 0x7d22
testl %r14d, %r14d
jne 0x7d1f
cmpb $0x3d, (%r15)
jne 0x7d1f
cmpb $0x3d, 0x1(%r15)
jne 0x7d1f
cmpb $0x3d, 0x2(%r15)
jne 0x7d1f
cmpb $0x3d, 0x3(%r15)
jne 0x7d1f
movzbl 0x4(%r15), %eax
jmp 0x7d99
jmp 0x7dee
jmp 0x7dee
jmp 0x7dee
jmp 0x7dee
jmp 0x7dee
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x7dfe
callq 0x4340
movq %r14, %rdi
callq 0x4640