#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int readRules(char rules[][450]) {
  int i = 0;
  int numLines;
  FILE *filePtr = NULL;
  filePtr = fopen("RULES", "r");
  if (filePtr == NULL) {
    fprintf(stderr, "Fatal: Failed to open file\n");
    fprintf(stderr, "Invalid filename or filepath\n");
    exit(0);
  }
  while (fgets(rules[i], 450, filePtr) != NULL) {
    i++;
  }
  numLines = i;
  fclose(filePtr);
  return numLines;
}


x86 assembly (clang, -O0):
<readRules>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe8e(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <readRules+0x6e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11c3 <readRules+0x73>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
imul   $0x1c2,%rax,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1c2,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11fb <readRules+0xab>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c3 <readRules+0x73>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readRules>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xea2(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ae <readRules+0x5e>
mov    %rax,%r14
mov    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1c2,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
add    $0x1,%ebp
add    $0x1c2,%rbx
test   %rax,%rax
jne    1180 <readRules+0x30>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e2b(%rip),%rbx
mov    (%rbx),%edi
lea    0xe4a(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"RULES\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Fatal: Failed to open file\0A\00"
@.str.3 = [30 x i8] c"Invalid filename or filepath\0A\00"
define i32 @readRules([450 x i8]* %0) {
%2 = alloca [450 x i8]*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
store [450 x i8]* %0, [450 x i8]** %2
store i32 0, i32* %3
store i32* null, i32** %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %1
br label %16
16: ; preds = %25, %15
%17 = load [450 x i8]*, [450 x i8]** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [450 x i8], [450 x i8]* %17, i64 %19
%21 = getelementptr inbounds [450 x i8], [450 x i8]* %20, i64 0, i64 0
%22 = load i32*, i32** %5
%23 = call i32* @fgets(i8* %21, i32 450, i32* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %16
28: ; preds = %16
%29 = load i32, i32* %3
store i32 %29, i32* %4
%30 = load i32*, i32** %5
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"RULES\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Fatal: Failed to open file\0A\00"
@.str.3 = [30 x i8] c"Invalid filename or filepath\0A\00"
define i32 @readRules([450 x i8]* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %1, %10
%11 = phi i64 [ %15, %10 ], [ 0, %1 ]
%12 = getelementptr inbounds [450 x i8], [450 x i8]* %0, i64 %11, i64 0
%13 = tail call i32* @fgets(i8* %12, i32 450, i32* %2)
%14 = icmp eq i32* %13, null
%15 = add nuw i64 %11, 1
br i1 %14, label %16, label %10
16: ; preds = %10
%17 = trunc i64 %11 to i32
%18 = tail call i32 @fclose(i32* %2)
ret i32 %17
}