#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 *jlibtool_basename(char const *);
char *malloc(int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
const char *nameof(const char *fullpath) {
  const char *name;
  const char *ext;
  name = jlibtool_basename(fullpath);
  ext = strrchr(name, '.');
  if (ext) {
    char *trimmed;
    trimmed = malloc(ext - name + 1);
    strncpy(trimmed, name, ext - name);
    trimmed[ext - name] = 0;
    return trimmed;
  }
  return name;
}


x86 assembly (clang, -O0):
<nameof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <jlibtool_basename@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ca <nameof+0x8a>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d2 <nameof+0x92>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nameof>:
push   %r15
push   %r14
push   %rbx
call   1060 <jlibtool_basename@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1185 <nameof+0x45>
mov    %rax,%rbx
sub    %r14,%rbx
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @nameof(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @jlibtool_basename(i8* %7)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i8* @strrchr(i8* %9, i8 signext 46)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %39
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = add nsw i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i32 @strncpy(i8* %22, i8* %23, i32 %29)
%31 = load i8*, i8** %6
%32 = load i8*, i8** %5
%33 = load i8*, i8** %4
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = getelementptr inbounds i8, i8* %31, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %6
store i8* %38, i8** %2
br label %41
39: ; preds = %1
%40 = load i8*, i8** %4
store i8* %40, i8** %2
br label %41
41: ; preds = %39, %13
%42 = load i8*, i8** %2
ret i8* %42
}

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