#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*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int /*<<< orphan*/ printf(char *);
void create_pid_file(void) {
  if (0 == access("irid.pid", R_OK)) {
    printf("Irid have running\n");
    exit(1);
  }
  FILE *fp = fopen("irid.pid", "w");
  if (NULL == fp) {
    printf("create pid file fail\n");
    exit(1);
  }
  fprintf(fp, "%d", getpid());
  fclose(fp);
}


x86 assembly (clang, -O0):
<create_pid_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11b1 <create_pid_file+0x41>
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe48(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    11ea <create_pid_file+0x7a>
lea    0xe43(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
lea    0xe2e(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_pid_file>:
push   %rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe7f(%rip),%rdi
call   1070 <access@plt>
test   %rax,%rax
je     11c7 <create_pid_file+0x57>
lea    0xe6e(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d0 <create_pid_file+0x60>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe57(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <fclose@plt>
lea    0xe55(%rip),%rdi
jmp    11d7 <create_pid_file+0x67>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"irid.pid\00"
@R_OK = global i32 0
@.str.1 = [19 x i8] c"Irid have running\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [22 x i8] c"create pid file fail\0A\00"
@.str.4 = [3 x i8] c"%d\00"
define void @create_pid_file() {
%1 = alloca i32*
%2 = load i32, i32* @R_OK
%3 = call i64 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i64 0, %3
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %1
%10 = load i32*, i32** %1
%11 = icmp eq i32* null, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = load i32*, i32** %1
%17 = call i32 (...) @getpid()
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = load i32*, i32** %1
%20 = call i32 @fclose(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"irid.pid\00"
@R_OK = global i32 0
@.str.2 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@str = [21 x i8] c"create pid file fail\00"
@str.5 = [18 x i8] c"Irid have running\00"
define void @create_pid_file() {
%1 = load i32, i32* @R_OK
%2 = tail call i64 @access(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = tail call i32 @fclose(i32* %8)
ret void
}