#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 strlen(char *);
char *get_file_extension(char *name) {
  char *extension = name + strlen(name);
  while (*extension != '.' && *extension != '/' && extension != name) {
    --extension;
  }
  if (*extension == '/' || extension == name) {
    return "";
  } else {
    return extension + 1;
  }
}


x86 assembly (clang, -O0):
<get_file_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x21(%rbp)
je     1175 <get_file_extension+0x65>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x21(%rbp)
je     1175 <get_file_extension+0x65>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1185 <get_file_extension+0x75>
jmp    1196 <get_file_extension+0x86>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    113d <get_file_extension+0x2d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11b4 <get_file_extension+0xa4>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11c4 <get_file_extension+0xb4>
lea    0xe45(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <get_file_extension+0xc0>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_extension>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rsi
lea    (%rsi,%rbx,1),%rax
add    $0x2,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rsi,%rcx
movzbl -0x2(%rax),%ebx
add    $0xffffffffffffffff,%rax
test   %rsi,%rsi
je     114e <get_file_extension+0x3e>
mov    %ebx,%edx
and    $0xfe,%dl
lea    -0x1(%rcx),%rsi
cmp    $0x2e,%dl
jne    1130 <get_file_extension+0x20>
cmp    $0x2f,%bl
lea    0xea8(%rip),%rdx
cmove  %rdx,%rax
test   %rcx,%rcx
cmove  %rdx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @get_file_extension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
store i8* %9, i8** %4
br label %10
10: ; preds = %26, %1
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 46
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 47
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8*, i8** %3
%23 = icmp ne i8* %21, %22
br label %24
24: ; preds = %20, %15, %10
%25 = phi i1 [ false, %15 ], [ false, %10 ], [ %23, %20 ]
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %4
br label %10
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 47
br i1 %33, label %38, label %34
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8*, i8** %3
%37 = icmp eq i8* %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34, %29
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %42
39: ; preds = %34
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8* %41, i8** %2
br label %42
42: ; preds = %39, %38
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @get_file_extension(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
br label %5
5: ; preds = %5, %1
%6 = phi i8* [ %4, %1 ], [ %12, %5 ]
%7 = load i8, i8* %6
%8 = and i8 %7, -2
%9 = icmp eq i8 %8, 46
%10 = icmp eq i8* %6, %0
%11 = or i1 %10, %9
%12 = getelementptr inbounds i8, i8* %6, i64 -1
br i1 %11, label %13, label %5
13: ; preds = %5
%14 = icmp eq i8 %7, 47
%15 = or i1 %10, %14
%16 = getelementptr inbounds i8, i8* %6, i64 1
%17 = select i1 %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %16
ret i8* %17
}