#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 *);
const char *extensionFromFilename(const char *filename) {
  int len = strlen(filename);
  if (len < 3)
    return filename;
  const char *p = filename + (len - 1);
  while (p != filename && *p != '.')
    --p;
  return p;
}


x86 assembly (clang, -O0):
<extensionFromFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    113f <extensionFromFilename+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <extensionFromFilename+0x8f>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
je     1176 <extensionFromFilename+0x66>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1186 <extensionFromFilename+0x76>
jmp    1197 <extensionFromFilename+0x87>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1153 <extensionFromFilename+0x43>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extensionFromFilename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x3,%eax
jl     1141 <extensionFromFilename+0x31>
add    $0xffffffff,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x2e,(%rbx,%rax,1)
je     113e <extensionFromFilename+0x2e>
add    $0xffffffffffffffff,%rax
jne    1130 <extensionFromFilename+0x20>
jmp    1141 <extensionFromFilename+0x31>
add    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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