#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 */
scalar_t__ strlen(char const *);
scalar_t__ toupper(char const);
int CheckExtension(const char *filename, const char *ext) {
  int A = (int)strlen(filename) - 1;
  int B = (int)strlen(ext) - 1;
  for (; B >= 0; B--, A--) {
    if (A < 0)
      return 0;
    if (toupper(filename[A]) != toupper(ext[B]))
      return 0;
  }
  return (A >= 1) && (filename[A] == '.');
}


x86 assembly (clang, -O0):
<CheckExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11cc <CheckExtension+0xac>
cmpl   $0x0,-0x1c(%rbp)
jge    116e <CheckExtension+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11fb <CheckExtension+0xdb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     11b0 <CheckExtension+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11fb <CheckExtension+0xdb>
jmp    11b5 <CheckExtension+0x95>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <CheckExtension+0x2e>
xor    %eax,%eax
cmpl   $0x1,-0x1c(%rbp)
mov    %al,-0x29(%rbp)
jl     11f0 <CheckExtension+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckExtension>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebp,%ebp
mov    %eax,%ebx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
jle    1180 <CheckExtension+0x60>
test   %ebp,%ebp
jle    119a <CheckExtension+0x7a>
movsbl -0x1(%r14,%rbp,1),%edi
call   1030 <toupper@plt>
mov    %rax,%r13
movsbl -0x1(%r15,%rbx,1),%edi
call   1030 <toupper@plt>
add    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%rbp
cmp    %rax,%r13
je     1150 <CheckExtension+0x30>
jmp    119a <CheckExtension+0x7a>
xor    %r12d,%r12d
cmp    $0x2,%ebp
jl     119a <CheckExtension+0x7a>
add    $0xffffffffffffffff,%rbp
mov    %ebp,%eax
xor    %r12d,%r12d
cmpb   $0x2e,(%r14,%rax,1)
sete   %r12b
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CheckExtension(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %7
br label %16
16: ; preds = %39, %2
%17 = load i32, i32* %7
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 0, i32* %3
br label %58
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i64 @toupper(i8 signext %28)
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = call i64 @toupper(i8 signext %34)
%36 = icmp ne i64 %29, %35
br i1 %36, label %37, label %38
37: ; preds = %23
store i32 0, i32* %3
br label %58
38: ; preds = %23
br label %39
39: ; preds = %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, -1
store i32 %41, i32* %7
%42 = load i32, i32* %6
%43 = add nsw i32 %42, -1
store i32 %43, i32* %6
br label %16
44: ; preds = %16
%45 = load i32, i32* %6
%46 = icmp sge i32 %45, 1
br i1 %46, label %47, label %55
47: ; preds = %44
%48 = load i8*, i8** %4
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 46
br label %55
55: ; preds = %47, %44
%56 = phi i1 [ false, %44 ], [ %54, %47 ]
%57 = zext i1 %56 to i32
store i32 %57, i32* %3
br label %58
58: ; preds = %55, %37, %22
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
define i32 @CheckExtension(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = and i64 %3, 4294967295
%6 = and i64 %4, 4294967295
br label %7
7: ; preds = %17, %2
%8 = phi i64 [ %10, %17 ], [ %6, %2 ]
%9 = phi i64 [ %11, %17 ], [ %5, %2 ]
%10 = add nsw i64 %8, -1
%11 = add nsw i64 %9, -1
%12 = trunc i64 %8 to i32
%13 = icmp sgt i32 %12, 0
%14 = trunc i64 %9 to i32
br i1 %13, label %15, label %25
15: ; preds = %7
%16 = icmp slt i32 %14, 1
br i1 %16, label %34, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %0, i64 %11
%19 = load i8, i8* %18
%20 = tail call i64 @toupper(i8 signext %19)
%21 = getelementptr inbounds i8, i8* %1, i64 %10
%22 = load i8, i8* %21
%23 = tail call i64 @toupper(i8 signext %22)
%24 = icmp eq i64 %20, %23
br i1 %24, label %7, label %34
25: ; preds = %7
%26 = trunc i64 %9 to i32
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = and i64 %11, 4294967295
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 46
%33 = zext i1 %32 to i32
br label %34
34: ; preds = %17, %15, %25, %28
%35 = phi i32 [ 0, %25 ], [ %33, %28 ], [ 0, %15 ], [ 0, %17 ]
ret i32 %35
}