#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 */
struct filesystem {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fsclose(struct filesystem *);
struct filesystem *fsopen(char *);
char *getsetting(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ uls(struct filesystem *, char *);
int main(int argc, char *argv[]) {
  struct filesystem *f;
  char path[1024];
  char *image = getsetting("imagefile");
  if (!image) {
    printf("Have you run ulogin?\n");
    return 10;
  }
  char *cwd = getsetting("cwd");
  if (argc == 2) {
    if (argv[1][0] == '/') {
      sprintf(path, "%s", argv[1]);
    } else {
      sprintf(path, "%s/%s", cwd, argv[1]);
    }
  } else {
    sprintf(path, "%s", cwd);
  }
  free(cwd);
  f = fsopen(image);
  if (!f) {
    printf("Unable to open %s\n", image);
  } else {
    if (!uls(f, path)) {
      printf("%s not found\n", path);
    }
  }
  fsclose(f);
  free(image);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
call   1080 <getsetting@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11c4 <main+0x54>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xa,-0x4(%rbp)
jmp    12ec <main+0x17c>
lea    0xe55(%rip),%rdi
call   1080 <getsetting@plt>
mov    %rax,-0x430(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1240 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1217 <main+0xa7>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    123b <main+0xcb>
lea    -0x420(%rbp),%rdi
mov    -0x430(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    125c <main+0xec>
lea    -0x420(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x430(%rbp),%rdi
call   1030 <free@plt>
mov    -0x428(%rbp),%rdi
call   1050 <fsopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    129d <main+0x12d>
mov    -0x428(%rbp),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12d0 <main+0x160>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1040 <uls@plt>
cmp    $0x0,%eax
jne    12cb <main+0x15b>
lea    -0x420(%rbp),%rsi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12d0 <main+0x160>
mov    -0x18(%rbp),%rdi
call   1070 <fsclose@plt>
mov    -0x428(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe57(%rip),%rdi
call   10a0 <getsetting@plt>
test   %rax,%rax
je     11db <main+0x4b>
mov    %rax,%r15
lea    0xe4d(%rip),%rdi
call   10a0 <getsetting@plt>
mov    %rax,%r14
cmp    $0x2,%ebp
jne    11ee <main+0x5e>
mov    0x8(%rbx),%rcx
cmpb   $0x2f,(%rcx)
jne    11fb <main+0x6b>
mov    %rsp,%rdi
mov    %rcx,%rsi
jmp    11f4 <main+0x64>
lea    0xe53(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%eax
jmp    1265 <main+0xd5>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
jmp    120f <main+0x7f>
lea    0xe0c(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1070 <fsopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1242 <main+0xb2>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <uls@plt>
test   %eax,%eax
jne    1253 <main+0xc3>
lea    0xdea(%rip),%rdi
mov    %rsp,%rsi
jmp    124c <main+0xbc>
lea    0xdcb(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1090 <fsclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.filesystem = type { i32 }
@.str = [10 x i8] c"imagefile\00"
@.str.1 = [22 x i8] c"Have you run ulogin?\0A\00"
@.str.2 = [4 x i8] c"cwd\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [19 x i8] c"Unable to open %s\0A\00"
@.str.6 = [14 x i8] c"%s not found\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.filesystem*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i8* @getsetting(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 10, i32* %3
br label %69
15: ; preds = %2
%16 = call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %16, i8** %9
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %41
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %33
27: ; preds = %19
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %40
33: ; preds = %19
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%35 = load i8*, i8** %9
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %35, i8* %38)
br label %40
40: ; preds = %33, %27
br label %45
41: ; preds = %15
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%43 = load i8*, i8** %9
%44 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %41, %40
%46 = load i8*, i8** %9
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %8
%49 = call %struct.filesystem* @fsopen(i8* %48)
store %struct.filesystem* %49, %struct.filesystem** %6
%50 = load %struct.filesystem*, %struct.filesystem** %6
%51 = icmp ne %struct.filesystem* %50, null
br i1 %51, label %55, label %52
52: ; preds = %45
%53 = load i8*, i8** %8
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %53)
br label %64
55: ; preds = %45
%56 = load %struct.filesystem*, %struct.filesystem** %6
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%58 = call i32 @uls(%struct.filesystem* %56, i8* %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %55
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %60, %55
br label %64
64: ; preds = %63, %52
%65 = load %struct.filesystem*, %struct.filesystem** %6
%66 = call i32 @fsclose(%struct.filesystem* %65)
%67 = load i8*, i8** %8
%68 = call i32 @free(i8* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %64, %13
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.filesystem = type { i32 }
@.str = [10 x i8] c"imagefile\00"
@.str.2 = [4 x i8] c"cwd\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [19 x i8] c"Unable to open %s\0A\00"
@.str.6 = [14 x i8] c"%s not found\0A\00"
@str = [21 x i8] c"Have you run ulogin?\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @getsetting(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %37
9: ; preds = %2
%10 = tail call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i8* @strcpy(i8* %4, i8* %14)
br label %23
19: ; preds = %12
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %14)
br label %23
21: ; preds = %9
%22 = call i8* @strcpy(i8* %4, i8* dereferenceable(1) %10)
br label %23
23: ; preds = %17, %19, %21
%24 = call i32 @free(i8* %10)
%25 = call %struct.filesystem* @fsopen(i8* %5)
%26 = icmp eq %struct.filesystem* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %34
29: ; preds = %23
%30 = call i32 @uls(%struct.filesystem* %25, i8* %4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %34
34: ; preds = %29, %32, %27
%35 = call i32 @fsclose(%struct.filesystem* %25)
%36 = call i32 @free(i8* %5)
br label %37
37: ; preds = %34, %7
%38 = phi i32 [ 0, %34 ], [ 10, %7 ]
ret i32 %38
}