int filetype(filename)
char *filename;
{
  int type;
  register int len;
  register char *suffix;
  if (!filename)
    type = -1;
  else {
    len = strlen(filename);
    suffix = filename + len - 1;
    while (*suffix != '.' && suffix != filename)
      suffix--;
    if (suffix == filename) {
      if (*filename == 'M' || *filename == 'm') {
        if (strncmp(filename + 1, "akefile", 7) == 0)
          type = 11;
        else
          type = 0;
      }
    } else {
      if (strlen(++suffix) == 1) {
        switch (*suffix) {
        case 'c':
          type = 1;
          break;
        case 'h':
          type = 5;
          break;
        case 'y':
          type = 6;
          break;
        case 'p':
          type = 2;
          break;
        case 's':
          type = 7;
          break;
        case 'm':
          type = 9;
          break;
        default:
          type = 0;
          break;
        }
      } else {
        if (strcmp(suffix, "sh") == 0)
          type = 3;
        else if (strcmp(suffix, "cob") == 0)
          type = 10;
        else if (strcmp(suffix, "awk") == 0)
          type = 8;
        else
          type = 0;
      }
    }
  }
  return type;
}


x86 assembly (clang, -O0):
<filetype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1153 <filetype+0x23>
movl   $0xffffffff,-0xc(%rbp)
jmp    134e <filetype+0x21e>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x19(%rbp)
je     1195 <filetype+0x65>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a5 <filetype+0x75>
jmp    11b6 <filetype+0x86>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1172 <filetype+0x42>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1223 <filetype+0xf3>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4d,%eax
je     11e4 <filetype+0xb4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
jne    121e <filetype+0xee>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xe69(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1212 <filetype+0xe2>
movl   $0xb,-0xc(%rbp)
jmp    1219 <filetype+0xe9>
movl   $0x0,-0xc(%rbp)
jmp    121e <filetype+0xee>
jmp    1349 <filetype+0x219>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x18(%rbp)
call   1040 <strlen@plt>
cmp    $0x1,%rax
jne    12bf <filetype+0x18f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x16,%eax
ja     12b3 <filetype+0x183>
mov    -0x28(%rbp),%rax
lea    0xd9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0xc(%rbp)
jmp    12ba <filetype+0x18a>
movl   $0x5,-0xc(%rbp)
jmp    12ba <filetype+0x18a>
movl   $0x6,-0xc(%rbp)
jmp    12ba <filetype+0x18a>
movl   $0x2,-0xc(%rbp)
jmp    12ba <filetype+0x18a>
movl   $0x7,-0xc(%rbp)
jmp    12ba <filetype+0x18a>
movl   $0x9,-0xc(%rbp)
jmp    12ba <filetype+0x18a>
movl   $0x0,-0xc(%rbp)
jmp    1344 <filetype+0x214>
mov    -0x18(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12e4 <filetype+0x1b4>
movl   $0x3,-0xc(%rbp)
jmp    133f <filetype+0x20f>
mov    -0x18(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1309 <filetype+0x1d9>
movl   $0xa,-0xc(%rbp)
jmp    133a <filetype+0x20a>
mov    -0x18(%rbp),%rdi
lea    0xd57(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    132e <filetype+0x1fe>
movl   $0x8,-0xc(%rbp)
jmp    1335 <filetype+0x205>
movl   $0x0,-0xc(%rbp)
jmp    133a <filetype+0x20a>
jmp    133f <filetype+0x20f>
jmp    1344 <filetype+0x214>
jmp    1349 <filetype+0x219>
jmp    134e <filetype+0x21e>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filetype>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a8 <filetype+0x78>
mov    %rdi,%r14
call   1040 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rbx
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x2e,-0x2(%rbx)
lea    -0x1(%rbx),%rbx
lea    -0x1(%rax),%rcx
je     1167 <filetype+0x37>
cmp    $0x1,%rax
mov    %rcx,%rax
jne    1150 <filetype+0x20>
test   %rcx,%rcx
je     11b2 <filetype+0x82>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x1,%rax
jne    11e1 <filetype+0xb1>
movsbl (%rbx),%ecx
add    $0xffffff9d,%ecx
cmp    $0x16,%ecx
ja     1234 <filetype+0x104>
mov    $0x1,%eax
lea    0xe6b(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x5,%eax
jmp    1252 <filetype+0x122>
mov    $0xffffffff,%eax
jmp    1252 <filetype+0x122>
mov    (%r14),%al
or     $0x20,%al
cmp    $0x6d,%al
jne    1224 <filetype+0xf4>
add    $0x1,%r14
lea    0xe96(%rip),%rsi
mov    $0x7,%edx
mov    %r14,%rdi
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
mov    $0xb,%eax
cmovne %ecx,%eax
jmp    1252 <filetype+0x122>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1226 <filetype+0xf6>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     122d <filetype+0xfd>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
shl    $0x3,%eax
jmp    1252 <filetype+0x122>
jmp    1252 <filetype+0x122>
mov    $0x3,%eax
jmp    1252 <filetype+0x122>
mov    $0xa,%eax
jmp    1252 <filetype+0x122>
xor    %eax,%eax
jmp    1252 <filetype+0x122>
mov    $0x9,%eax
jmp    1252 <filetype+0x122>
mov    $0x2,%eax
jmp    1252 <filetype+0x122>
mov    $0x7,%eax
jmp    1252 <filetype+0x122>
mov    $0x6,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"akefile\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [4 x i8] c"cob\00"
@.str.3 = [4 x i8] c"awk\00"
define i32 @filetype(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 -1, i32* %3
br label %93
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
store i32 %12, i32* %4
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -1
store i8* %17, i8** %5
br label %18
18: ; preds = %29, %9
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 46
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = load i8*, i8** %2
%26 = icmp ne i8* %24, %25
br label %27
27: ; preds = %23, %18
%28 = phi i1 [ false, %18 ], [ %26, %23 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %5
br label %18
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = load i8*, i8** %2
%35 = icmp eq i8* %33, %34
br i1 %35, label %36, label %55
36: ; preds = %32
%37 = load i8*, i8** %2
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 77
br i1 %40, label %46, label %41
41: ; preds = %36
%42 = load i8*, i8** %2
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 109
br i1 %45, label %46, label %54
46: ; preds = %41, %36
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = call i32 @strncmp(i8* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %46
store i32 11, i32* %3
br label %53
52: ; preds = %46
store i32 0, i32* %3
br label %53
53: ; preds = %52, %51
br label %54
54: ; preds = %53, %41
br label %92
55: ; preds = %32
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %5
%58 = call i64 @strlen(i8* %57)
%59 = icmp eq i64 %58, 1
br i1 %59, label %60, label %72
60: ; preds = %55
%61 = load i8*, i8** %5
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
switch i32 %63, label %70 [
i32 99, label %64
i32 104, label %65
i32 121, label %66
i32 112, label %67
i32 115, label %68
i32 109, label %69
]
64: ; preds = %60
store i32 1, i32* %3
br label %71
65: ; preds = %60
store i32 5, i32* %3
br label %71
66: ; preds = %60
store i32 6, i32* %3
br label %71
67: ; preds = %60
store i32 2, i32* %3
br label %71
68: ; preds = %60
store i32 7, i32* %3
br label %71
69: ; preds = %60
store i32 9, i32* %3
br label %71
70: ; preds = %60
store i32 0, i32* %3
br label %71
71: ; preds = %70, %69, %68, %67, %66, %65, %64
br label %91
72: ; preds = %55
%73 = load i8*, i8** %5
%74 = call i32 @strcmp(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %72
store i32 3, i32* %3
br label %90
77: ; preds = %72
%78 = load i8*, i8** %5
%79 = call i32 @strcmp(i8* %78, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %77
store i32 10, i32* %3
br label %89
82: ; preds = %77
%83 = load i8*, i8** %5
%84 = call i32 @strcmp(i8* %83, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %87
86: ; preds = %82
store i32 8, i32* %3
br label %88
87: ; preds = %82
store i32 0, i32* %3
br label %88
88: ; preds = %87, %86
br label %89
89: ; preds = %88, %81
br label %90
90: ; preds = %89, %76
br label %91
91: ; preds = %90, %71
br label %92
92: ; preds = %91, %54
br label %93
93: ; preds = %92, %8
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [8 x i8] c"akefile\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [4 x i8] c"cob\00"
@.str.3 = [4 x i8] c"awk\00"
define i32 @filetype(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %46, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = shl i64 %4, 32
%6 = ashr exact i64 %5, 32
%7 = getelementptr inbounds i8, i8* %0, i64 %6
br label %8
8: ; preds = %8, %3
%9 = phi i8* [ %7, %3 ], [ %10, %8 ]
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 46
%13 = icmp ne i8* %10, %0
%14 = and i1 %12, %13
br i1 %14, label %8, label %15
15: ; preds = %8
%16 = icmp eq i8* %10, %0
br i1 %16, label %17, label %24
17: ; preds = %15
%18 = load i8, i8* %0
switch i8 %18, label %46 [
i8 77, label %19
i8 109, label %19
]
19: ; preds = %17, %17
%20 = getelementptr inbounds i8, i8* %0, i64 1
%21 = tail call i32 @strncmp(i8* %20, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7)
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i32 11, i32 0
br label %46
24: ; preds = %15
%25 = tail call i64 @strlen(i8* %9)
%26 = icmp eq i64 %25, 1
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i8, i8* %9
%29 = sext i8 %28 to i32
switch i32 %29, label %35 [
i32 99, label %46
i32 104, label %30
i32 121, label %31
i32 112, label %32
i32 115, label %33
i32 109, label %34
]
30: ; preds = %27
br label %46
31: ; preds = %27
br label %46
32: ; preds = %27
br label %46
33: ; preds = %27
br label %46
34: ; preds = %27
br label %46
35: ; preds = %27
br label %46
36: ; preds = %24
%37 = tail call i32 @strcmp(i8* %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i32 %37, 0
br i1 %38, label %46, label %39
39: ; preds = %36
%40 = tail call i32 @strcmp(i8* %9, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = tail call i32 @strcmp(i8* %9, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 8, i32 0
br label %46
46: ; preds = %42, %39, %36, %27, %19, %17, %1, %30, %31, %32, %33, %34, %35
%47 = phi i32 [ 0, %35 ], [ 9, %34 ], [ 7, %33 ], [ 2, %32 ], [ 6, %31 ], [ 5, %30 ], [ -1, %1 ], [ undef, %17 ], [ %23, %19 ], [ 1, %27 ], [ 3, %36 ], [ 10, %39 ], [ %45, %42 ]
ret i32 %47
}