#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*/ access_ok(char const *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int path_ok(char *pathname, const char *p) {
  if (!access_ok(p, (1337 - 1080)))
    return 0;
  memcpy(pathname, p, (1337 - 1080));
  pathname[(1337 - 1080) - 1] = '\x00';
  if (strstr(pathname, "flag") != NULL)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<path_ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x101,%esi
call   1040 <access_ok@plt>
cmp    $0x0,%eax
jne    1163 <path_ok+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11ad <path_ok+0x7d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x101,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x100(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11a6 <path_ok+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11ad <path_ok+0x7d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_ok>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x101,%esi
call   1040 <access_ok@plt>
test   %eax,%eax
je     117f <path_ok+0x4f>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x101,%edx
call   1030 <memcpy@plt>
movb   $0x0,0x100(%r14)
lea    0xe96(%rip),%rsi
mov    %r14,%rdi
call   1050 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1181 <path_ok+0x51>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"flag\00"
define i32 @path_ok(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = call i32 @access_ok(i8* %6, i32 257)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 0, i32* %3
br label %21
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i32 @memcpy(i8* %11, i8* %12, i32 257)
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 256
store i8 0, i8* %15
%16 = load i8*, i8** %4
%17 = call i32* @strstr(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %10
store i32 0, i32* %3
br label %21
20: ; preds = %10
store i32 1, i32* %3
br label %21
21: ; preds = %20, %19, %9
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [5 x i8] c"flag\00"
define i32 @path_ok(i8* %0, i8* %1) {
%3 = tail call i32 @access_ok(i8* %1, i32 257)
%4 = icmp eq i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i32 @memcpy(i8* %0, i8* %1, i32 257)
%7 = getelementptr inbounds i8, i8* %0, i64 256
store i8 0, i8* %7
%8 = tail call i32* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %5, %2
%12 = phi i32 [ 0, %2 ], [ %10, %5 ]
ret i32 %12
}