#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 *);
int has_extension(char *fname, char *ext) {
  int i = strlen(fname) - 1, j = strlen(ext) - 1;
  while (i >= 0 && j >= 0) {
    if (fname[i] != ext[j])
      return 0;
    i--;
    j--;
  }
  return 1;
}


x86 assembly (clang, -O0):
<has_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>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jl     1157 <has_extension+0x47>
cmpl   $0x0,-0x20(%rbp)
setge  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1167 <has_extension+0x57>
jmp    11aa <has_extension+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1193 <has_extension+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <has_extension+0xa1>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    113e <has_extension+0x2e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_extension>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebp,%ecx
mov    %eax,%edx
nopl   (%rax)
mov    $0x1,%eax
test   %ecx,%ecx
jle    1156 <has_extension+0x46>
test   %edx,%edx
jle    1156 <has_extension+0x46>
movzbl -0x1(%rbx,%rcx,1),%eax
lea    -0x1(%rdx),%rsi
add    $0xffffffffffffffff,%rcx
cmp    -0x1(%r14,%rdx,1),%al
mov    %rsi,%rdx
je     1130 <has_extension+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @has_extension(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = zext i32 %3 to i64
%6 = zext i32 %4 to i64
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 %9 to i32
%13 = icmp sgt i32 %12, 0
%14 = trunc i64 %8 to i32
%15 = icmp sgt i32 %14, 0
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %23
17: ; preds = %7
%18 = getelementptr inbounds i8, i8* %0, i64 %11
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %1, i64 %10
%21 = load i8, i8* %20
%22 = icmp eq i8 %19, %21
br i1 %22, label %7, label %23
23: ; preds = %7, %17
%24 = phi i32 [ 0, %17 ], [ 1, %7 ]
ret i32 %24
}