#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 st_mode;
};

/* Variables and functions */
int S_IFDIR;
int S_IFMT;
int /*<<< orphan*/ dirwalk(char *, void (*)(char *));
int /*<<< orphan*/ error(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int stat(char *, struct stat *);
void list(char *file) {
  struct stat stbuf;
  if (stat(file, &stbuf) == -1)
    error("list: can't acess %s", file);
  if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
    dirwalk(file, list);
  printf("%s\n", file);
}


x86 assembly (clang, -O0):
<list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1172 <list+0x32>
mov    -0x8(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1050 <error@plt>
mov    -0x10(%rbp),%eax
mov    0x2e5c(%rip),%rcx
and    (%rcx),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
jne    119d <list+0x5d>
mov    -0x8(%rbp),%rdi
mov    0x2e50(%rip),%rsi
call   1060 <dirwalk@plt>
mov    -0x8(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1166 <list+0x26>
lea    0xea2(%rip),%rdi
mov    %rbx,%rsi
call   1050 <error@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%eax
jne    118d <list+0x4d>
mov    0x2e63(%rip),%rsi
mov    %rbx,%rdi
call   1060 <dirwalk@plt>
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [21 x i8] c"list: can't acess %s\00"
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@.str.1 = [4 x i8] c"%s\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 = call i32 @stat(i8* %4, %struct.stat* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %7, %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @S_IFMT
%14 = and i32 %12, %13
%15 = load i32, i32* @S_IFDIR
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = call i32 @dirwalk(i8* %18, void (i8*)* @list)
br label %20
20: ; preds = %17, %10
%21 = load i8*, i8** %2
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [21 x i8] c"list: can't acess %s\00"
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define void @list(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* @S_IFMT
%12 = and i32 %11, %10
%13 = load i32, i32* @S_IFDIR
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @dirwalk(i8* %0, void (i8*)* @list)
br label %17
17: ; preds = %15, %8
%18 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %0)
ret void
}