#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 strcasecmp(char const *, char const *);
char *strrchr(char const *, char);
int compare_filenames(const void *_n1, const void *_n2) {
  const char *s1 = *(const char **)_n1;
  const char *s2 = *(const char **)_n2;
  char *e1 = strrchr(s1, '.');
  char *e2 = strrchr(s2, '.');
  if (!e1 && !e2)
    return 0;
  if (e1 && !e2)
    return 1;
  if (!e1 && e2)
    return -1;
  int c = strcasecmp(e1 + 1, e2 + 1);
  if (c)
    return c;
  return strcasecmp(s1, s2);
}


x86 assembly (clang, -O0):
<compare_filenames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    118c <compare_filenames+0x6c>
cmpq   $0x0,-0x38(%rbp)
jne    118c <compare_filenames+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    120d <compare_filenames+0xed>
cmpq   $0x0,-0x30(%rbp)
je     11ae <compare_filenames+0x8e>
cmpq   $0x0,-0x38(%rbp)
jne    11ae <compare_filenames+0x8e>
movl   $0x1,-0x4(%rbp)
jmp    120d <compare_filenames+0xed>
cmpq   $0x0,-0x30(%rbp)
jne    11d0 <compare_filenames+0xb0>
cmpq   $0x0,-0x38(%rbp)
je     11d0 <compare_filenames+0xb0>
movl   $0xffffffff,-0x4(%rbp)
jmp    120d <compare_filenames+0xed>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcasecmp@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11fd <compare_filenames+0xdd>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120d <compare_filenames+0xed>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcasecmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_filenames>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%r15
mov    (%rsi),%r14
mov    %r15,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
xor    %ecx,%ecx
mov    %rbx,%rdx
or     %rax,%rdx
je     1189 <compare_filenames+0x69>
test   %rbx,%rbx
je     1161 <compare_filenames+0x41>
mov    $0x1,%ecx
test   %rax,%rax
je     1189 <compare_filenames+0x69>
test   %rbx,%rbx
jne    1170 <compare_filenames+0x50>
mov    $0xffffffff,%ecx
test   %rax,%rax
jne    1189 <compare_filenames+0x69>
add    $0x1,%rbx
add    $0x1,%rax
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcasecmp@plt>
mov    %eax,%ecx
test   %eax,%eax
je     1191 <compare_filenames+0x71>
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcasecmp@plt>

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

LLVM IR (-O2):
define i32 @compare_filenames(i8* nocapture %0, i8* nocapture %1) {
%3 = bitcast i8* %0 to i8**
%4 = load i8*, i8** %3
%5 = bitcast i8* %1 to i8**
%6 = load i8*, i8** %5
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %4, i8 signext 46)
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext 46)
%9 = icmp ne i8* %7, null
%10 = icmp ne i8* %8, null
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = icmp eq i8* %7, null
%14 = select i1 %13, i1 true, i1 %10
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = select i1 %13, i1 %10, i1 false
br i1 %16, label %24, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = getelementptr inbounds i8, i8* %8, i64 1
%20 = tail call i32 @strcasecmp(i8* %18, i8* %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @strcasecmp(i8* %4, i8* %6)
br label %24
24: ; preds = %22, %17, %15, %12, %2
%25 = phi i32 [ 0, %2 ], [ 1, %12 ], [ -1, %15 ], [ %23, %22 ], [ %20, %17 ]
ret i32 %25
}