#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct flock {
  scalar_t__ l_type;
  int /*<<< orphan*/ l_whence;
};

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ F_GETLK;
scalar_t__ F_RDLCK;
int /*<<< orphan*/ F_SETLKW;
scalar_t__ F_UNLCK;
scalar_t__ F_WRLCK;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncmp(char *, char *, int);
int t_fcntl(int, int /*<<< orphan*/, struct flock *);
int t5(int argc, char *argv[]) {
  struct flock lock = {
      .l_type = F_WRLCK,
      .l_whence = SEEK_SET,
  };
  int setlk = 0, getlk = 0, unlk = 0, secs = 0;
  int pos;
  int fd;
  int rc = 0;
  if (argc < 4 || argc > 7) {
    fprintf(
        stderr,
        "Usage: ./flocks_test 5 set|get|unlock [read|write] [sleep N] file1\n"
        "       set: F_SETLKW F_WRLCK\n"
        "       get: F_GETLK F_WRLCK  (conflict)\n"
        "       unlock: F_SETLKW F_UNLCK\n"
        "       read|write: lock mode, write by default\n"
        "       sleep N: sleep for N secs after fcntl\n"
        "       file1: fcntl is called for this file\n");
    return EXIT_FAILURE;
  }
  if (!strncmp(argv[2], "set", 4))
    setlk = 1;
  else if (!strncmp(argv[2], "get", 4))
    getlk = 1;
  else if (!strncmp(argv[2], "unlock", 7))
    unlk = 1;
  else {
    fprintf(stderr, "Wrong 2nd argument: %s\n", argv[2]);
    return EXIT_FAILURE;
  }
  pos = 3;
  if (!strncmp(argv[pos], "read", 5)) {
    lock.l_type = F_RDLCK;
    pos++;
  } else if (!strncmp(argv[pos], "write", 6)) {
    lock.l_type = F_WRLCK;
    pos++;
  }
  if (!strncmp(argv[pos], "sleep", 6)) {
    secs = atoi(argv[pos + 1]);
    if (secs < 0 || secs > 10) {
      fprintf(stderr, "Sleep argument is wrong: %s\n", argv[pos + 1]);
      return EXIT_FAILURE;
    }
    pos += 2;
  }
  fd = open(argv[pos], O_RDWR);
  if (fd < 0) {
    fprintf(stderr, "Couldn't open file: %s\n", argv[pos]);
    return EXIT_FAILURE;
  }
  fprintf(stderr, "\nFLOCKS_TEST 5: %s %s flock\n",
          setlk   ? "SET"
          : getlk ? "GET"
                  : "UNLOCK",
          lock.l_type == F_WRLCK ? "write" : "read");
  if (setlk) {
    rc = t_fcntl(fd, F_SETLKW, &lock);
  } else if (getlk) {
    rc = t_fcntl(fd, F_GETLK, &lock);
  } else if (unlk) {
    lock.l_type = F_UNLCK;
    rc = t_fcntl(fd, F_SETLKW, &lock);
  }
  if (secs)
    sleep(secs);
  close(fd);
  return rc < 0 ? -rc : 0;
}


x86 assembly (clang, -O0):
<t5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11d0 <t5+0x60>
cmpl   $0x7,-0x8(%rbp)
jle    11f8 <t5+0x88>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    157a <t5+0x40a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xf2a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1226 <t5+0xb6>
movl   $0x1,-0x24(%rbp)
jmp    12bc <t5+0x14c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xf00(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1254 <t5+0xe4>
movl   $0x1,-0x28(%rbp)
jmp    12b7 <t5+0x147>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xed6(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1282 <t5+0x112>
movl   $0x1,-0x2c(%rbp)
jmp    12b2 <t5+0x142>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xea6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    157a <t5+0x40a>
jmp    12b7 <t5+0x147>
jmp    12bc <t5+0x14c>
movl   $0x3,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe82(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1305 <t5+0x195>
mov    0x2ca8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1347 <t5+0x1d7>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe45(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1342 <t5+0x1d2>
mov    0x2c76(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1347 <t5+0x1d7>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe09(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13dc <t5+0x26c>
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jl     139a <t5+0x22a>
cmpl   $0xa,-0x30(%rbp)
jle    13d3 <t5+0x263>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2be7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    157a <t5+0x40a>
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2bf9(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1437 <t5+0x2c7>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2b83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    157a <t5+0x40a>
mov    0x2b82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     145d <t5+0x2ed>
lea    0xd67(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1479 <t5+0x309>
mov    -0x28(%rbp),%edx
lea    0xd5c(%rip),%rax
lea    0xd51(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    -0x20(%rbp),%rsi
mov    0x2b1d(%rip),%rax
mov    (%rax),%r8
lea    0xcc3(%rip),%rcx
lea    0xcc1(%rip),%rax
cmp    %r8,%rsi
cmove  %rax,%rcx
lea    0xcf4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
cmpl   $0x0,-0x24(%rbp)
je     14d8 <t5+0x368>
mov    -0x38(%rbp),%edi
mov    0x2b1b(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <t_fcntl@plt>
mov    %eax,-0x3c(%rbp)
jmp    1539 <t5+0x3c9>
cmpl   $0x0,-0x28(%rbp)
je     14ff <t5+0x38f>
mov    -0x38(%rbp),%edi
mov    0x2aec(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <t_fcntl@plt>
mov    %eax,-0x3c(%rbp)
jmp    1534 <t5+0x3c4>
cmpl   $0x0,-0x2c(%rbp)
je     152f <t5+0x3bf>
mov    0x2ac0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%edi
mov    0x2abf(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <t_fcntl@plt>
mov    %eax,-0x3c(%rbp)
jmp    1534 <t5+0x3c4>
jmp    1539 <t5+0x3c9>
cmpl   $0x0,-0x30(%rbp)
je     154b <t5+0x3db>
mov    -0x30(%rbp),%edi
call   1090 <sleep@plt>
mov    -0x38(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x3c(%rbp)
jge    156a <t5+0x3fa>
xor    %eax,%eax
sub    -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    1574 <t5+0x404>
xor    %eax,%eax
mov    %eax,-0x4c(%rbp)
jmp    1574 <t5+0x404>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e23(%rip),%r15
mov    (%r15),%rbp
mov    %rbp,0x18(%rsp)
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
add    $0xfffffff8,%edi
cmp    $0xfffffffb,%edi
ja     11be <t5+0x4e>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1403 <t5+0x293>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xf65(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
lea    0xfe6(%rip),%r14
test   %eax,%eax
je     122c <t5+0xbc>
mov    0x10(%rbx),%rdi
lea    0xf49(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1248 <t5+0xd8>
mov    0x10(%rbx),%rdi
lea    0xf34(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1267 <t5+0xf7>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xf19(%rip),%rsi
jmp    13fc <t5+0x28c>
mov    %r14,0x10(%rsp)
mov    $0x1,%al
mov    %eax,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
jmp    1281 <t5+0x111>
mov    $0x1,%al
mov    %eax,0x8(%rsp)
lea    0xf6a(%rip),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%al
mov    %eax,0x4(%rsp)
mov    $0x1,%al
mov    %eax,(%rsp)
jmp    1281 <t5+0x111>
mov    %r14,0x10(%rsp)
mov    $0x1,%al
mov    %eax,0x8(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    0x18(%rbx),%rdi
lea    0xecc(%rip),%r14
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     12c0 <t5+0x150>
mov    0x18(%rbx),%rdi
lea    0xeb5(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
mov    $0x3,%ecx
test   %eax,%eax
jne    12d4 <t5+0x164>
mov    (%r15),%rbp
jmp    12ca <t5+0x15a>
mov    0x2cd1(%rip),%rax
mov    (%rax),%rbp
mov    %rbp,0x18(%rsp)
mov    $0x4,%ecx
mov    %ecx,%r12d
mov    (%rbx,%r12,8),%rdi
lea    0xe81(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     12fa <t5+0x18a>
movl   $0x0,0xc(%rsp)
jmp    132c <t5+0x1bc>
mov    0x8(%rbx,%r12,8),%r13
mov    %r13,%rdi
call   1080 <atoi@plt>
cmp    $0xb,%eax
jb     1324 <t5+0x1b4>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    %r13,%rdx
jmp    13fc <t5+0x28c>
mov    %eax,0xc(%rsp)
add    $0x2,%r12d
mov    (%rbx,%r12,8),%rdi
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%r13d
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
test   %r13d,%r13d
js     13f1 <t5+0x281>
cmp    (%r15),%rbp
lea    0xe5e(%rip),%rdx
lea    0xdf9(%rip),%rax
cmove  %rax,%r14
mov    0x8(%rsp),%ebp
test   %bpl,%bpl
cmovne 0x10(%rsp),%rdx
lea    0xe22(%rip),%rsi
mov    0x2c5d(%rip),%r12
mov    0x2c4e(%rip),%r15
cmove  %r12,%r15
xor    %ebx,%ebx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    $0x1,%bpl
mov    0x4(%rsp),%eax
or     %bpl,%al
jne    13bf <t5+0x24f>
cmpb   $0x0,(%rsp)
jne    13d1 <t5+0x261>
mov    0x2c1c(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    %r12,%r15
mov    (%r15),%esi
lea    0x18(%rsp),%rdx
mov    %r13d,%edi
call   1050 <t_fcntl@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
test   %edi,%edi
je     13de <t5+0x26e>
call   1090 <sleep@plt>
mov    %r13d,%edi
call   1040 <close@plt>
mov    %ebx,%eax
neg    %eax
sar    $0x1f,%ebx
and    %eax,%ebx
jmp    140c <t5+0x29c>
mov    (%rbx,%r12,8),%rdx
lea    0xd8a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2ba6(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i64, i32 }
@F_WRLCK = global i64 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [305 x i8] c"Usage: ./flocks_test 5 set|get|unlock [read|write] [sleep N] file1\0A set: F_SETLKW F_WRLCK\0A get: F_GETLK F_WRLCK (conflict)\0A unlock: F_SETLKW F_UNLCK\0A read|write: lock mode, write by default\0A sleep N: sleep for N secs after fcntl\0A file1: fcntl is called for this file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [4 x i8] c"get\00"
@.str.3 = [7 x i8] c"unlock\00"
@.str.4 = [24 x i8] c"Wrong 2nd argument: %s\0A\00"
@.str.5 = [5 x i8] c"read\00"
@F_RDLCK = global i64 0
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [6 x i8] c"sleep\00"
@.str.8 = [29 x i8] c"Sleep argument is wrong: %s\0A\00"
@O_RDWR = global i32 0
@.str.9 = [24 x i8] c"Couldn't open file: %s\0A\00"
@.str.10 = [29 x i8] c"\0AFLOCKS_TEST 5: %s %s flock\0A\00"
@.str.11 = [4 x i8] c"SET\00"
@.str.12 = [4 x i8] c"GET\00"
@.str.13 = [7 x i8] c"UNLOCK\00"
@F_SETLKW = global i32 0
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
define i32 @t5(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.flock
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = getelementptr inbounds %struct.flock, %struct.flock* %6, i32 0, i32 0
%15 = load i64, i64* @F_WRLCK
store i64 %15, i64* %14
%16 = getelementptr inbounds %struct.flock, %struct.flock* %6, i32 0, i32 1
%17 = load i32, i32* @SEEK_SET
store i32 %17, i32* %16
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %13
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 4
br i1 %19, label %23, label %20
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 7
br i1 %22, label %23, label %27
23: ; preds = %20, %2
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([305 x i8], [305 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %197
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strncmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %27
store i32 1, i32* %7
br label %57
34: ; preds = %27
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @strncmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %34
store i32 1, i32* %8
br label %56
41: ; preds = %34
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @strncmp(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 7)
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %41
store i32 1, i32* %9
br label %55
48: ; preds = %41
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
store i32 %54, i32* %3
br label %197
55: ; preds = %47
br label %56
56: ; preds = %55, %40
br label %57
57: ; preds = %56, %33
store i32 3, i32* %11
%58 = load i8**, i8*** %5
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @strncmp(i8* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
%64 = icmp ne i32 %63, 0
br i1 %64, label %70, label %65
65: ; preds = %57
%66 = load i64, i64* @F_RDLCK
%67 = getelementptr inbounds %struct.flock, %struct.flock* %6, i32 0, i32 0
store i64 %66, i64* %67
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
store i32 %69, i32* %11
br label %84
70: ; preds = %57
%71 = load i8**, i8*** %5
%72 = load i32, i32* %11
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 @strncmp(i8* %75, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 6)
%77 = icmp ne i32 %76, 0
br i1 %77, label %83, label %78
78: ; preds = %70
%79 = load i64, i64* @F_WRLCK
%80 = getelementptr inbounds %struct.flock, %struct.flock* %6, i32 0, i32 0
store i64 %79, i64* %80
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 1
store i32 %82, i32* %11
br label %83
83: ; preds = %78, %70
br label %84
84: ; preds = %83, %65
%85 = load i8**, i8*** %5
%86 = load i32, i32* %11
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8*, i8** %85, i64 %87
%89 = load i8*, i8** %88
%90 = call i32 @strncmp(i8* %89, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 6)
%91 = icmp ne i32 %90, 0
br i1 %91, label %118, label %92
92: ; preds = %84
%93 = load i8**, i8*** %5
%94 = load i32, i32* %11
%95 = add nsw i32 %94, 1
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %93, i64 %96
%98 = load i8*, i8** %97
%99 = call i32 @atoi(i8* %98)
store i32 %99, i32* %10
%100 = load i32, i32* %10
%101 = icmp slt i32 %100, 0
br i1 %101, label %105, label %102
102: ; preds = %92
%103 = load i32, i32* %10
%104 = icmp sgt i32 %103, 10
br i1 %104, label %105, label %115
105: ; preds = %102, %92
%106 = load i32, i32* @stderr
%107 = load i8**, i8*** %5
%108 = load i32, i32* %11
%109 = add nsw i32 %108, 1
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i8*, i8** %107, i64 %110
%112 = load i8*, i8** %111
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %112)
%114 = load i32, i32* @EXIT_FAILURE
store i32 %114, i32* %3
br label %197
115: ; preds = %102
%116 = load i32, i32* %11
%117 = add nsw i32 %116, 2
store i32 %117, i32* %11
br label %118
118: ; preds = %115, %84
%119 = load i8**, i8*** %5
%120 = load i32, i32* %11
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %119, i64 %121
%123 = load i8*, i8** %122
%124 = load i32, i32* @O_RDWR
%125 = call i32 @open(i8* %123, i32 %124)
store i32 %125, i32* %12
%126 = load i32, i32* %12
%127 = icmp slt i32 %126, 0
br i1 %127, label %128, label %137
128: ; preds = %118
%129 = load i32, i32* @stderr
%130 = load i8**, i8*** %5
%131 = load i32, i32* %11
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i8*, i8** %130, i64 %132
%134 = load i8*, i8** %133
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %134)
%136 = load i32, i32* @EXIT_FAILURE
store i32 %136, i32* %3
br label %197
137: ; preds = %118
%138 = load i32, i32* @stderr
%139 = load i32, i32* %7
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %142
141: ; preds = %137
br label %147
142: ; preds = %137
%143 = load i32, i32* %8
%144 = icmp ne i32 %143, 0
%145 = zext i1 %144 to i64
%146 = select i1 %144, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0)
br label %147
147: ; preds = %142, %141
%148 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), %141 ], [ %146, %142 ]
%149 = getelementptr inbounds %struct.flock, %struct.flock* %6, i32 0, i32 0
%150 = load i64, i64* %149
%151 = load i64, i64* @F_WRLCK
%152 = icmp eq i64 %150, %151
%153 = zext i1 %152 to i64
%154 = select i1 %152, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
%155 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %148, i8* %154)
%156 = load i32, i32* %7
%157 = icmp ne i32 %156, 0
br i1 %157, label %158, label %162
158: ; preds = %147
%159 = load i32, i32* %12
%160 = load i32, i32* @F_SETLKW
%161 = call i32 @t_fcntl(i32 %159, i32 %160, %struct.flock* %6)
store i32 %161, i32* %13
br label %180
162: ; preds = %147
%163 = load i32, i32* %8
%164 = icmp ne i32 %163, 0
br i1 %164, label %165, label %169
165: ; preds = %162
%166 = load i32, i32* %12
%167 = load i32, i32* @F_GETLK
%168 = call i32 @t_fcntl(i32 %166, i32 %167, %struct.flock* %6)
store i32 %168, i32* %13
br label %179
169: ; preds = %162
%170 = load i32, i32* %9
%171 = icmp ne i32 %170, 0
br i1 %171, label %172, label %178
172: ; preds = %169
%173 = load i64, i64* @F_UNLCK
%174 = getelementptr inbounds %struct.flock, %struct.flock* %6, i32 0, i32 0
store i64 %173, i64* %174
%175 = load i32, i32* %12
%176 = load i32, i32* @F_SETLKW
%177 = call i32 @t_fcntl(i32 %175, i32 %176, %struct.flock* %6)
store i32 %177, i32* %13
br label %178
178: ; preds = %172, %169
br label %179
179: ; preds = %178, %165
br label %180
180: ; preds = %179, %158
%181 = load i32, i32* %10
%182 = icmp ne i32 %181, 0
br i1 %182, label %183, label %186
183: ; preds = %180
%184 = load i32, i32* %10
%185 = call i32 @sleep(i32 %184)
br label %186
186: ; preds = %183, %180
%187 = load i32, i32* %12
%188 = call i32 @close(i32 %187)
%189 = load i32, i32* %13
%190 = icmp slt i32 %189, 0
br i1 %190, label %191, label %194
191: ; preds = %186
%192 = load i32, i32* %13
%193 = sub nsw i32 0, %192
br label %195
194: ; preds = %186
br label %195
195: ; preds = %194, %191
%196 = phi i32 [ %193, %191 ], [ 0, %194 ]
store i32 %196, i32* %3
br label %197
197: ; preds = %195, %128, %105, %48, %23
%198 = load i32, i32* %3
ret i32 %198
}

LLVM IR (-O2):
%struct.flock = type { i64, i32 }
@F_WRLCK = global i64 0
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [305 x i8] c"Usage: ./flocks_test 5 set|get|unlock [read|write] [sleep N] file1\0A set: F_SETLKW F_WRLCK\0A get: F_GETLK F_WRLCK (conflict)\0A unlock: F_SETLKW F_UNLCK\0A read|write: lock mode, write by default\0A sleep N: sleep for N secs after fcntl\0A file1: fcntl is called for this file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [4 x i8] c"get\00"
@.str.3 = [7 x i8] c"unlock\00"
@.str.4 = [24 x i8] c"Wrong 2nd argument: %s\0A\00"
@.str.5 = [5 x i8] c"read\00"
@F_RDLCK = global i64 0
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [6 x i8] c"sleep\00"
@.str.8 = [29 x i8] c"Sleep argument is wrong: %s\0A\00"
@O_RDWR = global i32 0
@.str.9 = [24 x i8] c"Couldn't open file: %s\0A\00"
@.str.10 = [29 x i8] c"\0AFLOCKS_TEST 5: %s %s flock\0A\00"
@.str.11 = [4 x i8] c"SET\00"
@.str.12 = [4 x i8] c"GET\00"
@.str.13 = [7 x i8] c"UNLOCK\00"
@F_SETLKW = global i32 0
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
define i32 @t5(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.flock
%4 = bitcast %struct.flock* %3 to i8*
%5 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 0
%6 = load i64, i64* @F_WRLCK
store i64 %6, i64* %5
%7 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 1
%8 = load i32, i32* @SEEK_SET
store i32 %8, i32* %7
%9 = add i32 %0, -8
%10 = icmp ult i32 %9, -4
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([305 x i8], [305 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
br label %111
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %15
%21 = load i8*, i8** %16
%22 = tail call i32 @strncmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 4)
%23 = icmp eq i32 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %20
%25 = load i8*, i8** %16
%26 = tail call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 7)
%27 = icmp eq i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %16
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
br label %111
33: ; preds = %24, %20, %15
%34 = phi i1 [ false, %15 ], [ true, %20 ], [ true, %24 ]
%35 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), %15 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), %20 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0), %24 ]
%36 = phi i1 [ false, %15 ], [ true, %20 ], [ false, %24 ]
%37 = phi i1 [ true, %15 ], [ true, %20 ], [ false, %24 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 3
%39 = load i8*, i8** %38
%40 = tail call i32 @strncmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %33
%43 = load i64, i64* @F_RDLCK
store i64 %43, i64* %5
br label %50
44: ; preds = %33
%45 = load i8*, i8** %38
%46 = tail call i32 @strncmp(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 6)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = load i64, i64* @F_WRLCK
store i64 %49, i64* %5
br label %50
50: ; preds = %44, %48, %42
%51 = phi i64 [ %6, %44 ], [ %49, %48 ], [ %43, %42 ]
%52 = phi i32 [ 3, %44 ], [ 4, %48 ], [ 4, %42 ]
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %1, i64 %53
%55 = load i8*, i8** %54
%56 = tail call i32 @strncmp(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 6)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %72
58: ; preds = %50
%59 = add nuw nsw i32 %52, 1
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %1, i64 %60
%62 = load i8*, i8** %61
%63 = tail call i32 @atoi(i8* %62)
%64 = icmp ugt i32 %63, 10
br i1 %64, label %65, label %69
65: ; preds = %58
%66 = load i32, i32* @stderr
%67 = tail call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %62)
%68 = load i32, i32* @EXIT_FAILURE
br label %111
69: ; preds = %58
%70 = add nuw nsw i32 %52, 2
%71 = zext i32 %70 to i64
br label %72
72: ; preds = %69, %50
%73 = phi i64 [ %71, %69 ], [ %53, %50 ]
%74 = phi i32 [ %63, %69 ], [ 0, %50 ]
%75 = getelementptr inbounds i8*, i8** %1, i64 %73
%76 = load i8*, i8** %75
%77 = load i32, i32* @O_RDWR
%78 = tail call i32 @open(i8* %76, i32 %77)
%79 = icmp slt i32 %78, 0
%80 = load i32, i32* @stderr
br i1 %79, label %81, label %85
81: ; preds = %72
%82 = load i8*, i8** %75
%83 = tail call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0), i8* %82)
%84 = load i32, i32* @EXIT_FAILURE
br label %111
85: ; preds = %72
%86 = select i1 %34, i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0)
%87 = load i64, i64* @F_WRLCK
%88 = icmp eq i64 %51, %87
%89 = select i1 %88, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0)
%90 = tail call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i8* %86, i8* %89)
%91 = xor i1 %34, true
%92 = or i1 %36, %91
%93 = select i1 %34, i32* @F_GETLK, i32* @F_SETLKW
br i1 %92, label %97, label %94
94: ; preds = %85
br i1 %37, label %101, label %95
95: ; preds = %94
%96 = load i64, i64* @F_UNLCK
store i64 %96, i64* %5
br label %97
97: ; preds = %85, %95
%98 = phi i32* [ @F_SETLKW, %95 ], [ %93, %85 ]
%99 = load i32, i32* %98
%100 = call i32 @t_fcntl(i32 %78, i32 %99, %struct.flock* %3)
br label %101
101: ; preds = %97, %94
%102 = phi i32 [ 0, %94 ], [ %100, %97 ]
%103 = icmp eq i32 %74, 0
br i1 %103, label %106, label %104
104: ; preds = %101
%105 = call i32 @sleep(i32 %74)
br label %106
106: ; preds = %104, %101
%107 = call i32 @close(i32 %78)
%108 = icmp slt i32 %102, 0
%109 = sub nsw i32 0, %102
%110 = select i1 %108, i32 %109, i32 0
br label %111
111: ; preds = %106, %81, %65, %28, %11
%112 = phi i32 [ %14, %11 ], [ %32, %28 ], [ %84, %81 ], [ %110, %106 ], [ %68, %65 ]
ret i32 %112
}