#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *getExtension(char *path) {
  int pathLen = strlen(path), i, ind = -1, extLen;
  char *ext = NULL;
  for (i = pathLen - 2; i > 0; i--) {
    if (path[i] == '.') {
      ind = i;
      break;
    }
  }
  if (ind != -1) {
    extLen = pathLen - ind;
    if (extLen > 5) {
      return NULL;
    }
    ext = (char *)malloc(extLen);
    strcpy(ext, &path[ind + 1]);
  }
  return ext;
}


x86 assembly (clang, -O0):
<getExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    119d <getExtension+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    118a <getExtension+0x5a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <getExtension+0x6d>
jmp    118f <getExtension+0x5f>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1160 <getExtension+0x30>
cmpl   $0xffffffff,-0x1c(%rbp)
je     11eb <getExtension+0xbb>
mov    -0x14(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x5,-0x20(%rbp)
jle    11c7 <getExtension+0x97>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <getExtension+0xc3>
mov    -0x20(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getExtension>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1040 <strlen@plt>
cmp    $0x3,%eax
jl     117e <getExtension+0x4e>
mov    %eax,%r15d
lea    -0x1(%r15),%eax
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
cmpb   $0x2e,(%r12,%rax,1)
je     1175 <getExtension+0x45>
add    $0x1,%rbx
cmp    $0x1,%eax
jg     1160 <getExtension+0x30>
jmp    1181 <getExtension+0x51>
lea    0x2(%rbx),%rdi
cmp    $0x5,%edi
jle    1190 <getExtension+0x60>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
call   1050 <malloc@plt>
mov    %rax,%r14
add    $0xffffffff,%r15d
add    %r15,%r12
sub    %rbx,%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
jmp    1181 <getExtension+0x51>

LLVM IR (-O0):
define i8* @getExtension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
store i32 -1, i32* %6
store i8* null, i8** %8
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 2
store i32 %12, i32* %5
br label %13
13: ; preds = %27, %1
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 46
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = load i32, i32* %5
store i32 %25, i32* %6
br label %30
26: ; preds = %16
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
%29 = add nsw i32 %28, -1
store i32 %29, i32* %5
br label %13
30: ; preds = %24, %13
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %51
33: ; preds = %30
%34 = load i32, i32* %4
%35 = load i32, i32* %6
%36 = sub nsw i32 %34, %35
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp sgt i32 %37, 5
br i1 %38, label %39, label %40
39: ; preds = %33
store i8* null, i8** %2
br label %53
40: ; preds = %33
%41 = load i32, i32* %7
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = load i8*, i8** %3
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = call i32 @strcpy(i8* %44, i8* %49)
br label %51
51: ; preds = %40, %30
%52 = load i8*, i8** %8
store i8* %52, i8** %2
br label %53
53: ; preds = %51, %39
%54 = load i8*, i8** %2
ret i8* %54
}

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