#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 */

/* Variables and functions */
int strcasecmp(char const *, char const *);
int strlen(char const *);
int imgCheckFileExtension(const char *fn, const char *ext) {
  if (!fn || !ext)
    return -1;
  if (strlen(fn) < strlen(ext))
    return -1;
  return strcasecmp(fn + strlen(fn) - strlen(ext), ext);
}


x86 assembly (clang, -O0):
<imgCheckFileExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <imgCheckFileExtension+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <imgCheckFileExtension+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <imgCheckFileExtension+0xa5>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1180 <imgCheckFileExtension+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <imgCheckFileExtension+0xa5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
movslq %eax,%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imgCheckFileExtension>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1147 <imgCheckFileExtension+0x27>
mov    %rsi,%r14
test   %rsi,%rsi
je     1147 <imgCheckFileExtension+0x27>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jge    1151 <imgCheckFileExtension+0x31>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
sub    %rax,%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strcasecmp@plt>

LLVM IR (-O0):
define i32 @imgCheckFileExtension(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %8, %2
store i32 -1, i32* %3
br label %32
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 -1, i32* %3
br label %32
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8*, i8** %5
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = sub i64 0, %27
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8*, i8** %5
%31 = call i32 @strcasecmp(i8* %29, i8* %30)
store i32 %31, i32* %3
br label %32
32: ; preds = %19, %18, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @imgCheckFileExtension(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = icmp slt i32 %7, %8
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = tail call i32 @strlen(i8* %0)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @strlen(i8* %1)
%15 = sext i32 %14 to i64
%16 = sub nsw i64 0, %15
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = tail call i32 @strcasecmp(i8* %17, i8* %1)
br label %19
19: ; preds = %6, %2, %10
%20 = phi i32 [ %18, %10 ], [ -1, %2 ], [ -1, %6 ]
ret i32 %20
}