#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 */
unsigned int strlen(char *);
char *get_file_extension(char *filename) {
  int last_period = 0;
  unsigned int index = 0;
  for (; index < strlen(filename); index++) {
    if (*(filename + index) == '.') {
      last_period = index;
    }
  }
  return (filename + last_period);
}


x86 assembly (clang, -O0):
<get_file_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jae    1173 <get_file_extension+0x63>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1160 <get_file_extension+0x50>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <get_file_extension+0x55>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <get_file_extension+0x1a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_extension>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
xor    %r15d,%r15d
test   %eax,%eax
je     114f <get_file_extension+0x3f>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x2e,(%r14,%rbx,1)
cmove  %ebx,%r15d
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1130 <get_file_extension+0x20>
movslq %r15d,%r15
add    %r15,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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