#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ *openfile(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ vcalloc(int, int);
char **read_tree_list(char *tree_list, int ntree) {
  FILE *fp;
  char **list;
  int i = 0;
  list = (char **)vcalloc(ntree, sizeof(char *));
  for (i = 0; i < ntree; i++) {
    list[i] = (char *)vcalloc(1000, sizeof(char));
  }
  fp = openfile(tree_list, "r");
  for (i = 0; (i < ntree) && (fscanf(fp, "%s", list[i]) != EOF); i++)
    ;
  if (i != ntree) {
    fprintf(stderr,
            "ERROR - Incorrect number of trees (ntree) %d != (list) %d\n",
            ntree, i);
  }
  fclose(fp);
  return list;
}


x86 assembly (clang, -O0):
<read_tree_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x8,%esi
call   1070 <vcalloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b6 <read_tree_list+0x66>
mov    $0x3e8,%edi
mov    $0x1,%esi
call   1070 <vcalloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117e <read_tree_list+0x2e>
mov    -0x8(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1030 <openfile@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x25(%rbp)
jge    120e <read_tree_list+0xbe>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe09(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    121e <read_tree_list+0xce>
jmp    1231 <read_tree_list+0xe1>
jmp    1223 <read_tree_list+0xd3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d1 <read_tree_list+0x81>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1258 <read_tree_list+0x108>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdb2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_tree_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
mov    %esi,%edi
mov    $0x8,%esi
call   1070 <vcalloc@plt>
mov    %rax,%r13
test   %r12d,%r12d
jle    11f0 <read_tree_list+0xa0>
mov    %r12d,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x3e8,%edi
mov    $0x1,%esi
call   1070 <vcalloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1180 <read_tree_list+0x30>
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
call   1030 <openfile@plt>
mov    %rax,%r15
test   %r12d,%r12d
jle    1202 <read_tree_list+0xb2>
mov    %r12d,0x4(%rsp)
xor    %ebp,%ebp
lea    0xe40(%rip),%r12
mov    0x2e1f(%rip),%r14
nopl   0x0(%rax)
mov    0x0(%r13,%rbp,8),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <fscanf@plt>
cmp    (%r14),%rax
je     123d <read_tree_list+0xed>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11d0 <read_tree_list+0x80>
jmp    1223 <read_tree_list+0xd3>
lea    0xe09(%rip),%rsi
mov    %r14,%rdi
call   1030 <openfile@plt>
mov    %rax,%r15
xor    %ebp,%ebp
cmp    %r12d,%ebp
je     1223 <read_tree_list+0xd3>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
mov    %r12d,%edx
mov    %ebp,%ecx
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x4(%rsp),%r12d
cmp    %r12d,%ebp
je     1223 <read_tree_list+0xd3>
jmp    1209 <read_tree_list+0xb9>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@stderr = global i32 0
@.str.2 = [59 x i8] c"ERROR - Incorrect number of trees (ntree) %d != (list) %d\0A\00"
define i8** @read_tree_list(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = call i64 @vcalloc(i32 %8, i32 8)
%10 = inttoptr i64 %9 to i8**
store i8** %10, i8*** %6
store i32 0, i32* %7
br label %11
11: ; preds = %22, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = call i64 @vcalloc(i32 1000, i32 1)
%17 = inttoptr i64 %16 to i8*
%18 = load i8**, i8*** %6
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
store i8* %17, i8** %21
br label %22
22: ; preds = %15
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %11
25: ; preds = %11
%26 = load i8*, i8** %3
%27 = call i32* @openfile(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %5
store i32 0, i32* %7
br label %28
28: ; preds = %45, %25
%29 = load i32, i32* %7
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %42
32: ; preds = %28
%33 = load i32*, i32** %5
%34 = load i8**, i8*** %6
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i64 @fscanf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i64, i64* @EOF
%41 = icmp ne i64 %39, %40
br label %42
42: ; preds = %32, %28
%43 = phi i1 [ false, %28 ], [ %41, %32 ]
br i1 %43, label %44, label %48
44: ; preds = %42
br label %45
45: ; preds = %44
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %28
48: ; preds = %42
%49 = load i32, i32* %7
%50 = load i32, i32* %4
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i32, i32* %4
%55 = load i32, i32* %7
%56 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %55)
br label %57
57: ; preds = %52, %48
%58 = load i32*, i32** %5
%59 = call i32 @fclose(i32* %58)
%60 = load i8**, i8*** %6
ret i8** %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@stderr = global i32 0
@.str.2 = [59 x i8] c"ERROR - Incorrect number of trees (ntree) %d != (list) %d\0A\00"
define i8** @read_tree_list(i8* %0, i32 %1) {
%3 = tail call i64 @vcalloc(i32 %1, i32 8)
%4 = inttoptr i64 %3 to i8**
%5 = icmp sgt i32 %1, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32* @openfile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %33
8: ; preds = %2
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = tail call i64 @vcalloc(i32 1000, i32 1)
%13 = inttoptr i64 %12 to i8*
%14 = getelementptr inbounds i8*, i8** %4, i64 %11
store i8* %13, i8** %14
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = tail call i32* @openfile(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br i1 %5, label %19, label %33
19: ; preds = %17
%20 = zext i32 %1 to i64
br label %21
21: ; preds = %19, %28
%22 = phi i64 [ 0, %19 ], [ %29, %28 ]
%23 = getelementptr inbounds i8*, i8** %4, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i64 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = add nuw nsw i64 %22, 1
%30 = icmp eq i64 %29, %20
br i1 %30, label %40, label %21
31: ; preds = %21
%32 = trunc i64 %22 to i32
br label %33
33: ; preds = %31, %6, %17
%34 = phi i32* [ %18, %17 ], [ %7, %6 ], [ %18, %31 ]
%35 = phi i32 [ 0, %17 ], [ 0, %6 ], [ %32, %31 ]
%36 = icmp eq i32 %35, %1
br i1 %36, label %40, label %37
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %35)
br label %40
40: ; preds = %28, %37, %33
%41 = phi i32* [ %34, %37 ], [ %34, %33 ], [ %18, %28 ]
%42 = tail call i32 @fclose(i32* %41)
ret i8** %4
}