#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_extension(const char *name, size_t len) {
  const char *ext;
  if (!len)
    len = strlen(name);
  ext = name + len - 1;
  while ((name <= ext) && ('.' != *ext)) {
    ext--;
  }
  if (name == ext)
    ext = NULL;
  else
    ext++;
  return ext;
}


x86 assembly (clang, -O0):
<file_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1138 <file_extension+0x28>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x19(%rbp)
ja     116f <file_extension+0x5f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x2e,%eax
cmp    %ecx,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    117f <file_extension+0x6f>
jmp    1190 <file_extension+0x80>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1148 <file_extension+0x38>
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    11ab <file_extension+0x9b>
movq   $0x0,-0x18(%rbp)
jmp    11b7 <file_extension+0xa7>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_extension>:
push   %rbx
mov    %rdi,%rbx
test   %rsi,%rsi
jne    1124 <file_extension+0x14>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rsi
lea    (%rbx,%rsi,1),%rdx
add    $0xffffffffffffffff,%rdx
add    $0xffffffffffffffff,%rsi
mov    %rdx,%rax
mov    %rsi,%rcx
cmp    %rbx,%rdx
jb     1148 <file_extension+0x38>
lea    -0x1(%rax),%rdx
lea    -0x1(%rcx),%rsi
cmpb   $0x2e,(%rax)
jne    1130 <file_extension+0x20>
add    $0x1,%rax
test   %rcx,%rcx
cmove  %rcx,%rax
pop    %rbx
ret

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

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