#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 lockRange TYPE_1__;

/* Type definitions */
struct flock {
  scalar_t__ l_type;
  scalar_t__ l_start;
  scalar_t__ l_len;
  int l_pid;
  int /*<<< orphan*/ l_whence;
};
typedef scalar_t__ off_t;
typedef int /*<<< orphan*/ aPending;
struct lockRange {
  scalar_t__ lwr;
  scalar_t__ upr;
};

/* Variables and functions */
int /*<<< orphan*/ F_GETLK;
scalar_t__ F_UNLCK;
scalar_t__ F_WRLCK;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(TYPE_1__ *);
TYPE_1__ *malloc(int);
int /*<<< orphan*/ printf(char *, int, int, int, char *);
TYPE_1__ *realloc(TYPE_1__ *, int);
int /*<<< orphan*/ stderr;
int showLocksInRange(int fd, off_t lwr, off_t upr) {
  int cnt = 0;
  struct flock x;
  struct lockRange {
    off_t lwr;
    off_t upr;
  } *aPending = 0;
  int nAlloc = 1;
  int nPending = 0;
  int nDone = 0;
  nPending = 1;
  aPending = malloc(sizeof(aPending[0]));
  if (aPending == 0) {
    fprintf(stderr, "out of memory\n");
    exit(1);
  }
  aPending[0].lwr = lwr;
  aPending[0].upr = upr;
  for (nDone = 0; nDone < nPending; nDone++) {
    lwr = aPending[nDone].lwr;
    upr = aPending[nDone].upr;
    if (lwr >= upr)
      continue;
    x.l_type = F_WRLCK;
    x.l_whence = SEEK_SET;
    x.l_start = lwr;
    x.l_len = upr - lwr;
    fcntl(fd, F_GETLK, &x);
    if (x.l_type == F_UNLCK)
      continue;
    printf("start: %-12d len: %-5d pid: %-5d type: %s\n", (int)x.l_start,
           (int)x.l_len, x.l_pid, x.l_type == F_WRLCK ? "WRLCK" : "RDLCK");
    cnt++;
    if (nPending + 2 > nAlloc) {
      nAlloc = nAlloc * 2 + 2;
      aPending = realloc(aPending, sizeof(aPending[0]) * nAlloc);
    }
    if (aPending == 0) {
      fprintf(stderr, "unable to realloc for %d bytes\n",
              (int)sizeof(aPending[0]) * (nPending + 2));
      exit(1);
    }
    if (lwr < x.l_start) {
      aPending[nPending].lwr = lwr;
      aPending[nPending].upr = x.l_start;
      nPending++;
    }
    if (x.l_start + x.l_len <= upr) {
      aPending[nPending].lwr = x.l_start + x.l_len;
      aPending[nPending].upr = upr;
      nPending++;
    }
  }
  free(aPending);
  return cnt;
}


x86 assembly (clang, -O0):
<showLocksInRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x1,-0x50(%rbp)
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11e8 <showLocksInRange+0x78>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,0x8(%rax)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    13ff <showLocksInRange+0x28f>
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     1252 <showLocksInRange+0xe2>
jmp    13f1 <showLocksInRange+0x281>
mov    0x2d67(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1040 <fcntl@plt>
mov    -0x40(%rbp),%rax
mov    0x2d40(%rip),%rcx
cmp    (%rcx),%rax
jne    12ae <showLocksInRange+0x13e>
jmp    13f1 <showLocksInRange+0x281>
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x30(%rbp),%rax
mov    %eax,%edx
mov    -0x28(%rbp),%ecx
mov    -0x40(%rbp),%rdi
mov    0x2cf8(%rip),%rax
mov    (%rax),%r9
lea    0xd6e(%rip),%r8
lea    0xd61(%rip),%rax
cmp    %r9,%rdi
cmove  %rax,%r8
lea    0xd28(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x50(%rbp),%eax
add    $0x2,%eax
cmp    -0x4c(%rbp),%eax
jle    1327 <showLocksInRange+0x1b7>
mov    -0x4c(%rbp),%eax
shl    $0x1,%eax
add    $0x2,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
movslq -0x4c(%rbp),%rax
shl    $0x4,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    135c <showLocksInRange+0x1ec>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
mov    -0x50(%rbp),%edx
add    $0x2,%edx
shl    $0x4,%edx
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    13a0 <showLocksInRange+0x230>
mov    -0x10(%rbp),%rcx
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,0x8(%rax)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     13ec <showLocksInRange+0x27c>
mov    -0x38(%rbp),%rcx
add    -0x30(%rbp),%rcx
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rdx
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,0x8(%rax)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    13f1 <showLocksInRange+0x281>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1206 <showLocksInRange+0x96>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showLocksInRange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %edi,0x1c(%rsp)
mov    $0x10,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1337 <showLocksInRange+0x1c7>
mov    %rax,%rdi
mov    %rbp,(%rax)
mov    %r14,0x8(%rax)
xor    %r15d,%r15d
mov    $0x1,%ebx
mov    $0x8,%r12d
mov    0x2e06(%rip),%r14
mov    $0x1,%eax
mov    %rax,0x20(%rsp)
movl   $0x0,0xc(%rsp)
jmp    11e9 <showLocksInRange+0x79>
xchg   %ax,%ax
mov    0x10(%rsp),%rdi
add    $0x1,%r15
movslq %ebx,%rax
add    $0x10,%r12
cmp    %rax,%r15
jge    12f7 <showLocksInRange+0x187>
mov    -0x8(%rdi,%r12,1),%rbp
mov    (%rdi,%r12,1),%r13
mov    %r13,%rax
sub    %rbp,%rax
jle    11d5 <showLocksInRange+0x65>
mov    %rdi,0x10(%rsp)
mov    (%r14),%rcx
mov    %rcx,0x28(%rsp)
mov    0x2dba(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x44(%rsp)
mov    %rbp,0x30(%rsp)
mov    %rax,0x38(%rsp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
mov    0x1c(%rsp),%edi
lea    0x28(%rsp),%rdx
call   1040 <fcntl@plt>
mov    0x28(%rsp),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
je     11d0 <showLocksInRange+0x60>
mov    0x30(%rsp),%esi
mov    0x38(%rsp),%edx
mov    0x40(%rsp),%ecx
cmp    (%r14),%rax
lea    0xde4(%rip),%r8
lea    0xdd7(%rip),%rax
cmove  %rax,%r8
lea    0xda1(%rip),%rdi
call   1050 <printf@plt>
lea    0x2(%rbx),%r14d
mov    0x20(%rsp),%rax
cmp    %eax,%r14d
jle    12a4 <showLocksInRange+0x134>
add    %eax,%eax
add    $0x2,%eax
mov    %rax,0x20(%rsp)
mov    %eax,%esi
shl    $0x4,%esi
mov    0x10(%rsp),%rdi
call   1080 <realloc@plt>
mov    %rax,%rdi
test   %rax,%rax
jne    12a9 <showLocksInRange+0x139>
jmp    130f <showLocksInRange+0x19f>
mov    0x10(%rsp),%rdi
mov    0x30(%rsp),%rax
cmp    %rax,%rbp
jge    12c6 <showLocksInRange+0x156>
movslq %ebx,%rcx
shl    $0x4,%rcx
mov    %rbp,(%rdi,%rcx,1)
mov    %rax,0x8(%rdi,%rcx,1)
add    $0x1,%ebx
addl   $0x1,0xc(%rsp)
add    0x38(%rsp),%rax
cmp    %r13,%rax
jg     12eb <showLocksInRange+0x17b>
movslq %ebx,%rbx
mov    %rbx,%rcx
shl    $0x4,%rcx
mov    %rax,(%rdi,%rcx,1)
mov    %r13,0x8(%rdi,%rcx,1)
add    $0x1,%ebx
mov    0x2cce(%rip),%r14
jmp    11d5 <showLocksInRange+0x65>
call   1030 <free@plt>
mov    0xc(%rsp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
shl    $0x4,%r14d
lea    0xd23(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
lea    0xcb9(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.flock = type { i64, i64, i64, i32, i32 }
%struct.lockRange = type { i64, i64 }
%struct.lockRange.0 = type { i64, i64 }
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@F_WRLCK = global i64 0
@SEEK_SET = global i32 0
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
@.str.1 = [43 x i8] c"start: %-12d len: %-5d pid: %-5d type: %s\0A\00"
@.str.2 = [6 x i8] c"WRLCK\00"
@.str.3 = [6 x i8] c"RDLCK\00"
@.str.4 = [32 x i8] c"unable to realloc for %d bytes\0A\00"
define i32 @showLocksInRange(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.flock
%9 = alloca %struct.lockRange*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
store i32 0, i32* %7
store %struct.lockRange* null, %struct.lockRange** %9
store i32 1, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 1, i32* %11
%13 = call %struct.lockRange.0* @malloc(i32 16)
%14 = bitcast %struct.lockRange.0* %13 to %struct.lockRange*
store %struct.lockRange* %14, %struct.lockRange** %9
%15 = load %struct.lockRange*, %struct.lockRange** %9
%16 = icmp eq %struct.lockRange* %15, null
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = load i64, i64* %5
%23 = load %struct.lockRange*, %struct.lockRange** %9
%24 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %23, i64 0
%25 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %24, i32 0, i32 0
store i64 %22, i64* %25
%26 = load i64, i64* %6
%27 = load %struct.lockRange*, %struct.lockRange** %9
%28 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %27, i64 0
%29 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %28, i32 0, i32 1
store i64 %26, i64* %29
store i32 0, i32* %12
br label %30
30: ; preds = %163, %21
%31 = load i32, i32* %12
%32 = load i32, i32* %11
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %166
34: ; preds = %30
%35 = load %struct.lockRange*, %struct.lockRange** %9
%36 = load i32, i32* %12
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %35, i64 %37
%39 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %38, i32 0, i32 0
%40 = load i64, i64* %39
store i64 %40, i64* %5
%41 = load %struct.lockRange*, %struct.lockRange** %9
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %41, i64 %43
%45 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %44, i32 0, i32 1
%46 = load i64, i64* %45
store i64 %46, i64* %6
%47 = load i64, i64* %5
%48 = load i64, i64* %6
%49 = icmp sge i64 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %34
br label %163
51: ; preds = %34
%52 = load i64, i64* @F_WRLCK
%53 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
store i64 %52, i64* %53
%54 = load i32, i32* @SEEK_SET
%55 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 4
store i32 %54, i32* %55
%56 = load i64, i64* %5
%57 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
store i64 %56, i64* %57
%58 = load i64, i64* %6
%59 = load i64, i64* %5
%60 = sub nsw i64 %58, %59
%61 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 2
store i64 %60, i64* %61
%62 = load i32, i32* %4
%63 = load i32, i32* @F_GETLK
%64 = call i32 @fcntl(i32 %62, i32 %63, %struct.flock* %8)
%65 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
%66 = load i64, i64* %65
%67 = load i64, i64* @F_UNLCK
%68 = icmp eq i64 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %51
br label %163
70: ; preds = %51
%71 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
%72 = load i64, i64* %71
%73 = trunc i64 %72 to i32
%74 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 2
%75 = load i64, i64* %74
%76 = trunc i64 %75 to i32
%77 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 3
%78 = load i32, i32* %77
%79 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
%80 = load i64, i64* %79
%81 = load i64, i64* @F_WRLCK
%82 = icmp eq i64 %80, %81
%83 = zext i1 %82 to i64
%84 = select i1 %82, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%85 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %73, i32 %76, i32 %78, i8* %84)
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 1
store i32 %87, i32* %7
%88 = load i32, i32* %11
%89 = add nsw i32 %88, 2
%90 = load i32, i32* %10
%91 = icmp sgt i32 %89, %90
br i1 %91, label %92, label %104
92: ; preds = %70
%93 = load i32, i32* %10
%94 = mul nsw i32 %93, 2
%95 = add nsw i32 %94, 2
store i32 %95, i32* %10
%96 = load %struct.lockRange*, %struct.lockRange** %9
%97 = bitcast %struct.lockRange* %96 to %struct.lockRange.0*
%98 = load i32, i32* %10
%99 = sext i32 %98 to i64
%100 = mul i64 16, %99
%101 = trunc i64 %100 to i32
%102 = call %struct.lockRange.0* @realloc(%struct.lockRange.0* %97, i32 %101)
%103 = bitcast %struct.lockRange.0* %102 to %struct.lockRange*
store %struct.lockRange* %103, %struct.lockRange** %9
br label %104
104: ; preds = %92, %70
%105 = load %struct.lockRange*, %struct.lockRange** %9
%106 = icmp eq %struct.lockRange* %105, null
br i1 %106, label %107, label %114
107: ; preds = %104
%108 = load i32, i32* @stderr
%109 = load i32, i32* %11
%110 = add nsw i32 %109, 2
%111 = mul nsw i32 16, %110
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %104
%115 = load i64, i64* %5
%116 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
%117 = load i64, i64* %116
%118 = icmp slt i64 %115, %117
br i1 %118, label %119, label %135
119: ; preds = %114
%120 = load i64, i64* %5
%121 = load %struct.lockRange*, %struct.lockRange** %9
%122 = load i32, i32* %11
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %121, i64 %123
%125 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %124, i32 0, i32 0
store i64 %120, i64* %125
%126 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
%127 = load i64, i64* %126
%128 = load %struct.lockRange*, %struct.lockRange** %9
%129 = load i32, i32* %11
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %128, i64 %130
%132 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %131, i32 0, i32 1
store i64 %127, i64* %132
%133 = load i32, i32* %11
%134 = add nsw i32 %133, 1
store i32 %134, i32* %11
br label %135
135: ; preds = %119, %114
%136 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
%137 = load i64, i64* %136
%138 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 2
%139 = load i64, i64* %138
%140 = add nsw i64 %137, %139
%141 = load i64, i64* %6
%142 = icmp sle i64 %140, %141
br i1 %142, label %143, label %162
143: ; preds = %135
%144 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
%145 = load i64, i64* %144
%146 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 2
%147 = load i64, i64* %146
%148 = add nsw i64 %145, %147
%149 = load %struct.lockRange*, %struct.lockRange** %9
%150 = load i32, i32* %11
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %149, i64 %151
%153 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %152, i32 0, i32 0
store i64 %148, i64* %153
%154 = load i64, i64* %6
%155 = load %struct.lockRange*, %struct.lockRange** %9
%156 = load i32, i32* %11
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %155, i64 %157
%159 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %158, i32 0, i32 1
store i64 %154, i64* %159
%160 = load i32, i32* %11
%161 = add nsw i32 %160, 1
store i32 %161, i32* %11
br label %162
162: ; preds = %143, %135
br label %163
163: ; preds = %162, %69, %50
%164 = load i32, i32* %12
%165 = add nsw i32 %164, 1
store i32 %165, i32* %12
br label %30
166: ; preds = %30
%167 = load %struct.lockRange*, %struct.lockRange** %9
%168 = bitcast %struct.lockRange* %167 to %struct.lockRange.0*
%169 = call i32 @free(%struct.lockRange.0* %168)
%170 = load i32, i32* %7
ret i32 %170
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i64, i32, i32 }
%struct.lockRange = type { i64, i64 }
%struct.lockRange.0 = type { i64, i64 }
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@F_WRLCK = global i64 0
@SEEK_SET = global i32 0
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
@.str.1 = [43 x i8] c"start: %-12d len: %-5d pid: %-5d type: %s\0A\00"
@.str.2 = [6 x i8] c"WRLCK\00"
@.str.3 = [6 x i8] c"RDLCK\00"
@.str.4 = [32 x i8] c"unable to realloc for %d bytes\0A\00"
define i32 @showLocksInRange(i32 %0, i64 %1, i64 %2) {
%4 = alloca %struct.flock
%5 = bitcast %struct.flock* %4 to i8*
%6 = tail call %struct.lockRange.0* @malloc(i32 16)
%7 = icmp eq %struct.lockRange.0* %6, null
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = bitcast %struct.lockRange.0* %6 to %struct.lockRange*
%14 = getelementptr %struct.lockRange.0, %struct.lockRange.0* %6, i64 0, i32 0
store i64 %1, i64* %14
%15 = getelementptr inbounds %struct.lockRange.0, %struct.lockRange.0* %6, i64 0, i32 1
store i64 %2, i64* %15
%16 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 0
%17 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 4
%18 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 1
%19 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 2
%20 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 3
br label %21
21: ; preds = %12, %87
%22 = phi i64 [ 0, %12 ], [ %92, %87 ]
%23 = phi i32 [ 1, %12 ], [ %91, %87 ]
%24 = phi i32 [ 1, %12 ], [ %90, %87 ]
%25 = phi %struct.lockRange* [ %13, %12 ], [ %89, %87 ]
%26 = phi i32 [ 0, %12 ], [ %88, %87 ]
%27 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %25, i64 %22, i32 0
%28 = load i64, i64* %27
%29 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %25, i64 %22, i32 1
%30 = load i64, i64* %29
%31 = icmp sgt i64 %30, %28
br i1 %31, label %32, label %87
32: ; preds = %21
%33 = load i64, i64* @F_WRLCK
store i64 %33, i64* %16
%34 = load i32, i32* @SEEK_SET
store i32 %34, i32* %17
store i64 %28, i64* %18
%35 = sub nsw i64 %30, %28
store i64 %35, i64* %19
%36 = load i32, i32* @F_GETLK
%37 = call i32 @fcntl(i32 %0, i32 %36, %struct.flock* %4)
%38 = load i64, i64* %16
%39 = load i64, i64* @F_UNLCK
%40 = icmp eq i64 %38, %39
br i1 %40, label %87, label %41
41: ; preds = %32
%42 = load i64, i64* %18
%43 = trunc i64 %42 to i32
%44 = load i64, i64* %19
%45 = trunc i64 %44 to i32
%46 = load i32, i32* %20
%47 = load i64, i64* @F_WRLCK
%48 = icmp eq i64 %38, %47
%49 = select i1 %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%50 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %45, i32 %46, i8* %49)
%51 = add nsw i32 %26, 1
%52 = add nsw i32 %23, 2
%53 = icmp sgt i32 %52, %24
br i1 %53, label %54, label %67
54: ; preds = %41
%55 = shl nsw i32 %24, 1
%56 = add nsw i32 %55, 2
%57 = bitcast %struct.lockRange* %25 to %struct.lockRange.0*
%58 = shl i32 %56, 4
%59 = call %struct.lockRange.0* @realloc(%struct.lockRange.0* %57, i32 %58)
%60 = bitcast %struct.lockRange.0* %59 to %struct.lockRange*
%61 = icmp eq %struct.lockRange.0* %59, null
br i1 %61, label %62, label %67
62: ; preds = %54
%63 = load i32, i32* @stderr
%64 = shl nsw i32 %52, 4
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %41, %54
%68 = phi i32 [ %56, %54 ], [ %24, %41 ]
%69 = phi %struct.lockRange* [ %60, %54 ], [ %25, %41 ]
%70 = load i64, i64* %18
%71 = icmp slt i64 %28, %70
br i1 %71, label %72, label %77
72: ; preds = %67
%73 = sext i32 %23 to i64
%74 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %69, i64 %73, i32 0
store i64 %28, i64* %74
%75 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %69, i64 %73, i32 1
store i64 %70, i64* %75
%76 = add nsw i32 %23, 1
br label %77
77: ; preds = %72, %67
%78 = phi i32 [ %76, %72 ], [ %23, %67 ]
%79 = load i64, i64* %19
%80 = add nsw i64 %79, %70
%81 = icmp sgt i64 %80, %30
br i1 %81, label %87, label %82
82: ; preds = %77
%83 = sext i32 %78 to i64
%84 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %69, i64 %83, i32 0
store i64 %80, i64* %84
%85 = getelementptr inbounds %struct.lockRange, %struct.lockRange* %69, i64 %83, i32 1
store i64 %30, i64* %85
%86 = add nsw i32 %78, 1
br label %87
87: ; preds = %77, %82, %32, %21
%88 = phi i32 [ %26, %21 ], [ %26, %32 ], [ %51, %82 ], [ %51, %77 ]
%89 = phi %struct.lockRange* [ %25, %21 ], [ %25, %32 ], [ %69, %82 ], [ %69, %77 ]
%90 = phi i32 [ %24, %21 ], [ %24, %32 ], [ %68, %82 ], [ %68, %77 ]
%91 = phi i32 [ %23, %21 ], [ %23, %32 ], [ %86, %82 ], [ %78, %77 ]
%92 = add nuw nsw i64 %22, 1
%93 = sext i32 %91 to i64
%94 = icmp slt i64 %92, %93
br i1 %94, label %21, label %95
95: ; preds = %87
%96 = bitcast %struct.lockRange* %89 to %struct.lockRange.0*
%97 = call i32 @free(%struct.lockRange.0* %96)
ret i32 %88
}