#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 {
  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;
int /*<<< orphan*/ F_RDLCK;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ errno;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int has_fcntl(int fd) {
  struct flock f;
  f.l_type = F_RDLCK;
  f.l_whence = SEEK_SET;
  f.l_start = 0;
  f.l_len = 0;
  return fcntl(fd, F_SETLK, &f) == -1 && (errno == EACCES || errno == EAGAIN);
}


x86 assembly (clang, -O0):
<has_fcntl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <fcntl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x21(%rbp)
jne    11a7 <has_fcntl+0x97>
mov    0x2e61(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e65(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x22(%rbp)
je     11a1 <has_fcntl+0x91>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_fcntl>:
sub    $0x18,%rsp
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1154 <has_fcntl+0x44>
add    $0x18,%rsp
ret
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%rax
sete   %cl
mov    0x2e46(%rip),%rdx
cmp    (%rdx),%rax
sete   %al
or     %cl,%al
movzbl %al,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.flock = type { i64, i64, i32, i32 }
@F_RDLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@errno = global i64 0
@EACCES = global i64 0
@EAGAIN = global i64 0
define i32 @has_fcntl(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.flock
store i32 %0, i32* %2
%4 = load i32, i32* @F_RDLCK
%5 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 3
store i32 %4, i32* %5
%6 = load i32, i32* @SEEK_SET
%7 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 2
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 1
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 0
store i64 0, i64* %9
%10 = load i32, i32* %2
%11 = load i32, i32* @F_SETLK
%12 = call i32 @fcntl(i32 %10, i32 %11, %struct.flock* %3)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %24
14: ; preds = %1
%15 = load i64, i64* @errno
%16 = load i64, i64* @EACCES
%17 = icmp eq i64 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp eq i64 %19, %20
br label %22
22: ; preds = %18, %14
%23 = phi i1 [ true, %14 ], [ %21, %18 ]
br label %24
24: ; preds = %22, %1
%25 = phi i1 [ false, %1 ], [ %23, %22 ]
%26 = zext i1 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i32, i32 }
@F_RDLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@errno = global i64 0
@EACCES = global i64 0
@EAGAIN = global i64 0
define i32 @has_fcntl(i32 %0) {
%2 = alloca %struct.flock
%3 = bitcast %struct.flock* %2 to i8*
%4 = load i32, i32* @F_RDLCK
%5 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 3
store i32 %4, i32* %5
%6 = load i32, i32* @SEEK_SET
%7 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 2
store i32 %6, i32* %7
%8 = bitcast %struct.flock* %2 to i8*
%9 = load i32, i32* @F_SETLK
%10 = call i32 @fcntl(i32 %0, i32 %9, %struct.flock* %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = load i64, i64* @errno
%14 = load i64, i64* @EACCES
%15 = icmp eq i64 %13, %14
%16 = load i64, i64* @EAGAIN
%17 = icmp eq i64 %13, %16
%18 = select i1 %15, i1 true, i1 %17
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %12, %1
%21 = phi i32 [ 0, %1 ], [ %19, %12 ]
ret i32 %21
}