#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 dirent {
  int d_type;
  char *d_name;
};

/* Variables and functions */
int DT_CHR;
int DT_REG;
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int filter(const struct dirent *file) {
  char *est;
  if (file->d_type != (DT_REG | DT_CHR))
    return 0;
  if ((est = strrchr(file->d_name, '.')) == NULL)
    return 0;
  if (strcmp(est + 1, "so"))
    return 0;
  if (!strcmp(file->d_name, "libdbf2txt.so"))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e96(%rip),%rdx
or     (%rdx),%ecx
cmp    %ecx,%eax
je     1158 <filter+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11df <filter+0xbf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1184 <filter+0x64>
movl   $0x0,-0x4(%rbp)
jmp    11df <filter+0xbf>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe78(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11ae <filter+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    11df <filter+0xbf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe43(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11d8 <filter+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    11df <filter+0xbf>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eb6(%rip),%rax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %ebp,%ebp
cmp    %ecx,(%rdi)
jne    1182 <filter+0x62>
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1182 <filter+0x62>
add    $0x1,%rax
lea    0xeaf(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1182 <filter+0x62>
mov    0x8(%rbx),%rdi
lea    0xe8c(%rip),%rsi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32, i8* }
@DT_REG = global i32 0
@DT_CHR = global i32 0
@.str = [3 x i8] c"so\00"
@.str.1 = [14 x i8] c"libdbf2txt.so\00"
define i32 @filter(%struct.dirent* %0) {
%2 = alloca i32
%3 = alloca %struct.dirent*
%4 = alloca i8*
store %struct.dirent* %0, %struct.dirent** %3
%5 = load %struct.dirent*, %struct.dirent** %3
%6 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @DT_REG
%9 = load i32, i32* @DT_CHR
%10 = or i32 %8, %9
%11 = icmp ne i32 %7, %10
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %2
br label %34
13: ; preds = %1
%14 = load %struct.dirent*, %struct.dirent** %3
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 1
%16 = load i8*, i8** %15
%17 = call i8* @strrchr(i8* %16, i8 signext 46)
store i8* %17, i8** %4
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 0, i32* %2
br label %34
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 0, i32* %2
br label %34
26: ; preds = %20
%27 = load %struct.dirent*, %struct.dirent** %3
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %26
store i32 0, i32* %2
br label %34
33: ; preds = %26
store i32 1, i32* %2
br label %34
34: ; preds = %33, %32, %25, %19, %12
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
%struct.dirent = type { i32, i8* }
@DT_REG = global i32 0
@DT_CHR = global i32 0
@.str = [3 x i8] c"so\00"
@.str.1 = [14 x i8] c"libdbf2txt.so\00"
define i32 @filter(%struct.dirent* nocapture %0) {
%2 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = load i32, i32* @DT_REG
%5 = load i32, i32* @DT_CHR
%6 = or i32 %5, %4
%7 = icmp eq i32 %3, %6
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 1
%10 = load i8*, i8** %9
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %10, i8 signext 46)
%12 = icmp eq i8* %11, null
br i1 %12, label %22, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8*, i8** %9
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %17, %13, %8, %1
%23 = phi i32 [ 0, %1 ], [ 0, %8 ], [ 0, %13 ], [ %21, %17 ]
ret i32 %23
}