#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*/ chdir(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(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 main(int argc, char *argv[]) {
  struct flock lock;
  int fd, ret, status = 1;
  pid_t pid;
  char *testdir = NULL;
  testdir = getenv("TESTDIR");
  if (testdir)
    chdir(testdir);
  alarm(10);
  if (!(pid = fork())) {
    sleep(2);
    fd = open("conftest.fcntl", O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "ERROR: failed to open %s (errno=%d)\n", "conftest.fcntl",
              (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("conftest.fcntl");
  fd = open("conftest.fcntl", O_RDWR | O_CREAT | O_EXCL, 0600);
  if (fd == -1) {
    fprintf(stderr, "ERROR: failed to open %s (errno=%d)\n", "conftest.fcntl",
            (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);
  unlink("conftest.fcntl");
  if (ret != 0) {
    fprintf(stderr, "ERROR: failed to lock %s (errno=%d)\n", "conftest.fcntl",
            (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):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x3c(%rbp)
movq   $0x0,-0x48(%rbp)
lea    0xe14(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1209 <main+0x49>
mov    -0x48(%rbp),%rdi
call   1070 <chdir@plt>
mov    $0xa,%edi
call   1080 <alarm@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x40(%rbp)
cmp    $0x0,%eax
jne    1332 <main+0x172>
mov    $0x2,%edi
call   10d0 <sleep@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1288 <main+0xc8>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
mov    0x2d3c(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xda7(%rip),%rsi
lea    0xd91(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x4,-0x24(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %rax,-0x20(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <fcntl@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
je     12fb <main+0x13b>
mov    -0x30(%rbp),%rax
mov    0x2cce(%rip),%rcx
cmp    (%rcx),%rax
jne    132b <main+0x16b>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%edx
mov    0x2c92(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xccf(%rip),%rdi
call   1040 <unlink@plt>
mov    0x2c9b(%rip),%rax
mov    (%rax),%esi
mov    0x2caa(%rip),%rax
or     (%rax),%esi
mov    0x2c51(%rip),%rax
or     (%rax),%esi
lea    0xca8(%rip),%rdi
mov    $0x180,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    13ad <main+0x1ed>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
mov    0x2c17(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xc82(%rip),%rsi
lea    0xc6c(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2be4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x4,-0x24(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2bea(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <fcntl@plt>
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x3c(%rbp),%rsi
xor    %edx,%edx
call   10b0 <sys_waitpid@plt>
lea    0xbff(%rip),%rdi
call   1040 <unlink@plt>
cmpl   $0x0,-0x38(%rbp)
je     144c <main+0x28c>
mov    0x2b91(%rip),%rax
mov    (%rax),%edi
mov    0x2b78(%rip),%rax
mov    (%rax),%rax
mov    %eax,%ecx
lea    0xc33(%rip),%rsi
lea    0xbcd(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movslq -0x24(%rbp),%rax
movabs $0x100000004,%rcx
cmp    %rcx,%rax
jge    1484 <main+0x2c4>
mov    0x2b46(%rip),%rax
mov    (%rax),%edi
lea    0xc19(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x3c(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     14bb <main+0x2fb>
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%edx
lea    0xbf8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x3c(%rbp),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movl   $0x1,0x4(%rsp)
lea    0xe2b(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11e7 <main+0x27>
mov    %rax,%rdi
call   1070 <chdir@plt>
mov    $0xa,%edi
call   1080 <alarm@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
jne    12ba <main+0xfa>
mov    $0x2,%edi
call   10d0 <sleep@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     12fa <main+0x13a>
mov    %eax,%ebx
movq   $0x0,0x20(%rsp)
movabs $0x400000000,%rax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %rax,0x18(%rsp)
mov    0x2d41(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <fcntl@plt>
cmp    $0xffffffff,%eax
je     128e <main+0xce>
mov    0x8(%rsp),%rcx
mov    0x2d3b(%rip),%rdx
cmp    (%rdx),%rcx
jne    13cb <main+0x20b>
mov    0x2d1b(%rip),%rcx
mov    (%rcx),%edi
mov    0x2d02(%rip),%rcx
mov    (%rcx),%ecx
lea    0xd95(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%ebx
lea    0xd45(%rip),%rbp
mov    %rbp,%rdi
call   1040 <unlink@plt>
mov    0x2d0e(%rip),%rax
mov    0x2d1f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2cc4(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
jne    132b <main+0x16b>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
mov    0x2c96(%rip),%rax
mov    (%rax),%ecx
lea    0xd04(%rip),%rsi
lea    0xcee(%rip),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%ebp
mov    0x2c64(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x20(%rsp)
movabs $0x400000000,%rax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %rax,0x18(%rsp)
mov    0x2c69(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1050 <fcntl@plt>
mov    %eax,%ebp
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   10b0 <sys_waitpid@plt>
lea    0xc7c(%rip),%rdi
call   1040 <unlink@plt>
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
test   %ebp,%ebp
jne    13b6 <main+0x1f6>
lea    0xce7(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2be3(%rip),%rax
mov    (%rax),%ecx
lea    0xca1(%rip),%rsi
jmp    1313 <main+0x153>
xor    %edi,%edi
call   10c0 <exit@plt>

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

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