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


x86 assembly (clang, -O0):
<dowait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    1174 <dowait+0x44>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe9d(%rip),%rdi
call   1030 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ab <dowait+0x7b>
cmpl   $0x0,-0x10(%rbp)
je     119f <dowait+0x6f>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe90(%rip),%rdi
call   1040 <warnx@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ab <dowait+0x7b>
jmp    11a4 <dowait+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dowait>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r14d
lea    0xc(%rsp),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %rax,%rax
js     116d <dowait+0x3d>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
je     1183 <dowait+0x53>
lea    0xebd(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <warnx@plt>
jmp    117e <dowait+0x4e>
lea    0xe8c(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1030 <warn@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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