#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 getpid();
int /*<<< orphan*/ printf(char *, ...);
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) {
    printf("子进程ID：%d\n", getpid());
    ptrace(PTRACE_TRACEME, 0, NULL, NULL);
    printf("xxxx\n");
    execl("/bin/ls", "ls", NULL);
  } else {
    wait(NULL);
    orig_eax = ptrace(PTRACE_PEEKUSER, child, 4 * 1, 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   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11dd <main+0x7d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1050 <ptrace@plt>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe50(%rip),%rdi
lea    0xe4e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execl@plt>
jmp    122f <main+0xcf>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <ptrace@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <ptrace@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11c7 <main+0x57>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <wait@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
lea    0xe74(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
jmp    1213 <main+0xa3>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe2b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <ptrace@plt>
lea    0xe44(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0d(%rip),%rdi
lea    0xe0b(%rip),%rsi
xor    %edx,%edx
call   1070 <execl@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\E5\AD\90\E8\BF\9B\E7\A8\8BID\EF\BC\9A%d\0A\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [6 x i8] c"xxxx\0A\00"
@.str.2 = [8 x i8] c"/bin/ls\00"
@.str.3 = [3 x i8] c"ls\00"
@PTRACE_PEEKUSER = global i32 0
@.str.4 = [35 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 %14
7: ; preds = %0
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @PTRACE_TRACEME
%11 = call i64 @ptrace(i32 %10, i64 0, i32 0, i32* null)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %24
14: ; preds = %0
%15 = call i32 @wait(i32* null)
%16 = load i32, i32* @PTRACE_PEEKUSER
%17 = load i64, i64* %2
%18 = call i64 @ptrace(i32 %16, i64 %17, i32 4, i32* null)
store i64 %18, i64* %3
%19 = load i64, i64* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, 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 = %14, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"\E5\AD\90\E8\BF\9B\E7\A8\8BID\EF\BC\9A%d\0A\00"
@PTRACE_TRACEME = global i32 0
@.str.2 = [8 x i8] c"/bin/ls\00"
@.str.3 = [3 x i8] c"ls\00"
@PTRACE_PEEKUSER = global i32 0
@.str.4 = [35 x i8] c"The child made a system call %ld \0A\00"
@PTRACE_CONT = global i32 0
@str = [5 x i8] c"xxxx\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @PTRACE_TRACEME
%7 = tail call i64 @ptrace(i32 %6, i64 0, i32 0, i32* null)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %17
10: ; preds = %0
%11 = tail call i32 @wait(i32* null)
%12 = load i32, i32* @PTRACE_PEEKUSER
%13 = tail call i64 @ptrace(i32 %12, i64 %1, i32 4, i32* null)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i64 %13)
%15 = load i32, i32* @PTRACE_CONT
%16 = tail call i64 @ptrace(i32 %15, i64 %1, i32 0, i32* null)
br label %17
17: ; preds = %10, %3
ret i32 0
}