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

/* Variables and functions */
scalar_t__ EDEADLK;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_SETLKW;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ F_WRLCK;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, struct flock *);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ safe_waitpid(int);
int /*<<< orphan*/ sleep(int);
int test6(int fd, int argc, const char **argv) {
  int pid1, pid2;
  struct flock fl;
  int res;
  fl.l_start = 0;
  fl.l_len = 1;
  fl.l_type = F_WRLCK;
  fl.l_whence = SEEK_SET;
  if (fcntl(fd, F_SETLK, &fl) < 0)
    err(1, "F_SETLK 1 (parent)");
  pid1 = fork();
  if (pid1 < 0)
    err(1, "fork");
  if (pid1 == 0) {
    fl.l_start = 1;
    if (fcntl(fd, F_SETLK, &fl) < 0)
      err(1, "F_SETLK (child1)");
    pause();
    exit(0);
  }
  pid2 = fork();
  if (pid2 < 0)
    err(1, "fork");
  if (pid2 == 0) {
    fl.l_start = 2;
    if (fcntl(fd, F_SETLK, &fl) < 0)
      err(1, "F_SETLK (child2)");
    fl.l_start = 0;
    if (fcntl(fd, F_SETLKW, &fl) < 0)
      err(1, "F_SETLKW (child2)");
    exit(0);
  }
  sleep(1);
  alarm(1);
  printf("6 - F_SETLKW complex deadlock: ");
  fl.l_start = 1;
  fl.l_len = 2;
  res = fcntl(fd, F_SETLKW, &fl);
  kill(pid1, SIGTERM);
  safe_waitpid(pid1);
  kill(pid2, SIGTERM);
  safe_waitpid(pid2);
  fl.l_start = 0;
  fl.l_len = 0;
  fl.l_type = F_UNLCK;
  if (fcntl(fd, F_SETLK, &fl) < 0)
    err(1, "F_UNLCK");
  do {
    if (res == 0) {
      printf("FAIL (%s)\n", "res == 0");
      return -1;
    }
  } while (0);
  do {
    if (errno != EDEADLK) {
      printf("FAIL (%s)\n", "errno != EDEADLK");
      return -1;
    }
  } while (0);
  alarm(0);
  do {
    printf("SUCCEED\n");
    return 0;
  } while (0);
}


x86 assembly (clang, -O0):
<test6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    1207 <test6+0x67>
mov    $0x1,%edi
lea    0xdfe(%rip),%rsi
call   1090 <err@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    122c <test6+0x8c>
mov    $0x1,%edi
lea    0xdec(%rip),%rsi
call   1090 <err@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    127a <test6+0xda>
movl   $0x1,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    126c <test6+0xcc>
mov    $0x1,%edi
lea    0xdb1(%rip),%rsi
call   1090 <err@plt>
mov    $0x0,%al
call   1080 <pause@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    129f <test6+0xff>
mov    $0x1,%edi
lea    0xd79(%rip),%rsi
call   1090 <err@plt>
cmpl   $0x0,-0x20(%rbp)
jne    131c <test6+0x17c>
movl   $0x2,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    12df <test6+0x13f>
mov    $0x1,%edi
lea    0xd4f(%rip),%rsi
call   1090 <err@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    1315 <test6+0x175>
mov    $0x1,%edi
lea    0xd2a(%rip),%rsi
call   1090 <err@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    $0x1,%edi
call   1060 <alarm@plt>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x30(%rbp)
movl   $0x2,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2c8a(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <fcntl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c7a(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
mov    -0x1c(%rbp),%edi
call   1030 <safe_waitpid@plt>
mov    -0x20(%rbp),%edi
mov    0x2c61(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
mov    -0x20(%rbp),%edi
call   1030 <safe_waitpid@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    0x2c25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    13df <test6+0x23f>
mov    $0x1,%edi
lea    0xc92(%rip),%rsi
call   1090 <err@plt>
jmp    13e4 <test6+0x244>
cmpl   $0x0,-0x34(%rbp)
jne    140f <test6+0x26f>
lea    0xc7f(%rip),%rdi
lea    0xc83(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1475 <test6+0x2d5>
jmp    1414 <test6+0x274>
jmp    1419 <test6+0x279>
mov    0x2b98(%rip),%rax
mov    (%rax),%rax
mov    0x2b9e(%rip),%rcx
cmp    (%rcx),%rax
je     1454 <test6+0x2b4>
lea    0xc3a(%rip),%rdi
lea    0xc47(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1475 <test6+0x2d5>
jmp    1459 <test6+0x2b9>
xor    %edi,%edi
call   1060 <alarm@plt>
lea    0xc32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test6>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
movabs $0x100000000,%rax
mov    %rax,0x8(%rsp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2de7(%rip),%rbx
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
call   1050 <fcntl@plt>
test   %eax,%eax
jns    1212 <test6+0x62>
lea    0xdf8(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %eax,%ebp
test   %eax,%eax
js     125b <test6+0xab>
jne    126c <test6+0xbc>
movl   $0x1,0x8(%rsp)
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1050 <fcntl@plt>
test   %eax,%eax
jns    124d <test6+0x9d>
lea    0xdd5(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
xor    %eax,%eax
call   1090 <pause@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xdb1(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
js     12ee <test6+0x13e>
jne    12ff <test6+0x14f>
movl   $0x2,0x8(%rsp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%ebx
mov    %r15d,%edi
call   1050 <fcntl@plt>
test   %eax,%eax
jns    12b5 <test6+0x105>
lea    0xd7e(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
movl   $0x0,0x8(%rsp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <fcntl@plt>
test   %eax,%eax
jns    12e7 <test6+0x137>
lea    0xd5d(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd1e(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    $0x1,%edi
call   1070 <alarm@plt>
lea    0xd32(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movabs $0x200000001,%rax
mov    %rax,0x8(%rsp)
mov    0x2ca9(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r14
mov    %r15d,%edi
mov    %r14,%rdx
call   1050 <fcntl@plt>
mov    %eax,%r12d
mov    0x2c95(%rip),%r13
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1080 <kill@plt>
mov    %ebp,%edi
call   1040 <safe_waitpid@plt>
mov    0x0(%r13),%esi
mov    %ebx,%edi
call   1080 <kill@plt>
mov    %ebx,%edi
call   1040 <safe_waitpid@plt>
movq   $0x0,0x8(%rsp)
mov    0x2c49(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   1050 <fcntl@plt>
test   %eax,%eax
js     13d7 <test6+0x227>
test   %r12d,%r12d
je     13ed <test6+0x23d>
mov    0x2c07(%rip),%rax
mov    (%rax),%rax
mov    0x2c0d(%rip),%rcx
cmp    (%rcx),%rax
jne    13fd <test6+0x24d>
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <alarm@plt>
lea    0xcc9(%rip),%rdi
call   1030 <puts@plt>
jmp    1417 <test6+0x267>
lea    0xc8e(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
test   %r12d,%r12d
jne    13aa <test6+0x1fa>
lea    0xc80(%rip),%rdi
lea    0xc84(%rip),%rsi
jmp    140b <test6+0x25b>
lea    0xc70(%rip),%rdi
lea    0xc7d(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i32, i32, i32, i32 }
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [19 x i8] c"F_SETLK 1 (parent)\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [17 x i8] c"F_SETLK (child1)\00"
@.str.3 = [17 x i8] c"F_SETLK (child2)\00"
@F_SETLKW = global i32 0
@.str.4 = [18 x i8] c"F_SETLKW (child2)\00"
@.str.5 = [32 x i8] c"6 - F_SETLKW complex deadlock: \00"
@SIGTERM = global i32 0
@F_UNLCK = global i32 0
@.str.6 = [8 x i8] c"F_UNLCK\00"
@.str.7 = [11 x i8] c"FAIL (%s)\0A\00"
@.str.8 = [9 x i8] c"res == 0\00"
@errno = global i64 0
@EDEADLK = global i64 0
@.str.9 = [17 x i8] c"errno != EDEADLK\00"
@.str.10 = [9 x i8] c"SUCCEED\0A\00"
define i32 @test6(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.flock
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%12 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 0, i32* %12
%13 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 1
store i32 1, i32* %13
%14 = load i32, i32* @F_WRLCK
%15 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @SEEK_SET
%17 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 3
store i32 %16, i32* %17
%18 = load i32, i32* %5
%19 = load i32, i32* @F_SETLK
%20 = call i32 @fcntl(i32 %18, i32 %19, %struct.flock* %10)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %3
%25 = call i32 (...) @fork()
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %30
%34 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 1, i32* %34
%35 = load i32, i32* %5
%36 = load i32, i32* @F_SETLK
%37 = call i32 @fcntl(i32 %35, i32 %36, %struct.flock* %10)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %33
%42 = call i32 (...) @pause()
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %30
%45 = call i32 (...) @fork()
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
%51 = load i32, i32* %9
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %71
53: ; preds = %50
%54 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 2, i32* %54
%55 = load i32, i32* %5
%56 = load i32, i32* @F_SETLK
%57 = call i32 @fcntl(i32 %55, i32 %56, %struct.flock* %10)
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %53
%62 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 0, i32* %62
%63 = load i32, i32* %5
%64 = load i32, i32* @F_SETLKW
%65 = call i32 @fcntl(i32 %63, i32 %64, %struct.flock* %10)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %67, %61
%70 = call i32 @exit(i32 0)
unreachable
71: ; preds = %50
%72 = call i32 @sleep(i32 1)
%73 = call i32 @alarm(i32 1)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%75 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 1, i32* %75
%76 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 1
store i32 2, i32* %76
%77 = load i32, i32* %5
%78 = load i32, i32* @F_SETLKW
%79 = call i32 @fcntl(i32 %77, i32 %78, %struct.flock* %10)
store i32 %79, i32* %11
%80 = load i32, i32* %8
%81 = load i32, i32* @SIGTERM
%82 = call i32 @kill(i32 %80, i32 %81)
%83 = load i32, i32* %8
%84 = call i32 @safe_waitpid(i32 %83)
%85 = load i32, i32* %9
%86 = load i32, i32* @SIGTERM
%87 = call i32 @kill(i32 %85, i32 %86)
%88 = load i32, i32* %9
%89 = call i32 @safe_waitpid(i32 %88)
%90 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i32 0, i32* %90
%91 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 1
store i32 0, i32* %91
%92 = load i32, i32* @F_UNLCK
%93 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 2
store i32 %92, i32* %93
%94 = load i32, i32* %5
%95 = load i32, i32* @F_SETLK
%96 = call i32 @fcntl(i32 %94, i32 %95, %struct.flock* %10)
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %71
%99 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %100
100: ; preds = %98, %71
br label %101
101: ; preds = %100
%102 = load i32, i32* %11
%103 = icmp eq i32 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %101
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %4
br label %119
106: ; preds = %101
br label %107
107: ; preds = %106
br label %108
108: ; preds = %107
%109 = load i64, i64* @errno
%110 = load i64, i64* @EDEADLK
%111 = icmp ne i64 %109, %110
br i1 %111, label %112, label %114
112: ; preds = %108
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %4
br label %119
114: ; preds = %108
br label %115
115: ; preds = %114
%116 = call i32 @alarm(i32 0)
br label %117
117: ; preds = %115
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %4
br label %119
119: ; preds = %104, %112, %117
%120 = load i32, i32* %4
ret i32 %120
}

LLVM IR (-O2):
%struct.flock = type { i32, i32, i32, i32 }
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [19 x i8] c"F_SETLK 1 (parent)\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [17 x i8] c"F_SETLK (child1)\00"
@.str.3 = [17 x i8] c"F_SETLK (child2)\00"
@F_SETLKW = global i32 0
@.str.4 = [18 x i8] c"F_SETLKW (child2)\00"
@.str.5 = [32 x i8] c"6 - F_SETLKW complex deadlock: \00"
@SIGTERM = global i32 0
@F_UNLCK = global i32 0
@.str.6 = [8 x i8] c"F_UNLCK\00"
@.str.7 = [11 x i8] c"FAIL (%s)\0A\00"
@.str.8 = [9 x i8] c"res == 0\00"
@errno = global i64 0
@EDEADLK = global i64 0
@.str.9 = [17 x i8] c"errno != EDEADLK\00"
@str = [8 x i8] c"SUCCEED\00"
define i32 @test6(i32 %0, i32 %1, i8** nocapture readnone %2) {
%4 = alloca %struct.flock
%5 = bitcast %struct.flock* %4 to i8*
%6 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 0
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 1
store i32 1, i32* %7
%8 = load i32, i32* @F_WRLCK
%9 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @SEEK_SET
%11 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 3
store i32 %10, i32* %11
%12 = load i32, i32* @F_SETLK
%13 = call i32 @fcntl(i32 %0, i32 %12, %struct.flock* %4)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %3
%18 = call i32 (...) @fork()
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %33
22: ; preds = %17
%23 = icmp eq i32 %18, 0
br i1 %23, label %24, label %33
24: ; preds = %22
store i32 1, i32* %6
%25 = load i32, i32* @F_SETLK
%26 = call i32 @fcntl(i32 %0, i32 %25, %struct.flock* %4)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = call i32 (...) @pause()
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %20, %22
%34 = call i32 (...) @fork()
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %54
38: ; preds = %33
%39 = icmp eq i32 %34, 0
br i1 %39, label %40, label %54
40: ; preds = %38
store i32 2, i32* %6
%41 = load i32, i32* @F_SETLK
%42 = call i32 @fcntl(i32 %0, i32 %41, %struct.flock* %4)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
store i32 0, i32* %6
%47 = load i32, i32* @F_SETLKW
%48 = call i32 @fcntl(i32 %0, i32 %47, %struct.flock* %4)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %36, %38
%55 = call i32 @sleep(i32 1)
%56 = call i32 @alarm(i32 1)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %6
store i32 2, i32* %7
%58 = load i32, i32* @F_SETLKW
%59 = call i32 @fcntl(i32 %0, i32 %58, %struct.flock* %4)
%60 = load i32, i32* @SIGTERM
%61 = call i32 @kill(i32 %18, i32 %60)
%62 = call i32 @safe_waitpid(i32 %18)
%63 = load i32, i32* @SIGTERM
%64 = call i32 @kill(i32 %34, i32 %63)
%65 = call i32 @safe_waitpid(i32 %34)
store i32 0, i32* %6
store i32 0, i32* %7
%66 = load i32, i32* @F_UNLCK
store i32 %66, i32* %9
%67 = load i32, i32* @F_SETLK
%68 = call i32 @fcntl(i32 %0, i32 %67, %struct.flock* %4)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %54
%71 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %72
72: ; preds = %54, %70
%73 = icmp eq i32 %59, 0
br i1 %73, label %74, label %76
74: ; preds = %72
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %85
76: ; preds = %72
%77 = load i64, i64* @errno
%78 = load i64, i64* @EDEADLK
%79 = icmp eq i64 %77, %78
br i1 %79, label %82, label %80
80: ; preds = %76
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %85
82: ; preds = %76
%83 = call i32 @alarm(i32 0)
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %85
85: ; preds = %82, %80, %74
%86 = phi i32 [ -1, %74 ], [ -1, %80 ], [ 0, %82 ]
ret i32 %86
}