#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*/ SIGCONT;
int /*<<< orphan*/ WCONTINUED;
int /*<<< orphan*/ WIFCONTINUED(int);
scalar_t__ WIFEXITED(int);
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 resume(pid_t pid) {
  int status;
  fprintf(stderr, "resuming %d\n", pid);
  if (kill(pid, SIGCONT)) {
    perror("resume child");
    exit(1);
  }
  if (waitpid(pid, &status, WCONTINUED) == -1) {
    perror("waiting for child to resume");
    exit(1);
  }
  if (WIFEXITED(status))
    exit(0);
  if (!WIFCONTINUED(status)) {
    perror("child not resumed");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<resume>:
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    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
cmp    $0x0,%rax
je     11c4 <resume+0x54>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rsi
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11f8 <resume+0x88>
lea    0xe31(%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 <resume+0xa1>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <WIFCONTINUED@plt>
cmp    $0x0,%eax
jne    1238 <resume+0xc8>
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resume>:
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    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <kill@plt>
test   %rax,%rax
jne    11de <resume+0x6e>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
je     11e7 <resume+0x77>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
jne    11f0 <resume+0x80>
mov    0xc(%rsp),%edi
call   1040 <WIFCONTINUED@plt>
test   %eax,%eax
je     11f7 <resume+0x87>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe28(%rip),%rdi
jmp    11fe <resume+0x8e>
lea    0xe2c(%rip),%rdi
jmp    11fe <resume+0x8e>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe38(%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"resuming %d\0A\00"
@SIGCONT = global i32 0
@.str.1 = [13 x i8] c"resume child\00"
@WCONTINUED = global i32 0
@.str.2 = [28 x i8] c"waiting for child to resume\00"
@.str.3 = [18 x i8] c"child not resumed\00"
define void @resume(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* @SIGCONT
%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 ([13 x i8], [13 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* @WCONTINUED
%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 ([28 x i8], [28 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 @WIFCONTINUED(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"resuming %d\0A\00"
@SIGCONT = global i32 0
@.str.1 = [13 x i8] c"resume child\00"
@WCONTINUED = global i32 0
@.str.2 = [28 x i8] c"waiting for child to resume\00"
@.str.3 = [18 x i8] c"child not resumed\00"
define void @resume(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* @SIGCONT
%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 ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* @WCONTINUED
%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 ([28 x i8], [28 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 @WIFCONTINUED(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
}