// File: alfanick[P]rest-cpp/src/rest/utils.cpp
// Function: REST::Utils::base64_decode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
std::string base64_decode(std::string const& encoded_string) {
  int in_len = encoded_string.size();
  int i = 0;
  int j = 0;
  int in_ = 0;
  unsigned char char_array_4[4], char_array_3[3];
  std::string ret;

  while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
    char_array_4[i++] = encoded_string[in_]; in_++;
    if (i ==4) {
      for (i = 0; i <4; i++)
        char_array_4[i] = base64_chars.find(char_array_4[i]);

      char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
      char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
      char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];

      for (i = 0; (i < 3); i++)
        ret += char_array_3[i];
      i = 0;
    }
  }

  if (i) {
    for (j = i; j <4; j++)
      char_array_4[j] = 0;

    for (j = 0; j <4; j++)
      char_array_4[j] = base64_chars.find(char_array_4[j]);

    char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
    char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
    char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];

    for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
  }

  return ret;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x18(%rsp)
movq %rdi, %rax
movq %rax, 0x10(%rsp)
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x91060
movq 0x18(%rsp), %rdi
movl %eax, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x38(%rsp)
movb $0x0, 0x30(%rsp)
callq 0x959e0
movl 0x44(%rsp), %ecx
movl %ecx, %eax
addl $-0x1, %eax
movl %eax, 0x44(%rsp)
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0xf(%rsp)
je 0xd56fc
movq 0x48(%rsp), %rdi
movslq 0x38(%rsp), %rsi
callq 0x93af0
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x3d, %ecx
movb %al, 0xf(%rsp)
je 0xd56fc
movq 0x48(%rsp), %rdi
movslq 0x38(%rsp), %rsi
callq 0x93af0
movzbl (%rax), %edi
callq 0xd5960
movb %al, 0xe(%rsp)
jmp 0xd56f2
movb 0xe(%rsp), %al
movb %al, 0xf(%rsp)
jmp 0xd56fc
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0xd5709
jmp 0xd582d
movq 0x48(%rsp), %rdi
movslq 0x38(%rsp), %rsi
callq 0x93af0
movb (%rax), %cl
movl 0x40(%rsp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x40(%rsp)
cltq
movb %cl, 0x34(%rsp,%rax)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
cmpl $0x4, 0x40(%rsp)
jne 0xd5828
movl $0x0, 0x40(%rsp)
cmpl $0x4, 0x40(%rsp)
jge 0xd57a1
movslq 0x40(%rsp), %rax
leaq 0x37162(%rip), %rdi     # 0x10c8c0
xorl %ecx, %ecx
movl %ecx, %edx
movsbl 0x34(%rsp,%rax), %esi
callq 0x94fe0
movb %al, %cl
movslq 0x40(%rsp), %rax
movb %cl, 0x34(%rsp,%rax)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xd574b
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
callq 0x99830
jmp 0xd5948
movzbl 0x34(%rsp), %eax
shll $0x2, %eax
movzbl 0x35(%rsp), %ecx
andl $0x30, %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, 0x31(%rsp)
movzbl 0x35(%rsp), %eax
andl $0xf, %eax
shll $0x4, %eax
movzbl 0x36(%rsp), %ecx
andl $0x3c, %ecx
sarl $0x2, %ecx
addl %ecx, %eax
movb %al, 0x32(%rsp)
movzbl 0x36(%rsp), %eax
andl $0x3, %eax
shll $0x6, %eax
movzbl 0x37(%rsp), %ecx
addl %ecx, %eax
movb %al, 0x33(%rsp)
movl $0x0, 0x40(%rsp)
cmpl $0x3, 0x40(%rsp)
jge 0xd5820
movq 0x18(%rsp), %rdi
movslq 0x40(%rsp), %rax
movsbl 0x31(%rsp,%rax), %esi
callq 0x90a10
jmp 0xd5811
jmp 0xd5813
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xd57f4
movl $0x0, 0x40(%rsp)
jmp 0xd56a0
cmpl $0x0, 0x40(%rsp)
je 0xd5928
movl 0x40(%rsp), %eax
movl %eax, 0x3c(%rsp)
cmpl $0x4, 0x3c(%rsp)
jge 0xd585e
movslq 0x3c(%rsp), %rax
movb $0x0, 0x34(%rsp,%rax)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0xd5840
movl $0x0, 0x3c(%rsp)
cmpl $0x4, 0x3c(%rsp)
jge 0xd589f
movslq 0x3c(%rsp), %rax
leaq 0x37047(%rip), %rdi     # 0x10c8c0
xorl %ecx, %ecx
movl %ecx, %edx
movsbl 0x34(%rsp,%rax), %esi
callq 0x94fe0
movb %al, %cl
movslq 0x3c(%rsp), %rax
movb %cl, 0x34(%rsp,%rax)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0xd5866
movzbl 0x34(%rsp), %eax
shll $0x2, %eax
movzbl 0x35(%rsp), %ecx
andl $0x30, %ecx
sarl $0x4, %ecx
addl %ecx, %eax
movb %al, 0x31(%rsp)
movzbl 0x35(%rsp), %eax
andl $0xf, %eax
shll $0x4, %eax
movzbl 0x36(%rsp), %ecx
andl $0x3c, %ecx
sarl $0x2, %ecx
addl %ecx, %eax
movb %al, 0x32(%rsp)
movzbl 0x36(%rsp), %eax
andl $0x3, %eax
shll $0x6, %eax
movzbl 0x37(%rsp), %ecx
addl %ecx, %eax
movb %al, 0x33(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movl 0x40(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xd5926
movq 0x18(%rsp), %rdi
movslq 0x3c(%rsp), %rax
movsbl 0x31(%rsp,%rax), %esi
callq 0x90a10
jmp 0xd5917
jmp 0xd5919
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0xd58f2
jmp 0xd5928
movb $0x1, 0x30(%rsp)
testb $0x1, 0x30(%rsp)
jne 0xd593e
movq 0x18(%rsp), %rdi
callq 0x99830
movq 0x10(%rsp), %rax
addq $0x58, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x981c0
nopw %cs:(%rax,%rax)