#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*/ strcmp(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
int guessFileType(char *fn) {
  int fnlen;
  char *suffix;
  int ftype;
  fnlen = strlen(fn);
  suffix = strrchr(fn, '.');
  ftype = 0;
  if (suffix != NULL) {
    if (!strcmp(suffix, ".fq")) {
      ftype = 2;
    } else if (!strcmp(suffix, ".qseq")) {
      ftype = 1;
    } else if (!strcmp(suffix, ".export")) {
      ftype = 3;
    }
  }
  return ftype;
}


x86 assembly (clang, -O0):
<guessFileType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e5 <guessFileType+0xb5>
mov    -0x18(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1191 <guessFileType+0x61>
movl   $0x2,-0x1c(%rbp)
jmp    11e0 <guessFileType+0xb0>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b6 <guessFileType+0x86>
movl   $0x1,-0x1c(%rbp)
jmp    11db <guessFileType+0xab>
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11d6 <guessFileType+0xa6>
movl   $0x3,-0x1c(%rbp)
jmp    11db <guessFileType+0xab>
jmp    11e0 <guessFileType+0xb0>
jmp    11e5 <guessFileType+0xb5>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guessFileType>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     118f <guessFileType+0x5f>
mov    %rax,%rbx
lea    0xeab(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1193 <guessFileType+0x63>
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     119a <guessFileType+0x6a>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,2),%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c".fq\00"
@.str.1 = [6 x i8] c".qseq\00"
@.str.2 = [8 x i8] c".export\00"
define i32 @guessFileType(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i8*, i8** %2
%9 = call i8* @strrchr(i8* %8, i8 signext 46)
store i8* %9, i8** %4
store i32 0, i32* %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %30
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %12
store i32 2, i32* %5
br label %29
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17
store i32 1, i32* %5
br label %28
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
store i32 3, i32* %5
br label %27
27: ; preds = %26, %22
br label %28
28: ; preds = %27, %21
br label %29
29: ; preds = %28, %16
br label %30
30: ; preds = %29, %1
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@.str = [4 x i8] c".fq\00"
@.str.1 = [6 x i8] c".qseq\00"
@.str.2 = [8 x i8] c".export\00"
define i32 @guessFileType(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = tail call i32 @strcmp(i8* %3, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = tail call i32 @strcmp(i8* %3, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32 @strcmp(i8* %3, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 3, i32 0
br label %15
15: ; preds = %11, %8, %5, %1
%16 = phi i32 [ 0, %1 ], [ 2, %5 ], [ 1, %8 ], [ %14, %11 ]
ret i32 %16
}