#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(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
char *strdup(char *);
int strlen(char const *);
char *extension(const char *path) {
  int len = strlen(path);
  int i;
  char *ext;
  for (i = len - 1; i >= 0; i--) {
    if (path[i] == '.') {
      break;
    }
  }
  if (i < 0) {
    ext = strdup("");
  } else {
    ext = malloc(sizeof(char) * (len - i));
    sprintf(ext, "%s", path + i + 1);
  }
  return ext;
}


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    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1198 <extension+0x58>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1185 <extension+0x45>
jmp    1198 <extension+0x58>
jmp    118a <extension+0x4a>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1161 <extension+0x21>
cmpl   $0x0,-0x10(%rbp)
jge    11b7 <extension+0x77>
lea    0xe59(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    11ed <extension+0xad>
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x10(%rbp),%rax
add    %rax,%rdx
add    $0x1,%rdx
lea    0xe18(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extension>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%eax
xor    %edi,%edi
test   %eax,%eax
jle    1184 <extension+0x44>
add    $0x1,%edi
lea    -0x1(%rax),%rbx
cmpb   $0x2e,-0x1(%r14,%rax,1)
mov    %rbx,%rax
jne    1150 <extension+0x10>
call   1050 <malloc@plt>
mov    %ebx,%ecx
lea    (%r14,%rcx,1),%rsi
add    $0x1,%rsi
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>
lea    0xe75(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <strdup@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%s\00"
define i8* @extension(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %4
br label %10
10: ; preds = %23, %1
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, 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 %22
21: ; preds = %13
br label %26
22: ; preds = %13
br label %23
23: ; preds = %22
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
br label %10
26: ; preds = %21, %10
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %30, i8** %5
br label %46
31: ; preds = %26
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = sub nsw i32 %32, %33
%35 = sext i32 %34 to i64
%36 = mul i64 1, %35
%37 = trunc i64 %36 to i32
%38 = call i8* @malloc(i32 %37)
store i8* %38, i8** %5
%39 = load i8*, i8** %5
%40 = load i8*, i8** %2
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %31, %29
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @extension(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
br label %4
4: ; preds = %9, %1
%5 = phi i64 [ %6, %9 ], [ %3, %1 ]
%6 = add nsw i64 %5, -1
%7 = trunc i64 %5 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 46
br i1 %12, label %15, label %4
13: ; preds = %4
%14 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %23
15: ; preds = %9
%16 = trunc i64 %6 to i32
%17 = sub nsw i32 %2, %16
%18 = tail call i8* @malloc(i32 %17)
%19 = and i64 %6, 4294967295
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = tail call i8* @strcpy(i8* dereferenceable(1) %18, i8* %21)
br label %23
23: ; preds = %15, %13
%24 = phi i8* [ %14, %13 ], [ %18, %15 ]
ret i8* %24
}