#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 */
int /*<<< orphan*/ strcpy(char *, char const *);
unsigned long strlen(char const *);
void dmfh_get_extension(const char *file_name, char *extension) {
  int i = 0;
  unsigned long length = strlen(file_name);
  if (length > 0) {
    i = (int)length - 1;
    while (i >= 0) {
      if (file_name[i] == '.')
        break;
      i--;
    }
    if (i >= 0) {
      strcpy(extension, file_name + i + 1);
      return;
    } else
      strcpy(extension, "\0");
  }
  strcpy(extension, "\0");
}


x86 assembly (clang, -O0):
<dmfh_get_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    11c7 <dmfh_get_extension+0xa7>
mov    -0x20(%rbp),%rax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     118b <dmfh_get_extension+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    117d <dmfh_get_extension+0x5d>
jmp    118b <dmfh_get_extension+0x6b>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <dmfh_get_extension+0x39>
cmpl   $0x0,-0x14(%rbp)
jl     11b2 <dmfh_get_extension+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
jmp    11d7 <dmfh_get_extension+0xb7>
mov    -0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c7 <dmfh_get_extension+0xa7>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmfh_get_extension>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
test   %rax,%rax
je     116d <dmfh_get_extension+0x4d>
mov    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
test   %eax,%eax
jle    115e <dmfh_get_extension+0x3e>
lea    -0x1(%rax),%rcx
cmpb   $0x2e,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1140 <dmfh_get_extension+0x20>
mov    %ecx,%eax
lea    (%rbx,%rax,1),%rsi
add    $0x1,%rsi
jmp    1174 <dmfh_get_extension+0x54>
lea    0xe9b(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe8c(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] zeroinitializer
define void @dmfh_get_extension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp ugt i64 %9, 0
br i1 %10, label %11, label %45
11: ; preds = %2
%12 = load i64, i64* %6
%13 = trunc i64 %12 to i32
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %5
br label %15
15: ; preds = %27, %11
%16 = load i32, i32* %5
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 46
br i1 %25, label %26, label %27
26: ; preds = %18
br label %30
27: ; preds = %18
%28 = load i32, i32* %5
%29 = add nsw i32 %28, -1
store i32 %29, i32* %5
br label %15
30: ; preds = %26, %15
%31 = load i32, i32* %5
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i8*, i8** %4
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @strcpy(i8* %34, i8* %39)
br label %48
41: ; preds = %30
%42 = load i8*, i8** %4
%43 = call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %41
br label %45
45: ; preds = %44, %2
%46 = load i8*, i8** %4
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %45, %33
ret void
}

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