#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 stat {
  int /*<<< orphan*/ st_mode;
};
struct flock {
  scalar_t__ l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
  int /*<<< orphan*/ l_type;
};

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_SETLKW;
int /*<<< orphan*/ F_WRLCK;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstat(int, struct stat *);
char *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
char *strerror(scalar_t__);
int strlen(char *);
int system(char *);
int /*<<< orphan*/ usage(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *file, *command, *envvar;
  int wait = 1, n;
  int fd;
  struct stat st;
  struct flock fl;
  if (argv[1] &&
      (0 == strcmp(argv[1], "-h") || 0 == strcmp(argv[1], "--help"))) {
    usage(stdout);
    return 0;
  }
  if (argc == 4) {
    if (strcmp(argv[1], "-n") != 0) {
      fprintf(stderr, "run-with-lockfile: `%s' is not a valid option\n",
              argv[1]);
      usage(stderr);
      return 101;
    } else {
      wait = 0;
      --argc;
      ++argv;
    }
  }
  if (argc != 3) {
    fprintf(stderr, "run-with-lockfile: incorrect arguments\n");
    usage(stderr);
    return 101;
  }
  file = argv[1];
  command = argv[2];
  if (-1 == (fd = open(file, O_RDWR | O_CREAT, 0666))) {
    fprintf(stderr, "run-with-lockfile: %s: %s\n", file, strerror(errno));
    return 101;
  }
  if (-1 == fstat(fd, &st)) {
    fprintf(stderr, "run-with-lockfile: %s: %s\n", file, strerror(errno));
    return 101;
  } else if (!S_ISREG(st.st_mode)) {
    fprintf(stderr, "run-with-lockfile: %s: is not a regular file\n", file);
    return 101;
  }
  fl.l_type = F_WRLCK;
  fl.l_whence = SEEK_SET;
  fl.l_start = 0;
  fl.l_len = 0;
  while (-1 == (n = fcntl(fd, wait ? F_SETLKW : F_SETLK, &fl)) &&
         errno == EINTR)
    ;
  if (n == -1) {
    if (!wait && (errno == EAGAIN || errno == EACCES))
      return 100;
    else {
      fprintf(stderr, "run-with-lockfile: %s: set lock: %s\n", file,
              strerror(errno));
      return 101;
    }
  }
  envvar = malloc(strlen(file) + sizeof("LOCKFILE="));
  sprintf(envvar, "LOCKFILE=%s", file);
  putenv(envvar);
  errno = 0;
  n = system(command);
  if (n == -1) {
    fprintf(stderr, "run-with-lockfile: %s: %s\n", command, strerror(errno));
    n = 101;
  } else if (n == 127 && errno != 0) {
    fprintf(stderr, "run-with-lockfile: /bin/sh: %s\n", strerror(errno));
    n = 101;
  }
  close(fd);
  return n;
}


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   $0x1,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     126d <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde2(%rip),%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1253 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc3(%rip),%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    126d <main+0x8d>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10c0 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    16bd <main+0x4dd>
cmpl   $0x4,-0x8(%rbp)
jne    12ef <main+0x10f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd84(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12ce <main+0xee>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
call   10c0 <usage@plt>
movl   $0x65,-0x4(%rbp)
jmp    16bd <main+0x4dd>
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    12ef <main+0x10f>
cmpl   $0x3,-0x8(%rbp)
je     132a <main+0x14a>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
lea    0xd33(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
call   10c0 <usage@plt>
movl   $0x65,-0x4(%rbp)
jmp    16bd <main+0x4dd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
mov    0x2ca2(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   10d0 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13bb <main+0x1db>
mov    0x2c3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xcbc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x65,-0x4(%rbp)
jmp    16bd <main+0x4dd>
mov    -0x34(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1100 <fstat@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    141d <main+0x23d>
mov    0x2bdb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2bbf(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xc5a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x65,-0x4(%rbp)
jmp    16bd <main+0x4dd>
mov    -0x38(%rbp),%edi
call   10a0 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1455 <main+0x275>
mov    0x2b83(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xc3d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x65,-0x4(%rbp)
jmp    16bd <main+0x4dd>
jmp    145a <main+0x27a>
mov    0x2b2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2b3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x70(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     14a3 <main+0x2c3>
mov    0x2b3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
jmp    14af <main+0x2cf>
mov    0x2b26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x70(%rbp),%edi
mov    -0x74(%rbp),%esi
lea    -0x50(%rbp),%rdx
call   1030 <fcntl@plt>
mov    %eax,%edx
mov    %edx,-0x30(%rbp)
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    %edx,%ecx
mov    %al,-0x75(%rbp)
jne    14ef <main+0x30f>
mov    0x2ad4(%rip),%rax
mov    (%rax),%rax
mov    0x2aba(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    14ff <main+0x31f>
jmp    1504 <main+0x324>
jmp    1482 <main+0x2a2>
cmpl   $0xffffffff,-0x30(%rbp)
jne    15a5 <main+0x3c5>
cmpl   $0x0,-0x2c(%rbp)
jne    1558 <main+0x378>
mov    0x2a91(%rip),%rax
mov    (%rax),%rax
mov    0x2a57(%rip),%rcx
cmp    (%rcx),%rax
je     154c <main+0x36c>
mov    0x2a77(%rip),%rax
mov    (%rax),%rax
mov    0x2a85(%rip),%rcx
cmp    (%rcx),%rax
jne    1558 <main+0x378>
movl   $0x64,-0x4(%rbp)
jmp    16bd <main+0x4dd>
mov    0x2a59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x2a3a(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xb1b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x65,-0x4(%rbp)
jmp    16bd <main+0x4dd>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0xa,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xb04(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <putenv@plt>
mov    0x29cd(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1653 <main+0x473>
mov    0x29b1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    0x298f(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rdx
mov    %rax,%rcx
lea    0xa24(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x65,-0x30(%rbp)
jmp    16af <main+0x4cf>
cmpl   $0x7f,-0x30(%rbp)
jne    16aa <main+0x4ca>
mov    0x294c(%rip),%rax
cmpq   $0x0,(%rax)
je     16aa <main+0x4ca>
mov    0x2943(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x292c(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rdx
lea    0xa42(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x65,-0x30(%rbp)
jmp    16af <main+0x4cf>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-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    $0x38,%rsp
mov    %rsi,%rbp
mov    %edi,%r15d
lea    0x8(%rsi),%rbx
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     1226 <main+0x46>
lea    0xdf8(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1260 <main+0x80>
mov    (%rbx),%rdi
lea    0xde7(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1260 <main+0x80>
cmp    $0x4,%r15d
jne    1275 <main+0x95>
mov    (%rbx),%rdi
lea    0xdd4(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     129e <main+0xbe>
mov    0x2d71(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xdb9(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x0(%rbp),%edi
jmp    1294 <main+0xb4>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   10c0 <usage@plt>
xor    %ebx,%ebx
jmp    1435 <main+0x255>
cmp    $0x3,%r15d
je     12a1 <main+0xc1>
mov    0x2d36(%rip),%rbx
mov    (%rbx),%edi
lea    0xdb1(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
call   10c0 <usage@plt>
jmp    1430 <main+0x250>
mov    %rbx,%rbp
mov    0x8(%rbp),%rbx
mov    0x10(%rbp),%rbp
mov    0x2d30(%rip),%rax
mov    0x2d41(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1402 <main+0x222>
mov    %eax,%r12d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1100 <fstat@plt>
cmp    $0xffffffff,%eax
je     1402 <main+0x222>
mov    0x8(%rsp),%edi
call   10a0 <S_ISREG@plt>
test   %eax,%eax
je     1446 <main+0x266>
mov    %rbp,0x18(%rsp)
mov    %rbx,0x10(%rsp)
mov    0x2c85(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x34(%rsp)
mov    0x2c90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2cab(%rip),%rbx
lea    0x20(%rsp),%rbp
mov    0x2c77(%rip),%r13
mov    0x2c60(%rip),%r14
mov    %rbx,%rax
cmp    $0x4,%r15d
jne    1350 <main+0x170>
mov    0x2c80(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %rbp,%rdx
call   1030 <fcntl@plt>
mov    0x0(%r13),%rdi
cmp    $0xffffffff,%eax
jne    136b <main+0x18b>
cmp    (%r14),%rdi
je     1340 <main+0x160>
cmp    $0xffffffff,%eax
je     1462 <main+0x282>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0xa(%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
lea    0xd3f(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <putenv@plt>
movq   $0x0,0x0(%r13)
mov    0x18(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <system@plt>
cmp    $0xffffffff,%eax
je     14a6 <main+0x2c6>
mov    %eax,%ebx
cmp    $0x7f,%eax
jne    14d3 <main+0x2f3>
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     14d3 <main+0x2f3>
mov    0x2bd5(%rip),%rax
mov    (%rax),%ebx
call   10f0 <strerror@plt>
lea    0xced(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    14ce <main+0x2ee>
mov    0x2baf(%rip),%rax
mov    (%rax),%ebp
mov    0x2b9e(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
lea    0xc43(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x65,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b6b(%rip),%rax
mov    (%rax),%edi
lea    0xc29(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1430 <main+0x250>
cmp    $0x4,%r15d
mov    0x10(%rsp),%rbp
jne    148a <main+0x2aa>
mov    0x2b0c(%rip),%rax
mov    $0x64,%ebx
cmp    (%rax),%rdi
je     1435 <main+0x255>
mov    0x2b43(%rip),%rax
cmp    (%rax),%rdi
je     1435 <main+0x255>
mov    0x2b27(%rip),%rax
mov    (%rax),%ebx
call   10f0 <strerror@plt>
lea    0xc0e(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
jmp    1426 <main+0x246>
mov    0x2b0b(%rip),%rax
mov    (%rax),%ebx
mov    0x0(%r13),%rdi
call   10f0 <strerror@plt>
lea    0xba5(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x65,%ebx
mov    %r12d,%edi
call   1060 <close@plt>
jmp    1435 <main+0x255>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.flock = type { i64, i64, i32, i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@stdout = global i32 0
@.str.2 = [3 x i8] c"-n\00"
@stderr = global i32 0
@.str.3 = [47 x i8] c"run-with-lockfile: `%s' is not a valid option\0A\00"
@.str.4 = [40 x i8] c"run-with-lockfile: incorrect arguments\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.5 = [27 x i8] c"run-with-lockfile: %s: %s\0A\00"
@errno = global i64 0
@.str.6 = [46 x i8] c"run-with-lockfile: %s: is not a regular file\0A\00"
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLKW = global i32 0
@F_SETLK = global i32 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@EACCES = global i64 0
@.str.7 = [37 x i8] c"run-with-lockfile: %s: set lock: %s\0A\00"
@.str.8 = [12 x i8] c"LOCKFILE=%s\00"
@.str.9 = [32 x i8] c"run-with-lockfile: /bin/sh: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.stat
%13 = alloca %struct.flock
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %33
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 0, %22
br i1 %23, label %30, label %24
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 0, %28
br i1 %29, label %30, label %33
30: ; preds = %24, %18
%31 = load i32, i32* @stdout
%32 = call i32 @usage(i32 %31)
store i32 0, i32* %3
br label %188
33: ; preds = %24, %2
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 4
br i1 %35, label %36, label %56
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @stderr
%49 = call i32 @usage(i32 %48)
store i32 101, i32* %3
br label %188
50: ; preds = %36
store i32 0, i32* %9
%51 = load i32, i32* %4
%52 = add nsw i32 %51, -1
store i32 %52, i32* %4
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i32 1
store i8** %54, i8*** %5
br label %55
55: ; preds = %50
br label %56
56: ; preds = %55, %33
%57 = load i32, i32* %4
%58 = icmp ne i32 %57, 3
br i1 %58, label %59, label %64
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32, i32* @stderr
%63 = call i32 @usage(i32 %62)
store i32 101, i32* %3
br label %188
64: ; preds = %56
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
store i8* %67, i8** %6
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 2
%70 = load i8*, i8** %69
store i8* %70, i8** %7
%71 = load i8*, i8** %6
%72 = load i32, i32* @O_RDWR
%73 = load i32, i32* @O_CREAT
%74 = or i32 %72, %73
%75 = call i32 @open(i8* %71, i32 %74, i32 438)
store i32 %75, i32* %11
%76 = icmp eq i32 -1, %75
br i1 %76, label %77, label %83
77: ; preds = %64
%78 = load i32, i32* @stderr
%79 = load i8*, i8** %6
%80 = load i64, i64* @errno
%81 = call i8* @strerror(i64 %80)
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %79, i8* %81)
store i32 101, i32* %3
br label %188
83: ; preds = %64
%84 = load i32, i32* %11
%85 = call i32 @fstat(i32 %84, %struct.stat* %12)
%86 = icmp eq i32 -1, %85
br i1 %86, label %87, label %93
87: ; preds = %83
%88 = load i32, i32* @stderr
%89 = load i8*, i8** %6
%90 = load i64, i64* @errno
%91 = call i8* @strerror(i64 %90)
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %89, i8* %91)
store i32 101, i32* %3
br label %188
93: ; preds = %83
%94 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%95 = load i32, i32* %94
%96 = call i32 @S_ISREG(i32 %95)
%97 = icmp ne i32 %96, 0
br i1 %97, label %102, label %98
98: ; preds = %93
%99 = load i32, i32* @stderr
%100 = load i8*, i8** %6
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %100)
store i32 101, i32* %3
br label %188
102: ; preds = %93
br label %103
103: ; preds = %102
%104 = load i32, i32* @F_WRLCK
%105 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 3
store i32 %104, i32* %105
%106 = load i32, i32* @SEEK_SET
%107 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 2
store i32 %106, i32* %107
%108 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 1
store i64 0, i64* %108
%109 = getelementptr inbounds %struct.flock, %struct.flock* %13, i32 0, i32 0
store i64 0, i64* %109
br label %110
110: ; preds = %128, %103
%111 = load i32, i32* %11
%112 = load i32, i32* %9
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %116
114: ; preds = %110
%115 = load i32, i32* @F_SETLKW
br label %118
116: ; preds = %110
%117 = load i32, i32* @F_SETLK
br label %118
118: ; preds = %116, %114
%119 = phi i32 [ %115, %114 ], [ %117, %116 ]
%120 = call i32 @fcntl(i32 %111, i32 %119, %struct.flock* %13)
store i32 %120, i32* %10
%121 = icmp eq i32 -1, %120
br i1 %121, label %122, label %126
122: ; preds = %118
%123 = load i64, i64* @errno
%124 = load i64, i64* @EINTR
%125 = icmp eq i64 %123, %124
br label %126
126: ; preds = %122, %118
%127 = phi i1 [ false, %118 ], [ %125, %122 ]
br i1 %127, label %128, label %129
128: ; preds = %126
br label %110
129: ; preds = %126
%130 = load i32, i32* %10
%131 = icmp eq i32 %130, -1
br i1 %131, label %132, label %150
132: ; preds = %129
%133 = load i32, i32* %9
%134 = icmp ne i32 %133, 0
br i1 %134, label %144, label %135
135: ; preds = %132
%136 = load i64, i64* @errno
%137 = load i64, i64* @EAGAIN
%138 = icmp eq i64 %136, %137
br i1 %138, label %143, label %139
139: ; preds = %135
%140 = load i64, i64* @errno
%141 = load i64, i64* @EACCES
%142 = icmp eq i64 %140, %141
br i1 %142, label %143, label %144
143: ; preds = %139, %135
store i32 100, i32* %3
br label %188
144: ; preds = %139, %132
%145 = load i32, i32* @stderr
%146 = load i8*, i8** %6
%147 = load i64, i64* @errno
%148 = call i8* @strerror(i64 %147)
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %146, i8* %148)
store i32 101, i32* %3
br label %188
150: ; preds = %129
%151 = load i8*, i8** %6
%152 = call i32 @strlen(i8* %151)
%153 = sext i32 %152 to i64
%154 = add i64 %153, 10
%155 = trunc i64 %154 to i32
%156 = call i8* @malloc(i32 %155)
store i8* %156, i8** %8
%157 = load i8*, i8** %8
%158 = load i8*, i8** %6
%159 = call i32 @sprintf(i8* %157, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %158)
%160 = load i8*, i8** %8
%161 = call i32 @putenv(i8* %160)
store i64 0, i64* @errno
%162 = load i8*, i8** %7
%163 = call i32 @system(i8* %162)
store i32 %163, i32* %10
%164 = load i32, i32* %10
%165 = icmp eq i32 %164, -1
br i1 %165, label %166, label %172
166: ; preds = %150
%167 = load i32, i32* @stderr
%168 = load i8*, i8** %7
%169 = load i64, i64* @errno
%170 = call i8* @strerror(i64 %169)
%171 = call i32 (i32, i8*, ...) @fprintf(i32 %167, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %168, i8* %170)
store i32 101, i32* %10
br label %184
172: ; preds = %150
%173 = load i32, i32* %10
%174 = icmp eq i32 %173, 127
br i1 %174, label %175, label %183
175: ; preds = %172
%176 = load i64, i64* @errno
%177 = icmp ne i64 %176, 0
br i1 %177, label %178, label %183
178: ; preds = %175
%179 = load i32, i32* @stderr
%180 = load i64, i64* @errno
%181 = call i8* @strerror(i64 %180)
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %179, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %181)
store i32 101, i32* %10
br label %183
183: ; preds = %178, %175, %172
br label %184
184: ; preds = %183, %166
%185 = load i32, i32* %11
%186 = call i32 @close(i32 %185)
%187 = load i32, i32* %10
store i32 %187, i32* %3
br label %188
188: ; preds = %184, %144, %143, %98, %87, %77, %59, %42, %30
%189 = load i32, i32* %3
ret i32 %189
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.flock = type { i64, i64, i32, i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@stdout = global i32 0
@.str.2 = [3 x i8] c"-n\00"
@stderr = global i32 0
@.str.3 = [47 x i8] c"run-with-lockfile: `%s' is not a valid option\0A\00"
@.str.4 = [40 x i8] c"run-with-lockfile: incorrect arguments\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str.5 = [27 x i8] c"run-with-lockfile: %s: %s\0A\00"
@errno = global i64 0
@.str.6 = [46 x i8] c"run-with-lockfile: %s: is not a regular file\0A\00"
@F_WRLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLKW = global i32 0
@F_SETLK = global i32 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@EACCES = global i64 0
@.str.7 = [37 x i8] c"run-with-lockfile: %s: set lock: %s\0A\00"
@.str.8 = [12 x i8] c"LOCKFILE=%s\00"
@.str.9 = [32 x i8] c"run-with-lockfile: /bin/sh: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.flock
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.flock* %4 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %20, label %10
10: ; preds = %2
%11 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i8*, i8** %7
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13, %10
%18 = load i32, i32* @stdout
%19 = tail call i32 @usage(i32 %18)
br label %124
20: ; preds = %13, %2
%21 = icmp eq i32 %0, 4
br i1 %21, label %22, label %32
22: ; preds = %20
%23 = load i8*, i8** %7
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %39, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %7
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stderr
%31 = tail call i32 @usage(i32 %30)
br label %124
32: ; preds = %20
%33 = icmp eq i32 %0, 3
br i1 %33, label %39, label %34
34: ; preds = %32
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @stderr
%38 = tail call i32 @usage(i32 %37)
br label %124
39: ; preds = %22, %32
%40 = phi i8** [ %1, %32 ], [ %7, %22 ]
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8*, i8** %40, i64 2
%44 = load i8*, i8** %43
%45 = load i32, i32* @O_RDWR
%46 = load i32, i32* @O_CREAT
%47 = or i32 %46, %45
%48 = tail call i32 @open(i8* %42, i32 %47, i32 438)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %39
%51 = load i32, i32* @stderr
%52 = load i64, i64* @errno
%53 = tail call i8* @strerror(i64 %52)
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %42, i8* %53)
br label %124
55: ; preds = %39
%56 = call i32 @fstat(i32 %48, %struct.stat* %3)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = load i64, i64* @errno
%61 = tail call i8* @strerror(i64 %60)
%62 = tail call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %42, i8* %61)
br label %124
63: ; preds = %55
%64 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%65 = load i32, i32* %64
%66 = tail call i32 @S_ISREG(i32 %65)
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32, i32* @stderr
%70 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %42)
br label %124
71: ; preds = %63
%72 = load i32, i32* @F_WRLCK
%73 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 3
store i32 %72, i32* %73
%74 = load i32, i32* @SEEK_SET
%75 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 2
store i32 %74, i32* %75
%76 = bitcast %struct.flock* %4 to i8*
br label %77
77: ; preds = %77, %71
%78 = load i32, i32* @F_SETLKW
%79 = load i32, i32* @F_SETLK
%80 = select i1 %21, i32 %79, i32 %78
%81 = call i32 @fcntl(i32 %48, i32 %80, %struct.flock* %4)
%82 = icmp eq i32 %81, -1
%83 = load i64, i64* @errno
%84 = load i64, i64* @EINTR
%85 = icmp eq i64 %83, %84
%86 = select i1 %82, i1 %85, i1 false
br i1 %86, label %77, label %87
87: ; preds = %77
br i1 %82, label %88, label %99
88: ; preds = %87
br i1 %21, label %89, label %95
89: ; preds = %88
%90 = load i64, i64* @EAGAIN
%91 = icmp eq i64 %83, %90
%92 = load i64, i64* @EACCES
%93 = icmp eq i64 %83, %92
%94 = select i1 %91, i1 true, i1 %93
br i1 %94, label %124, label %95
95: ; preds = %89, %88
%96 = load i32, i32* @stderr
%97 = call i8* @strerror(i64 %83)
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i8* %42, i8* %97)
br label %124
99: ; preds = %87
%100 = call i32 @strlen(i8* %42)
%101 = add i32 %100, 10
%102 = call i8* @malloc(i32 %101)
%103 = call i32 @sprintf(i8* dereferenceable(1) %102, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %42)
%104 = call i32 @putenv(i8* %102)
store i64 0, i64* @errno
%105 = call i32 @system(i8* %44)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %112
107: ; preds = %99
%108 = load i32, i32* @stderr
%109 = load i64, i64* @errno
%110 = call i8* @strerror(i64 %109)
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %44, i8* %110)
br label %121
112: ; preds = %99
%113 = icmp eq i32 %105, 127
%114 = load i64, i64* @errno
%115 = icmp ne i64 %114, 0
%116 = select i1 %113, i1 %115, i1 false
br i1 %116, label %117, label %121
117: ; preds = %112
%118 = load i32, i32* @stderr
%119 = call i8* @strerror(i64 %114)
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i8* %119)
br label %121
121: ; preds = %112, %117, %107
%122 = phi i32 [ 101, %107 ], [ 101, %117 ], [ %105, %112 ]
%123 = call i32 @close(i32 %48)
br label %124
124: ; preds = %89, %121, %95, %68, %58, %50, %34, %26, %17
%125 = phi i32 [ 0, %17 ], [ 101, %26 ], [ 101, %34 ], [ 101, %50 ], [ 101, %58 ], [ 101, %95 ], [ %122, %121 ], [ 101, %68 ], [ 100, %89 ]
ret i32 %125
}