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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ get_suffix(char *, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcmp(char *, char *);
scalar_t__ strlen(char *);
int _select_img_files(const struct dirent *entry) {
  int select;
  char *fname;
  char *suff;
  suff = NULL;
  fname = (char *)entry->d_name;
  suff = malloc(strlen(fname) + 1);
  if (suff == NULL)
    goto fail;
  get_suffix(fname, suff);
  if (!strcmp(suff, "img"))
    select = 1;
  else
    select = 0;
  free(suff);
  return select;
fail:
  if (suff != NULL)
    free(suff);
  return 0;
}


x86 assembly (clang, -O0):
<_select_img_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1198 <_select_img_files+0x48>
jmp    11e5 <_select_img_files+0x95>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <get_suffix@plt>
mov    -0x28(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11ca <_select_img_files+0x7a>
movl   $0x1,-0x14(%rbp)
jmp    11d1 <_select_img_files+0x81>
movl   $0x0,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <_select_img_files+0xb0>
cmpq   $0x0,-0x28(%rbp)
je     11f9 <_select_img_files+0xa9>
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):
<_select_img_files>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     119c <_select_img_files+0x4c>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <get_suffix@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    119e <_select_img_files+0x4e>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i64 }
@.str = [4 x i8] c"img\00"
define i32 @_select_img_files(%struct.dirent* %0) {
%2 = alloca i32
%3 = alloca %struct.dirent*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store %struct.dirent* %0, %struct.dirent** %3
store i8* null, i8** %6
%7 = load %struct.dirent*, %struct.dirent** %3
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 1
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %1
br label %31
18: ; preds = %1
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = call i32 @get_suffix(i8* %19, i8* %20)
%22 = load i8*, i8** %6
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %18
store i32 1, i32* %4
br label %27
26: ; preds = %18
store i32 0, i32* %4
br label %27
27: ; preds = %26, %25
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %4
store i32 %30, i32* %2
br label %38
31: ; preds = %17
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %34, %31
store i32 0, i32* %2
br label %38
38: ; preds = %37, %27
%39 = load i32, i32* %2
ret i32 %39
}

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