#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_TRACEME;
int /*<<< orphan*/ printf(char *);
scalar_t__ ptrace(int /*<<< orphan*/, int /*<<< orphan*/, int,
                  int /*<<< orphan*/);
int main() {
  printf("Requesting to be traced...\n");
  if (ptrace(PTRACE_TRACEME, 0, 1, 0) < 0)
    printf("ptrace() failed - DEBUGGER DETECTED!\n");
  else
    printf("It looks like I'm not being traced, ALL IS GOOD!\n");
  printf("\nAll done!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    $0x1,%edx
mov    %ecx,%esi
call   1040 <ptrace@plt>
cmp    $0x0,%rax
jge    116d <main+0x4d>
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
jmp    1179 <main+0x59>
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
lea    0xef4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2eac(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <ptrace@plt>
test   %rax,%rax
lea    0xf09(%rip),%rax
lea    0xec6(%rip),%rdi
cmovs  %rax,%rdi
call   1030 <puts@plt>
lea    0xee7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Requesting to be traced...\0A\00"
@PTRACE_TRACEME = global i32 0
@.str.1 = [38 x i8] c"ptrace() failed - DEBUGGER DETECTED!\0A\00"
@.str.2 = [50 x i8] c"It looks like I'm not being traced, ALL IS GOOD!\0A\00"
@.str.3 = [12 x i8] c"\0AAll done!\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @PTRACE_TRACEME
%4 = call i64 @ptrace(i32 %3, i32 0, i32 1, i32 0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@PTRACE_TRACEME = global i32 0
@str = [27 x i8] c"Requesting to be traced...\00"
@str.4 = [49 x i8] c"It looks like I'm not being traced, ALL IS GOOD!\00"
@str.5 = [11 x i8] c"\0AAll done!\00"
@str.6 = [37 x i8] c"ptrace() failed - DEBUGGER DETECTED!\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%2 = load i32, i32* @PTRACE_TRACEME
%3 = tail call i64 @ptrace(i32 %2, i32 0, i32 1, i32 0)
%4 = icmp slt i64 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([49 x i8], [49 x i8]* @str.4, i64 0, i64 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}