#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ LOCK_UN;
int close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int flock(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void close_lockfile(int fd) {
  if (flock(fd, LOCK_UN) == -1) {
    perror("Failed to unlock file");
    exit(EXIT_FAILURE);
  }
  if (close(fd) == -1) {
    perror("Closing descriptor on lock file failed");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<close_lockfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1050 <flock@plt>
cmp    $0xffffffff,%eax
jne    117f <close_lockfile+0x3f>
lea    0xe94(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    11aa <close_lockfile+0x6a>
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_lockfile>:
push   %rbx
mov    %edi,%ebx
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
call   1050 <flock@plt>
cmp    $0xffffffff,%eax
je     1164 <close_lockfile+0x24>
mov    %ebx,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
je     116d <close_lockfile+0x2d>
pop    %rbx
ret
lea    0xe95(%rip),%rdi
jmp    1174 <close_lockfile+0x34>
lea    0xea2(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@LOCK_UN = global i32 0
@.str = [22 x i8] c"Failed to unlock file\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"Closing descriptor on lock file failed\00"
define void @close_lockfile(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @LOCK_UN
%5 = call i32 @flock(i32 %3, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
ret void
}

LLVM IR (-O2):
@LOCK_UN = global i32 0
@.str = [22 x i8] c"Failed to unlock file\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"Closing descriptor on lock file failed\00"
define void @close_lockfile(i32 %0) {
%2 = load i32, i32* @LOCK_UN
%3 = tail call i32 @flock(i32 %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = tail call i32 @close(i32 %0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %9
ret void
}