#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void waitfor(pid_t pid) {
  int wstatus = 0;
  while (1) {
    check(waitpid(pid, &wstatus, WUNTRACED), "waitpid");
    if (WIFEXITED(wstatus) || WIFSIGNALED(wstatus)) {
      return;
    }
  }
}


x86 assembly (clang, -O0):
<waitfor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rsi
call   1040 <waitpid@plt>
mov    %eax,%edi
lea    0xe90(%rip),%rsi
call   1050 <check@plt>
mov    -0x8(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
jne    1199 <waitfor+0x59>
mov    -0x8(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     119f <waitfor+0x5f>
add    $0x10,%rsp
pop    %rbp
ret
jmp    1152 <waitfor+0x12>

x86 assembly (clang, -O2):
<waitfor>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x0,0x4(%rsp)
mov    0x2e87(%rip),%r12
lea    0x4(%rsp),%r14
lea    0xe9b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <waitpid@plt>
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <check@plt>
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
jne    11a4 <waitfor+0x64>
mov    0x4(%rsp),%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
je     1170 <waitfor+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@WUNTRACED = global i32 0
@.str = [8 x i8] c"waitpid\00"
define void @waitfor(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %1, %17
%5 = load i32, i32* %2
%6 = load i32, i32* @WUNTRACED
%7 = call i32 @waitpid(i32 %5, i32* %3, i32 %6)
%8 = call i32 @check(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %3
%10 = call i64 @WIFEXITED(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = load i32, i32* %3
%14 = call i64 @WIFSIGNALED(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12, %4
ret void
17: ; preds = %12
br label %4
}

LLVM IR (-O2):
@WUNTRACED = global i32 0
@.str = [8 x i8] c"waitpid\00"
define void @waitfor(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %11, %1
%5 = load i32, i32* @WUNTRACED
%6 = call i32 @waitpid(i32 %0, i32* %2, i32 %5)
%7 = call i32 @check(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = call i64 @WIFEXITED(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i32, i32* %2
%13 = call i64 @WIFSIGNALED(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %4, label %15
15: ; preds = %11, %4
ret void
}