#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*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ umkdir(struct filesystem *, char *);
int main(int argc, char *argv[]) {
  struct filesystem *f;
  int i;
  char *image = getsetting("imagefile");
  char temp[1024];
  char *cwd;
  if (argc < 2) {
    printf("Usage: %s <directory> ...\n", argv[0]);
    return 10;
  }
  f = fsopen(image);
  if (!f) {
    return 10;
  }
  cwd = getsetting("cwd");
  for (i = 1; i < argc; i++) {
    if (argv[i][0] == '/') {
      umkdir(f, argv[i]);
    } else {
      if (!cwd) {
        sprintf(temp, "/%s", argv[i]);
      } else {
        sprintf(temp, "%s/%s", cwd, argv[i]);
      }
      compresspath(temp);
      umkdir(f, temp);
    }
  }
  if (cwd)
    free(cwd);
  free(image);
  fsclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
call   1070 <getsetting@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11d2 <main+0x52>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
movl   $0xa,-0x4(%rbp)
jmp    130c <main+0x18c>
mov    -0x28(%rbp),%rdi
call   1040 <fsopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f6 <main+0x76>
movl   $0xa,-0x4(%rbp)
jmp    130c <main+0x18c>
lea    0xe28(%rip),%rdi
call   1070 <getsetting@plt>
mov    %rax,-0x438(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d9 <main+0x159>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    124e <main+0xce>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1080 <umkdir@plt>
jmp    12c6 <main+0x146>
cmpq   $0x0,-0x438(%rbp)
jne    1282 <main+0x102>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    12aa <main+0x12a>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   10a0 <compresspath@plt>
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1080 <umkdir@plt>
jmp    12cb <main+0x14b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1210 <main+0x90>
cmpq   $0x0,-0x438(%rbp)
je     12f3 <main+0x173>
mov    -0x438(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fsclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
lea    0xe62(%rip),%rdi
call   1070 <getsetting@plt>
cmp    $0x1,%r14d
jg     11bd <main+0x3d>
mov    (%r15),%rsi
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
jmp    1254 <main+0xd4>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <fsopen@plt>
test   %rax,%rax
je     1254 <main+0xd4>
mov    %rax,%rbx
mov    %rbp,0x8(%rsp)
lea    0xe45(%rip),%rdi
call   1070 <getsetting@plt>
mov    %rax,%r12
mov    %r14d,%r14d
mov    $0x1,%r13d
lea    0x10(%rsp),%rbp
jmp    1230 <main+0xb0>
nopl   0x0(%rax,%rax,1)
lea    0xe22(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   10a0 <compresspath@plt>
mov    %rbp,%rcx
mov    %rbx,%rdi
mov    %rcx,%rsi
call   1080 <umkdir@plt>
add    $0x1,%r13
cmp    %r13,%r14
je     125b <main+0xdb>
mov    (%r15,%r13,8),%rcx
cmpb   $0x2f,(%rcx)
je     121c <main+0x9c>
mov    %rbp,%rdi
test   %r12,%r12
jne    1200 <main+0x80>
lea    0xde3(%rip),%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
jmp    1211 <main+0x91>
mov    $0xa,%eax
jmp    127c <main+0xfc>
test   %r12,%r12
je     1268 <main+0xe8>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1060 <fsclose@plt>
xor    %eax,%eax
add    $0x418,%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 = [27 x i8] c"Usage: %s <directory> ...\0A\00"
@.str.2 = [4 x i8] c"cwd\00"
@.str.3 = [4 x i8] c"/%s\00"
@.str.4 = [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 i32
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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 i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 10, i32* %3
br label %90
19: ; preds = %2
%20 = load i8*, i8** %8
%21 = call %struct.filesystem* @fsopen(i8* %20)
store %struct.filesystem* %21, %struct.filesystem** %6
%22 = load %struct.filesystem*, %struct.filesystem** %6
%23 = icmp ne %struct.filesystem* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 10, i32* %3
br label %90
25: ; preds = %19
%26 = call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i8* %26, i8** %10
store i32 1, i32* %7
br label %27
27: ; preds = %76, %25
%28 = load i32, i32* %7
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %79
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 47
br i1 %40, label %41, label %49
41: ; preds = %31
%42 = load %struct.filesystem*, %struct.filesystem** %6
%43 = load i8**, i8*** %5
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @umkdir(%struct.filesystem* %42, i8* %47)
br label %75
49: ; preds = %31
%50 = load i8*, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %60, label %52
52: ; preds = %49
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%54 = load i8**, i8*** %5
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %58)
br label %69
60: ; preds = %49
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%62 = load i8*, i8** %10
%63 = load i8**, i8*** %5
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %61, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %62, i8* %67)
br label %69
69: ; preds = %60, %52
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%71 = call i32 @compresspath(i8* %70)
%72 = load %struct.filesystem*, %struct.filesystem** %6
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%74 = call i32 @umkdir(%struct.filesystem* %72, i8* %73)
br label %75
75: ; preds = %69, %41
br label %76
76: ; preds = %75
%77 = load i32, i32* %7
%78 = add nsw i32 %77, 1
store i32 %78, i32* %7
br label %27
79: ; preds = %27
%80 = load i8*, i8** %10
%81 = icmp ne i8* %80, null
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i8*, i8** %10
%84 = call i32 @free(i8* %83)
br label %85
85: ; preds = %82, %79
%86 = load i8*, i8** %8
%87 = call i32 @free(i8* %86)
%88 = load %struct.filesystem*, %struct.filesystem** %6
%89 = call i32 @fsclose(%struct.filesystem* %88)
store i32 0, i32* %3
br label %90
90: ; preds = %85, %24, %14
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
%struct.filesystem = type { i32 }
@.str = [10 x i8] c"imagefile\00"
@.str.1 = [27 x i8] c"Usage: %s <directory> ...\0A\00"
@.str.2 = [4 x i8] c"cwd\00"
@.str.3 = [4 x i8] c"/%s\00"
@.str.4 = [6 x i8] c"%s/%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = tail call i8* @getsetting(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %42
10: ; preds = %2
%11 = tail call %struct.filesystem* @fsopen(i8* %4)
%12 = icmp eq %struct.filesystem* %11, null
br i1 %12, label %42, label %13
13: ; preds = %10
%14 = tail call i8* @getsetting(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i8* %14, null
%16 = zext i32 %0 to i64
br label %17
17: ; preds = %13, %30
%18 = phi i64 [ 1, %13 ], [ %33, %30 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 47
br i1 %22, label %30, label %23
23: ; preds = %17
br i1 %15, label %24, label %26
24: ; preds = %23
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %28
26: ; preds = %23
%27 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %14, i8* %20)
br label %28
28: ; preds = %26, %24
%29 = call i32 @compresspath(i8* %5)
br label %30
30: ; preds = %17, %28
%31 = phi i8* [ %5, %28 ], [ %20, %17 ]
%32 = call i32 @umkdir(%struct.filesystem* %11, i8* %31)
%33 = add nuw nsw i64 %18, 1
%34 = icmp eq i64 %33, %16
br i1 %34, label %35, label %17
35: ; preds = %30
%36 = icmp eq i8* %14, null
br i1 %36, label %39, label %37
37: ; preds = %35
%38 = call i32 @free(i8* %14)
br label %39
39: ; preds = %37, %35
%40 = call i32 @free(i8* %4)
%41 = call i32 @fsclose(%struct.filesystem* %11)
br label %42
42: ; preds = %10, %39, %7
%43 = phi i32 [ 10, %7 ], [ 0, %39 ], [ 10, %10 ]
ret i32 %43
}