#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ EIO;
int /*<<< orphan*/ PTRACE_CONT;
int /*<<< orphan*/ PTRACE_SINGLESTEP;
scalar_t__ SIGSTOP;
scalar_t__ SIGTRAP;
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ WIFSTOPPED(int);
scalar_t__ WSTOPSIG(int);
int /*<<< orphan*/ __WALL;
int /*<<< orphan*/ child(int);
scalar_t__ errno;
scalar_t__ fork();
int /*<<< orphan*/ ksft_exit_skip(char *, int /*<<< orphan*/);
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/);
scalar_t__ ptrace(int /*<<< orphan*/, scalar_t__, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(scalar_t__);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
bool run_test(int cpu) {
  int status;
  pid_t pid = fork();
  pid_t wpid;
  if (pid < 0) {
    ksft_print_msg("fork() failed: %s\n", strerror(errno));
    return false;
  }
  if (pid == 0)
    child(cpu);
  wpid = waitpid(pid, &status, __WALL);
  if (wpid != pid) {
    ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
    return false;
  }
  if (!WIFSTOPPED(status)) {
    ksft_print_msg("child did not stop: %s\n", strerror(errno));
    return false;
  }
  if (WSTOPSIG(status) != SIGSTOP) {
    ksft_print_msg("child did not stop with SIGSTOP: %s\n", strerror(errno));
    return false;
  }
  if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
    if (errno == EIO) {
      ksft_exit_skip(
          "ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n",
          strerror(errno));
    }
    ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n", strerror(errno));
    return false;
  }
  wpid = waitpid(pid, &status, __WALL);
  if (wpid != pid) {
    ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
    return false;
  }
  if (WIFEXITED(status)) {
    ksft_print_msg("child did not single-step: %s\n", strerror(errno));
    return false;
  }
  if (!WIFSTOPPED(status)) {
    ksft_print_msg("child did not stop: %s\n", strerror(errno));
    return false;
  }
  if (WSTOPSIG(status) != SIGTRAP) {
    ksft_print_msg("child did not stop with SIGTRAP: %s\n", strerror(errno));
    return false;
  }
  if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
    ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n", strerror(errno));
    return false;
  }
  wpid = waitpid(pid, &status, __WALL);
  if (wpid != pid) {
    ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
    return false;
  }
  if (!WIFEXITED(status)) {
    ksft_print_msg("child did not exit after PTRACE_CONT: %s\n",
                   strerror(errno));
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11ea <run_test+0x4a>
mov    0x2e08(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xe27(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
cmpq   $0x0,-0x18(%rbp)
jne    11fd <run_test+0x5d>
mov    -0x8(%rbp),%edi
call   1030 <child@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1080 <waitpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     124e <run_test+0xae>
mov    0x2da4(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xdd6(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0xc(%rbp),%edi
call   1050 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    1288 <run_test+0xe8>
mov    0x2d6a(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xdb2(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0xc(%rbp),%edi
call   10b0 <WSTOPSIG@plt>
mov    0x2d19(%rip),%rcx
cmp    (%rcx),%rax
je     12c9 <run_test+0x129>
mov    0x2d29(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xd89(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
jge    134c <run_test+0x1ac>
mov    0x2cdd(%rip),%rax
mov    (%rax),%rax
mov    0x2ce3(%rip),%rcx
cmp    (%rcx),%rax
jne    1323 <run_test+0x183>
mov    0x2cc3(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xd48(%rip),%rdi
call   1040 <ksft_exit_skip@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xd6d(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0x18(%rbp),%rdi
mov    0x2c71(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1080 <waitpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     139d <run_test+0x1fd>
mov    0x2c55(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xd42(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0xc(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     13d8 <run_test+0x238>
mov    0x2c1a(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xd1d(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0xc(%rbp),%edi
call   1050 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    1412 <run_test+0x272>
mov    0x2be0(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xc28(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0xc(%rbp),%edi
call   10b0 <WSTOPSIG@plt>
mov    0x2b9f(%rip),%rcx
cmp    (%rcx),%rax
je     1453 <run_test+0x2b3>
mov    0x2b9f(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xcc1(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    0x2b5e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1060 <ptrace@plt>
cmp    $0x0,%rax
jge    149f <run_test+0x2ff>
mov    0x2b53(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xc9a(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0x18(%rbp),%rdi
mov    0x2b1e(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1080 <waitpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     14f0 <run_test+0x350>
mov    0x2b02(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xb34(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
mov    -0xc(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
jne    152b <run_test+0x38b>
mov    0x2ac7(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    %eax,%esi
lea    0xc2e(%rip),%rdi
call   1070 <ksft_print_msg@plt>
movl   $0x0,-0x4(%rbp)
jmp    1532 <run_test+0x392>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     1276 <run_test+0xd6>
mov    %rax,%r14
jne    11c8 <run_test+0x28>
mov    %ebp,%edi
call   1030 <child@plt>
mov    0x2df9(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1080 <waitpid@plt>
cmp    %r14,%rax
jne    1395 <run_test+0x1f5>
mov    0xc(%rsp),%edi
call   1050 <WIFSTOPPED@plt>
test   %eax,%eax
je     13ad <run_test+0x20d>
mov    0xc(%rsp),%edi
call   10b0 <WSTOPSIG@plt>
mov    0x2da7(%rip),%rcx
cmp    (%rcx),%rax
jne    1298 <run_test+0xf8>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
test   %rax,%rax
js     12b3 <run_test+0x113>
mov    0x0(%rbp),%edx
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1080 <waitpid@plt>
cmp    %r14,%rax
jne    12f0 <run_test+0x150>
mov    0xc(%rsp),%edi
call   1090 <WIFEXITED@plt>
test   %rax,%rax
je     130b <run_test+0x16b>
mov    0x2d6e(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xe73(%rip),%rdi
jmp    13c3 <run_test+0x223>
mov    0x2d53(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xd74(%rip),%rdi
mov    %eax,%esi
call   1070 <ksft_print_msg@plt>
jmp    13cc <run_test+0x22c>
mov    0x2d31(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xd93(%rip),%rdi
jmp    13c3 <run_test+0x223>
mov    0x2d16(%rip),%rbx
mov    (%rbx),%rdi
mov    0x2d1c(%rip),%rax
cmp    (%rax),%rdi
jne    12df <run_test+0x13f>
call   10a0 <strerror@plt>
lea    0xd91(%rip),%rdi
mov    %eax,%esi
call   1040 <ksft_exit_skip@plt>
mov    (%rbx),%rdi
call   10a0 <strerror@plt>
lea    0xdbd(%rip),%rdi
jmp    13c3 <run_test+0x223>
mov    0x2cd9(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xdc8(%rip),%rdi
jmp    13c3 <run_test+0x223>
mov    0xc(%rsp),%edi
call   1050 <WIFSTOPPED@plt>
test   %eax,%eax
je     13ad <run_test+0x20d>
mov    0xc(%rsp),%edi
call   10b0 <WSTOPSIG@plt>
mov    0x2c94(%rip),%rcx
cmp    (%rcx),%rax
jne    13d7 <run_test+0x237>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
test   %rax,%rax
js     13ef <run_test+0x24f>
mov    0x0(%rbp),%edx
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1080 <waitpid@plt>
cmp    %r14,%rax
jne    1395 <run_test+0x1f5>
mov    0xc(%rsp),%edi
call   1090 <WIFEXITED@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    13cc <run_test+0x22c>
mov    0x2c4c(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xdb5(%rip),%rdi
jmp    13c3 <run_test+0x223>
mov    0x2c34(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xc68(%rip),%rdi
jmp    13c3 <run_test+0x223>
mov    0x2c1c(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xc66(%rip),%rdi
mov    %eax,%esi
call   1070 <ksft_print_msg@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2bf2(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xd16(%rip),%rdi
jmp    13c3 <run_test+0x223>
mov    0x2bda(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xd23(%rip),%rdi
jmp    128c <run_test+0xec>

LLVM IR (-O0):
@.str = [19 x i8] c"fork() failed: %s\0A\00"
@errno = global i64 0
@__WALL = global i32 0
@.str.1 = [22 x i8] c"waitpid() failed: %s\0A\00"
@.str.2 = [24 x i8] c"child did not stop: %s\0A\00"
@SIGSTOP = global i64 0
@.str.3 = [37 x i8] c"child did not stop with SIGSTOP: %s\0A\00"
@PTRACE_SINGLESTEP = global i32 0
@EIO = global i64 0
@.str.4 = [66 x i8] c"ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\0A\00"
@.str.5 = [38 x i8] c"ptrace(PTRACE_SINGLESTEP) failed: %s\0A\00"
@.str.6 = [22 x i8] c"waitpid() failed: $s\0A\00"
@.str.7 = [31 x i8] c"child did not single-step: %s\0A\00"
@SIGTRAP = global i64 0
@.str.8 = [37 x i8] c"child did not stop with SIGTRAP: %s\0A\00"
@PTRACE_CONT = global i32 0
@.str.9 = [32 x i8] c"ptrace(PTRACE_CONT) failed: %s\0A\00"
@.str.10 = [42 x i8] c"child did not exit after PTRACE_CONT: %s\0A\00"
define i32 @run_test(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %3
%7 = call i64 (...) @fork()
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i64, i64* @errno
%12 = call i32 @strerror(i64 %11)
%13 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 0, i32* %2
br label %130
14: ; preds = %1
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %3
%19 = call i32 @child(i32 %18)
br label %20
20: ; preds = %17, %14
%21 = load i64, i64* %5
%22 = load i32, i32* @__WALL
%23 = call i64 @waitpid(i64 %21, i32* %4, i32 %22)
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = load i64, i64* %5
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load i64, i64* @errno
%29 = call i32 @strerror(i64 %28)
%30 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 0, i32* %2
br label %130
31: ; preds = %20
%32 = load i32, i32* %4
%33 = call i32 @WIFSTOPPED(i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load i64, i64* @errno
%37 = call i32 @strerror(i64 %36)
%38 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %37)
store i32 0, i32* %2
br label %130
39: ; preds = %31
%40 = load i32, i32* %4
%41 = call i64 @WSTOPSIG(i32 %40)
%42 = load i64, i64* @SIGSTOP
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i64, i64* @errno
%46 = call i32 @strerror(i64 %45)
%47 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %46)
store i32 0, i32* %2
br label %130
48: ; preds = %39
%49 = load i32, i32* @PTRACE_SINGLESTEP
%50 = load i64, i64* %5
%51 = call i64 @ptrace(i32 %49, i64 %50, i32* null, i32* null)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %65
53: ; preds = %48
%54 = load i64, i64* @errno
%55 = load i64, i64* @EIO
%56 = icmp eq i64 %54, %55
br i1 %56, label %57, label %61
57: ; preds = %53
%58 = load i64, i64* @errno
%59 = call i32 @strerror(i64 %58)
%60 = call i32 @ksft_exit_skip(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %57, %53
%62 = load i64, i64* @errno
%63 = call i32 @strerror(i64 %62)
%64 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %63)
store i32 0, i32* %2
br label %130
65: ; preds = %48
%66 = load i64, i64* %5
%67 = load i32, i32* @__WALL
%68 = call i64 @waitpid(i64 %66, i32* %4, i32 %67)
store i64 %68, i64* %6
%69 = load i64, i64* %6
%70 = load i64, i64* %5
%71 = icmp ne i64 %69, %70
br i1 %71, label %72, label %76
72: ; preds = %65
%73 = load i64, i64* @errno
%74 = call i32 @strerror(i64 %73)
%75 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %74)
store i32 0, i32* %2
br label %130
76: ; preds = %65
%77 = load i32, i32* %4
%78 = call i64 @WIFEXITED(i32 %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %76
%81 = load i64, i64* @errno
%82 = call i32 @strerror(i64 %81)
%83 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %82)
store i32 0, i32* %2
br label %130
84: ; preds = %76
%85 = load i32, i32* %4
%86 = call i32 @WIFSTOPPED(i32 %85)
%87 = icmp ne i32 %86, 0
br i1 %87, label %92, label %88
88: ; preds = %84
%89 = load i64, i64* @errno
%90 = call i32 @strerror(i64 %89)
%91 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %90)
store i32 0, i32* %2
br label %130
92: ; preds = %84
%93 = load i32, i32* %4
%94 = call i64 @WSTOPSIG(i32 %93)
%95 = load i64, i64* @SIGTRAP
%96 = icmp ne i64 %94, %95
br i1 %96, label %97, label %101
97: ; preds = %92
%98 = load i64, i64* @errno
%99 = call i32 @strerror(i64 %98)
%100 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i32 %99)
store i32 0, i32* %2
br label %130
101: ; preds = %92
%102 = load i32, i32* @PTRACE_CONT
%103 = load i64, i64* %5
%104 = call i64 @ptrace(i32 %102, i64 %103, i32* null, i32* null)
%105 = icmp slt i64 %104, 0
br i1 %105, label %106, label %110
106: ; preds = %101
%107 = load i64, i64* @errno
%108 = call i32 @strerror(i64 %107)
%109 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %108)
store i32 0, i32* %2
br label %130
110: ; preds = %101
%111 = load i64, i64* %5
%112 = load i32, i32* @__WALL
%113 = call i64 @waitpid(i64 %111, i32* %4, i32 %112)
store i64 %113, i64* %6
%114 = load i64, i64* %6
%115 = load i64, i64* %5
%116 = icmp ne i64 %114, %115
br i1 %116, label %117, label %121
117: ; preds = %110
%118 = load i64, i64* @errno
%119 = call i32 @strerror(i64 %118)
%120 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %119)
store i32 0, i32* %2
br label %130
121: ; preds = %110
%122 = load i32, i32* %4
%123 = call i64 @WIFEXITED(i32 %122)
%124 = icmp ne i64 %123, 0
br i1 %124, label %129, label %125
125: ; preds = %121
%126 = load i64, i64* @errno
%127 = call i32 @strerror(i64 %126)
%128 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i32 %127)
store i32 0, i32* %2
br label %130
129: ; preds = %121
store i32 1, i32* %2
br label %130
130: ; preds = %129, %125, %117, %106, %97, %88, %80, %72, %61, %44, %35, %27, %10
%131 = load i32, i32* %2
ret i32 %131
}

LLVM IR (-O2):
@.str = [19 x i8] c"fork() failed: %s\0A\00"
@errno = global i64 0
@__WALL = global i32 0
@.str.1 = [22 x i8] c"waitpid() failed: %s\0A\00"
@.str.2 = [24 x i8] c"child did not stop: %s\0A\00"
@SIGSTOP = global i64 0
@.str.3 = [37 x i8] c"child did not stop with SIGSTOP: %s\0A\00"
@PTRACE_SINGLESTEP = global i32 0
@EIO = global i64 0
@.str.4 = [66 x i8] c"ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\0A\00"
@.str.5 = [38 x i8] c"ptrace(PTRACE_SINGLESTEP) failed: %s\0A\00"
@.str.6 = [22 x i8] c"waitpid() failed: $s\0A\00"
@.str.7 = [31 x i8] c"child did not single-step: %s\0A\00"
@SIGTRAP = global i64 0
@.str.8 = [37 x i8] c"child did not stop with SIGTRAP: %s\0A\00"
@PTRACE_CONT = global i32 0
@.str.9 = [32 x i8] c"ptrace(PTRACE_CONT) failed: %s\0A\00"
@.str.10 = [42 x i8] c"child did not exit after PTRACE_CONT: %s\0A\00"
define i32 @run_test(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = tail call i32 @strerror(i64 %7)
%9 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %112
10: ; preds = %1
%11 = icmp eq i64 %4, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @child(i32 %0)
br label %14
14: ; preds = %12, %10
%15 = load i32, i32* @__WALL
%16 = call i64 @waitpid(i64 %4, i32* %2, i32 %15)
%17 = icmp eq i64 %16, %4
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i64, i64* @errno
%20 = call i32 @strerror(i64 %19)
%21 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %112
22: ; preds = %14
%23 = load i32, i32* %2
%24 = call i32 @WIFSTOPPED(i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i64, i64* @errno
%28 = call i32 @strerror(i64 %27)
%29 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %112
30: ; preds = %22
%31 = load i32, i32* %2
%32 = call i64 @WSTOPSIG(i32 %31)
%33 = load i64, i64* @SIGSTOP
%34 = icmp eq i64 %32, %33
br i1 %34, label %39, label %35
35: ; preds = %30
%36 = load i64, i64* @errno
%37 = call i32 @strerror(i64 %36)
%38 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %112
39: ; preds = %30
%40 = load i32, i32* @PTRACE_SINGLESTEP
%41 = call i64 @ptrace(i32 %40, i64 %4, i32* null, i32* null)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = load i64, i64* @errno
%45 = load i64, i64* @EIO
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = call i32 @strerror(i64 %44)
%49 = call i32 @ksft_exit_skip(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = load i64, i64* @errno
br label %51
51: ; preds = %47, %43
%52 = phi i64 [ %50, %47 ], [ %44, %43 ]
%53 = call i32 @strerror(i64 %52)
%54 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %53)
br label %112
55: ; preds = %39
%56 = load i32, i32* @__WALL
%57 = call i64 @waitpid(i64 %4, i32* %2, i32 %56)
%58 = icmp eq i64 %57, %4
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i64, i64* @errno
%61 = call i32 @strerror(i64 %60)
%62 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %61)
br label %112
63: ; preds = %55
%64 = load i32, i32* %2
%65 = call i64 @WIFEXITED(i32 %64)
%66 = icmp eq i64 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %63
%68 = load i64, i64* @errno
%69 = call i32 @strerror(i64 %68)
%70 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %69)
br label %112
71: ; preds = %63
%72 = load i32, i32* %2
%73 = call i32 @WIFSTOPPED(i32 %72)
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %71
%76 = load i64, i64* @errno
%77 = call i32 @strerror(i64 %76)
%78 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %77)
br label %112
79: ; preds = %71
%80 = load i32, i32* %2
%81 = call i64 @WSTOPSIG(i32 %80)
%82 = load i64, i64* @SIGTRAP
%83 = icmp eq i64 %81, %82
br i1 %83, label %88, label %84
84: ; preds = %79
%85 = load i64, i64* @errno
%86 = call i32 @strerror(i64 %85)
%87 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i32 %86)
br label %112
88: ; preds = %79
%89 = load i32, i32* @PTRACE_CONT
%90 = call i64 @ptrace(i32 %89, i64 %4, i32* null, i32* null)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %88
%93 = load i64, i64* @errno
%94 = call i32 @strerror(i64 %93)
%95 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %94)
br label %112
96: ; preds = %88
%97 = load i32, i32* @__WALL
%98 = call i64 @waitpid(i64 %4, i32* %2, i32 %97)
%99 = icmp eq i64 %98, %4
br i1 %99, label %104, label %100
100: ; preds = %96
%101 = load i64, i64* @errno
%102 = call i32 @strerror(i64 %101)
%103 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %102)
br label %112
104: ; preds = %96
%105 = load i32, i32* %2
%106 = call i64 @WIFEXITED(i32 %105)
%107 = icmp eq i64 %106, 0
br i1 %107, label %108, label %112
108: ; preds = %104
%109 = load i64, i64* @errno
%110 = call i32 @strerror(i64 %109)
%111 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i32 %110)
br label %112
112: ; preds = %104, %108, %100, %92, %84, %75, %67, %59, %51, %35, %26, %18, %6
%113 = phi i32 [ 0, %6 ], [ 0, %18 ], [ 0, %35 ], [ 0, %51 ], [ 0, %59 ], [ 0, %67 ], [ 0, %84 ], [ 0, %92 ], [ 0, %100 ], [ 0, %108 ], [ 0, %75 ], [ 0, %26 ], [ 1, %104 ]
ret i32 %113
}