#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 */

/* Variables and functions */
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ dolock(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  if (argc < 3) {
    (void)write(2, "Usage: lockf file exe...\n",
                sizeof("Usage: lockf file exe...\n") - 1);
    exit(0);
  }
  fd = open(argv[1], O_RDWR);
  if (fd > -1) {
    if (fcntl(fd, F_SETFD, 0) == 0)
      dolock(fd);
  }
  execvp(argv[2], argv + 2);
  exit(127);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119d <main+0x3d>
mov    $0x2,%edi
lea    0xe74(%rip),%rsi
mov    $0x19,%edx
call   1050 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jle    11ea <main+0x8a>
mov    -0x14(%rbp),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
cmp    $0x0,%rax
jne    11e5 <main+0x85>
mov    -0x14(%rbp),%edi
call   1030 <dolock@plt>
jmp    11ea <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1070 <execvp@plt>
mov    $0x7f,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     1185 <main+0x25>
lea    0xe91(%rip),%rsi
mov    $0x2,%edi
mov    $0x19,%edx
call   1050 <write@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11be <main+0x5e>
mov    %eax,%ebp
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
test   %rax,%rax
jne    11be <main+0x5e>
mov    %ebp,%edi
call   1030 <dolock@plt>
mov    0x10(%rbx),%rdi
add    $0x10,%rbx
mov    %rbx,%rsi
call   1070 <execvp@plt>
mov    $0x7f,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Usage: lockf file exe...\0A\00"
@O_RDWR = global i32 0
@F_SETFD = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @write(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 25)
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, -1
br i1 %19, label %20, label %29
20: ; preds = %12
%21 = load i32, i32* %6
%22 = load i32, i32* @F_SETFD
%23 = call i64 @fcntl(i32 %21, i32 %22, i32 0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* %6
%27 = call i32 @dolock(i32 %26)
br label %28
28: ; preds = %25, %20
br label %29
29: ; preds = %28, %12
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = call i32 @execvp(i8* %32, i8** %34)
%36 = call i32 @exit(i32 127)
unreachable
}

LLVM IR (-O2):
@.str = [26 x i8] c"Usage: lockf file exe...\0A\00"
@O_RDWR = global i32 0
@F_SETFD = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 25)
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %7
%14 = load i32, i32* @F_SETFD
%15 = tail call i64 @fcntl(i32 %11, i32 %14, i32 0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @dolock(i32 %11)
br label %19
19: ; preds = %13, %17, %7
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @execvp(i8* %21, i8** %20)
%23 = tail call i32 @exit(i32 127)
unreachable
}