#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);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int read_rules(char *filename, char **p) {
  int i = 0;
  char buf[2048];
  FILE *fin;
  fin = fopen(filename, "rb");
  if (fin == NULL) {
    printf("\nError in open: %s \n\n", filename);
    exit(1);
  }
  while (fgets(buf, 2048, fin) != NULL) {
    strcpy(p[i], buf);
    i++;
  }
  fclose(fin);
  return i;
}


x86 assembly (clang, -O0):
<read_rules>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x828(%rbp)
cmpq   $0x0,-0x828(%rbp)
jne    11b9 <read_rules+0x59>
mov    -0x8(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11be <read_rules+0x5e>
lea    -0x820(%rbp),%rdi
mov    -0x828(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1206 <read_rules+0xa6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x820(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <read_rules+0x5e>
mov    -0x828(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_rules>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ee <read_rules+0x8e>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11d5 <read_rules+0x75>
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
add    $0x1,%rbx
mov    %r12,%rdi
mov    $0x800,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <read_rules+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe0e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"\0AError in open: %s \0A\0A\00"
define i32 @read_rules(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca [2048 x i8]
%7 = alloca i32*
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %22, %16
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %7
%20 = call i32* @fgets(i8* %18, i32 2048, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %32
22: ; preds = %17
%23 = load i8**, i8*** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %17
32: ; preds = %17
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"\0AError in open: %s \0A\0A\00"
define i32 @read_rules(i8* %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %23, label %13
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %13
%14 = phi i64 [ %18, %13 ], [ 0, %7 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %16, i8* %4)
%18 = add nuw i64 %14, 1
%19 = call i32* @fgets(i8* %4, i32 2048, i32* %5)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %13
21: ; preds = %13
%22 = trunc i64 %18 to i32
br label %23
23: ; preds = %21, %7
%24 = phi i32 [ 0, %7 ], [ %22, %21 ]
%25 = call i32 @fclose(i32* %5)
ret i32 %24
}