#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 *strrchr(char const *, char);
const char *file_extension(const char *filename) {
  const char *tmp;
  tmp = strrchr(filename, '/');
  if (!tmp)
    tmp = filename;
  else
    tmp++;
  if (*tmp == '.') {
    tmp++;
  }
  tmp = strrchr(tmp, '.');
  if (!tmp)
    return NULL;
  return tmp;
}


x86 assembly (clang, -O0):
<file_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1146 <file_extension+0x36>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1152 <file_extension+0x42>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    116e <file_extension+0x5e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1198 <file_extension+0x88>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <file_extension+0x90>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_extension>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %rbx,%rcx
xor    %edi,%edi
cmpb   $0x2e,(%rcx)
sete   %dil
add    %rcx,%rdi
mov    $0x2e,%esi
pop    %rbx
jmp    1030 <strrchr@plt>

LLVM IR (-O0):
define i8* @file_extension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strrchr(i8* %5, i8 signext 47)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
store i8* %10, i8** %4
br label %14
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
br label %14
14: ; preds = %11, %9
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 46
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
br label %22
22: ; preds = %19, %14
%23 = load i8*, i8** %4
%24 = call i8* @strrchr(i8* %23, i8 signext 46)
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %22
store i8* null, i8** %2
br label %30
28: ; preds = %22
%29 = load i8*, i8** %4
store i8* %29, i8** %2
br label %30
30: ; preds = %28, %27
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
define i8* @file_extension(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, 46
%8 = zext i1 %7 to i64
%9 = getelementptr i8, i8* %5, i64 %8
%10 = tail call i8* @strrchr(i8* %9, i8 signext 46)
ret i8* %10
}