#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*/ LOCK_UN;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ flock(int, int /*<<< orphan*/);
int /*<<< orphan*/ logger(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
void _unlock(int fd, char *lockfile) {
  if (fd < 0)
    return;
  unlink(lockfile);
  if (flock(fd, LOCK_UN))
    logger(-1, errno, "Error in flock(LOCK_UN)");
  close(fd);
}


x86 assembly (clang, -O0):
<_unlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    115e <_unlock+0x1e>
jmp    11a4 <_unlock+0x64>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1060 <flock@plt>
cmp    $0x0,%rax
je     119c <_unlock+0x5c>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
lea    0xe69(%rip),%rdx
call   1050 <logger@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_unlock>:
test   %edi,%edi
js     1186 <_unlock+0x46>
push   %rbx
mov    %edi,%ebx
mov    %rsi,%rdi
call   1030 <unlink@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <flock@plt>
test   %rax,%rax
je     117e <_unlock+0x3e>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdx
mov    $0xffffffff,%edi
call   1050 <logger@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1040 <close@plt>
ret

LLVM IR (-O0):
@LOCK_UN = global i32 0
@errno = global i32 0
@.str = [24 x i8] c"Error in flock(LOCK_UN)\00"
define void @_unlock(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %2
br label %21
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = call i32 @unlink(i8* %9)
%11 = load i32, i32* %3
%12 = load i32, i32* @LOCK_UN
%13 = call i64 @flock(i32 %11, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* @errno
%17 = call i32 @logger(i32 -1, i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %8
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %18, %7
ret void
}

LLVM IR (-O2):
@LOCK_UN = global i32 0
@errno = global i32 0
@.str = [24 x i8] c"Error in flock(LOCK_UN)\00"
define void @_unlock(i32 %0, i8* nocapture %1) {
%3 = icmp slt i32 %0, 0
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = tail call i32 @unlink(i8* %1)
%6 = load i32, i32* @LOCK_UN
%7 = tail call i64 @flock(i32 %0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = load i32, i32* @errno
%11 = tail call i32 @logger(i32 -1, i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %4
%13 = tail call i32 @close(i32 %0)
br label %14
14: ; preds = %2, %12
ret void
}