#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 *malloc(int);
int strlen(char const *);
char *strrchr(char const *, char);
char *filename_to_title(const char *filename) {
  char *title = malloc(strlen(filename) * 2 + 1);
  char *s, *out = title;
  s = strrchr(filename, '/');
  if (s)
    filename = s + 1;
  while (*filename >= '0' && *filename <= '9')
    filename++;
  while (*filename == ' ')
    filename++;
  while (*filename) {
    char c = *filename++;
    *out++ = c;
  }
  *out = 0;
  s = strrchr(title, '.');
  if (s)
    *s = 0;
  return title;
}


x86 assembly (clang, -O0):
<filename_to_title>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1187 <filename_to_title+0x57>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    118c <filename_to_title+0x5c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x22(%rbp)
jl     11b1 <filename_to_title+0x81>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11c1 <filename_to_title+0x91>
jmp    11d2 <filename_to_title+0xa2>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    118c <filename_to_title+0x5c>
jmp    11d7 <filename_to_title+0xa7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11f8 <filename_to_title+0xc8>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <filename_to_title+0xa7>
jmp    11fd <filename_to_title+0xcd>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1237 <filename_to_title+0x107>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11fd <filename_to_title+0xcd>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1262 <filename_to_title+0x132>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_to_title>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %rbx,%rcx
add    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%rcx),%eax
add    $0x1,%rcx
lea    -0x30(%rax),%edx
cmp    $0xa,%dl
jb     1170 <filename_to_title+0x40>
jmp    1198 <filename_to_title+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x1(%rcx),%eax
add    $0x1,%rcx
cmp    $0x20,%al
je     1190 <filename_to_title+0x60>
mov    %r14,%rdx
test   %al,%al
je     11c1 <filename_to_title+0x91>
add    $0x1,%rcx
mov    %r14,%rdx
nopw   0x0(%rax,%rax,1)
mov    %al,(%rdx)
add    $0x1,%rdx
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    11b0 <filename_to_title+0x80>
movb   $0x0,(%rdx)
mov    %r14,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11d9 <filename_to_title+0xa9>
movb   $0x0,(%rax)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @filename_to_title(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 i32 @strlen(i8* %7)
%9 = mul nsw i32 %8, 2
%10 = add nsw i32 %9, 1
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
store i8* %12, i8** %5
%13 = load i8*, i8** %2
%14 = call i8* @strrchr(i8* %13, i8 signext 47)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %19, i8** %2
br label %20
20: ; preds = %17, %1
br label %21
21: ; preds = %33, %20
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp sge i32 %24, 48
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i8*, i8** %2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp sle i32 %29, 57
br label %31
31: ; preds = %26, %21
%32 = phi i1 [ false, %21 ], [ %30, %26 ]
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %2
br label %21
36: ; preds = %31
br label %37
37: ; preds = %42, %36
%38 = load i8*, i8** %2
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 32
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %2
br label %37
45: ; preds = %37
br label %46
46: ; preds = %50, %45
%47 = load i8*, i8** %2
%48 = load i8, i8* %47
%49 = icmp ne i8 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %46
%51 = load i8*, i8** %2
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %2
%53 = load i8, i8* %51
store i8 %53, i8* %6
%54 = load i8, i8* %6
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %5
store i8 %54, i8* %55
br label %46
57: ; preds = %46
%58 = load i8*, i8** %5
store i8 0, i8* %58
%59 = load i8*, i8** %3
%60 = call i8* @strrchr(i8* %59, i8 signext 46)
store i8* %60, i8** %4
%61 = load i8*, i8** %4
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %65
63: ; preds = %57
%64 = load i8*, i8** %4
store i8 0, i8* %64
br label %65
65: ; preds = %63, %57
%66 = load i8*, i8** %3
ret i8* %66
}

LLVM IR (-O2):
define i8* @filename_to_title(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = or i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%7 = icmp eq i8* %6, null
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = select i1 %7, i8* %0, i8* %8
br label %10
10: ; preds = %10, %1
%11 = phi i8* [ %9, %1 ], [ %15, %10 ]
%12 = load i8, i8* %11
%13 = add i8 %12, -48
%14 = icmp ult i8 %13, 10
%15 = getelementptr inbounds i8, i8* %11, i64 1
br i1 %14, label %10, label %16
16: ; preds = %10
%17 = icmp eq i8 %12, 32
br i1 %17, label %22, label %18
18: ; preds = %22, %16
%19 = phi i8 [ %12, %16 ], [ %25, %22 ]
%20 = phi i8* [ %11, %16 ], [ %24, %22 ]
%21 = icmp eq i8 %19, 0
br i1 %21, label %35, label %27
22: ; preds = %16, %22
%23 = phi i8* [ %24, %22 ], [ %11, %16 ]
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 32
br i1 %26, label %22, label %18
27: ; preds = %18, %27
%28 = phi i8 [ %33, %27 ], [ %19, %18 ]
%29 = phi i8* [ %31, %27 ], [ %20, %18 ]
%30 = phi i8* [ %32, %27 ], [ %5, %18 ]
%31 = getelementptr inbounds i8, i8* %29, i64 1
%32 = getelementptr inbounds i8, i8* %30, i64 1
store i8 %28, i8* %30
%33 = load i8, i8* %31
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %27
35: ; preds = %27, %18
%36 = phi i8* [ %5, %18 ], [ %32, %27 ]
store i8 0, i8* %36
%37 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 46)
%38 = icmp eq i8* %37, null
br i1 %38, label %40, label %39
39: ; preds = %35
store i8 0, i8* %37
br label %40
40: ; preds = %39, %35
ret i8* %5
}