// File: /workspace/github_c_makefile_star2_O0/uhlin[P]enhanced-duc/source/b64_encode.c
// Function: b64_encode
int
b64_encode(uint8_t const *src, size_t srclength, char *target, size_t targsize)
{
	size_t datalength = 0;
	uint8_t input[3];
	uint8_t output[4];
	size_t i;

	while (2 < srclength) {
		input[0] = *src++;
		input[1] = *src++;
		input[2] = *src++;
		srclength -= 3;

		output[0] = input[0] >> 2;
		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
		output[3] = input[2] & 0x3f;
		Assert(output[0] < 64);
		Assert(output[1] < 64);
		Assert(output[2] < 64);
		Assert(output[3] < 64);

		if (datalength + 4 > targsize)
			return (-1);
		target[datalength++] = Base64[output[0]];
		target[datalength++] = Base64[output[1]];
		target[datalength++] = Base64[output[2]];
		target[datalength++] = Base64[output[3]];
	}

	/* Now we worry about padding. */
	if (0 != srclength) {
		/* Get what's left. */
		input[0] = input[1] = input[2] = '\0';
		for (i = 0; i < srclength; i++)
			input[i] = *src++;

		output[0] = input[0] >> 2;
		output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
		output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
		Assert(output[0] < 64);
		Assert(output[1] < 64);
		Assert(output[2] < 64);

		if (datalength + 4 > targsize)
			return (-1);
		target[datalength++] = Base64[output[0]];
		target[datalength++] = Base64[output[1]];
		if (srclength == 1)
			target[datalength++] = Pad64;
		else
			target[datalength++] = Base64[output[2]];
		target[datalength++] = Pad64;
	}
	if (datalength >= targsize)
		return (-1);
	target[datalength] = '\0';	/* Returned value doesn't count \0. */
	return (datalength);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x2, %eax
cmpq -0x18(%rbp), %rax
jae 0x50ea
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %al
movb %al, -0x33(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %al
movb %al, -0x32(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %al
movb %al, -0x31(%rbp)
movq -0x18(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x18(%rbp)
movzbl -0x33(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x37(%rbp)
movzbl -0x33(%rbp), %eax
andl $0x3, %eax
shll $0x4, %eax
movzbl -0x32(%rbp), %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, -0x36(%rbp)
movzbl -0x32(%rbp), %eax
andl $0xf, %eax
shll $0x2, %eax
movzbl -0x31(%rbp), %ecx
sarl $0x6, %ecx
addl %ecx, %eax
movb %al, -0x35(%rbp)
movzbl -0x31(%rbp), %eax
andl $0x3f, %eax
movb %al, -0x34(%rbp)
movq -0x30(%rbp), %rax
addq $0x4, %rax
cmpq -0x28(%rbp), %rax
jbe 0x504d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x525a
movzbl -0x37(%rbp), %eax
movl %eax, %ecx
leaq 0x6026(%rip), %rax      # 0xb080
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
movzbl -0x36(%rbp), %eax
movl %eax, %ecx
leaq 0x6000(%rip), %rax      # 0xb080
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
movzbl -0x35(%rbp), %eax
movl %eax, %ecx
leaq 0x5fda(%rip), %rax      # 0xb080
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
movzbl -0x34(%rbp), %eax
movl %eax, %ecx
leaq 0x5fb4(%rip), %rax      # 0xb080
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x4f9c
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x5234
movb $0x0, -0x31(%rbp)
movb $0x0, -0x32(%rbp)
movb $0x0, -0x33(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x513b
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x10(%rbp)
movb (%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, -0x33(%rbp,%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x510a
movzbl -0x33(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x37(%rbp)
movzbl -0x33(%rbp), %eax
andl $0x3, %eax
shll $0x4, %eax
movzbl -0x32(%rbp), %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, -0x36(%rbp)
movzbl -0x32(%rbp), %eax
andl $0xf, %eax
shll $0x2, %eax
movzbl -0x31(%rbp), %ecx
sarl $0x6, %ecx
addl %ecx, %eax
movb %al, -0x35(%rbp)
movq -0x30(%rbp), %rax
addq $0x4, %rax
cmpq -0x28(%rbp), %rax
jbe 0x518b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x525a
movzbl -0x37(%rbp), %eax
movl %eax, %ecx
leaq 0x5ee8(%rip), %rax      # 0xb080
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
movzbl -0x36(%rbp), %eax
movl %eax, %ecx
leaq 0x5ec2(%rip), %rax      # 0xb080
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
cmpq $0x1, -0x18(%rbp)
jne 0x51f7
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb $0x3d, (%rax,%rcx)
jmp 0x521d
movzbl -0x35(%rbp), %eax
movl %eax, %ecx
leaq 0x5e7c(%rip), %rax      # 0xb080
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb $0x3d, (%rax,%rcx)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jb 0x5247
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x525a
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nop