#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 */
char *baseFilename(char const *const);
char *eStrndup(char const *const, int);
scalar_t__ strcmp(char const *, char const *const);
char *strrchr(char const *const, char const);
extern char *baseFilenameSansExtensionNew(const char *const fileName,
                                          const char *const templateExt) {
  const char *pDelimiter;
  const char *const base = baseFilename(fileName);
  char *shorten_base;
  pDelimiter = strrchr(base, templateExt[0]);
  if (pDelimiter && (strcmp(pDelimiter, templateExt) == 0)) {
    shorten_base = eStrndup(base, pDelimiter - base);
    return shorten_base;
  } else
    return NULL;
}


x86 assembly (clang, -O0):
<baseFilenameSansExtensionNew>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <baseFilename@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ba <baseFilenameSansExtensionNew+0x7a>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ba <baseFilenameSansExtensionNew+0x7a>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1030 <eStrndup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <baseFilenameSansExtensionNew+0x82>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<baseFilenameSansExtensionNew>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
call   1040 <baseFilename@plt>
mov    %rax,%r14
movsbl (%r15),%esi
mov    %rax,%rdi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1174 <baseFilenameSansExtensionNew+0x34>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     117c <baseFilenameSansExtensionNew+0x3c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
sub    %r14d,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <eStrndup@plt>

LLVM IR (-O0):
define i8* @baseFilenameSansExtensionNew(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i8* @baseFilename(i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = call i8* @strrchr(i8* %11, i8 signext %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %33
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = load i8*, i8** %5
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = ptrtoint i8* %25 to i64
%28 = ptrtoint i8* %26 to i64
%29 = sub i64 %27, %28
%30 = trunc i64 %29 to i32
%31 = call i8* @eStrndup(i8* %24, i32 %30)
store i8* %31, i8** %8
%32 = load i8*, i8** %8
store i8* %32, i8** %3
br label %34
33: ; preds = %18, %2
store i8* null, i8** %3
br label %34
34: ; preds = %33, %23
%35 = load i8*, i8** %3
ret i8* %35
}

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