#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 *extension(const char *file_name) {
  size_t len = strlen(file_name);
  const char *chptr = file_name + len - 1;
  while (chptr != file_name && *chptr != '.') {
    chptr--;
  }
  if (*chptr == '.') {
    chptr++;
  }
  return chptr;
}


x86 assembly (clang, -O0):
<extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
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    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
je     115c <extension+0x4c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116c <extension+0x5c>
jmp    117d <extension+0x6d>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1139 <extension+0x29>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1199 <extension+0x89>
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):
<extension>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
nopl   0x0(%rax)
cmp    $0x1,%rax
je     113e <extension+0x2e>
lea    -0x1(%rax),%rcx
cmpb   $0x2e,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1120 <extension+0x10>
lea    (%rbx,%rcx,1),%rax
add    $0x1,%rax
pop    %rbx
ret
xor    %eax,%eax
cmpb   $0x2e,(%rbx)
sete   %al
add    %rbx,%rax
pop    %rbx
ret

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

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