#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;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *private_concat_paths(char const *, char const *);
scalar_t__ stat(char *, struct stat *);
int lisys_dir_filter_dirs(const char *dir, const char *name, void *data) {
  char *path;
  struct stat st;
  path = private_concat_paths(dir, name);
  if (path == NULL)
    return 1;
  if (stat(path, &st) < 0) {
    free(path);
    return 0;
  }
  if (S_ISDIR(st.st_mode)) {
    free(path);
    return 1;
  }
  free(path);
  return 0;
}


x86 assembly (clang, -O0):
<lisys_dir_filter_dirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <private_concat_paths@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117c <lisys_dir_filter_dirs+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    11df <lisys_dir_filter_dirs+0x9f>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11a8 <lisys_dir_filter_dirs+0x68>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11df <lisys_dir_filter_dirs+0x9f>
mov    -0x30(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11cf <lisys_dir_filter_dirs+0x8f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11df <lisys_dir_filter_dirs+0x9f>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lisys_dir_filter_dirs>:
push   %rbp
push   %rbx
push   %rax
call   1060 <private_concat_paths@plt>
test   %rax,%rax
je     117b <lisys_dir_filter_dirs+0x3b>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     1182 <lisys_dir_filter_dirs+0x42>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    118c <lisys_dir_filter_dirs+0x4c>
mov    $0x1,%ebp
jmp    118c <lisys_dir_filter_dirs+0x4c>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @lisys_dir_filter_dirs(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.stat
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = call i8* @private_concat_paths(i8* %10, i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 1, i32* %4
br label %34
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = call i64 @stat(i8* %17, %struct.stat* %9)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = call i32 @free(i8* %21)
store i32 0, i32* %4
br label %34
23: ; preds = %16
%24 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @S_ISDIR(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
store i32 1, i32* %4
br label %34
31: ; preds = %23
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
store i32 0, i32* %4
br label %34
34: ; preds = %31, %28, %20, %15
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @lisys_dir_filter_dirs(i8* %0, i8* %1, i8* nocapture readnone %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = tail call i8* @private_concat_paths(i8* %0, i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = call i64 @stat(i8* %6, %struct.stat* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @free(i8* %6)
br label %20
13: ; preds = %8
%14 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @S_ISDIR(i32 %15)
%17 = icmp ne i64 %16, 0
%18 = call i32 @free(i8* %6)
%19 = zext i1 %17 to i32
br label %20
20: ; preds = %13, %3, %11
%21 = phi i32 [ 0, %11 ], [ 1, %3 ], [ %19, %13 ]
ret i32 %21
}