#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 strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *strrchr(char *, char);
int guessFileType(char *fn, int compressed) {
  int fnlen;
  char *suffix;
  int ftype;
  fnlen = strlen(fn);
  if (compressed) {
    fn[fnlen - 3] = '\0';
  }
  suffix = strrchr(fn, '.');
  if (suffix != NULL) {
    if (!strncmp(suffix, ".bed", 4)) {
      ftype = 1;
    } else if (!strncmp(suffix, ".gff", 4)) {
      ftype = 2;
    } else if (!strncmp(suffix, ".map", 4)) {
      ftype = 3;
    } else if (!strncmp(suffix, ".bow", 4)) {
      ftype = 4;
    } else {
      ftype = 0;
    }
  } else {
    ftype = 0;
  }
  if (compressed) {
    fn[fnlen - 3] = '.';
  }
  return ftype;
}


x86 assembly (clang, -O0):
<guessFileType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1166 <guessFileType+0x36>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1246 <guessFileType+0x116>
mov    -0x18(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ad <guessFileType+0x7d>
movl   $0x1,-0x1c(%rbp)
jmp    1241 <guessFileType+0x111>
mov    -0x18(%rbp),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11d7 <guessFileType+0xa7>
movl   $0x2,-0x1c(%rbp)
jmp    123c <guessFileType+0x10c>
mov    -0x18(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1201 <guessFileType+0xd1>
movl   $0x3,-0x1c(%rbp)
jmp    1237 <guessFileType+0x107>
mov    -0x18(%rbp),%rdi
lea    0xe03(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    122b <guessFileType+0xfb>
movl   $0x4,-0x1c(%rbp)
jmp    1232 <guessFileType+0x102>
movl   $0x0,-0x1c(%rbp)
jmp    1237 <guessFileType+0x107>
jmp    123c <guessFileType+0x10c>
jmp    1241 <guessFileType+0x111>
jmp    124d <guessFileType+0x11d>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1268 <guessFileType+0x138>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guessFileType>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <strlen@plt>
movslq %eax,%r15
test   %r14d,%r14d
je     1150 <guessFileType+0x20>
movb   $0x0,-0x3(%r15,%rbx,1)
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11d4 <guessFileType+0xa4>
mov    %rax,%rbp
lea    0xe94(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11dd <guessFileType+0xad>
lea    0xe81(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11e9 <guessFileType+0xb9>
lea    0xe6e(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1204 <guessFileType+0xd4>
lea    0xe5b(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
shl    $0x2,%eax
test   %r14d,%r14d
jne    11f3 <guessFileType+0xc3>
jmp    11f9 <guessFileType+0xc9>
xor    %eax,%eax
test   %r14d,%r14d
jne    11f3 <guessFileType+0xc3>
jmp    11f9 <guessFileType+0xc9>
mov    $0x1,%eax
test   %r14d,%r14d
jne    11f3 <guessFileType+0xc3>
jmp    11f9 <guessFileType+0xc9>
mov    $0x2,%eax
test   %r14d,%r14d
je     11f9 <guessFileType+0xc9>
movb   $0x2e,-0x3(%r15,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x3,%eax
test   %r14d,%r14d
jne    11f3 <guessFileType+0xc3>
jmp    11f9 <guessFileType+0xc9>

LLVM IR (-O0):
@.str = [5 x i8] c".bed\00"
@.str.1 = [5 x i8] c".gff\00"
@.str.2 = [5 x i8] c".map\00"
@.str.3 = [5 x i8] c".bow\00"
define i32 @guessFileType(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %12, %2
%19 = load i8*, i8** %3
%20 = call i8* @strrchr(i8* %19, i8 signext 46)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %48
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = call i32 @strncmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23
store i32 1, i32* %7
br label %47
28: ; preds = %23
%29 = load i8*, i8** %6
%30 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
store i32 2, i32* %7
br label %46
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = call i32 @strncmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
store i32 3, i32* %7
br label %45
38: ; preds = %33
%39 = load i8*, i8** %6
%40 = call i32 @strncmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %38
store i32 4, i32* %7
br label %44
43: ; preds = %38
store i32 0, i32* %7
br label %44
44: ; preds = %43, %42
br label %45
45: ; preds = %44, %37
br label %46
46: ; preds = %45, %32
br label %47
47: ; preds = %46, %27
br label %49
48: ; preds = %18
store i32 0, i32* %7
br label %49
49: ; preds = %48, %47
%50 = load i32, i32* %4
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i8*, i8** %3
%54 = load i32, i32* %5
%55 = sub nsw i32 %54, 3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 46, i8* %57
br label %58
58: ; preds = %52, %49
%59 = load i32, i32* %7
ret i32 %59
}

LLVM IR (-O2):
@.str = [5 x i8] c".bed\00"
@.str.1 = [5 x i8] c".gff\00"
@.str.2 = [5 x i8] c".map\00"
@.str.3 = [5 x i8] c".bow\00"
define i32 @guessFileType(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %1, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = add nsw i32 %3, -3
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %8
br label %9
9: ; preds = %5, %2
%10 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%11 = icmp eq i8* %10, null
br i1 %11, label %25, label %12
12: ; preds = %9
%13 = tail call i32 @strncmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = icmp eq i32 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = tail call i32 @strncmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = tail call i32 @strncmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i32 @strncmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i32 4, i32 0
br label %25
25: ; preds = %9, %21, %18, %15, %12
%26 = phi i32 [ 1, %12 ], [ 2, %15 ], [ 3, %18 ], [ %24, %21 ], [ 0, %9 ]
br i1 %4, label %31, label %27
27: ; preds = %25
%28 = add nsw i32 %3, -3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 46, i8* %30
br label %31
31: ; preds = %27, %25
ret i32 %26
}