#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*/ SIGSTOP;
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ WIFSTOPPED(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int waitpid(int, int *, int /*<<< orphan*/);
void stop(pid_t pid) {
  int status;
  fprintf(stderr, "stopping %d\n", pid);
  if (kill(pid, SIGSTOP)) {
    perror("stop child");
    exit(1);
  }
  if (waitpid(pid, &status, WUNTRACED) == -1) {
    perror("waiting for child to stop");
    exit(1);
  }
  if (WIFEXITED(status))
    exit(0);
  if (!WIFSTOPPED(status)) {
    perror("child not stopped");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<stop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe72(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
cmp    $0x0,%rax
je     11c4 <stop+0x54>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rsi
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11f8 <stop+0x88>
lea    0xe2f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1211 <stop+0xa1>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    1238 <stop+0xc8>
lea    0xe09(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stop>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <kill@plt>
test   %rax,%rax
jne    11de <stop+0x6e>
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
je     11e7 <stop+0x77>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    11f0 <stop+0x80>
mov    0xc(%rsp),%edi
call   1050 <WIFSTOPPED@plt>
test   %eax,%eax
je     11f7 <stop+0x87>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe28(%rip),%rdi
jmp    11fe <stop+0x8e>
lea    0xe2a(%rip),%rdi
jmp    11fe <stop+0x8e>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"stopping %d\0A\00"
@SIGSTOP = global i32 0
@.str.1 = [11 x i8] c"stop child\00"
@WUNTRACED = global i32 0
@.str.2 = [26 x i8] c"waiting for child to stop\00"
@.str.3 = [18 x i8] c"child not stopped\00"
define void @stop(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @stderr
%5 = load i32, i32* %2
%6 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %2
%8 = load i32, i32* @SIGSTOP
%9 = call i64 @kill(i32 %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i32, i32* %2
%16 = load i32, i32* @WUNTRACED
%17 = call i32 @waitpid(i32 %15, i32* %3, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = load i32, i32* %3
%24 = call i64 @WIFEXITED(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %22
%29 = load i32, i32* %3
%30 = call i32 @WIFSTOPPED(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"stopping %d\0A\00"
@SIGSTOP = global i32 0
@.str.1 = [11 x i8] c"stop child\00"
@WUNTRACED = global i32 0
@.str.2 = [26 x i8] c"waiting for child to stop\00"
@.str.3 = [18 x i8] c"child not stopped\00"
define void @stop(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %0)
%6 = load i32, i32* @SIGSTOP
%7 = tail call i64 @kill(i32 %0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* @WUNTRACED
%14 = call i32 @waitpid(i32 %0, i32* %2, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = load i32, i32* %2
%21 = call i64 @WIFEXITED(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %19
%26 = load i32, i32* %2
%27 = call i32 @WIFSTOPPED(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
ret void
}