// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
testq %rdx, %rdx
je 0x6fae
movb $0x0, (%rdx)
movq %rdx, 0x10(%rsp)
xorps %xmm0, %xmm0
movq 0x8(%rsp), %rbx
movups %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movq %r15, %rdi
callq 0x4180
leaq (%rax,%rax,4), %rsi
shrq $0x3, %rsi
movq %rbx, %rdi
callq 0x72b4
xorl %r14d, %r14d
leaq 0x9363(%rip), %r12      # 0x10348
leaq 0x9308(%rip), %r13      # 0x102f4
xorl %ebx, %ebx
movl %ebx, %ebp
movzbl (%r15), %esi
movq %r12, %rdi
callq 0x733a
movl (%rax), %ebx
movl %r14d, %eax
cmpl $-0x1, %ebx
je 0x70f7
incq %r15
movslq (%r13,%rax,4), %rax
addq %r13, %rax
pushq $0x1
popq %r14
jmpq *%rax
shll $0x3, %ebp
movl %ebx, %eax
shrl $0x2, %eax
orl %ebp, %eax
movb %al, 0x7(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rsi
callq 0x73f2
andl $0x3, %ebx
pushq $0x2
popq %r14
jmp 0x6fee
shll $0x5, %ebp
orl %ebp, %ebx
pushq $0x6
popq %r14
jmp 0x6fee
addl %ebp, %ebp
movl %ebx, %eax
shrl $0x4, %eax
orl %ebp, %eax
movb %al, 0x6(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x6(%rsp), %rsi
callq 0x73f2
andl $0xf, %ebx
pushq $0x4
popq %r14
jmp 0x6fee
shll $0x4, %ebp
movl %ebx, %eax
shrl %eax
orl %ebp, %eax
movb %al, 0x5(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x5(%rsp), %rsi
callq 0x73f2
andl $0x1, %ebx
pushq $0x5
popq %r14
jmp 0x6fee
shll $0x5, %ebp
orl %ebp, %ebx
pushq $0x3
popq %r14
jmp 0x6fee
shll $0x2, %ebp
movl %ebx, %eax
shrl $0x3, %eax
orl %ebp, %eax
movb %al, 0x4(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x73f2
andl $0x7, %ebx
pushq $0x7
popq %r14
jmp 0x6fee
movl %ebp, %eax
shll $0x5, %eax
orl %eax, %ebx
movb %bl, 0x3(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x3(%rsp), %rsi
callq 0x73f2
xorl %r14d, %r14d
movl %ebp, %ebx
jmp 0x6fee
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0x7114
leaq 0x920c(%rip), %rcx      # 0x10314
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x1, (%rbx)
movq 0x8(%rsp), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
jne 0x7111
cmpb $0x3d, (%r15)
jne 0x7111
cmpb $0x3d, 0x1(%r15)
jne 0x7111
cmpb $0x3d, 0x2(%r15)
jne 0x7111
cmpb $0x3d, 0x3(%r15)
jne 0x7111
cmpb $0x3d, 0x4(%r15)
jne 0x7111
cmpb $0x3d, 0x5(%r15)
jne 0x7111
movzbl 0x6(%r15), %esi
leaq 0x91e7(%rip), %rdi      # 0x10348
callq 0x733a
jmp 0x7183
testl %ebp, %ebp
jne 0x7111
cmpb $0x3d, (%r15)
jne 0x7111
movzbl 0x1(%r15), %esi
leaq 0x91ca(%rip), %rdi      # 0x10348
callq 0x733a
cmpl $-0x1, (%rax)
jne 0x7111
jmp 0x7114
testl %ebp, %ebp
jne 0x7111
cmpb $0x3d, (%r15)
jne 0x7111
cmpb $0x3d, 0x1(%r15)
jne 0x7111
cmpb $0x3d, 0x2(%r15)
jne 0x7111
cmpb $0x3d, 0x3(%r15)
jne 0x7111
movzbl 0x4(%r15), %esi
leaq 0x9183(%rip), %rdi      # 0x10348
callq 0x733a
jmp 0x7183
testl %ebp, %ebp
jne 0x7111
cmpb $0x3d, (%r15)
jne 0x7111
cmpb $0x3d, 0x1(%r15)
jne 0x7111
cmpb $0x3d, 0x2(%r15)
jne 0x7111
movzbl 0x3(%r15), %esi
leaq 0x9148(%rip), %rdi      # 0x10348
callq 0x733a
jmp 0x7183
jmp 0x7218
jmp 0x7218
jmp 0x7218
jmp 0x7218
jmp 0x7218
jmp 0x7218
jmp 0x7218
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x4fd0
movq %r14, %rdi
callq 0x4660