#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*/ LOG_WARNING;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *);
void make_pidfile(char *pidfile) {
  FILE *fpidfile;
  if (!pidfile)
    return;
  fpidfile = fopen(pidfile, "w");
  if (!fpidfile) {
    syslog(LOG_WARNING, "Error opening pidfile '%s': %m, pidfile not created",
           pidfile);
    return;
  }
  fprintf(fpidfile, "%d\n", getpid());
  fclose(fpidfile);
}


x86 assembly (clang, -O0):
<make_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116c <make_pidfile+0x1c>
jmp    11d3 <make_pidfile+0x83>
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <make_pidfile+0x59>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1060 <syslog@plt>
jmp    11d3 <make_pidfile+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
lea    0xe71(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_pidfile>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1197 <make_pidfile+0x47>
mov    %rdi,%rbx
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     119f <make_pidfile+0x4f>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeb8(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <syslog@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@LOG_WARNING = global i32 0
@.str.1 = [52 x i8] c"Error opening pidfile '%s': %m, pidfile not created\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @make_pidfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
br label %22
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = load i32, i32* @LOG_WARNING
%14 = load i8*, i8** %2
%15 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %22
16: ; preds = %7
%17 = load i32*, i32** %3
%18 = call i32 (...) @getpid()
%19 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %16, %12, %6
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@LOG_WARNING = global i32 0
@.str.1 = [52 x i8] c"Error opening pidfile '%s': %m, pidfile not created\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @make_pidfile(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i32* @fopen(i8* %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 %6, label %9
6: ; preds = %3
%7 = load i32, i32* @LOG_WARNING
%8 = tail call i32 @syslog(i32 %7, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
9: ; preds = %3
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 @fclose(i32* %4)
br label %13
13: ; preds = %1, %9, %6
ret void
}