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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ encode_block(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
void base64_encode(FILE *input) {
  int blocks_left;
  uint8_t buffer[(512 - (512 % 3))];
  int i;
  int j;
  char output[(((512 - (512 % 3)) / 3) * 4) + 1];
  uint8_t block[3] = {0};
  int size;
  while ((size = fread(buffer, 1, (512 - (512 % 3)), input))) {
    i = 0;
    j = 0;
    while (i + 3 <= size) {
      encode_block(buffer + i, output, j);
      i += 3;
      j += 4;
    }
    if (i < size) {
      for (blocks_left = 0; i < size; i++, blocks_left++)
        block[blocks_left] = buffer[i];
      encode_block(block, output, j);
      for (i = j + blocks_left + 1; i < j + 4; i++)
        output[i] = '=';
      j += 4;
    }
    output[j] = '\0';
    printf("%s", output);
  }
  if (ferror(input)) {
    fprintf(stderr, "error reading input\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<base64_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0xae0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xadc(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1fe,%edx
call   1040 <fread@plt>
mov    %eax,-0xae0(%rbp)
cmp    $0x0,%eax
je     132a <base64_encode+0x1ba>
movl   $0x0,-0x814(%rbp)
movl   $0x0,-0x818(%rbp)
mov    -0x814(%rbp),%eax
add    $0x3,%eax
cmp    -0xae0(%rbp),%eax
jg     122e <base64_encode+0xbe>
lea    -0x810(%rbp),%rdi
movslq -0x814(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0xad0(%rbp),%rsi
mov    -0x818(%rbp),%edx
call   1090 <encode_block@plt>
mov    -0x814(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x814(%rbp)
mov    -0x818(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x818(%rbp)
jmp    11cf <base64_encode+0x5f>
mov    -0x814(%rbp),%eax
cmp    -0xae0(%rbp),%eax
jge    1303 <base64_encode+0x193>
movl   $0x0,-0xc(%rbp)
mov    -0x814(%rbp),%eax
cmp    -0xae0(%rbp),%eax
jge    128f <base64_encode+0x11f>
movslq -0x814(%rbp),%rax
mov    -0x810(%rbp,%rax,4),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0xadc(%rbp,%rax,4)
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1247 <base64_encode+0xd7>
lea    -0xadc(%rbp),%rdi
lea    -0xad0(%rbp),%rsi
mov    -0x818(%rbp),%edx
call   1090 <encode_block@plt>
mov    -0x818(%rbp),%eax
add    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%eax
mov    -0x818(%rbp),%ecx
add    $0x4,%ecx
cmp    %ecx,%eax
jge    12f4 <base64_encode+0x184>
movslq -0x814(%rbp),%rax
movb   $0x3d,-0xad0(%rbp,%rax,1)
3d
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    12ba <base64_encode+0x14a>
mov    -0x818(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x818(%rbp)
movslq -0x818(%rbp),%rax
movb   $0x0,-0xad0(%rbp,%rax,1)
lea    -0xad0(%rbp),%rsi
lea    0xce0(%rip),%rdi
call   1050 <printf@plt>
jmp    1192 <base64_encode+0x22>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1360 <base64_encode+0x1f0>
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
lea    0xcb6(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
add    $0xae0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xac8,%rsp
mov    %rdi,%rcx
movl   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x2d0(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1fe,%edx
mov    %rcx,0x8(%rsp)
call   1040 <fread@plt>
test   %eax,%eax
je     12e3 <base64_encode+0x163>
mov    %eax,%ebp
lea    0x20(%rsp),%r12
jmp    121d <base64_encode+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %r15d,%rax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xe11(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
lea    0x2d0(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1fe,%edx
mov    0x8(%rsp),%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
test   %eax,%eax
je     12e3 <base64_encode+0x163>
xor    %r13d,%r13d
mov    $0x0,%r15d
cmp    $0x3,%ebp
jl     1264 <base64_encode+0xe4>
xor    %ebx,%ebx
lea    0x2d0(%rsp),%r14
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   10a0 <encode_block@plt>
add    $0x4,%r15d
add    $0xc,%r14
lea    0x3(%rbx),%r13d
add    $0x6,%ebx
cmp    %ebx,%ebp
mov    %r13d,%ebx
jge    1240 <base64_encode+0xc0>
mov    %ebp,%ebx
sub    %r13d,%ebx
jle    11e0 <base64_encode+0x60>
mov    %r13d,%eax
lea    (%rsp,%rax,4),%rsi
add    $0x2d0,%rsi
mov    %r13d,%eax
not    %eax
add    %ebp,%eax
lea    0x4(,%rax,4),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1080 <memcpy@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   10a0 <encode_block@plt>
mov    %r15d,%eax
add    $0x4,%r15d
add    %ebx,%eax
add    $0x1,%eax
cmp    %r15d,%eax
jae    11e0 <base64_encode+0x60>
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
sub    %ebp,%r13d
add    $0x2,%r13d
add    $0x1,%r13
mov    $0x3d,%esi
mov    %r13,%rdx
call   1060 <memset@plt>
jmp    11e0 <base64_encode+0x60>
mov    0x8(%rsp),%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1304 <base64_encode+0x184>
add    $0xac8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"error reading input\0A\00"
@EXIT_FAILURE = global i32 0
define void @base64_encode(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [510 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca [681 x i8]
%8 = alloca [3 x i32]
%9 = alloca i32
store i32* %0, i32** %2
%10 = bitcast [3 x i32]* %8 to i8*
br label %11
11: ; preds = %80, %1
%12 = getelementptr inbounds [510 x i32], [510 x i32]* %4, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32 @fread(i32* %12, i32 1, i32 510, i32* %13)
store i32 %14, i32* %9
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %86
16: ; preds = %11
store i32 0, i32* %5
store i32 0, i32* %6
br label %17
17: ; preds = %22, %16
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 3
%20 = load i32, i32* %9
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %34
22: ; preds = %17
%23 = getelementptr inbounds [510 x i32], [510 x i32]* %4, i64 0, i64 0
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = getelementptr inbounds [681 x i8], [681 x i8]* %7, i64 0, i64 0
%28 = load i32, i32* %6
%29 = call i32 @encode_block(i32* %26, i8* %27, i32 %28)
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 3
store i32 %31, i32* %5
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 4
store i32 %33, i32* %6
br label %17
34: ; preds = %17
%35 = load i32, i32* %5
%36 = load i32, i32* %9
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %80
38: ; preds = %34
store i32 0, i32* %3
br label %39
39: ; preds = %51, %38
%40 = load i32, i32* %5
%41 = load i32, i32* %9
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %56
43: ; preds = %39
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [510 x i32], [510 x i32]* %4, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = load i32, i32* %3
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 %49
store i32 %47, i32* %50
br label %51
51: ; preds = %43
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %39
56: ; preds = %39
%57 = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 0, i64 0
%58 = getelementptr inbounds [681 x i8], [681 x i8]* %7, i64 0, i64 0
%59 = load i32, i32* %6
%60 = call i32 @encode_block(i32* %57, i8* %58, i32 %59)
%61 = load i32, i32* %6
%62 = load i32, i32* %3
%63 = add nsw i32 %61, %62
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %65
65: ; preds = %74, %56
%66 = load i32, i32* %5
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 4
%69 = icmp slt i32 %66, %68
br i1 %69, label %70, label %77
70: ; preds = %65
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [681 x i8], [681 x i8]* %7, i64 0, i64 %72
store i8 61, i8* %73
br label %74
74: ; preds = %70
%75 = load i32, i32* %5
%76 = add nsw i32 %75, 1
store i32 %76, i32* %5
br label %65
77: ; preds = %65
%78 = load i32, i32* %6
%79 = add nsw i32 %78, 4
store i32 %79, i32* %6
br label %80
80: ; preds = %77, %34
%81 = load i32, i32* %6
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [681 x i8], [681 x i8]* %7, i64 0, i64 %82
store i8 0, i8* %83
%84 = getelementptr inbounds [681 x i8], [681 x i8]* %7, i64 0, i64 0
%85 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %84)
br label %11
86: ; preds = %11
%87 = load i32*, i32** %2
%88 = call i64 @ferror(i32* %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %95
90: ; preds = %86
%91 = load i32, i32* @stderr
%92 = call i32 @fprintf(i32 %91, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%93 = load i32, i32* @EXIT_FAILURE
%94 = call i32 @exit(i32 %93)
unreachable
95: ; preds = %86
ret void
}

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