#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 /*<<< orphan*/ l_pid;
  int /*<<< orphan*/ member_4;
  int /*<<< orphan*/ member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ F_UNLCK;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ perror(char *);
void kvp_release_lock(int fd) {
  struct flock fl = {F_UNLCK, SEEK_SET, 0, 0, 0};
  fl.l_pid = getpid();
  if (fcntl(fd, F_SETLK, &fl) == -1) {
    perror("fcntl unlock");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<kvp_release_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11bd <kvp_release_lock+0x7d>
lea    0xe52(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvp_release_lock>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0x8(%rsp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1187 <kvp_release_lock+0x47>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.flock = type { i32, i32, i32, i32, i32, i32 }
@F_UNLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [13 x i8] c"fcntl unlock\00"
define void @kvp_release_lock(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.flock
store i32 %0, i32* %2
%4 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 0
%5 = load i32, i32* @F_UNLCK
store i32 %5, i32* %4
%6 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 1
%7 = load i32, i32* @SEEK_SET
store i32 %7, i32* %6
%8 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 2
store i32 0, i32* %8
%9 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 3
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 4
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 5
store i32 0, i32* %11
%12 = call i32 (...) @getpid()
%13 = getelementptr inbounds %struct.flock, %struct.flock* %3, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %2
%15 = load i32, i32* @F_SETLK
%16 = call i32 @fcntl(i32 %14, i32 %15, %struct.flock* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %1
ret void
}

LLVM IR (-O2):
%struct.flock = type { i32, i32, i32, i32, i32, i32 }
@F_UNLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str = [13 x i8] c"fcntl unlock\00"
define void @kvp_release_lock(i32 %0) {
%2 = alloca %struct.flock
%3 = bitcast %struct.flock* %2 to i8*
%4 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 0
%5 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 1
%6 = load i32, i32* @SEEK_SET
store i32 %6, i32* %5
%7 = getelementptr inbounds %struct.flock, %struct.flock* %2, i64 0, i32 2
%8 = bitcast i32* %7 to i8*
%9 = tail call i32 (...) @getpid()
store i32 %9, i32* %4
%10 = load i32, i32* @F_SETLK
%11 = call i32 @fcntl(i32 %0, i32 %10, %struct.flock* %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %1
ret void
}