// File: /workspace/github_cpp_makefile_star2_O3/theuni[P]libbtcnet/src/base32.cpp
// Function: EncodeBase32[abi:cxx11](unsigned char const*, unsigned long)
std::string EncodeBase32(const unsigned char* pch, size_t len)
{
    static const char* pbase32 = "abcdefghijklmnopqrstuvwxyz234567";

    std::string strRet = "";
    strRet.reserve((len + 4) / 5 * 8);

    int mode = 0, left = 0;
    const unsigned char* pchEnd = pch + len;

    while (pch < pchEnd) {
        int enc = *(pch++);
        switch (mode) {
        case 0: // we have no bits
            strRet += pbase32[enc >> 3];
            left = (enc & 7) << 2;
            mode = 1;
            break;

        case 1: // we have three bits
            strRet += pbase32[left | (enc >> 6)];
            strRet += pbase32[(enc >> 1) & 31];
            left = (enc & 1) << 4;
            mode = 2;
            break;

        case 2: // we have one bit
            strRet += pbase32[left | (enc >> 4)];
            left = (enc & 15) << 1;
            mode = 3;
            break;

        case 3: // we have four bits
            strRet += pbase32[left | (enc >> 7)];
            strRet += pbase32[(enc >> 2) & 31];
            left = (enc & 3) << 3;
            mode = 4;
            break;

        case 4: // we have two bits
            strRet += pbase32[left | (enc >> 5)];
            strRet += pbase32[enc & 31];
            mode = 0;
        }
    }

    static constexpr std::array<int, 5> nPadding{{0, 6, 4, 3, 1}};
    if (mode != 0) {
        strRet += pbase32[left];
        for (int n = 0; n < nPadding.at(mode); n++)
            strRet += '=';
    }

    return strRet;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rsp)
movq %rax, (%rdi)
leaq 0xc04e(%rip), %rdx      # 0x138ac
movq %rdx, %rsi
callq 0x5200
leaq 0x4(%r14), %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
leaq (%rdx,%rdx), %rsi
andq $-0x8, %rsi
movq %rbx, %rdi
callq 0x4580
testq %r14, %r14
jle 0x7a28
addq %r15, %r14
xorl %ebp, %ebp
xorl %r13d, %r13d
movzbl (%r15), %r12d
cmpl $0x4, %r13d
jne 0x78df
movl %r12d, %eax
shrl $0x5, %eax
orl %ebp, %eax
leaq 0xaebf(%rip), %r13      # 0x12770
movsbl (%rax,%r13), %esi
movq %rbx, %rdi
callq 0x42e0
andl $0x1f, %r12d
movsbl (%r12,%r13), %esi
movq %rbx, %rdi
callq 0x42e0
incq %r15
xorl %r13d, %r13d
cmpq %r14, %r15
jb 0x7898
jmp 0x7a28
jae 0x79d5
movl %r13d, %eax
leaq 0xaa21(%rip), %rcx      # 0x12310
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %r12d, %eax
shrl $0x3, %eax
leaq 0xae6b(%rip), %rcx      # 0x12770
movsbl (%rax,%rcx), %esi
movq %rbx, %rdi
callq 0x42e0
shll $0x2, %r12d
andl $0x1c, %r12d
movl $0x1, %r13d
jmp 0x79d2
movl %r12d, %eax
shrl $0x4, %eax
orl %ebp, %eax
leaq 0xae3d(%rip), %rcx      # 0x12770
movsbl (%rax,%rcx), %esi
movq %rbx, %rdi
callq 0x42e0
addl %r12d, %r12d
andl $0x1e, %r12d
movl $0x3, %r13d
jmp 0x79d2
movl %r12d, %eax
shrl $0x7, %eax
orl %ebp, %eax
leaq 0xae10(%rip), %r13      # 0x12770
movsbl (%rax,%r13), %esi
movq %rbx, %rdi
callq 0x42e0
movl %r12d, %eax
shrl $0x2, %eax
andl $0x1f, %eax
movsbl (%rax,%r13), %esi
movq %rbx, %rdi
callq 0x42e0
shll $0x3, %r12d
andl $0x18, %r12d
movl $0x4, %r13d
jmp 0x79d2
movl %r12d, %eax
shrl $0x6, %eax
orl %ebp, %eax
leaq 0xadce(%rip), %r13      # 0x12770
movsbl (%rax,%r13), %esi
movq %rbx, %rdi
callq 0x42e0
movl %r12d, %eax
shrl %eax
andl $0x1f, %eax
movsbl (%rax,%r13), %esi
movq %rbx, %rdi
callq 0x42e0
shll $0x4, %r12d
andl $0x10, %r12d
movl $0x2, %r13d
movl %r12d, %ebp
incq %r15
cmpq %r14, %r15
jb 0x7898
testl %r13d, %r13d
je 0x7a28
movl %ebp, %eax
leaq 0xad81(%rip), %rcx      # 0x12770
movsbl (%rax,%rcx), %esi
movq %rbx, %rdi
callq 0x42e0
movslq %r13d, %rsi
cmpl $0x4, %r13d
ja 0x7a3a
leaq 0xa951(%rip), %rax      # 0x1235c
movl (%rax,%rsi,4), %eax
xorl %ebp, %ebp
testl %eax, %eax
cmovgl %eax, %ebp
jle 0x7a28
movq %rbx, %rdi
movl $0x3d, %esi
callq 0x42e0
decl %ebp
jne 0x7a17
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xad50(%rip), %rdi      # 0x12791
movl $0x5, %edx
xorl %eax, %eax
callq 0x4520
jmp 0x7a57
jmp 0x7a57
jmp 0x7a57
jmp 0x7a57
jmp 0x7a57
movq %rax, %r14
movq (%rbx), %rdi
cmpq (%rsp), %rdi
je 0x7a68
callq 0x4340
movq %r14, %rdi
callq 0x4640