#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int fts_info;
  char *fts_path;
};
typedef TYPE_1__ FTSENT;
typedef int /*<<< orphan*/ FTS;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int FTS_D;
int FTS_DP;
int FTS_F;
int /*<<< orphan*/ FTS_PHYSICAL;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fts_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fts_open(char **, int /*<<< orphan*/, int /*<<< orphan*/ *);
TYPE_1__ *fts_read(int /*<<< orphan*/ *);
char *getcwd(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char *paths[] = {".", NULL};
  FTS *ftsp = fts_open(paths, FTS_PHYSICAL, NULL);
  if (ftsp == NULL) {
    perror("fts_open");
    exit(EXIT_FAILURE);
  }
  while (1) {
    FTSENT *ent = fts_read(ftsp);
    if (ent == NULL) {
      if (errno == 0)
        break;
      else {
        perror("fts_read");
        exit(EXIT_FAILURE);
      }
    }
    if (ent->fts_info & FTS_D)
      printf("Enter dir: ");
    else if (ent->fts_info & FTS_DP)
      printf("Exit dir:  ");
    else if (ent->fts_info & FTS_F)
      printf("File:      ");
    else
      printf("Other:     ");
    printf("%s\n", ent->fts_path);
    if (0) {
      char buf[2048];
      char *c = getcwd(buf, 2048);
      if (c == NULL)
        perror("getcwd");
      else
        printf("current working directory: %s\n", c);
    }
  }
  if (fts_close(ftsp) == -1)
    perror("fts_close");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c6a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c67(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <fts_open@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c4 <main+0x64>
lea    0xe51(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11c9 <main+0x69>
mov    -0x28(%rbp),%rdi
call   1050 <fts_read@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1211 <main+0xb1>
mov    0x2dd8(%rip),%rax
cmpq   $0x0,(%rax)
jne    11f7 <main+0x97>
jmp    12c5 <main+0x165>
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    0x2db2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     123c <main+0xdc>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12aa <main+0x14a>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    0x2d97(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1267 <main+0x107>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a5 <main+0x145>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    0x2d64(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1292 <main+0x132>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a0 <main+0x140>
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a5 <main+0x145>
jmp    12aa <main+0x14a>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c9 <main+0x69>
mov    -0x28(%rbp),%rdi
call   1030 <fts_close@plt>
cmp    $0xffffffff,%eax
jne    12e3 <main+0x183>
lea    0xd6a(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movaps 0x2c5b(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
xor    %edx,%edx
call   1070 <fts_open@plt>
test   %rax,%rax
je     1269 <main+0xf9>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <fts_read@plt>
test   %rax,%rax
je     1230 <main+0xc0>
mov    %rax,%rbx
mov    0x2e11(%rip),%r15
lea    0xe4e(%rip),%r12
mov    0x2e13(%rip),%r13
lea    0xe4c(%rip),%rbp
jmp    1200 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <fts_read@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1230 <main+0xc0>
mov    (%rbx),%eax
mov    %r12,%rdi
test   %eax,(%r15)
jne    11e0 <main+0x70>
mov    %rbp,%rdi
test   %eax,0x0(%r13)
jne    11e0 <main+0x70>
mov    0x2dbe(%rip),%rcx
test   %eax,(%rcx)
lea    0xe09(%rip),%rdi
lea    0xe0e(%rip),%rax
cmove  %rax,%rdi
jmp    11e0 <main+0x70>
mov    0x2d89(%rip),%rax
cmpq   $0x0,(%rax)
jne    1272 <main+0x102>
mov    %r14,%rdi
call   1040 <fts_close@plt>
cmp    $0xffffffff,%eax
je     125b <main+0xeb>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde2(%rip),%rdi
call   1080 <perror@plt>
jmp    124a <main+0xda>
lea    0xd92(%rip),%rdi
jmp    1279 <main+0x109>
lea    0xd92(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8* }
@.str = [2 x i8] c".\00"
@__const.main.paths = [2 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* null]
@FTS_PHYSICAL = global i32 0
@.str.1 = [9 x i8] c"fts_open\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@.str.2 = [9 x i8] c"fts_read\00"
@FTS_D = global i32 0
@.str.3 = [12 x i8] c"Enter dir: \00"
@FTS_DP = global i32 0
@.str.4 = [12 x i8] c"Exit dir: \00"
@FTS_F = global i32 0
@.str.5 = [12 x i8] c"File: \00"
@.str.6 = [12 x i8] c"Other: \00"
@.str.7 = [4 x i8] c"%s\0A\00"
@.str.8 = [10 x i8] c"fts_close\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8*]
%3 = alloca i32*
%4 = alloca %struct.TYPE_3__*
store i32 0, i32* %1
%5 = bitcast [2 x i8*]* %2 to i8*
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%7 = load i32, i32* @FTS_PHYSICAL
%8 = call i32* @fts_open(i8** %6, i32 %7, i32* null)
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
br label %16
16: ; preds = %15, %60
%17 = load i32*, i32** %3
%18 = call %struct.TYPE_3__* @fts_read(i32* %17)
store %struct.TYPE_3__* %18, %struct.TYPE_3__** %4
%19 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%20 = icmp eq %struct.TYPE_3__* %19, null
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i64, i64* @errno
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
br label %65
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %16
%30 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load i32, i32* @FTS_D
%34 = and i32 %32, %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %60
38: ; preds = %29
%39 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load i32, i32* @FTS_DP
%43 = and i32 %41, %42
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %59
47: ; preds = %38
%48 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%49 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = load i32, i32* @FTS_F
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %47
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %58
56: ; preds = %47
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %56, %54
br label %59
59: ; preds = %58, %45
br label %60
60: ; preds = %59, %36
%61 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%62 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %61, i32 0, i32 1
%63 = load i8*, i8** %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %63)
br label %16
65: ; preds = %24
%66 = load i32*, i32** %3
%67 = call i32 @fts_close(i32* %66)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %71
69: ; preds = %65
%70 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %71
71: ; preds = %69, %65
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8* }
@.str = [2 x i8] c".\00"
@__const.main.paths = [2 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* null]
@FTS_PHYSICAL = global i32 0
@.str.1 = [9 x i8] c"fts_open\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@.str.2 = [9 x i8] c"fts_read\00"
@FTS_D = global i32 0
@.str.3 = [12 x i8] c"Enter dir: \00"
@FTS_DP = global i32 0
@.str.4 = [12 x i8] c"Exit dir: \00"
@FTS_F = global i32 0
@.str.5 = [12 x i8] c"File: \00"
@.str.6 = [12 x i8] c"Other: \00"
@.str.8 = [10 x i8] c"fts_close\00"
define i32 @main() {
%1 = alloca [2 x i8*]
%2 = bitcast [2 x i8*]* %1 to i8*
%3 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 0
%4 = load i32, i32* @FTS_PHYSICAL
%5 = call i32* @fts_open(i8** %3, i32 %4, i32* null)
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call %struct.TYPE_3__* @fts_read(i32* %5)
%9 = icmp eq %struct.TYPE_3__* %8, null
br i1 %9, label %14, label %21
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %37, %7
%15 = load i64, i64* @errno
%16 = icmp eq i64 %15, 0
br i1 %16, label %45, label %17
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %7, %37
%22 = phi %struct.TYPE_3__* [ %43, %37 ], [ %8, %7 ]
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @FTS_D
%26 = and i32 %25, %24
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %21
%29 = load i32, i32* @FTS_DP
%30 = and i32 %29, %24
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* @FTS_F
%34 = and i32 %33, %24
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0)
br label %37
37: ; preds = %32, %28, %21
%38 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %21 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %28 ], [ %36, %32 ]
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %38)
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 1
%41 = load i8*, i8** %40
%42 = call i32 @puts(i8* dereferenceable(1) %41)
%43 = call %struct.TYPE_3__* @fts_read(i32* %5)
%44 = icmp eq %struct.TYPE_3__* %43, null
br i1 %44, label %14, label %21
45: ; preds = %14
%46 = call i32 @fts_close(i32* %5)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
ret i32 0
}