#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 */
scalar_t__ base64_decode_block(unsigned char *, unsigned char *);
size_t strlen(char const *);
int base64_decode_binary(unsigned char *out, const char *in) {
  size_t len = strlen(in), i = 0;
  int numbytes = 0;
  while (i < len) {
    if ((numbytes += base64_decode_block(out, (unsigned char *)in)) < 0)
      return (-1);
    out += 3;
    in += 4;
    i += 4;
  }
  return (numbytes);
}


x86 assembly (clang, -O0):
<base64_decode_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11b2 <base64_decode_binary+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <base64_decode_block@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1189 <base64_decode_binary+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <base64_decode_binary+0x98>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    114c <base64_decode_binary+0x2c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode_binary>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1171 <base64_decode_binary+0x51>
mov    %rax,%r15
xor    %eax,%eax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ebp
lea    (%r14,%rbx,1),%rsi
mov    %r12,%rdi
call   1040 <base64_decode_block@plt>
add    %ebp,%eax
js     1175 <base64_decode_binary+0x55>
add    $0x3,%r12
add    $0x4,%rbx
cmp    %r15,%rbx
jb     1150 <base64_decode_binary+0x30>
jmp    117a <base64_decode_binary+0x5a>
xor    %eax,%eax
jmp    117a <base64_decode_binary+0x5a>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @base64_decode_binary(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %2, %14
%6 = phi i32 [ %12, %14 ], [ 0, %2 ]
%7 = phi i64 [ %17, %14 ], [ 0, %2 ]
%8 = phi i8* [ %16, %14 ], [ %1, %2 ]
%9 = phi i8* [ %15, %14 ], [ %0, %2 ]
%10 = tail call i64 @base64_decode_block(i8* %9, i8* %8)
%11 = trunc i64 %10 to i32
%12 = add i32 %6, %11
%13 = icmp slt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %5
%15 = getelementptr inbounds i8, i8* %9, i64 3
%16 = getelementptr inbounds i8, i8* %8, i64 4
%17 = add i64 %7, 4
%18 = icmp ult i64 %17, %3
br i1 %18, label %5, label %19
19: ; preds = %5, %14, %2
%20 = phi i32 [ 0, %2 ], [ %12, %14 ], [ -1, %5 ]
ret i32 %20
}