// File: /workspace/github_c_makefile_star2_O2/NedFreed[P]msglint/msglint.c
// Function: decode64
int decode64(base64ctx *bctx, const char *in, int inlen,
	     char *out, int outmax)
{
    int infill, outfill, j;
    unsigned in0, in1, in2, in3;
    unsigned char *iptr, *end;
    unsigned char inbuf[4], outbuf[3];

    /* set up results */
    bctx->outlen = 0;
    bctx->badc = 0;
    
    /* check for invalid params, insufficient data */
    if (bctx->tmplen > 3) return (-3);
    if (inlen == 0 && (bctx->tmplen == 2 || bctx->tmplen == 3)) {
	while (bctx->tmplen < 4) {
	    bctx->tmpbuf[bctx->tmplen] = '=';
	    ++bctx->tmplen;
	}
    } else if (inlen + bctx->tmplen < 4) {
	memcpy(bctx->tmpbuf + bctx->tmplen, in, inlen);
	iptr = (unsigned char *) bctx->tmpbuf;
	end = iptr + bctx->tmplen + inlen;
	while (iptr < end) {
	    if (*iptr != '=' && CHAR64(*iptr) == XX) {
		bctx->badc = *iptr;
		return (-1);
	    }
	    ++iptr;
	}
	bctx->tmplen += inlen;
	return (1);
    }

    /* fill up initial input data buffer */
    infill = 4;
    if (bctx->tmplen > 0) {
	infill -= bctx->tmplen;
	memcpy(inbuf, bctx->tmpbuf, bctx->tmplen);
	bctx->tmplen = 0;
    }
    memcpy(inbuf + (4 - infill), in, infill);
    in += infill;
    inlen -= infill;

    for (;;) {
	/* check for end */
	if (bctx->sawend) return (-4);

	/* do decode/validation */
	if ((in0 = CHAR64(inbuf[0])) == XX) {
	    bctx->badc = inbuf[0];
	    return (-1);
	}
	if ((in1 = CHAR64(inbuf[1])) == XX) {
	    bctx->badc = inbuf[1];
	    bctx->tmpbuf[0] = inbuf[0];
	    bctx->tmplen = 1;
	    return (-1);
	}
	outbuf[0] = (in0 << 2) + (in1 >> 4);
	outfill = 3;
	if (inbuf[2] == '=' && inbuf[3] == '=') {
	    outbuf[1] = outbuf[2] = 0;
	    outfill = 1;
	    bctx->sawend = 1;
	} else if ((in2 = CHAR64(inbuf[2])) == XX) {
	    bctx->badc = inbuf[2];
	    bctx->tmpbuf[0] = inbuf[0];
	    bctx->tmpbuf[1] = inbuf[1];
	    bctx->tmplen = 2;
	    return (-1);
	} else {
	    outbuf[1] = (in1 << 4) | (in2 >> 2);
	    if (inbuf[3] == '=') {
		outbuf[2] = 0;
		outfill = 2;
		bctx->sawend = 1;
	    } else if ((in3 = CHAR64(inbuf[3])) == XX) {
		bctx->badc = inbuf[3];
		bctx->tmpbuf[0] = inbuf[0];
		bctx->tmpbuf[1] = inbuf[1];
		bctx->tmpbuf[2] = inbuf[2];
		bctx->tmplen = 3;
		return (-1);
	    } else {
		outbuf[2] = (in2 << 6) | in3;
	    }
	}

	/* process output buffer */
	if (out != NULL) {
	    if (outmax < outfill) return (-2);
	    memcpy(out, outbuf, outfill);
	    out += outfill;
	    outmax -= outfill;
	}
	bctx->outlen += outfill;

	/* fill input buffer */
	if (inlen < 4) break;
	memcpy(inbuf, in, 4);
	in += 4;
	inlen -= 4;
    }

    /* save remaining input buffer */
    if (inlen > 0) {
	memcpy(bctx->tmpbuf, in, inlen);
	bctx->tmplen = inlen;

	return (1);
    }

    return (0);
}

// Assembly:
andl $0x0, 0x4(%rdi)
movb $0x0, 0x10(%rdi)
movslq 0x8(%rdi), %rax
cmpq $0x3, %rax
jle 0x2322
pushq $-0x3
popq %rax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r12
movq %rdi, %rbx
movq %rsi, %r15
movl %eax, %ecx
andl $-0x2, %ecx
xorl $0x2, %ecx
orl %edx, %ecx
pushq $0x4
popq %r13
je 0x23b6
leal (%rax,%rdx), %ecx
cmpl $0x3, %ecx
jg 0x23c7
leaq 0xc(%rbx), %r13
leaq (%rbx,%rax), %rdi
addq $0xc, %rdi
movq %rdx, %r14
movslq %edx, %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x2130
movslq 0x8(%rbx), %rax
leaq (%rbx,%rax), %rcx
addq $0xc, %rcx
addq %r12, %rcx
leaq 0x993c(%rip), %rdx      # 0xbcc0
cmpq %rcx, %r13
jae 0x253e
movzbl (%r13), %esi
cmpq $0x3d, %rsi
je 0x23a2
cmpb $0x7f, (%rsi,%rdx)
je 0x257e
incq %r13
jmp 0x2384
cltq
movb $0x3d, 0xc(%rbx,%rax)
movl 0x8(%rbx), %eax
incl %eax
movl %eax, 0x8(%rbx)
cmpl $0x3, %eax
jle 0x23a7
movl %r8d, 0xc(%rsp)
movq %rdx, 0x10(%rsp)
jmp 0x23d8
movl %r8d, 0xc(%rsp)
movq %rdx, 0x10(%rsp)
movl %r13d, %r14d
testl %eax, %eax
jle 0x23f3
pushq $0x4
popq %r14
subl %eax, %r14d
leaq 0xc(%rbx), %rsi
movl %eax, %edx
leaq 0x8(%rsp), %rdi
callq 0x2130
andl $0x0, 0x8(%rbx)
subl %r14d, %r13d
leaq (%rsp,%r13), %rdi
addq $0x8, %rdi
movslq %r14d, %r13
movq %r15, %rsi
movq %r13, %rdx
callq 0x2130
addq %r13, %r15
movq 0x10(%rsp), %r10
subl %r13d, %r10d
leaq 0x98a2(%rip), %rbp      # 0xbcc0
cmpl $0x0, (%rbx)
jne 0x2543
movzbl 0x8(%rsp), %eax
movsbl (%rax,%rbp), %edx
cmpl $0x7f, %edx
je 0x2547
movzbl 0x9(%rsp), %ecx
movsbl (%rcx,%rbp), %edi
cmpl $0x7f, %edi
je 0x254c
movl %edi, %esi
shrl $0x4, %esi
leal (%rsi,%rdx,4), %edx
movb %dl, 0x5(%rsp)
movb 0xa(%rsp), %dl
movb 0xb(%rsp), %sil
movl %edx, %r8d
xorb $0x3d, %r8b
movl %esi, %r9d
xorb $0x3d, %r9b
orb %r8b, %r9b
jne 0x2483
andw $0x0, 0x6(%rsp)
movl $0x1, (%rbx)
pushq $0x1
jmp 0x24dd
movzbl %dl, %r8d
movsbl (%r8,%rbp), %r8d
cmpl $0x7f, %r8d
je 0x2584
shll $0x4, %edi
movl %r8d, %r9d
shrl $0x2, %r9d
orl %edi, %r9d
movb %r9b, 0x6(%rsp)
cmpb $0x3d, %sil
jne 0x24bd
movb $0x0, 0x7(%rsp)
movl $0x1, (%rbx)
pushq $0x2
jmp 0x24dd
movzbl %sil, %edi
movb (%rdi,%rbp), %dil
cmpb $0x7f, %dil
je 0x259a
shlb $0x6, %r8b
orb %r8b, %dil
movb %dil, 0x7(%rsp)
pushq $0x3
popq %r14
testq %r12, %r12
je 0x251d
subl %r14d, 0xc(%rsp)
jl 0x257a
movl %r14d, %r13d
movq %r12, %rdi
leaq 0x5(%rsp), %rsi
movq %r13, %rdx
movq %r15, 0x10(%rsp)
movq %r12, %r15
movq %r10, %r12
callq 0x2130
movq %r12, %r10
movq %r15, %r12
movq 0x10(%rsp), %r15
addq %r13, %r12
jmp 0x2520
xorl %r12d, %r12d
addl %r14d, 0x4(%rbx)
cmpl $0x4, %r10d
jl 0x255b
movl (%r15), %eax
movl %eax, 0x8(%rsp)
addq $0x4, %r15
addq $-0x4, %r10
jmp 0x241e
addl %eax, %r14d
jmp 0x2572
pushq $-0x4
jmp 0x25b0
movb %al, 0x10(%rbx)
jmp 0x25ae
movb %cl, 0x10(%rbx)
movb %al, 0xc(%rbx)
movl $0x1, 0x8(%rbx)
jmp 0x25ae
testl %r10d, %r10d
jle 0x2596
leaq 0xc(%rbx), %rdi
movq %r15, %rsi
movq %r10, %rdx
movq %r10, %r14
callq 0x2130
movl %r14d, 0x8(%rbx)
pushq $0x1
jmp 0x25b0
pushq $-0x2
jmp 0x25b0
movb %sil, 0x10(%rbx)
jmp 0x25ae
movb %dl, 0x10(%rbx)
movb %al, 0xc(%rbx)
movb %cl, 0xd(%rbx)
movl $0x2, 0x8(%rbx)
jmp 0x25ae
xorl %eax, %eax
jmp 0x25b1
movb %sil, 0x10(%rbx)
movb %al, 0xc(%rbx)
movb %cl, 0xd(%rbx)
movb %dl, 0xe(%rbx)
movl $0x3, 0x8(%rbx)
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq