#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 */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
scalar_t__ zmaster_lock_pid(char *);
int /*<<< orphan*/ zmaster_start(int /*<<< orphan*/, char *);
int main(int argc, char **argv) {
  char *config_file;
  int test_lock = 0;
  char *lock_fn = "zfile/pid/master.pid";
  if (argc == 1) {
    config_file = "main.cf";
  } else {
    config_file = argv[1];
  }
  if (!strcmp(config_file, "-test_lock")) {
    test_lock = 1;
  }
  if (zmaster_lock_pid(lock_fn)) {
    if (test_lock) {
      exit(0);
    }
  } else {
    if (test_lock) {
      exit(1);
    }
  }
  {
    int i;
    for (i = 0; i < 3; i++) {
      (void)close(i);
    }
    open("/dev/null", O_RDWR, 0);
  }
  zmaster_start(0, config_file);
  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)
movl   $0x0,-0x1c(%rbp)
lea    0xe7c(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a2 <main+0x42>
lea    0xe7c(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11ae <main+0x4e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ce <main+0x6e>
movl   $0x1,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <zmaster_lock_pid@plt>
cmp    $0x0,%rax
je     11f7 <main+0x97>
cmpl   $0x0,-0x1c(%rbp)
je     11f2 <main+0x92>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1210 <main+0xb0>
cmpl   $0x0,-0x1c(%rbp)
je     120b <main+0xab>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1210 <main+0xb0>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jge    1237 <main+0xd7>
mov    -0x2c(%rbp),%edi
call   1030 <close@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1217 <main+0xb7>
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
lea    0xde1(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    -0x18(%rbp),%rsi
xor    %edi,%edi
call   1060 <zmaster_start@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    1171 <main+0x11>
lea    0xea6(%rip),%rbx
jmp    1175 <main+0x15>
mov    0x8(%rsi),%rbx
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
mov    %eax,%ebp
lea    0xe73(%rip),%rdi
call   1040 <zmaster_lock_pid@plt>
test   %rax,%rax
je     11a2 <main+0x42>
test   %ebp,%ebp
jne    11a6 <main+0x46>
xor    %edi,%edi
call   1080 <exit@plt>
test   %ebp,%ebp
je     11eb <main+0x8b>
xor    %edi,%edi
call   1030 <close@plt>
mov    $0x1,%edi
call   1030 <close@plt>
mov    $0x2,%edi
call   1030 <close@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <zmaster_start@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"zfile/pid/master.pid\00"
@.str.1 = [8 x i8] c"main.cf\00"
@.str.2 = [11 x i8] c"-test_lock\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %17
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
br label %17
17: ; preds = %13, %12
%18 = load i8*, i8** %6
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17
store i32 1, i32* %7
br label %22
22: ; preds = %21, %17
%23 = load i8*, i8** %8
%24 = call i64 @zmaster_lock_pid(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %26
br label %38
32: ; preds = %22
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %32
br label %38
38: ; preds = %37, %31
store i32 0, i32* %9
br label %39
39: ; preds = %45, %38
%40 = load i32, i32* %9
%41 = icmp slt i32 %40, 3
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = load i32, i32* %9
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %42
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %39
48: ; preds = %39
%49 = load i32, i32* @O_RDWR
%50 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %49, i32 0)
%51 = load i8*, i8** %6
%52 = call i32 @zmaster_start(i32 0, i8* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"zfile/pid/master.pid\00"
@.str.1 = [8 x i8] c"main.cf\00"
@.str.2 = [11 x i8] c"-test_lock\00"
@.str.3 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
br label %7
7: ; preds = %2, %4
%8 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %2 ]
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
%11 = tail call i64 @zmaster_lock_pid(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
br i1 %10, label %14, label %19
14: ; preds = %13
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %7
br i1 %10, label %17, label %19
17: ; preds = %16
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %16, %13
%20 = tail call i32 @close(i32 0)
%21 = tail call i32 @close(i32 1)
%22 = tail call i32 @close(i32 2)
%23 = load i32, i32* @O_RDWR
%24 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 0)
%25 = tail call i32 @zmaster_start(i32 0, i8* %8)
ret i32 0
}