#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 enum __ptrace_request {
  ____Placeholder___ptrace_request
} __ptrace_request;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
#define PTRACE_ATTACH 139
#define PTRACE_CONT 138
#define PTRACE_DETACH 137
#define PTRACE_GETREGS 136
#define PTRACE_KILL 135
#define PTRACE_PEEKTEXT 134
#define PTRACE_PEEKUSER 133
#define PTRACE_POKETEXT 132
#define PTRACE_POKEUSER 131
#define PTRACE_SETREGS 130
#define PTRACE_SINGLESTEP 129
#define PTRACE_TRACEME 128
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
long ptrace(enum __ptrace_request request, ...) {
  char *request_str = 0;
  switch (request) {
  case PTRACE_TRACEME:
    request_str = "PTRACE_TRACEME";
    break;
  case PTRACE_ATTACH:
    request_str = "PTRACE_ATTACH";
    break;
  case PTRACE_KILL:
    request_str = "PTRACE_KILL";
    break;
  case PTRACE_DETACH:
    request_str = "PTRACE_DETACH";
    break;
  case PTRACE_SINGLESTEP:
    request_str = "PTRACE_SINGLESTEP";
    break;
  case PTRACE_CONT:
    request_str = "PTRACE_CONT";
    break;
  case PTRACE_PEEKTEXT:
    request_str = "PTRACE_PEEKTEXT";
    break;
  case PTRACE_POKETEXT:
    request_str = "PTRACE_POKETEXT";
    break;
  case PTRACE_PEEKUSER:
    request_str = "PTRACE_PEEKUSER";
    break;
  case PTRACE_POKEUSER:
    request_str = "PTRACE_POKEUSER";
    break;
  case PTRACE_GETREGS:
    request_str = "PTRACE_GETREGS";
    break;
  case PTRACE_SETREGS:
    request_str = "PTRACE_SETREGS";
    break;
  }
  printf("ptrace(%s) called - not implemented!\n", request_str);
  errno = EINVAL;
  return -1;
}


x86 assembly (clang, -O0):
<ptrace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0xb,%eax
ja     1207 <ptrace+0xf7>
mov    -0x18(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xedd(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xedc(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xeda(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed6(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed4(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed6(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed2(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed2(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed2(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed2(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed2(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1207 <ptrace+0xf7>
lea    0xed1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%ecx
mov    0x2db9(%rip),%rax
mov    %ecx,(%rax)
mov    $0xffffffffffffffff,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptrace>:
push   %rax
add    $0xffffff80,%edi
cmp    $0xb,%edi
ja     112c <ptrace+0x1c>
movslq %edi,%rax
lea    0xfb9(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
jmp    112e <ptrace+0x1e>
xor    %esi,%esi
lea    0xf7e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    0x2e96(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffffffffffff,%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"PTRACE_TRACEME\00"
@.str.1 = [14 x i8] c"PTRACE_ATTACH\00"
@.str.2 = [12 x i8] c"PTRACE_KILL\00"
@.str.3 = [14 x i8] c"PTRACE_DETACH\00"
@.str.4 = [18 x i8] c"PTRACE_SINGLESTEP\00"
@.str.5 = [12 x i8] c"PTRACE_CONT\00"
@.str.6 = [16 x i8] c"PTRACE_PEEKTEXT\00"
@.str.7 = [16 x i8] c"PTRACE_POKETEXT\00"
@.str.8 = [16 x i8] c"PTRACE_PEEKUSER\00"
@.str.9 = [16 x i8] c"PTRACE_POKEUSER\00"
@.str.10 = [15 x i8] c"PTRACE_GETREGS\00"
@.str.11 = [15 x i8] c"PTRACE_SETREGS\00"
@.str.12 = [38 x i8] c"ptrace(%s) called - not implemented!\0A\00"
@EINVAL = global i32 0
@errno = global i32 0
define i64 @ptrace(i32 %0, ...) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
store i8* null, i8** %3
%4 = load i32, i32* %2
switch i32 %4, label %17 [
i32 128, label %5
i32 139, label %6
i32 135, label %7
i32 137, label %8
i32 129, label %9
i32 138, label %10
i32 134, label %11
i32 132, label %12
i32 133, label %13
i32 131, label %14
i32 136, label %15
i32 130, label %16
]
5: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %3
br label %17
6: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %17
7: ; preds = %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %17
8: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %17
9: ; preds = %1
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %17
10: ; preds = %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %17
11: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %17
12: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8** %3
br label %17
13: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8** %3
br label %17
14: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i8** %3
br label %17
15: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8** %3
br label %17
16: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8** %3
br label %17
17: ; preds = %1, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EINVAL
store i32 %20, i32* @errno
ret i64 -1
}

LLVM IR (-O2):
@.str = [15 x i8] c"PTRACE_TRACEME\00"
@.str.1 = [14 x i8] c"PTRACE_ATTACH\00"
@.str.2 = [12 x i8] c"PTRACE_KILL\00"
@.str.3 = [14 x i8] c"PTRACE_DETACH\00"
@.str.4 = [18 x i8] c"PTRACE_SINGLESTEP\00"
@.str.5 = [12 x i8] c"PTRACE_CONT\00"
@.str.6 = [16 x i8] c"PTRACE_PEEKTEXT\00"
@.str.7 = [16 x i8] c"PTRACE_POKETEXT\00"
@.str.8 = [16 x i8] c"PTRACE_PEEKUSER\00"
@.str.9 = [16 x i8] c"PTRACE_POKEUSER\00"
@.str.10 = [15 x i8] c"PTRACE_GETREGS\00"
@.str.11 = [15 x i8] c"PTRACE_SETREGS\00"
@.str.12 = [38 x i8] c"ptrace(%s) called - not implemented!\0A\00"
@EINVAL = global i32 0
@errno = global i32 0
@reltable.ptrace = [12 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.4 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.11 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.9 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.7 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.8 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.6 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.2 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @.str.10 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.3 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.5 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.1 to i64), i64 ptrtoint ([12 x i32]* @reltable.ptrace to i64)) to i32)]
define i64 @ptrace(i32 %0, ...) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 12
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([12 x i32]* @reltable.ptrace to i8*), i64 %6)
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ null, %1 ], [ %7, %4 ]
%10 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EINVAL
store i32 %11, i32* @errno
ret i64 -1
}