// File: /workspace/github_c_makefile_star2_O0/uhlin[P]enhanced-duc/source/b64_decode.c
// Function: b64_decode_do
static int
b64_decode_do(unsigned char const *src, uint8_t *target, size_t targsize)
{
	int tarindex, state, ch;
	uint8_t ofs;

	state = 0;
	tarindex = 0;

	while (1)
	{
		ch = *src++;
		ofs = b64rmap[ch];

		if (ofs >= b64rmap_special) {
			/* Ignore whitespaces */
			if (ofs == b64rmap_space)
				continue;
			/* End of base64 characters */
			if (ofs == b64rmap_end)
				break;
			/* A non-base64 character. */
			return (-1);
		}

		switch (state) {
		case 0:
			if ((size_t)tarindex >= targsize)
				return (-1);
			target[tarindex] = ofs << 2;
			state = 1;
			break;
		case 1:
			if ((size_t)tarindex + 1 >= targsize)
				return (-1);
			target[tarindex]   |=  ofs >> 4;
			target[tarindex+1]  = (ofs & 0x0f)
						<< 4 ;
			tarindex++;
			state = 2;
			break;
		case 2:
			if ((size_t)tarindex + 1 >= targsize)
				return (-1);
			target[tarindex]   |=  ofs >> 2;
			target[tarindex+1]  = (ofs & 0x03)
						<< 6;
			tarindex++;
			state = 3;
			break;
		case 3:
			if ((size_t)tarindex >= targsize)
				return (-1);
			target[tarindex] |= ofs;
			tarindex++;
			state = 0;
			break;
		default:
			abort();
		}
	}

	/*
	 * We are done decoding Base-64 chars.  Let's see if we ended
	 * on a byte boundary, and/or with erroneous trailing characters.
	 */

	if (ch == Pad64) {		/* We got a pad char. */
		ch = *src++;		/* Skip it, get next. */
		switch (state) {
		case 0:		/* Invalid = in first position */
		case 1:		/* Invalid = in second position */
			return (-1);

		case 2:		/* Valid, means one byte of info */
			/* Skip any number of spaces. */
			for ((void)NULL; ch != '\0'; ch = *src++)
				if (b64rmap[ch] != b64rmap_space)
					break;
			/* Make sure there is another trailing = sign. */
			if (ch != Pad64)
				return (-1);
			ch = *src++;		/* Skip the = */
			/* Fall through to "single trailing =" case. */
			/* FALLTHROUGH */

		case 3:		/* Valid, means two bytes of info */
			/*
			 * We know this char is an =.  Is there anything but
			 * whitespace after it?
			 */
			for ((void)NULL; ch != '\0'; ch = *src++)
				if (b64rmap[ch] != b64rmap_space)
					return (-1);

			/*
			 * Now make sure for cases 2 and 3 that the "extra"
			 * bits that slopped past the last full byte were
			 * zeros.  If we don't check them, they become a
			 * subliminal channel.
			 */
			if (target[tarindex] != 0)
				return (-1);
		}
	} else {
		/*
		 * We ended by seeing the end of the string.  Make sure we
		 * have no partial bytes lying around.
		 */
		if (state != 0)
			return (-1);
	}

	return (tarindex);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rcx
leaq 0xbd5e(%rip), %rax      # 0x10820
movb (%rax,%rcx), %al
movb %al, -0x2d(%rbp)
movzbl -0x2d(%rbp), %eax
cmpl $0xf0, %eax
jl 0x4afc
movzbl -0x2d(%rbp), %eax
cmpl $0xfe, %eax
jne 0x4ae0
jmp 0x4aa2
movzbl -0x2d(%rbp), %eax
cmpl $0xfd, %eax
jne 0x4af0
jmp 0x4c61
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
movl -0x28(%rbp), %eax
movq %rax, -0x38(%rbp)
subq $0x3, %rax
ja 0x4c57
movq -0x38(%rbp), %rax
leaq 0x64f8(%rip), %rcx      # 0xb010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movslq -0x24(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x4b37
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
movzbl -0x2d(%rbp), %eax
shll $0x2, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl $0x1, -0x28(%rbp)
jmp 0x4c5c
movslq -0x24(%rbp), %rax
addq $0x1, %rax
cmpq -0x20(%rbp), %rax
jb 0x4b71
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
movzbl -0x2d(%rbp), %esi
sarl $0x4, %esi
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movzbl -0x2d(%rbp), %eax
andl $0xf, %eax
shll $0x4, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x2, -0x28(%rbp)
jmp 0x4c5c
movslq -0x24(%rbp), %rax
addq $0x1, %rax
cmpq -0x20(%rbp), %rax
jb 0x4bd4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
movzbl -0x2d(%rbp), %esi
sarl $0x2, %esi
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movzbl -0x2d(%rbp), %eax
andl $0x3, %eax
shll $0x6, %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x3, -0x28(%rbp)
jmp 0x4c5c
movslq -0x24(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x4c30
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
movzbl -0x2d(%rbp), %esi
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
jmp 0x4c5c
callq 0x4220
jmp 0x4aa2
cmpl $0x3d, -0x2c(%rbp)
jne 0x4d6d
movq -0x10(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x3c(%rbp)
subl $0x2, %eax
jb 0x4ca3
jmp 0x4c8c
movl -0x3c(%rbp), %eax
subl $0x2, %eax
je 0x4caf
jmp 0x4c96
movl -0x3c(%rbp), %eax
subl $0x3, %eax
je 0x4d0f
jmp 0x4d6b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
jmp 0x4cb1
cmpl $0x0, -0x2c(%rbp)
je 0x4ce8
movslq -0x2c(%rbp), %rcx
leaq 0xbb5e(%rip), %rax      # 0x10820
movzbl (%rax,%rcx), %eax
cmpl $0xfe, %eax
je 0x4ccf
jmp 0x4ce8
jmp 0x4cd1
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x4cb1
cmpl $0x3d, -0x2c(%rbp)
je 0x4cfa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x4d11
cmpl $0x0, -0x2c(%rbp)
je 0x4d4f
movslq -0x2c(%rbp), %rcx
leaq 0xbafe(%rip), %rax      # 0x10820
movzbl (%rax,%rcx), %eax
cmpl $0xfe, %eax
je 0x4d36
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
jmp 0x4d38
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x4d11
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x4d69
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
jmp 0x4d6b
jmp 0x4d7e
cmpl $0x0, -0x28(%rbp)
je 0x4d7c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4d84
jmp 0x4d7e
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)