#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*/ bzero(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int allowed_site(const char *site) {
  FILE *file = fopen("parental_controls.log", "r");
  int result = 0;
  if (file) {
    char buf[64];
    bzero(buf, sizeof(buf));
    char *line = fgets(buf, sizeof(buf), file);
    while (line != NULL) {
      int len1 = strlen(buf);
      int len2 = strlen(site);
      int len = len1 > len2 ? len2 : len1;
      if (strncmp(site, buf, len) == 0) {
        result = 0;
        break;
      } else {
        result = -1;
      }
      line = fgets(buf, sizeof(buf), file);
    }
    fclose(file);
  }
  return result;
}


x86 assembly (clang, -O0):
<allowed_site>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1253 <allowed_site+0xf3>
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
call   1080 <bzero@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40,%esi
call   1060 <fgets@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     124a <allowed_site+0xea>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x70(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x70(%rbp),%eax
jle    11f6 <allowed_site+0x96>
mov    -0x70(%rbp),%eax
mov    %eax,-0x78(%rbp)
jmp    11fc <allowed_site+0x9c>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1228 <allowed_site+0xc8>
movl   $0x0,-0x14(%rbp)
jmp    124a <allowed_site+0xea>
movl   $0xffffffff,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40,%esi
call   1060 <fgets@plt>
mov    %rax,-0x68(%rbp)
jmp    11bc <allowed_site+0x5c>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allowed_site>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%r12
lea    0xe8a(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     120e <allowed_site+0xae>
mov    %rax,%r14
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
call   1080 <bzero@plt>
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     1204 <allowed_site+0xa4>
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebx
cmovg  %eax,%ebx
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1204 <allowed_site+0xa4>
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11c0 <allowed_site+0x60>
mov    $0xffffffff,%r15d
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1211 <allowed_site+0xb1>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"parental_controls.log\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @allowed_site(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [64 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
%10 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
store i32 0, i32* %4
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %50
13: ; preds = %1
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%15 = call i32 @bzero(i8* %14, i32 64)
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i8* @fgets(i8* %16, i32 64, i32* %17)
store i8* %18, i8** %6
br label %19
19: ; preds = %43, %13
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %47
22: ; preds = %19
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %7
%25 = load i8*, i8** %2
%26 = call i32 @strlen(i8* %25)
store i32 %26, i32* %8
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = icmp sgt i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %22
%31 = load i32, i32* %8
br label %34
32: ; preds = %22
%33 = load i32, i32* %7
br label %34
34: ; preds = %32, %30
%35 = phi i32 [ %31, %30 ], [ %33, %32 ]
store i32 %35, i32* %9
%36 = load i8*, i8** %2
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* %9
%39 = call i64 @strncmp(i8* %36, i8* %37, i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %34
store i32 0, i32* %4
br label %47
42: ; preds = %34
store i32 -1, i32* %4
br label %43
43: ; preds = %42
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%45 = load i32*, i32** %3
%46 = call i8* @fgets(i8* %44, i32 64, i32* %45)
store i8* %46, i8** %6
br label %19
47: ; preds = %41, %19
%48 = load i32*, i32** %3
%49 = call i32 @fclose(i32* %48)
br label %50
50: ; preds = %47, %1
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [22 x i8] c"parental_controls.log\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @allowed_site(i8* %0) {
%2 = alloca [64 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 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 %23, label %5
5: ; preds = %1
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 64)
%8 = call i8* @fgets(i8* %6, i32 64, i32* %3)
%9 = icmp eq i8* %8, null
br i1 %9, label %20, label %10
10: ; preds = %5, %17
%11 = call i32 @strlen(i8* %6)
%12 = call i32 @strlen(i8* %0)
%13 = icmp sgt i32 %11, %12
%14 = select i1 %13, i32 %12, i32 %11
%15 = call i64 @strncmp(i8* %0, i8* %6, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = call i8* @fgets(i8* %6, i32 64, i32* %3)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %10
20: ; preds = %17, %10, %5
%21 = phi i32 [ 0, %5 ], [ 0, %10 ], [ -1, %17 ]
%22 = call i32 @fclose(i32* %3)
br label %23
23: ; preds = %20, %1
%24 = phi i32 [ %21, %20 ], [ 0, %1 ]
ret i32 %24
}