#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*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
void ls() {
  DIR *dir;
  struct dirent *dir_ent;
  dir = opendir("./");
  if (dir == NULL)
    return;
  while (dir_ent = readdir(dir)) {
    const char *name = dir_ent->d_name;
    if (strcmp(name, "..") == 0)
      continue;
    else if (strcmp(name, ".") == 0)
      continue;
    printf("%s\n", dir_ent->d_name);
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1178 <ls+0x28>
jmp    1203 <ls+0xb3>
jmp    117d <ls+0x2d>
mov    -0x8(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11fa <ls+0xaa>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11be <ls+0x6e>
jmp    117d <ls+0x2d>
mov    -0x18(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11dd <ls+0x8d>
jmp    117d <ls+0x2d>
jmp    11e2 <ls+0x92>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
jmp    117d <ls+0x2d>
mov    -0x8(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11f6 <ls+0xa6>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11e0 <ls+0x90>
mov    %rax,%rbx
lea    0xe79(%rip),%r14
lea    0xe73(%rip),%r15
lea    0xe6e(%rip),%r12
jmp    11b0 <ls+0x60>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e0 <ls+0x90>
mov    (%rbx),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <ls+0x50>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <ls+0x50>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    11a0 <ls+0x50>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <closedir@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"./\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @ls() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca i8*
%4 = call i32* @opendir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
br label %35
8: ; preds = %0
br label %9
9: ; preds = %27, %25, %20, %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 %32
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
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
br label %9
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
br label %9
26: ; preds = %21
br label %27
27: ; preds = %26
%28 = load %struct.dirent*, %struct.dirent** %2
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %9
32: ; preds = %9
%33 = load i32*, i32** %1
%34 = call i32 @closedir(i32* %33)
br label %35
35: ; preds = %32, %7
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"./\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @ls() {
%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 %23, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3, %18
%7 = phi %struct.dirent* [ %19, %18 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %6
%13 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i8*, i8** %8
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %12, %6, %15
%19 = tail call %struct.dirent* @readdir(i32* %1)
%20 = icmp eq %struct.dirent* %19, null
br i1 %20, label %21, label %6
21: ; preds = %18, %3
%22 = tail call i32 @closedir(i32* %1)
br label %23
23: ; preds = %0, %21
ret void
}