#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*/ close_connection();
int /*<<< orphan*/ connect_to_nnserver();
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ wait_for_connecting();
int /*<<< orphan*/ write_msg(char *);
int main() {
  connect_to_nnserver();
  wait_for_connecting();
  char pfad[] = "./bin";
  DIR *dir;
  struct dirent *file;
  dir = opendir(pfad);
  while (file = readdir(dir)) {
    write_msg(file->d_name);
    write_msg("\n");
  }
  close_connection();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <connect_to_nnserver@plt>
mov    $0x0,%al
call   1030 <wait_for_connecting@plt>
mov    0xe7d(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xe77(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0xa(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11d2 <main+0x72>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1080 <write_msg@plt>
lea    0xe3e(%rip),%rdi
call   1080 <write_msg@plt>
jmp    119e <main+0x3e>
mov    $0x0,%al
call   1050 <close_connection@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <connect_to_nnserver@plt>
xor    %eax,%eax
call   1030 <wait_for_connecting@plt>
movw   $0x6e,0x4(%rsp)
movl   $0x69622f2e,(%rsp)
mov    %rsp,%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11bd <main+0x5d>
lea    0xe67(%rip),%r14
nop
mov    (%rax),%rdi
call   1080 <write_msg@plt>
mov    %r14,%rdi
call   1080 <write_msg@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
jne    11a0 <main+0x40>
xor    %eax,%eax
call   1050 <close_connection@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@__const.main.pfad = [6 x i8] c"./bin\00"
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [6 x i8]
%3 = alloca i32*
%4 = alloca %struct.dirent*
store i32 0, i32* %1
%5 = call i32 (...) @connect_to_nnserver()
%6 = call i32 (...) @wait_for_connecting()
%7 = bitcast [6 x i8]* %2 to i8*
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %3
br label %10
10: ; preds = %14, %0
%11 = load i32*, i32** %3
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %4
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %4
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 @write_msg(i8* %17)
%19 = call i32 @write_msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %10
20: ; preds = %10
%21 = call i32 (...) @close_connection()
ret i32 0
}

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