#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ F_RDLCK;
int /*<<< orphan*/ F_WRLCK;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ isLocked(int, int /*<<< orphan*/, int, int, char *);
char *malloc(int);
scalar_t__ memcmp(unsigned char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int hDb;
  int hShm;
  char *zShm;
  ssize_t got;
  int isWal;
  int nName;
  unsigned char aHdr[100];
  int nLock = 0;
  int i;
  if (argc != 2)
    usage(argv[0]);
  hDb = open(argv[1], O_RDONLY, 0);
  if (hDb < 0) {
    fprintf(stderr, "cannot open %s\n", argv[1]);
    return 1;
  }
  got = read(hDb, aHdr, 100);
  if (got != 100 || memcmp(aHdr, "SQLite format 3", 16) != 0) {
    fprintf(stderr, "not an SQLite database: %s\n", argv[1]);
    exit(1);
  }
  if (isLocked(hDb, F_RDLCK, ((0x40000000) + 2), 510, "EXCLUSIVE")) {
    return 0;
  }
  isWal = aHdr[18] == 2;
  if (isWal == 0) {
    if (isLocked(hDb, F_RDLCK, (0x40000000), 1, "PENDING"))
      return 0;
    if (isLocked(hDb, F_RDLCK, ((0x40000000) + 1), 1, "RESERVED"))
      return 0;
    if (isLocked(hDb, F_WRLCK, ((0x40000000) + 2), 510, "SHARED")) {
      return 0;
    }
  } else {
    nName = (int)strlen(argv[1]);
    zShm = malloc(nName + 100);
    if (zShm == 0) {
      fprintf(stderr, "out of memory\n");
      exit(1);
    }
    memcpy(zShm, argv[1], nName);
    memcpy(&zShm[nName], "-shm", 5);
    hShm = open(zShm, O_RDONLY, 0);
    if (hShm < 0) {
      fprintf(stderr, "cannot open %s\n", zShm);
      return 1;
    }
    if (isLocked(hShm, F_RDLCK, (120 + 2), 1, "WAL-RECOVERY")) {
      return 0;
    }
    nLock += isLocked(hShm, F_RDLCK, (120 + 1), 1, "WAL-CHECKPOINT");
    nLock += isLocked(hShm, F_RDLCK, 120, 1, "WAL-WRITE");
    for (i = 0; i < 5; i++) {
      nLock += isLocked(hShm, F_WRLCK, (120 + 3) + i, 1, "WAL-READ");
    }
  }
  if (nLock == 0) {
    printf("file is not locked\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x94(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e9 <main+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1239 <main+0x89>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1594 <main+0x3e4>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jne    127c <main+0xcc>
lea    -0x90(%rbp),%rdi
lea    0xda8(%rip),%rsi
mov    $0x10,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     12a5 <main+0xf5>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    $0x40000002,%edx
mov    $0x1fe,%ecx
lea    0xd7a(%rip),%r8
call   10c0 <isLocked@plt>
cmp    $0x0,%rax
je     12dd <main+0x12d>
movl   $0x0,-0x4(%rbp)
jmp    1594 <main+0x3e4>
movzbl -0x7e(%rbp),%eax
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    13a6 <main+0x1f6>
mov    -0x14(%rbp),%edi
mov    0x2cbd(%rip),%rax
mov    (%rax),%esi
mov    $0x40000000,%edx
mov    $0x1,%ecx
lea    0xd30(%rip),%r8
call   10c0 <isLocked@plt>
cmp    $0x0,%rax
je     1331 <main+0x181>
movl   $0x0,-0x4(%rbp)
jmp    1594 <main+0x3e4>
mov    -0x14(%rbp),%edi
mov    0x2c85(%rip),%rax
mov    (%rax),%esi
mov    $0x40000001,%edx
mov    $0x1,%ecx
lea    0xd00(%rip),%r8
call   10c0 <isLocked@plt>
cmp    $0x0,%rax
je     1369 <main+0x1b9>
movl   $0x0,-0x4(%rbp)
jmp    1594 <main+0x3e4>
mov    -0x14(%rbp),%edi
mov    0x2c5d(%rip),%rax
mov    (%rax),%esi
mov    $0x40000002,%edx
mov    $0x1fe,%ecx
lea    0xcd1(%rip),%r8
call   10c0 <isLocked@plt>
cmp    $0x0,%rax
je     13a1 <main+0x1f1>
movl   $0x0,-0x4(%rbp)
jmp    1594 <main+0x3e4>
jmp    1574 <main+0x3c4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13f1 <main+0x241>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
lea    0xc7e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x2c(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
lea    0xc56(%rip),%rsi
mov    $0x5,%edx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    0x2bbc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1469 <main+0x2b9>
mov    0x2b8f(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xbaa(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1594 <main+0x3e4>
mov    -0x18(%rbp),%edi
mov    0x2b4d(%rip),%rax
mov    (%rax),%esi
mov    $0x7a,%edx
mov    $0x1,%ecx
lea    0xbec(%rip),%r8
call   10c0 <isLocked@plt>
cmp    $0x0,%rax
je     14a1 <main+0x2f1>
movl   $0x0,-0x4(%rbp)
jmp    1594 <main+0x3e4>
mov    -0x18(%rbp),%edi
mov    0x2b15(%rip),%rax
mov    (%rax),%esi
mov    $0x79,%edx
mov    $0x1,%ecx
lea    0xbc1(%rip),%r8
call   10c0 <isLocked@plt>
mov    %rax,%rcx
movslq -0x94(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x94(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2ae0(%rip),%rax
mov    (%rax),%esi
mov    $0x78,%edx
mov    $0x1,%ecx
lea    0xb9b(%rip),%r8
call   10c0 <isLocked@plt>
mov    %rax,%rcx
movslq -0x94(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
cmpl   $0x5,-0x98(%rbp)
jge    156f <main+0x3bf>
mov    -0x18(%rbp),%edi
mov    0x2aa4(%rip),%rax
mov    (%rax),%esi
mov    -0x98(%rbp),%edx
add    $0x7b,%edx
mov    $0x1,%ecx
lea    0xb55(%rip),%r8
call   10c0 <isLocked@plt>
mov    %rax,%rcx
movslq -0x94(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x94(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1515 <main+0x365>
jmp    1574 <main+0x3c4>
cmpl   $0x0,-0x94(%rbp)
jne    158d <main+0x3dd>
lea    0xb19(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11ce <main+0x1e>
mov    (%rbx),%rdi
call   10a0 <usage@plt>
mov    0x8(%rbx),%rdi
mov    0x2e0f(%rip),%r15
mov    (%r15),%esi
xor    %edx,%edx
call   10b0 <open@plt>
test   %eax,%eax
js     13cb <main+0x21b>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1050 <read@plt>
cmp    $0x64,%eax
jne    1492 <main+0x2e2>
lea    0xe04(%rip),%rsi
mov    %rsp,%rdi
mov    $0x10,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
jne    1492 <main+0x2e2>
mov    0x2d97(%rip),%r12
mov    (%r12),%esi
lea    0xe08(%rip),%r8
mov    %ebp,%edi
mov    $0x40000002,%edx
mov    $0x1fe,%ecx
call   10c0 <isLocked@plt>
xor    %r14d,%r14d
test   %rax,%rax
jne    13ec <main+0x23c>
cmpb   $0x2,0x12(%rsp)
jne    13fe <main+0x24e>
mov    0x8(%rbx),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
lea    0x64(%rax),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     14b7 <main+0x307>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
movslq %ebp,%rdi
add    %rbx,%rdi
lea    0xdd4(%rip),%rsi
mov    $0x5,%edx
call   1080 <memcpy@plt>
mov    (%r15),%esi
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %edx,%edx
call   10b0 <open@plt>
test   %eax,%eax
js     147a <main+0x2ca>
mov    %eax,%ebp
mov    (%r12),%esi
lea    0xdaa(%rip),%r8
mov    %eax,%edi
mov    $0x7a,%edx
mov    $0x1,%ecx
call   10c0 <isLocked@plt>
test   %rax,%rax
jne    13ec <main+0x23c>
mov    (%r12),%esi
lea    0xd92(%rip),%r8
mov    %ebp,%edi
mov    $0x79,%edx
mov    $0x1,%ecx
call   10c0 <isLocked@plt>
mov    %rax,%r15
mov    (%r12),%esi
lea    0xd82(%rip),%r8
mov    %ebp,%edi
mov    $0x78,%edx
mov    $0x1,%ecx
call   10c0 <isLocked@plt>
mov    %rax,%r12
add    %r15d,%r12d
mov    0x2ca6(%rip),%r13
mov    0x0(%r13),%esi
lea    0xd63(%rip),%r15
mov    %ebp,%edi
mov    $0x7b,%edx
mov    $0x1,%ecx
mov    %r15,%r8
call   10c0 <isLocked@plt>
mov    %rax,%rbx
add    %r12d,%ebx
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    $0x7c,%edx
mov    $0x1,%ecx
mov    %r15,%r8
call   10c0 <isLocked@plt>
mov    %rax,%r12
add    %ebx,%r12d
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    $0x7d,%edx
mov    $0x1,%ecx
mov    %r15,%r8
call   10c0 <isLocked@plt>
mov    %rax,%rbx
add    %r12d,%ebx
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    $0x7e,%edx
mov    $0x1,%ecx
mov    %r15,%r8
call   10c0 <isLocked@plt>
mov    %rax,%r12
add    %ebx,%r12d
mov    0x0(%r13),%esi
mov    %ebp,%edi
mov    $0x7f,%edx
mov    $0x1,%ecx
mov    %r15,%r8
call   10c0 <isLocked@plt>
add    %r12d,%eax
jne    13ec <main+0x23c>
jmp    1466 <main+0x2b6>
mov    0x2c06(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xc21(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%esi
lea    0xc3d(%rip),%r8
mov    %ebp,%edi
mov    $0x40000000,%edx
mov    $0x1,%ecx
call   10c0 <isLocked@plt>
test   %rax,%rax
jne    13ec <main+0x23c>
mov    (%r12),%esi
lea    0xc24(%rip),%r8
mov    %ebp,%edi
mov    $0x40000001,%edx
mov    $0x1,%ecx
call   10c0 <isLocked@plt>
test   %rax,%rax
jne    13ec <main+0x23c>
mov    0x2b89(%rip),%rax
mov    (%rax),%esi
lea    0xc07(%rip),%r8
mov    %ebp,%edi
mov    $0x40000002,%edx
mov    $0x1fe,%ecx
call   10c0 <isLocked@plt>
test   %rax,%rax
jne    13ec <main+0x23c>
lea    0xc34(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
jmp    13ec <main+0x23c>
mov    0x2b57(%rip),%rax
mov    (%rax),%edi
lea    0xb76(%rip),%rsi
mov    %rbx,%rdx
jmp    13df <main+0x22f>
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xb7a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2b1a(%rip),%rax
mov    (%rax),%edi
lea    0xb97(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"cannot open %s\0A\00"
@.str.1 = [16 x i8] c"SQLite format 3\00"
@.str.2 = [28 x i8] c"not an SQLite database: %s\0A\00"
@F_RDLCK = global i32 0
@.str.3 = [10 x i8] c"EXCLUSIVE\00"
@.str.4 = [8 x i8] c"PENDING\00"
@.str.5 = [9 x i8] c"RESERVED\00"
@F_WRLCK = global i32 0
@.str.6 = [7 x i8] c"SHARED\00"
@.str.7 = [15 x i8] c"out of memory\0A\00"
@.str.8 = [5 x i8] c"-shm\00"
@.str.9 = [13 x i8] c"WAL-RECOVERY\00"
@.str.10 = [15 x i8] c"WAL-CHECKPOINT\00"
@.str.11 = [10 x i8] c"WAL-WRITE\00"
@.str.12 = [9 x i8] c"WAL-READ\00"
@.str.13 = [20 x i8] c"file is not locked\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [100 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @usage(i8* %20)
br label %22
22: ; preds = %17, %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26, i32 0)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %34)
store i32 1, i32* %3
br label %166
36: ; preds = %22
%37 = load i32, i32* %6
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 100)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 100
br i1 %41, label %46, label %42
42: ; preds = %36
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%44 = call i64 @memcmp(i8* %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 16)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %42, %36
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = load i32, i32* %6
%55 = load i32, i32* @F_RDLCK
%56 = call i64 @isLocked(i32 %54, i32 %55, i32 1073741826, i32 510, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
store i32 0, i32* %3
br label %166
59: ; preds = %53
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 18
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = icmp eq i32 %62, 2
%64 = zext i1 %63 to i32
store i32 %64, i32* %10
%65 = load i32, i32* %10
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %86
67: ; preds = %59
%68 = load i32, i32* %6
%69 = load i32, i32* @F_RDLCK
%70 = call i64 @isLocked(i32 %68, i32 %69, i32 1073741824, i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %67
store i32 0, i32* %3
br label %166
73: ; preds = %67
%74 = load i32, i32* %6
%75 = load i32, i32* @F_RDLCK
%76 = call i64 @isLocked(i32 %74, i32 %75, i32 1073741825, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %73
store i32 0, i32* %3
br label %166
79: ; preds = %73
%80 = load i32, i32* %6
%81 = load i32, i32* @F_WRLCK
%82 = call i64 @isLocked(i32 %80, i32 %81, i32 1073741826, i32 510, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %85
84: ; preds = %79
store i32 0, i32* %3
br label %166
85: ; preds = %79
br label %160
86: ; preds = %59
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = call i64 @strlen(i8* %89)
%91 = trunc i64 %90 to i32
store i32 %91, i32* %11
%92 = load i32, i32* %11
%93 = add nsw i32 %92, 100
%94 = call i8* @malloc(i32 %93)
store i8* %94, i8** %8
%95 = load i8*, i8** %8
%96 = icmp eq i8* %95, null
br i1 %96, label %97, label %101
97: ; preds = %86
%98 = load i32, i32* @stderr
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %86
%102 = load i8*, i8** %8
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 1
%105 = load i8*, i8** %104
%106 = load i32, i32* %11
%107 = call i32 @memcpy(i8* %102, i8* %105, i32 %106)
%108 = load i8*, i8** %8
%109 = load i32, i32* %11
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8, i8* %108, i64 %110
%112 = call i32 @memcpy(i8* %111, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 5)
%113 = load i8*, i8** %8
%114 = load i32, i32* @O_RDONLY
%115 = call i32 @open(i8* %113, i32 %114, i32 0)
store i32 %115, i32* %7
%116 = load i32, i32* %7
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %122
118: ; preds = %101
%119 = load i32, i32* @stderr
%120 = load i8*, i8** %8
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %120)
store i32 1, i32* %3
br label %166
122: ; preds = %101
%123 = load i32, i32* %7
%124 = load i32, i32* @F_RDLCK
%125 = call i64 @isLocked(i32 %123, i32 %124, i32 122, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %128
127: ; preds = %122
store i32 0, i32* %3
br label %166
128: ; preds = %122
%129 = load i32, i32* %7
%130 = load i32, i32* @F_RDLCK
%131 = call i64 @isLocked(i32 %129, i32 %130, i32 121, i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%132 = load i32, i32* %13
%133 = sext i32 %132 to i64
%134 = add nsw i64 %133, %131
%135 = trunc i64 %134 to i32
store i32 %135, i32* %13
%136 = load i32, i32* %7
%137 = load i32, i32* @F_RDLCK
%138 = call i64 @isLocked(i32 %136, i32 %137, i32 120, i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%139 = load i32, i32* %13
%140 = sext i32 %139 to i64
%141 = add nsw i64 %140, %138
%142 = trunc i64 %141 to i32
store i32 %142, i32* %13
store i32 0, i32* %14
br label %143
143: ; preds = %156, %128
%144 = load i32, i32* %14
%145 = icmp slt i32 %144, 5
br i1 %145, label %146, label %159
146: ; preds = %143
%147 = load i32, i32* %7
%148 = load i32, i32* @F_WRLCK
%149 = load i32, i32* %14
%150 = add nsw i32 123, %149
%151 = call i64 @isLocked(i32 %147, i32 %148, i32 %150, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%152 = load i32, i32* %13
%153 = sext i32 %152 to i64
%154 = add nsw i64 %153, %151
%155 = trunc i64 %154 to i32
store i32 %155, i32* %13
br label %156
156: ; preds = %146
%157 = load i32, i32* %14
%158 = add nsw i32 %157, 1
store i32 %158, i32* %14
br label %143
159: ; preds = %143
br label %160
160: ; preds = %159, %85
%161 = load i32, i32* %13
%162 = icmp eq i32 %161, 0
br i1 %162, label %163, label %165
163: ; preds = %160
%164 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
br label %165
165: ; preds = %163, %160
store i32 0, i32* %3
br label %166
166: ; preds = %165, %127, %118, %84, %78, %72, %58, %30
%167 = load i32, i32* %3
ret i32 %167
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"cannot open %s\0A\00"
@.str.1 = [16 x i8] c"SQLite format 3\00"
@.str.2 = [28 x i8] c"not an SQLite database: %s\0A\00"
@F_RDLCK = global i32 0
@.str.3 = [10 x i8] c"EXCLUSIVE\00"
@.str.4 = [8 x i8] c"PENDING\00"
@.str.5 = [9 x i8] c"RESERVED\00"
@F_WRLCK = global i32 0
@.str.6 = [7 x i8] c"SHARED\00"
@.str.7 = [15 x i8] c"out of memory\0A\00"
@.str.8 = [5 x i8] c"-shm\00"
@.str.9 = [13 x i8] c"WAL-RECOVERY\00"
@.str.10 = [15 x i8] c"WAL-CHECKPOINT\00"
@.str.11 = [10 x i8] c"WAL-WRITE\00"
@.str.12 = [9 x i8] c"WAL-READ\00"
@str = [19 x i8] c"file is not locked\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %10
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %102
19: ; preds = %9
%20 = call i32 @read(i32 %13, i8* %4, i32 100)
%21 = icmp eq i32 %20, 100
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 16)
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22, %19
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %10
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
%31 = load i32, i32* @F_RDLCK
%32 = call i64 @isLocked(i32 %13, i32 %31, i32 1073741826, i32 510, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %102
34: ; preds = %30
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 18
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 2
br i1 %37, label %50, label %38
38: ; preds = %34
%39 = load i32, i32* @F_RDLCK
%40 = call i64 @isLocked(i32 %13, i32 %39, i32 1073741824, i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %102
42: ; preds = %38
%43 = load i32, i32* @F_RDLCK
%44 = call i64 @isLocked(i32 %13, i32 %43, i32 1073741825, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %102
46: ; preds = %42
%47 = load i32, i32* @F_WRLCK
%48 = call i64 @isLocked(i32 %13, i32 %47, i32 1073741826, i32 510, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %100, label %102
50: ; preds = %34
%51 = load i8*, i8** %10
%52 = call i64 @strlen(i8* dereferenceable(1) %51)
%53 = trunc i64 %52 to i32
%54 = add nsw i32 %53, 100
%55 = call i8* @malloc(i32 %54)
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %50
%62 = call i32 @memcpy(i8* %55, i8* %51, i32 %53)
%63 = shl i64 %52, 32
%64 = ashr exact i64 %63, 32
%65 = getelementptr inbounds i8, i8* %55, i64 %64
%66 = call i32 @memcpy(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 5)
%67 = load i32, i32* @O_RDONLY
%68 = call i32 @open(i8* %55, i32 %67, i32 0)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %61
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %55)
br label %102
73: ; preds = %61
%74 = load i32, i32* @F_RDLCK
%75 = call i64 @isLocked(i32 %68, i32 %74, i32 122, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %102
77: ; preds = %73
%78 = load i32, i32* @F_RDLCK
%79 = call i64 @isLocked(i32 %68, i32 %78, i32 121, i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%80 = load i32, i32* @F_RDLCK
%81 = call i64 @isLocked(i32 %68, i32 %80, i32 120, i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%82 = add i64 %81, %79
%83 = load i32, i32* @F_WRLCK
%84 = call i64 @isLocked(i32 %68, i32 %83, i32 123, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%85 = add i64 %84, %82
%86 = load i32, i32* @F_WRLCK
%87 = call i64 @isLocked(i32 %68, i32 %86, i32 124, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%88 = add i64 %87, %85
%89 = load i32, i32* @F_WRLCK
%90 = call i64 @isLocked(i32 %68, i32 %89, i32 125, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%91 = add i64 %90, %88
%92 = load i32, i32* @F_WRLCK
%93 = call i64 @isLocked(i32 %68, i32 %92, i32 126, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%94 = add i64 %93, %91
%95 = load i32, i32* @F_WRLCK
%96 = call i64 @isLocked(i32 %68, i32 %95, i32 127, i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%97 = add i64 %96, %94
%98 = trunc i64 %97 to i32
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %46, %77
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %102
102: ; preds = %77, %100, %73, %46, %42, %38, %30, %70, %15
%103 = phi i32 [ 1, %15 ], [ 1, %70 ], [ 0, %30 ], [ 0, %38 ], [ 0, %42 ], [ 0, %46 ], [ 0, %73 ], [ 0, %100 ], [ 0, %77 ]
ret i32 %103
}