#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 msdos_dir_entry {
  int *name;
  int attr;
};
struct dir_info_s {
  int dummy;
};
struct FAT16_info_s {
  int dummy;
};

/* Variables and functions */
int DELETED_FLAG;
int *MSDOS_DOT;
struct msdos_dir_entry *next_dir(int, struct FAT16_info_s *,
                                 struct dir_info_s *);
int /*<<< orphan*/ print_name(int, struct FAT16_info_s *,
                              struct msdos_dir_entry *);
void dir_walker(int fd, struct FAT16_info_s *FAT16_info,
                struct dir_info_s *dir_info) {
  struct msdos_dir_entry *dir_entry;
  for (dir_entry = next_dir(fd, FAT16_info, dir_info);
       dir_entry != NULL && dir_entry->name[0] != 0x00;
       dir_entry = next_dir(fd, FAT16_info, dir_info)) {
    if (dir_entry->name[0] == MSDOS_DOT[0])
      continue;
    if (dir_entry->name[0] == DELETED_FLAG)
      continue;
    if (dir_entry->attr & 0x40)
      continue;
    if (dir_entry->attr & 0x80)
      continue;
    if (dir_entry->attr == 0xF)
      continue;
    print_name(fd, FAT16_info, dir_entry);
    dir_entry = next_dir(fd, FAT16_info, dir_info);
  }
}


x86 assembly (clang, -O0):
<dir_walker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <next_dir@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     1167 <dir_walker+0x47>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
cmpl   $0x0,(%rax)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1177 <dir_walker+0x57>
jmp    1236 <dir_walker+0x116>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%rcx
cmp    (%rcx),%eax
jne    1197 <dir_walker+0x77>
jmp    121d <dir_walker+0xfd>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
jne    11b4 <dir_walker+0x94>
jmp    121d <dir_walker+0xfd>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     11cc <dir_walker+0xac>
jmp    121d <dir_walker+0xfd>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     11e6 <dir_walker+0xc6>
jmp    121d <dir_walker+0xfd>
mov    -0x20(%rbp),%rax
cmpl   $0xf,0x8(%rax)
jne    11f9 <dir_walker+0xd9>
jmp    121d <dir_walker+0xfd>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <print_name@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <next_dir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <next_dir@plt>
mov    %rax,-0x20(%rbp)
jmp    1147 <dir_walker+0x27>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_walker>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
call   1040 <next_dir@plt>
test   %rax,%rax
je     11a4 <dir_walker+0x84>
mov    0x2eb7(%rip),%r15
mov    0x2e90(%rip),%r12
jmp    1162 <dir_walker+0x42>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <next_dir@plt>
test   %rax,%rax
je     11a4 <dir_walker+0x84>
mov    (%rax),%rcx
mov    (%rcx),%ecx
test   %ecx,%ecx
je     11a4 <dir_walker+0x84>
mov    (%r15),%rdx
cmp    (%rdx),%ecx
je     1150 <dir_walker+0x30>
cmp    (%r12),%ecx
je     1150 <dir_walker+0x30>
mov    0x8(%rax),%ecx
cmp    $0xf,%ecx
je     1150 <dir_walker+0x30>
and    $0xc0,%ecx
jne    1150 <dir_walker+0x30>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <print_name@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <next_dir@plt>
jmp    1150 <dir_walker+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.FAT16_info_s = type { i32 }
%struct.dir_info_s = type { i32 }
%struct.msdos_dir_entry = type { i32*, i32 }
@MSDOS_DOT = global i32* null
@DELETED_FLAG = global i32 0
define void @dir_walker(i32 %0, %struct.FAT16_info_s* %1, %struct.dir_info_s* %2) {
%4 = alloca i32
%5 = alloca %struct.FAT16_info_s*
%6 = alloca %struct.dir_info_s*
%7 = alloca %struct.msdos_dir_entry*
store i32 %0, i32* %4
store %struct.FAT16_info_s* %1, %struct.FAT16_info_s** %5
store %struct.dir_info_s* %2, %struct.dir_info_s** %6
%8 = load i32, i32* %4
%9 = load %struct.FAT16_info_s*, %struct.FAT16_info_s** %5
%10 = load %struct.dir_info_s*, %struct.dir_info_s** %6
%11 = call %struct.msdos_dir_entry* @next_dir(i32 %8, %struct.FAT16_info_s* %9, %struct.dir_info_s* %10)
store %struct.msdos_dir_entry* %11, %struct.msdos_dir_entry** %7
br label %12
12: ; preds = %73, %3
%13 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%14 = icmp ne %struct.msdos_dir_entry* %13, null
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%17 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %16, i32 0, i32 0
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %15, %12
%23 = phi i1 [ false, %12 ], [ %21, %15 ]
br i1 %23, label %24, label %78
24: ; preds = %22
%25 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%26 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %25, i32 0, i32 0
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %28
%30 = load i32*, i32** @MSDOS_DOT
%31 = getelementptr inbounds i32, i32* %30, i64 0
%32 = load i32, i32* %31
%33 = icmp eq i32 %29, %32
br i1 %33, label %34, label %35
34: ; preds = %24
br label %73
35: ; preds = %24
%36 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%37 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %36, i32 0, i32 0
%38 = load i32*, i32** %37
%39 = getelementptr inbounds i32, i32* %38, i64 0
%40 = load i32, i32* %39
%41 = load i32, i32* @DELETED_FLAG
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %35
br label %73
44: ; preds = %35
%45 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%46 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = and i32 %47, 64
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
br label %73
51: ; preds = %44
%52 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%53 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = and i32 %54, 128
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %51
br label %73
58: ; preds = %51
%59 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%60 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = icmp eq i32 %61, 15
br i1 %62, label %63, label %64
63: ; preds = %58
br label %73
64: ; preds = %58
%65 = load i32, i32* %4
%66 = load %struct.FAT16_info_s*, %struct.FAT16_info_s** %5
%67 = load %struct.msdos_dir_entry*, %struct.msdos_dir_entry** %7
%68 = call i32 @print_name(i32 %65, %struct.FAT16_info_s* %66, %struct.msdos_dir_entry* %67)
%69 = load i32, i32* %4
%70 = load %struct.FAT16_info_s*, %struct.FAT16_info_s** %5
%71 = load %struct.dir_info_s*, %struct.dir_info_s** %6
%72 = call %struct.msdos_dir_entry* @next_dir(i32 %69, %struct.FAT16_info_s* %70, %struct.dir_info_s* %71)
store %struct.msdos_dir_entry* %72, %struct.msdos_dir_entry** %7
br label %73
73: ; preds = %64, %63, %57, %50, %43, %34
%74 = load i32, i32* %4
%75 = load %struct.FAT16_info_s*, %struct.FAT16_info_s** %5
%76 = load %struct.dir_info_s*, %struct.dir_info_s** %6
%77 = call %struct.msdos_dir_entry* @next_dir(i32 %74, %struct.FAT16_info_s* %75, %struct.dir_info_s* %76)
store %struct.msdos_dir_entry* %77, %struct.msdos_dir_entry** %7
br label %12
78: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.FAT16_info_s = type { i32 }
%struct.dir_info_s = type { i32 }
%struct.msdos_dir_entry = type { i32*, i32 }
@MSDOS_DOT = global i32* null
@DELETED_FLAG = global i32 0
define void @dir_walker(i32 %0, %struct.FAT16_info_s* %1, %struct.dir_info_s* %2) {
%4 = tail call %struct.msdos_dir_entry* @next_dir(i32 %0, %struct.FAT16_info_s* %1, %struct.dir_info_s* %2)
%5 = icmp eq %struct.msdos_dir_entry* %4, null
br i1 %5, label %32, label %6
6: ; preds = %3, %29
%7 = phi %struct.msdos_dir_entry* [ %30, %29 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %7, i64 0, i32 0
%9 = load i32*, i32** %8
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %6
%13 = load i32*, i32** @MSDOS_DOT
%14 = load i32, i32* %13
%15 = icmp eq i32 %10, %14
%16 = load i32, i32* @DELETED_FLAG
%17 = icmp eq i32 %10, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %29, label %19
19: ; preds = %12
%20 = getelementptr inbounds %struct.msdos_dir_entry, %struct.msdos_dir_entry* %7, i64 0, i32 1
%21 = load i32, i32* %20
%22 = and i32 %21, 192
%23 = icmp ne i32 %22, 0
%24 = icmp eq i32 %21, 15
%25 = or i1 %24, %23
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = tail call i32 @print_name(i32 %0, %struct.FAT16_info_s* %1, %struct.msdos_dir_entry* %7)
%28 = tail call %struct.msdos_dir_entry* @next_dir(i32 %0, %struct.FAT16_info_s* %1, %struct.dir_info_s* %2)
br label %29
29: ; preds = %19, %12, %26
%30 = tail call %struct.msdos_dir_entry* @next_dir(i32 %0, %struct.FAT16_info_s* %1, %struct.dir_info_s* %2)
%31 = icmp eq %struct.msdos_dir_entry* %30, null
br i1 %31, label %32, label %6
32: ; preds = %6, %29, %3
ret void
}