#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 {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ pastShield(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncat(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int ls(int sock, char *path) {
  DIR *dir;
  struct dirent *de;
  char ans[256];
  bzero(ans, 256);
  if ((dir = opendir(path)) == NULL) {
    ans[0] = 'n';
  } else
    ans[0] = 'y';
  write(sock, ans, 1);
  while ((de = readdir(dir)) != NULL) {
    bzero(ans, 256);
    strncat(ans, de->d_name, 256);
    if (!(strncmp(ans, "_ls_end", 256)))
      pastShield(ans);
    write(sock, ans, 256);
  }
  write(sock, "_ls_end", 256);
  closedir(dir);
  return 1;
}


x86 assembly (clang, -O0):
<ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c6 <ls+0x46>
movb   $0x6e,-0x120(%rbp)
jmp    11cd <ls+0x4d>
movb   $0x79,-0x120(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1266 <ls+0xe6>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    $0x100,%edx
call   1060 <strncat@plt>
lea    -0x120(%rbp),%rdi
lea    0xdd2(%rip),%rsi
mov    $0x100,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    124d <ls+0xcd>
lea    -0x120(%rbp),%rdi
call   10a0 <pastShield@plt>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1040 <write@plt>
jmp    11e1 <ls+0x61>
mov    -0x4(%rbp),%edi
lea    0xd90(%rip),%rsi
mov    $0x100,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
mov    $0x1,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
mov    %rbx,%rdi
call   1050 <opendir@plt>
mov    %rax,%r12
test   %rax,%rax
mov    $0x6e,%eax
mov    $0x79,%ecx
cmove  %eax,%ecx
mov    %cl,(%rsp)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %r12,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     124a <ls+0xca>
mov    %rax,%rbx
mov    %rsp,%rbp
lea    0xe13(%rip),%r15
jmp    1210 <ls+0x90>
nop
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1040 <write@plt>
mov    %r12,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124a <ls+0xca>
mov    %rbp,%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
mov    (%rbx),%esi
mov    %rbp,%rdi
mov    $0x100,%edx
call   1060 <strncat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x100,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11f0 <ls+0x70>
mov    %rbp,%rdi
call   10a0 <pastShield@plt>
jmp    11f0 <ls+0x70>
lea    0xdaf(%rip),%rsi
mov    %r14d,%edi
mov    $0x100,%edx
call   1040 <write@plt>
mov    %r12,%rdi
call   1070 <closedir@plt>
mov    $0x1,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [8 x i8] c"_ls_end\00"
define i32 @ls(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca [256 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%9 = call i32 @bzero(i8* %8, i32 256)
%10 = load i8*, i8** %4
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
store i8 110, i8* %14
br label %17
15: ; preds = %2
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
store i8 121, i8* %16
br label %17
17: ; preds = %15, %13
%18 = load i32, i32* %3
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = call i32 @write(i32 %18, i8* %19, i32 1)
br label %21
21: ; preds = %39, %17
%22 = load i32*, i32** %5
%23 = call %struct.dirent* @readdir(i32* %22)
store %struct.dirent* %23, %struct.dirent** %6
%24 = icmp ne %struct.dirent* %23, null
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%27 = call i32 @bzero(i8* %26, i32 256)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%29 = load %struct.dirent*, %struct.dirent** %6
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @strncat(i8* %28, i32 %31, i32 256)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%34 = call i32 @strncmp(i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 256)
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %25
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%38 = call i32 @pastShield(i8* %37)
br label %39
39: ; preds = %36, %25
%40 = load i32, i32* %3
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%42 = call i32 @write(i32 %40, i8* %41, i32 256)
br label %21
43: ; preds = %21
%44 = load i32, i32* %3
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 256)
%46 = load i32*, i32** %5
%47 = call i32 @closedir(i32* %46)
ret i32 1
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [8 x i8] c"_ls_end\00"
define i32 @ls(i32 %0, i8* nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @bzero(i8* %4, i32 256)
%6 = tail call i32* @opendir(i8* %1)
%7 = icmp eq i32* %6, null
%8 = select i1 %7, i8 110, i8 121
store i8 %8, i8* %4
%9 = call i32 @write(i32 %0, i8* %4, i32 1)
%10 = call %struct.dirent* @readdir(i32* %6)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %26, label %12
12: ; preds = %2, %22
%13 = phi %struct.dirent* [ %24, %22 ], [ %10, %2 ]
%14 = call i32 @bzero(i8* %4, i32 256)
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @strncat(i8* %4, i32 %16, i32 256)
%18 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 256)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @pastShield(i8* %4)
br label %22
22: ; preds = %20, %12
%23 = call i32 @write(i32 %0, i8* %4, i32 256)
%24 = call %struct.dirent* @readdir(i32* %6)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %12
26: ; preds = %22, %2
%27 = call i32 @write(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 256)
%28 = call i32 @closedir(i32* %6)
ret i32 1
}