#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*/ string;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ remove_newline(char *);
int /*<<< orphan*/ rule_for_word(char *, char *);
int /*<<< orphan*/ stderr;
void rules_from_file(char *filename, char *token) {
  FILE *file;
  char *s, string[4096];
  file = fopen(filename, "r");
  if (file == NULL) {
    fprintf(stderr, "Could not find %s.\n", filename);
    exit(1);
  }
  printf("\n /* rules from file %s */\n", filename);
  while (!feof(file)) {
    s = fgets(string, sizeof(string), file);
    if (s == NULL)
      break;
    remove_newline(string);
    rule_for_word(string, token);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<rules_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e5 <rules_from_file+0x55>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe2c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1213 <rules_from_file+0x83>
jmp    125d <rules_from_file+0xcd>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123c <rules_from_file+0xac>
jmp    125d <rules_from_file+0xcd>
lea    -0x1020(%rbp),%rdi
call   1030 <remove_newline@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <rule_for_word@plt>
jmp    11f5 <rules_from_file+0x65>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rules_from_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1229 <rules_from_file+0x99>
mov    %rax,%rbx
lea    0xe59(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1214 <rules_from_file+0x84>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1214 <rules_from_file+0x84>
mov    %r15,%rdi
call   1030 <remove_newline@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <rule_for_word@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11e0 <rules_from_file+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    %r15,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Could not find %s.\0A\00"
@.str.2 = [28 x i8] c"\0A /* rules from file %s */\0A\00"
define void @rules_from_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [4096 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %32, %17
%21 = load i32*, i32** %5
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %25, label %38
25: ; preds = %20
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%27 = load i32*, i32** %5
%28 = call i8* @fgets(i8* %26, i32 4096, i32* %27)
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %25
br label %38
32: ; preds = %25
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%34 = call i32 @remove_newline(i8* %33)
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%36 = load i8*, i8** %4
%37 = call i32 @rule_for_word(i8* %35, i8* %36)
br label %20
38: ; preds = %31, %20
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Could not find %s.\0A\00"
@.str.2 = [28 x i8] c"\0A /* rules from file %s */\0A\00"
define void @rules_from_file(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%13 = call i32 @feof(i32* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %11, %18
%16 = call i8* @fgets(i8* %4, i32 4096, i32* %5)
%17 = icmp eq i8* %16, null
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = call i32 @remove_newline(i8* %4)
%20 = call i32 @rule_for_word(i8* %4, i8* %1)
%21 = call i32 @feof(i32* %5)
%22 = icmp eq i32 %21, 0
br i1 %22, label %15, label %23
23: ; preds = %18, %15, %11
%24 = call i32 @fclose(i32* %5)
ret void
}