#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *mstrdup(char const *);
int /*<<< orphan*/ stderr;
char *strrchr(char *, char);
char *chopname(const char *i) {
  char *p = mstrdup(i);
  char *t;
  if (p == NULL) {
    fprintf(stderr, "Out of memory.\n");
    exit(1);
  }
  t = strrchr(p, '/');
  if (t) {
    t = strrchr(t + 1, '.');
    if (t)
      *t = 0;
  }
  return p;
}


x86 assembly (clang, -O0):
<chopname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <mstrdup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <chopname+0x43>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cd <chopname+0x8d>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c8 <chopname+0x88>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11cd <chopname+0x8d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chopname>:
push   %rbx
call   1040 <mstrdup@plt>
test   %rax,%rax
je     117e <chopname+0x3e>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1179 <chopname+0x39>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1179 <chopname+0x39>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Out of memory.\0A\00"
define i8* @chopname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @mstrdup(i8* %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i8* @strrchr(i8* %14, i8 signext 47)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i8* @strrchr(i8* %20, i8 signext 46)
store i8* %21, i8** %4
%22 = load i8*, i8** %4
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i8*, i8** %4
store i8 0, i8* %25
br label %26
26: ; preds = %24, %18
br label %27
27: ; preds = %26, %13
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Out of memory.\0A\00"
define i8* @chopname(i8* %0) {
%2 = tail call i8* @mstrdup(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i8* @strrchr(i8* %2, i8 signext 47)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = tail call i8* @strrchr(i8* %12, i8 signext 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %11
store i8 0, i8* %13
br label %16
16: ; preds = %11, %15, %8
ret i8* %2
}