#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*/ EXIT_FAILURE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  DIR *dp;
  struct dirent *p;
  dp = opendir(".");
  if (dp == NULL)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day02/dir.c",
              22, "opendir", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  while ((p = readdir(dp)) != NULL) {
    if (p->d_name[0] == '.')
      continue;
    printf("%s\n", p->d_name);
  }
  closedir(dp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ec <main+0x7c>
jmp    119f <main+0x2f>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%r9
lea    0xe3c(%rip),%rsi
lea    0xe45(%rip),%rdx
mov    $0x16,%ecx
lea    0xecb(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11f1 <main+0x81>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1238 <main+0xc8>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1220 <main+0xb0>
jmp    11f1 <main+0x81>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xde0(%rip),%rdi
call   1040 <printf@plt>
jmp    11f1 <main+0x81>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11d1 <main+0x61>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11bf <main+0x4f>
lea    0xe72(%rip),%r14
jmp    11ad <main+0x3d>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11bf <main+0x4f>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     11a0 <main+0x30>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    11a0 <main+0x30>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e08(%rip),%rax
mov    (%rax),%ebx
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe13(%rip),%rsi
lea    0xe1c(%rip),%rdx
lea    0xea7(%rip),%r8
mov    %ebx,%edi
mov    $0x16,%ecx
mov    %rax,%r9
call   1060 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day02/dir.c\00"
@.str.3 = [8 x i8] c"opendir\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
store i32 0, i32* %1
%4 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %16
7: ; preds = %0
br label %8
8: ; preds = %7
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.2, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; No predecessors!
br label %16
16: ; preds = %15, %0
br label %17
17: ; preds = %30, %29, %16
%18 = load i32*, i32** %2
%19 = call %struct.dirent* @readdir(i32* %18)
store %struct.dirent* %19, %struct.dirent** %3
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load %struct.dirent*, %struct.dirent** %3
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 46
br i1 %28, label %29, label %30
29: ; preds = %21
br label %17
30: ; preds = %21
%31 = load %struct.dirent*, %struct.dirent** %3
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %17
35: ; preds = %17
%36 = load i32*, i32** %2
%37 = call i32 @closedir(i32* %36)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.2 = [146 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day02/dir.c\00"
@.str.3 = [8 x i8] c"opendir\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %24, label %13
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([146 x i8], [146 x i8]* @.str.2, i64 0, i64 0), i32 22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %3, %21
%14 = phi %struct.dirent* [ %22, %21 ], [ %4, %3 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 46
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %16)
br label %21
21: ; preds = %19, %13
%22 = tail call %struct.dirent* @readdir(i32* %1)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %24, label %13
24: ; preds = %21, %3
%25 = tail call i32 @closedir(i32* %1)
ret i32 0
}