#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 {
  short l_type;
  int /*<<< orphan*/ l_whence;
  void *l_len;
  void *l_start;
};
typedef void *off_t;

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ EAGAIN;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ errno;
int /*<<< orphan*/ error(char *);
int fcntl(int, int /*<<< orphan*/, struct flock *);
char flockRangeNB(int fd, off_t start, off_t len, short int type) {
  struct flock l;
  l.l_start = start;
  l.l_len = len;
  l.l_type = type;
  l.l_whence = SEEK_SET;
  if (fcntl(fd, F_SETLK, &l) == -1) {
    if (errno == EAGAIN || errno == EACCES)
      return 0;
    error("unable to lock range");
  }
  return 1;
}


x86 assembly (clang, -O0):
<flockRangeNB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cx,%ax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1a(%rbp),%ax
mov    %ax,-0x38(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11c5 <flockRangeNB+0xa5>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
je     11b0 <flockRangeNB+0x90>
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
jne    11b9 <flockRangeNB+0x99>
movb   $0x0,-0x1(%rbp)
jmp    11c9 <flockRangeNB+0xa9>
lea    0xe40(%rip),%rdi
call   1040 <error@plt>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flockRangeNB>:
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdx,0x8(%rsp)
mov    %cx,(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0xffffffff,%ecx
je     115e <flockRangeNB+0x3e>
add    $0x18,%rsp
ret
mov    0x2e6b(%rip),%rax
mov    (%rax),%rcx
mov    0x2e49(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     1159 <flockRangeNB+0x39>
mov    0x2e63(%rip),%rdx
cmp    (%rdx),%rcx
je     1159 <flockRangeNB+0x39>
lea    0xe77(%rip),%rdi
call   1040 <error@plt>
mov    $0x1,%al
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.flock = type { i16, i32, i8*, i8* }
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EACCES = global i64 0
@.str = [21 x i8] c"unable to lock range\00"
define signext i8 @flockRangeNB(i32 %0, i8* %1, i8* %2, i16 signext %3) {
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i16
%10 = alloca %struct.flock
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i16 %3, i16* %9
%11 = load i8*, i8** %7
%12 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 3
store i8* %11, i8** %12
%13 = load i8*, i8** %8
%14 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 2
store i8* %13, i8** %14
%15 = load i16, i16* %9
%16 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 0
store i16 %15, i16* %16
%17 = load i32, i32* @SEEK_SET
%18 = getelementptr inbounds %struct.flock, %struct.flock* %10, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* %6
%20 = load i32, i32* @F_SETLK
%21 = call i32 @fcntl(i32 %19, i32 %20, %struct.flock* %10)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %34
23: ; preds = %4
%24 = load i64, i64* @errno
%25 = load i64, i64* @EAGAIN
%26 = icmp eq i64 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i64, i64* @errno
%29 = load i64, i64* @EACCES
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27, %23
store i8 0, i8* %5
br label %35
32: ; preds = %27
%33 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %4
store i8 1, i8* %5
br label %35
35: ; preds = %34, %31
%36 = load i8, i8* %5
ret i8 %36
}

LLVM IR (-O2):
%struct.flock = type { i16, i32, i8*, i8* }
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EACCES = global i64 0
@.str = [21 x i8] c"unable to lock range\00"
define signext i8 @flockRangeNB(i32 %0, i8* %1, i8* %2, i16 signext %3) {
%5 = alloca %struct.flock
%6 = bitcast %struct.flock* %5 to i8*
%7 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 3
store i8* %1, i8** %7
%8 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 2
store i8* %2, i8** %8
%9 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 0
store i16 %3, i16* %9
%10 = load i32, i32* @SEEK_SET
%11 = getelementptr inbounds %struct.flock, %struct.flock* %5, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @F_SETLK
%13 = call i32 @fcntl(i32 %0, i32 %12, %struct.flock* %5)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %24
15: ; preds = %4
%16 = load i64, i64* @errno
%17 = load i64, i64* @EAGAIN
%18 = icmp eq i64 %16, %17
%19 = load i64, i64* @EACCES
%20 = icmp eq i64 %16, %19
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %4, %22, %15
%25 = phi i8 [ 0, %15 ], [ 1, %22 ], [ 1, %4 ]
ret i8 %25
}