#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*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ add_to_string(char *, char *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ initialize_string(char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int system(char *);
void base64(char *variable, char *path, int filesize) {
  int status_code = system("which base64 >/dev/null 2>&1");
  if (status_code == 0) {
    char command[1024];
    initialize_string(command);
    add_to_string(command, "base64 ");
    add_to_string(command, path);
    FILE *stream = popen(command, "r");
    if (stream != NULL) {
      char character;
      int i = 0;
      while ((character = fgetc(stream)) != EOF) {
        variable[i++] = character;
      }
      i = i - 1;
      while (isspace(variable[i])) {
        variable[i] = '\0';
        i--;
      }
      pclose(stream);
    }
  }
}


x86 assembly (clang, -O0):
<base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xe73(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    12ae <base64+0x13e>
lea    -0x420(%rbp),%rdi
call   1080 <initialize_string@plt>
lea    -0x420(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1070 <add_to_string@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <add_to_string@plt>
lea    -0x420(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     12a9 <base64+0x139>
movl   $0x0,-0x430(%rbp)
mov    -0x428(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x429(%rbp)
movsbl %al,%eax
mov    0x2dcc(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     124d <base64+0xdd>
mov    -0x429(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x430(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x430(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1200 <base64+0x90>
mov    -0x430(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x430(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x430(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     129d <base64+0x12d>
mov    -0x8(%rbp),%rax
movslq -0x430(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x430(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x430(%rbp)
jmp    125c <base64+0xec>
mov    -0x428(%rbp),%rdi
call   1040 <pclose@plt>
jmp    12ae <base64+0x13e>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe72(%rip),%rdi
call   1030 <system@plt>
test   %eax,%eax
jne    1261 <base64+0xf1>
mov    %rsp,%r15
mov    %r15,%rdi
call   1080 <initialize_string@plt>
lea    0xe70(%rip),%rsi
mov    %r15,%rdi
call   1070 <add_to_string@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <add_to_string@plt>
lea    0xe5e(%rip),%rsi
mov    %r15,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     1261 <base64+0xf1>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2dfe(%rip),%r15
mov    $0xffffffffffffffff,%rbx
cmp    (%r15),%al
je     122b <base64+0xbb>
movabs $0xffffffff00000000,%rbx
ff ff ff
movabs $0x100000000,%r13
mov    %r12,%rbp
nopl   (%rax)
add    %r13,%rbx
mov    %al,0x0(%rbp)
mov    %r14,%rdi
call   1050 <fgetc@plt>
add    $0x1,%rbp
cmp    (%r15),%al
jne    1210 <base64+0xa0>
sar    $0x20,%rbx
movsbl (%r12,%rbx,1),%edi
call   1060 <isspace@plt>
test   %rax,%rax
je     1259 <base64+0xe9>
add    %rbx,%r12
nopl   (%rax)
movb   $0x0,(%r12)
movsbl -0x1(%r12),%edi
add    $0xffffffffffffffff,%r12
call   1060 <isspace@plt>
test   %rax,%rax
jne    1240 <base64+0xd0>
mov    %r14,%rdi
call   1040 <pclose@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"which base64 >/dev/null 2>&1\00"
@.str.1 = [8 x i8] c"base64 \00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i8 0
define void @base64(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32*
%10 = alloca i8
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %64
15: ; preds = %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = call i32 @initialize_string(i8* %16)
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%19 = call i32 @add_to_string(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i32 @add_to_string(i8* %20, i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = call i32* @popen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %9
%25 = load i32*, i32** %9
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %63
27: ; preds = %15
store i32 0, i32* %11
br label %28
28: ; preds = %35, %27
%29 = load i32*, i32** %9
%30 = call signext i8 @fgetc(i32* %29)
store i8 %30, i8* %10
%31 = sext i8 %30 to i32
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %42
35: ; preds = %28
%36 = load i8, i8* %10
%37 = load i8*, i8** %4
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %11
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
br label %28
42: ; preds = %28
%43 = load i32, i32* %11
%44 = sub nsw i32 %43, 1
store i32 %44, i32* %11
br label %45
45: ; preds = %53, %42
%46 = load i8*, i8** %4
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = call i64 @isspace(i8 signext %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %45
%54 = load i8*, i8** %4
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = load i32, i32* %11
%59 = add nsw i32 %58, -1
store i32 %59, i32* %11
br label %45
60: ; preds = %45
%61 = load i32*, i32** %9
%62 = call i32 @pclose(i32* %61)
br label %63
63: ; preds = %60, %15
br label %64
64: ; preds = %63, %3
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"which base64 >/dev/null 2>&1\00"
@.str.1 = [8 x i8] c"base64 \00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i8 0
define void @base64(i8* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = tail call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %46
7: ; preds = %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 @initialize_string(i8* %8)
%10 = call i32 @add_to_string(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @add_to_string(i8* %8, i8* %1)
%12 = call i32* @popen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %45, label %14
14: ; preds = %7
%15 = call signext i8 @fgetc(i32* %12)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %21, label %27
18: ; preds = %27
%19 = shl i64 %28, 32
%20 = ashr exact i64 %19, 32
br label %21
21: ; preds = %18, %14
%22 = phi i64 [ -1, %14 ], [ %20, %18 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = call i64 @isspace(i8 signext %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %43, label %35
27: ; preds = %14, %27
%28 = phi i64 [ %30, %27 ], [ 0, %14 ]
%29 = phi i8 [ %32, %27 ], [ %15, %14 ]
%30 = add nuw i64 %28, 1
%31 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 %29, i8* %31
%32 = call signext i8 @fgetc(i32* %12)
%33 = load i8, i8* @EOF
%34 = icmp eq i8 %32, %33
br i1 %34, label %18, label %27
35: ; preds = %21, %35
%36 = phi i64 [ %38, %35 ], [ %22, %21 ]
%37 = phi i8* [ %39, %35 ], [ %23, %21 ]
store i8 0, i8* %37
%38 = add i64 %36, -1
%39 = getelementptr inbounds i8, i8* %0, i64 %38
%40 = load i8, i8* %39
%41 = call i64 @isspace(i8 signext %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %35
43: ; preds = %35, %21
%44 = call i32 @pclose(i32* %12)
br label %45
45: ; preds = %43, %7
br label %46
46: ; preds = %45, %3
ret void
}