#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct TYPE_3__ {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
struct itimerval {
  TYPE_2__ it_value;
  TYPE_1__ it_interval;
};
struct flock {
  int /*<<< orphan*/ l_type;
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
};

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_SETLKW;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ F_WRLCK;
int /*<<< orphan*/ ITIMER_REAL;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ safe_waitpid(int);
int /*<<< orphan*/ setitimer(int /*<<< orphan*/, struct itimerval *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(int);
scalar_t__ write(int, char *, int);
int test13(int fd, int argc, const char **argv) {
  int i;
  int pid;
  int pfd[2];
  struct flock fl;
  char ch;
  int res;
  struct itimerval itv;
  printf("13 - F_SETLKW on locked region, race with owner: ");
  fflush(stdout);
  for (i = 0; i < 100; i++) {
    if (pipe(pfd) < 0)
      err(1, "pipe");
    fl.l_start = 0;
    fl.l_len = 0;
    fl.l_type = F_WRLCK;
    fl.l_whence = SEEK_SET;
    pid = fork();
    if (pid < 0)
      err(1, "fork");
    if (pid == 0) {
      if (fcntl(fd, F_SETLK, &fl) < 0)
        err(1, "F_SETLK (child)");
      if (write(pfd[1], "a", 1) < 0)
        err(1, "writing to pipe (child)");
      usleep(1);
      exit(0);
    }
    while (read(pfd[0], &ch, 1) != 1) {
      if (errno == EINTR)
        continue;
      err(1, "reading from pipe (child)");
    }
    itv.it_interval.tv_sec = 0;
    itv.it_interval.tv_usec = 0;
    itv.it_value.tv_sec = 0;
    itv.it_value.tv_usec = 2;
    setitimer(ITIMER_REAL, &itv, NULL);
    res = fcntl(fd, F_SETLKW, &fl);
    kill(pid, SIGTERM);
    safe_waitpid(pid);
    close(pfd[0]);
    close(pfd[1]);
    do {
      if (!(res == 0 || (res == -1 && errno == EINTR))) {
        printf("FAIL (%s)\n", "!(res == 0 || (res == -1 && errno == EINTR))");
        return -1;
      }
    } while (0);
    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 {
    printf("SUCCEED\n");
    return 0;
  } while (0);
}


x86 assembly (clang, -O0):
<test13>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    1485 <test13+0x2a5>
lea    -0x28(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jge    1243 <test13+0x63>
mov    $0x1,%edi
lea    0xdf4(%rip),%rsi
call   10b0 <err@plt>
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1290 <test13+0xb0>
mov    $0x1,%edi
lea    0xdac(%rip),%rsi
call   10b0 <err@plt>
cmpl   $0x0,-0x20(%rbp)
jne    1309 <test13+0x129>
mov    -0x8(%rbp),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    12c9 <test13+0xe9>
mov    $0x1,%edi
lea    0xd78(%rip),%rsi
call   10b0 <err@plt>
mov    -0x24(%rbp),%edi
lea    0xd79(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    12f8 <test13+0x118>
mov    $0x1,%edi
lea    0xd5b(%rip),%rsi
call   10b0 <err@plt>
mov    $0x1,%edi
call   1100 <usleep@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    130e <test13+0x12e>
mov    -0x28(%rbp),%edi
lea    -0x49(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x1,%eax
je     135d <test13+0x17d>
mov    0x2c89(%rip),%rax
mov    (%rax),%rax
mov    0x2c6f(%rip),%rcx
cmp    (%rcx),%rax
jne    1347 <test13+0x167>
jmp    130e <test13+0x12e>
mov    $0x1,%edi
lea    0xd13(%rip),%rsi
call   10b0 <err@plt>
jmp    130e <test13+0x12e>
movq   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
movl   $0x2,-0x70(%rbp)
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <setitimer@plt>
mov    -0x8(%rbp),%edi
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1040 <fcntl@plt>
mov    %eax,-0x50(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2c34(%rip),%rax
mov    (%rax),%esi
call   10a0 <kill@plt>
mov    -0x20(%rbp),%edi
call   1030 <safe_waitpid@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x50(%rbp)
je     1422 <test13+0x242>
cmpl   $0xffffffff,-0x50(%rbp)
jne    1401 <test13+0x221>
mov    0x2bca(%rip),%rax
mov    (%rax),%rax
mov    0x2bb0(%rip),%rcx
cmp    (%rcx),%rax
je     1422 <test13+0x242>
lea    0xc78(%rip),%rdi
lea    0xc7c(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    149f <test13+0x2bf>
jmp    1427 <test13+0x247>
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2b92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2b8b(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    1472 <test13+0x292>
mov    $0x1,%edi
lea    0xc4b(%rip),%rsi
call   10b0 <err@plt>
jmp    1477 <test13+0x297>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1215 <test13+0x35>
jmp    148a <test13+0x2aa>
lea    0xc2f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test13>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edi,%r13d
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
lea    0x20(%rsp),%r14
lea    0xb(%rsp),%rbx
mov    0x2d8a(%rip),%r15
mov    0x2d73(%rip),%rbp
xor    %r12d,%r12d
mov    %r13d,0x14(%rsp)
jmp    128a <test13+0x9a>
nop
lea    0x20(%rsp),%r14
xorps  %xmm0,%xmm0
movups %xmm0,(%r14)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
mov    0x14(%rsp),%r13d
mov    %r13d,%edi
lea    0x18(%rsp),%rdx
call   1050 <fcntl@plt>
test   %eax,%eax
js     13d0 <test13+0x1e0>
add    $0x1,%r12d
cmp    $0x64,%r12d
je     1402 <test13+0x212>
lea    0xc(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
jns    12aa <test13+0xba>
mov    $0x1,%edi
lea    0xd9d(%rip),%rsi
call   10c0 <err@plt>
xorps  %xmm0,%xmm0
movups %xmm0,(%r14)
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xor    %eax,%eax
call   1100 <fork@plt>
mov    %eax,%r14d
test   %eax,%eax
js     12e0 <test13+0xf0>
jne    131a <test13+0x12a>
jmp    141f <test13+0x22f>
mov    $0x1,%edi
lea    0xd5b(%rip),%rsi
call   10c0 <err@plt>
jmp    131a <test13+0x12a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%rax
cmp    0x0(%rbp),%rax
je     131a <test13+0x12a>
mov    $0x1,%edi
lea    0xd61(%rip),%rsi
call   10c0 <err@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0x1,%eax
jne    1300 <test13+0x110>
lea    0x40(%rsp),%rax
xorps  %xmm0,%xmm0
movups %xmm0,(%rax)
movq   $0x0,0x10(%rax)
movl   $0x2,0x38(%rsp)
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
lea    0x38(%rsp),%rsi
xor    %edx,%edx
call   10e0 <setitimer@plt>
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
lea    0x18(%rsp),%rdx
call   1050 <fcntl@plt>
mov    %eax,%r13d
mov    0x2c68(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   10b0 <kill@plt>
mov    %r14d,%edi
call   1040 <safe_waitpid@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x10(%rsp),%edi
call   1080 <close@plt>
test   %r13d,%r13d
je     1240 <test13+0x50>
cmp    $0xffffffff,%r13d
jne    13e6 <test13+0x1f6>
mov    (%r15),%rax
cmp    0x0(%rbp),%rax
je     1240 <test13+0x50>
jmp    13e6 <test13+0x1f6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%edi
lea    0xcec(%rip),%rsi
call   10c0 <err@plt>
jmp    127c <test13+0x8c>
lea    0xca3(%rip),%rdi
lea    0xca7(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
jmp    1410 <test13+0x220>
lea    0xcc7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bb2(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %r13d,%edi
call   1050 <fcntl@plt>
test   %eax,%eax
jns    144a <test13+0x25a>
lea    0xc0c(%rip),%rsi
mov    $0x1,%edi
call   10c0 <err@plt>
mov    0x10(%rsp),%edi
lea    0xc07(%rip),%rsi
mov    $0x1,%edx
call   1060 <write@plt>
test   %rax,%rax
jns    1475 <test13+0x285>
lea    0xbf3(%rip),%rsi
mov    $0x1,%edi
call   10c0 <err@plt>
mov    $0x1,%edi
call   1110 <usleep@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.flock = type { i32, i64, i64, i32 }
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@.str = [50 x i8] c"13 - F_SETLKW on locked region, race with owner: \00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"pipe\00"
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [5 x i8] c"fork\00"
@F_SETLK = global i32 0
@.str.3 = [16 x i8] c"F_SETLK (child)\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [24 x i8] c"writing to pipe (child)\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.6 = [26 x i8] c"reading from pipe (child)\00"
@ITIMER_REAL = global i32 0
@F_SETLKW = global i32 0
@SIGTERM = global i32 0
@.str.7 = [11 x i8] c"FAIL (%s)\0A\00"
@.str.8 = [45 x i8] c"!(res == 0 || (res == -1 && errno == EINTR))\00"
@F_UNLCK = global i32 0
@.str.9 = [8 x i8] c"F_UNLCK\00"
@.str.10 = [9 x i8] c"SUCCEED\0A\00"
define i32 @test13(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 [2 x i32]
%11 = alloca %struct.flock
%12 = alloca i8
%13 = alloca i32
%14 = alloca %struct.itimerval
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stdout
%17 = call i32 @fflush(i32 %16)
store i32 0, i32* %8
br label %18
18: ; preds = %122, %3
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 100
br i1 %20, label %21, label %125
21: ; preds = %18
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%23 = call i64 @pipe(i32* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 2
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 1
store i64 0, i64* %29
%30 = load i32, i32* @F_WRLCK
%31 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* @SEEK_SET
%33 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 3
store i32 %32, i32* %33
%34 = call i32 (...) @fork()
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %27
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %59
42: ; preds = %39
%43 = load i32, i32* %5
%44 = load i32, i32* @F_SETLK
%45 = call i32 @fcntl(i32 %43, i32 %44, %struct.flock* %11)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i64 @write(i32 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %49
%57 = call i32 @usleep(i32 1)
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %39
br label %60
60: ; preds = %70, %69, %59
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%62 = load i32, i32* %61
%63 = call i32 @read(i32 %62, i8* %12, i32 1)
%64 = icmp ne i32 %63, 1
br i1 %64, label %65, label %72
65: ; preds = %60
%66 = load i64, i64* @errno
%67 = load i64, i64* @EINTR
%68 = icmp eq i64 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %65
br label %60
70: ; preds = %65
%71 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %60
72: ; preds = %60
%73 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %14, i32 0, i32 1
%74 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %73, i32 0, i32 1
store i64 0, i64* %74
%75 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %14, i32 0, i32 1
%76 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %75, i32 0, i32 0
store i64 0, i64* %76
%77 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %14, i32 0, i32 0
%78 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %77, i32 0, i32 1
store i64 0, i64* %78
%79 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %14, i32 0, i32 0
%80 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %79, i32 0, i32 0
store i32 2, i32* %80
%81 = load i32, i32* @ITIMER_REAL
%82 = call i32 @setitimer(i32 %81, %struct.itimerval* %14, i32* null)
%83 = load i32, i32* %5
%84 = load i32, i32* @F_SETLKW
%85 = call i32 @fcntl(i32 %83, i32 %84, %struct.flock* %11)
store i32 %85, i32* %13
%86 = load i32, i32* %9
%87 = load i32, i32* @SIGTERM
%88 = call i32 @kill(i32 %86, i32 %87)
%89 = load i32, i32* %9
%90 = call i32 @safe_waitpid(i32 %89)
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%92 = load i32, i32* %91
%93 = call i32 @close(i32 %92)
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%95 = load i32, i32* %94
%96 = call i32 @close(i32 %95)
br label %97
97: ; preds = %72
%98 = load i32, i32* %13
%99 = icmp eq i32 %98, 0
br i1 %99, label %109, label %100
100: ; preds = %97
%101 = load i32, i32* %13
%102 = icmp eq i32 %101, -1
br i1 %102, label %103, label %107
103: ; preds = %100
%104 = load i64, i64* @errno
%105 = load i64, i64* @EINTR
%106 = icmp eq i64 %104, %105
br i1 %106, label %109, label %107
107: ; preds = %103, %100
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %4
br label %128
109: ; preds = %103, %97
br label %110
110: ; preds = %109
%111 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 2
store i64 0, i64* %111
%112 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 1
store i64 0, i64* %112
%113 = load i32, i32* @F_UNLCK
%114 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 0
store i32 %113, i32* %114
%115 = load i32, i32* %5
%116 = load i32, i32* @F_SETLK
%117 = call i32 @fcntl(i32 %115, i32 %116, %struct.flock* %11)
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %110
%120 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %121
121: ; preds = %119, %110
br label %122
122: ; preds = %121
%123 = load i32, i32* %8
%124 = add nsw i32 %123, 1
store i32 %124, i32* %8
br label %18
125: ; preds = %18
br label %126
126: ; preds = %125
%127 = 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 %128
128: ; preds = %107, %126
%129 = load i32, i32* %4
ret i32 %129
}

LLVM IR (-O2):
%struct.flock = type { i32, i64, i64, i32 }
%struct.itimerval = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i64 }
%struct.TYPE_3__ = type { i64, i64 }
@.str = [50 x i8] c"13 - F_SETLKW on locked region, race with owner: \00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"pipe\00"
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [5 x i8] c"fork\00"
@F_SETLK = global i32 0
@.str.3 = [16 x i8] c"F_SETLK (child)\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [24 x i8] c"writing to pipe (child)\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.6 = [26 x i8] c"reading from pipe (child)\00"
@ITIMER_REAL = global i32 0
@F_SETLKW = global i32 0
@SIGTERM = global i32 0
@.str.7 = [11 x i8] c"FAIL (%s)\0A\00"
@.str.8 = [45 x i8] c"!(res == 0 || (res == -1 && errno == EINTR))\00"
@F_UNLCK = global i32 0
@.str.9 = [8 x i8] c"F_UNLCK\00"
@str = [8 x i8] c"SUCCEED\00"
define i32 @test13(i32 %0, i32 %1, i8** nocapture readnone %2) {
%4 = alloca [2 x i32]
%5 = alloca %struct.flock
%6 = alloca i8
%7 = alloca %struct.itimerval
%8 = bitcast [2 x i32]* %4 to i8*
%9 = bitcast %struct.flock* %5 to i8*
%10 = bitcast %struct.itimerval* %7 to i8*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = tail call i32 @fflush(i32 %12)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%15 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 1
%16 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 0
%17 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 3
%18 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i64 0, i32 0, i32 1
%19 = getelementptr inbounds %struct.itimerval, %struct.itimerval* %7, i64 0, i32 0, i32 0
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%21 = bitcast i64* %15 to i8*
%22 = bitcast i64* %18 to i8*
%23 = bitcast i64* %15 to i8*
br label %24
24: ; preds = %3, %93
%25 = phi i32 [ 0, %3 ], [ %94, %93 ]
%26 = call i64 @pipe(i32* %14)
%27 = icmp slt i64 %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* @F_WRLCK
store i32 %31, i32* %16
%32 = load i32, i32* @SEEK_SET
store i32 %32, i32* %17
%33 = call i32 (...) @fork()
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %39
37: ; preds = %30
%38 = icmp eq i32 %33, 0
br i1 %38, label %43, label %39
39: ; preds = %35, %37
%40 = load i32, i32* %14
%41 = call i32 @read(i32 %40, i8* %6, i32 1)
%42 = icmp eq i32 %41, 1
br i1 %42, label %68, label %58
43: ; preds = %37
%44 = load i32, i32* @F_SETLK
%45 = call i32 @fcntl(i32 %0, i32 %44, %struct.flock* %5)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
%50 = load i32, i32* %20
%51 = call i64 @write(i32 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
%56 = call i32 @usleep(i32 1)
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %39, %64
%59 = load i64, i64* @errno
%60 = load i64, i64* @EINTR
%61 = icmp eq i64 %59, %60
br i1 %61, label %64, label %62
62: ; preds = %58
%63 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %64
64: ; preds = %62, %58
%65 = load i32, i32* %14
%66 = call i32 @read(i32 %65, i8* %6, i32 1)
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %58
68: ; preds = %64, %39
store i32 2, i32* %19
%69 = load i32, i32* @ITIMER_REAL
%70 = call i32 @setitimer(i32 %69, %struct.itimerval* %7, i32* null)
%71 = load i32, i32* @F_SETLKW
%72 = call i32 @fcntl(i32 %0, i32 %71, %struct.flock* %5)
%73 = load i32, i32* @SIGTERM
%74 = call i32 @kill(i32 %33, i32 %73)
%75 = call i32 @safe_waitpid(i32 %33)
%76 = load i32, i32* %14
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %20
%79 = call i32 @close(i32 %78)
switch i32 %72, label %84 [
i32 0, label %86
i32 -1, label %80
]
80: ; preds = %68
%81 = load i64, i64* @errno
%82 = load i64, i64* @EINTR
%83 = icmp eq i64 %81, %82
br i1 %83, label %86, label %84
84: ; preds = %68, %80
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
br label %98
86: ; preds = %68, %80
%87 = load i32, i32* @F_UNLCK
store i32 %87, i32* %16
%88 = load i32, i32* @F_SETLK
%89 = call i32 @fcntl(i32 %0, i32 %88, %struct.flock* %5)
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %93
91: ; preds = %86
%92 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %93
93: ; preds = %86, %91
%94 = add nuw nsw i32 %25, 1
%95 = icmp eq i32 %94, 100
br i1 %95, label %96, label %24
96: ; preds = %93
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %98
98: ; preds = %96, %84
%99 = phi i32 [ -1, %84 ], [ 0, %96 ]
ret i32 %99
}