#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 *strdup(char const *);
char *strndup(char const *, int);
char *strrchr(char const *, char);
char *mz_utils_get_filename_without_extension(const char *filename) {
  char *dot;
  if (!filename)
    return NULL;
  dot = strrchr(filename, '.');
  if (!dot)
    return strdup(filename);
  return strndup(filename, dot - filename);
}


x86 assembly (clang, -O0):
<mz_utils_get_filename_without_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <mz_utils_get_filename_without_extension+0x24>
movq   $0x0,-0x8(%rbp)
jmp    119d <mz_utils_get_filename_without_extension+0x6d>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <mz_utils_get_filename_without_extension+0x53>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    119d <mz_utils_get_filename_without_extension+0x6d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1040 <strndup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mz_utils_get_filename_without_extension>:
push   %rbx
test   %rdi,%rdi
je     1155 <mz_utils_get_filename_without_extension+0x25>
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1159 <mz_utils_get_filename_without_extension+0x29>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
jmp    1040 <strndup@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <strdup@plt>

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

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