#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
void readListFile(const char *path) {
  if (path == NULL) {
    printf("ERROR: Could not read filesystem\n");
    return;
  }
  char filePath[255];
  filePath[0] = 0;
  strncat(filePath, path, 255);
  strncat(filePath, ".list", 6);
  FILE *file = fopen(filePath, "r");
  if (file == NULL) {
    printf("ERROR: ls failed to read filesystem\n");
    fclose(file);
    return;
  }
  char line[255];
  while (fgets(line, 255, file) != NULL) {
    if (strlen(line) > 0) {
      printf("%s", line);
    }
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<readListFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118d <readListFile+0x2d>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126b <readListFile+0x10b>
movb   $0x0,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xff,%edx
call   1060 <strncat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x6,%edx
call   1060 <strncat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    1208 <readListFile+0xa8>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
jmp    126b <readListFile+0x10b>
jmp    120d <readListFile+0xad>
lea    -0x220(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    $0xff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     125f <readListFile+0xff>
lea    -0x220(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    125a <readListFile+0xfa>
lea    -0x220(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120d <readListFile+0xad>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readListFile>:
test   %rdi,%rdi
je     1236 <readListFile+0xc6>
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rsi
movb   $0x0,0x100(%rsp)
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xff,%edx
call   1070 <strncat@plt>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1070 <strncat@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1242 <readListFile+0xd2>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1231 <readListFile+0xc1>
mov    %rsp,%rbx
lea    0xe19(%rip),%r15
jmp    1215 <readListFile+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1231 <readListFile+0xc1>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jle    1200 <readListFile+0x90>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1200 <readListFile+0x90>
mov    %r14,%rdi
jmp    1250 <readListFile+0xe0>
lea    0xdf2(%rip),%rdi
jmp    1030 <puts@plt>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1040 <fclose@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"ERROR: Could not read filesystem\0A\00"
@.str.1 = [6 x i8] c".list\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [37 x i8] c"ERROR: ls failed to read filesystem\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define void @readListFile(i8* %0) {
%2 = alloca i8*
%3 = alloca [255 x i8]
%4 = alloca i32*
%5 = alloca [255 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %42
10: ; preds = %1
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
store i8 0, i8* %11
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 @strncat(i8* %12, i8* %13, i32 255)
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%16 = call i32 @strncat(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %4
%19 = load i32*, i32** %4
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %10
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32*, i32** %4
%24 = call i32 @fclose(i32* %23)
br label %42
25: ; preds = %10
br label %26
26: ; preds = %38, %25
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%28 = load i32*, i32** %4
%29 = call i32* @fgets(i8* %27, i32 255, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %39
31: ; preds = %26
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%33 = call i64 @strlen(i8* %32)
%34 = icmp sgt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %31
br label %26
39: ; preds = %26
%40 = load i32*, i32** %4
%41 = call i32 @fclose(i32* %40)
br label %42
42: ; preds = %39, %21, %8
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c".list\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@str = [36 x i8] c"ERROR: ls failed to read filesystem\00"
@str.5 = [33 x i8] c"ERROR: Could not read filesystem\00"
define void @readListFile(i8* %0) {
%2 = alloca [255 x i8]
%3 = alloca [255 x i8]
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.5, i64 0, i64 0))
br label %31
7: ; preds = %1
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
store i8 0, i8* %8
%9 = call i32 @strncat(i8* %8, i8* %0, i32 255)
%10 = call i32 @strncat(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 6)
%11 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%15 = call i32 @fclose(i32* null)
br label %30
16: ; preds = %7
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%18 = call i32* @fgets(i8* %17, i32 255, i32* %11)
%19 = icmp eq i32* %18, null
br i1 %19, label %28, label %20
20: ; preds = %16, %25
%21 = call i64 @strlen(i8* %17)
%22 = icmp sgt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %17)
br label %25
25: ; preds = %23, %20
%26 = call i32* @fgets(i8* %17, i32 255, i32* %11)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %20
28: ; preds = %25, %16
%29 = call i32 @fclose(i32* %11)
br label %30
30: ; preds = %28, %13
br label %31
31: ; preds = %30, %5
ret void
}