#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 */
size_t strlen(char const *);
char *strrchr(char const *, char);
const char *get_extension(const char *fqpn) {
  const char *begin = fqpn;
  const char *slash = strrchr(fqpn, '/');
  if (slash)
    begin = slash + 1;
  const char *dot = strrchr(begin, '.');
  if (!dot || dot == begin)
    return &fqpn[strlen(fqpn)];
  else
    return dot;
}


x86 assembly (clang, -O0):
<get_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     115d <get_extension+0x3d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1188 <get_extension+0x68>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11ac <get_extension+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11b4 <get_extension+0x94>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_extension>:
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
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1153 <get_extension+0x33>
cmp    %rbx,%rax
jne    115e <get_extension+0x3e>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @get_extension(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
store i8* %7, i8** %4
%8 = load i8*, i8** %3
%9 = call i8* @strrchr(i8* %8, i8 signext 47)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8* %14, i8** %4
br label %15
15: ; preds = %12, %1
%16 = load i8*, i8** %4
%17 = call i8* @strrchr(i8* %16, i8 signext 46)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = icmp eq i8* %21, %22
br i1 %23, label %24, label %29
24: ; preds = %20, %15
%25 = load i8*, i8** %3
%26 = load i8*, i8** %3
%27 = call i64 @strlen(i8* %26)
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8* %28, i8** %2
br label %31
29: ; preds = %20
%30 = load i8*, i8** %6
store i8* %30, i8** %2
br label %31
31: ; preds = %29, %24
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
define i8* @get_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 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 46)
%7 = icmp eq i8* %6, null
%8 = icmp eq i8* %6, %5
%9 = or i1 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = getelementptr inbounds i8, i8* %0, i64 %11
br label %13
13: ; preds = %1, %10
%14 = phi i8* [ %12, %10 ], [ %6, %1 ]
ret i8* %14
}