// File: /workspace/github_c_makefile_star2_O0/archer1357[P]Offline-Raytracer/base64.c
// Function: base64_encode
void base64_encode(unsigned char const* bytes_to_encode,unsigned int in_len, char *out) {
  //todo: test

  static const char * base64_chars =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "abcdefghijklmnopqrstuvwxyz"
    "0123456789+/";

  int outInd=0;
  int i = 0;
  int j = 0;
  unsigned char char_array_3[3];
  unsigned char char_array_4[4];

  while(in_len--) {
    char_array_3[i++] = *(bytes_to_encode++);

    if(i == 3) {
      char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
      char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
      char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
      char_array_4[3] = char_array_3[2] & 0x3f;

      for(i = 0; (i <4); i++) {
        out[outInd++]=base64_chars[char_array_4[i]];
      }

      i = 0;
    }
  }

  if(i) {
    for(j = i; j < 3; j++) {
      char_array_3[j] = '\0';
    }

    char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
    char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
    char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
    char_array_4[3] = char_array_3[2] & 0x3f;

    for(j = 0; (j < i + 1); j++) {
      out[outInd++]=base64_chars[char_array_4[j]];
    }

    while((i++ < 3)) {
      out[outInd++]='=';
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0xc(%rbp)
cmpl $0x0, %eax
je 0x408231
movq -0x8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x8(%rbp)
movb (%rax), %cl
movl -0x20(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x20(%rbp)
cltq
movb %cl, -0x27(%rbp,%rax)
cmpl $0x3, -0x20(%rbp)
jne 0x40822c
movzbl -0x27(%rbp), %eax
andl $0xfc, %eax
sarl $0x2, %eax
movb %al, -0x2b(%rbp)
movzbl -0x27(%rbp), %eax
andl $0x3, %eax
shll $0x4, %eax
movzbl -0x26(%rbp), %ecx
andl $0xf0, %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, -0x2a(%rbp)
movzbl -0x26(%rbp), %eax
andl $0xf, %eax
shll $0x2, %eax
movzbl -0x25(%rbp), %ecx
andl $0xc0, %ecx
sarl $0x6, %ecx
addl %ecx, %eax
movb %al, -0x29(%rbp)
movzbl -0x25(%rbp), %eax
andl $0x3f, %eax
movb %al, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x4, -0x20(%rbp)
jge 0x408225
movq 0x11dff7(%rip), %rax    # 0x5261f0
movslq -0x20(%rbp), %rcx
movzbl -0x2b(%rbp,%rcx), %ecx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4081ec
movl $0x0, -0x20(%rbp)
jmp 0x408154
cmpl $0x0, -0x20(%rbp)
je 0x40831f
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jge 0x40825b
movslq -0x24(%rbp), %rax
movb $0x0, -0x27(%rbp,%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x408241
movzbl -0x27(%rbp), %eax
andl $0xfc, %eax
sarl $0x2, %eax
movb %al, -0x2b(%rbp)
movzbl -0x27(%rbp), %eax
andl $0x3, %eax
shll $0x4, %eax
movzbl -0x26(%rbp), %ecx
andl $0xf0, %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, -0x2a(%rbp)
movzbl -0x26(%rbp), %eax
andl $0xf, %eax
shll $0x2, %eax
movzbl -0x25(%rbp), %ecx
andl $0xc0, %ecx
sarl $0x6, %ecx
addl %ecx, %eax
movb %al, -0x29(%rbp)
movzbl -0x25(%rbp), %eax
andl $0x3f, %eax
movb %al, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4082f3
movq 0x11df29(%rip), %rax    # 0x5261f0
movslq -0x24(%rbp), %rcx
movzbl -0x2b(%rbp,%rcx), %ecx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4082b3
jmp 0x4082f5
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x20(%rbp)
cmpl $0x3, %eax
jge 0x40831d
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x1c(%rbp)
movslq %ecx, %rcx
movb $0x3d, (%rax,%rcx)
jmp 0x4082f5
jmp 0x40831f
popq %rbp
retq
nopw %cs:(%rax,%rax)