#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 *calloc(int, int /*<<< orphan*/);
char *strrchr(char *, char);
char *get_fileext(char *file) {
  int i;
  char *ext = calloc(sizeof(char) * 16, 0);
  char *v = strrchr(file, '.');
  if (v) {
    v++;
    for (i = 0; i < 16; i++) {
      ext[i] = v[i];
    }
  }
  return ext;
}


x86 assembly (clang, -O0):
<get_fileext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x10,%edi
xor    %esi,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119f <get_fileext+0x7f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    119a <get_fileext+0x7a>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116c <get_fileext+0x4c>
jmp    119f <get_fileext+0x7f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fileext>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x10,%edi
xor    %esi,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     114f <get_fileext+0x2f>
movups 0x1(%rax),%xmm0
movups %xmm0,(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define noalias i8* @get_fileext(i8* %0) {
%2 = tail call i8* @calloc(i32 16, i32 0)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %3, i64 1
br label %7
7: ; preds = %5, %1
ret i8* %2
}