// File: alfanick[P]rest-cpp/src/rest/utils.cpp
// Function: REST::Utils::base64_encode[abi:cxx11](unsigned char const*, unsigned int)
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
  std::string ret;
  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++)
        ret += 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++)
      ret += base64_chars[char_array_4[j]];

    while((i++ < 3))
      ret += '=';

  }

  return ret;

}

// Assembly:
subq $0x48, %rsp
movq %rdi, (%rsp)
movq %rdi, %rax
movq %rax, 0x8(%rsp)
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movb $0x0, 0x33(%rsp)
callq 0x959e0
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movl 0x34(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0x34(%rsp)
cmpl $0x0, %eax
je 0xd5527
movq 0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rsp)
movb (%rax), %cl
movl 0x2c(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x2c(%rsp)
cltq
movb %cl, 0x25(%rsp,%rax)
cmpl $0x3, 0x2c(%rsp)
jne 0xd5522
movzbl 0x25(%rsp), %eax
andl $0xfc, %eax
sarl $0x2, %eax
movb %al, 0x21(%rsp)
movzbl 0x25(%rsp), %eax
andl $0x3, %eax
shll $0x4, %eax
movzbl 0x26(%rsp), %ecx
andl $0xf0, %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, 0x22(%rsp)
movzbl 0x26(%rsp), %eax
andl $0xf, %eax
shll $0x2, %eax
movzbl 0x27(%rsp), %ecx
andl $0xc0, %ecx
sarl $0x6, %ecx
addl %ecx, %eax
movb %al, 0x23(%rsp)
movzbl 0x27(%rsp), %eax
andl $0x3f, %eax
movb %al, 0x24(%rsp)
movl $0x0, 0x2c(%rsp)
cmpl $0x4, 0x2c(%rsp)
jge 0xd551a
movslq 0x2c(%rsp), %rax
movzbl 0x21(%rsp,%rax), %eax
movl %eax, %esi
leaq 0x373e4(%rip), %rdi     # 0x10c8c0
callq 0x93af0
movq (%rsp), %rdi
movsbl (%rax), %esi
callq 0x90a10
jmp 0xd54ef
jmp 0xd54f1
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xd54c2
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x18(%rsp)
movl %eax, 0x14(%rsp)
callq 0x99830
jmp 0xd5646
movl $0x0, 0x2c(%rsp)
jmp 0xd5418
cmpl $0x0, 0x2c(%rsp)
je 0xd5627
movl 0x2c(%rsp), %eax
movl %eax, 0x28(%rsp)
cmpl $0x3, 0x28(%rsp)
jge 0xd5558
movslq 0x28(%rsp), %rax
movb $0x0, 0x25(%rsp,%rax)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0xd553a
movzbl 0x25(%rsp), %eax
andl $0xfc, %eax
sarl $0x2, %eax
movb %al, 0x21(%rsp)
movzbl 0x25(%rsp), %eax
andl $0x3, %eax
shll $0x4, %eax
movzbl 0x26(%rsp), %ecx
andl $0xf0, %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, 0x22(%rsp)
movzbl 0x26(%rsp), %eax
andl $0xf, %eax
shll $0x2, %eax
movzbl 0x27(%rsp), %ecx
andl $0xc0, %ecx
sarl $0x6, %ecx
addl %ecx, %eax
movb %al, 0x23(%rsp)
movzbl 0x27(%rsp), %eax
andl $0x3f, %eax
movb %al, 0x24(%rsp)
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
movl 0x2c(%rsp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0xd55ff
movslq 0x28(%rsp), %rax
movzbl 0x21(%rsp,%rax), %eax
movl %eax, %esi
leaq 0x372e3(%rip), %rdi     # 0x10c8c0
callq 0x93af0
movq (%rsp), %rdi
movsbl (%rax), %esi
callq 0x90a10
jmp 0xd55f0
jmp 0xd55f2
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0xd55bb
jmp 0xd5601
movl 0x2c(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x2c(%rsp)
cmpl $0x3, %eax
jge 0xd5625
movq (%rsp), %rdi
movl $0x3d, %esi
callq 0x90a10
jmp 0xd5623
jmp 0xd5601
jmp 0xd5627
movb $0x1, 0x33(%rsp)
testb $0x1, 0x33(%rsp)
jne 0xd563c
movq (%rsp), %rdi
callq 0x99830
movq 0x8(%rsp), %rax
addq $0x48, %rsp
retq
movq 0x18(%rsp), %rdi
callq 0x981c0