#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 const *);
char *S_FileExtension(const char *fni) {
  char *fn = (char *)fni + strlen(fni) - 1;
  char *eptr = ((void *)0);
  while (*fn != '/' && fn != fni) {
    if (*fn == '.') {
      eptr = fn;
      break;
    }
    fn--;
  }
  return eptr;
}


x86 assembly (clang, -O0):
<S_FileExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x21(%rbp)
je     116c <S_FileExtension+0x5c>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    117c <S_FileExtension+0x6c>
jmp    11aa <S_FileExtension+0x9a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1199 <S_FileExtension+0x89>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11aa <S_FileExtension+0x9a>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1149 <S_FileExtension+0x39>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<S_FileExtension>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
xor    %eax,%eax
xchg   %ax,%ax
movzbl -0x1(%rbx,%rcx,1),%edx
cmp    $0x2f,%dl
je     113f <S_FileExtension+0x2f>
cmp    $0x1,%rcx
je     113f <S_FileExtension+0x2f>
add    $0xffffffffffffffff,%rcx
cmp    $0x2e,%dl
jne    1120 <S_FileExtension+0x10>
add    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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