#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*/ compresspath(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fsclose(struct filesystem *);
struct filesystem *fsopen(char *);
char *getsetting(char *);
int /*<<< orphan*/ inodebypath(struct filesystem *, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ storesetting(char *, char *);
int main(int argc, char *argv[]) {
  struct filesystem *f;
  char *temp = malloc(1024);
  char *image;
  image = getsetting("imagefile");
  if (!image) {
    printf("Have you run ulogin?\n");
    return 10;
  }
  if (argc != 2) {
    printf("Usage: %s <dir>\n", argv[0]);
    free(image);
    return 10;
  }
  f = fsopen(image);
  if (!f) {
    if (image)
      free(image);
    return 10;
  }
  if (argv[1][0] == '/') {
    if (!inodebypath(f, argv[1])) {
      printf("%s not found\n", argv[1]);
    } else {
      storesetting("cwd", argv[1]);
    }
    fsclose(f);
    free(image);
    return 0;
  } else {
    char *cwd = getsetting("cwd");
    if (!cwd) {
      sprintf(temp, "/%s", argv[1]);
    } else {
      sprintf(temp, "%s/%s", cwd, argv[1]);
      compresspath(temp);
      free(cwd);
    }
    if (!inodebypath(f, temp)) {
      printf("%s not found\n", temp);
    } else {
      storesetting("cwd", temp);
    }
    free(image);
    fsclose(f);
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe35(%rip),%rdi
call   10a0 <getsetting@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f9 <main+0x59>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xa,-0x4(%rbp)
jmp    13a0 <main+0x200>
cmpl   $0x2,-0x8(%rbp)
je     122d <main+0x8d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xa,-0x4(%rbp)
jmp    13a0 <main+0x200>
mov    -0x28(%rbp),%rdi
call   1050 <fsopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1265 <main+0xc5>
cmpq   $0x0,-0x28(%rbp)
je     1259 <main+0xb9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xa,-0x4(%rbp)
jmp    13a0 <main+0x200>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    12e0 <main+0x140>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <inodebypath@plt>
cmp    $0x0,%eax
jne    12ae <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12c2 <main+0x122>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd82(%rip),%rdi
call   1090 <storesetting@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fsclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a0 <main+0x200>
lea    0xd58(%rip),%rdi
call   10a0 <getsetting@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    131a <main+0x17a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
jmp    134a <main+0x1aa>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xd12(%rip),%rsi
mov    $0x0,%al
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <compresspath@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <inodebypath@plt>
cmp    $0x0,%eax
jne    1377 <main+0x1d7>
mov    -0x20(%rbp),%rsi
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1387 <main+0x1e7>
mov    -0x20(%rbp),%rsi
lea    0xcbd(%rip),%rdi
call   1090 <storesetting@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fsclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
lea    0xe2c(%rip),%rdi
call   10b0 <getsetting@plt>
test   %rax,%rax
je     1224 <main+0x74>
mov    %rax,%r12
cmp    $0x2,%ebp
jne    123a <main+0x8a>
mov    %r12,%rdi
call   1060 <fsopen@plt>
test   %rax,%rax
je     124b <main+0x9b>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
cmpb   $0x2f,(%rsi)
jne    125d <main+0xad>
mov    %r14,%rdi
call   1050 <inodebypath@plt>
mov    0x8(%rbx),%rsi
test   %eax,%eax
je     129b <main+0xeb>
lea    0xe0f(%rip),%rdi
call   10a0 <storesetting@plt>
jmp    12a9 <main+0xf9>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%eax
jmp    1312 <main+0x162>
mov    (%rbx),%rsi
lea    0xdc6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0xa,%eax
jmp    1312 <main+0x162>
lea    0xdc5(%rip),%rdi
call   10b0 <getsetting@plt>
mov    0x8(%rbx),%rcx
test   %rax,%rax
je     12bb <main+0x10b>
mov    %rax,%r13
lea    0xdb1(%rip),%rsi
mov    %r15,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r15,%rdi
call   10d0 <compresspath@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    12cf <main+0x11f>
lea    0xd79(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1080 <fsclose@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1310 <main+0x160>
lea    0xd6d(%rip),%rsi
mov    %r15,%rdi
mov    %rcx,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <inodebypath@plt>
test   %eax,%eax
je     12ef <main+0x13f>
lea    0xd44(%rip),%rdi
mov    %r15,%rsi
call   10a0 <storesetting@plt>
jmp    1300 <main+0x150>
lea    0xd25(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1080 <fsclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [17 x i8] c"Usage: %s <dir>\0A\00"
@.str.3 = [14 x i8] c"%s not found\0A\00"
@.str.4 = [4 x i8] c"cwd\00"
@.str.5 = [4 x i8] c"/%s\00"
@.str.6 = [6 x i8] c"%s/%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.filesystem*
%7 = alloca 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* @malloc(i32 1024)
store i8* %10, i8** %7
%11 = call i8* @getsetting(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = 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 %105
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %8
%25 = call i32 @free(i8* %24)
store i32 10, i32* %3
br label %105
26: ; preds = %16
%27 = load i8*, i8** %8
%28 = call %struct.filesystem* @fsopen(i8* %27)
store %struct.filesystem* %28, %struct.filesystem** %6
%29 = load %struct.filesystem*, %struct.filesystem** %6
%30 = icmp ne %struct.filesystem* %29, null
br i1 %30, label %38, label %31
31: ; preds = %26
%32 = load i8*, i8** %8
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %8
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %34, %31
store i32 10, i32* %3
br label %105
38: ; preds = %26
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 47
br i1 %45, label %46, label %68
46: ; preds = %38
%47 = load %struct.filesystem*, %struct.filesystem** %6
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 @inodebypath(%struct.filesystem* %47, i8* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %46
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %56)
br label %63
58: ; preds = %46
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 @storesetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %58, %53
%64 = load %struct.filesystem*, %struct.filesystem** %6
%65 = call i32 @fsclose(%struct.filesystem* %64)
%66 = load i8*, i8** %8
%67 = call i32 @free(i8* %66)
store i32 0, i32* %3
br label %105
68: ; preds = %38
%69 = call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i8* %69, i8** %9
%70 = load i8*, i8** %9
%71 = icmp ne i8* %70, null
br i1 %71, label %78, label %72
72: ; preds = %68
%73 = load i8*, i8** %7
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %76)
br label %89
78: ; preds = %68
%79 = load i8*, i8** %7
%80 = load i8*, i8** %9
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 1
%83 = load i8*, i8** %82
%84 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %79, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %80, i8* %83)
%85 = load i8*, i8** %7
%86 = call i32 @compresspath(i8* %85)
%87 = load i8*, i8** %9
%88 = call i32 @free(i8* %87)
br label %89
89: ; preds = %78, %72
%90 = load %struct.filesystem*, %struct.filesystem** %6
%91 = load i8*, i8** %7
%92 = call i32 @inodebypath(%struct.filesystem* %90, i8* %91)
%93 = icmp ne i32 %92, 0
br i1 %93, label %97, label %94
94: ; preds = %89
%95 = load i8*, i8** %7
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %95)
br label %100
97: ; preds = %89
%98 = load i8*, i8** %7
%99 = call i32 @storesetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %98)
br label %100
100: ; preds = %97, %94
%101 = load i8*, i8** %8
%102 = call i32 @free(i8* %101)
%103 = load %struct.filesystem*, %struct.filesystem** %6
%104 = call i32 @fsclose(%struct.filesystem* %103)
store i32 0, i32* %3
br label %105
105: ; preds = %100, %63, %37, %19, %14
%106 = load i32, i32* %3
ret i32 %106
}

LLVM IR (-O2):
%struct.filesystem = type { i32 }
@.str = [10 x i8] c"imagefile\00"
@.str.2 = [17 x i8] c"Usage: %s <dir>\0A\00"
@.str.3 = [14 x i8] c"%s not found\0A\00"
@.str.4 = [4 x i8] c"cwd\00"
@.str.5 = [4 x i8] c"/%s\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@str = [21 x i8] c"Have you run ulogin?\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call i8* @getsetting(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %55
8: ; preds = %2
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = tail call i32 @free(i8* %4)
br label %55
14: ; preds = %8
%15 = tail call %struct.filesystem* @fsopen(i8* %4)
%16 = icmp eq %struct.filesystem* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @free(i8* %4)
br label %55
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 47
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = tail call i32 @inodebypath(%struct.filesystem* %15, i8* %21)
%26 = icmp eq i32 %25, 0
%27 = load i8*, i8** %20
br i1 %26, label %28, label %30
28: ; preds = %24
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %32
30: ; preds = %24
%31 = tail call i32 @storesetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %27)
br label %32
32: ; preds = %30, %28
%33 = tail call i32 @fsclose(%struct.filesystem* %15)
%34 = tail call i32 @free(i8* %4)
br label %55
35: ; preds = %19
%36 = tail call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i8* %36, null
%38 = load i8*, i8** %20
br i1 %37, label %39, label %41
39: ; preds = %35
%40 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %38)
br label %45
41: ; preds = %35
%42 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %36, i8* %38)
%43 = tail call i32 @compresspath(i8* %3)
%44 = tail call i32 @free(i8* %36)
br label %45
45: ; preds = %41, %39
%46 = tail call i32 @inodebypath(%struct.filesystem* %15, i8* %3)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %52
50: ; preds = %45
%51 = tail call i32 @storesetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %3)
br label %52
52: ; preds = %50, %48
%53 = tail call i32 @free(i8* %4)
%54 = tail call i32 @fsclose(%struct.filesystem* %15)
br label %55
55: ; preds = %52, %32, %17, %10, %6
%56 = phi i32 [ 10, %10 ], [ 0, %32 ], [ 0, %52 ], [ 10, %17 ], [ 10, %6 ]
ret i32 %56
}