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

/* Variables and functions */
scalar_t__ DT_REG;
scalar_t__ strcmp(char *, char *);
size_t strlen(char *);
int is_bmp_file(struct dirent *ep) {
  char *filename = ep->d_name;
  size_t len = strlen(filename);
  if (len < 5 || ep->d_type != DT_REG) {
    return 0;
  }
  char *extension = &filename[len - 4];
  if (strcmp(extension, ".bmp") != 0) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_bmp_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x5,-0x20(%rbp)
jb     1167 <is_bmp_file+0x47>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
je     1173 <is_bmp_file+0x53>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <is_bmp_file+0x93>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x4,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11ac <is_bmp_file+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <is_bmp_file+0x93>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_bmp_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x5,%rcx
jb     116c <is_bmp_file+0x4c>
mov    0x8(%rbx),%rdx
mov    0x2e98(%rip),%rsi
cmp    (%rsi),%rdx
jne    116c <is_bmp_file+0x4c>
lea    (%rcx,%r14,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xea4(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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