#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*/ die(char *, char const *);
void *strrchr(char const *, char);
char toupper(char);
char *xstrdup(char const *);
char *extract_lumpname(const char *filename) {
  const char *base;
  char *lumpname, *suffix, *c;
  base = strrchr(filename, '/');
  if (!base)
    base = filename;
  else
    base += 1;
  if (!*base)
    die("Empty lumpname: %s\n", filename);
  lumpname = xstrdup(base);
  suffix = strrchr(lumpname, '.');
  if (suffix)
    *suffix = '\0';
  for (c = lumpname; *c; c++)
    *c = toupper(*c);
  return lumpname;
}


x86 assembly (clang, -O0):
<extract_lumpname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1176 <extract_lumpname+0x36>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1182 <extract_lumpname+0x42>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119f <extract_lumpname+0x5f>
mov    -0x8(%rbp),%rsi
lea    0xe66(%rip),%rdi
call   1060 <die@plt>
mov    -0x10(%rbp),%rdi
call   1050 <xstrdup@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     11d0 <extract_lumpname+0x90>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     120a <extract_lumpname+0xca>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11d8 <extract_lumpname+0x98>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_lumpname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r14,%rbx
cmpb   $0x0,(%rbx)
jne    1170 <extract_lumpname+0x30>
lea    0xe98(%rip),%rdi
mov    %r14,%rsi
call   1060 <die@plt>
mov    %rbx,%rdi
call   1050 <xstrdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1190 <extract_lumpname+0x50>
movb   $0x0,(%rax)
mov    (%r14),%al
test   %al,%al
je     11b6 <extract_lumpname+0x76>
mov    %r14,%rbx
add    $0x1,%rbx
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <extract_lumpname+0x60>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Empty lumpname: %s\0A\00"
define i8* @extract_lumpname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = load i8*, i8** %2
store i8* %12, i8** %3
br label %16
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %3
br label %16
16: ; preds = %13, %11
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %16
%24 = load i8*, i8** %3
%25 = call i8* @xstrdup(i8* %24)
store i8* %25, i8** %4
%26 = load i8*, i8** %4
%27 = call i8* @strrchr(i8* %26, i8 signext 46)
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = load i8*, i8** %5
store i8 0, i8* %31
br label %32
32: ; preds = %30, %23
%33 = load i8*, i8** %4
store i8* %33, i8** %6
br label %34
34: ; preds = %43, %32
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %34
%39 = load i8*, i8** %6
%40 = load i8, i8* %39
%41 = call signext i8 @toupper(i8 signext %40)
%42 = load i8*, i8** %6
store i8 %41, i8* %42
br label %43
43: ; preds = %38
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %6
br label %34
46: ; preds = %34
%47 = load i8*, i8** %4
ret i8* %47
}

LLVM IR (-O2):
@.str = [20 x i8] c"Empty lumpname: %s\0A\00"
define i8* @extract_lumpname(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
%4 = getelementptr inbounds i8, i8* %2, i64 1
%5 = select i1 %3, i8* %0, i8* %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @die(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %1
%11 = tail call i8* @xstrdup(i8* %5)
%12 = tail call i8* @strrchr(i8* dereferenceable(1) %11, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %10
store i8 0, i8* %12
br label %15
15: ; preds = %14, %10
%16 = load i8, i8* %11
%17 = icmp eq i8 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15, %18
%19 = phi i8 [ %23, %18 ], [ %16, %15 ]
%20 = phi i8* [ %22, %18 ], [ %11, %15 ]
%21 = tail call signext i8 @toupper(i8 signext %19)
store i8 %21, i8* %20
%22 = getelementptr inbounds i8, i8* %20, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %18
25: ; preds = %18, %15
ret i8* %11
}