// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl -0x28(%rbp), %edx
leaq 0x35e5c(%rip), %rax     # 0x416e0
leaq 0x35e15(%rip), %rcx     # 0x416a0
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
shll $0x2, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x34d0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xb8d8
movq $0x0, -0x8(%rbp)
jmp 0xbaaf
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xba37
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xb915
movq -0x10(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x40(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x58(%rbp)
jmp 0xb91c
xorl %eax, %eax
movl %eax, -0x58(%rbp)
jmp 0xb91c
movl -0x58(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xb945
movq -0x10(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x40(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
jmp 0xb94c
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0xb94c
movl -0x5c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xb975
movq -0x10(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x40(%rbp)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x60(%rbp)
jmp 0xb97c
xorl %eax, %eax
movl %eax, -0x60(%rbp)
jmp 0xb97c
movl -0x60(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x48(%rbp), %eax
shll $0x10, %eax
movl -0x4c(%rbp), %ecx
shll $0x8, %ecx
addl %ecx, %eax
addl -0x50(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
shrl $0x12, %ecx
andl $0x3f, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
shrl $0xc, %ecx
andl $0x3f, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
shrl $0x6, %ecx
andl $0x3f, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movl -0x54(%rbp), %ecx
shrl $0x0, %ecx
andl $0x3f, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x38(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
jmp 0xb8e6
movl -0x14(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x35cd4(%rip), %rax     # 0x41720
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xba8b
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0xba89
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x3d, (%rax,%rcx)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xba5f
jmp 0xba98
movl -0x3c(%rbp), %edx
movq -0x20(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)
nopl (%rax)