#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 *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
void readFromDir(char *buffer) {
  DIR *dir;
  struct dirent *ent;
  if ((dir = opendir(".")) != NULL) {
    while ((ent = readdir(dir)) != NULL) {
      strcat(buffer, ent->d_name);
      strcat(buffer, "\n");
    }
    closedir(dir);
  } else {
  }
}


x86 assembly (clang, -O0):
<readFromDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11b5 <readFromDir+0x75>
jmp    116b <readFromDir+0x2b>
mov    -0x10(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a7 <readFromDir+0x67>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1060 <strcat@plt>
jmp    116b <readFromDir+0x2b>
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
jmp    11ba <readFromDir+0x7a>
jmp    11ba <readFromDir+0x7a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFromDir>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11a0 <readFromDir+0x60>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     1193 <readFromDir+0x53>
lea    0xe92(%rip),%r15
mov    (%rax),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %r14,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
jne    1170 <readFromDir+0x30>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <closedir@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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