#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 *);
scalar_t__ strncmp(char *, char *, int);
char *strrchr(char *, char);
int fnames_equal(char *a, char *b) {
  char *adotpos = strrchr(a, '.');
  char *bdotpos = strrchr(b, '.');
  int adotlen = (adotpos == NULL) ? 0 : strlen(adotpos);
  int bdotlen = (bdotpos == NULL) ? 0 : strlen(bdotpos);
  int alen = strlen(a) - adotlen;
  int blen = strlen(b) - bdotlen;
  return alen == blen && strncmp(a, b, alen) == 0;
}


x86 assembly (clang, -O0):
<fnames_equal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1179 <fnames_equal+0x49>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    1185 <fnames_equal+0x55>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a0 <fnames_equal+0x70>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    11ac <fnames_equal+0x7c>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x30(%rbp),%ecx
mov    %al,-0x39(%rbp)
jne    11fb <fnames_equal+0xcb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnames_equal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbp
xor    %r12d,%r12d
mov    $0x0,%r13d
test   %rbx,%rbx
je     1177 <fnames_equal+0x47>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
test   %rbp,%rbp
je     1187 <fnames_equal+0x57>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
sub    %r13d,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
sub    %r12d,%ecx
xor    %eax,%eax
cmp    %ecx,%ebp
jne    11bf <fnames_equal+0x8f>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fnames_equal(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %3
%12 = call i8* @strrchr(i8* %11, i8 signext 46)
store i8* %12, i8** %5
%13 = load i8*, i8** %4
%14 = call i8* @strrchr(i8* %13, i8 signext 46)
store i8* %14, i8** %6
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
br label %21
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
br label %21
21: ; preds = %18, %17
%22 = phi i32 [ 0, %17 ], [ %20, %18 ]
store i32 %22, i32* %7
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %21
br label %29
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
br label %29
29: ; preds = %26, %25
%30 = phi i32 [ 0, %25 ], [ %28, %26 ]
store i32 %30, i32* %8
%31 = load i8*, i8** %3
%32 = call i32 @strlen(i8* %31)
%33 = load i32, i32* %7
%34 = sub nsw i32 %32, %33
store i32 %34, i32* %9
%35 = load i8*, i8** %4
%36 = call i32 @strlen(i8* %35)
%37 = load i32, i32* %8
%38 = sub nsw i32 %36, %37
store i32 %38, i32* %10
%39 = load i32, i32* %9
%40 = load i32, i32* %10
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %48
42: ; preds = %29
%43 = load i8*, i8** %3
%44 = load i8*, i8** %4
%45 = load i32, i32* %9
%46 = call i64 @strncmp(i8* %43, i8* %44, i32 %45)
%47 = icmp eq i64 %46, 0
br label %48
48: ; preds = %42, %29
%49 = phi i1 [ false, %29 ], [ %47, %42 ]
%50 = zext i1 %49 to i32
ret i32 %50
}

LLVM IR (-O2):
define i32 @fnames_equal(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 46)
%5 = icmp eq i8* %3, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %3)
br label %8
8: ; preds = %2, %6
%9 = phi i32 [ %7, %6 ], [ 0, %2 ]
%10 = icmp eq i8* %4, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %4)
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ %12, %11 ], [ 0, %8 ]
%15 = tail call i32 @strlen(i8* %0)
%16 = sub nsw i32 %15, %9
%17 = tail call i32 @strlen(i8* %1)
%18 = sub nsw i32 %17, %14
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = tail call i64 @strncmp(i8* %0, i8* %1, i32 %16)
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %20, %13
%25 = phi i32 [ 0, %13 ], [ %23, %20 ]
ret i32 %25
}