#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 */
typedef int uint32_t;

/* Variables and functions */
size_t strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
uint32_t getFileType(const char *filename) {
  const char *ext = filename;
  size_t length = strlen(filename);
  while (ext < (ext + length) && *ext++ != '.')
    ;
  if (strncmp(ext, "gim", 3) == 0)
    return 0x01;
  if (strncmp(ext, "smd", 3) == 0)
    return 0x03;
  else
    return 0x06;
}


x86 assembly (clang, -O0):
<getFileType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x18(%rbp),%rdx
add    -0x20(%rbp),%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x21(%rbp)
jae    1176 <getFileType+0x56>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1186 <getFileType+0x66>
jmp    118b <getFileType+0x6b>
jmp    1141 <getFileType+0x21>
mov    -0x18(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b6 <getFileType+0x96>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <getFileType+0xc8>
mov    -0x18(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e1 <getFileType+0xc1>
movl   $0x3,-0x4(%rbp)
jmp    11e8 <getFileType+0xc8>
movl   $0x6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileType>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %r14,%rcx
nop
test   %rax,%rax
jle    1143 <getFileType+0x23>
lea    0x1(%rcx),%rbx
cmpb   $0x2e,(%rcx)
mov    %rbx,%rcx
jne    1130 <getFileType+0x10>
jmp    1146 <getFileType+0x26>
mov    %r14,%rbx
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1183 <getFileType+0x63>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,2),%eax
add    $0x3,%eax
jmp    1188 <getFileType+0x68>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"gim\00"
@.str.1 = [4 x i8] c"smd\00"
define i32 @getFileType(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %5
br label %9
9: ; preds = %23, %1
%10 = load i8*, i8** %4
%11 = load i8*, i8** %4
%12 = load i64, i64* %5
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = icmp ult i8* %10, %13
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
%18 = load i8, i8* %16
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 46
br label %21
21: ; preds = %15, %9
%22 = phi i1 [ false, %9 ], [ %20, %15 ]
br i1 %22, label %23, label %24
23: ; preds = %21
br label %9
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 1, i32* %2
br label %35
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = call i64 @strncmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 3, i32* %2
br label %35
34: ; preds = %29
store i32 6, i32* %2
br label %35
35: ; preds = %34, %33, %28
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [4 x i8] c"gim\00"
@.str.1 = [4 x i8] c"smd\00"
define i32 @getFileType(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp sgt i64 %2, 0
br label %4
4: ; preds = %6, %1
%5 = phi i8* [ %0, %1 ], [ %7, %6 ]
br i1 %3, label %6, label %10
6: ; preds = %4
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 46
br i1 %9, label %10, label %4
10: ; preds = %4, %6
%11 = phi i8* [ %7, %6 ], [ %0, %4 ]
%12 = tail call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = tail call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i32 3, i32 6
br label %18
18: ; preds = %14, %10
%19 = phi i32 [ 1, %10 ], [ %17, %14 ]
ret i32 %19
}