#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 */
int /*<<< orphan*/ PTRACE_CONT;
int /*<<< orphan*/ PTRACE_PEEKUSER;
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, long);
long ptrace(int /*<<< orphan*/, scalar_t__, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  pid_t child;
  long orig_eax;
  child = fork();
  if (child == 0) {
    ptrace(PTRACE_TRACEME, 0, NULL, NULL);
    execl("/bin/ls", "ls", NULL);
  } else {
    wait(NULL);
    orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * 11, NULL);
    printf("The child made a system call %ld\n", orig_eax);
    ptrace(PTRACE_CONT, child, NULL, NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <main+0x58>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <ptrace@plt>
lea    0xe6d(%rip),%rdi
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execl@plt>
jmp    11f8 <main+0xa8>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0x2c,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <ptrace@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <ptrace@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11a5 <main+0x55>
mov    %rax,%rbx
xor    %edi,%edi
call   1060 <wait@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0x2c,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
jmp    11ce <main+0x7e>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
lea    0xe40(%rip),%rdi
lea    0xe3e(%rip),%rsi
xor    %edx,%edx
call   1050 <execl@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PTRACE_TRACEME = global i32 0
@.str = [8 x i8] c"/bin/ls\00"
@.str.1 = [3 x i8] c"ls\00"
@PTRACE_PEEKUSER = global i32 0
@.str.2 = [34 x i8] c"The child made a system call %ld\0A\00"
@PTRACE_CONT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @PTRACE_TRACEME
%9 = call i64 @ptrace(i32 %8, i64 0, i32 0, i32* null)
%10 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %21
11: ; preds = %0
%12 = call i32 @wait(i32* null)
%13 = load i32, i32* @PTRACE_PEEKUSER
%14 = load i64, i64* %2
%15 = call i64 @ptrace(i32 %13, i64 %14, i32 44, i32* null)
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %16)
%18 = load i32, i32* @PTRACE_CONT
%19 = load i64, i64* %2
%20 = call i64 @ptrace(i32 %18, i64 %19, i32 0, i32* null)
br label %21
21: ; preds = %11, %7
ret i32 0
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
@.str = [8 x i8] c"/bin/ls\00"
@.str.1 = [3 x i8] c"ls\00"
@PTRACE_PEEKUSER = global i32 0
@.str.2 = [34 x i8] c"The child made a system call %ld\0A\00"
@PTRACE_CONT = global i32 0
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @PTRACE_TRACEME
%5 = tail call i64 @ptrace(i32 %4, i64 0, i32 0, i32* null)
%6 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %14
7: ; preds = %0
%8 = tail call i32 @wait(i32* null)
%9 = load i32, i32* @PTRACE_PEEKUSER
%10 = tail call i64 @ptrace(i32 %9, i64 %1, i32 44, i32* null)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %10)
%12 = load i32, i32* @PTRACE_CONT
%13 = tail call i64 @ptrace(i32 %12, i64 %1, i32 0, i32* null)
br label %14
14: ; preds = %7, %3
ret i32 0
}