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

/* Variables and functions */
int /*<<< orphan*/ F_GETLK;
int F_UNLCK;
scalar_t__ fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
pid_t lock_test(int fd, int type, off_t offset, int whence, off_t len) {
  struct flock lock;
  lock.l_type = type;
  lock.l_start = offset;
  lock.l_whence = whence;
  lock.l_len = len;
  if (fcntl(fd, F_GETLK, &lock) < 0) {
    fprintf(stderr, "fcntl error\n");
  }
  if (lock.l_type == F_UNLCK)
    ;
  { return 0; }
  return lock.l_pid;
}


x86 assembly (clang, -O0):
<lock_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    1189 <lock_test+0x69>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x40(%rbp),%eax
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%eax
jne    11a0 <lock_test+0x80>
jmp    11a0 <lock_test+0x80>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lock_test>:
sub    $0x28,%rsp
mov    %esi,0x8(%rsp)
mov    %rdx,0x20(%rsp)
mov    %ecx,0xc(%rsp)
mov    %r8,0x18(%rsp)
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1030 <fcntl@plt>
test   %rax,%rax
jns    1163 <lock_test+0x43>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.flock = type { i32, i32, i32, i8*, i8* }
@F_GETLK = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"fcntl error\0A\00"
@F_UNLCK = global i32 0
define i32 @lock_test(i32 %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca %struct.flock
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i32, i32* %7
%13 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i8*, i8** %8
%15 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 4
store i8* %14, i8** %15
%16 = load i32, i32* %9
%17 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i8*, i8** %10
%19 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 3
store i8* %18, i8** %19
%20 = load i32, i32* %6
%21 = load i32, i32* @F_GETLK
%22 = call i64 @fcntl(i32 %20, i32 %21, %struct.flock* %11)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %5
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %24, %5
%28 = getelementptr inbounds %struct.flock, %struct.flock* %11, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load i32, i32* @F_UNLCK
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %27
br label %33
33: ; preds = %32, %27
ret i32 0
}

LLVM IR (-O2):
%struct.flock = type { i32, i32, i32, i8*, i8* }
@F_GETLK = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"fcntl error\0A\00"
@F_UNLCK = global i32 0
define i32 @lock_test(i32 %0, i32 %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca %struct.flock
%7 = bitcast %struct.flock* %6 to i8*
%8 = getelementptr inbounds %struct.flock, %struct.flock* %6, i64 0, i32 0
store i32 %1, i32* %8
%9 = getelementptr inbounds %struct.flock, %struct.flock* %6, i64 0, i32 4
store i8* %2, i8** %9
%10 = getelementptr inbounds %struct.flock, %struct.flock* %6, i64 0, i32 1
store i32 %3, i32* %10
%11 = getelementptr inbounds %struct.flock, %struct.flock* %6, i64 0, i32 3
store i8* %4, i8** %11
%12 = load i32, i32* @F_GETLK
%13 = call i64 @fcntl(i32 %0, i32 %12, %struct.flock* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %5
ret i32 0
}