#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 ORIG_RAX;
int /*<<< orphan*/ PTRACE_CONT;
int /*<<< orphan*/ PTRACE_PEEKUSER;
int /*<<< orphan*/ PTRACE_TRACEME;
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
long ptrace(int /*<<< orphan*/, scalar_t__, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(void) {
  pid_t child;
  long orig_rax;
  child = fork();
  if (0 == child) {
    ptrace(PTRACE_TRACEME, 0, NULL, NULL);
    execl("/bin/ls", "ls", NULL);
  } else {
    wait(NULL);
    orig_rax = ptrace(PTRACE_PEEKUSER, child, 8 * ORIG_RAX, NULL);
    fprintf(stdout, "The child mode a system call %ld ", orig_rax);
    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)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11a9 <main+0x59>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <ptrace@plt>
lea    0xe6c(%rip),%rdi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execl@plt>
jmp    1209 <main+0xb9>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
shl    $0x3,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <ptrace@plt>
mov    %rax,-0x18(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe1c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2dd0(%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     11b5 <main+0x65>
mov    %rax,%rbx
xor    %edi,%edi
call   1060 <wait@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
shl    $0x3,%edx
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1040 <ptrace@plt>
mov    0x2e43(%rip),%rcx
mov    (%rcx),%edi
lea    0xe72(%rip),%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
jmp    11de <main+0x8e>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
lea    0xe30(%rip),%rdi
lea    0xe2e(%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
@ORIG_RAX = global i32 0
@stdout = global i32 0
@.str.2 = [34 x i8] c"The child mode a system call %ld \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 0, %5
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 %24
11: ; preds = %0
%12 = call i32 @wait(i32* null)
%13 = load i32, i32* @PTRACE_PEEKUSER
%14 = load i64, i64* %2
%15 = load i32, i32* @ORIG_RAX
%16 = mul nsw i32 8, %15
%17 = call i64 @ptrace(i32 %13, i64 %14, i32 %16, i32* null)
store i64 %17, i64* %3
%18 = load i32, i32* @stdout
%19 = load i64, i64* %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = load i32, i32* @PTRACE_CONT
%22 = load i64, i64* %2
%23 = call i64 @ptrace(i32 %21, i64 %22, i32 0, i32* null)
br label %24
24: ; 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
@ORIG_RAX = global i32 0
@stdout = global i32 0
@.str.2 = [34 x i8] c"The child mode a system call %ld \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 %17
7: ; preds = %0
%8 = tail call i32 @wait(i32* null)
%9 = load i32, i32* @PTRACE_PEEKUSER
%10 = load i32, i32* @ORIG_RAX
%11 = shl nsw i32 %10, 3
%12 = tail call i64 @ptrace(i32 %9, i64 %1, i32 %11, i32* null)
%13 = load i32, i32* @stdout
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %12)
%15 = load i32, i32* @PTRACE_CONT
%16 = tail call i64 @ptrace(i32 %15, i64 %1, i32 0, i32* null)
br label %17
17: ; preds = %7, %3
ret i32 0
}