// File: /workspace/github_c_makefile_star2_O3/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 0x1a677(%rip), %rax     # 0x22540
leaq 0x1a630(%rip), %r13     # 0x22500
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 0x8012
testl %r14d, %r14d
jle 0x7fae
movq %rax, %rcx
addq $0x3, %rcx
xorl %edi, %edi
movslq %edi, %r8
leaq 0x1(%r8), %rdx
movl $0x0, %esi
cmpl %r14d, %edx
jge 0x7f44
addl $0x2, %edi
movzbl (%r15,%rdx), %esi
shll $0x8, %esi
movl %edi, %edx
xorl %edi, %edi
cmpl %r14d, %edx
jge 0x7f55
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 0x7f26
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 0x1a5ab(%rip), %rdx     # 0x22580
movl (%rdx,%rcx,4), %edx
testl %ebp, %ebp
je 0x8005
decl %r14d
cmpl $0x1, %r14d
ja 0x800b
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
leal -0x1(%r12), %edx
movslq %edx, %rdx
movb $0x3d, (%rax,%rdx)
decl %edx
decq %rcx
jne 0x7ff5
jmp 0x800b
subl %edx, %r12d
movl %r12d, (%rbx)
movslq %r12d, %rcx
movb $0x0, (%rax,%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)