#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*/ pidbuf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int getpid();
int /*<<< orphan*/ isns_fatal(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
void __update_pidfile(int fd) {
  char pidbuf[32];
  snprintf(pidbuf, sizeof(pidbuf), "%u\n", getpid());
  if (write(fd, pidbuf, strlen(pidbuf)) < 0)
    isns_fatal("Error writing pid file: %m\n");
  close(fd);
}


x86 assembly (clang, -O0):
<__update_pidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%ecx
mov    $0x20,%esi
lea    0xe74(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11cc <__update_pidfile+0x6c>
lea    0xe3d(%rip),%rdi
call   1030 <isns_fatal@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__update_pidfile>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe8a(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %eax,%ecx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    11ad <__update_pidfile+0x4d>
lea    0xe5c(%rip),%rdi
call   1030 <isns_fatal@plt>
mov    %ebp,%edi
call   1080 <close@plt>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%u\0A\00"
@.str.1 = [28 x i8] c"Error writing pid file: %m\0A\00"
define void @__update_pidfile(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
store i32 %0, i32* %2
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 (...) @getpid()
%6 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %2
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = call i64 @write(i32 %7, i8* %8, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @isns_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = load i32, i32* %2
%17 = call i32 @close(i32 %16)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%u\0A\00"
@.str.1 = [28 x i8] c"Error writing pid file: %m\0A\00"
define void @__update_pidfile(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @getpid()
%5 = call i32 @snprintf(i8* %3, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 @strlen(i8* %3)
%7 = call i64 @write(i32 %0, i8* %3, i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @isns_fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = call i32 @close(i32 %0)
ret void
}