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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
char **fread_list(char *file) {
  FILE *rl;
  char **rlist;
  char line[100];
  int lcount = 0;
  int trim;
  if ((rl = fopen(file, "r")) == NULL)
    return NULL;
  while (fgets(line, sizeof(line), rl) != NULL)
    lcount++;
  rewind(rl);
  rlist = (char **)malloc(sizeof(char *) * (lcount + 1));
  lcount = 0;
  while (fgets(line, sizeof(line), rl) != NULL) {
    trim = strlen(line) - 1;
    while (trim >= 0 && (line[trim] == '\r' || line[trim] == '\n')) {
      line[trim] = '\0';
      trim--;
    }
    rlist[lcount] = (char *)malloc(sizeof(char) * (strlen(line) + 1));
    snprintf(rlist[lcount], strlen(line) + 1, "%s", line);
    lcount++;
  }
  rlist[lcount] = NULL;
  fclose(rl);
  return rlist;
}


x86 assembly (clang, -O0):
<fread_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x94(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b4 <fread_list+0x44>
movq   $0x0,-0x8(%rbp)
jmp    1386 <fread_list+0x216>
jmp    11b9 <fread_list+0x49>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     11ec <fread_list+0x7c>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11b9 <fread_list+0x49>
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1362 <fread_list+0x1f2>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x98(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x98(%rbp)
mov    %al,-0x99(%rbp)
jl     12a9 <fread_list+0x139>
movslq -0x98(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%ecx
ff
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x9a(%rbp)
je     129d <fread_list+0x12d>
movslq -0x98(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
sete   %al
mov    %al,-0x9a(%rbp)
mov    -0x9a(%rbp),%al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
test   $0x1,%al
jne    12bc <fread_list+0x14c>
jmp    12df <fread_list+0x16f>
movslq -0x98(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x98(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x98(%rbp)
jmp    124d <fread_list+0xdd>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
lea    -0x90(%rbp),%rcx
lea    0xcb9(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1219 <fread_list+0xa9>
mov    -0x20(%rbp),%rax
movslq -0x94(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe7b(%rip),%rsi
call   1090 <fopen@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     129b <fread_list+0x12b>
mov    %rax,%r14
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
add    $0x8,%r13d
test   %rax,%rax
jne    11a0 <fread_list+0x30>
mov    %r14,%rdi
call   1050 <rewind@plt>
mov    %r13d,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1288 <fread_list+0x118>
xor    %ebp,%ebp
mov    %rsp,%r15
lea    0xe11(%rip),%r12
jmp    124a <fread_list+0xda>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x0(%r13,%rbp,8)
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
call   1060 <snprintf@plt>
add    $0x1,%rbp
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1284 <fread_list+0x114>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1200 <fread_list+0x90>
mov    %eax,%eax
add    $0x1,%rax
jmp    126e <fread_list+0xfe>
xchg   %ax,%ax
movb   $0x0,(%rsp,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
jbe    1200 <fread_list+0x90>
lea    -0x2(%rax),%ecx
movzbl (%rsp,%rcx,1),%edx
cmp    $0xd,%dl
je     1260 <fread_list+0xf0>
cmp    $0xa,%dl
je     1260 <fread_list+0xf0>
jmp    1200 <fread_list+0x90>
mov    %ebp,%eax
jmp    128a <fread_list+0x11a>
xor    %eax,%eax
movq   $0x0,0x0(%r13,%rax,8)
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r13,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define i8** @fread_list(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i8** null, i8*** %2
br label %101
13: ; preds = %1
br label %14
14: ; preds = %19, %13
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i32* @fgets(i8* %15, i32 100, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
br label %14
22: ; preds = %14
%23 = load i32*, i32** %4
%24 = call i32 @rewind(i32* %23)
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = mul i64 8, %27
%29 = trunc i64 %28 to i32
%30 = call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i8**
store i8** %31, i8*** %5
store i32 0, i32* %7
br label %32
32: ; preds = %68, %22
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%34 = load i32*, i32** %4
%35 = call i32* @fgets(i8* %33, i32 100, i32* %34)
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %93
37: ; preds = %32
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
store i32 %40, i32* %8
br label %41
41: ; preds = %62, %37
%42 = load i32, i32* %8
%43 = icmp sge i32 %42, 0
br i1 %43, label %44, label %60
44: ; preds = %41
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 13
br i1 %50, label %58, label %51
51: ; preds = %44
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 10
br label %58
58: ; preds = %51, %44
%59 = phi i1 [ true, %44 ], [ %57, %51 ]
br label %60
60: ; preds = %58, %41
%61 = phi i1 [ false, %41 ], [ %59, %58 ]
br i1 %61, label %62, label %68
62: ; preds = %60
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %64
store i8 0, i8* %65
%66 = load i32, i32* %8
%67 = add nsw i32 %66, -1
store i32 %67, i32* %8
br label %41
68: ; preds = %60
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = mul i64 1, %72
%74 = trunc i64 %73 to i32
%75 = call i64 @malloc(i32 %74)
%76 = inttoptr i64 %75 to i8*
%77 = load i8**, i8*** %5
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
store i8* %76, i8** %80
%81 = load i8**, i8*** %5
%82 = load i32, i32* %7
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8*, i8** %81, i64 %83
%85 = load i8*, i8** %84
%86 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%87 = call i32 @strlen(i8* %86)
%88 = add nsw i32 %87, 1
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%90 = call i32 @snprintf(i8* %85, i32 %88, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %89)
%91 = load i32, i32* %7
%92 = add nsw i32 %91, 1
store i32 %92, i32* %7
br label %32
93: ; preds = %32
%94 = load i8**, i8*** %5
%95 = load i32, i32* %7
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
store i8* null, i8** %97
%98 = load i32*, i32** %4
%99 = call i32 @fclose(i32* %98)
%100 = load i8**, i8*** %5
store i8** %100, i8*** %2
br label %101
101: ; preds = %93, %12
%102 = load i8**, i8*** %2
ret i8** %102
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define i8** @fread_list(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %50, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %10, %6 ], [ 1, %1 ]
%8 = call i32* @fgets(i8* %3, i32 100, i32* %4)
%9 = icmp eq i32* %8, null
%10 = add i32 %7, 1
br i1 %9, label %11, label %6
11: ; preds = %6
%12 = call i32 @rewind(i32* %4)
%13 = shl i32 %7, 3
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8**
%16 = call i32* @fgets(i8* %3, i32 100, i32* %4)
%17 = icmp eq i32* %16, null
br i1 %17, label %46, label %18
18: ; preds = %11, %32
%19 = phi i64 [ %41, %32 ], [ 0, %11 ]
%20 = call i32 @strlen(i8* %3)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = zext i32 %20 to i64
br label %24
24: ; preds = %22, %30
%25 = phi i64 [ %23, %22 ], [ %26, %30 ]
%26 = add nsw i64 %25, -1
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
switch i8 %29, label %32 [
i8 13, label %30
i8 10, label %30
]
30: ; preds = %24, %24
store i8 0, i8* %28
%31 = icmp ugt i64 %25, 1
br i1 %31, label %24, label %32
32: ; preds = %30, %24, %18
%33 = call i32 @strlen(i8* %3)
%34 = add nsw i32 %33, 1
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i8*
%37 = getelementptr inbounds i8*, i8** %15, i64 %19
store i8* %36, i8** %37
%38 = call i32 @strlen(i8* %3)
%39 = add nsw i32 %38, 1
%40 = call i32 @snprintf(i8* %36, i32 %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%41 = add nuw i64 %19, 1
%42 = call i32* @fgets(i8* %3, i32 100, i32* %4)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %18
44: ; preds = %32
%45 = and i64 %41, 4294967295
br label %46
46: ; preds = %44, %11
%47 = phi i64 [ 0, %11 ], [ %45, %44 ]
%48 = getelementptr inbounds i8*, i8** %15, i64 %47
store i8* null, i8** %48
%49 = call i32 @fclose(i32* %4)
br label %50
50: ; preds = %1, %46
%51 = phi i8** [ %15, %46 ], [ null, %1 ]
ret i8** %51
}