#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*/ _starts_with(char *, char *);
char *concat(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
unsigned int ls(char *filename) {
  char *home = getenv("HOME");
  char *p = concat(home, filename);
  FILE *fp = fopen(p, "r");
  if (fp == NULL) {
    free(p);
    return 0;
  }
  char line[256];
  while (fgets(line, sizeof(line), fp))
    if (!_starts_with(line, "---"))
      printf("> %s", line);
  fclose(fp);
  if (ferror(fp)) {
    free(p);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe5a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f4 <ls+0x64>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <ls+0xf4>
jmp    11f9 <ls+0x69>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x100,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     124c <ls+0xbc>
lea    -0x130(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   10a0 <_starts_with@plt>
cmp    $0x0,%eax
jne    1247 <ls+0xb7>
lea    -0x130(%rbp),%rsi
lea    0xdc9(%rip),%rdi
call   1070 <printf@plt>
jmp    11f9 <ls+0x69>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     127d <ls+0xed>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1284 <ls+0xf4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
lea    0xe56(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1080 <concat@plt>
mov    %rax,%r14
lea    0xe41(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1246 <ls+0xb6>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1231 <ls+0xa1>
lea    0xe17(%rip),%r15
mov    %rsp,%rbx
lea    0xe11(%rip),%r13
jmp    1215 <ls+0x85>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1231 <ls+0xa1>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <_starts_with@plt>
test   %eax,%eax
jne    1200 <ls+0x70>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
jmp    1200 <ls+0x70>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r12,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     1252 <ls+0xc2>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    1257 <ls+0xc7>
mov    $0x1,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"---\00"
@.str.3 = [5 x i8] c"> %s\00"
define i32 @ls(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [256 x i8]
store i8* %0, i8** %3
%8 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = load i8*, i8** %3
%11 = call i8* @concat(i8* %9, i8* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = load i8*, i8** %5
%18 = call i32 @free(i8* %17)
store i32 0, i32* %2
br label %43
19: ; preds = %1
br label %20
20: ; preds = %32, %19
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i64 @fgets(i8* %21, i32 256, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%27 = call i32 @_starts_with(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%31 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %25
br label %20
33: ; preds = %20
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** %6
%37 = call i64 @ferror(i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
store i32 0, i32* %2
br label %43
42: ; preds = %33
store i32 1, i32* %2
br label %43
43: ; preds = %42, %39, %16
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"---\00"
@.str.3 = [5 x i8] c"> %s\00"
define i32 @ls(i8* %0) {
%2 = alloca [256 x i8]
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @concat(i8* %3, i8* %0)
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @free(i8* %4)
br label %29
9: ; preds = %1
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i64 @fgets(i8* %10, i32 256, i32* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %9, %18
%14 = call i32 @_starts_with(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %10)
br label %18
18: ; preds = %16, %13
%19 = call i64 @fgets(i8* %10, i32 256, i32* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %13
21: ; preds = %18, %9
%22 = call i32 @fclose(i32* %5)
%23 = call i64 @ferror(i32* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 @free(i8* %4)
br label %27
27: ; preds = %21, %25
%28 = phi i32 [ 0, %25 ], [ 1, %21 ]
br label %29
29: ; preds = %27, %7
%30 = phi i32 [ 0, %7 ], [ %28, %27 ]
ret i32 %30
}