#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 strlen(char const *);
scalar_t__ tolower(char const);
int phonica_find_extension(const char *filename, const char *extension) {
  int i, j;
  i = strlen(filename);
  j = strlen(extension);
  if (i - j <= 1) {
    return 0;
  }
  while (i-- && j--) {
    if (tolower(filename[i]) != tolower(extension[j])) {
      return 0;
    }
  }
  if (filename[i] == '.') {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<phonica_find_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
cmp    $0x1,%eax
jg     1163 <phonica_find_extension+0x43>
movl   $0x0,-0x4(%rbp)
jmp    1214 <phonica_find_extension+0xf4>
jmp    1168 <phonica_find_extension+0x48>
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1195 <phonica_find_extension+0x75>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11a5 <phonica_find_extension+0x85>
jmp    11ec <phonica_find_extension+0xcc>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     11e7 <phonica_find_extension+0xc7>
movl   $0x0,-0x4(%rbp)
jmp    1214 <phonica_find_extension+0xf4>
jmp    1168 <phonica_find_extension+0x48>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    120d <phonica_find_extension+0xed>
movl   $0x1,-0x4(%rbp)
jmp    1214 <phonica_find_extension+0xf4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<phonica_find_extension>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%edx
mov    %ebx,%ecx
sub    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
jl     11ca <phonica_find_extension+0xaa>
movslq %ebx,%rbp
movslq %edx,%r13
not    %edx
add    %ebx,%edx
mov    %edx,0xc(%rsp)
add    %r13,%r15
add    $0xffffffffffffffff,%r15
neg    %r13
mov    %r14,0x10(%rsp)
add    %rbp,%r14
add    $0xffffffffffffffff,%r14
neg    %rbp
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
cmp    %r12,%rbp
je     11ae <phonica_find_extension+0x8e>
cmp    %r12,%r13
je     11b5 <phonica_find_extension+0x95>
movsbl (%r14,%r12,1),%edi
call   1040 <tolower@plt>
mov    %rax,%rbx
movsbl (%r15,%r12,1),%edi
call   1040 <tolower@plt>
add    $0xffffffffffffffff,%r12
cmp    %rax,%rbx
je     1180 <phonica_find_extension+0x60>
xor    %eax,%eax
jmp    11ca <phonica_find_extension+0xaa>
mov    $0xffffffff,%eax
jmp    11b9 <phonica_find_extension+0x99>
mov    0xc(%rsp),%eax
movslq %eax,%rcx
xor    %eax,%eax
mov    0x10(%rsp),%rdx
cmpb   $0x2e,(%rdx,%rcx,1)
sete   %al
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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