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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char **malloc(int);
char **realloc(char **, int);
char *strdup(char *);
int strlen(char *);
char **read_conf_file(const char *conf_filename) {
  FILE *fp;
  int num;
  char buf[(10000)];
  char **conf = NULL;
  conf = malloc(sizeof(char *));
  conf[0] = NULL;
  fp = fopen(conf_filename, "r");
  if (fp) {
    num = 0;
    while (fgets(buf, sizeof(buf), fp)) {
      if (buf[strlen(buf) - 1] == '\n') {
        buf[strlen(buf) - 1] = 0;
      }
      num++;
      conf = realloc(conf, sizeof(char *) * (num + 1));
      conf[num - 1] = strdup(buf);
      conf[num] = NULL;
    }
    fclose(fp);
  }
  return conf;
}


x86 assembly (clang, -O0):
<read_conf_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x2738(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x2738(%rbp)
mov    -0x2738(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1297 <read_conf_file+0x127>
movl   $0x0,-0x14(%rbp)
lea    -0x2730(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2710,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     128e <read_conf_file+0x11e>
lea    -0x2730(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x2730(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1229 <read_conf_file+0xb9>
lea    -0x2730(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x2730(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x2738(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x2738(%rbp)
lea    -0x2730(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rdx
mov    -0x2738(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2738(%rbp),%rax
movslq -0x14(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    11cf <read_conf_file+0x5f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2738(%rbp),%rax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_conf_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2710,%rsp
mov    %rdi,%r14
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
movq   $0x0,(%rax)
lea    0xe62(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     124b <read_conf_file+0xdb>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x2710,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1243 <read_conf_file+0xd3>
mov    $0x8,%ebx
jmp    121f <read_conf_file+0xaf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x8(%rbx),%r13
mov    %r12,%rdi
mov    %r13d,%esi
call   1070 <realloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%r12,%rbx,1)
movq   $0x0,(%r12,%rbx,1)
mov    %r15,%rdi
mov    $0x2710,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    %r13,%rbx
test   %rax,%rax
je     1243 <read_conf_file+0xd3>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r15,1)
jne    11e0 <read_conf_file+0x70>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
jmp    11e0 <read_conf_file+0x70>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12,%rax
add    $0x2710,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8** @read_conf_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [10000 x i8]
%6 = alloca i8**
store i8* %0, i8** %2
store i8** null, i8*** %6
%7 = call i8** @malloc(i32 8)
store i8** %7, i8*** %6
%8 = load i8**, i8*** %6
%9 = getelementptr inbounds i8*, i8** %8, i64 0
store i8* null, i8** %9
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %59
14: ; preds = %1
store i32 0, i32* %4
br label %15
15: ; preds = %35, %14
%16 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i64 @fgets(i8* %16, i32 10000, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %56
20: ; preds = %15
%21 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %35
29: ; preds = %20
%30 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %29, %20
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
%38 = load i8**, i8*** %6
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = mul i64 8, %41
%43 = trunc i64 %42 to i32
%44 = call i8** @realloc(i8** %38, i32 %43)
store i8** %44, i8*** %6
%45 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%46 = call i8* @strdup(i8* %45)
%47 = load i8**, i8*** %6
%48 = load i32, i32* %4
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %47, i64 %50
store i8* %46, i8** %51
%52 = load i8**, i8*** %6
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
store i8* null, i8** %55
br label %15
56: ; preds = %15
%57 = load i32*, i32** %3
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %56, %1
%60 = load i8**, i8*** %6
ret i8** %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i8** @read_conf_file(i8* nocapture %0) {
%2 = alloca [10000 x i8]
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%4 = tail call i8** @malloc(i32 8)
store i8* null, i8** %4
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %38, label %7
7: ; preds = %1
%8 = call i64 @fgets(i8* %3, i32 10000, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %35, label %10
10: ; preds = %7, %24
%11 = phi i64 [ %25, %24 ], [ 0, %7 ]
%12 = phi i8** [ %29, %24 ], [ %4, %7 ]
%13 = call i32 @strlen(i8* %3)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %24
19: ; preds = %10
%20 = call i32 @strlen(i8* %3)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %19, %10
%25 = add nuw i64 %11, 1
%26 = trunc i64 %11 to i32
%27 = shl i32 %26, 3
%28 = add i32 %27, 16
%29 = call i8** @realloc(i8** %12, i32 %28)
%30 = call i8* @strdup(i8* %3)
%31 = getelementptr inbounds i8*, i8** %29, i64 %11
store i8* %30, i8** %31
%32 = getelementptr inbounds i8*, i8** %29, i64 %25
store i8* null, i8** %32
%33 = call i64 @fgets(i8* %3, i32 10000, i32* %5)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %10
35: ; preds = %24, %7
%36 = phi i8** [ %4, %7 ], [ %29, %24 ]
%37 = call i32 @fclose(i32* %5)
br label %38
38: ; preds = %35, %1
%39 = phi i8** [ %36, %35 ], [ %4, %1 ]
ret i8** %39
}