#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 int /*<<< orphan*/ TracerPid;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ free(char *);
char *read_proc_file(char *);
char *strstr(char *, char const *);
int vogl_is_debugger_present() {
  int debugger_present = 0;
  char *status = read_proc_file("/proc/self/status");
  if (status) {
    static const char TracerPid[] = "TracerPid:";
    char *tracer_pid = strstr(status, TracerPid);
    if (tracer_pid)
      debugger_present = !!atoi(tracer_pid + sizeof(TracerPid) - 1);
    free(status);
  }
  return debugger_present;
}


x86 assembly (clang, -O0):
<vogl_is_debugger_present>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <read_proc_file@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b5 <vogl_is_debugger_present+0x75>
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ac <vogl_is_debugger_present+0x6c>
mov    -0x18(%rbp),%rdi
add    $0xb,%rdi
add    $0xffffffffffffffff,%rdi
call   1050 <atoi@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vogl_is_debugger_present>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1040 <read_proc_file@plt>
test   %rax,%rax
je     1181 <vogl_is_debugger_present+0x41>
mov    %rax,%rbx
lea    0xeb4(%rip),%rsi
mov    %rax,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     1185 <vogl_is_debugger_present+0x45>
add    $0xa,%rax
mov    %rax,%rdi
call   1050 <atoi@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
jmp    1187 <vogl_is_debugger_present+0x47>
xor    %ebp,%ebp
jmp    118f <vogl_is_debugger_present+0x4f>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@vogl_is_debugger_present.TracerPid = internal constant [11 x i8] c"TracerPid:\00"
define i32 @vogl_is_debugger_present() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @read_proc_file(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %24
7: ; preds = %0
%8 = load i8*, i8** %2
%9 = call i8* @strstr(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @vogl_is_debugger_present.TracerPid, i64 0, i64 0))
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 11
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = call i32 @atoi(i8* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
%19 = xor i1 %18, true
%20 = zext i1 %19 to i32
store i32 %20, i32* %1
br label %21
21: ; preds = %12, %7
%22 = load i8*, i8** %2
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %21, %0
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@vogl_is_debugger_present.TracerPid = internal constant [11 x i8] c"TracerPid:\00"
define i32 @vogl_is_debugger_present() {
%1 = tail call i8* @read_proc_file(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %14, label %3
3: ; preds = %0
%4 = tail call i8* @strstr(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @vogl_is_debugger_present.TracerPid, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 10
%8 = tail call i32 @atoi(i8* %7)
%9 = icmp ne i32 %8, 0
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %6, %3
%12 = phi i32 [ %10, %6 ], [ 0, %3 ]
%13 = tail call i32 @free(i8* %1)
br label %14
14: ; preds = %11, %0
%15 = phi i32 [ %12, %11 ], [ 0, %0 ]
ret i32 %15
}