#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ pm_asprintf(char const **const, char *, int /*<<< orphan*/,
                               int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ waitpid(scalar_t__ const, int *const, int const);
void pm_waitpid(pid_t const pid, int *const statusP, int const options,
                pid_t *const exitedPidP, const char **const errorP) {
  pid_t rc;
  rc = waitpid(pid, statusP, options);
  if (rc == (pid_t)-1) {
    pm_asprintf(errorP,
                "Failed to wait for process exit.  "
                "waitpid() errno = %d (%s)",
                errno, strerror(errno));
  } else {
    *exitedPidP = rc;
    *errorP = NULL;
  }
}


x86 assembly (clang, -O0):
<pm_waitpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <waitpid@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    11a6 <pm_waitpid+0x76>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
lea    0xe64(%rip),%rsi
call   1030 <pm_asprintf@plt>
jmp    11bc <pm_waitpid+0x8c>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_waitpid>:
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbx
call   1040 <waitpid@plt>
cmp    $0xffffffffffffffff,%rax
je     1157 <pm_waitpid+0x27>
mov    %rax,(%rbx)
movq   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e82(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xe92(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
mov    %eax,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <pm_asprintf@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"Failed to wait for process exit. waitpid() errno = %d (%s)\00"
@errno = global i32 0
define void @pm_waitpid(i64 %0, i32* %1, i32 %2, i64* %3, i8** %4) {
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i8**
%11 = alloca i64
store i64 %0, i64* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i64* %3, i64** %9
store i8** %4, i8*** %10
%12 = load i64, i64* %6
%13 = load i32*, i32** %7
%14 = load i32, i32* %8
%15 = call i64 @waitpid(i64 %12, i32* %13, i32 %14)
store i64 %15, i64* %11
%16 = load i64, i64* %11
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %5
%19 = load i8**, i8*** %10
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @pm_asprintf(i8** %19, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %22)
br label %28
24: ; preds = %5
%25 = load i64, i64* %11
%26 = load i64*, i64** %9
store i64 %25, i64* %26
%27 = load i8**, i8*** %10
store i8* null, i8** %27
br label %28
28: ; preds = %24, %18
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"Failed to wait for process exit. waitpid() errno = %d (%s)\00"
@errno = global i32 0
define void @pm_waitpid(i64 %0, i32* %1, i32 %2, i64* nocapture writeonly %3, i8** %4) {
%6 = tail call i64 @waitpid(i64 %0, i32* %1, i32 %2)
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 @pm_asprintf(i8** %4, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
br label %13
12: ; preds = %5
store i64 %6, i64* %3
store i8* null, i8** %4
br label %13
13: ; preds = %12, %8
ret void
}