// File: /workspace/github_c_makefile_star2_O1/inflex[P]ripMIME/libmime-decoders.c
// Function: MDECODE_decode_short64
int MDECODE_decode_short64( char *short64 )
{
    int i;
    int realm_size = strlen( short64 );
    int stopcount = 0; /* How many stop (=) characters we've read in */
    int c; /* a single char as retrieved using MDECODE_get_char() */
    int char_count = 0; /* How many chars have been received */
    char output[3]; /* The 4->3 byte output array */
    char input[4]; /* The 4->3 byte input array */
    char *outstring = short64;

    char_count = 0;
    while (char_count < realm_size)
    {
        /* Initialise the decode buffer */
        input[0] = input[1] = input[2] = input[3] = 0;

        /* snatch 4 characters from the input */
        for (i = 0; i < 4; i++) {
            /* get a char from the filestream */
            c = *short64;
            short64++;
            /* assuming we've gotten this far, then we increment the char_count */
            char_count++;
            /* if we detect the "stopchar" then we better increment the STOP counter */
            if (c == '=') {
                stopcount++;
            }
            /* test for and discard invalid chars */
            if (b64[c] == 0x80) {
                i--;
                continue;
            }
            /* do the conversion from encoded -> decoded */
            input[i] = (char)b64[c];

        } /* for */

        /* now that our 4-char buffer is full, we can do some fancy bit-shifting and get the required 3-chars of 8-bit data */
        output[0] = (input[0] << 2) | (input[1] >> 4);
        output[1] = (input[1] << 4) | (input[2] >> 2);
        output[2] = (input[2] << 6) | input[3];

        /* determine how many chars to write write and check for errors if our input char count was 4 then we did receive a propper 4:3 Base64 block, hence write it */
        if (i == 4) {
            for (i = 0; i < (3 -stopcount); i++){
                *outstring = output[i];
                outstring++;
            } /* copy our data across */
        } /* if 4 chars were inputted */
    } /* while more chars to proccess */

    *outstring = '\0';  // Set the last char to NULL
    return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
callq 0x2110
testl %eax, %eax
jle 0xcc30
xorl %ecx, %ecx
leaq 0xae5a(%rip), %rdx      # 0x179c0
movl $0x1, %esi
movq %rbx, %rdi
xorl %r8d, %r8d
movl $0x0, 0x8(%rsp)
xorl %r9d, %r9d
movsbq (%rdi), %r14
xorl %r10d, %r10d
cmpq $0x3d, %r14
sete %r11b
movb (%r14,%rdx), %bpl
cmpb $-0x80, %bpl
je 0xcba0
movslq %r9d, %r9
movb %bpl, 0x8(%rsp,%r9)
incl %r9d
incq %rdi
movb %r11b, %r10b
addl %r10d, %r8d
incl %ecx
cmpl $0x4, %r9d
jl 0xcb7c
movb 0x8(%rsp), %r10b
movb 0x9(%rsp), %r11b
shlb $0x2, %r10b
movl %r11d, %ebp
sarb $0x4, %bpl
orb %r10b, %bpl
movb %bpl, 0xd(%rsp)
shlb $0x4, %r11b
movb 0xa(%rsp), %r10b
movl %r10d, %ebp
sarb $0x2, %bpl
orb %r11b, %bpl
movb %bpl, 0xe(%rsp)
shlb $0x6, %r10b
orb 0xb(%rsp), %r10b
movb %r10b, 0xf(%rsp)
cmpl $0x4, %r9d
jne 0xcc28
cmpl $0x2, %r8d
jg 0xcc28
movl $0x3, %r9d
subl %r8d, %r9d
cmpl $0x2, %r9d
cmovll %esi, %r9d
xorl %r10d, %r10d
movb 0xd(%rsp,%r10), %r11b
movb %r11b, (%rbx,%r10)
incq %r10
cmpq %r10, %r9
jne 0xcc14
addq %r10, %rbx
cmpl %eax, %ecx
jl 0xcb71
movb $0x0, (%rbx)
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq