#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 EINTR;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int closedir(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fdopendir(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int main(int argc, char *argv[]) {
  int dfd;
  DIR *dir;
  struct dirent *dp;
  if (argc < 2) {
    fprintf(stderr, "Uso: %s <dirname>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  dfd = open(argv[1], O_RDONLY);
  if ((dir = fdopendir(dfd)) == NULL) {
    fprintf(stderr, "Err.:(%d) - %s: %s\n", errno, strerror(errno), argv[1]);
    exit(EXIT_SUCCESS);
  }
  while ((dp = readdir(dir)) != NULL) {
    if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
      continue;
    else
      printf("%s\n", dp->d_name);
  }
  while ((closedir(dir) == -1) & (errno == EINTR))
    ;
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11dc <main+0x4c>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <fdopendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    125e <main+0xce>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1263 <main+0xd3>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12d1 <main+0x141>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xda0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     12b4 <main+0x124>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xd82(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12b9 <main+0x129>
jmp    1263 <main+0xd3>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xd5c(%rip),%rdi
call   1030 <printf@plt>
jmp    1263 <main+0xd3>
jmp    12d6 <main+0x146>
mov    -0x20(%rbp),%rdi
call   1040 <closedir@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    0x2cdf(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2cc6(%rip),%rdx
cmp    (%rdx),%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1315 <main+0x185>
jmp    12d6 <main+0x146>
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    1279 <main+0xe9>
mov    0x8(%rbx),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%edi
call   1090 <fdopendir@plt>
test   %rax,%rax
je     12a1 <main+0x111>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1254 <main+0xc4>
mov    %rax,%rbx
lea    0xe45(%rip),%r14
lea    0xe3d(%rip),%r15
lea    0xe32(%rip),%r12
jmp    1210 <main+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1254 <main+0xc4>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1030 <printf@plt>
jmp    1200 <main+0x70>
nopl   (%rax)
mov    0x2d89(%rip),%rax
mov    0x2d72(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,(%rax)
jne    1261 <main+0xd1>
mov    %r13,%rdi
call   1040 <closedir@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0xb0>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd74(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%r14d
mov    0x2d1e(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
mov    0x8(%rbx),%r8
lea    0xd4d(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [19 x i8] c"Uso: %s <dirname>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Err.:(%d) - %s: %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@EINTR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = call i32* @fdopendir(i32 %25)
store i32* %26, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %39
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %32, i8* %35)
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %19
br label %40
40: ; preds = %62, %56, %39
%41 = load i32*, i32** %7
%42 = call %struct.dirent* @readdir(i32* %41)
store %struct.dirent* %42, %struct.dirent** %8
%43 = icmp ne %struct.dirent* %42, null
br i1 %43, label %44, label %63
44: ; preds = %40
%45 = load %struct.dirent*, %struct.dirent** %8
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %56, label %50
50: ; preds = %44
%51 = load %struct.dirent*, %struct.dirent** %8
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50, %44
br label %40
57: ; preds = %50
%58 = load %struct.dirent*, %struct.dirent** %8
%59 = getelementptr inbounds %struct.dirent, %struct.dirent* %58, i32 0, i32 0
%60 = load i8*, i8** %59
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %57
br label %40
63: ; preds = %40
br label %64
64: ; preds = %75, %63
%65 = load i32*, i32** %7
%66 = call i32 @closedir(i32* %65)
%67 = icmp eq i32 %66, -1
%68 = zext i1 %67 to i32
%69 = load i32, i32* @errno
%70 = load i32, i32* @EINTR
%71 = icmp eq i32 %69, %70
%72 = zext i1 %71 to i32
%73 = and i32 %68, %72
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %64
br label %64
76: ; preds = %64
%77 = load i32, i32* @EXIT_SUCCESS
ret i32 %77
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [19 x i8] c"Uso: %s <dirname>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Err.:(%d) - %s: %s\0A\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@EINTR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = tail call i32* @fdopendir(i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %10
%18 = tail call %struct.dirent* @readdir(i32* %15)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %20, label %29
20: ; preds = %39, %17
br label %45
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = load i8*, i8** %11
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %24, i8* %25)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %17, %39
%30 = phi %struct.dirent* [ %40, %39 ], [ %18, %17 ]
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i64 0, i32 0
%32 = load i8*, i8** %31
%33 = tail call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %29
%36 = load i8*, i8** %31
%37 = tail call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %29, %35, %42
%40 = tail call %struct.dirent* @readdir(i32* %15)
%41 = icmp eq %struct.dirent* %40, null
br i1 %41, label %20, label %29
42: ; preds = %35
%43 = load i8*, i8** %31
%44 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %43)
br label %39
45: ; preds = %20, %45
%46 = tail call i32 @closedir(i32* %15)
%47 = icmp eq i32 %46, -1
%48 = load i32, i32* @errno
%49 = load i32, i32* @EINTR
%50 = icmp eq i32 %48, %49
%51 = and i1 %47, %50
br i1 %51, label %45, label %52
52: ; preds = %45
%53 = load i32, i32* @EXIT_SUCCESS
ret i32 %53
}