#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__ match_input_suffix(char *);
int strlen(char *);
char *strrchr(char *, char);
int filename_length_without_suffix(char *in_fn) {
  char *p;
  int len = strlen(in_fn);
  p = strrchr(in_fn, '.');
  if (p && match_input_suffix(p))
    return (p - in_fn);
  return (len);
}


x86 assembly (clang, -O0):
<filename_length_without_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118b <filename_length_without_suffix+0x5b>
mov    -0x18(%rbp),%rdi
call   1050 <match_input_suffix@plt>
cmp    $0x0,%rax
je     118b <filename_length_without_suffix+0x5b>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    1191 <filename_length_without_suffix+0x61>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_length_without_suffix>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1166 <filename_length_without_suffix+0x36>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <match_input_suffix@plt>
test   %rax,%rax
je     1166 <filename_length_without_suffix+0x36>
sub    %ebx,%ebp
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @filename_length_without_suffix(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i8*, i8** %3
%9 = call i8* @strrchr(i8* %8, i8 signext 46)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %23
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i64 @match_input_suffix(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
store i32 %22, i32* %2
br label %25
23: ; preds = %12, %1
%24 = load i32, i32* %5
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %16
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @filename_length_without_suffix(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = tail call i64 @match_input_suffix(i8* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = ptrtoint i8* %3 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %1, %5, %8
%14 = phi i32 [ %12, %8 ], [ %2, %5 ], [ %2, %1 ]
ret i32 %14
}