#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 *index(char *, char);
char *rindex(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void get_extension(char *fullfilename, char *filetype) {
  char *r, *s, *v;
  r = rindex(fullfilename, '/');
  if (!r) {
    r = rindex(fullfilename, '.');
    if (!r) {
      *filetype = '\0';
      return;
    } else
      strcpy(filetype, r);
  } else {
    s = index(r, '.');
    if (!s) {
      *filetype = '\0';
      return;
    }
    v = index(s, ';');
    if (v) {
      strncpy(filetype, s, (int)(v - s));
      filetype[(v - s) + 1] = '\0';
    } else
      strcpy(filetype, s);
  }
}


x86 assembly (clang, -O0):
<get_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <rindex@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <get_extension+0x68>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <rindex@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1196 <get_extension+0x56>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1233 <get_extension+0xf3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1233 <get_extension+0xf3>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <index@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d1 <get_extension+0x91>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1233 <get_extension+0xf3>
mov    -0x20(%rbp),%rdi
mov    $0x3b,%esi
call   1050 <index@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1221 <get_extension+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
jmp    122e <get_extension+0xee>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1233 <get_extension+0xf3>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_extension>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1060 <rindex@plt>
test   %rax,%rax
je     119d <get_extension+0x5d>
mov    %rax,%rdi
mov    $0x2e,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11b7 <get_extension+0x77>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x3b,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11c1 <get_extension+0x81>
mov    %rax,%r15
sub    %rbx,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x1(%r15,%r14,1)
jmp    11bb <get_extension+0x7b>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <rindex@plt>
test   %rax,%rax
je     11b7 <get_extension+0x77>
mov    %r14,%rdi
mov    %rax,%rsi
jmp    11c7 <get_extension+0x87>
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

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

LLVM IR (-O2):
define void @get_extension(i8* %0, i8* %1) {
%3 = tail call i8* @rindex(i8* %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i8* @rindex(i8* %0, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %5
store i8 0, i8* %1
br label %28
9: ; preds = %5
%10 = tail call i32 @strcpy(i8* %1, i8* %6)
br label %28
11: ; preds = %2
%12 = tail call i8* @index(i8* %3, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11
store i8 0, i8* %1
br label %28
15: ; preds = %11
%16 = tail call i8* @index(i8* %12, i8 signext 59)
%17 = icmp eq i8* %16, null
br i1 %17, label %26, label %18
18: ; preds = %15
%19 = ptrtoint i8* %16 to i64
%20 = ptrtoint i8* %12 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = tail call i32 @strncpy(i8* %1, i8* %12, i32 %22)
%24 = add nsw i64 %21, 1
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
br label %28
26: ; preds = %15
%27 = tail call i32 @strcpy(i8* %1, i8* %12)
br label %28
28: ; preds = %9, %26, %18, %14, %8
ret void
}