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

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ nxweb_log_error(char *, char const *, int /*<<< orphan*/);
int open(char const *, int, int);
int /*<<< orphan*/ strlen(char const *);
char *uint_to_decimal_string(int /*<<< orphan*/, char *, int);
scalar_t__ write(int, char const *, int /*<<< orphan*/);
void nxweb_create_pid_file(const char *pid_file, pid_t pid) {
  char buf[32];
  const char *pid_str = uint_to_decimal_string(pid, buf, sizeof(buf));
  int fd = open(pid_file, O_CREAT | O_TRUNC | O_WRONLY, 0666);
  if (fd == -1) {
    nxweb_log_error("can't create pid file %s [%d]", pid_file, errno);
    return;
  }
  if (write(fd, pid_str, strlen(pid_str)))
    ;
  close(fd);
}


x86 assembly (clang, -O0):
<nxweb_create_pid_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1060 <uint_to_decimal_string@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2e58(%rip),%rax
or     (%rax),%esi
mov    0x2e1f(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11d8 <nxweb_create_pid_file+0x78>
mov    -0x8(%rbp),%rsi
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
lea    0xe32(%rip),%rdi
call   1080 <nxweb_log_error@plt>
jmp    1214 <nxweb_create_pid_file+0xb4>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
je     120c <nxweb_create_pid_file+0xac>
jmp    120c <nxweb_create_pid_file+0xac>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nxweb_create_pid_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%eax
mov    %rdi,%r14
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x20,%edx
call   1060 <uint_to_decimal_string@plt>
mov    0x2e75(%rip),%rcx
mov    0x2e66(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %rax,%rbx
mov    0x2e28(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11cb <nxweb_create_pid_file+0x6b>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11e3 <nxweb_create_pid_file+0x83>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
lea    0xe25(%rip),%rdi
mov    %r14,%rsi
call   1080 <nxweb_log_error@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@.str = [30 x i8] c"can't create pid file %s [%d]\00"
@errno = global i32 0
define void @nxweb_create_pid_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%10 = call i8* @uint_to_decimal_string(i32 %8, i8* %9, i32 32)
store i8* %10, i8** %6
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = load i32, i32* @O_WRONLY
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %11, i32 %16, i32 438)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = load i32, i32* @errno
%23 = call i32 @nxweb_log_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22)
br label %35
24: ; preds = %2
%25 = load i32, i32* %7
%26 = load i8*, i8** %6
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
%29 = call i64 @write(i32 %25, i8* %26, i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
br label %32
32: ; preds = %31, %24
%33 = load i32, i32* %7
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %32, %20
ret void
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@.str = [30 x i8] c"can't create pid file %s [%d]\00"
@errno = global i32 0
define void @nxweb_create_pid_file(i8* %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i8* @uint_to_decimal_string(i32 %1, i8* %4, i32 32)
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %7, %6
%9 = load i32, i32* @O_WRONLY
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %0, i32 %10, i32 438)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = call i32 @nxweb_log_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %14)
br label %20
16: ; preds = %2
%17 = call i32 @strlen(i8* %5)
%18 = call i64 @write(i32 %11, i8* %5, i32 %17)
%19 = call i32 @close(i32 %11)
br label %20
20: ; preds = %16, %13
ret void
}