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


x86 assembly (clang, -O0):
<dowait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    115d <dowait+0x1d>
jmp    11c7 <dowait+0x87>
cmpl   $0x0,-0x8(%rbp)
jne    116e <dowait+0x2e>
xor    %edi,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jne    11c7 <dowait+0x87>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    11a1 <dowait+0x61>
lea    0xe69(%rip),%rdi
call   1030 <warn@plt>
jmp    11c2 <dowait+0x82>
cmpl   $0x0,-0xc(%rbp)
je     11bd <dowait+0x7d>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe50(%rip),%rdi
call   1040 <warnx@plt>
jmp    11c2 <dowait+0x82>
jmp    11c7 <dowait+0x87>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dowait>:
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
js     114f <dowait+0xf>
je     1190 <dowait+0x50>
test   %edi,%edi
je     1155 <dowait+0x15>
add    $0x10,%rsp
pop    %rbx
ret
mov    %esi,%ebx
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %rax,%rax
js     1182 <dowait+0x42>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     114f <dowait+0xf>
lea    0xe8f(%rip),%rdi
mov    %ebx,%esi
call   1040 <warnx@plt>
jmp    114f <dowait+0xf>
lea    0xe77(%rip),%rdi
call   1030 <warn@plt>
jmp    114f <dowait+0xf>
xor    %edi,%edi
call   1060 <exit@plt>

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

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