#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 */
char *malloc(size_t);
size_t strlen(char *);
char *strncpy(char *, char *, size_t);
char *getFileExtension(char *filePath) {
  size_t len = strlen(filePath);
  size_t index = len;
  for (size_t i = 0; i < len; ++i) {
    if (*(filePath + i) == '.') {
      index = i + 1;
      break;
    }
  }
  char *ret = malloc((len - index) + 1);
  return strncpy(ret, filePath + index, len - index);
}


x86 assembly (clang, -O0):
<getFileExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a3 <getFileExtension+0x73>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    118d <getFileExtension+0x5d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <getFileExtension+0x73>
jmp    1192 <getFileExtension+0x62>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <getFileExtension+0x29>
mov    -0x10(%rbp),%rdi
sub    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
sub    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileExtension>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%r14
test   %rax,%rax
je     116f <getFileExtension+0x3f>
mov    %r14,%rax
neg    %rax
mov    $0x1,%ebx
cmpb   $0x2e,-0x1(%r15,%rbx,1)
je     1171 <getFileExtension+0x41>
lea    (%rax,%rbx,1),%rcx
add    $0x1,%rcx
add    $0x1,%rbx
cmp    $0x1,%rcx
jne    1150 <getFileExtension+0x20>
mov    %r14,%rbx
jmp    1171 <getFileExtension+0x41>
xor    %ebx,%ebx
sub    %rbx,%r14
lea    0x1(%r14),%rdi
call   1050 <malloc@plt>
add    %rbx,%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strncpy@plt>

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

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