#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 */
char *options_get_extension();
scalar_t__ strcmp(char *, char *);
char *strrchr(char const *, char);
int extension_match(const char *filename) {
  char *lastdot;
  char *extension = options_get_extension();
  if (extension == NULL) {
    return 1;
  }
  lastdot = strrchr(filename, '.');
  if (lastdot == NULL)
    return 0;
  lastdot++;
  return strcmp(lastdot, extension) == 0;
}


x86 assembly (clang, -O0):
<extension_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <options_get_extension@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115e <extension_match+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    11af <extension_match+0x7f>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <extension_match+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11af <extension_match+0x7f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extension_match>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <options_get_extension@plt>
test   %rax,%rax
je     1174 <extension_match+0x44>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1179 <extension_match+0x49>
add    $0x1,%rax
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
jmp    1179 <extension_match+0x49>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @extension_match(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = call i8* (...) @options_get_extension()
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %2
br label %24
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @strrchr(i8* %11, i8 signext 46)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 0, i32* %2
br label %24
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
store i32 %23, i32* %2
br label %24
24: ; preds = %16, %15, %9
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @extension_match(i8* %0) {
%2 = tail call i8* (...) @options_get_extension()
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%6 = icmp eq i8* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = tail call i64 @strcmp(i8* %8, i8* %2)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %4, %1, %7
%13 = phi i32 [ %11, %7 ], [ 1, %1 ], [ 0, %4 ]
ret i32 %13
}