#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 const *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ initialize_string(char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int system(char *);
void base64(char *variable, const char *path) {
  int status_code = system("which base64 >/dev/null 2>&1");
  if (status_code == 0) {
    char command[1024 + 1024 + 2];
    initialize_string(command);
    add_to_string(command, "base64 --wrap=0 ");
    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;
      }
      variable[i++] = '\0';
      pclose(stream);
    }
  }
}


x86 assembly (clang, -O0):
<base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe86(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1267 <base64+0x107>
lea    -0x820(%rbp),%rdi
call   1070 <initialize_string@plt>
lea    -0x820(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <add_to_string@plt>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <add_to_string@plt>
lea    -0x820(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
je     1262 <base64+0x102>
movl   $0x0,-0x830(%rbp)
mov    -0x828(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x829(%rbp)
movsbl %al,%eax
mov    0x2ddf(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     123a <base64+0xda>
mov    -0x829(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x830(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x830(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ed <base64+0x8d>
mov    -0x8(%rbp),%rax
mov    -0x830(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x830(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x828(%rbp),%rdi
call   1040 <pclose@plt>
jmp    1267 <base64+0x107>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe85(%rip),%rdi
call   1030 <system@plt>
test   %eax,%eax
jne    1204 <base64+0xa4>
mov    %rsp,%r15
mov    %r15,%rdi
call   1070 <initialize_string@plt>
lea    0xe83(%rip),%rsi
mov    %r15,%rdi
call   1060 <add_to_string@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <add_to_string@plt>
lea    0xe7a(%rip),%rsi
mov    %r15,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     1204 <base64+0xa4>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e15(%rip),%r15
cmp    (%r15),%al
jne    11dc <base64+0x7c>
xor    %eax,%eax
jmp    11f7 <base64+0x97>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11e0 <base64+0x80>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r12,%rdi
call   1040 <pclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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