#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__ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *, int, ...);
void dowait(int pid) {
  int status;
  if (waitpid(pid, &status, 0) < 0) {
    warn("waitpid for %d", pid);
  } else if (status != 0) {
    warn("pid %d: exit %d", pid, 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   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    1159 <dowait+0x39>
mov    -0x4(%rbp),%esi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
jmp    117c <dowait+0x5c>
cmpl   $0x0,-0x8(%rbp)
je     1177 <dowait+0x57>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <warn@plt>
jmp    117c <dowait+0x5c>
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   1040 <waitpid@plt>
test   %rax,%rax
js     1152 <dowait+0x32>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     1162 <dowait+0x42>
lea    0xec8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <warn@plt>
jmp    1162 <dowait+0x42>
lea    0xea7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <warn@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"waitpid for %d\00"
@.str.1 = [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 (i8*, i32, ...) @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %18
10: ; preds = %1
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = call i32 (i8*, i32, ...) @warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15)
br label %17
17: ; preds = %13, %10
br label %18
18: ; preds = %17, %7
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"waitpid for %d\00"
@.str.1 = [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 (i8*, i32, ...) @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 (i8*, i32, ...) @warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %9)
br label %13
13: ; preds = %8, %11, %6
ret void
}