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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fatal(char *);
scalar_t__ ftruncate(int, long);
int /*<<< orphan*/ lseek(int, long, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, long);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
void updateChildPid(int fd, long childPid) {
  char buf[100];
  snprintf(buf, 100, "%ld\n", childPid);
  if (ftruncate(fd, 0L) != 0)
    fatal("Error truncating PID file");
  lseek(fd, 0L, SEEK_SET);
  if (write(fd, buf, strlen(buf)) != strlen(buf)) {
    fatal("Error updating PID file");
  }
  return;
}


x86 assembly (clang, -O0):
<updateChildPid>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x64,%esi
lea    0xe7a(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <ftruncate@plt>
cmp    $0x0,%rax
je     11ad <updateChildPid+0x4d>
lea    0xe5d(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x4(%rbp),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <lseek@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
cmp    %rcx,%rax
je     1223 <updateChildPid+0xc3>
lea    0xe01(%rip),%rdi
call   1080 <fatal@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updateChildPid>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rcx
mov    %edi,%ebx
lea    0xe8d(%rip),%rdx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1050 <snprintf@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <ftruncate@plt>
test   %rax,%rax
je     119a <updateChildPid+0x3a>
lea    0xe70(%rip),%rdi
call   1080 <fatal@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
je     11e0 <updateChildPid+0x80>
lea    0xe44(%rip),%rdi
call   1080 <fatal@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%ld\0A\00"
@.str.1 = [26 x i8] c"Error truncating PID file\00"
@SEEK_SET = global i32 0
@.str.2 = [24 x i8] c"Error updating PID file\00"
define void @updateChildPid(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca [100 x i8]
store i32 %0, i32* %3
store i64 %1, i64* %4
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%7 = load i64, i64* %4
%8 = call i32 @snprintf(i8* %6, i32 100, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = load i32, i32* %3
%10 = call i64 @ftruncate(i32 %9, i64 0)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %3
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @lseek(i32 %15, i64 0, i32 %16)
%18 = load i32, i32* %3
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = call i64 @write(i32 %18, i8* %19, i64 %21)
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%24 = call i64 @strlen(i8* %23)
%25 = icmp ne i64 %22, %24
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = call i32 @fatal(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%ld\0A\00"
@.str.1 = [26 x i8] c"Error truncating PID file\00"
@SEEK_SET = global i32 0
@.str.2 = [24 x i8] c"Error updating PID file\00"
define void @updateChildPid(i32 %0, i64 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 100, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %1)
%6 = call i64 @ftruncate(i32 %0, i64 0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = call i32 @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i32, i32* @SEEK_SET
%12 = call i32 @lseek(i32 %0, i64 0, i32 %11)
%13 = call i64 @strlen(i8* %4)
%14 = call i64 @write(i32 %0, i8* %4, i64 %13)
%15 = call i64 @strlen(i8* %4)
%16 = icmp eq i64 %14, %15
br i1 %16, label %19, label %17
17: ; preds = %10
%18 = call i32 @fatal(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %10
ret void
}