// File: /workspace/github_c_makefile_star2_O1/GangZhuo[P]dohclient/src/base64url.c
// Function: base64url_encode
char *base64url_encode(const unsigned char *data,
                    int input_length,
                    int *output_length,
                    int tail_padding, int dns)
{
	char *table = dns ? dns_encoding_table : encoding_table;
    char *encoded_data;
    int padding, i, j;

    *output_length = 4 * ((input_length + 2) / 3);

    encoded_data = malloc(*output_length + 1);

    if (encoded_data == NULL) return NULL;

    for (i = 0, j = 0; i < input_length;) {

        uint32_t octet_a = i < input_length ? (unsigned char)data[i++] : 0;
        uint32_t octet_b = i < input_length ? (unsigned char)data[i++] : 0;
        uint32_t octet_c = i < input_length ? (unsigned char)data[i++] : 0;

        uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;

        encoded_data[j++] = table[(triple >> 3 * 6) & 0x3F];
        encoded_data[j++] = table[(triple >> 2 * 6) & 0x3F];
        encoded_data[j++] = table[(triple >> 1 * 6) & 0x3F];
        encoded_data[j++] = table[(triple >> 0 * 6) & 0x3F];
    }

    padding = mod_table[input_length % 3];

    if (tail_padding) {
        for (i = 0; i < padding; i++) {
            encoded_data[*output_length - i - 1] = '=';
        }
    }
    else {
        *output_length -= padding;
    }


    encoded_data[*output_length] = '\0';

    return encoded_data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %rbx
movl %esi, %r14d
testl %r8d, %r8d
leaq 0x1a39f(%rip), %rax     # 0x22560
leaq 0x1a358(%rip), %r13     # 0x22520
cmoveq %rax, %r13
movq %rdi, %r15
leal 0x2(%r14), %eax
cltq
imulq $0x55555556, %rax, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
leal (,%rax,4), %r12d
movl %r12d, (%rdx)
leal 0x1(,%rax,4), %eax
movslq %eax, %rdi
callq 0x34b0
testq %rax, %rax
je 0x82fa
testl %r14d, %r14d
jle 0x82a3
leaq 0x3(%rax), %rcx
xorl %edi, %edi
movslq %edi, %r8
leaq 0x1(%r8), %rdx
movl $0x0, %esi
cmpl %r14d, %edx
jge 0x8239
addl $0x2, %edi
movzbl (%r15,%rdx), %esi
shll $0x8, %esi
movl %edi, %edx
xorl %edi, %edi
cmpl %r14d, %edx
jge 0x824a
movslq %edx, %rdi
incl %edx
movzbl (%r15,%rdi), %edi
movzbl (%r15,%r8), %r8d
shll $0x10, %r8d
movl %edi, %r9d
orl %esi, %r9d
orl %r8d, %esi
shrl $0x12, %r8d
movb (%r13,%r8), %r8b
movb %r8b, -0x3(%rcx)
shrl $0xc, %esi
andl $0x3f, %esi
movb (%r13,%rsi), %sil
movb %sil, -0x2(%rcx)
shrl $0x6, %r9d
andl $0x3f, %r9d
movb (%r13,%r9), %sil
movb %sil, -0x1(%rcx)
andl $0x3f, %edi
movb (%r13,%rdi), %sil
movb %sil, (%rcx)
addq $0x4, %rcx
movl %edx, %edi
cmpl %r14d, %edx
jl 0x821b
movslq %r14d, %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %r14d
movslq %r14d, %rcx
leaq 0x1a2d6(%rip), %rdx     # 0x225a0
movl (%rdx,%rcx,4), %edx
testl %ebp, %ebp
je 0x82fe
decl %r14d
cmpl $0x1, %r14d
ja 0x8304
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
decl %r12d
movslq %r12d, %r12
movb $0x3d, (%rax,%r12)
decl %r12d
decq %rcx
jne 0x82e8
jmp 0x8304
xorl %eax, %eax
jmp 0x830b
subl %edx, %r12d
movl %r12d, (%rbx)
movslq (%rbx), %rcx
movb $0x0, (%rax,%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop