#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 */

/* Variables and functions */
int /*<<< orphan*/ PTRACE_ATTACH;
int /*<<< orphan*/ PTRACE_DETACH;
unsigned long *PTRACE_O_TRACESYSGOOD;
int /*<<< orphan*/ PTRACE_PEEKDATA;
int /*<<< orphan*/ PTRACE_SETOPTIONS;
int /*<<< orphan*/ PTRACE_SYSCALL;
int /*<<< orphan*/ PTRACE_TRACEME;
int ptrace(int /*<<< orphan*/, ...);
int main(void) {
  int pid = 1, ret;
  void *addr = ((void *)0);
  unsigned long data;
  ret = ptrace(PTRACE_SYSCALL, pid, 0, 0);
  (void)ret;
  ret = ptrace(PTRACE_TRACEME);
  (void)ret;
  ret = ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACESYSGOOD);
  (void)ret;
  ret = ptrace(PTRACE_ATTACH, pid, ((void *)0), ((void *)0));
  (void)ret;
  ret = ptrace(PTRACE_DETACH, pid, ((void *)0), ((void *)0));
  (void)ret;
  ret = ptrace(PTRACE_PEEKDATA, pid, addr, &data);
  (void)ret;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
mov    $0x0,%al
call   1030 <ptrace@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    $0x0,%al
call   1030 <ptrace@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    0x2e72(%rip),%rax
mov    (%rax),%rcx
xor    %edx,%edx
mov    $0x0,%al
call   1030 <ptrace@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
mov    $0x0,%al
call   1030 <ptrace@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
mov    $0x0,%al
call   1030 <ptrace@plt>
mov    %eax,-0xc(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1030 <ptrace@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <ptrace@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1030 <ptrace@plt>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    0x2e96(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <ptrace@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <ptrace@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <ptrace@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rcx
mov    $0x1,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1030 <ptrace@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@PTRACE_SYSCALL = global i32 0
@PTRACE_TRACEME = global i32 0
@PTRACE_SETOPTIONS = global i32 0
@PTRACE_O_TRACESYSGOOD = global i64* null
@PTRACE_ATTACH = global i32 0
@PTRACE_DETACH = global i32 0
@PTRACE_PEEKDATA = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
store i32 1, i32* %2
store i8* null, i8** %4
%6 = load i32, i32* @PTRACE_SYSCALL
%7 = load i32, i32* %2
%8 = call i32 (i32, ...) @ptrace(i32 %6, i32 %7, i32 0, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = load i32, i32* @PTRACE_TRACEME
%11 = call i32 (i32, ...) @ptrace(i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = load i32, i32* @PTRACE_SETOPTIONS
%14 = load i32, i32* %2
%15 = load i64*, i64** @PTRACE_O_TRACESYSGOOD
%16 = call i32 (i32, ...) @ptrace(i32 %13, i32 %14, i32 0, i64* %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = load i32, i32* @PTRACE_ATTACH
%19 = load i32, i32* %2
%20 = call i32 (i32, ...) @ptrace(i32 %18, i32 %19, i8* null, i8* null)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = load i32, i32* @PTRACE_DETACH
%23 = load i32, i32* %2
%24 = call i32 (i32, ...) @ptrace(i32 %22, i32 %23, i8* null, i8* null)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = load i32, i32* @PTRACE_PEEKDATA
%27 = load i32, i32* %2
%28 = load i8*, i8** %4
%29 = call i32 (i32, ...) @ptrace(i32 %26, i32 %27, i8* %28, i64* %5)
store i32 %29, i32* %3
%30 = load i32, i32* %3
ret i32 0
}

LLVM IR (-O2):
@PTRACE_SYSCALL = global i32 0
@PTRACE_TRACEME = global i32 0
@PTRACE_SETOPTIONS = global i32 0
@PTRACE_O_TRACESYSGOOD = global i64* null
@PTRACE_ATTACH = global i32 0
@PTRACE_DETACH = global i32 0
@PTRACE_PEEKDATA = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = load i32, i32* @PTRACE_SYSCALL
%4 = tail call i32 (i32, ...) @ptrace(i32 %3, i32 1, i32 0, i32 0)
%5 = load i32, i32* @PTRACE_TRACEME
%6 = tail call i32 (i32, ...) @ptrace(i32 %5)
%7 = load i32, i32* @PTRACE_SETOPTIONS
%8 = load i64*, i64** @PTRACE_O_TRACESYSGOOD
%9 = tail call i32 (i32, ...) @ptrace(i32 %7, i32 1, i32 0, i64* %8)
%10 = load i32, i32* @PTRACE_ATTACH
%11 = tail call i32 (i32, ...) @ptrace(i32 %10, i32 1, i8* null, i8* null)
%12 = load i32, i32* @PTRACE_DETACH
%13 = tail call i32 (i32, ...) @ptrace(i32 %12, i32 1, i8* null, i8* null)
%14 = load i32, i32* @PTRACE_PEEKDATA
%15 = call i32 (i32, ...) @ptrace(i32 %14, i32 1, i8* null, i64* %1)
ret i32 0
}