#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int si_code;
};
typedef TYPE_1__ siginfo_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_GETSIGINFO;
int /*<<< orphan*/ PTRACE_SINGLESTEP;
int /*<<< orphan*/ PTRACE_SYSCALL;
int SIGSTOP;
int SIGTRAP;
int /*<<< orphan*/ perror(char *);
int print_wait_res(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/, ...);
int /*<<< orphan*/ wait(int *);
int process_parent(pid_t child) {
  int sig;
  do {
    int status;
    pid_t pid;
    pid = wait(&status);
    sig = print_wait_res(pid, status);
    if (sig == SIGTRAP) {
      siginfo_t siginfo;
      long res = ptrace(PTRACE_GETSIGINFO, pid, 0, &siginfo);
      if (res < 0) {
        perror("ptrace(GETSIGINFO failed)");
      } else {
        printf("siginfo.si_code=%d\n", siginfo.si_code);
      }
      ptrace(PTRACE_SYSCALL, pid, 0, 0);
    } else {
      int sig2 = sig;
      if (sig2 == SIGSTOP)
        sig2 = 0;
      ptrace(PTRACE_SINGLESTEP, pid, 0, sig2);
    }
  } while (sig > 0);
  return 0;
}


x86 assembly (clang, -O0):
<process_parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <print_wait_res@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%eax
jne    11eb <process_parent+0x9b>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%esi
xor    %edx,%edx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1050 <ptrace@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11c0 <process_parent+0x70>
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
jmp    11cf <process_parent+0x7f>
mov    -0x18(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
mov    $0x0,%al
call   1050 <ptrace@plt>
jmp    1222 <process_parent+0xd2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%eax
jne    120a <process_parent+0xba>
movl   $0x0,-0x24(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%esi
mov    -0x24(%rbp),%ecx
xor    %edx,%edx
mov    $0x0,%al
call   1050 <ptrace@plt>
jmp    1227 <process_parent+0xd7>
cmpl   $0x0,-0x8(%rbp)
jg     115b <process_parent+0xb>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_parent>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x4(%rsp),%r13
mov    0x2e71(%rip),%r15
mov    0x2e62(%rip),%r14
mov    0x2e6b(%rip),%r12
jmp    1193 <process_parent+0x43>
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <ptrace@plt>
test   %ebp,%ebp
jle    120c <process_parent+0xbc>
mov    %r13,%rdi
call   1070 <wait@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%esi
mov    %eax,%edi
call   1030 <print_wait_res@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    11f0 <process_parent+0xa0>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
mov    %rsp,%rcx
xor    %eax,%eax
call   1050 <ptrace@plt>
test   %rax,%rax
js     11fe <process_parent+0xae>
mov    (%rsp),%esi
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
jmp    1188 <process_parent+0x38>
nopl   0x0(%rax,%rax,1)
mov    $0x0,%ecx
cmp    (%r14),%ebp
je     1180 <process_parent+0x30>
mov    %ebp,%ecx
jmp    1180 <process_parent+0x30>
lea    0xdfb(%rip),%rdi
call   1060 <perror@plt>
jmp    11da <process_parent+0x8a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_2__ = type { i32 }
@SIGTRAP = global i32 0
@PTRACE_GETSIGINFO = global i32 0
@.str = [26 x i8] c"ptrace(GETSIGINFO failed)\00"
@.str.1 = [20 x i8] c"siginfo.si_code=%d\0A\00"
@PTRACE_SYSCALL = global i32 0
@SIGSTOP = global i32 0
@PTRACE_SINGLESTEP = global i32 0
define i32 @process_parent(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_2__
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %2
br label %9
9: ; preds = %45, %1
%10 = call i32 @wait(i32* %4)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = call i32 @print_wait_res(i32 %11, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = load i32, i32* @SIGTRAP
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %33
17: ; preds = %9
%18 = load i32, i32* @PTRACE_GETSIGINFO
%19 = load i32, i32* %5
%20 = call i64 (i32, i32, i32, ...) @ptrace(i32 %18, i32 %19, i32 0, %struct.TYPE_2__* %6)
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %29
25: ; preds = %17
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %6, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %25, %23
%30 = load i32, i32* @PTRACE_SYSCALL
%31 = load i32, i32* %5
%32 = call i64 (i32, i32, i32, ...) @ptrace(i32 %30, i32 %31, i32 0, i32 0)
br label %44
33: ; preds = %9
%34 = load i32, i32* %3
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = load i32, i32* @SIGSTOP
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 0, i32* %8
br label %39
39: ; preds = %38, %33
%40 = load i32, i32* @PTRACE_SINGLESTEP
%41 = load i32, i32* %5
%42 = load i32, i32* %8
%43 = call i64 (i32, i32, i32, ...) @ptrace(i32 %40, i32 %41, i32 0, i32 %42)
br label %44
44: ; preds = %39, %29
br label %45
45: ; preds = %44
%46 = load i32, i32* %3
%47 = icmp sgt i32 %46, 0
br i1 %47, label %9, label %48
48: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i32 }
@SIGTRAP = global i32 0
@PTRACE_GETSIGINFO = global i32 0
@.str = [26 x i8] c"ptrace(GETSIGINFO failed)\00"
@.str.1 = [20 x i8] c"siginfo.si_code=%d\0A\00"
@PTRACE_SYSCALL = global i32 0
@SIGSTOP = global i32 0
@PTRACE_SINGLESTEP = global i32 0
define i32 @process_parent(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.TYPE_2__
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.TYPE_2__* %3 to i8*
%6 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %3, i64 0, i32 0
br label %7
7: ; preds = %31, %1
%8 = call i32 @wait(i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @print_wait_res(i32 %8, i32 %9)
%11 = load i32, i32* @SIGTRAP
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %7
%14 = load i32, i32* @PTRACE_GETSIGINFO
%15 = call i64 (i32, i32, i32, ...) @ptrace(i32 %14, i32 %8, i32 0, %struct.TYPE_2__* %3)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %22
19: ; preds = %13
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %17
%23 = load i32, i32* @PTRACE_SYSCALL
%24 = call i64 (i32, i32, i32, ...) @ptrace(i32 %23, i32 %8, i32 0, i32 0)
br label %31
25: ; preds = %7
%26 = load i32, i32* @SIGSTOP
%27 = icmp eq i32 %10, %26
%28 = select i1 %27, i32 0, i32 %10
%29 = load i32, i32* @PTRACE_SINGLESTEP
%30 = call i64 (i32, i32, i32, ...) @ptrace(i32 %29, i32 %8, i32 0, i32 %28)
br label %31
31: ; preds = %25, %22
%32 = icmp sgt i32 %10, 0
br i1 %32, label %7, label %33
33: ; preds = %31
ret i32 0
}