#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 flock {
  scalar_t__ l_type;
  int l_start;
  int l_len;
  void *l_pid;
  scalar_t__ l_whence;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ F_GETLK;
int /*<<< orphan*/ F_SETLK;
scalar_t__ F_UNLCK;
void *F_WRLCK;
int O_CREAT;
int O_EXCL;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ close(int);
int create_temp_file(char *, char **);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
void *getpid();
int open(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ sys_waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int do_test(void) {
  struct flock lock;
  int fd, ret, status = 1;
  pid_t pid;
  char *fname;
  fd = create_temp_file("tst-flock3-", &fname);
  if (fd == -1)
    return -1;
  close(fd);
  alarm(10);
  if (!(pid = fork())) {
    sleep(2);
    fd = open(fname, O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "ERROR: failed to open %s (errno=%d)\n", fname,
              (int)errno);
      exit(1);
    }
    lock.l_type = F_WRLCK;
    lock.l_whence = 0;
    lock.l_start = 0x100000000LL;
    lock.l_len = 4;
    lock.l_pid = getpid();
    lock.l_type = F_WRLCK;
    ret = fcntl(fd, F_GETLK, &lock);
    if ((ret == -1) || (lock.l_type == F_UNLCK)) {
      fprintf(stderr, "ERROR: lock test failed (ret=%d errno=%d)\n", ret,
              (int)errno);
      exit(1);
    } else {
      exit(0);
    }
  }
  unlink(fname);
  fd = open(fname, O_RDWR | O_CREAT | O_EXCL, 0600);
  if (fd == -1) {
    fprintf(stderr, "ERROR: failed to open %s (errno=%d)\n", fname, (int)errno);
    exit(1);
  }
  lock.l_type = F_WRLCK;
  lock.l_whence = 0;
  lock.l_start = 0;
  lock.l_len = 0x100000004LL;
  lock.l_pid = getpid();
  ret = fcntl(fd, F_SETLK, &lock);
  sys_waitpid(pid, &status, 0);
  if (ret != 0) {
    fprintf(stderr, "ERROR: failed to lock %s (errno=%d)\n", fname, (int)errno);
    exit(1);
  }
  if (lock.l_len < 0x100000004LL) {
    fprintf(stderr, "ERROR: settign lock overflowed\n");
    exit(1);
  }
  status = (status == 0) ? 0 : 1;
  if (status) {
    fprintf(stderr, "ERROR: lock test failed with status=%d\n", status);
  }
  exit(status);
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x1,-0x2c(%rbp)
lea    0xe2a(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <create_temp_file@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11f7 <do_test+0x37>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbp
ret
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    $0xa,%edi
call   1070 <alarm@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jne    1322 <do_test+0x162>
mov    $0x2,%edi
call   10d0 <sleep@plt>
mov    -0x38(%rbp),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1278 <do_test+0xb8>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    0x2d45(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x4,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,-0x10(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <fcntl@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
je     12eb <do_test+0x12b>
mov    -0x20(%rbp),%rax
mov    0x2cde(%rip),%rcx
cmp    (%rcx),%rax
jne    131b <do_test+0x15b>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    0x2ca2(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x38(%rbp),%rdi
mov    0x2caa(%rip),%rax
mov    (%rax),%esi
mov    0x2cb9(%rip),%rax
or     (%rax),%esi
mov    0x2c60(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1394 <do_test+0x1d4>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    0x2c29(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2bfd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x4,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2c03(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <fcntl@plt>
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   10b0 <sys_waitpid@plt>
cmpl   $0x0,-0x28(%rbp)
je     1424 <do_test+0x264>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    0x2b99(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xc49(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movslq -0x14(%rbp),%rax
movabs $0x100000004,%rcx
cmp    %rcx,%rax
jge    145c <do_test+0x29c>
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
lea    0xc36(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x2c(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1493 <do_test+0x2d3>
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xc15(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movl   $0x1,0x14(%rsp)
lea    0xe2b(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <create_temp_file@plt>
cmp    $0xffffffff,%eax
jne    11f0 <do_test+0x30>
mov    $0xffffffff,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%edi
call   1080 <close@plt>
mov    $0xa,%edi
call   1070 <alarm@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
jne    12d2 <do_test+0x112>
mov    $0x2,%edi
call   10d0 <sleep@plt>
mov    0x8(%rsp),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     130f <do_test+0x14f>
mov    %eax,%ebx
mov    0x2d57(%rip),%rbp
mov    0x0(%rbp),%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x30(%rsp)
movabs $0x400000000,%rax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rax,0x28(%rsp)
mov    0x0(%rbp),%rax
mov    %rax,0x18(%rsp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %ebx,%edi
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     12a6 <do_test+0xe6>
mov    0x18(%rsp),%rcx
mov    0x2d23(%rip),%rdx
cmp    (%rdx),%rcx
jne    13d7 <do_test+0x217>
mov    0x2d03(%rip),%rcx
mov    (%rcx),%edi
mov    0x2cea(%rip),%rcx
mov    (%rcx),%ecx
lea    0xd72(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <unlink@plt>
mov    0x2cfb(%rip),%rax
mov    0x2d0c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x8(%rsp),%rdi
mov    0x2cac(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    133e <do_test+0x17e>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
mov    0x2c7c(%rip),%rax
mov    (%rax),%ecx
lea    0xcdf(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%ebp
mov    0x2c51(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x30(%rsp)
movabs $0x400000000,%rax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %rax,0x28(%rsp)
mov    0x2c56(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %ebp,%edi
call   1040 <fcntl@plt>
mov    %eax,%ebp
lea    0x14(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   10b0 <sys_waitpid@plt>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
test   %ebp,%ebp
jne    13bd <do_test+0x1fd>
lea    0xcd5(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x8(%rsp),%rdx
mov    0x2bd7(%rip),%rax
mov    (%rax),%ecx
lea    0xc8a(%rip),%rsi
jmp    132d <do_test+0x16d>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.flock = type { i64, i32, i32, i8*, i64 }
@.str = [12 x i8] c"tst-flock3-\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"ERROR: failed to open %s (errno=%d)\0A\00"
@errno = global i64 0
@F_WRLCK = global i8* null
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
@.str.2 = [43 x i8] c"ERROR: lock test failed (ret=%d errno=%d)\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@F_SETLK = global i32 0
@.str.3 = [37 x i8] c"ERROR: failed to lock %s (errno=%d)\0A\00"
@.str.4 = [32 x i8] c"ERROR: settign lock overflowed\0A\00"
@.str.5 = [40 x i8] c"ERROR: lock test failed with status=%d\0A\00"
define i32 @do_test() {
%1 = alloca %struct.flock
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 1, i32* %4
%7 = call i32 @create_temp_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %0
ret i32 -1
11: ; preds = %0
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = call i32 @alarm(i32 10)
%15 = call i32 (...) @fork()
store i32 %15, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %62, label %17
17: ; preds = %11
%18 = call i32 @sleep(i32 2)
%19 = load i8*, i8** %6
%20 = load i32, i32* @O_RDONLY
%21 = call i32 (i8*, i32, ...) @open(i8* %19, i32 %20)
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %31
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %6
%27 = load i64, i64* @errno
%28 = trunc i64 %27 to i32
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = load i8*, i8** @F_WRLCK
%33 = ptrtoint i8* %32 to i64
%34 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 0
store i64 %33, i64* %34
%35 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 4
store i64 0, i64* %35
%36 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 1
store i32 0, i32* %36
%37 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 2
store i32 4, i32* %37
%38 = call i8* (...) @getpid()
%39 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 3
store i8* %38, i8** %39
%40 = load i8*, i8** @F_WRLCK
%41 = ptrtoint i8* %40 to i64
%42 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 0
store i64 %41, i64* %42
%43 = load i32, i32* %2
%44 = load i32, i32* @F_GETLK
%45 = call i32 @fcntl(i32 %43, i32 %44, %struct.flock* %1)
store i32 %45, i32* %3
%46 = load i32, i32* %3
%47 = icmp eq i32 %46, -1
br i1 %47, label %53, label %48
48: ; preds = %31
%49 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 0
%50 = load i64, i64* %49
%51 = load i64, i64* @F_UNLCK
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %60
53: ; preds = %48, %31
%54 = load i32, i32* @stderr
%55 = load i32, i32* %3
%56 = load i64, i64* @errno
%57 = trunc i64 %56 to i32
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %55, i32 %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %48
%61 = call i32 @exit(i32 0)
unreachable
62: ; preds = %11
%63 = load i8*, i8** %6
%64 = call i32 @unlink(i8* %63)
%65 = load i8*, i8** %6
%66 = load i32, i32* @O_RDWR
%67 = load i32, i32* @O_CREAT
%68 = or i32 %66, %67
%69 = load i32, i32* @O_EXCL
%70 = or i32 %68, %69
%71 = call i32 (i8*, i32, ...) @open(i8* %65, i32 %70, i32 384)
store i32 %71, i32* %2
%72 = load i32, i32* %2
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %81
74: ; preds = %62
%75 = load i32, i32* @stderr
%76 = load i8*, i8** %6
%77 = load i64, i64* @errno
%78 = trunc i64 %77 to i32
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %76, i32 %78)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %62
%82 = load i8*, i8** @F_WRLCK
%83 = ptrtoint i8* %82 to i64
%84 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 0
store i64 %83, i64* %84
%85 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 4
store i64 0, i64* %85
%86 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 1
store i32 0, i32* %86
%87 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 2
store i32 4, i32* %87
%88 = call i8* (...) @getpid()
%89 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 3
store i8* %88, i8** %89
%90 = load i32, i32* %2
%91 = load i32, i32* @F_SETLK
%92 = call i32 @fcntl(i32 %90, i32 %91, %struct.flock* %1)
store i32 %92, i32* %3
%93 = load i32, i32* %5
%94 = call i32 @sys_waitpid(i32 %93, i32* %4, i32 0)
%95 = load i32, i32* %3
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %104
97: ; preds = %81
%98 = load i32, i32* @stderr
%99 = load i8*, i8** %6
%100 = load i64, i64* @errno
%101 = trunc i64 %100 to i32
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %99, i32 %101)
%103 = call i32 @exit(i32 1)
unreachable
104: ; preds = %81
%105 = getelementptr inbounds %struct.flock, %struct.flock* %1, i32 0, i32 2
%106 = load i32, i32* %105
%107 = sext i32 %106 to i64
%108 = icmp slt i64 %107, 4294967300
br i1 %108, label %109, label %113
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %104
%114 = load i32, i32* %4
%115 = icmp eq i32 %114, 0
%116 = zext i1 %115 to i64
%117 = select i1 %115, i32 0, i32 1
store i32 %117, i32* %4
%118 = load i32, i32* %4
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %124
120: ; preds = %113
%121 = load i32, i32* @stderr
%122 = load i32, i32* %4
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %122)
br label %124
124: ; preds = %120, %113
%125 = load i32, i32* %4
%126 = call i32 @exit(i32 %125)
unreachable
}

LLVM IR (-O2):
%struct.flock = type { i64, i32, i32, i8*, i64 }
@.str = [12 x i8] c"tst-flock3-\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [37 x i8] c"ERROR: failed to open %s (errno=%d)\0A\00"
@errno = global i64 0
@F_WRLCK = global i8* null
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
@.str.2 = [43 x i8] c"ERROR: lock test failed (ret=%d errno=%d)\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@F_SETLK = global i32 0
@.str.3 = [37 x i8] c"ERROR: failed to lock %s (errno=%d)\0A\00"
@.str.4 = [32 x i8] c"ERROR: settign lock overflowed\0A\00"
define i32 @do_test() {
%1 = alloca %struct.flock
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast %struct.flock* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%6 = bitcast i8** %3 to i8*
%7 = call i32 @create_temp_file(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %0
ret i32 -1
10: ; preds = %0
%11 = call i32 @close(i32 %7)
%12 = call i32 @alarm(i32 10)
%13 = call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %54
15: ; preds = %10
%16 = call i32 @sleep(i32 2)
%17 = load i8*, i8** %3
%18 = load i32, i32* @O_RDONLY
%19 = call i32 (i8*, i32, ...) @open(i8* %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %3
%24 = load i64, i64* @errno
%25 = trunc i64 %24 to i32
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %15
%29 = load i8*, i8** @F_WRLCK
%30 = ptrtoint i8* %29 to i64
%31 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 0
store i64 %30, i64* %31
%32 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 4
store i64 0, i64* %32
%33 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 1
store i32 0, i32* %33
%34 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 2
store i32 4, i32* %34
%35 = call i8* (...) @getpid()
%36 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 3
store i8* %35, i8** %36
%37 = load i8*, i8** @F_WRLCK
%38 = ptrtoint i8* %37 to i64
store i64 %38, i64* %31
%39 = load i32, i32* @F_GETLK
%40 = call i32 @fcntl(i32 %19, i32 %39, %struct.flock* %1)
%41 = icmp eq i32 %40, -1
br i1 %41, label %46, label %42
42: ; preds = %28
%43 = load i64, i64* %31
%44 = load i64, i64* @F_UNLCK
%45 = icmp eq i64 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %42, %28
%47 = load i32, i32* @stderr
%48 = load i64, i64* @errno
%49 = trunc i64 %48 to i32
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %40, i32 %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %10
%55 = load i8*, i8** %3
%56 = call i32 @unlink(i8* %55)
%57 = load i8*, i8** %3
%58 = load i32, i32* @O_RDWR
%59 = load i32, i32* @O_CREAT
%60 = or i32 %59, %58
%61 = load i32, i32* @O_EXCL
%62 = or i32 %60, %61
%63 = call i32 (i8*, i32, ...) @open(i8* %57, i32 %62, i32 384)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %72
65: ; preds = %54
%66 = load i32, i32* @stderr
%67 = load i8*, i8** %3
%68 = load i64, i64* @errno
%69 = trunc i64 %68 to i32
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %67, i32 %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %54
%73 = load i8*, i8** @F_WRLCK
%74 = ptrtoint i8* %73 to i64
%75 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 0
store i64 %74, i64* %75
%76 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 4
store i64 0, i64* %76
%77 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 1
store i32 0, i32* %77
%78 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 2
store i32 4, i32* %78
%79 = call i8* (...) @getpid()
%80 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 3
store i8* %79, i8** %80
%81 = load i32, i32* @F_SETLK
%82 = call i32 @fcntl(i32 %63, i32 %81, %struct.flock* %1)
%83 = call i32 @sys_waitpid(i32 %13, i32* %2, i32 0)
%84 = icmp eq i32 %82, 0
%85 = load i32, i32* @stderr
br i1 %84, label %92, label %86
86: ; preds = %72
%87 = load i8*, i8** %3
%88 = load i64, i64* @errno
%89 = trunc i64 %88 to i32
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %87, i32 %89)
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %72
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
}