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

/* Variables and functions */
scalar_t__ strcmp(char *, char *);
char *strrchr(char *, char);
int filter_images(const struct dirent *entry) {
  if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
    return 0;
  }
  char *ptr = strrchr(entry->d_name, '.');
  if (ptr != NULL && (strcmp(ptr, ".png") == 0 || strcmp(ptr, ".PNG") == 0 ||
                      strcmp(ptr, ".bmp") == 0 || strcmp(ptr, ".BMP") == 0 ||
                      strcmp(ptr, ".jpg") == 0 || strcmp(ptr, ".JPG") == 0)) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<filter_images>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xec7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1166 <filter_images+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xea9(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1172 <filter_images+0x52>
movl   $0x0,-0x4(%rbp)
jmp    1241 <filter_images+0x121>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     123a <filter_images+0x11a>
mov    -0x18(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     122e <filter_images+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     122e <filter_images+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     122e <filter_images+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     122e <filter_images+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     122e <filter_images+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xdfd(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    123a <filter_images+0x11a>
movl   $0x1,-0x4(%rbp)
jmp    1241 <filter_images+0x121>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_images>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%rdi
lea    0xed0(%rip),%rsi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11f1 <filter_images+0xd1>
mov    (%rbx),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f1 <filter_images+0xd1>
mov    (%rbx),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     11ef <filter_images+0xcf>
mov    %rax,%r14
lea    0xe8a(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11f1 <filter_images+0xd1>
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f1 <filter_images+0xd1>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f1 <filter_images+0xd1>
lea    0xe58(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f1 <filter_images+0xd1>
lea    0xe49(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f1 <filter_images+0xd1>
lea    0xe3a(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f1 <filter_images+0xd1>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [5 x i8] c".png\00"
@.str.3 = [5 x i8] c".PNG\00"
@.str.4 = [5 x i8] c".bmp\00"
@.str.5 = [5 x i8] c".BMP\00"
@.str.6 = [5 x i8] c".jpg\00"
@.str.7 = [5 x i8] c".JPG\00"
define i32 @filter_images(%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 i8*, i8** %6
%8 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = load %struct.dirent*, %struct.dirent** %3
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10, %1
store i32 0, i32* %2
br label %50
17: ; preds = %10
%18 = load %struct.dirent*, %struct.dirent** %3
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i8* @strrchr(i8* %20, i8 signext 46)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %49
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %48, label %28
28: ; preds = %24
%29 = load i8*, i8** %4
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %48, label %32
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %48, label %36
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %48, label %40
40: ; preds = %36
%41 = load i8*, i8** %4
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i8*, i8** %4
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44, %40, %36, %32, %28, %24
store i32 1, i32* %2
br label %50
49: ; preds = %44, %17
store i32 0, i32* %2
br label %50
50: ; preds = %49, %48, %16
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [5 x i8] c".png\00"
@.str.3 = [5 x i8] c".PNG\00"
@.str.4 = [5 x i8] c".bmp\00"
@.str.5 = [5 x i8] c".BMP\00"
@.str.6 = [5 x i8] c".jpg\00"
@.str.7 = [5 x i8] c".JPG\00"
define i32 @filter_images(%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 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %33, label %6
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %33, label %10
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = tail call i8* @strrchr(i8* dereferenceable(1) %11, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %32, label %14
14: ; preds = %10
%15 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %33, label %17
17: ; preds = %14
%18 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %20
%24 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %29, %10
br label %33
33: ; preds = %32, %29, %26, %23, %20, %17, %14, %1, %6
%34 = phi i32 [ 0, %6 ], [ 0, %1 ], [ 0, %32 ], [ 1, %29 ], [ 1, %26 ], [ 1, %23 ], [ 1, %20 ], [ 1, %17 ], [ 1, %14 ]
ret i32 %34
}