#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int showLocksInRange(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int fd;
  int cnt;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s FILENAME\n", argv[0]);
    return 1;
  }
  fd = open(argv[1], O_RDWR, 0);
  if (fd < 0) {
    fprintf(stderr, "%s: cannot open %s\n", argv[0], argv[1]);
    return 1;
  }
  cnt = showLocksInRange(fd, 0, 2147483647);
  if (cnt == 0)
    printf("no locks\n");
  close(fd);
  return 0;
}


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   $0x2,-0x8(%rbp)
je     119a <main+0x4a>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1228 <main+0xd8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11f1 <main+0xa1>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1228 <main+0xd8>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
mov    $0x7fffffff,%edx
call   1030 <showLocksInRange@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1219 <main+0xc9>
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    119e <main+0x4e>
mov    0x8(%rbx),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11ba <main+0x6a>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x7fffffff,%edx
call   1040 <showLocksInRange@plt>
test   %eax,%eax
jne    1195 <main+0x45>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11dd <main+0x8d>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe4f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d8 <main+0x88>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xe43(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s FILENAME\0A\00"
@O_RDWR = global i32 0
@.str.1 = [20 x i8] c"%s: cannot open %s\0A\00"
@.str.2 = [10 x i8] c"no locks\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %43
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %31)
store i32 1, i32* %3
br label %43
33: ; preds = %16
%34 = load i32, i32* %6
%35 = call i32 @showLocksInRange(i32 %34, i32 0, i32 2147483647)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %40, %24, %10
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s FILENAME\0A\00"
@O_RDWR = global i32 0
@.str.1 = [20 x i8] c"%s: cannot open %s\0A\00"
@str = [9 x i8] c"no locks\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %26
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = load i8*, i8** %9
%18 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
br label %26
19: ; preds = %8
%20 = tail call i32 @showLocksInRange(i32 %12, i32 0, i32 2147483647)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = tail call i32 @close(i32 %12)
br label %26
26: ; preds = %24, %14, %4
%27 = phi i32 [ 1, %4 ], [ 1, %14 ], [ 0, %24 ]
ret i32 %27
}