#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 */
typedef char uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ decode_block(char *, char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void base64_decode(FILE *input) {
  uint8_t buffer[(((512 - (512 % 3)) / 3) * 4)];
  int i;
  int j;
  uint8_t output[(512 - (512 % 3)) + 1];
  int size;
  while ((size = fread(buffer, 1, (((512 - (512 % 3)) / 3) * 4), input))) {
    i = 0;
    j = 0;
    while (i + 4 <= size) {
      decode_block(buffer + i, output, j);
      i += 4;
      j += 3;
    }
    if (i < size) {
      fprintf(stderr, "incorrect input\n");
      exit(EXIT_FAILURE);
    }
    if (buffer[i - 1] == '=') {
      --j;
      if (buffer[i - 2] == '=') {
        --j;
      }
    }
    fwrite(output, 1, j, stdout);
  }
  if (ferror(input)) {
    fprintf(stderr, "error reading input\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<base64_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x2b0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2a8,%edx
call   1040 <fread@plt>
mov    %eax,-0x4c4(%rbp)
cmp    $0x0,%eax
je     12bc <base64_decode+0x15c>
movl   $0x0,-0x2b4(%rbp)
movl   $0x0,-0x2b8(%rbp)
mov    -0x2b4(%rbp),%eax
add    $0x4,%eax
cmp    -0x4c4(%rbp),%eax
jg     1207 <base64_decode+0xa7>
lea    -0x2b0(%rbp),%rdi
movslq -0x2b4(%rbp),%rax
add    %rax,%rdi
lea    -0x4c0(%rbp),%rsi
mov    -0x2b8(%rbp),%edx
call   1050 <decode_block@plt>
mov    -0x2b4(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x2b4(%rbp)
mov    -0x2b8(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x2b8(%rbp)
jmp    11ac <base64_decode+0x4c>
mov    -0x2b4(%rbp),%eax
cmp    -0x4c4(%rbp),%eax
jge    123c <base64_decode+0xdc>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x2b4(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x2b0(%rbp,%rax,1),%eax
ff
cmp    $0x3d,%eax
jne    1297 <base64_decode+0x137>
mov    -0x2b8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2b8(%rbp)
mov    -0x2b4(%rbp),%eax
sub    $0x2,%eax
cltq
movsbl -0x2b0(%rbp,%rax,1),%eax
ff
cmp    $0x3d,%eax
jne    1292 <base64_decode+0x132>
mov    -0x2b8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2b8(%rbp)
jmp    1297 <base64_decode+0x137>
lea    -0x4c0(%rbp),%rdi
mov    -0x2b8(%rbp),%edx
mov    0x2d25(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1080 <fwrite@plt>
jmp    116f <base64_decode+0xf>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12f2 <base64_decode+0x192>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd32(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4b8,%rsp
mov    %rdi,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2a8,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     1231 <base64_decode+0xd1>
mov    %eax,%ebx
lea    0x2b0(%rsp),%r12
jmp    11d3 <base64_decode+0x73>
mov    0x2e29(%rip),%rax
mov    (%rax),%ecx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1080 <fwrite@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x2a8,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1231 <base64_decode+0xd1>
xor    %ebp,%ebp
mov    $0x0,%r13d
cmp    $0x4,%ebx
jl     120d <base64_decode+0xad>
xor    %r13d,%r13d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%rsp,%r13,1),%rdi
add    $0x4,%r13
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <decode_block@plt>
add    $0x3,%ebp
lea    0x4(%r13),%eax
cmp    %eax,%ebx
jge    11f0 <base64_decode+0x90>
cmp    %ebx,%r13d
jl     1250 <base64_decode+0xf0>
movslq %r13d,%rax
cmpb   $0x3d,-0x1(%rax,%r15,1)
jne    11a0 <base64_decode+0x40>
xor    %ecx,%ecx
cmpb   $0x3d,-0x2(%rax,%r15,1)
sete   %cl
not    %ecx
add    %ecx,%ebp
jmp    11a0 <base64_decode+0x40>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1273 <base64_decode+0x113>
add    $0x4b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
jmp    1260 <base64_decode+0x100>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"incorrect input\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [21 x i8] c"error reading input\0A\00"
define void @base64_decode(i32* %0) {
%2 = alloca i32*
%3 = alloca [680 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [511 x i8]
%7 = alloca i32
store i32* %0, i32** %2
br label %8
8: ; preds = %62, %1
%9 = getelementptr inbounds [680 x i8], [680 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32 @fread(i8* %9, i32 1, i32 680, i32* %10)
store i32 %11, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %67
13: ; preds = %8
store i32 0, i32* %4
store i32 0, i32* %5
br label %14
14: ; preds = %19, %13
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 4
%17 = load i32, i32* %7
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = getelementptr inbounds [680 x i8], [680 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = getelementptr inbounds [511 x i8], [511 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @decode_block(i8* %23, i8* %24, i32 %25)
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 4
store i32 %28, i32* %4
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 3
store i32 %30, i32* %5
br label %14
31: ; preds = %14
%32 = load i32, i32* %4
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %31
%41 = load i32, i32* %4
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [680 x i8], [680 x i8]* %3, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 61
br i1 %47, label %48, label %62
48: ; preds = %40
%49 = load i32, i32* %5
%50 = add nsw i32 %49, -1
store i32 %50, i32* %5
%51 = load i32, i32* %4
%52 = sub nsw i32 %51, 2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [680 x i8], [680 x i8]* %3, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 61
br i1 %57, label %58, label %61
58: ; preds = %48
%59 = load i32, i32* %5
%60 = add nsw i32 %59, -1
store i32 %60, i32* %5
br label %61
61: ; preds = %58, %48
br label %62
62: ; preds = %61, %40
%63 = getelementptr inbounds [511 x i8], [511 x i8]* %6, i64 0, i64 0
%64 = load i32, i32* %5
%65 = load i32, i32* @stdout
%66 = call i32 @fwrite(i8* %63, i32 1, i32 %64, i32 %65)
br label %8
67: ; preds = %8
%68 = load i32*, i32** %2
%69 = call i64 @ferror(i32* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %67
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"incorrect input\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [21 x i8] c"error reading input\0A\00"
define void @base64_decode(i32* nocapture %0) {
%2 = alloca [680 x i8]
%3 = alloca [511 x i8]
%4 = getelementptr inbounds [680 x i8], [680 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [511 x i8], [511 x i8]* %3, i64 0, i64 0
%6 = call i32 @fread(i8* %4, i32 1, i32 680, i32* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %53, label %8
8: ; preds = %1, %47
%9 = phi i32 [ %51, %47 ], [ %6, %1 ]
%10 = icmp slt i32 %9, 4
br i1 %10, label %24, label %11
11: ; preds = %8, %11
%12 = phi i64 [ %15, %11 ], [ 0, %8 ]
%13 = phi i64 [ %19, %11 ], [ 4, %8 ]
%14 = phi i32 [ %18, %11 ], [ 0, %8 ]
%15 = add nuw nsw i64 %12, 4
%16 = getelementptr inbounds [680 x i8], [680 x i8]* %2, i64 0, i64 %12
%17 = call i32 @decode_block(i8* %16, i8* %5, i32 %14)
%18 = add nuw nsw i32 %14, 3
%19 = add nuw i64 %13, 4
%20 = trunc i64 %19 to i32
%21 = icmp slt i32 %9, %20
br i1 %21, label %22, label %11
22: ; preds = %11
%23 = trunc i64 %13 to i32
br label %24
24: ; preds = %22, %8
%25 = phi i32 [ 0, %8 ], [ %18, %22 ]
%26 = phi i32 [ 0, %8 ], [ %23, %22 ]
%27 = icmp slt i32 %26, %9
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %24
%34 = add nsw i32 %26, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [680 x i8], [680 x i8]* %2, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 61
br i1 %38, label %39, label %47
39: ; preds = %33
%40 = add nsw i32 %26, -2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [680 x i8], [680 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 61
%45 = select i1 %44, i32 -2, i32 -1
%46 = add nsw i32 %45, %25
br label %47
47: ; preds = %39, %33
%48 = phi i32 [ %25, %33 ], [ %46, %39 ]
%49 = load i32, i32* @stdout
%50 = call i32 @fwrite(i8* %5, i32 1, i32 %48, i32 %49)
%51 = call i32 @fread(i8* %4, i32 1, i32 680, i32* %0)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %8
53: ; preds = %47, %1
%54 = call i64 @ferror(i32* %0)
%55 = icmp eq i64 %54, 0
br i1 %55, label %61, label %56
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %53
ret void
}