#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*/ printf(char *, ...);
scalar_t__ strcasecmp(char *, char *);
char *strrchr(char const *, char const);
const char *lookup(const char *path) {
  const int SIZE = 8;
  const char dot = '.';
  char *getExtension = strrchr(path, dot);
  char *extensions[8] = {".css", ".html", ".gif", ".ico",
                         ".jpg", ".js",   ".php", ".png"};
  char *texts[8] = {"text/css",     "text/html",  "image/gif",
                    "image/x-icon", "image/jpeg", "text/javascript",
                    "text/x-php",   "image/png"};
  printf("This is extension: %s\n", getExtension);
  for (int i = 0; i < SIZE; i++) {
    if (strcasecmp(getExtension, extensions[i]) == 0) {
      printf("Found correct extension\n");
      return texts[i];
    }
  }
  printf("Invalid file type\n");
  return NULL;
}


x86 assembly (clang, -O0):
<lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x8,-0x14(%rbp)
movb   $0x2e,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2c29(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
lea    0x2c51(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rsi
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xa4(%rbp)
cmpl   $0x8,-0xa4(%rbp)
jge    1220 <lookup+0xe0>
mov    -0x20(%rbp),%rdi
movslq -0xa4(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1207 <lookup+0xc7>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0xa4(%rbp),%rax
mov    -0xa0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
jmp    1236 <lookup+0xf6>
jmp    120c <lookup+0xcc>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    11b5 <lookup+0x75>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup>:
push   %r14
push   %rbx
push   %rax
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,%rbx
lea    0xf2a(%rip),%rdi
xor    %r14d,%r14d
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1253 <lookup+0x113>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     121d <lookup+0xdd>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1225 <lookup+0xe5>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     122d <lookup+0xed>
lea    0xe51(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1235 <lookup+0xf5>
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     123d <lookup+0xfd>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1245 <lookup+0x105>
lea    0xe23(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     124d <lookup+0x10d>
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    126d <lookup+0x12d>
mov    $0x1,%r14d
jmp    1253 <lookup+0x113>
mov    $0x2,%r14d
jmp    1253 <lookup+0x113>
mov    $0x3,%r14d
jmp    1253 <lookup+0x113>
mov    $0x4,%r14d
jmp    1253 <lookup+0x113>
mov    $0x5,%r14d
jmp    1253 <lookup+0x113>
mov    $0x6,%r14d
jmp    1253 <lookup+0x113>
mov    $0x7,%r14d
lea    0xe51(%rip),%rdi
call   1040 <puts@plt>
lea    0xe5e(%rip),%rcx
movslq (%rcx,%r14,4),%rax
add    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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.texts = [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)]
@.str.16 = [23 x i8] c"This is extension: %s\0A\00"
@.str.17 = [25 x i8] c"Found correct extension\0A\00"
@.str.18 = [19 x i8] c"Invalid file type\0A\00"
define i8* @lookup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca [8 x i8*]
%8 = alloca [8 x i8*]
%9 = alloca i32
store i8* %0, i8** %3
store i32 8, i32* %4
store i8 46, i8* %5
%10 = load i8*, i8** %3
%11 = call i8* @strrchr(i8* %10, i8 signext 46)
store i8* %11, i8** %6
%12 = bitcast [8 x i8*]* %7 to i8*
%13 = bitcast [8 x i8*]* %8 to i8*
%14 = load i8*, i8** %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.16, i64 0, i64 0), i8* %14)
store i32 0, i32* %9
br label %16
16: ; preds = %34, %1
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %37
19: ; preds = %16
%20 = load i8*, i8** %6
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [8 x i8*], [8 x i8*]* %7, i64 0, i64 %22
%24 = load i8*, i8** %23
%25 = call i64 @strcasecmp(i8* %20, i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %19
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.17, i64 0, i64 0))
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8 x i8*], [8 x i8*]* %8, i64 0, i64 %30
%32 = load i8*, i8** %31
store i8* %32, i8** %2
br label %39
33: ; preds = %19
br label %34
34: ; preds = %33
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %16
37: ; preds = %16
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.18, i64 0, i64 0))
store i8* null, i8** %2
br label %39
39: ; preds = %37, %27
%40 = load i8*, i8** %2
ret i8* %40
}

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)]
@.str.16 = [23 x i8] c"This is extension: %s\0A\00"
@str = [18 x i8] c"Invalid file type\00"
@str.19 = [24 x i8] c"Found correct extension\00"
define i8* @lookup(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.16, i64 0, i64 0), i8* %2)
%4 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %29, %26, %23, %20, %17, %14, %11, %1
%7 = phi i64 [ 0, %1 ], [ 1, %11 ], [ 2, %14 ], [ 3, %17 ], [ 4, %20 ], [ 5, %23 ], [ 6, %26 ], [ 7, %29 ]
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.19, i64 0, i64 0))
%9 = shl i64 %7, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.lookup to i8*), i64 %9)
br label %34
11: ; preds = %1
%12 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %11
%15 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %6, label %17
17: ; preds = %14
%18 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %6, label %20
20: ; preds = %17
%21 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %6, label %23
23: ; preds = %20
%24 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %6, label %26
26: ; preds = %23
%27 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %6, label %29
29: ; preds = %26
%30 = tail call i64 @strcasecmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %6, label %32
32: ; preds = %29
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %6, %32
%35 = phi i8* [ null, %32 ], [ %10, %6 ]
ret i8* %35
}