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

/* Variables and functions */
int /*<<< orphan*/ debugPrintf(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int strnlen(char *, int);
char readFile(char *fileName, char itemArray[512][512]) {
  FILE *file;
  int c;
  if (!(file = fopen(fileName, "r"))) {
    printf("Could not open file\n");
    exit(1);
  }
  while (fgets(itemArray[c++], sizeof(itemArray[512]), file)) {
    itemArray[c - 1][strnlen(itemArray[c - 1], 512) - 1] = '\0';
    debugPrintf("readFile itemArray[c] == %s\n", itemArray[c - 1]);
  }
  fclose(file);
  return c - 1;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b4 <readFile+0x44>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11b9 <readFile+0x49>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
cltq
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1252 <readFile+0xe2>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x9,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x9,%rax
add    %rax,%rdi
mov    $0x200,%esi
call   1050 <strnlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x9,%rax
add    %rax,%rsi
lea    0xdcf(%rip),%rdi
call   1070 <debugPrintf@plt>
jmp    11b9 <readFile+0x49>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
movsbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1206 <readFile+0x96>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f1 <readFile+0x81>
xor    %ebp,%ebp
lea    0xe56(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x200,%esi
call   1050 <strnlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <debugPrintf@plt>
add    $0x200,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
add    $0x1,%bpl
test   %rax,%rax
jne    11b0 <readFile+0x40>
jmp    11f1 <readFile+0x81>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"Could not open file\0A\00"
@.str.2 = [29 x i8] c"readFile itemArray[c] == %s\0A\00"
define signext i8 @readFile(i8* %0, [512 x i8]* %1) {
%3 = alloca i8*
%4 = alloca [512 x i8]*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store [512 x i8]* %1, [512 x i8]** %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
br label %14
14: ; preds = %24, %13
%15 = load [512 x i8]*, [512 x i8]** %4
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
store i32 %17, i32* %6
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 %18
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %19, i64 0, i64 0
%21 = load i32*, i32** %5
%22 = call i64 @fgets(i8* %20, i32 512, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %47
24: ; preds = %14
%25 = load [512 x i8]*, [512 x i8]** %4
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %25, i64 %28
%30 = load [512 x i8]*, [512 x i8]** %4
%31 = load i32, i32* %6
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %30, i64 %33
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %34, i64 0, i64 0
%36 = call i32 @strnlen(i8* %35, i32 512)
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %29, i64 0, i64 %38
store i8 0, i8* %39
%40 = load [512 x i8]*, [512 x i8]** %4
%41 = load i32, i32* %6
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %40, i64 %43
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %44, i64 0, i64 0
%46 = call i32 @debugPrintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %14
47: ; preds = %14
%48 = load i32*, i32** %5
%49 = call i32 @fclose(i32* %48)
%50 = load i32, i32* %6
%51 = sub nsw i32 %50, 1
%52 = trunc i32 %51 to i8
ret i8 %52
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"readFile itemArray[c] == %s\0A\00"
@str = [20 x i8] c"Could not open file\00"
define signext i8 @readFile(i8* nocapture %0, [512 x i8]* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%7 = tail call i64 @fgets(i8* %6, i32 512, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %26, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5, %12
%13 = phi i64 [ %15, %12 ], [ 0, %5 ]
%14 = phi i8* [ %21, %12 ], [ %6, %5 ]
%15 = add i64 %13, 1
%16 = tail call i32 @strnlen(i8* %14, i32 512)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 %13, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @debugPrintf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 %15, i64 0
%22 = tail call i64 @fgets(i8* %21, i32 512, i32* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %12
24: ; preds = %12
%25 = trunc i64 %15 to i8
br label %26
26: ; preds = %24, %5
%27 = phi i8 [ undef, %5 ], [ %25, %24 ]
%28 = tail call i32 @fclose(i32* %3)
ret i8 %27
}