#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;
};
typedef int /*<<< orphan*/ flock;

/* Variables and functions */
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ SEEK_SET;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
bool qfile_unlock(int fd) {
  struct flock lock;
  memset((void *)&lock, 0, sizeof(flock));
  lock.l_type = F_UNLCK;
  lock.l_whence = SEEK_SET;
  lock.l_start = 0;
  lock.l_len = 0;
  int ret = fcntl(fd, F_SETLK, &lock);
  if (ret == 0)
    return true;
  return false;
}


x86 assembly (clang, -O0):
<qfile_unlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <fcntl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1191 <qfile_unlock+0x71>
movl   $0x1,-0x4(%rbp)
jmp    1198 <qfile_unlock+0x78>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfile_unlock>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    0x2e9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <fcntl@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.flock = type { i64, i64, i32, i32 }
@F_UNLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
define i32 @qfile_unlock(i32 %0) {
%2 = alloca %struct.flock
%3 = bitcast %struct.flock* %2 to i8*
%4 = call i32 @memset(i8* %3, i32 0, i32 4)
%5 = load i32, i32* @F_UNLCK
%6 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 3
store i32 %5, i32* %6
%7 = load i32, i32* @SEEK_SET
%8 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 2
store i32 %7, i32* %8
%9 = bitcast %struct.flock* %2 to i8*
%10 = load i32, i32* @F_SETLK
%11 = call i32 @fcntl(i32 %0, i32 %10, %struct.flock* %2)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
ret i32 %13
}