#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 *);
const char *file_ext(const char *filename) {
  size_t i = strlen(filename);
  while (i && filename[i - 1] != '/') {
    if (filename[i - 1] == '.')
      return &filename[i];
    --i;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<file_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
je     1152 <file_ext+0x42>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1162 <file_ext+0x52>
jmp    119d <file_ext+0x8d>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    118c <file_ext+0x7c>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <file_ext+0x95>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1129 <file_ext+0x19>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_ext>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
add    %rbx,%rax
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
sub    $0x1,%rcx
jb     114a <file_ext+0x3a>
movzbl -0x2(%rax),%edx
cmp    $0x2f,%dl
je     114a <file_ext+0x3a>
add    $0xffffffffffffffff,%rax
cmp    $0x2e,%dl
jne    1130 <file_ext+0x20>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @file_ext(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br label %3
3: ; preds = %6, %1
%4 = phi i64 [ %2, %1 ], [ %7, %6 ]
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = add i64 %4, -1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
switch i8 %9, label %3 [
i8 47, label %12
i8 46, label %10
]
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %0, i64 %4
br label %12
12: ; preds = %3, %6, %10
%13 = phi i8* [ %11, %10 ], [ null, %6 ], [ null, %3 ]
ret i8* %13
}