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

/* Variables and functions */
int /*<<< orphan*/ LOCK_UN;
scalar_t__ errno;
int fileno(int /*<<< orphan*/ *);
int flock(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void file_unlock(FILE *fp) {
  errno = 0;
  int fd = fileno(fp);
  if (fd == -1) {
    perror("fileno");
    return;
  }
  if (flock(fd, LOCK_UN) == -1)
    perror("can't unlock file; flock");
}


x86 assembly (clang, -O0):
<file_unlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e9d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <fileno@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1171 <file_unlock+0x41>
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
jmp    1197 <file_unlock+0x67>
mov    -0xc(%rbp),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1050 <flock@plt>
cmp    $0xffffffff,%eax
jne    1197 <file_unlock+0x67>
lea    0xe75(%rip),%rdi
call   1040 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_unlock>:
push   %rax
mov    0x2ea8(%rip),%rax
movq   $0x0,(%rax)
call   1030 <fileno@plt>
cmp    $0xffffffff,%eax
je     1160 <file_unlock+0x30>
mov    0x2e88(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1050 <flock@plt>
cmp    $0xffffffff,%eax
je     116d <file_unlock+0x3d>
pop    %rax
ret
lea    0xe99(%rip),%rdi
pop    %rax
jmp    1040 <perror@plt>
lea    0xe93(%rip),%rdi
pop    %rax
jmp    1040 <perror@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [7 x i8] c"fileno\00"
@LOCK_UN = global i32 0
@.str.1 = [25 x i8] c"can't unlock file; flock\00"
define void @file_unlock(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
store i64 0, i64* @errno
%4 = load i32*, i32** %2
%5 = call i32 @fileno(i32* %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* @LOCK_UN
%13 = call i32 @flock(i32 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %8, %15, %10
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [7 x i8] c"fileno\00"
@LOCK_UN = global i32 0
@.str.1 = [25 x i8] c"can't unlock file; flock\00"
define void @file_unlock(i32* nocapture %0) {
store i64 0, i64* @errno
%2 = tail call i32 @fileno(i32* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i32, i32* @LOCK_UN
%6 = tail call i32 @flock(i32 %2, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %4, %1
%9 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %4 ]
%10 = tail call i32 @perror(i8* %9)
br label %11
11: ; preds = %8, %4
ret void
}