#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 stat {
  int /*<<< orphan*/ member_0;
};
struct flock {
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
  int /*<<< orphan*/ l_type;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_WRLCK;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ errno;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fstat64(int, struct stat *);
int open(char *, int, int /*<<< orphan*/);
int run_child(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int fd = -1, ret = -1, status = 0;
  char *filename = NULL, *cmd = NULL;
  struct stat stbuf = {
      0,
  };
  struct flock lock = {
      0,
  };
  if (argc != 3) {
    fprintf(stderr,
            "Usage: %s <filename> "
            "<gluster-cmd-to-trigger-graph-switch>\n",
            argv[0]);
    goto out;
  }
  filename = argv[1];
  cmd = argv[2];
  fd = open(filename, O_RDWR | O_CREAT, 0);
  if (fd < 0) {
    fprintf(stderr, "open (%s) failed (%s)\n", filename, strerror(errno));
    goto out;
  }
  lock.l_type = F_WRLCK;
  lock.l_whence = SEEK_SET;
  lock.l_start = 0;
  lock.l_len = 0;
  ret = fcntl(fd, F_SETLK, &lock);
  if (ret < 0) {
    fprintf(stderr, "fcntl failed (%s)\n", strerror(errno));
    goto out;
  }
  system(cmd);
  ret = fstat64(fd, &stbuf);
  if (ret < 0) {
    fprintf(stderr, "fstat64 failure (%s)\n", strerror(errno));
    goto out;
  }
  sleep(10);
  ret = fork();
  if (ret == 0) {
    ret = run_child(filename);
  } else {
    wait(&status);
    if (WIFEXITED(status)) {
      ret = WEXITSTATUS(status);
    } else {
      ret = 0;
    }
  }
out:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
je     1258 <main+0x88>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1416 <main+0x246>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    0x2d74(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12d9 <main+0x109>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1416 <main+0x246>
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1030 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1356 <main+0x186>
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1416 <main+0x246>
mov    -0x30(%rbp),%rdi
call   1040 <system@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10b0 <fstat64@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13ab <main+0x1db>
mov    0x2c49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1416 <main+0x246>
mov    $0xa,%edi
call   10d0 <sleep@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    13da <main+0x20a>
mov    -0x28(%rbp),%rdi
call   1090 <run_child@plt>
mov    %eax,-0x18(%rbp)
jmp    1411 <main+0x241>
lea    -0x1c(%rbp),%rdi
call   10e0 <wait@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1405 <main+0x235>
mov    -0x1c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,-0x18(%rbp)
jmp    140c <main+0x23c>
movl   $0x0,-0x18(%rbp)
jmp    1411 <main+0x241>
jmp    1416 <main+0x246>
mov    -0x18(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movl   $0x0,0x4(%rsp)
movl   $0x0,0x8(%rsp)
movq   $0x0,0x28(%rsp)
cmp    $0x3,%edi
jne    12ba <main+0xfa>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%r15
mov    0x2de5(%rip),%rax
mov    0x2df6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
xor    %edx,%edx
call   1070 <open@plt>
test   %eax,%eax
js     12de <main+0x11e>
mov    %eax,%ebp
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %ebp,%edi
call   1030 <fcntl@plt>
test   %eax,%eax
js     1312 <main+0x152>
mov    %r15,%rdi
call   1040 <system@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
call   10a0 <fstat64@plt>
test   %eax,%eax
js     1334 <main+0x174>
mov    $0xa,%edi
call   10c0 <sleep@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1362 <main+0x1a2>
lea    0x4(%rsp),%rdi
call   10d0 <wait@plt>
mov    0x4(%rsp),%edi
call   1090 <WIFEXITED@plt>
test   %rax,%rax
je     136c <main+0x1ac>
mov    0x4(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
jmp    136a <main+0x1aa>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd33(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    136c <main+0x1ac>
mov    0x2ce3(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd40(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    136c <main+0x1ac>
mov    %eax,%ebx
mov    0x2cad(%rip),%rax
mov    (%rax),%ebp
mov    0x2c9c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd21(%rip),%rsi
jmp    1354 <main+0x194>
mov    %eax,%ebx
mov    0x2c8b(%rip),%rax
mov    (%rax),%ebp
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd12(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    136c <main+0x1ac>
mov    %r14,%rdi
call   1080 <run_child@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.flock = type { i64, i64, i32, i32, i32 }
@stderr = global i32 0
@.str = [60 x i8] c"Usage: %s <filename> <gluster-cmd-to-trigger-graph-switch>\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [23 x i8] c"open (%s) failed (%s)\0A\00"
@errno = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.2 = [19 x i8] c"fcntl failed (%s)\0A\00"
@.str.3 = [22 x i8] c"fstat64 failure (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca %struct.stat
%12 = alloca %struct.flock
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %8
store i8* null, i8** %9
store i8* null, i8** %10
%13 = bitcast %struct.stat* %11 to i8*
%14 = bitcast %struct.flock* %12 to i8*
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %91
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %9
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %10
%30 = load i8*, i8** %9
%31 = load i32, i32* @O_RDWR
%32 = load i32, i32* @O_CREAT
%33 = or i32 %31, %32
%34 = call i32 @open(i8* %30, i32 %33, i32 0)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %23
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %9
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %41)
br label %91
43: ; preds = %23
%44 = load i32, i32* @F_WRLCK
%45 = getelementptr inbounds %struct.flock, %struct.flock* %12, i32 0, i32 3
store i32 %44, i32* %45
%46 = load i32, i32* @SEEK_SET
%47 = getelementptr inbounds %struct.flock, %struct.flock* %12, i32 0, i32 2
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.flock, %struct.flock* %12, i32 0, i32 1
store i64 0, i64* %48
%49 = getelementptr inbounds %struct.flock, %struct.flock* %12, i32 0, i32 0
store i64 0, i64* %49
%50 = load i32, i32* %6
%51 = load i32, i32* @F_SETLK
%52 = call i32 @fcntl(i32 %50, i32 %51, %struct.flock* %12)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %43
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %58)
br label %91
60: ; preds = %43
%61 = load i8*, i8** %10
%62 = call i32 @system(i8* %61)
%63 = load i32, i32* %6
%64 = call i32 @fstat64(i32 %63, %struct.stat* %11)
store i32 %64, i32* %7
%65 = load i32, i32* %7
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %70)
br label %91
72: ; preds = %60
%73 = call i32 @sleep(i32 10)
%74 = call i32 (...) @fork()
store i32 %74, i32* %7
%75 = load i32, i32* %7
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i8*, i8** %9
%79 = call i32 @run_child(i8* %78)
store i32 %79, i32* %7
br label %90
80: ; preds = %72
%81 = call i32 @wait(i32* %8)
%82 = load i32, i32* %8
%83 = call i64 @WIFEXITED(i32 %82)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %80
%86 = load i32, i32* %8
%87 = call i32 @WEXITSTATUS(i32 %86)
store i32 %87, i32* %7
br label %89
88: ; preds = %80
store i32 0, i32* %7
br label %89
89: ; preds = %88, %85
br label %90
90: ; preds = %89, %77
br label %91
91: ; preds = %90, %67, %55, %37, %17
%92 = load i32, i32* %7
ret i32 %92
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.flock = type { i64, i64, i32, i32, i32 }
@stderr = global i32 0
@.str = [60 x i8] c"Usage: %s <filename> <gluster-cmd-to-trigger-graph-switch>\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.1 = [23 x i8] c"open (%s) failed (%s)\0A\00"
@errno = global i32 0
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.2 = [19 x i8] c"fcntl failed (%s)\0A\00"
@.str.3 = [22 x i8] c"fstat64 failure (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca %struct.flock
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast %struct.stat* %4 to i8*
%8 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
store i32 0, i32* %8
%9 = bitcast %struct.flock* %5 to i8*
%10 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 4
%11 = bitcast i32* %10 to i64*
store i64 0, i64* %11
%12 = icmp eq i32 %0, 3
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %69
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_CREAT
%24 = or i32 %23, %22
%25 = tail call i32 @open(i8* %19, i32 %24, i32 0)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %30)
br label %69
32: ; preds = %17
%33 = load i32, i32* @F_WRLCK
%34 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 3
store i32 %33, i32* %34
%35 = load i32, i32* @SEEK_SET
%36 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 2
store i32 %35, i32* %36
%37 = bitcast %struct.flock* %5 to i8*
%38 = load i32, i32* @F_SETLK
%39 = call i32 @fcntl(i32 %25, i32 %38, %struct.flock* %5)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %32
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %69
46: ; preds = %32
%47 = call i32 @system(i8* %21)
%48 = call i32 @fstat64(i32 %25, %struct.stat* %4)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %69
55: ; preds = %46
%56 = call i32 @sleep(i32 10)
%57 = call i32 (...) @fork()
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @run_child(i8* %19)
br label %69
61: ; preds = %55
%62 = call i32 @wait(i32* %3)
%63 = load i32, i32* %3
%64 = call i64 @WIFEXITED(i32 %63)
%65 = icmp eq i64 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %61
%67 = load i32, i32* %3
%68 = call i32 @WEXITSTATUS(i32 %67)
br label %69
69: ; preds = %61, %59, %66, %50, %41, %27, %13
%70 = phi i32 [ -1, %13 ], [ -1, %27 ], [ %39, %41 ], [ %48, %50 ], [ %60, %59 ], [ %68, %66 ], [ 0, %61 ]
ret i32 %70
}