#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*/ __ploop_err(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ flock(int, int /*<<< orphan*/);
void ploop_unlock(int *lckfd) {
  if (*lckfd != -1) {
    if (flock(*lckfd, LOCK_UN))
      __ploop_err(errno, "Can't flock(%d, LOCK_UN)", *lckfd);
    close(*lckfd);
    *lckfd = -1;
  }
}


x86 assembly (clang, -O0):
<ploop_unlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0xffffffff,(%rax)
je     1197 <ploop_unlock+0x67>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1040 <flock@plt>
cmp    $0x0,%rax
je     1182 <ploop_unlock+0x52>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xe83(%rip),%rsi
call   1050 <__ploop_err@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <close@plt>
mov    -0x8(%rbp),%rax
movl   $0xffffffff,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ploop_unlock>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%edi
cmp    $0xffffffff,%edi
je     1172 <ploop_unlock+0x42>
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
call   1040 <flock@plt>
test   %rax,%rax
je     1165 <ploop_unlock+0x35>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%edx
lea    0xea0(%rip),%rsi
call   1050 <__ploop_err@plt>
mov    (%rbx),%edi
call   1030 <close@plt>
movl   $0xffffffff,(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
@LOCK_UN = global i32 0
@errno = global i32 0
@.str = [25 x i8] c"Can't flock(%d, LOCK_UN)\00"
define void @ploop_unlock(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = icmp eq i32 %2, -1
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = load i32, i32* @LOCK_UN
%6 = tail call i64 @flock(i32 %2, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @errno
%10 = load i32, i32* %0
%11 = tail call i32 @__ploop_err(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %4
%13 = load i32, i32* %0
%14 = tail call i32 @close(i32 %13)
store i32 -1, i32* %0
br label %15
15: ; preds = %12, %1
ret void
}