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

/* Variables and functions */
char *concat(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
char *read_line(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ versionChar();
bool checkForUpdate() {
  char cwd[1024];
  if (getcwd(cwd, sizeof(cwd)) != NULL) {
    FILE *versionFile;
    char *buff;
    system("mkdir ~/.prfx_tmp/");
    system("cd ~/.prfx_tmp/");
    system(
        "curl -OLs "
        "https://raw.githubusercontent.com/kylefrost/prfx/master/version.txt");
    versionFile = fopen("version.txt", "r");
    char *currentVersion = read_line(versionFile);
    char *command = concat("cd ", cwd);
    fclose(versionFile);
    system(command);
    system("rm -rf ~/.prfx_tmp/");
    if ((strcmp(currentVersion, versionChar()))) {
      return false;
    } else {
      return true;
    }
  } else {
    perror("Error 1: Could not get current directory");
  }
  return false;
}


x86 assembly (clang, -O0):
<checkForUpdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
cmp    $0x0,%rax
je     128a <checkForUpdate+0xfa>
lea    0xe43(%rip),%rdi
call   1050 <system@plt>
lea    0xe4a(%rip),%rdi
call   1050 <system@plt>
lea    0xe4e(%rip),%rdi
call   1050 <system@plt>
lea    0xe84(%rip),%rdi
lea    0xe89(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rdi
call   1090 <read_line@plt>
mov    %rax,-0x428(%rbp)
lea    -0x410(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1060 <concat@plt>
mov    %rax,-0x430(%rbp)
mov    -0x418(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x430(%rbp),%rdi
call   1050 <system@plt>
lea    0xe37(%rip),%rdi
call   1050 <system@plt>
mov    -0x428(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    $0x0,%al
call   1030 <versionChar@plt>
mov    -0x438(%rbp),%rdi
mov    %eax,%esi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     127e <checkForUpdate+0xee>
movl   $0x0,-0x4(%rbp)
jmp    129d <checkForUpdate+0x10d>
movl   $0x1,-0x4(%rbp)
jmp    129d <checkForUpdate+0x10d>
lea    0xdfa(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkForUpdate>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     124e <checkForUpdate+0xbe>
lea    0xe47(%rip),%rdi
call   1050 <system@plt>
lea    0xe4e(%rip),%rdi
call   1050 <system@plt>
lea    0xe52(%rip),%rdi
call   1050 <system@plt>
lea    0xe88(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <read_line@plt>
mov    %rax,%r14
lea    0xe75(%rip),%rdi
mov    %rsp,%rsi
call   1060 <concat@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1050 <system@plt>
lea    0xe57(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
call   1030 <versionChar@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe36(%rip),%rdi
call   10b0 <perror@plt>
xor    %eax,%eax
jmp    1241 <checkForUpdate+0xb1>

LLVM IR (-O0):
@.str = [19 x i8] c"mkdir ~/.prfx_tmp/\00"
@.str.1 = [16 x i8] c"cd ~/.prfx_tmp/\00"
@.str.2 = [78 x i8] c"curl -OLs https://raw.githubusercontent.com/kylefrost/prfx/master/version.txt\00"
@.str.3 = [12 x i8] c"version.txt\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [4 x i8] c"cd \00"
@.str.6 = [20 x i8] c"rm -rf ~/.prfx_tmp/\00"
@.str.7 = [41 x i8] c"Error 1: Could not get current directory\00"
define i32 @checkForUpdate() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = call i32* @getcwd(i8* %7, i32 1024)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %30
10: ; preds = %0
%11 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @system(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %14, i32** %3
%15 = load i32*, i32** %3
%16 = call i8* @read_line(i32* %15)
store i8* %16, i8** %5
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%18 = call i8* @concat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %17)
store i8* %18, i8** %6
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
%21 = load i8*, i8** %6
%22 = call i32 @system(i8* %21)
%23 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%24 = load i8*, i8** %5
%25 = call i32 (...) @versionChar()
%26 = call i64 @strcmp(i8* %24, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %10
store i32 0, i32* %1
br label %33
29: ; preds = %10
store i32 1, i32* %1
br label %33
30: ; preds = %0
%31 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %30
store i32 0, i32* %1
br label %33
33: ; preds = %32, %29, %28
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [19 x i8] c"mkdir ~/.prfx_tmp/\00"
@.str.1 = [16 x i8] c"cd ~/.prfx_tmp/\00"
@.str.2 = [78 x i8] c"curl -OLs https://raw.githubusercontent.com/kylefrost/prfx/master/version.txt\00"
@.str.3 = [12 x i8] c"version.txt\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [4 x i8] c"cd \00"
@.str.6 = [20 x i8] c"rm -rf ~/.prfx_tmp/\00"
@.str.7 = [41 x i8] c"Error 1: Could not get current directory\00"
define i32 @checkForUpdate() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32* @getcwd(i8* %2, i32 1024)
%4 = icmp eq i32* %3, null
br i1 %4, label %19, label %5
5: ; preds = %0
%6 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @system(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%10 = call i8* @read_line(i32* %9)
%11 = call i8* @concat(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%12 = call i32 @fclose(i32* %9)
%13 = call i32 @system(i8* %11)
%14 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%15 = call i32 (...) @versionChar()
%16 = call i64 @strcmp(i8* %10, i32 %15)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %21
19: ; preds = %0
%20 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
br label %21
21: ; preds = %19, %5
%22 = phi i32 [ %18, %5 ], [ 0, %19 ]
ret i32 %22
}