#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 /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ _log(int /*<<< orphan*/, char *, char const *, char const *);
int /*<<< orphan*/ dirfd(int /*<<< orphan*/ *);
int /*<<< orphan*/ fstatat(int /*<<< orphan*/, char const *, struct stat *,
                           int /*<<< orphan*/);
scalar_t__ strcmp(char const *, char *);
size_t strlen(char const *);
int cfg_files_filter_out(DIR *d, const char *dir, const char *name) {
  size_t len = strlen(name);
  struct stat st;
  if (name[0] == '.')
    return 1;
  if (len < 6 || !(strcmp((name + len - 5), (".conf")) == 0)) {
    _log(LOG_INFO, "All cfg files need .conf: %s/%s\n", dir, name);
    return 1;
  }
  fstatat(dirfd(d), name, &st, 0);
  if (S_ISDIR(st.st_mode)) {
    _log(LOG_ERR, "Directories inside directories are not supported: %s/%s\n",
         dir, name);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cfg_files_filter_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    119d <cfg_files_filter_out+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    124f <cfg_files_filter_out+0xef>
cmpq   $0x6,-0x28(%rbp)
jb     11ca <cfg_files_filter_out+0x6a>
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe45(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11f3 <cfg_files_filter_out+0x93>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe24(%rip),%rsi
call   1030 <_log@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <cfg_files_filter_out+0xef>
mov    -0x10(%rbp),%rdi
call   1070 <dirfd@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %ecx,%ecx
call   1080 <fstatat@plt>
mov    -0x30(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1248 <cfg_files_filter_out+0xe8>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdf0(%rip),%rsi
call   1030 <_log@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <cfg_files_filter_out+0xef>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_files_filter_out>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%ebp
cmpb   $0x2e,(%rbx)
je     11c1 <cfg_files_filter_out+0x61>
cmp    $0x6,%rax
jb     11a1 <cfg_files_filter_out+0x41>
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe69(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ce <cfg_files_filter_out+0x6e>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <_log@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1070 <dirfd@plt>
mov    %rsp,%rdx
xor    %ebp,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1080 <fstatat@plt>
mov    (%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     11c1 <cfg_files_filter_out+0x61>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
jmp    11b1 <cfg_files_filter_out+0x51>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c".conf\00"
@LOG_INFO = global i32 0
@.str.1 = [33 x i8] c"All cfg files need .conf: %s/%s\0A\00"
@LOG_ERR = global i32 0
@.str.2 = [57 x i8] c"Directories inside directories are not supported: %s/%s\0A\00"
define i32 @cfg_files_filter_out(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.stat
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %8
%12 = load i8*, i8** %7
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 46
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 1, i32* %4
br label %48
18: ; preds = %3
%19 = load i64, i64* %8
%20 = icmp ult i64 %19, 6
br i1 %20, label %28, label %21
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = load i64, i64* %8
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 -5
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %21, %18
%29 = load i32, i32* @LOG_INFO
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = call i32 @_log(i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
store i32 1, i32* %4
br label %48
33: ; preds = %21
%34 = load i32*, i32** %5
%35 = call i32 @dirfd(i32* %34)
%36 = load i8*, i8** %7
%37 = call i32 @fstatat(i32 %35, i8* %36, %struct.stat* %9, i32 0)
%38 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i64 @S_ISDIR(i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %33
%43 = load i32, i32* @LOG_ERR
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = call i32 @_log(i32 %43, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %45)
store i32 1, i32* %4
br label %48
47: ; preds = %33
store i32 0, i32* %4
br label %48
48: ; preds = %47, %42, %28, %17
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c".conf\00"
@LOG_INFO = global i32 0
@.str.1 = [33 x i8] c"All cfg files need .conf: %s/%s\0A\00"
@LOG_ERR = global i32 0
@.str.2 = [57 x i8] c"Directories inside directories are not supported: %s/%s\0A\00"
define i32 @cfg_files_filter_out(i32* %0, i8* %1, i8* %2) {
%4 = alloca %struct.stat
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = bitcast %struct.stat* %4 to i8*
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 46
br i1 %8, label %29, label %9
9: ; preds = %3
%10 = icmp ult i64 %5, 6
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = getelementptr inbounds i8, i8* %2, i64 %5
%13 = getelementptr inbounds i8, i8* %12, i64 -5
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11, %9
%17 = load i32, i32* @LOG_INFO
%18 = tail call i32 @_log(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
br label %29
19: ; preds = %11
%20 = tail call i32 @dirfd(i32* %0)
%21 = call i32 @fstatat(i32 %20, i8* %2, %struct.stat* %4, i32 0)
%22 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @S_ISDIR(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = load i32, i32* @LOG_ERR
%28 = call i32 @_log(i32 %27, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
br label %29
29: ; preds = %19, %3, %26, %16
%30 = phi i32 [ 1, %16 ], [ 1, %26 ], [ 1, %3 ], [ 0, %19 ]
ret i32 %30
}