#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 */

/* Variables and functions */
long atoi(char *);
int /*<<< orphan*/ cleanup();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ run();
int /*<<< orphan*/ say(char *, ...);
int /*<<< orphan*/ setup(char const *);
int /*<<< orphan*/ srandom(long);
int main(int argc, char *argv[]) {
  const char *fs;
  long seed = 0;
  say("Concurrent directory ops test\n");
  if (argc == 0 || argv == NULL) {
    say("Warning: argc is 0 - assuming you mean to run on lhd1: "
        "with seed 0\n");
    fs = "lhd1:";
  } else if (argc == 2) {
    fs = argv[1];
  } else if (argc == 3) {
    fs = argv[1];
    seed = atoi(argv[2]);
  } else {
    say("Usage: dirconc filesystem [random-seed]\n");
    exit(1);
  }
  srandom(seed);
  setup(fs);
  say("Starting in %s/%s\n", fs, "dirconc");
  run();
  say("Cleaning up\n");
  cleanup();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1080 <say@plt>
cmpl   $0x0,-0x8(%rbp)
je     11b1 <main+0x41>
cmpq   $0x0,-0x10(%rbp)
jne    11cf <main+0x5f>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1080 <say@plt>
lea    0xe9d(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1238 <main+0xc8>
cmpl   $0x2,-0x8(%rbp)
jne    11ea <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1233 <main+0xc3>
cmpl   $0x3,-0x8(%rbp)
jne    1216 <main+0xa6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x20(%rbp)
jmp    122e <main+0xbe>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1080 <say@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1233 <main+0xc3>
jmp    1238 <main+0xc8>
mov    -0x20(%rbp),%rdi
call   1030 <srandom@plt>
mov    -0x18(%rbp),%rdi
call   1090 <setup@plt>
mov    -0x18(%rbp),%rsi
lea    0xe3d(%rip),%rdi
lea    0xe49(%rip),%rdx
mov    $0x0,%al
call   1080 <say@plt>
mov    $0x0,%al
call   1040 <run@plt>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1080 <say@plt>
mov    $0x0,%al
call   1050 <cleanup@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1080 <say@plt>
test   %ebx,%ebx
je     11a7 <main+0x37>
test   %r14,%r14
je     11a7 <main+0x37>
cmp    $0x3,%ebx
je     11c1 <main+0x51>
cmp    $0x2,%ebx
jne    121f <main+0xaf>
mov    0x8(%r14),%rbx
xor    %r14d,%r14d
jmp    11d1 <main+0x61>
lea    0xe71(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1080 <say@plt>
lea    0xea4(%rip),%rbx
jmp    11d1 <main+0x61>
mov    0x8(%r14),%rbx
mov    0x10(%r14),%rdi
call   1060 <atoi@plt>
mov    %rax,%r14
mov    %r14,%rdi
call   1030 <srandom@plt>
mov    %rbx,%rdi
call   1090 <setup@plt>
lea    0xeaa(%rip),%rdi
lea    0xeb6(%rip),%rdx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <say@plt>
xor    %eax,%eax
call   1040 <run@plt>
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1080 <say@plt>
xor    %eax,%eax
call   1050 <cleanup@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1080 <say@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Concurrent directory ops test\0A\00"
@.str.1 = [68 x i8] c"Warning: argc is 0 - assuming you mean to run on lhd1: with seed 0\0A\00"
@.str.2 = [6 x i8] c"lhd1:\00"
@.str.3 = [41 x i8] c"Usage: dirconc filesystem [random-seed]\0A\00"
@.str.4 = [19 x i8] c"Starting in %s/%s\0A\00"
@.str.5 = [8 x i8] c"dirconc\00"
@.str.6 = [13 x i8] c"Cleaning up\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
%8 = call i32 (i8*, ...) @say(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = icmp eq i8** %12, null
br i1 %13, label %14, label %16
14: ; preds = %11, %2
%15 = call i32 (i8*, ...) @say(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %39
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
br label %38
23: ; preds = %16
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
store i8* %29, i8** %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i64 @atoi(i8* %32)
store i64 %33, i64* %7
br label %37
34: ; preds = %23
%35 = call i32 (i8*, ...) @say(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
br label %38
38: ; preds = %37, %19
br label %39
39: ; preds = %38, %14
%40 = load i64, i64* %7
%41 = call i32 @srandom(i64 %40)
%42 = load i8*, i8** %6
%43 = call i32 @setup(i8* %42)
%44 = load i8*, i8** %6
%45 = call i32 (i8*, ...) @say(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 (...) @run()
%47 = call i32 (i8*, ...) @say(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%48 = call i32 (...) @cleanup()
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Concurrent directory ops test\0A\00"
@.str.1 = [68 x i8] c"Warning: argc is 0 - assuming you mean to run on lhd1: with seed 0\0A\00"
@.str.2 = [6 x i8] c"lhd1:\00"
@.str.3 = [41 x i8] c"Usage: dirconc filesystem [random-seed]\0A\00"
@.str.4 = [19 x i8] c"Starting in %s/%s\0A\00"
@.str.5 = [8 x i8] c"dirconc\00"
@.str.6 = [13 x i8] c"Cleaning up\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 (i8*, ...) @say(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %0, 0
%5 = icmp eq i8** %1, null
%6 = or i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @say(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
br label %22
9: ; preds = %2
switch i32 %0, label %19 [
i32 2, label %10
i32 3, label %13
]
10: ; preds = %9
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
br label %22
13: ; preds = %9
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @atoi(i8* %17)
br label %22
19: ; preds = %9
%20 = tail call i32 (i8*, ...) @say(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %10, %13, %7
%23 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %7 ], [ %12, %10 ], [ %15, %13 ]
%24 = phi i64 [ 0, %7 ], [ 0, %10 ], [ %18, %13 ]
%25 = tail call i32 @srandom(i64 %24)
%26 = tail call i32 @setup(i8* %23)
%27 = tail call i32 (i8*, ...) @say(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%28 = tail call i32 (...) @run()
%29 = tail call i32 (i8*, ...) @say(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%30 = tail call i32 (...) @cleanup()
ret i32 0
}