#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_level;
  char *fts_path;
  int /*<<< orphan*/ fts_info;
};
typedef TYPE_1__ FTSENT;
typedef int /*<<< orphan*/ FTS;

/* Variables and functions */
int FTS_NOCHDIR;
int FTS_PHYSICAL;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fts_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fts_open(char **, int, int /*<<< orphan*/ *);
TYPE_1__ *fts_read(int /*<<< orphan*/ *);
char *ftype(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, ...);
char *strerror(int /*<<< orphan*/);
void do_fts(const char *path) {
  char *paths[] = {(char *)path, NULL};
  FTS *fts;
  int options = FTS_PHYSICAL | FTS_NOCHDIR;
  fts = fts_open(paths, options, NULL);
  if (fts == NULL) {
    printf("fts_open(%s): %s\n", path, strerror(errno));
    return;
  }
  assert(fts != NULL);
  for (FTSENT *e = fts_read(fts); e; e = fts_read(fts)) {
    printf("%-12s level %d %s\n", ftype(e->fts_info), e->fts_level,
           e->fts_path);
  }
  fts_close(fts);
}


x86 assembly (clang, -O0):
<do_fts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    0x2e34(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <fts_open@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f0 <do_fts+0x80>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1260 <do_fts+0xf0>
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fts_read@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1257 <do_fts+0xe7>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%edi
call   1080 <ftype@plt>
mov    %rax,%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fts_read@plt>
mov    %rax,-0x38(%rbp)
jmp    120f <do_fts+0x9f>
mov    -0x28(%rbp),%rdi
call   1030 <fts_close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_fts>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    %rdi,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e60(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rsp,%rdi
xor    %edx,%edx
call   1060 <fts_open@plt>
test   %rax,%rax
je     1205 <do_fts+0x95>
mov    %rax,%r15
mov    $0x1,%edi
call   1070 <assert@plt>
mov    %r15,%rdi
call   1050 <fts_read@plt>
test   %rax,%rax
je     11fb <do_fts+0x8b>
mov    %rax,%rbx
lea    0xe44(%rip),%r14
xchg   %ax,%ax
mov    0x10(%rbx),%edi
call   1080 <ftype@plt>
mov    (%rbx),%edx
mov    0x8(%rbx),%rcx
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <fts_read@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d0 <do_fts+0x60>
mov    %r15,%rdi
call   1030 <fts_close@plt>
jmp    1227 <do_fts+0xb7>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xde6(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8*, i32 }
@FTS_PHYSICAL = global i32 0
@FTS_NOCHDIR = global i32 0
@.str = [18 x i8] c"fts_open(%s): %s\0A\00"
@errno = global i32 0
@.str.1 = [19 x i8] c"%-12s level %d %s\0A\00"
define void @do_fts(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i8*]
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.TYPE_3__*
store i8* %0, i8** %2
%7 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%8 = load i8*, i8** %2
store i8* %8, i8** %7
%9 = getelementptr inbounds i8*, i8** %7, i64 1
store i8* null, i8** %9
%10 = load i32, i32* @FTS_PHYSICAL
%11 = load i32, i32* @FTS_NOCHDIR
%12 = or i32 %10, %11
store i32 %12, i32* %5
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%14 = load i32, i32* %5
%15 = call i32* @fts_open(i8** %13, i32 %14, i32* null)
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %21)
br label %51
23: ; preds = %1
%24 = load i32*, i32** %4
%25 = icmp ne i32* %24, null
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i32*, i32** %4
%29 = call %struct.TYPE_3__* @fts_read(i32* %28)
store %struct.TYPE_3__* %29, %struct.TYPE_3__** %6
br label %30
30: ; preds = %45, %23
%31 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%32 = icmp ne %struct.TYPE_3__* %31, null
br i1 %32, label %33, label %48
33: ; preds = %30
%34 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i8* @ftype(i32 %36)
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %41, i32 0, i32 1
%43 = load i8*, i8** %42
%44 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %37, i32 %40, i8* %43)
br label %45
45: ; preds = %33
%46 = load i32*, i32** %4
%47 = call %struct.TYPE_3__* @fts_read(i32* %46)
store %struct.TYPE_3__* %47, %struct.TYPE_3__** %6
br label %30
48: ; preds = %30
%49 = load i32*, i32** %4
%50 = call i32 @fts_close(i32* %49)
br label %51
51: ; preds = %48, %18
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8*, i32 }
@FTS_PHYSICAL = global i32 0
@FTS_NOCHDIR = global i32 0
@.str = [18 x i8] c"fts_open(%s): %s\0A\00"
@errno = global i32 0
@.str.1 = [19 x i8] c"%-12s level %d %s\0A\00"
define void @do_fts(i8* %0) {
%2 = alloca [2 x i8*]
%3 = bitcast [2 x i8*]* %2 to i8*
%4 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
store i8* %0, i8** %4
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %5
%6 = load i32, i32* @FTS_PHYSICAL
%7 = load i32, i32* @FTS_NOCHDIR
%8 = or i32 %7, %6
%9 = call i32* @fts_open(i8** %4, i32 %8, i32* null)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %13)
br label %33
15: ; preds = %1
%16 = call i32 @assert(i32 1)
%17 = call %struct.TYPE_3__* @fts_read(i32* %9)
%18 = icmp eq %struct.TYPE_3__* %17, null
br i1 %18, label %19, label %21
19: ; preds = %21, %15
%20 = call i32 @fts_close(i32* %9)
br label %33
21: ; preds = %15, %21
%22 = phi %struct.TYPE_3__* [ %31, %21 ], [ %17, %15 ]
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 2
%24 = load i32, i32* %23
%25 = call i8* @ftype(i32 %24)
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i64 0, i32 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %27, i8* %29)
%31 = call %struct.TYPE_3__* @fts_read(i32* %9)
%32 = icmp eq %struct.TYPE_3__* %31, null
br i1 %32, label %19, label %21
33: ; preds = %19, %11
ret void
}