#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_filename_extension(char *filename) {
  char *ext = filename + strlen(filename);
  while (*ext != '.' && ext > filename)
    ext--;
  ext += *ext == '.';
  return ext;
}


x86 assembly (clang, -O0):
<get_filename_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x19(%rbp)
je     1160 <get_filename_extension+0x50>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
seta   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1170 <get_filename_extension+0x60>
jmp    1181 <get_filename_extension+0x71>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    113d <get_filename_extension+0x2d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename_extension>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
xchg   %ax,%ax
mov    %rax,%rdx
movzbl (%rax),%ecx
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rdx
jbe    1134 <get_filename_extension+0x24>
cmp    $0x2e,%cl
jne    1120 <get_filename_extension+0x10>
xor    %edx,%edx
cmp    $0x2e,%cl
sete   %dl
add    %rdx,%rax
add    $0x1,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @get_filename_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 ], [ %11, %5 ]
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 46
%9 = icmp ugt i8* %6, %0
%10 = and i1 %9, %8
%11 = getelementptr inbounds i8, i8* %6, i64 -1
br i1 %10, label %5, label %12
12: ; preds = %5
%13 = icmp eq i8 %7, 46
%14 = zext i1 %13 to i64
%15 = getelementptr inbounds i8, i8* %6, i64 %14
ret i8* %15
}