#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 */
int EBADF;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ SEEK_SET;
int errno;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int c_unlock(int fd) {
  struct flock fl;
  if (fd < 0) {
    return EBADF;
  }
  fl.l_type = F_UNLCK;
  fl.l_whence = SEEK_SET;
  fl.l_start = 0;
  fl.l_len = 0;
  if (fcntl(fd, F_SETLK, &fl) == -1) {
    return errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<c_unlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1136 <c_unlock+0x26>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <c_unlock+0x84>
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    118d <c_unlock+0x7d>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <c_unlock+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_unlock>:
sub    $0x18,%rsp
test   %edi,%edi
js     115c <c_unlock+0x4c>
mov    0x2ec1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <fcntl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1165 <c_unlock+0x55>
mov    0x2e76(%rip),%rax
jmp    1163 <c_unlock+0x53>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.flock = type { i64, i64, i32, i32 }
@EBADF = global i32 0
@F_UNLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@errno = global i32 0
define i32 @c_unlock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.flock
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32, i32* @EBADF
store i32 %8, i32* %2
br label %23
9: ; preds = %1
%10 = load i32, i32* @F_UNLCK
%11 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 3
store i32 %10, i32* %11
%12 = load i32, i32* @SEEK_SET
%13 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 2
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 1
store i64 0, i64* %14
%15 = getelementptr inbounds %struct.flock, %struct.flock* %4, i32 0, i32 0
store i64 0, i64* %15
%16 = load i32, i32* %3
%17 = load i32, i32* @F_SETLK
%18 = call i32 @fcntl(i32 %16, i32 %17, %struct.flock* %4)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = load i32, i32* @errno
store i32 %21, i32* %2
br label %23
22: ; preds = %9
store i32 0, i32* %2
br label %23
23: ; preds = %22, %20, %7
%24 = load i32, i32* %2
ret i32 %24
}

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