#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 */
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WTERMSIG(int);
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *, int);
int /*<<< orphan*/ warnx(char *, int, scalar_t__);
void dowait(int pid) {
  int status;
  if (waitpid(pid, &status, 0) < 0) {
    warn("waitpid for %d", pid);
  } else if (WIFSIGNALED(status)) {
    warnx("pid %d: signal %d", pid, WTERMSIG(status));
  } else if (WEXITSTATUS(status) != 0) {
    warnx("pid %d: exit %d", pid, WEXITSTATUS(status));
  }
}


x86 assembly (clang, -O0):
<dowait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0x0,%rax
jge    1197 <dowait+0x37>
mov    -0x4(%rbp),%esi
lea    0xe73(%rip),%rdi
call   1030 <warn@plt>
jmp    120a <dowait+0xaa>
mov    -0x8(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11ce <dowait+0x6e>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    -0xc(%rbp),%esi
mov    %rax,%rdx
lea    0xe4b(%rip),%rdi
call   1040 <warnx@plt>
jmp    1205 <dowait+0xa5>
mov    -0x8(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1200 <dowait+0xa0>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rdx
lea    0xe26(%rip),%rdi
call   1040 <warnx@plt>
jmp    1205 <dowait+0xa5>
jmp    120a <dowait+0xaa>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dowait>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
test   %rax,%rax
js     1198 <dowait+0x38>
mov    0xc(%rsp),%edi
call   1050 <WIFSIGNALED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     11a8 <dowait+0x48>
call   1060 <WTERMSIG@plt>
lea    0xe79(%rip),%rdi
jmp    11c2 <dowait+0x62>
lea    0xe61(%rip),%rdi
mov    %ebx,%esi
call   1030 <warn@plt>
jmp    11cc <dowait+0x6c>
call   1070 <WEXITSTATUS@plt>
test   %rax,%rax
je     11cc <dowait+0x6c>
mov    0xc(%rsp),%edi
call   1070 <WEXITSTATUS@plt>
lea    0xe5f(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1040 <warnx@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"waitpid for %d\00"
@.str.1 = [18 x i8] c"pid %d: signal %d\00"
@.str.2 = [16 x i8] c"pid %d: exit %d\00"
define void @dowait(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i64 @waitpid(i32 %4, i32* %3, i32 0)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %30
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i64 @WIFSIGNALED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i64 @WTERMSIG(i32 %16)
%18 = call i32 @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %15, i64 %17)
br label %29
19: ; preds = %10
%20 = load i32, i32* %3
%21 = call i64 @WEXITSTATUS(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = call i64 @WEXITSTATUS(i32 %25)
%27 = call i32 @warnx(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %24, i64 %26)
br label %28
28: ; preds = %23, %19
br label %29
29: ; preds = %28, %14
br label %30
30: ; preds = %29, %7
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"waitpid for %d\00"
@.str.1 = [18 x i8] c"pid %d: signal %d\00"
@.str.2 = [16 x i8] c"pid %d: exit %d\00"
define void @dowait(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i64 @waitpid(i32 %0, i32* %2, i32 0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %23
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i64 @WIFSIGNALED(i32 %9)
%11 = icmp eq i64 %10, 0
%12 = load i32, i32* %2
br i1 %11, label %16, label %13
13: ; preds = %8
%14 = call i64 @WTERMSIG(i32 %12)
%15 = call i32 @warnx(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %0, i64 %14)
br label %23
16: ; preds = %8
%17 = call i64 @WEXITSTATUS(i32 %12)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = load i32, i32* %2
%21 = call i64 @WEXITSTATUS(i32 %20)
%22 = call i32 @warnx(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %0, i64 %21)
br label %23
23: ; preds = %13, %19, %16, %6
ret void
}