#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_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*/);
int 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 1;
  }
  if (pid == 0)
    child(cpu);
  wpid = waitpid(pid, &status, __WALL);
  if (wpid != pid) {
    ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
    return 1;
  }
  if (!WIFSTOPPED(status)) {
    ksft_print_msg("child did not stop: %s\n", strerror(errno));
    return 1;
  }
  if (WSTOPSIG(status) != SIGSTOP) {
    ksft_print_msg("child did not stop with SIGSTOP: %s\n", strerror(errno));
    return 1;
  }
  if (ptrace(PTRACE_SINGLESTEP, pid, NULL, NULL) < 0) {
    if (errno == EIO) {
      ksft_print_msg(
          "ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n",
          strerror(errno));
      return 4;
    }
    ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n", strerror(errno));
    return 1;
  }
  wpid = waitpid(pid, &status, __WALL);
  if (wpid != pid) {
    ksft_print_msg("waitpid() failed: $s\n", strerror(errno));
    return 1;
  }
  if (WIFEXITED(status)) {
    ksft_print_msg("child did not single-step: %s\n", strerror(errno));
    return 1;
  }
  if (!WIFSTOPPED(status)) {
    ksft_print_msg("child did not stop: %s\n", strerror(errno));
    return 1;
  }
  if (WSTOPSIG(status) != SIGTRAP) {
    ksft_print_msg("child did not stop with SIGTRAP: %s\n", strerror(errno));
    return 1;
  }
  if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
    ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n", strerror(errno));
    return 1;
  }
  wpid = waitpid(pid, &status, __WALL);
  if (wpid != pid) {
    ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
    return 1;
  }
  if (!WIFEXITED(status)) {
    ksft_print_msg("child did not exit after PTRACE_CONT: %s\n",
                   strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11da <run_test+0x4a>
mov    0x2e18(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe37(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
cmpq   $0x0,-0x18(%rbp)
jne    11ed <run_test+0x5d>
mov    -0x8(%rbp),%edi
call   1030 <child@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1070 <waitpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     123e <run_test+0xae>
mov    0x2db4(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xde6(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0xc(%rbp),%edi
call   1040 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    1278 <run_test+0xe8>
mov    0x2d7a(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xdc2(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    0x2d29(%rip),%rcx
cmp    (%rcx),%rax
je     12b9 <run_test+0x129>
mov    0x2d39(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xd99(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <ptrace@plt>
cmp    $0x0,%rax
jge    1348 <run_test+0x1b8>
mov    0x2ced(%rip),%rax
mov    (%rax),%rax
mov    0x2cf3(%rip),%rcx
cmp    (%rcx),%rax
jne    131f <run_test+0x18f>
mov    0x2cd3(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xd58(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x4,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    0x2caa(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xd71(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0x18(%rbp),%rdi
mov    0x2c75(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1070 <waitpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1399 <run_test+0x209>
mov    0x2c59(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xd46(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0xc(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     13d4 <run_test+0x244>
mov    0x2c1e(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xd21(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0xc(%rbp),%edi
call   1040 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    140e <run_test+0x27e>
mov    0x2be4(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xc2c(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    0x2ba3(%rip),%rcx
cmp    (%rcx),%rax
je     144f <run_test+0x2bf>
mov    0x2ba3(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xcc5(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <ptrace@plt>
cmp    $0x0,%rax
jge    149b <run_test+0x30b>
mov    0x2b57(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xc9e(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0x18(%rbp),%rdi
mov    0x2b22(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1070 <waitpid@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     14ec <run_test+0x35c>
mov    0x2b06(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xb38(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
mov    -0xc(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
jne    1527 <run_test+0x397>
mov    0x2acb(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xc32(%rip),%rdi
call   1060 <ksft_print_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    152e <run_test+0x39e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     1257 <run_test+0xc7>
mov    %rax,%rbx
jne    11b1 <run_test+0x21>
mov    %ebp,%edi
call   1030 <child@plt>
mov    0x2e10(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <waitpid@plt>
cmp    %rbx,%rax
jne    1375 <run_test+0x1e5>
mov    0x4(%rsp),%edi
call   1040 <WIFSTOPPED@plt>
test   %eax,%eax
je     138d <run_test+0x1fd>
mov    0x4(%rsp),%edi
call   10a0 <WSTOPSIG@plt>
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%rax
jne    1272 <run_test+0xe2>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
test   %rax,%rax
js     128d <run_test+0xfd>
mov    0x0(%rbp),%edx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <waitpid@plt>
cmp    %rbx,%rax
jne    12c6 <run_test+0x136>
mov    0x4(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
je     12ed <run_test+0x15d>
mov    0x2d8d(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xe92(%rip),%rdi
jmp    13a3 <run_test+0x213>
mov    0x2d72(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xd93(%rip),%rdi
jmp    13a3 <run_test+0x213>
mov    0x2d57(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xdb9(%rip),%rdi
jmp    13a3 <run_test+0x213>
mov    0x2d3c(%rip),%rax
mov    (%rax),%rbx
mov    0x2d42(%rip),%rax
mov    (%rax),%rbp
mov    %rbx,%rdi
call   1090 <strerror@plt>
cmp    %rbp,%rbx
jne    12e1 <run_test+0x151>
lea    0xdb1(%rip),%rdi
mov    %eax,%esi
call   1060 <ksft_print_msg@plt>
mov    $0x4,%eax
jmp    13af <run_test+0x21f>
mov    0x2d03(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xdf2(%rip),%rdi
jmp    13a3 <run_test+0x213>
lea    0xdc0(%rip),%rdi
jmp    13a3 <run_test+0x213>
mov    0x4(%rsp),%edi
call   1040 <WIFSTOPPED@plt>
test   %eax,%eax
je     138d <run_test+0x1fd>
mov    0x4(%rsp),%edi
call   10a0 <WSTOPSIG@plt>
mov    0x2cb2(%rip),%rcx
cmp    (%rcx),%rax
jne    13b6 <run_test+0x226>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
test   %rax,%rax
js     13ce <run_test+0x23e>
mov    0x0(%rbp),%edx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <waitpid@plt>
cmp    %rbx,%rax
jne    1375 <run_test+0x1e5>
mov    0x4(%rsp),%edi
call   1080 <WIFEXITED@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    13af <run_test+0x21f>
mov    0x2c6c(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xdd5(%rip),%rdi
jmp    13a3 <run_test+0x213>
mov    0x2c54(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xc88(%rip),%rdi
jmp    13a3 <run_test+0x213>
mov    0x2c3c(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xc86(%rip),%rdi
mov    %eax,%esi
call   1060 <ksft_print_msg@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2c13(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xd37(%rip),%rdi
jmp    13a3 <run_test+0x213>
mov    0x2bfb(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
lea    0xd44(%rip),%rdi
jmp    13a3 <run_test+0x213>

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 1, 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 1, 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 1, 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 1, 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_print_msg(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i32 %59)
store i32 4, i32* %2
br label %130
61: ; preds = %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 1, 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 1, 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 1, 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 1, 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 1, 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 1, 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 1, 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 1, i32* %2
br label %130
129: ; preds = %121
store i32 0, i32* %2
br label %130
130: ; preds = %129, %125, %117, %106, %97, %88, %80, %72, %61, %57, %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 %109
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 %109
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 %109
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 %109
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 %52
43: ; preds = %39
%44 = load i64, i64* @errno
%45 = load i64, i64* @EIO
%46 = icmp eq i64 %44, %45
%47 = call i32 @strerror(i64 %44)
br i1 %46, label %48, label %50
48: ; preds = %43
%49 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i32 %47)
br label %109
50: ; preds = %43
%51 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %47)
br label %109
52: ; preds = %39
%53 = load i32, i32* @__WALL
%54 = call i64 @waitpid(i64 %4, i32* %2, i32 %53)
%55 = icmp eq i64 %54, %4
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = load i64, i64* @errno
%58 = call i32 @strerror(i64 %57)
%59 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %58)
br label %109
60: ; preds = %52
%61 = load i32, i32* %2
%62 = call i64 @WIFEXITED(i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %68, label %64
64: ; preds = %60
%65 = load i64, i64* @errno
%66 = call i32 @strerror(i64 %65)
%67 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %66)
br label %109
68: ; preds = %60
%69 = load i32, i32* %2
%70 = call i32 @WIFSTOPPED(i32 %69)
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %68
%73 = load i64, i64* @errno
%74 = call i32 @strerror(i64 %73)
%75 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %74)
br label %109
76: ; preds = %68
%77 = load i32, i32* %2
%78 = call i64 @WSTOPSIG(i32 %77)
%79 = load i64, i64* @SIGTRAP
%80 = icmp eq i64 %78, %79
br i1 %80, label %85, label %81
81: ; preds = %76
%82 = load i64, i64* @errno
%83 = call i32 @strerror(i64 %82)
%84 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i32 %83)
br label %109
85: ; preds = %76
%86 = load i32, i32* @PTRACE_CONT
%87 = call i64 @ptrace(i32 %86, i64 %4, i32* null, i32* null)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %85
%90 = load i64, i64* @errno
%91 = call i32 @strerror(i64 %90)
%92 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %91)
br label %109
93: ; preds = %85
%94 = load i32, i32* @__WALL
%95 = call i64 @waitpid(i64 %4, i32* %2, i32 %94)
%96 = icmp eq i64 %95, %4
br i1 %96, label %101, label %97
97: ; preds = %93
%98 = load i64, i64* @errno
%99 = call i32 @strerror(i64 %98)
%100 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %99)
br label %109
101: ; preds = %93
%102 = load i32, i32* %2
%103 = call i64 @WIFEXITED(i32 %102)
%104 = icmp eq i64 %103, 0
br i1 %104, label %105, label %109
105: ; preds = %101
%106 = load i64, i64* @errno
%107 = call i32 @strerror(i64 %106)
%108 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i32 %107)
br label %109
109: ; preds = %101, %105, %97, %89, %81, %72, %64, %56, %50, %48, %35, %26, %18, %6
%110 = phi i32 [ 1, %6 ], [ 1, %18 ], [ 1, %35 ], [ 4, %48 ], [ 1, %50 ], [ 1, %56 ], [ 1, %64 ], [ 1, %81 ], [ 1, %89 ], [ 1, %97 ], [ 1, %105 ], [ 1, %72 ], [ 1, %26 ], [ 0, %101 ]
ret i32 %110
}