#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 scalar_t__ time_t;
struct flock {
  scalar_t__ l_type;
  int l_start;
  int l_len;
  int l_pid;
};
typedef int pid_t;
typedef int /*<<< orphan*/ fl;

/* Variables and functions */
int F_GETLK;
scalar_t__ F_RDLCK;
int F_SETLK;
int F_SETLKW;
scalar_t__ F_UNLCK;
scalar_t__ F_WRLCK;
int LOCK_EX;
int LOCK_NB;
int LOCK_SH;
int O_CREAT;
int O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ fcntl(int, int, struct flock *);
scalar_t__ flock(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int getpid();
int /*<<< orphan*/ memset(struct flock *, int /*<<< orphan*/, int);
int open(char const *, int, int);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ pause();
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(scalar_t__);
int /*<<< orphan*/ stderr;
scalar_t__ strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int nfslock(int argc, char **argv) {
  pid_t mypid = getpid();
  int opt_flock = 0;
  int opt_excl = 0;
  int opt_nonblock = 0;
  int opt_unlock = 0;
  time_t opt_delay = 0;
  time_t opt_timeout = 0;
  int opt_sequential = 0;
  int c, fd, locked = 0;
  int flags, maxfd = 2;
  while ((c = getopt(argc, argv, "bd:nst:ux")) != -1) {
    switch (c) {
    case 'b':
      opt_flock = 1;
      break;
    case 'd':
      opt_delay = strtoul(optarg, NULL, 10);
      break;
    case 'n':
      opt_nonblock = 1;
      break;
    case 'x':
      opt_excl = 1;
      break;
    case 's':
      opt_sequential = 1;
      break;
    case 't':
      opt_timeout = strtoul(optarg, NULL, 10);
      break;
    case 'u':
      opt_unlock = 1;
      break;
    default:
      fprintf(stderr, "Invalid option\n");
      return 1;
    }
  }
  if (optind == argc) {
    fprintf(stderr, "need file to lock\n");
    return 1;
  }
  if (opt_delay)
    sleep(opt_delay);
  flags = O_CREAT;
  flags |= opt_excl ? O_RDWR : O_RDONLY;
  while (optind < argc) {
    const char *fname;
    int how;
    fname = argv[optind++];
    if ((fd = open(fname, flags, 0644)) < 0) {
      perror(fname);
      return 1;
    }
    if (fd > maxfd)
      maxfd = fd;
    printf("[%u] Trying to lock file %s...\n", mypid, fname);
    if (opt_flock) {
      how = opt_excl ? LOCK_EX : LOCK_SH;
      if (opt_nonblock)
        how |= LOCK_NB;
      if (flock(fd, how) < 0)
        perror("flock");
      else
        locked++;
    } else {
      struct flock fl;
      memset(&fl, 0, sizeof(fl));
      fl.l_type = opt_excl ? F_WRLCK : F_RDLCK;
      how = opt_nonblock ? F_SETLK : F_SETLKW;
      if (opt_sequential) {
        int j;
        for (j = 0; j < 16; j++) {
          fl.l_start = 2 * j;
          fl.l_len = 1;
          if (fcntl(fd, how, &fl) < 0) {
            perror("fcntl");
            break;
          }
          locked++;
        }
      } else {
        if (fcntl(fd, how, &fl) < 0)
          perror("fcntl");
        else
          locked++;
      }
      if (opt_unlock) {
        fl.l_type = F_UNLCK;
        fl.l_start = 0;
        fl.l_len = 0;
        if (fcntl(fd, F_SETLK, &fl) < 0) {
          perror("fcntl(F_UNLCK)");
          continue;
        }
        memset(&fl, 0, sizeof(fl));
        if (fcntl(fd, F_GETLK, &fl) < 0) {
          perror("fcntl(F_GETLK)");
          continue;
        }
        if (fl.l_type != F_UNLCK) {
          fprintf(stderr, "[%u] File still locked by pid %d\n", mypid,
                  fl.l_pid);
        }
      }
    }
  }
  if (!locked) {
    fprintf(stderr, "[%u] No files locked, exit\n", mypid);
    return 1;
  }
  printf("[%u] Locked %d file%s.\n", mypid, locked, (locked == 1) ? "" : "s");
  if (opt_timeout) {
    printf("[%u] Sleeping for %ld seconds\n", mypid, opt_timeout);
    sleep(opt_timeout);
    printf("[%u] Closing all files...\n", mypid);
    for (fd = 2; fd < maxfd; fd++)
      close(fd);
    printf("[%u] Exiting...\n", mypid);
  } else {
    printf("[%u] Going to sleep, press ctrl-c to terminate\n", mypid);
    pause();
  }
  return 0;
}


x86 assembly (clang, -O0):
<nfslock>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x2,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe21(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x40(%rbp)
cmp    $0xffffffff,%eax
je     131f <nfslock+0x14f>
mov    -0x40(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x88(%rbp)
sub    $0x16,%eax
ja     12f7 <nfslock+0x127>
mov    -0x88(%rbp),%rax
lea    0xd8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x18(%rbp)
jmp    131a <nfslock+0x14a>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10d0 <strtoul@plt>
mov    %rax,-0x30(%rbp)
jmp    131a <nfslock+0x14a>
movl   $0x1,-0x20(%rbp)
jmp    131a <nfslock+0x14a>
movl   $0x1,-0x1c(%rbp)
jmp    131a <nfslock+0x14a>
movl   $0x1,-0x3c(%rbp)
jmp    131a <nfslock+0x14a>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10d0 <strtoul@plt>
mov    %rax,-0x38(%rbp)
jmp    131a <nfslock+0x14a>
movl   $0x1,-0x24(%rbp)
jmp    131a <nfslock+0x14a>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17c0 <nfslock+0x5f0>
jmp    122d <nfslock+0x5d>
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    1354 <nfslock+0x184>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17c0 <nfslock+0x5f0>
cmpq   $0x0,-0x30(%rbp)
je     1368 <nfslock+0x198>
mov    -0x30(%rbp),%rdi
call   10f0 <sleep@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1392 <nfslock+0x1c2>
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
jmp    13a1 <nfslock+0x1d1>
mov    0x2c27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
or     -0x4c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2bf4(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    16cc <nfslock+0x4fc>
mov    -0x10(%rbp),%rax
mov    0x2bde(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2bd0(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    $0x1a4,%edx
call   10a0 <open@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jge    1417 <nfslock+0x247>
mov    -0x58(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    17c0 <nfslock+0x5f0>
mov    -0x44(%rbp),%eax
cmp    -0x50(%rbp),%eax
jle    1429 <nfslock+0x259>
mov    -0x44(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x58(%rbp),%rdx
lea    0xc52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     14cb <nfslock+0x2fb>
cmpl   $0x0,-0x1c(%rbp)
je     1466 <nfslock+0x296>
mov    0x2b77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
jmp    1475 <nfslock+0x2a5>
mov    0x2b5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    -0x90(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1497 <nfslock+0x2c7>
mov    0x2ad9(%rip),%rax
mov    (%rax),%eax
or     -0x5c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x5c(%rbp),%esi
call   10e0 <flock@plt>
cmp    $0x0,%rax
jge    14bd <nfslock+0x2ed>
lea    0xbf6(%rip),%rdi
call   10b0 <perror@plt>
jmp    14c6 <nfslock+0x2f6>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    16c7 <nfslock+0x4f7>
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
cmpl   $0x0,-0x1c(%rbp)
je     14fb <nfslock+0x32b>
mov    0x2a94(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x98(%rbp)
jmp    150c <nfslock+0x33c>
mov    0x2a6e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1535 <nfslock+0x365>
mov    0x2a88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
jmp    1544 <nfslock+0x374>
mov    0x2a7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     15be <nfslock+0x3ee>
movl   $0x0,-0x7c(%rbp)
cmpl   $0x10,-0x7c(%rbp)
jge    15b9 <nfslock+0x3e9>
mov    -0x7c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x70(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x5c(%rbp),%esi
lea    -0x78(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    15a2 <nfslock+0x3d2>
lea    0xb17(%rip),%rdi
call   10b0 <perror@plt>
jmp    15b9 <nfslock+0x3e9>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    155e <nfslock+0x38e>
jmp    15f6 <nfslock+0x426>
mov    -0x44(%rbp),%edi
mov    -0x5c(%rbp),%esi
lea    -0x78(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    15e8 <nfslock+0x418>
lea    0xad1(%rip),%rdi
call   10b0 <perror@plt>
jmp    15f1 <nfslock+0x421>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    15f6 <nfslock+0x426>
cmpl   $0x0,-0x24(%rbp)
je     16c2 <nfslock+0x4f2>
mov    0x2991(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x70(%rbp)
movl   $0x0,-0x6c(%rbp)
mov    -0x44(%rbp),%edi
mov    0x298a(%rip),%rax
mov    (%rax),%esi
lea    -0x78(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    164c <nfslock+0x47c>
lea    0xa73(%rip),%rdi
call   10b0 <perror@plt>
jmp    13ad <nfslock+0x1dd>
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    -0x44(%rbp),%edi
mov    0x293a(%rip),%rax
mov    (%rax),%esi
lea    -0x78(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    168c <nfslock+0x4bc>
lea    0xa42(%rip),%rdi
call   10b0 <perror@plt>
jmp    13ad <nfslock+0x1dd>
mov    -0x78(%rbp),%rax
mov    0x2901(%rip),%rcx
cmp    (%rcx),%rax
je     16bd <nfslock+0x4ed>
mov    0x28e1(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x68(%rbp),%ecx
lea    0xa1d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    16c2 <nfslock+0x4f2>
jmp    16c7 <nfslock+0x4f7>
jmp    13ad <nfslock+0x1dd>
cmpl   $0x0,-0x48(%rbp)
jne    16fc <nfslock+0x52c>
mov    0x28ab(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xa0c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    17c0 <nfslock+0x5f0>
mov    -0x14(%rbp),%esi
mov    -0x48(%rbp),%edx
mov    -0x48(%rbp),%edi
lea    0xa1d(%rip),%rcx
lea    0xa62(%rip),%rax
cmp    $0x1,%edi
cmove  %rax,%rcx
lea    0x9f0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x38(%rbp)
je     17a1 <nfslock+0x5d1>
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0x9ea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <sleep@plt>
mov    -0x14(%rbp),%esi
lea    0x9ef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    178b <nfslock+0x5bb>
mov    -0x44(%rbp),%edi
call   1070 <close@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1769 <nfslock+0x599>
mov    -0x14(%rbp),%esi
lea    0x9d0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    17b9 <nfslock+0x5e9>
mov    -0x14(%rbp),%esi
lea    0x9cb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <pause@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nfslock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,0x10(%rsp)
mov    %edi,%r14d
xor    %eax,%eax
mov    %rax,0x50(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x8(%rsp)
mov    $0x1,%al
mov    %eax,0xc(%rsp)
lea    0xe4f(%rip),%rbx
lea    0xdf4(%rip),%rbp
movl   $0x0,0x1c(%rsp)
xor    %r15d,%r15d
xor    %eax,%eax
mov    %rax,0x48(%rsp)
movl   $0x0,0x20(%rsp)
xor    %r12d,%r12d
mov    0x10(%rsp),%r13
mov    %r12d,%ecx
mov    %ecx,%r12d
mov    %r14d,%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10c0 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x62,%eax
je     1231 <nfslock+0x61>
lea    -0x64(%rax),%ecx
cmp    $0x14,%ecx
ja     12c4 <nfslock+0xf4>
movslq 0x0(%rbp,%rcx,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10d0 <strtoul@plt>
mov    %rax,%r15
jmp    122e <nfslock+0x5e>
movl   $0x1,0x1c(%rsp)
jmp    122e <nfslock+0x5e>
movl   $0x1,0x20(%rsp)
jmp    122e <nfslock+0x5e>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   10d0 <strtoul@plt>
mov    %rax,0x48(%rsp)
jmp    122e <nfslock+0x5e>
mov    $0x1,%eax
mov    %rax,0x50(%rsp)
jmp    122e <nfslock+0x5e>
movl   $0x0,0xc(%rsp)
jmp    122e <nfslock+0x5e>
cmp    $0xffffffff,%eax
jne    12e9 <nfslock+0x119>
mov    0x2cd8(%rip),%rsi
mov    (%rsi),%eax
cmp    %r14d,%eax
jne    1316 <nfslock+0x146>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
jmp    12f9 <nfslock+0x129>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r15,%r15
je     132c <nfslock+0x15c>
mov    %r15,%rdi
call   10f0 <sleep@plt>
mov    0x2c7e(%rip),%rsi
mov    (%rsi),%eax
testb  $0x1,0xc(%rsp)
mov    0x10(%rsp),%rbp
je     1349 <nfslock+0x179>
mov    0x2c81(%rip),%rcx
cmp    %r14d,%eax
jl     1359 <nfslock+0x189>
jmp    16c5 <nfslock+0x4f5>
mov    0x2c88(%rip),%rcx
cmp    %r14d,%eax
jge    16c5 <nfslock+0x4f5>
mov    0x2c98(%rip),%rdx
mov    (%rcx),%ecx
or     (%rdx),%ecx
mov    %ecx,0x2c(%rsp)
mov    $0x2,%r13d
xor    %r15d,%r15d
jmp    13a8 <nfslock+0x1d8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
or     (%rax),%esi
mov    %ebx,%edi
call   10e0 <flock@plt>
test   %rax,%rax
js     15b7 <nfslock+0x3e7>
add    $0x1,%r15d
mov    0x2c0b(%rip),%rsi
mov    (%rsi),%eax
cmp    %r14d,%eax
jge    1605 <nfslock+0x435>
lea    0x1(%rax),%ecx
mov    %ecx,(%rsi)
cltq
mov    0x0(%rbp,%rax,8),%rbp
mov    %rbp,%rdi
mov    0x2c(%rsp),%esi
mov    $0x1a4,%edx
call   10a0 <open@plt>
test   %eax,%eax
js     1702 <nfslock+0x532>
mov    %eax,%ebx
cmp    %r13d,%eax
mov    %r13d,0x28(%rsp)
cmovg  %eax,%r13d
lea    0xc9f(%rip),%rdi
mov    0x8(%rsp),%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12d,%r12d
je     1430 <nfslock+0x260>
mov    0x2bd4(%rip),%rax
testb  $0x1,0xc(%rsp)
mov    0x10(%rsp),%rbp
je     140f <nfslock+0x23f>
mov    0x2bb9(%rip),%rax
mov    0x1c(%rsp),%ecx
mov    %ecx,%esi
test   %ecx,%ecx
je     1380 <nfslock+0x1b0>
mov    0x2b44(%rip),%rcx
mov    (%rcx),%esi
jmp    1380 <nfslock+0x1b0>
nopl   0x0(%rax,%rax,1)
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2b35(%rip),%rax
testb  $0x1,0xc(%rsp)
je     1459 <nfslock+0x289>
mov    0x2b17(%rip),%rax
mov    %r13d,0x4(%rsp)
mov    0x2b4b(%rip),%rcx
cmpl   $0x0,0x1c(%rsp)
jne    1473 <nfslock+0x2a3>
mov    0x2b45(%rip),%rcx
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    (%rcx),%r13d
cmpl   $0x0,0x20(%rsp)
je     14ce <nfslock+0x2fe>
lea    0x10(%r15),%eax
mov    %eax,0x24(%rsp)
xor    %ebp,%ebp
nop
mov    %ebp,0x38(%rsp)
movl   $0x1,0x3c(%rsp)
mov    %ebx,%edi
mov    %r13d,%esi
lea    0x30(%rsp),%rdx
call   1030 <fcntl@plt>
test   %rax,%rax
js     15de <nfslock+0x40e>
add    $0x1,%r15d
add    $0x2,%ebp
cmp    $0x20,%ebp
jne    1490 <nfslock+0x2c0>
mov    0x24(%rsp),%eax
mov    %eax,%r15d
mov    0x10(%rsp),%rbp
jmp    14ed <nfslock+0x31d>
mov    %ebx,%edi
mov    %r13d,%esi
mov    %rbp,%rdx
call   1030 <fcntl@plt>
test   %rax,%rax
mov    0x10(%rsp),%rbp
js     15f4 <nfslock+0x424>
add    $0x1,%r15d
mov    0x2ab4(%rip),%rsi
mov    0x4(%rsp),%r13d
cmpl   $0x0,0x50(%rsp)
je     139d <nfslock+0x1cd>
mov    0x2a8d(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    0x2a8d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    0x30(%rsp),%rbp
mov    %rbp,%rdx
call   1030 <fcntl@plt>
lea    0xb72(%rip),%rdi
test   %rax,%rax
js     15c8 <nfslock+0x3f8>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2a46(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1030 <fcntl@plt>
lea    0xb4f(%rip),%rdi
test   %rax,%rax
js     15c8 <nfslock+0x3f8>
mov    0x30(%rsp),%rax
mov    0x2a1a(%rip),%rcx
cmp    (%rcx),%rax
mov    0x2a20(%rip),%rsi
mov    0x10(%rsp),%rbp
je     139d <nfslock+0x1cd>
mov    0x29ee(%rip),%rax
mov    (%rax),%edi
mov    0x40(%rsp),%ecx
lea    0xb24(%rip),%rsi
mov    0x8(%rsp),%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1396 <nfslock+0x1c6>
lea    0xae3(%rip),%rdi
call   10b0 <perror@plt>
jmp    1396 <nfslock+0x1c6>
call   10b0 <perror@plt>
mov    0x29d4(%rip),%rsi
mov    0x10(%rsp),%rbp
jmp    139d <nfslock+0x1cd>
lea    0xac2(%rip),%rdi
call   10b0 <perror@plt>
mov    0x10(%rsp),%rbp
jmp    14ed <nfslock+0x31d>
lea    0xaac(%rip),%rdi
call   10b0 <perror@plt>
jmp    14ed <nfslock+0x31d>
test   %r15d,%r15d
je     16c5 <nfslock+0x4f5>
cmp    $0x1,%r15d
lea    0xb54(%rip),%rax
lea    0xb01(%rip),%rcx
cmove  %rax,%rcx
lea    0xade(%rip),%rdi
xor    %ebp,%ebp
mov    0x8(%rsp),%r12d
mov    %r12d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x48(%rsp),%r14
test   %r14,%r14
je     16e5 <nfslock+0x515>
lea    0xacf(%rip),%rdi
xor    %ebp,%ebp
mov    %r12d,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   10f0 <sleep@plt>
lea    0xad0(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x3,%r13d
mov    0x28(%rsp),%r14d
jl     16af <nfslock+0x4df>
cmp    %r14d,%ebx
cmovg  %ebx,%r14d
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1070 <close@plt>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    16a0 <nfslock+0x4d0>
lea    0xaa7(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1305 <nfslock+0x135>
mov    0x28bc(%rip),%rax
mov    (%rax),%edi
lea    0xa18(%rip),%rsi
mov    0x8(%rsp),%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1300 <nfslock+0x130>
lea    0xa82(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <pause@plt>
jmp    1305 <nfslock+0x135>
mov    %rbp,%rdi
call   10b0 <perror@plt>
jmp    1300 <nfslock+0x130>

LLVM IR (-O0):
%struct.flock = type { i64, i32, i32, i32 }
@.str = [10 x i8] c"bd:nst:ux\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Invalid option\0A\00"
@optind = global i32 0
@.str.2 = [19 x i8] c"need file to lock\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [32 x i8] c"[%u] Trying to lock file %s...\0A\00"
@LOCK_EX = global i32 0
@LOCK_SH = global i32 0
@LOCK_NB = global i32 0
@.str.4 = [6 x i8] c"flock\00"
@F_WRLCK = global i64 0
@F_RDLCK = global i64 0
@F_SETLK = global i32 0
@F_SETLKW = global i32 0
@.str.5 = [6 x i8] c"fcntl\00"
@F_UNLCK = global i64 0
@.str.6 = [15 x i8] c"fcntl(F_UNLCK)\00"
@F_GETLK = global i32 0
@.str.7 = [15 x i8] c"fcntl(F_GETLK)\00"
@.str.8 = [34 x i8] c"[%u] File still locked by pid %d\0A\00"
@.str.9 = [28 x i8] c"[%u] No files locked, exit\0A\00"
@.str.10 = [24 x i8] c"[%u] Locked %d file%s.\0A\00"
@.str.11 = [1 x i8] zeroinitializer
@.str.12 = [2 x i8] c"s\00"
@.str.13 = [31 x i8] c"[%u] Sleeping for %ld seconds\0A\00"
@.str.14 = [27 x i8] c"[%u] Closing all files...\0A\00"
@.str.15 = [17 x i8] c"[%u] Exiting...\0A\00"
@.str.16 = [48 x i8] c"[%u] Going to sleep, press ctrl-c to terminate\0A\00"
define i32 @nfslock(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i32
%21 = alloca %struct.flock
%22 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = call i32 (...) @getpid()
store i32 %23, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i64 0, i64* %11
store i64 0, i64* %12
store i32 0, i32* %13
store i32 0, i32* %16
store i32 2, i32* %18
br label %24
24: ; preds = %45, %2
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = call i32 @getopt(i32 %25, i8** %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %27, i32* %14
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %46
29: ; preds = %24
%30 = load i32, i32* %14
switch i32 %30, label %42 [
i32 98, label %31
i32 100, label %32
i32 110, label %35
i32 120, label %36
i32 115, label %37
i32 116, label %38
i32 117, label %41
]
31: ; preds = %29
store i32 1, i32* %7
br label %45
32: ; preds = %29
%33 = load i32, i32* @optarg
%34 = call i64 @strtoul(i32 %33, i32* null, i32 10)
store i64 %34, i64* %11
br label %45
35: ; preds = %29
store i32 1, i32* %9
br label %45
36: ; preds = %29
store i32 1, i32* %8
br label %45
37: ; preds = %29
store i32 1, i32* %13
br label %45
38: ; preds = %29
%39 = load i32, i32* @optarg
%40 = call i64 @strtoul(i32 %39, i32* null, i32 10)
store i64 %40, i64* %12
br label %45
41: ; preds = %29
store i32 1, i32* %10
br label %45
42: ; preds = %29
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %260
45: ; preds = %41, %38, %37, %36, %35, %32, %31
br label %24
46: ; preds = %24
%47 = load i32, i32* @optind
%48 = load i32, i32* %4
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %260
53: ; preds = %46
%54 = load i64, i64* %11
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i64, i64* %11
%58 = call i32 @sleep(i64 %57)
br label %59
59: ; preds = %56, %53
%60 = load i32, i32* @O_CREAT
store i32 %60, i32* %17
%61 = load i32, i32* %8
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = load i32, i32* @O_RDWR
br label %67
65: ; preds = %59
%66 = load i32, i32* @O_RDONLY
br label %67
67: ; preds = %65, %63
%68 = phi i32 [ %64, %63 ], [ %66, %65 ]
%69 = load i32, i32* %17
%70 = or i32 %69, %68
store i32 %70, i32* %17
br label %71
71: ; preds = %216, %201, %193, %67
%72 = load i32, i32* @optind
%73 = load i32, i32* %4
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %217
75: ; preds = %71
%76 = load i8**, i8*** %5
%77 = load i32, i32* @optind
%78 = add nsw i32 %77, 1
store i32 %78, i32* @optind
%79 = sext i32 %77 to i64
%80 = getelementptr inbounds i8*, i8** %76, i64 %79
%81 = load i8*, i8** %80
store i8* %81, i8** %19
%82 = load i8*, i8** %19
%83 = load i32, i32* %17
%84 = call i32 @open(i8* %82, i32 %83, i32 420)
store i32 %84, i32* %15
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %75
%87 = load i8*, i8** %19
%88 = call i32 @perror(i8* %87)
store i32 1, i32* %3
br label %260
89: ; preds = %75
%90 = load i32, i32* %15
%91 = load i32, i32* %18
%92 = icmp sgt i32 %90, %91
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = load i32, i32* %15
store i32 %94, i32* %18
br label %95
95: ; preds = %93, %89
%96 = load i32, i32* %6
%97 = load i8*, i8** %19
%98 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %96, i8* %97)
%99 = load i32, i32* %7
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %127
101: ; preds = %95
%102 = load i32, i32* %8
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %101
%105 = load i32, i32* @LOCK_EX
br label %108
106: ; preds = %101
%107 = load i32, i32* @LOCK_SH
br label %108
108: ; preds = %106, %104
%109 = phi i32 [ %105, %104 ], [ %107, %106 ]
store i32 %109, i32* %20
%110 = load i32, i32* %9
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %116
112: ; preds = %108
%113 = load i32, i32* @LOCK_NB
%114 = load i32, i32* %20
%115 = or i32 %114, %113
store i32 %115, i32* %20
br label %116
116: ; preds = %112, %108
%117 = load i32, i32* %15
%118 = load i32, i32* %20
%119 = call i64 @flock(i32 %117, i32 %118)
%120 = icmp slt i64 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %116
%122 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %126
123: ; preds = %116
%124 = load i32, i32* %16
%125 = add nsw i32 %124, 1
store i32 %125, i32* %16
br label %126
126: ; preds = %123, %121
br label %216
127: ; preds = %95
%128 = call i32 @memset(%struct.flock* %21, i32 0, i32 24)
%129 = load i32, i32* %8
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %133
131: ; preds = %127
%132 = load i64, i64* @F_WRLCK
br label %135
133: ; preds = %127
%134 = load i64, i64* @F_RDLCK
br label %135
135: ; preds = %133, %131
%136 = phi i64 [ %132, %131 ], [ %134, %133 ]
%137 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 0
store i64 %136, i64* %137
%138 = load i32, i32* %9
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %142
140: ; preds = %135
%141 = load i32, i32* @F_SETLK
br label %144
142: ; preds = %135
%143 = load i32, i32* @F_SETLKW
br label %144
144: ; preds = %142, %140
%145 = phi i32 [ %141, %140 ], [ %143, %142 ]
store i32 %145, i32* %20
%146 = load i32, i32* %13
%147 = icmp ne i32 %146, 0
br i1 %147, label %148, label %170
148: ; preds = %144
store i32 0, i32* %22
br label %149
149: ; preds = %166, %148
%150 = load i32, i32* %22
%151 = icmp slt i32 %150, 16
br i1 %151, label %152, label %169
152: ; preds = %149
%153 = load i32, i32* %22
%154 = mul nsw i32 2, %153
%155 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 1
store i32 %154, i32* %155
%156 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 2
store i32 1, i32* %156
%157 = load i32, i32* %15
%158 = load i32, i32* %20
%159 = call i64 @fcntl(i32 %157, i32 %158, %struct.flock* %21)
%160 = icmp slt i64 %159, 0
br i1 %160, label %161, label %163
161: ; preds = %152
%162 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %169
163: ; preds = %152
%164 = load i32, i32* %16
%165 = add nsw i32 %164, 1
store i32 %165, i32* %16
br label %166
166: ; preds = %163
%167 = load i32, i32* %22
%168 = add nsw i32 %167, 1
store i32 %168, i32* %22
br label %149
169: ; preds = %161, %149
br label %181
170: ; preds = %144
%171 = load i32, i32* %15
%172 = load i32, i32* %20
%173 = call i64 @fcntl(i32 %171, i32 %172, %struct.flock* %21)
%174 = icmp slt i64 %173, 0
br i1 %174, label %175, label %177
175: ; preds = %170
%176 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %180
177: ; preds = %170
%178 = load i32, i32* %16
%179 = add nsw i32 %178, 1
store i32 %179, i32* %16
br label %180
180: ; preds = %177, %175
br label %181
181: ; preds = %180, %169
%182 = load i32, i32* %10
%183 = icmp ne i32 %182, 0
br i1 %183, label %184, label %215
184: ; preds = %181
%185 = load i64, i64* @F_UNLCK
%186 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 0
store i64 %185, i64* %186
%187 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 1
store i32 0, i32* %187
%188 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 2
store i32 0, i32* %188
%189 = load i32, i32* %15
%190 = load i32, i32* @F_SETLK
%191 = call i64 @fcntl(i32 %189, i32 %190, %struct.flock* %21)
%192 = icmp slt i64 %191, 0
br i1 %192, label %193, label %195
193: ; preds = %184
%194 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %71
195: ; preds = %184
%196 = call i32 @memset(%struct.flock* %21, i32 0, i32 24)
%197 = load i32, i32* %15
%198 = load i32, i32* @F_GETLK
%199 = call i64 @fcntl(i32 %197, i32 %198, %struct.flock* %21)
%200 = icmp slt i64 %199, 0
br i1 %200, label %201, label %203
201: ; preds = %195
%202 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %71
203: ; preds = %195
%204 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 0
%205 = load i64, i64* %204
%206 = load i64, i64* @F_UNLCK
%207 = icmp ne i64 %205, %206
br i1 %207, label %208, label %214
208: ; preds = %203
%209 = load i32, i32* @stderr
%210 = load i32, i32* %6
%211 = getelementptr inbounds %struct.flock, %struct.flock* %21, i32 0, i32 3
%212 = load i32, i32* %211
%213 = call i32 (i32, i8*, ...) @fprintf(i32 %209, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %210, i32 %212)
br label %214
214: ; preds = %208, %203
br label %215
215: ; preds = %214, %181
br label %216
216: ; preds = %215, %126
br label %71
217: ; preds = %71
%218 = load i32, i32* %16
%219 = icmp ne i32 %218, 0
br i1 %219, label %224, label %220
220: ; preds = %217
%221 = load i32, i32* @stderr
%222 = load i32, i32* %6
%223 = call i32 (i32, i8*, ...) @fprintf(i32 %221, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %222)
store i32 1, i32* %3
br label %260
224: ; preds = %217
%225 = load i32, i32* %6
%226 = load i32, i32* %16
%227 = load i32, i32* %16
%228 = icmp eq i32 %227, 1
%229 = zext i1 %228 to i64
%230 = select i1 %228, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0)
%231 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 %225, i32 %226, i8* %230)
%232 = load i64, i64* %12
%233 = icmp ne i64 %232, 0
br i1 %233, label %234, label %255
234: ; preds = %224
%235 = load i32, i32* %6
%236 = load i64, i64* %12
%237 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i32 %235, i64 %236)
%238 = load i64, i64* %12
%239 = call i32 @sleep(i64 %238)
%240 = load i32, i32* %6
%241 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %240)
store i32 2, i32* %15
br label %242
242: ; preds = %249, %234
%243 = load i32, i32* %15
%244 = load i32, i32* %18
%245 = icmp slt i32 %243, %244
br i1 %245, label %246, label %252
246: ; preds = %242
%247 = load i32, i32* %15
%248 = call i32 @close(i32 %247)
br label %249
249: ; preds = %246
%250 = load i32, i32* %15
%251 = add nsw i32 %250, 1
store i32 %251, i32* %15
br label %242
252: ; preds = %242
%253 = load i32, i32* %6
%254 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0), i32 %253)
br label %259
255: ; preds = %224
%256 = load i32, i32* %6
%257 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.16, i64 0, i64 0), i32 %256)
%258 = call i32 (...) @pause()
br label %259
259: ; preds = %255, %252
store i32 0, i32* %3
br label %260
260: ; preds = %259, %220, %86, %50, %42
%261 = load i32, i32* %3
ret i32 %261
}

LLVM IR (-O2):
%struct.flock = type { i64, i32, i32, i32 }
@.str = [10 x i8] c"bd:nst:ux\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"Invalid option\0A\00"
@optind = global i32 0
@.str.2 = [19 x i8] c"need file to lock\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [32 x i8] c"[%u] Trying to lock file %s...\0A\00"
@LOCK_EX = global i32 0
@LOCK_SH = global i32 0
@LOCK_NB = global i32 0
@.str.4 = [6 x i8] c"flock\00"
@F_WRLCK = global i64 0
@F_RDLCK = global i64 0
@F_SETLK = global i32 0
@F_SETLKW = global i32 0
@.str.5 = [6 x i8] c"fcntl\00"
@F_UNLCK = global i64 0
@.str.6 = [15 x i8] c"fcntl(F_UNLCK)\00"
@F_GETLK = global i32 0
@.str.7 = [15 x i8] c"fcntl(F_GETLK)\00"
@.str.8 = [34 x i8] c"[%u] File still locked by pid %d\0A\00"
@.str.9 = [28 x i8] c"[%u] No files locked, exit\0A\00"
@.str.10 = [24 x i8] c"[%u] Locked %d file%s.\0A\00"
@.str.11 = [1 x i8] zeroinitializer
@.str.12 = [2 x i8] c"s\00"
@.str.13 = [31 x i8] c"[%u] Sleeping for %ld seconds\0A\00"
@.str.14 = [27 x i8] c"[%u] Closing all files...\0A\00"
@.str.15 = [17 x i8] c"[%u] Exiting...\0A\00"
@.str.16 = [48 x i8] c"[%u] Going to sleep, press ctrl-c to terminate\0A\00"
define i32 @nfslock(i32 %0, i8** %1) {
%3 = alloca %struct.flock
%4 = tail call i32 (...) @getpid()
br label %5
5: ; preds = %38, %2
%6 = phi i1 [ true, %2 ], [ false, %38 ]
%7 = phi i32 [ 0, %2 ], [ %14, %38 ]
%8 = phi i32 [ 0, %2 ], [ %21, %38 ]
%9 = phi i64 [ 0, %2 ], [ %27, %38 ]
%10 = phi i64 [ 0, %2 ], [ %32, %38 ]
%11 = phi i32 [ 0, %2 ], [ %36, %38 ]
%12 = phi i32 [ 0, %2 ], [ %39, %38 ]
br label %13
13: ; preds = %38, %5
%14 = phi i32 [ %7, %5 ], [ 1, %38 ]
%15 = phi i32 [ %8, %5 ], [ %21, %38 ]
%16 = phi i64 [ %9, %5 ], [ %27, %38 ]
%17 = phi i64 [ %10, %5 ], [ %32, %38 ]
%18 = phi i32 [ %11, %5 ], [ %36, %38 ]
%19 = phi i32 [ %12, %5 ], [ %39, %38 ]
br label %20
20: ; preds = %38, %13
%21 = phi i32 [ %15, %13 ], [ 1, %38 ]
%22 = phi i64 [ %16, %13 ], [ %27, %38 ]
%23 = phi i64 [ %17, %13 ], [ %32, %38 ]
%24 = phi i32 [ %18, %13 ], [ %36, %38 ]
%25 = phi i32 [ %19, %13 ], [ %39, %38 ]
br label %26
26: ; preds = %20, %41
%27 = phi i64 [ %22, %20 ], [ %43, %41 ]
%28 = phi i64 [ %23, %20 ], [ %32, %41 ]
%29 = phi i32 [ %24, %20 ], [ %36, %41 ]
%30 = phi i32 [ %25, %20 ], [ %39, %41 ]
br label %31
31: ; preds = %26, %44
%32 = phi i64 [ %28, %26 ], [ %46, %44 ]
%33 = phi i32 [ %29, %26 ], [ %36, %44 ]
%34 = phi i32 [ %30, %26 ], [ %39, %44 ]
br label %35
35: ; preds = %38, %31
%36 = phi i32 [ %33, %31 ], [ 1, %38 ]
%37 = phi i32 [ %34, %31 ], [ %39, %38 ]
br label %38
38: ; preds = %35, %38
%39 = phi i32 [ 1, %38 ], [ %37, %35 ]
%40 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
switch i32 %40, label %47 [
i32 -1, label %50
i32 98, label %38
i32 100, label %41
i32 110, label %13
i32 120, label %5
i32 115, label %35
i32 116, label %44
i32 117, label %20
]
41: ; preds = %38
%42 = load i32, i32* @optarg
%43 = tail call i64 @strtoul(i32 %42, i32* null, i32 10)
br label %26
44: ; preds = %38
%45 = load i32, i32* @optarg
%46 = tail call i64 @strtoul(i32 %45, i32* null, i32 10)
br label %31
47: ; preds = %38
%48 = load i32, i32* @stderr
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %190
50: ; preds = %38
%51 = load i32, i32* @optind
%52 = icmp eq i32 %51, %0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %190
56: ; preds = %50
%57 = icmp eq i64 %27, 0
br i1 %57, label %61, label %58
58: ; preds = %56
%59 = tail call i32 @sleep(i64 %27)
%60 = load i32, i32* @optind
br label %61
61: ; preds = %58, %56
%62 = phi i32 [ %60, %58 ], [ %51, %56 ]
%63 = load i32, i32* @O_CREAT
%64 = load i32, i32* @O_RDWR
%65 = load i32, i32* @O_RDONLY
%66 = select i1 %6, i32 %65, i32 %64
%67 = or i32 %66, %63
%68 = icmp slt i32 %62, %0
br i1 %68, label %69, label %167
69: ; preds = %61
%70 = icmp eq i32 %39, 0
%71 = icmp eq i32 %14, 0
%72 = bitcast %struct.flock* %3 to i8*
%73 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 0
%74 = icmp eq i32 %36, 0
%75 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 1
%76 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 2
%77 = icmp eq i32 %21, 0
%78 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 3
br label %79
79: ; preds = %69, %161
%80 = phi i32 [ %62, %69 ], [ %163, %161 ]
%81 = phi i32 [ 2, %69 ], [ %93, %161 ]
%82 = phi i32 [ 0, %69 ], [ %162, %161 ]
%83 = add nsw i32 %80, 1
store i32 %83, i32* @optind
%84 = sext i32 %80 to i64
%85 = getelementptr inbounds i8*, i8** %1, i64 %84
%86 = load i8*, i8** %85
%87 = call i32 @open(i8* %86, i32 %67, i32 420)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %79
%90 = call i32 @perror(i8* %86)
br label %190
91: ; preds = %79
%92 = icmp sgt i32 %87, %81
%93 = select i1 %92, i32 %87, i32 %81
%94 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %4, i8* %86)
br i1 %70, label %108, label %95
95: ; preds = %91
%96 = load i32, i32* @LOCK_EX
%97 = load i32, i32* @LOCK_SH
%98 = select i1 %6, i32 %97, i32 %96
%99 = load i32, i32* @LOCK_NB
%100 = select i1 %71, i32 0, i32 %99
%101 = or i32 %100, %98
%102 = call i64 @flock(i32 %87, i32 %101)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %95
%105 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %161
106: ; preds = %95
%107 = add nsw i32 %82, 1
br label %161
108: ; preds = %91
%109 = call i32 @memset(%struct.flock* %3, i32 0, i32 24)
%110 = load i64, i64* @F_WRLCK
%111 = load i64, i64* @F_RDLCK
%112 = select i1 %6, i64 %111, i64 %110
store i64 %112, i64* %73
%113 = load i32, i32* @F_SETLK
%114 = load i32, i32* @F_SETLKW
%115 = select i1 %71, i32 %114, i32 %113
br i1 %74, label %130, label %116
116: ; preds = %108
%117 = add i32 %82, 16
br label %118
118: ; preds = %116, %126
%119 = phi i32 [ %128, %126 ], [ 0, %116 ]
%120 = phi i32 [ %127, %126 ], [ %82, %116 ]
%121 = shl nuw nsw i32 %119, 1
store i32 %121, i32* %75
store i32 1, i32* %76
%122 = call i64 @fcntl(i32 %87, i32 %115, %struct.flock* %3)
%123 = icmp slt i64 %122, 0
br i1 %123, label %124, label %126
124: ; preds = %118
%125 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %137
126: ; preds = %118
%127 = add nsw i32 %120, 1
%128 = add nuw nsw i32 %119, 1
%129 = icmp eq i32 %128, 16
br i1 %129, label %137, label %118
130: ; preds = %108
%131 = call i64 @fcntl(i32 %87, i32 %115, %struct.flock* %3)
%132 = icmp slt i64 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %130
%134 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %137
135: ; preds = %130
%136 = add nsw i32 %82, 1
br label %137
137: ; preds = %126, %124, %133, %135
%138 = phi i32 [ %82, %133 ], [ %136, %135 ], [ %120, %124 ], [ %117, %126 ]
br i1 %77, label %157, label %139
139: ; preds = %137
%140 = load i64, i64* @F_UNLCK
store i64 %140, i64* %73
store i32 0, i32* %75
store i32 0, i32* %76
%141 = load i32, i32* @F_SETLK
%142 = call i64 @fcntl(i32 %87, i32 %141, %struct.flock* %3)
%143 = icmp slt i64 %142, 0
br i1 %143, label %158, label %144
144: ; preds = %139
%145 = call i32 @memset(%struct.flock* %3, i32 0, i32 24)
%146 = load i32, i32* @F_GETLK
%147 = call i64 @fcntl(i32 %87, i32 %146, %struct.flock* %3)
%148 = icmp slt i64 %147, 0
br i1 %148, label %158, label %149
149: ; preds = %144
%150 = load i64, i64* %73
%151 = load i64, i64* @F_UNLCK
%152 = icmp eq i64 %150, %151
br i1 %152, label %157, label %153
153: ; preds = %149
%154 = load i32, i32* @stderr
%155 = load i32, i32* %78
%156 = call i32 (i32, i8*, ...) @fprintf(i32 %154, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i32 %4, i32 %155)
br label %157
157: ; preds = %149, %153, %137
br label %161
158: ; preds = %144, %139
%159 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), %139 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), %144 ]
%160 = call i32 @perror(i8* %159)
br label %161
161: ; preds = %106, %104, %157, %158
%162 = phi i32 [ %138, %158 ], [ %82, %104 ], [ %107, %106 ], [ %138, %157 ]
%163 = load i32, i32* @optind
%164 = icmp slt i32 %163, %0
br i1 %164, label %79, label %165
165: ; preds = %161
%166 = icmp eq i32 %162, 0
br i1 %166, label %167, label %170
167: ; preds = %61, %165
%168 = load i32, i32* @stderr
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %168, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %4)
br label %190
170: ; preds = %165
%171 = icmp eq i32 %162, 1
%172 = select i1 %171, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0)
%173 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i32 %4, i32 %162, i8* %172)
%174 = icmp eq i64 %32, 0
br i1 %174, label %187, label %175
175: ; preds = %170
%176 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), i32 %4, i64 %32)
%177 = call i32 @sleep(i64 %32)
%178 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %4)
%179 = icmp sgt i32 %93, 2
br i1 %179, label %180, label %185
180: ; preds = %175, %180
%181 = phi i32 [ %183, %180 ], [ 2, %175 ]
%182 = call i32 @close(i32 %181)
%183 = add nuw nsw i32 %181, 1
%184 = icmp eq i32 %183, %93
br i1 %184, label %185, label %180
185: ; preds = %180, %175
%186 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.15, i64 0, i64 0), i32 %4)
br label %190
187: ; preds = %170
%188 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.16, i64 0, i64 0), i32 %4)
%189 = call i32 (...) @pause()
br label %190
190: ; preds = %89, %185, %187, %167, %53, %47
%191 = phi i32 [ 1, %47 ], [ 1, %53 ], [ 1, %167 ], [ 0, %187 ], [ 0, %185 ], [ 1, %89 ]
ret i32 %191
}