#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*/ PTRACE_CONT;
int /*<<< orphan*/ __WALL;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ptrace(int /*<<< orphan*/, int, int /*<<< orphan*/ *,
                  int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int ptrace_cont(pid_t pid) {
  int status;
  if (ptrace(PTRACE_CONT, pid, NULL, 0)) {
    fprintf(stderr, "Failed to ptrace_cont: %s\n", strerror(errno));
    return -1;
  }
  if (waitpid(pid, &status, __WALL) < 0) {
    fprintf(stderr, "Failed to wait for PID %d, %s\n", pid, strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ptrace_cont>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
cmp    $0x0,%rax
je     11a6 <ptrace_cont+0x66>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <ptrace_cont+0xcf>
mov    -0x8(%rbp),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    1208 <ptrace_cont+0xc8>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    %rax,%rcx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <ptrace_cont+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptrace_cont>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
test   %rax,%rax
je     1191 <ptrace_cont+0x51>
mov    0x2e79(%rip),%rax
mov    (%rax),%ebx
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe82(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    11ab <ptrace_cont+0x6b>
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
call   1050 <waitpid@plt>
test   %rax,%rax
js     11b4 <ptrace_cont+0x74>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e25(%rip),%rax
mov    (%rax),%ebx
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe49(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    118a <ptrace_cont+0x4a>

LLVM IR (-O0):
@PTRACE_CONT = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Failed to ptrace_cont: %s\0A\00"
@errno = global i32 0
@__WALL = global i32 0
@.str.1 = [31 x i8] c"Failed to wait for PID %d, %s\0A\00"
define i32 @ptrace_cont(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* @PTRACE_CONT
%6 = load i32, i32* %3
%7 = call i64 @ptrace(i32 %5, i32 %6, i32* null, i32 0)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 -1, i32* %2
br label %26
14: ; preds = %1
%15 = load i32, i32* %3
%16 = load i32, i32* @__WALL
%17 = call i64 @waitpid(i32 %15, i32* %4, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i32, i32* %3
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %23)
store i32 -1, i32* %2
br label %26
25: ; preds = %14
store i32 0, i32* %2
br label %26
26: ; preds = %25, %19, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@PTRACE_CONT = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"Failed to ptrace_cont: %s\0A\00"
@errno = global i32 0
@__WALL = global i32 0
@.str.1 = [31 x i8] c"Failed to wait for PID %d, %s\0A\00"
define i32 @ptrace_cont(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @PTRACE_CONT
%5 = tail call i64 @ptrace(i32 %4, i32 %0, i32* null, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %21
12: ; preds = %1
%13 = load i32, i32* @__WALL
%14 = call i64 @waitpid(i32 %0, i32* %2, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %19)
br label %21
21: ; preds = %12, %16, %7
%22 = phi i32 [ -1, %7 ], [ -1, %16 ], [ 0, %12 ]
ret i32 %22
}