#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 stat {
  int dummy;
};

/* Variables and functions */
#define FTW_D 131
#define FTW_DNR 130
#define FTW_F 129
#define FTW_NS 128
int /*<<< orphan*/ printf(char *, ...);
int ftw_func(char const *fpath, struct stat const *sb, int typeflag) {
  switch (typeflag) {
  case FTW_F:
    printf("[R] %s\n", fpath);
    break;
  case FTW_D:
    printf("[D] %s\n", fpath);
    break;
  case FTW_DNR:
    printf("[DNR] %s\n", fpath);
    break;
  case FTW_NS:
    printf("[NS] %s\n", fpath);
    break;
  default:
    printf("unknown typeflag %d\n", typeflag);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ftw_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     11a8 <ftw_func+0x98>
mov    -0x28(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <ftw_func+0xb5>
mov    -0x10(%rbp),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <ftw_func+0xb5>
mov    -0x10(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <ftw_func+0xb5>
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <ftw_func+0xb5>
mov    -0x1c(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <ftw_func+0xbc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftw_func>:
push   %rbx
lea    -0x80(%rdx),%eax
cmp    $0x3,%eax
ja     1135 <ftw_func+0x25>
mov    %rdi,%rsi
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xef7(%rip),%rdi
jmp    1165 <ftw_func+0x55>
lea    0xef7(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
jmp    116e <ftw_func+0x5e>
lea    0xebd(%rip),%rdi
jmp    1165 <ftw_func+0x55>
lea    0xec4(%rip),%rdi
jmp    1165 <ftw_func+0x55>
lea    0xeb3(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [8 x i8] c"[R] %s\0A\00"
@.str.1 = [8 x i8] c"[D] %s\0A\00"
@.str.2 = [10 x i8] c"[DNR] %s\0A\00"
@.str.3 = [9 x i8] c"[NS] %s\0A\00"
@.str.4 = [21 x i8] c"unknown typeflag %d\0A\00"
define i32 @ftw_func(i8* %0, %struct.stat* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.stat*
%7 = alloca i32
store i8* %0, i8** %5
store %struct.stat* %1, %struct.stat** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
switch i32 %8, label %21 [
i32 129, label %9
i32 131, label %12
i32 130, label %15
i32 128, label %18
]
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %24
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %24
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %24
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %24
21: ; preds = %3
%22 = load i32, i32* %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %22)
store i32 -1, i32* %4
br label %25
24: ; preds = %18, %15, %12, %9
store i32 0, i32* %4
br label %25
25: ; preds = %24, %21
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [8 x i8] c"[R] %s\0A\00"
@.str.1 = [8 x i8] c"[D] %s\0A\00"
@.str.2 = [10 x i8] c"[DNR] %s\0A\00"
@.str.3 = [9 x i8] c"[NS] %s\0A\00"
@.str.4 = [21 x i8] c"unknown typeflag %d\0A\00"
define i32 @ftw_func(i8* %0, %struct.stat* nocapture readnone %1, i32 %2) {
switch i32 %2, label %12 [
i32 129, label %4
i32 131, label %6
i32 130, label %8
i32 128, label %10
]
4: ; preds = %3
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
6: ; preds = %3
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %14
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %14
10: ; preds = %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %14
12: ; preds = %3
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %2)
br label %14
14: ; preds = %4, %6, %8, %10, %12
%15 = phi i32 [ -1, %12 ], [ 0, %10 ], [ 0, %8 ], [ 0, %6 ], [ 0, %4 ]
ret i32 %15
}