#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__ strcasecmp(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
int csc_cmp_file_extname(char *fname, char *ext) {
  char *p;
  int n;
  if (!fname || !ext) {
    if (!fname && !ext) {
      return 0;
    }
    return -2;
  }
  if ((p = strrchr(ext, '.')) != NULL) {
    ext = p + 1;
  }
  if ((n = strlen(fname) - strlen(ext)) <= 0) {
    return -1;
  }
  if (fname[n - 1] != '.') {
    return n;
  }
  if (strcasecmp(fname + n, ext)) {
    return n;
  }
  return 0;
}


x86 assembly (clang, -O0):
<csc_cmp_file_extname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <csc_cmp_file_extname+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1184 <csc_cmp_file_extname+0x54>
cmpq   $0x0,-0x10(%rbp)
jne    1178 <csc_cmp_file_extname+0x48>
cmpq   $0x0,-0x18(%rbp)
jne    1178 <csc_cmp_file_extname+0x48>
movl   $0x0,-0x4(%rbp)
jmp    1235 <csc_cmp_file_extname+0x105>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1235 <csc_cmp_file_extname+0x105>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ac <csc_cmp_file_extname+0x7c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jg     11e0 <csc_cmp_file_extname+0xb0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <csc_cmp_file_extname+0x105>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1205 <csc_cmp_file_extname+0xd5>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1235 <csc_cmp_file_extname+0x105>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     122e <csc_cmp_file_extname+0xfe>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1235 <csc_cmp_file_extname+0x105>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csc_cmp_file_extname>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
je     1199 <csc_cmp_file_extname+0x69>
test   %rbx,%rbx
je     1199 <csc_cmp_file_extname+0x69>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%r15
test   %rax,%rax
cmove  %rbx,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
jle    11a9 <csc_cmp_file_extname+0x79>
lea    -0x1(%rbx),%eax
cmpb   $0x2e,(%r14,%rax,1)
jne    11ae <csc_cmp_file_extname+0x7e>
mov    %ebx,%eax
add    %rax,%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcasecmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
cmovne %ebx,%ecx
mov    %ecx,%ebx
jmp    11ae <csc_cmp_file_extname+0x7e>
xor    %eax,%eax
or     %rbx,%r14
sete   %al
lea    (%rax,%rax,1),%ebx
add    $0xfffffffe,%ebx
jmp    11ae <csc_cmp_file_extname+0x7e>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @csc_cmp_file_extname(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 %9, label %6
6: ; preds = %2
%7 = or i1 %3, %4
%8 = select i1 %7, i32 -2, i32 0
br label %30
9: ; preds = %2
%10 = tail call i8* @strrchr(i8* %1, i8 signext 46)
%11 = icmp eq i8* %10, null
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = select i1 %11, i8* %1, i8* %12
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i32 @strlen(i8* %13)
%16 = sub nsw i32 %14, %15
%17 = icmp slt i32 %16, 1
br i1 %17, label %30, label %18
18: ; preds = %9
%19 = add nsw i32 %16, -1
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 46
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = zext i32 %16 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = tail call i64 @strcasecmp(i8* %26, i8* %13)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i32 0, i32 %16
br label %30
30: ; preds = %24, %18, %9, %6
%31 = phi i32 [ %8, %6 ], [ -1, %9 ], [ %16, %18 ], [ %29, %24 ]
ret i32 %31
}