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

/* Variables and functions */
int BUFSIZ;
void *allocateMemory(unsigned int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
unsigned int getLineCountOfFile(char const *);
int /*<<< orphan*/ *openFileForReading(char const *);
unsigned int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
void readFileToStringArray(const char *file, char ***strings,
                           unsigned *numStrings) {
  *numStrings = getLineCountOfFile(file);
  *strings = allocateMemory((*numStrings) * sizeof(char *));
  FILE *filePtr = openFileForReading(file);
  unsigned lineNumber = 0, lineLength;
  char lineBuffer[BUFSIZ];
  while (fgets(lineBuffer, sizeof(lineBuffer), filePtr)) {
    lineLength = strlen(lineBuffer);
    (*strings)[lineNumber] = allocateMemory(lineLength + 1);
    strncpy((*strings)[lineNumber], lineBuffer, lineLength + 1);
    ++lineNumber;
  }
  fclose(filePtr);
}


x86 assembly (clang, -O0):
<readFileToStringArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getLineCountOfFile@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
shl    $0x3,%edi
call   1090 <allocateMemory@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1080 <openFileForReading@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1261 <readFileToStringArray+0xf1>
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
add    $0x1,%edi
call   1090 <allocateMemory@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x24(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f1 <readFileToStringArray+0x81>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFileToStringArray>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1070 <getLineCountOfFile@plt>
mov    %eax,(%r14)
lea    0x0(,%rax,8),%edi
call   1090 <allocateMemory@plt>
mov    %rbx,-0x30(%rbp)
mov    %rax,(%rbx)
mov    %r15,%rdi
call   1080 <openFileForReading@plt>
mov    %rax,%r15
mov    0x2e2c(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%r13
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1238 <readFileToStringArray+0xc8>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%ebx
mov    %ebx,%edi
call   1090 <allocateMemory@plt>
mov    -0x30(%rbp),%rsi
mov    (%rsi),%rcx
mov    %r14d,%edx
mov    %rax,(%rcx,%rdx,8)
mov    (%rsi),%rax
mov    (%rax,%rdx,8),%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
add    $0x1,%r14d
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11f0 <readFileToStringArray+0x80>
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
define void @readFileToStringArray(i8* %0, i8*** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8***
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %4
store i8*** %1, i8**** %5
store i32* %2, i32** %6
%12 = load i8*, i8** %4
%13 = call i32 @getLineCountOfFile(i8* %12)
%14 = load i32*, i32** %6
store i32 %13, i32* %14
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = zext i32 %16 to i64
%18 = mul i64 %17, 8
%19 = trunc i64 %18 to i32
%20 = call i8* @allocateMemory(i32 %19)
%21 = bitcast i8* %20 to i8**
%22 = load i8***, i8**** %5
store i8** %21, i8*** %22
%23 = load i8*, i8** %4
%24 = call i32* @openFileForReading(i8* %23)
store i32* %24, i32** %7
store i32 0, i32* %8
%25 = load i32, i32* @BUFSIZ
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %10
%28 = alloca i8, i64 %26
store i64 %26, i64* %11
br label %29
29: ; preds = %34, %3
%30 = trunc i64 %26 to i32
%31 = load i32*, i32** %7
%32 = call i64 @fgets(i8* %28, i32 %30, i32* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %55
34: ; preds = %29
%35 = call i32 @strlen(i8* %28)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = add i32 %36, 1
%38 = call i8* @allocateMemory(i32 %37)
%39 = load i8***, i8**** %5
%40 = load i8**, i8*** %39
%41 = load i32, i32* %8
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
store i8* %38, i8** %43
%44 = load i8***, i8**** %5
%45 = load i8**, i8*** %44
%46 = load i32, i32* %8
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* %9
%51 = add i32 %50, 1
%52 = call i32 @strncpy(i8* %49, i8* %28, i32 %51)
%53 = load i32, i32* %8
%54 = add i32 %53, 1
store i32 %54, i32* %8
br label %29
55: ; preds = %29
%56 = load i32*, i32** %7
%57 = call i32 @fclose(i32* %56)
%58 = load i8*, i8** %10
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define void @readFileToStringArray(i8* %0, i8*** nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @getLineCountOfFile(i8* %0)
store i32 %4, i32* %2
%5 = shl i32 %4, 3
%6 = tail call i8* @allocateMemory(i32 %5)
%7 = bitcast i8*** %1 to i8**
store i8* %6, i8** %7
%8 = tail call i32* @openFileForReading(i8* %0)
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = call i64 @fgets(i8* %11, i32 %9, i32* %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %3, %14
%15 = phi i32 [ %26, %14 ], [ 0, %3 ]
%16 = call i32 @strlen(i8* %11)
%17 = add i32 %16, 1
%18 = call i8* @allocateMemory(i32 %17)
%19 = load i8**, i8*** %1
%20 = zext i32 %15 to i64
%21 = getelementptr inbounds i8*, i8** %19, i64 %20
store i8* %18, i8** %21
%22 = load i8**, i8*** %1
%23 = getelementptr inbounds i8*, i8** %22, i64 %20
%24 = load i8*, i8** %23
%25 = call i32 @strncpy(i8* %24, i8* %11, i32 %17)
%26 = add i32 %15, 1
%27 = call i64 @fgets(i8* %11, i32 %9, i32* %8)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %14
29: ; preds = %14, %3
%30 = call i32 @fclose(i32* %8)
ret void
}