#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strcmp(char *, char *);
bool isdebugged(void) {
  FILE *fp;
  char buf[4096];
  bool ret;
  fp = fopen("/proc/self/status", "r");
  if (!fp)
    return false;
  ret = true;
  while (fgets(buf, sizeof(buf), fp)) {
    if (strcmp(buf, "TracerPid:\t0\n") == 0) {
      ret = false;
      break;
    }
  }
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<isdebugged>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <isdebugged+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <isdebugged+0xa5>
movl   $0x1,-0x1014(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11d3 <isdebugged+0x93>
lea    -0x1010(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ce <isdebugged+0x8e>
movl   $0x0,-0x1014(%rbp)
jmp    11d3 <isdebugged+0x93>
jmp    1183 <isdebugged+0x43>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1014(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isdebugged>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xead(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a9 <isdebugged+0x69>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xea3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11ad <isdebugged+0x6d>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1180 <isdebugged+0x40>
xor    %ebx,%ebx
jmp    11b2 <isdebugged+0x72>
xor    %ebx,%ebx
jmp    11ba <isdebugged+0x7a>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"TracerPid:\090\0A\00"
define i32 @isdebugged() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 0, i32* %1
br label %25
9: ; preds = %0
store i32 1, i32* %4
br label %10
10: ; preds = %20, %9
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i64 @fgets(i8* %11, i32 4096, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %4
br label %21
20: ; preds = %15
br label %10
21: ; preds = %19, %10
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %4
store i32 %24, i32* %1
br label %25
25: ; preds = %21, %8
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/self/status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"TracerPid:\090\0A\00"
define i32 @isdebugged() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %14, label %5
5: ; preds = %0, %8
%6 = call i64 @fgets(i8* %2, i32 4096, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %5
11: ; preds = %8, %5
%12 = phi i32 [ 1, %5 ], [ 0, %8 ]
%13 = call i32 @fclose(i32* %3)
br label %14
14: ; preds = %0, %11
%15 = phi i32 [ %12, %11 ], [ 0, %0 ]
ret i32 %15
}