#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 */
struct match_tree_head {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fread(char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ match_tree_add_pattern(struct match_tree_head *, char *,
                                          unsigned int);
struct match_tree_head *match_tree_init();
int /*<<< orphan*/ memcpy(char *, char const *, unsigned int);
__attribute((unused)) struct match_tree_head *
match_tree_init_from_file(const char *file_name, const char *delimiter,
                          unsigned int delimiter_len) {
  FILE *fp = NULL;
  char *file_content = NULL;
  unsigned int file_content_len = 0;
  unsigned int i = 0;
  unsigned int j = 0;
  unsigned int is_delimiter = 0;
  char *pattern = NULL;
  unsigned int pattern_len = 0;
  struct match_tree_head *head = NULL;
  if (delimiter == NULL || delimiter_len == 0) {
    return NULL;
  }
  fp = fopen(file_name, "rb");
  if (!fp) {
    return NULL;
  }
  fseek(fp, 0, SEEK_END);
  file_content_len = ftell(fp);
  file_content = (char *)malloc(file_content_len + delimiter_len + 1);
  fseek(fp, 0, SEEK_SET);
  file_content_len = (unsigned int)fread(file_content, 1, file_content_len, fp);
  fclose(fp);
  fp = NULL;
  memcpy(file_content + file_content_len, delimiter, delimiter_len);
  file_content[file_content_len + delimiter_len] = '\0';
  file_content_len += delimiter_len;
  head = match_tree_init();
  pattern = file_content;
  i = 0;
  while (i + delimiter_len <= file_content_len) {
    is_delimiter = 1;
    for (j = 0; j < delimiter_len; j++) {
      if (file_content[i + j] != delimiter[j]) {
        is_delimiter = 0;
        break;
      }
    }
    if (is_delimiter) {
      pattern_len = (unsigned int)(file_content + i - pattern);
      match_tree_add_pattern(head, pattern, pattern_len);
      i = i + delimiter_len;
      pattern = file_content + i;
    } else {
      i++;
    }
  }
  free(file_content);
  file_content = NULL;
  file_content_len = 0;
  return head;
}


x86 assembly (clang, -O0):
<match_tree_init_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movq   $0x0,-0x58(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120b <match_tree_init_from_file+0x6b>
cmpl   $0x0,-0x1c(%rbp)
jne    1218 <match_tree_init_from_file+0x78>
movq   $0x0,-0x8(%rbp)
jmp    13df <match_tree_init_from_file+0x23f>
mov    -0x10(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1244 <match_tree_init_from_file+0xa4>
movq   $0x0,-0x8(%rbp)
jmp    13df <match_tree_init_from_file+0x23f>
mov    -0x28(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x1c(%rbp),%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1060 <match_tree_init@plt>
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x34(%rbp),%eax
ja     13bf <match_tree_init_from_file+0x21f>
movl   $0x1,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1367 <match_tree_init_from_file+0x1c7>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    -0x3c(%rbp),%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x3c(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1354 <match_tree_init_from_file+0x1b4>
movl   $0x0,-0x40(%rbp)
jmp    1367 <match_tree_init_from_file+0x1c7>
jmp    1359 <match_tree_init_from_file+0x1b9>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1319 <match_tree_init_from_file+0x179>
cmpl   $0x0,-0x40(%rbp)
je     13b1 <match_tree_init_from_file+0x211>
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    %rcx,%rax
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4c(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   10c0 <match_tree_add_pattern@plt>
mov    -0x38(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    13ba <match_tree_init_from_file+0x21a>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12fc <match_tree_init_from_file+0x15c>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_tree_init_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
mov    %rax,0x8(%rsp)
test   %rsi,%rsi
je     1289 <match_tree_init_from_file+0xe9>
test   %edx,%edx
je     1289 <match_tree_init_from_file+0xe9>
mov    %rsi,%r15
mov    %rdx,0x10(%rsp)
lea    0xe2b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1282 <match_tree_init_from_file+0xe2>
mov    %rax,%r13
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r13,%rdi
call   1070 <ftell@plt>
mov    %eax,%r12d
mov    0x10(%rsp),%r14
lea    (%r14,%r12,1),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0x2db7(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
mov    %rax,%r12
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r12d,%edi
add    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1080 <memcpy@plt>
lea    (%r12,%r14,1),%eax
movb   $0x0,(%rbx,%rax,1)
xor    %eax,%eax
call   1060 <match_tree_init@plt>
mov    %r14,%rdi
mov    %rax,0x8(%rsp)
add    %edi,%r12d
jae    129d <match_tree_init_from_file+0xfd>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1289 <match_tree_init_from_file+0xe9>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
mov    0x8(%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%r13d
mov    %edi,%r14d
mov    %rbx,%rsi
jmp    12c2 <match_tree_init_from_file+0x122>
nopl   0x0(%rax,%rax,1)
add    $0x1,%edx
mov    %edx,%r14d
mov    %r14d,%ebp
lea    (%rdi,%rbp,1),%r14d
cmp    %r12d,%r14d
ja     1278 <match_tree_init_from_file+0xd8>
mov    %ebp,%edx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
lea    (%rdx,%rax,1),%ecx
movzbl (%rbx,%rcx,1),%ecx
cmp    (%r15,%rax,1),%cl
jne    12b0 <match_tree_init_from_file+0x110>
add    $0x1,%rax
cmp    %rax,%r13
jne    12d0 <match_tree_init_from_file+0x130>
add    %ebx,%edx
sub    %esi,%edx
mov    0x8(%rsp),%rdi
call   10c0 <match_tree_add_pattern@plt>
mov    0x10(%rsp),%rdi
mov    %r14d,%esi
add    %rbx,%rsi
jmp    12b6 <match_tree_init_from_file+0x116>

LLVM IR (-O0):
%struct.match_tree_head = type { i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.match_tree_head* @match_tree_init_from_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.match_tree_head*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca %struct.match_tree_head*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* null, i32** %8
store i8* null, i8** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i8* null, i8** %14
store i32 0, i32* %15
store %struct.match_tree_head* null, %struct.match_tree_head** %16
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19, %3
store %struct.match_tree_head* null, %struct.match_tree_head** %4
br label %133
23: ; preds = %19
%24 = load i8*, i8** %5
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %8
%26 = load i32*, i32** %8
%27 = icmp ne i32* %26, null
br i1 %27, label %29, label %28
28: ; preds = %23
store %struct.match_tree_head* null, %struct.match_tree_head** %4
br label %133
29: ; preds = %23
%30 = load i32*, i32** %8
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
%33 = load i32*, i32** %8
%34 = call i32 @ftell(i32* %33)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = load i32, i32* %7
%37 = add i32 %35, %36
%38 = add i32 %37, 1
%39 = call i64 @malloc(i32 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %9
%41 = load i32*, i32** %8
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @fseek(i32* %41, i32 0, i32 %42)
%44 = load i8*, i8** %9
%45 = load i32, i32* %10
%46 = load i32*, i32** %8
%47 = call i64 @fread(i8* %44, i32 1, i32 %45, i32* %46)
%48 = trunc i64 %47 to i32
store i32 %48, i32* %10
%49 = load i32*, i32** %8
%50 = call i32 @fclose(i32* %49)
store i32* null, i32** %8
%51 = load i8*, i8** %9
%52 = load i32, i32* %10
%53 = zext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8*, i8** %6
%56 = load i32, i32* %7
%57 = call i32 @memcpy(i8* %54, i8* %55, i32 %56)
%58 = load i8*, i8** %9
%59 = load i32, i32* %10
%60 = load i32, i32* %7
%61 = add i32 %59, %60
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %58, i64 %62
store i8 0, i8* %63
%64 = load i32, i32* %7
%65 = load i32, i32* %10
%66 = add i32 %65, %64
store i32 %66, i32* %10
%67 = call %struct.match_tree_head* (...) @match_tree_init()
store %struct.match_tree_head* %67, %struct.match_tree_head** %16
%68 = load i8*, i8** %9
store i8* %68, i8** %14
store i32 0, i32* %11
br label %69
69: ; preds = %128, %29
%70 = load i32, i32* %11
%71 = load i32, i32* %7
%72 = add i32 %70, %71
%73 = load i32, i32* %10
%74 = icmp ule i32 %72, %73
br i1 %74, label %75, label %129
75: ; preds = %69
store i32 1, i32* %13
store i32 0, i32* %12
br label %76
76: ; preds = %98, %75
%77 = load i32, i32* %12
%78 = load i32, i32* %7
%79 = icmp ult i32 %77, %78
br i1 %79, label %80, label %101
80: ; preds = %76
%81 = load i8*, i8** %9
%82 = load i32, i32* %11
%83 = load i32, i32* %12
%84 = add i32 %82, %83
%85 = zext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %81, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = load i8*, i8** %6
%90 = load i32, i32* %12
%91 = zext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %89, i64 %91
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp ne i32 %88, %94
br i1 %95, label %96, label %97
96: ; preds = %80
store i32 0, i32* %13
br label %101
97: ; preds = %80
br label %98
98: ; preds = %97
%99 = load i32, i32* %12
%100 = add i32 %99, 1
store i32 %100, i32* %12
br label %76
101: ; preds = %96, %76
%102 = load i32, i32* %13
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %125
104: ; preds = %101
%105 = load i8*, i8** %9
%106 = load i32, i32* %11
%107 = zext i32 %106 to i64
%108 = getelementptr inbounds i8, i8* %105, i64 %107
%109 = load i8*, i8** %14
%110 = ptrtoint i8* %108 to i64
%111 = ptrtoint i8* %109 to i64
%112 = sub i64 %110, %111
%113 = trunc i64 %112 to i32
store i32 %113, i32* %15
%114 = load %struct.match_tree_head*, %struct.match_tree_head** %16
%115 = load i8*, i8** %14
%116 = load i32, i32* %15
%117 = call i32 @match_tree_add_pattern(%struct.match_tree_head* %114, i8* %115, i32 %116)
%118 = load i32, i32* %11
%119 = load i32, i32* %7
%120 = add i32 %118, %119
store i32 %120, i32* %11
%121 = load i8*, i8** %9
%122 = load i32, i32* %11
%123 = zext i32 %122 to i64
%124 = getelementptr inbounds i8, i8* %121, i64 %123
store i8* %124, i8** %14
br label %128
125: ; preds = %101
%126 = load i32, i32* %11
%127 = add i32 %126, 1
store i32 %127, i32* %11
br label %128
128: ; preds = %125, %104
br label %69
129: ; preds = %69
%130 = load i8*, i8** %9
%131 = call i32 @free(i8* %130)
store i8* null, i8** %9
store i32 0, i32* %10
%132 = load %struct.match_tree_head*, %struct.match_tree_head** %16
store %struct.match_tree_head* %132, %struct.match_tree_head** %4
br label %133
133: ; preds = %129, %28, %22
%134 = load %struct.match_tree_head*, %struct.match_tree_head** %4
ret %struct.match_tree_head* %134
}

LLVM IR (-O2):
%struct.match_tree_head = type { i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.match_tree_head* @match_tree_init_from_file(i8* nocapture %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
%5 = icmp eq i32 %2, 0
%6 = or i1 %4, %5
br i1 %6, label %69, label %7
7: ; preds = %3
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %69, label %10
10: ; preds = %7
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %8, i32 0, i32 %11)
%13 = tail call i32 @ftell(i32* %8)
%14 = add i32 %2, 1
%15 = add i32 %14, %13
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %8, i32 0, i32 %18)
%20 = tail call i64 @fread(i8* %17, i32 1, i32 %13, i32* %8)
%21 = trunc i64 %20 to i32
%22 = tail call i32 @fclose(i32* %8)
%23 = and i64 %20, 4294967295
%24 = getelementptr inbounds i8, i8* %17, i64 %23
%25 = tail call i32 @memcpy(i8* %24, i8* %1, i32 %2)
%26 = add i32 %21, %2
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %17, i64 %27
store i8 0, i8* %28
%29 = tail call %struct.match_tree_head* (...) @match_tree_init()
%30 = icmp ult i32 %26, %2
br i1 %30, label %67, label %31
31: ; preds = %10
%32 = zext i32 %2 to i64
br label %33
33: ; preds = %62, %31
%34 = phi i32 [ %2, %31 ], [ %65, %62 ]
%35 = phi i8* [ %17, %31 ], [ %64, %62 ]
%36 = phi i32 [ 0, %31 ], [ %63, %62 ]
br label %39
37: ; preds = %39
%38 = icmp eq i64 %49, %32
br i1 %38, label %50, label %39
39: ; preds = %33, %37
%40 = phi i64 [ 0, %33 ], [ %49, %37 ]
%41 = trunc i64 %40 to i32
%42 = add i32 %36, %41
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %17, i64 %43
%45 = load i8, i8* %44
%46 = getelementptr inbounds i8, i8* %1, i64 %40
%47 = load i8, i8* %46
%48 = icmp eq i8 %45, %47
%49 = add nuw nsw i64 %40, 1
br i1 %48, label %37, label %60
50: ; preds = %37
%51 = zext i32 %36 to i64
%52 = getelementptr inbounds i8, i8* %17, i64 %51
%53 = ptrtoint i8* %52 to i64
%54 = ptrtoint i8* %35 to i64
%55 = sub i64 %53, %54
%56 = trunc i64 %55 to i32
%57 = tail call i32 @match_tree_add_pattern(%struct.match_tree_head* %29, i8* %35, i32 %56)
%58 = zext i32 %34 to i64
%59 = getelementptr inbounds i8, i8* %17, i64 %58
br label %62
60: ; preds = %39
%61 = add i32 %36, 1
br label %62
62: ; preds = %60, %50
%63 = phi i32 [ %34, %50 ], [ %61, %60 ]
%64 = phi i8* [ %59, %50 ], [ %35, %60 ]
%65 = add i32 %63, %2
%66 = icmp ugt i32 %65, %26
br i1 %66, label %67, label %33
67: ; preds = %62, %10
%68 = tail call i32 @free(i8* %17)
br label %69
69: ; preds = %7, %3, %67
%70 = phi %struct.match_tree_head* [ %29, %67 ], [ null, %3 ], [ null, %7 ]
ret %struct.match_tree_head* %70
}