#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ base64_decode_chunk(char *, char const *);
int base64_decode(char *out, const char *in, size_t size) {
  if (size % 4) {
    return -1;
  }
  int i;
  for (i = 0; i < (size / 4) + 2; ++i) {
    base64_decode_chunk(out + (i * 3), in + (i * 4));
  }
  return 0;
}


x86 assembly (clang, -O0):
<base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
je     1142 <base64_decode+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <base64_decode+0x88>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x2,%rcx
add    $0x2,%rcx
cmp    %rcx,%rax
jae    1191 <base64_decode+0x81>
mov    -0x10(%rbp),%rdi
imul   $0x3,-0x24(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rsi
call   1030 <base64_decode_chunk@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1149 <base64_decode+0x39>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    $0xffffffff,%eax
test   $0x3,%r14b
jne    115b <base64_decode+0x4b>
mov    %rsi,%r15
mov    %rdi,%rbx
shr    $0x2,%r14
add    $0x2,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <base64_decode_chunk@plt>
add    $0x3,%rbx
add    $0x4,%r15
add    $0xffffffffffffffff,%r14
jne    1140 <base64_decode+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @base64_decode(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = urem i64 %9, 4
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %37
13: ; preds = %3
store i32 0, i32* %8
br label %14
14: ; preds = %33, %13
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = load i64, i64* %7
%18 = udiv i64 %17, 4
%19 = add i64 %18, 2
%20 = icmp ult i64 %16, %19
br i1 %20, label %21, label %36
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = load i32, i32* %8
%24 = mul nsw i32 %23, 3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8*, i8** %6
%28 = load i32, i32* %8
%29 = mul nsw i32 %28, 4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = call i32 @base64_decode_chunk(i8* %26, i8* %31)
br label %33
33: ; preds = %21
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %14
36: ; preds = %14
store i32 0, i32* %4
br label %37
37: ; preds = %36, %12
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
define i32 @base64_decode(i8* %0, i8* %1, i64 %2) {
%4 = and i64 %2, 3
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = lshr i64 %2, 2
%8 = add nuw nsw i64 %7, 1
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %16, %9 ]
%11 = mul nuw nsw i64 %10, 3
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = shl nsw i64 %10, 2
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = tail call i32 @base64_decode_chunk(i8* %12, i8* %14)
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %10, %8
br i1 %17, label %18, label %9
18: ; preds = %9, %3
%19 = phi i32 [ -1, %3 ], [ 0, %9 ]
ret i32 %19
}