#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t strlen(char *);
scalar_t__ strstr(char *, char *);
int check_if_allowed(char *path) {
  FILE *fp;
  char buf[4096];
  int allowed = 1;
  if (access("/etc/proftpd/libhook.deny", R_OK)) {
    return allowed;
  }
  fp = fopen("/etc/proftpd/libhook.deny", "r");
  while (fgets(buf, 4096, fp)) {
    buf[strlen(buf)] = '\0';
    if (strstr(path, buf)) {
      allowed = 0;
      break;
    }
    if (strstr(buf, "ALL")) {
      allowed = 0;
      break;
    }
  }
  fclose(fp);
  return allowed;
}


x86 assembly (clang, -O0):
<check_if_allowed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x1024(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe77(%rip),%rdi
call   1060 <access@plt>
cmp    $0x0,%rax
je     11a6 <check_if_allowed+0x46>
mov    -0x1024(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125c <check_if_allowed+0xfc>
lea    0xe53(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     124a <check_if_allowed+0xea>
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
movb   $0x0,-0x1020(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1219 <check_if_allowed+0xb9>
movl   $0x0,-0x1024(%rbp)
jmp    124a <check_if_allowed+0xea>
lea    -0x1020(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1245 <check_if_allowed+0xe5>
movl   $0x0,-0x1024(%rbp)
jmp    124a <check_if_allowed+0xea>
jmp    11bd <check_if_allowed+0x5d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1024(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_if_allowed>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r14
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1060 <access@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1210 <check_if_allowed+0xb0>
lea    0xe68(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rbx
lea    0xe6b(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1203 <check_if_allowed+0xa3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
jne    1208 <check_if_allowed+0xa8>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11c0 <check_if_allowed+0x60>
jmp    1208 <check_if_allowed+0xa8>
mov    $0x1,%ebp
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"/etc/proftpd/libhook.deny\00"
@R_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"ALL\00"
define i32 @check_if_allowed(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4096 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 1, i32* %6
%7 = load i32, i32* @R_OK
%8 = call i64 @access(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %6
store i32 %11, i32* %2
br label %38
12: ; preds = %1
%13 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %4
br label %14
14: ; preds = %33, %12
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i64 @fgets(i8* %15, i32 4096, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %34
19: ; preds = %14
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %3
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%25 = call i64 @strstr(i8* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 0, i32* %6
br label %34
28: ; preds = %19
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%30 = call i64 @strstr(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 0, i32* %6
br label %34
33: ; preds = %28
br label %14
34: ; preds = %32, %27, %14
%35 = load i32*, i32** %4
%36 = call i32 @fclose(i32* %35)
%37 = load i32, i32* %6
store i32 %37, i32* %2
br label %38
38: ; preds = %34, %10
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [26 x i8] c"/etc/proftpd/libhook.deny\00"
@R_OK = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"ALL\00"
define i32 @check_if_allowed(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @R_OK
%5 = tail call i64 @access(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %1
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %17, %7
%10 = call i64 @fgets(i8* %3, i32 4096, i32* %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = call i64 @strlen(i8* %3)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i64 @strstr(i8* %0, i8* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i64 @strstr(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %9, label %20
20: ; preds = %17, %12, %9
%21 = phi i32 [ 1, %9 ], [ 0, %12 ], [ 0, %17 ]
%22 = call i32 @fclose(i32* %8)
br label %23
23: ; preds = %1, %20
%24 = phi i32 [ %21, %20 ], [ 1, %1 ]
ret i32 %24
}