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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printstatus(int);
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ warn(char *, int);
void dowait(pid_t pid) {
  int status;
  if (waitpid(pid, &status, 0) < 0) {
    warn("pid %d", pid);
  } else {
    printf("pid %d: ", pid);
    printstatus(status);
    printf("\n");
  }
}


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   1060 <waitpid@plt>
cmp    $0x0,%rax
jge    1177 <dowait+0x37>
mov    -0x4(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <warn@plt>
jmp    119e <dowait+0x5e>
mov    -0x4(%rbp),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <printstatus@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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   1070 <waitpid@plt>
test   %rax,%rax
js     118d <dowait+0x3d>
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   1060 <printstatus@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    119b <dowait+0x4b>
lea    0xe6c(%rip),%rdi
mov    %ebx,%esi
call   1040 <warn@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

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