#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*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ puts(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
void __attribute__((no)) list_func(void) {
  DIR *dir = opendir("db");
  struct dirent *ent;
  if (dir == NULL)
    _exit(0);
  while ((ent = readdir(dir)) != NULL) {
    if (ent->d_name[0] == '.')
      continue;
    puts(ent->d_name);
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<list_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117a <list_func+0x2a>
xor    %edi,%edi
call   1030 <_exit@plt>
jmp    117f <list_func+0x2f>
mov    -0x8(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11bf <list_func+0x6f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ae <list_func+0x5e>
jmp    117f <list_func+0x2f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <puts@plt>
jmp    117f <list_func+0x2f>
mov    -0x8(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_func>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1195 <list_func+0x45>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     118c <list_func+0x3c>
mov    (%rax),%rdi
cmpb   $0x2e,(%rdi)
je     1170 <list_func+0x20>
call   1040 <puts@plt>
jmp    1170 <list_func+0x20>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <closedir@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"db\00"
define void @list_func() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = call i32* @opendir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @_exit(i32 0)
unreachable
8: ; preds = %0
br label %9
9: ; preds = %22, %21, %8
%10 = load i32*, i32** %1
%11 = call %struct.dirent* @readdir(i32* %10)
store %struct.dirent* %11, %struct.dirent** %2
%12 = icmp ne %struct.dirent* %11, null
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %2
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 46
br i1 %20, label %21, label %22
21: ; preds = %13
br label %9
22: ; preds = %13
%23 = load %struct.dirent*, %struct.dirent** %2
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @puts(i8* %25)
br label %9
27: ; preds = %9
%28 = load i32*, i32** %1
%29 = call i32 @closedir(i32* %28)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"db\00"
define void @list_func() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %19, label %8
6: ; preds = %0
%7 = tail call i32 @_exit(i32 0)
unreachable
8: ; preds = %3, %16
%9 = phi %struct.dirent* [ %17, %16 ], [ %4, %3 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 46
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = tail call i32 @puts(i8* %11)
br label %16
16: ; preds = %14, %8
%17 = tail call %struct.dirent* @readdir(i32* %1)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %19, label %8
19: ; preds = %16, %3
%20 = tail call i32 @closedir(i32* %1)
ret void
}