#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 */
char *b64encode(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int ret = 0;
  FILE *fp = NULL;
  uint8_t *buf = NULL;
  do {
    fp = fopen("client.p12", "r");
    if (!fp) {
      printf("Failed to open file\n");
      break;
    }
    buf = malloc((500 * 1024));
    if (!buf) {
      printf("Failed to allocate buf\n");
      break;
    }
    ret = fread(buf, 1, (500 * 1024), fp);
    printf("ret = %d\n", ret);
    printf("b64 = %s\n", b64encode(buf, ret));
  } while (0);
  if (fp)
    fclose(fp);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cb <main+0x5b>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    123f <main+0xcf>
mov    $0x7d000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f7 <main+0x87>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    123f <main+0xcf>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x7d000,%edx
call   1040 <fread@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1090 <b64encode@plt>
mov    %rax,%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1253 <main+0xe3>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe75(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f5 <main+0x75>
mov    %rax,%r14
mov    $0x7d000,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1205 <main+0x85>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x7d000,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   10a0 <b64encode@plt>
lea    0xe2e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1211 <main+0x91>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1219 <main+0x99>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"client.p12\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Failed to open file\0A\00"
@.str.3 = [24 x i8] c"Failed to allocate buf\0A\00"
@.str.4 = [10 x i8] c"ret = %d\0A\00"
@.str.5 = [10 x i8] c"b64 = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
store i32* null, i32** %3
store i32* null, i32** %4
br label %5
5: ; preds = %0
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %27
11: ; preds = %5
%12 = call i32* @malloc(i32 512000)
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %27
17: ; preds = %11
%18 = load i32*, i32** %4
%19 = load i32*, i32** %3
%20 = call i32 @fread(i32* %18, i32 1, i32 512000, i32* %19)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %4
%24 = load i32, i32* %2
%25 = call i8* @b64encode(i32* %23, i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %17, %15, %9
%28 = load i32*, i32** %3
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32*, i32** %3
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %30, %27
%34 = load i32*, i32** %4
%35 = call i32 @free(i32* %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"client.p12\00"
@.str.1 = [2 x i8] c"r\00"
@.str.4 = [10 x i8] c"ret = %d\0A\00"
@.str.5 = [10 x i8] c"b64 = %s\0A\00"
@str = [20 x i8] c"Failed to open file\00"
@str.6 = [23 x i8] c"Failed to allocate buf\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = tail call i32* @malloc(i32 512000)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
br label %15
8: ; preds = %3
%9 = tail call i32 @fread(i32* %4, i32 1, i32 512000, i32* %1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%11 = tail call i8* @b64encode(i32* %4, i32 %9)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %11)
br label %15
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %17
15: ; preds = %8, %6
%16 = tail call i32 @fclose(i32* %1)
br label %17
17: ; preds = %13, %15
%18 = phi i32* [ %4, %15 ], [ null, %13 ]
%19 = tail call i32 @free(i32* %18)
ret i32 0
}