#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 */
scalar_t__ strcasecmp(char *, char const *);
char *strchr(char const *, char const);
const char *lookup(const char *path) {
  int index = -1;
  const char *extensions[] = {".css", ".html", ".gif", ".ico",
                              ".jpg", ".js",   ".php", ".png"};
  const char *types[] = {"text/css",     "text/html",  "image/gif",
                         "image/x-icon", "image/jpeg", "text/javascript",
                         "text/x-php",   "image/png"};
  const char dot = '.';
  char *absolute_path;
  absolute_path = strchr(path, dot);
  for (int i = 0; i < 8; i++) {
    if (strcasecmp(absolute_path, extensions[i]) == 0) {
      index = i;
    }
  }
  if (index == -1) {
    return NULL;
  } else {
    return types[index];
  }
}


x86 assembly (clang, -O0):
<lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2c4f(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    0x2c77(%rip),%rsi
mov    $0x40,%edx
call   1050 <memcpy@plt>
movb   $0x2e,-0xa1(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0xb0(%rbp)
movl   $0x0,-0xb4(%rbp)
cmpl   $0x8,-0xb4(%rbp)
jge    11ea <lookup+0xba>
mov    -0xb0(%rbp),%rdi
movslq -0xb4(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11d1 <lookup+0xa1>
mov    -0xb4(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11d6 <lookup+0xa6>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1199 <lookup+0x69>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1201 <lookup+0xd1>
movq   $0x0,-0x8(%rbp)
jmp    1211 <lookup+0xe1>
movslq -0x14(%rbp),%rax
mov    -0xa0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,%r15
lea    0xec5(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcasecmp@plt>
neg    %rax
sbb    %r14d,%r14d
lea    0xeb5(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
mov    $0x1,%ebp
cmovne %r14d,%ebp
lea    0xea0(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
mov    $0x2,%ebx
cmovne %ebp,%ebx
lea    0xe8b(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
mov    $0x3,%ebp
cmovne %ebx,%ebp
lea    0xe76(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
mov    $0x4,%ebx
cmovne %ebp,%ebx
lea    0xe61(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
mov    $0x5,%ebp
cmovne %ebx,%ebp
lea    0xe4b(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
mov    $0x6,%ebx
cmovne %ebp,%ebx
lea    0xe36(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
mov    $0x7,%eax
cmovne %ebx,%eax
cmp    $0xffffffff,%eax
je     1217 <lookup+0xf7>
mov    %eax,%eax
lea    0xe76(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    1219 <lookup+0xf9>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".css\00"
@.str.1 = [6 x i8] c".html\00"
@.str.2 = [5 x i8] c".gif\00"
@.str.3 = [5 x i8] c".ico\00"
@.str.4 = [5 x i8] c".jpg\00"
@.str.5 = [4 x i8] c".js\00"
@.str.6 = [5 x i8] c".php\00"
@.str.7 = [5 x i8] c".png\00"
@__const.lookup.extensions = [8 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0)]
@.str.8 = [9 x i8] c"text/css\00"
@.str.9 = [10 x i8] c"text/html\00"
@.str.10 = [10 x i8] c"image/gif\00"
@.str.11 = [13 x i8] c"image/x-icon\00"
@.str.12 = [11 x i8] c"image/jpeg\00"
@.str.13 = [16 x i8] c"text/javascript\00"
@.str.14 = [11 x i8] c"text/x-php\00"
@.str.15 = [10 x i8] c"image/png\00"
@__const.lookup.types = [8 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.15, i32 0, i32 0)]
define i8* @lookup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [8 x i8*]
%6 = alloca [8 x i8*]
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %4
%10 = bitcast [8 x i8*]* %5 to i8*
%11 = bitcast [8 x i8*]* %6 to i8*
store i8 46, i8* %7
%12 = load i8*, i8** %3
%13 = call i8* @strchr(i8* %12, i8 signext 46)
store i8* %13, i8** %8
store i32 0, i32* %9
br label %14
14: ; preds = %28, %1
%15 = load i32, i32* %9
%16 = icmp slt i32 %15, 8
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i8*, i8** %8
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [8 x i8*], [8 x i8*]* %5, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = call i64 @strcasecmp(i8* %18, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = load i32, i32* %9
store i32 %26, i32* %4
br label %27
27: ; preds = %25, %17
br label %28
28: ; preds = %27
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %14
31: ; preds = %14
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %35
34: ; preds = %31
store i8* null, i8** %2
br label %40
35: ; preds = %31
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [8 x i8*], [8 x i8*]* %6, i64 0, i64 %37
%39 = load i8*, i8** %38
store i8* %39, i8** %2
br label %40
40: ; preds = %35, %34
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [5 x i8] c".css\00"
@.str.1 = [6 x i8] c".html\00"
@.str.2 = [5 x i8] c".gif\00"
@.str.3 = [5 x i8] c".ico\00"
@.str.4 = [5 x i8] c".jpg\00"
@.str.5 = [4 x i8] c".js\00"
@.str.6 = [5 x i8] c".php\00"
@.str.7 = [5 x i8] c".png\00"
@.str.8 = [9 x i8] c"text/css\00"
@.str.9 = [10 x i8] c"text/html\00"
@.str.10 = [10 x i8] c"image/gif\00"
@.str.11 = [13 x i8] c"image/x-icon\00"
@.str.12 = [11 x i8] c"image/jpeg\00"
@.str.13 = [16 x i8] c"text/javascript\00"
@.str.14 = [11 x i8] c"text/x-php\00"
@.str.15 = [10 x i8] c"image/png\00"
@reltable.lookup = [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.8 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.9 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.10 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.11 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.12 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.13 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.14 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.15 to i64), i64 ptrtoint ([8 x i32]* @reltable.lookup to i64)) to i32)]
define i8* @lookup(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i64 %3, 0
%5 = sext i1 %4 to i32
%6 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32 1, i32 %5
%9 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i32 2, i32 %8
%12 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i32 3, i32 %11
%15 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i32 4, i32 %14
%18 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 5, i32 %17
%21 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i32 6, i32 %20
%24 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
%26 = select i1 %25, i32 7, i32 %23
%27 = icmp eq i32 %26, -1
br i1 %27, label %32, label %28
28: ; preds = %1
%29 = zext i32 %26 to i64
%30 = shl i64 %29, 2
%31 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.lookup to i8*), i64 %30)
br label %32
32: ; preds = %1, %28
%33 = phi i8* [ %31, %28 ], [ null, %1 ]
ret i8* %33
}