#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *getext_(char *fname) {
  int i = 0;
  int len = 0;
  char *buff = NULL;
  if (fname == NULL)
    return NULL;
  len = strlen(fname);
  for (i = len; i >= 0; i--) {
    if (fname[i] == '.') {
      buff = (char *)malloc(sizeof(char) * (len - i + 1));
      strncpy(buff, fname + i + 1, len - i + 1);
      return buff;
    }
    if (fname[i] == '/') {
      return NULL;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getext_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116a <getext_+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    1220 <getext_+0xf0>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1218 <getext_+0xe8>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11e3 <getext_+0xb3>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%edx
sub    -0x14(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1220 <getext_+0xf0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1205 <getext_+0xd5>
movq   $0x0,-0x8(%rbp)
jmp    1220 <getext_+0xf0>
jmp    120a <getext_+0xda>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    117c <getext_+0x4c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getext_>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117f <getext_+0x4f>
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %eax,%eax
js     117f <getext_+0x4f>
mov    %eax,%eax
mov    $0x1,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rax,1),%ecx
cmp    $0x2f,%cl
je     1182 <getext_+0x52>
cmp    $0x2e,%cl
je     1190 <getext_+0x60>
lea    -0x1(%rax),%rcx
add    $0x1,%ebp
test   %rax,%rax
mov    %rcx,%rax
jg     1160 <getext_+0x30>
jmp    1182 <getext_+0x52>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    (%rbx,%r15,1),%rsi
add    $0x1,%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
jmp    1182 <getext_+0x52>

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

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