#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*/ send(int, char *, int, int /*<<< orphan*/);
void do_list(int connfd) {
  DIR *mydir;
  struct dirent *ep;
  mydir = opendir(".");
  while ((ep = readdir(mydir)) != NULL) {
    if (ep->d_name[0] == '.')
      continue;
    send(connfd, ep->d_name, 64, 0);
  }
  closedir(mydir);
  return;
}


x86 assembly (clang, -O0):
<do_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a5 <do_list+0x65>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    118a <do_list+0x4a>
jmp    115b <do_list+0x1b>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    115b <do_list+0x1b>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_list>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeb4(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    1163 <do_list+0x23>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1185 <do_list+0x45>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     1160 <do_list+0x20>
mov    %ebp,%edi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    1160 <do_list+0x20>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <closedir@plt>

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

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