#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ getpid();
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void writePidFile(void) {
  FILE *fp;
  const char *f = "/var/run/nginx_lunbo.pid";
  fp = fopen(f, "w+");
  if (!fp) {
    fprintf(stderr, "could not write pid file '%s': %s\n", f, strerror(errno));
    return;
  }
  fprintf(fp, "%d\n", (int)getpid());
  fclose(fp);
}


x86 assembly (clang, -O0):
<writePidFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c4 <writePidFile+0x74>
mov    0x2e57(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11f0 <writePidFile+0xa0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writePidFile>:
push   %rbx
lea    0xea8(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118f <writePidFile+0x3f>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xec5(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <fclose@plt>
mov    0x2e4a(%rip),%rax
movslq (%rax),%rbx
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe6e(%rip),%rsi
lea    0xe4b(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rcx
xor    %eax,%eax
pop    %rbx
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"/var/run/nginx_lunbo.pid\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"could not write pid file '%s': %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
define void @writePidFile() {
%1 = alloca i32*
%2 = alloca i8*
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = load i8*, i8** %2
%4 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %15, label %7
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i32*
%11 = load i8*, i8** %2
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %13)
br label %22
15: ; preds = %0
%16 = load i32*, i32** %1
%17 = call i64 (...) @getpid()
%18 = trunc i64 %17 to i32
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %15, %7
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"/var/run/nginx_lunbo.pid\00"
@.str.1 = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.2 = [35 x i8] c"could not write pid file '%s': %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
define void @writePidFile() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i32*
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %15
10: ; preds = %0
%11 = tail call i64 (...) @getpid()
%12 = trunc i64 %11 to i32
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = tail call i32 @fclose(i32* %1)
br label %15
15: ; preds = %10, %3
ret void
}