#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 *filename) {
  int l = strlen(filename);
  while (filename[l] != '.' && l > 0)
    l--;
  return (l == 0 ? NULL : filename + l + 1);
}


x86 assembly (clang, -O0):
<get_file_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0xd(%rbp)
je     114c <get_file_extension+0x3c>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    115c <get_file_extension+0x4c>
jmp    116a <get_file_extension+0x5a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1128 <get_file_extension+0x18>
cmpl   $0x0,-0xc(%rbp)
jne    117f <get_file_extension+0x6f>
xor    %eax,%eax
mov    %rax,-0x18(%rbp)
jmp    1192 <get_file_extension+0x82>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_extension>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
xor    %ecx,%ecx
mov    %rax,%rdx
add    $0x1,%rcx
cmpb   $0x2e,(%rbx,%rdx,1)
je     1136 <get_file_extension+0x26>
lea    -0x1(%rdx),%rsi
test   %rdx,%rdx
mov    %rsi,%rdx
jg     1120 <get_file_extension+0x10>
lea    0x1(%rax),%edx
add    %rax,%rbx
sub    %rcx,%rbx
add    $0x2,%rbx
xor    %eax,%eax
cmp    %ecx,%edx
cmovne %rbx,%rax
pop    %rbx
ret

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

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