// File: Computer-Kids-Club[P]screenshare-pro-backend/base64.c
// Function: base64_encode_block(char const*, int, char*, base64_encodestate*)
int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, base64_encodestate *state_in) {
    const char *plainchar = plaintext_in;
    const char *const plaintextend = plaintext_in + length_in;
    char *codechar = code_out;
    char result;
    char fragment;

    result = state_in->result;

    switch (state_in->step) {
        while (1) {
            case step_A:
                if (plainchar == plaintextend) {
                    state_in->result = result;
                    state_in->step = step_A;
                    return codechar - code_out;
                }
                fragment = *plainchar++;
                result = (fragment & 0x0fc) >> 2;
                *codechar++ = base64_encode_value(result);
                result = (fragment & 0x003) << 4;
            case step_B:
                if (plainchar == plaintextend) {
                    state_in->result = result;
                    state_in->step = step_B;
                    return codechar - code_out;
                }
                fragment = *plainchar++;
                result |= (fragment & 0x0f0) >> 4;
                *codechar++ = base64_encode_value(result);
                result = (fragment & 0x00f) << 2;
            case step_C:
                if (plainchar == plaintextend) {
                    state_in->result = result;
                    state_in->step = step_C;
                    return codechar - code_out;
                }
                fragment = *plainchar++;
                result |= (fragment & 0x0c0) >> 6;
                *codechar++ = base64_encode_value(result);
                result = (fragment & 0x03f) >> 0;
                *codechar++ = base64_encode_value(result);

                ++(state_in->stepcount);
                if (state_in->stepcount == CHARS_PER_LINE / 4) {
                    *codechar++ = '\n';
                    state_in->stepcount = 0;
                }
        }
    }
    /* control should not reach here */
    return codechar - code_out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movb 0x4(%rax), %al
movb %al, -0x41(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
testl %eax, %eax
je 0xebd0
jmp 0xebaf
movl -0x48(%rbp), %eax
subl $0x1, %eax
je 0xec4d
jmp 0xebbd
movl -0x48(%rbp), %eax
subl $0x2, %eax
je 0xecd1
jmp 0xedaa
jmp 0xebd0
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xec01
movb -0x41(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4(%rbp)
jmp 0xedb8
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb (%rax), %al
movb %al, -0x42(%rbp)
movsbl -0x42(%rbp), %eax
andl $0xfc, %eax
sarl $0x2, %eax
movb %al, -0x41(%rbp)
movsbl -0x41(%rbp), %edi
callq 0xeb20
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movsbl -0x42(%rbp), %eax
andl $0x3, %eax
shll $0x4, %eax
movb %al, -0x41(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xec7e
movb -0x41(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4(%rbp)
jmp 0xedb8
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb (%rax), %al
movb %al, -0x42(%rbp)
movsbl -0x42(%rbp), %ecx
andl $0xf0, %ecx
sarl $0x4, %ecx
movsbl -0x41(%rbp), %eax
orl %ecx, %eax
movb %al, -0x41(%rbp)
movsbl -0x41(%rbp), %edi
callq 0xeb20
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movsbl -0x42(%rbp), %eax
andl $0xf, %eax
shll $0x2, %eax
movb %al, -0x41(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xed02
movb -0x41(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x2, (%rax)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4(%rbp)
jmp 0xedb8
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb (%rax), %al
movb %al, -0x42(%rbp)
movsbl -0x42(%rbp), %ecx
andl $0xc0, %ecx
sarl $0x6, %ecx
movsbl -0x41(%rbp), %eax
orl %ecx, %eax
movb %al, -0x41(%rbp)
movsbl -0x41(%rbp), %edi
callq 0xeb20
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movsbl -0x42(%rbp), %eax
andl $0x3f, %eax
sarl $0x0, %eax
movb %al, -0x41(%rbp)
movsbl -0x41(%rbp), %edi
callq 0xeb20
movb %al, %cl
movq -0x40(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x40(%rbp)
movb %cl, (%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpl $0x12, 0x8(%rax)
jne 0xeda5
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movb $0xa, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x8(%rax)
jmp 0xebce
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)