#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*/ EACCES;
int PATH_MAX;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
char *realpath(char const *, char *);
int /*<<< orphan*/ stderr;
char *strchrnul(char const *, char);
scalar_t__ strncmp(char const *, char *, int);
int allowed_match(const char *path, const char *okpath) {
  char resolvedBuf[PATH_MAX];
  char *resolved = realpath(path, resolvedBuf);
  if (resolved == NULL) {
    return 0;
  }
  while (*okpath) {
    const char *end = strchrnul(okpath, ':');
    if (strncmp(okpath, resolved, end - okpath) == 0)
      return 1;
    okpath = end;
    while (*okpath == ':')
      ++okpath;
  }
  fprintf(stderr, "Access to \"%s\" denied by gcc-explorer policy\n", path);
  errno = EACCES;
  return 0;
}


x86 assembly (clang, -O0):
<allowed_match>:
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,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <realpath@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a3 <allowed_match+0x63>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1265 <allowed_match+0x125>
jmp    11a8 <allowed_match+0x68>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     122c <allowed_match+0xec>
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchrnul@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11fe <allowed_match+0xbe>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1265 <allowed_match+0x125>
mov    -0x40(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1227 <allowed_match+0xe7>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1206 <allowed_match+0xc6>
jmp    11a8 <allowed_match+0x68>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdc0(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%ecx
mov    0x2d73(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allowed_match>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rsi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rsi
mov    %rsi,%rsp
call   1060 <realpath@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11ea <allowed_match+0xaa>
cmpb   $0x0,(%rbx)
je     11c0 <allowed_match+0x80>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchrnul@plt>
mov    %rax,%r13
mov    %r13d,%edx
sub    %ebx,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strncmp@plt>
test   %rax,%rax
je     11fc <allowed_match+0xbc>
add    $0xffffffffffffffff,%r13
mov    %r13,%rbx
nop
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x3a,%al
je     11b0 <allowed_match+0x70>
test   %al,%al
jne    1183 <allowed_match+0x43>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    0x2de0(%rip),%rcx
mov    %eax,(%rcx)
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r14d
jmp    11ea <allowed_match+0xaa>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"Access to \22%s\22 denied by gcc-explorer policy\0A\00"
@EACCES = global i32 0
@errno = global i32 0
define i32 @allowed_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i8*, i8** %4
%16 = call i8* @realpath(i8* %15, i8* %14)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 0, i32* %3
store i32 1, i32* %9
br label %55
20: ; preds = %2
br label %21
21: ; preds = %49, %20
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = call i8* @strchrnul(i8* %26, i8 signext 58)
store i8* %27, i8** %10
%28 = load i8*, i8** %5
%29 = load i8*, i8** %8
%30 = load i8*, i8** %10
%31 = load i8*, i8** %5
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @strncmp(i8* %28, i8* %29, i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %25
store i32 1, i32* %3
store i32 1, i32* %9
br label %55
39: ; preds = %25
%40 = load i8*, i8** %10
store i8* %40, i8** %5
br label %41
41: ; preds = %46, %39
%42 = load i8*, i8** %5
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 58
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %5
br label %41
49: ; preds = %41
br label %21
50: ; preds = %21
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %4
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EACCES
store i32 %54, i32* @errno
store i32 0, i32* %3
store i32 1, i32* %9
br label %55
55: ; preds = %50, %38, %19
%56 = load i8*, i8** %6
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"Access to \22%s\22 denied by gcc-explorer policy\0A\00"
@EACCES = global i32 0
@errno = global i32 0
define i32 @allowed_match(i8* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i8* @realpath(i8* %0, i8* %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %28, label %8
8: ; preds = %2
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %20, %8
%12 = phi i8* [ %1, %8 ], [ %21, %20 ]
%13 = call i8* @strchrnul(i8* %12, i8 signext 58)
%14 = ptrtoint i8* %13 to i64
%15 = ptrtoint i8* %12 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @strncmp(i8* %12, i8* %6, i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %11, %20
%21 = phi i8* [ %23, %20 ], [ %13, %11 ]
%22 = load i8, i8* %21
%23 = getelementptr inbounds i8, i8* %21, i64 1
switch i8 %22, label %11 [
i8 58, label %20
i8 0, label %24
]
24: ; preds = %20, %8
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0)
%27 = load i32, i32* @EACCES
store i32 %27, i32* @errno
br label %28
28: ; preds = %11, %2, %24
%29 = phi i32 [ 0, %24 ], [ 0, %2 ], [ 1, %11 ]
ret i32 %29
}