#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*/ LOG_WARNING;
int PATH_MAX;
int /*<<< orphan*/ *realpath(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ stringstartswith(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, char *, char *);
int checkforevasion(char *gopherroot, char *localfile) {
  char resolvedpath[PATH_MAX];
  if (realpath(localfile, resolvedpath) == NULL)
    return (0);
  strcat(resolvedpath, "/");
  if (stringstartswith(resolvedpath, gopherroot) == 0) {
    syslog(LOG_WARNING,
           "Evasion check: path '%s' (%s) do not seem to belong to '%s'",
           localfile, resolvedpath, gopherroot);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<checkforevasion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <realpath@plt>
cmp    $0x0,%rax
jne    11a2 <checkforevasion+0x62>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    120b <checkforevasion+0xcb>
mov    -0x38(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <stringstartswith@plt>
cmp    $0x0,%rax
jne    11fd <checkforevasion+0xbd>
mov    -0x38(%rbp),%rcx
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%r8
lea    0xe1d(%rip),%rsi
call   1050 <syslog@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    120b <checkforevasion+0xcb>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkforevasion>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1040 <realpath@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     11c1 <checkforevasion+0x81>
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stringstartswith@plt>
test   %rax,%rax
jne    11c1 <checkforevasion+0x81>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1050 <syslog@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@LOG_WARNING = global i32 0
@.str.1 = [60 x i8] c"Evasion check: path '%s' (%s) do not seem to belong to '%s'\00"
define i32 @checkforevasion(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8*, i8** %5
%14 = call i32* @realpath(i8* %13, i8* %12)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 0, i32* %3
store i32 1, i32* %8
br label %28
17: ; preds = %2
%18 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %4
%20 = call i64 @stringstartswith(i8* %12, i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @LOG_WARNING
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* %12, i8* %25)
store i32 1, i32* %3
store i32 1, i32* %8
br label %28
27: ; preds = %17
store i32 0, i32* %3
store i32 1, i32* %8
br label %28
28: ; preds = %27, %22, %16
%29 = load i8*, i8** %6
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@LOG_WARNING = global i32 0
@.str.1 = [60 x i8] c"Evasion check: path '%s' (%s) do not seem to belong to '%s'\00"
define i32 @checkforevasion(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32* @realpath(i8* %1, i8* %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i64 @stringstartswith(i8* %5, i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @LOG_WARNING
%14 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %5, i8* %0)
br label %15
15: ; preds = %8, %2, %12
%16 = phi i32 [ 1, %12 ], [ 0, %2 ], [ 0, %8 ]
ret i32 %16
}