#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*/ F_UNLCK;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int /*<<< orphan*/ lockf(int, int /*<<< orphan*/, int /*<<< orphan*/);
void pidfile_write_release(int pid_fd) {
  FILE *out;
  if (pid_fd < 0)
    return;
  if ((out = fdopen(pid_fd, "w")) != NULL) {
    fprintf(out, "%d\n", getpid());
    fclose(out);
  }
  lockf(pid_fd, F_UNLCK, 0);
  close(pid_fd);
}


x86 assembly (clang, -O0):
<pidfile_write_release>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    117a <pidfile_write_release+0x1a>
jmp    11dc <pidfile_write_release+0x7c>
mov    -0x4(%rbp),%edi
lea    0xe7c(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11c1 <pidfile_write_release+0x61>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
lea    0xe4f(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <lockf@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pidfile_write_release>:
test   %edi,%edi
js     11be <pidfile_write_release+0x5e>
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xe8f(%rip),%rsi
call   1080 <fdopen@plt>
test   %rax,%rax
je     119e <pidfile_write_release+0x3e>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <lockf@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <close@plt>
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@F_UNLCK = global i32 0
define void @pidfile_write_release(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1
br label %23
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i32* @fdopen(i32 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = call i32 (...) @getpid()
%14 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32*, i32** %3
%16 = call i32 @fclose(i32* %15)
br label %17
17: ; preds = %11, %7
%18 = load i32, i32* %2
%19 = load i32, i32* @F_UNLCK
%20 = call i32 @lockf(i32 %18, i32 %19, i32 0)
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
br label %23
23: ; preds = %17, %6
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@F_UNLCK = global i32 0
define void @pidfile_write_release(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32* @fdopen(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @fclose(i32* %4)
br label %10
10: ; preds = %6, %3
%11 = load i32, i32* @F_UNLCK
%12 = tail call i32 @lockf(i32 %0, i32 %11, i32 0)
%13 = tail call i32 @close(i32 %0)
br label %14
14: ; preds = %1, %10
ret void
}