#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 {
  size_t d_name;
};

/* Variables and functions */
size_t strlen(size_t);
scalar_t__ strncmp(size_t, char *, int);
int filter_extension_dat(const struct dirent *d) {
  size_t len = strlen(d->d_name);
  return (len > 4) && (strncmp(d->d_name + (len - 4), ".dat", 4) == 0);
}


x86 assembly (clang, -O0):
<filter_extension_dat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x4,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jbe    1179 <filter_extension_dat+0x59>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
sub    $0x4,%rax
add    %rax,%rdi
lea    0xe9b(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_extension_dat>:
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x5,%rcx
jb     115e <filter_extension_dat+0x3e>
mov    (%rbx),%rax
lea    (%rcx,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xeb7(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i64 }
@.str = [5 x i8] c".dat\00"
define i32 @filter_extension_dat(%struct.dirent* %0) {
%2 = alloca %struct.dirent*
%3 = alloca i64
store %struct.dirent* %0, %struct.dirent** %2
%4 = load %struct.dirent*, %struct.dirent** %2
%5 = getelementptr inbounds %struct.dirent, %struct.dirent* %4, i32 0, i32 0
%6 = load i64, i64* %5
%7 = call i64 @strlen(i64 %6)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = icmp ugt i64 %8, 4
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load %struct.dirent*, %struct.dirent** %2
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* %3
%15 = sub i64 %14, 4
%16 = add i64 %13, %15
%17 = call i64 @strncmp(i64 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%18 = icmp eq i64 %17, 0
br label %19
19: ; preds = %10, %1
%20 = phi i1 [ false, %1 ], [ %18, %10 ]
%21 = zext i1 %20 to i32
ret i32 %21
}

LLVM IR (-O2):
%struct.dirent = type { i64 }
@.str = [5 x i8] c".dat\00"
define i32 @filter_extension_dat(%struct.dirent* nocapture %0) {
%2 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = tail call i64 @strlen(i64 %3)
%5 = icmp ugt i64 %4, 4
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i64, i64* %2
%8 = add i64 %4, -4
%9 = add i64 %8, %7
%10 = tail call i64 @strncmp(i64 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %6, %1
%14 = phi i32 [ 0, %1 ], [ %12, %6 ]
ret i32 %14
}