#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*/ *);
scalar_t__ fgetline(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int read_list(char *filename, char **list, char *basedir) {
  FILE *fd;
  char line[255];
  int size = 0;
  fd = fopen(filename, "r");
  while (fgetline(fd, line, 255) != EOF) {
    if (basedir && *basedir)
      sprintf(list[size], "%s/%s", basedir, line);
    else
      sprintf(list[size], "%s", line);
    size++;
  }
  fclose(fd);
  return size;
}


x86 assembly (clang, -O0):
<read_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x124(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1030 <fgetline@plt>
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
je     121a <read_list+0xda>
cmpq   $0x0,-0x18(%rbp)
je     11e2 <read_list+0xa2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e2 <read_list+0xa2>
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x120(%rbp),%rcx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    1206 <read_list+0xc6>
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1175 <read_list+0x35>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x124(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xff,%edx
call   1030 <fgetline@plt>
mov    0x2e5b(%rip),%rbp
xor    %ebx,%ebx
cmp    0x0(%rbp),%rax
jne    11b1 <read_list+0x61>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r13
xor    %ebx,%ebx
jmp    11e6 <read_list+0x96>
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
add    $0x1,%rbx
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0xff,%edx
call   1030 <fgetline@plt>
cmp    0x0(%rbp),%rax
je     1195 <read_list+0x45>
test   %r12,%r12
je     11c0 <read_list+0x70>
cmpb   $0x0,(%r12)
je     11c0 <read_list+0x70>
mov    (%r14,%rbx,8),%rdi
lea    0xe05(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    11cc <read_list+0x7c>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @read_list(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [255 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
br label %12
12: ; preds = %43, %3
%13 = load i32*, i32** %7
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%15 = call i64 @fgetline(i32* %13, i8* %14, i32 255)
%16 = load i64, i64* @EOF
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %46
18: ; preds = %12
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %21
%27 = load i8**, i8*** %5
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = load i8*, i8** %6
%33 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%34 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33)
br label %43
35: ; preds = %21, %18
%36 = load i8**, i8*** %5
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%42 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %35, %26
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %12
46: ; preds = %12
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
%49 = load i32, i32* %9
ret i32 %49
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @read_list(i8* nocapture %0, i8** nocapture %1, i8* %2) {
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i64 @fgetline(i32* %6, i8* %5, i32 255)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
br i1 %9, label %32, label %10
10: ; preds = %3
%11 = icmp eq i8* %2, null
br label %12
12: ; preds = %10, %25
%13 = phi i64 [ 0, %10 ], [ %26, %25 ]
br i1 %11, label %21, label %14
14: ; preds = %12
%15 = load i8, i8* %2
%16 = icmp eq i8 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8*, i8** %1, i64 %13
%19 = load i8*, i8** %18
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %5)
br label %25
21: ; preds = %14, %12
%22 = getelementptr inbounds i8*, i8** %1, i64 %13
%23 = load i8*, i8** %22
%24 = call i8* @strcpy(i8* dereferenceable(1) %23, i8* %5)
br label %25
25: ; preds = %21, %17
%26 = add nuw i64 %13, 1
%27 = call i64 @fgetline(i32* %6, i8* %5, i32 255)
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %12
30: ; preds = %25
%31 = trunc i64 %26 to i32
br label %32
32: ; preds = %30, %3
%33 = phi i32 [ 0, %3 ], [ %31, %30 ]
%34 = call i32 @fclose(i32* %6)
ret i32 %33
}