#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ add_entry(char const *, struct stat *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ list_entries(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ listdir(char const *);
scalar_t__ lstat(char const *, struct stat *);
int /*<<< orphan*/ malloc(int);
int /*<<< orphan*/ stderr;
void list(const char *path) {
  if (path[0] == '\0') {
    return;
  }
  struct stat buf;
  if (lstat(path, &buf) == 0) {
    if (S_ISDIR(buf.st_mode)) {
      listdir(path);
    } else {
      add_entry(path, &buf);
      list_entries(malloc(255), 0);
    }
  } else {
    fprintf(stderr, "%s not found.\n", path);
  }
}


x86 assembly (clang, -O0):
<list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1191 <list+0x21>
jmp    1206 <list+0x96>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <lstat@plt>
cmp    $0x0,%rax
jne    11ed <list+0x7d>
mov    -0x10(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11c8 <list+0x58>
mov    -0x8(%rbp),%rdi
call   1040 <listdir@plt>
jmp    11e8 <list+0x78>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <add_entry@plt>
mov    $0xff,%edi
call   1090 <malloc@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <list_entries@plt>
jmp    1206 <list+0x96>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdff(%rip),%rsi
call   1080 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list>:
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,(%rdi)
je     11de <list+0x6e>
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <lstat@plt>
test   %rax,%rax
je     11a6 <list+0x36>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
mov    %rbx,%rdx
call   1080 <fprintf@plt>
jmp    11de <list+0x6e>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     11be <list+0x4e>
mov    %rbx,%rdi
call   1040 <listdir@plt>
jmp    11de <list+0x6e>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <add_entry@plt>
mov    $0xff,%edi
call   1090 <malloc@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <list_entries@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"%s not found.\0A\00"
define void @list(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
br label %32
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i64 @lstat(i8* %11, %struct.stat* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @S_ISDIR(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %2
%21 = call i32 @listdir(i8* %20)
br label %27
22: ; preds = %14
%23 = load i8*, i8** %2
%24 = call i32 @add_entry(i8* %23, %struct.stat* %3)
%25 = call i32 @malloc(i32 255)
%26 = call i32 @list_entries(i32 %25, i32 0)
br label %27
27: ; preds = %22, %19
br label %32
28: ; preds = %10
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %2
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %9, %28, %27
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [15 x i8] c"%s not found.\0A\00"
define void @list(i8* %0) {
%2 = alloca %struct.stat
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = bitcast %struct.stat* %2 to i8*
%7 = call i64 @lstat(i8* %0, %struct.stat* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i64 @S_ISDIR(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = tail call i32 @listdir(i8* %0)
br label %23
16: ; preds = %9
%17 = call i32 @add_entry(i8* %0, %struct.stat* %2)
%18 = call i32 @malloc(i32 255)
%19 = call i32 @list_entries(i32 %18, i32 0)
br label %23
20: ; preds = %5
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %23
23: ; preds = %14, %16, %20
br label %24
24: ; preds = %1, %23
ret void
}