#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 dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ start_dot(char *);
int /*<<< orphan*/ stderr;
void do_list(char *dir, bool flaga) {
  DIR *dir_ptr;
  struct dirent *dirent;
  if ((dir_ptr = opendir(dir)) == NULL)
    fprintf(stderr, "ls1: cann't open %s", dir);
  while ((dirent = readdir(dir_ptr)) != NULL) {
    if (!start_dot(dirent->d_name))
      printf("%s\n", dirent->d_name);
    else if (flaga)
      printf("%s\n", dirent->d_name);
  }
  closedir(dir_ptr);
}


x86 assembly (clang, -O0):
<do_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119f <do_list+0x3f>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe66(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11a4 <do_list+0x44>
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     120f <do_list+0xaf>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1080 <start_dot@plt>
cmp    $0x0,%eax
jne    11e8 <do_list+0x88>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
jmp    120a <do_list+0xaa>
cmpl   $0x0,-0xc(%rbp)
je     1205 <do_list+0xa5>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
jmp    120a <do_list+0xaa>
jmp    11a4 <do_list+0x44>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_list>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbp
call   1030 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1192 <do_list+0x32>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11e0 <do_list+0x80>
mov    %rax,%rbp
lea    0xe6b(%rip),%r14
jmp    11cc <do_list+0x6c>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11e0 <do_list+0x80>
mov    0x0(%rbp),%rdi
call   1080 <start_dot@plt>
test   %eax,%eax
je     11b0 <do_list+0x50>
test   %r15d,%r15d
je     11bc <do_list+0x5c>
jmp    11b0 <do_list+0x50>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <closedir@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [20 x i8] c"ls1: cann't open %s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @do_list(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.dirent*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32* @opendir(i8* %7)
store i32* %8, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %2
br label %15
15: ; preds = %39, %14
%16 = load i32*, i32** %5
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %6
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %40
19: ; preds = %15
%20 = load %struct.dirent*, %struct.dirent** %6
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 @start_dot(i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %19
%26 = load %struct.dirent*, %struct.dirent** %6
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %39
30: ; preds = %19
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load %struct.dirent*, %struct.dirent** %6
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %33, %30
br label %39
39: ; preds = %38, %25
br label %15
40: ; preds = %15
%41 = load i32*, i32** %5
%42 = call i32 @closedir(i32* %41)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [20 x i8] c"ls1: cann't open %s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @do_list(i8* %0, i32 %1) {
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %5, %2
%9 = tail call %struct.dirent* @readdir(i32* %3)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %26, label %11
11: ; preds = %8
%12 = icmp ne i32 %1, 0
br label %13
13: ; preds = %11, %23
%14 = phi %struct.dirent* [ %9, %11 ], [ %24, %23 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i32 @start_dot(i8* %16)
%18 = icmp eq i32 %17, 0
%19 = or i1 %18, %12
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i8*, i8** %15
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %13, %20
%24 = tail call %struct.dirent* @readdir(i32* %3)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %13
26: ; preds = %23, %8
%27 = tail call i32 @closedir(i32* %3)
ret void
}