#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 */
int /*<<< orphan*/ WEXITSTATUS(int);
int /*<<< orphan*/ WIFSTOPPED(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void waitforstop(pid_t child) {
  int status;
  if (waitpid(child, &status, WUNTRACED) < 0)
    error(1, errno, "waitpid");
  if (!WIFSTOPPED(status))
    exit(WEXITSTATUS(status));
}


x86 assembly (clang, -O0):
<waitforstop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rsi
call   1060 <waitpid@plt>
cmp    $0x0,%rax
jge    1194 <waitforstop+0x44>
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe71(%rip),%rdx
call   1050 <error@plt>
mov    -0x8(%rbp),%edi
call   1030 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    11b4 <waitforstop+0x64>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitforstop>:
push   %rax
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rsi
call   1060 <waitpid@plt>
test   %rax,%rax
jns    1183 <waitforstop+0x33>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
mov    0x4(%rsp),%edi
call   1030 <WIFSTOPPED@plt>
test   %eax,%eax
je     1192 <waitforstop+0x42>
pop    %rax
ret
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@WUNTRACED = global i32 0
@errno = global i32 0
@.str = [8 x i8] c"waitpid\00"
define void @waitforstop(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @WUNTRACED
%5 = call i64 @waitpid(i32 %0, i32* %2, i32 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = call i32 @error(i32 1, i32 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = load i32, i32* %2
%12 = call i32 @WIFSTOPPED(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %2
%16 = call i32 @WEXITSTATUS(i32 %15)
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
ret void
}