#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__ strcmp(char *, char *);
size_t strlen(char const *);
char tolower(char const);
const char *lookup(const char *extension) {
  char ext[strlen(extension) + 1];
  for (int i = 0, extlen = strlen(extension); i < extlen; i++)
    ext[i] = tolower(extension[i]);
  ext[strlen(extension)] = '\0';
  if (strcmp(ext, "css") == 0)
    return "text/css";
  else if (strcmp(ext, "html") == 0)
    return "text/html";
  else if (strcmp(ext, "js") == 0)
    return "text/javascript";
  else if (strcmp(ext, "gif") == 0)
    return "image/gif";
  else if (strcmp(ext, "ico") == 0)
    return "image/x-icon";
  else if (strcmp(ext, "jpg") == 0)
    return "image/jpg";
  else if (strcmp(ext, "png") == 0)
    return "image/png";
  else
    return NULL;
}


x86 assembly (clang, -O0):
<lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdx
mov    %rdx,%rax
add    $0x1,%rax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
add    $0x10,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11ba <lookup+0x8a>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x38(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1182 <lookup+0x52>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
movb   $0x0,(%rdi,%rax,1)
lea    0xe33(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11f8 <lookup+0xc8>
lea    0xe18(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    132d <lookup+0x1fd>
mov    -0x38(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1229 <lookup+0xf9>
lea    0xdf0(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    132d <lookup+0x1fd>
mov    -0x38(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    125a <lookup+0x12a>
lea    0xdcc(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    132d <lookup+0x1fd>
mov    -0x38(%rbp),%rdi
lea    0xdc7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    128b <lookup+0x15b>
lea    0xdab(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    132d <lookup+0x1fd>
mov    -0x38(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12bc <lookup+0x18c>
lea    0xd88(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    132d <lookup+0x1fd>
mov    -0x38(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12ed <lookup+0x1bd>
lea    0xd64(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    132d <lookup+0x1fd>
mov    -0x38(%rbp),%rdi
lea    0xd59(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    131e <lookup+0x1ee>
lea    0xd3d(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    132d <lookup+0x1fd>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rsp,%r14
lea    0x10(%rax),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r14
mov    %r14,%rsp
test   %eax,%eax
jle    1177 <lookup+0x47>
mov    %eax,%r12d
xor    %ebx,%ebx
nopl   (%rax)
movsbl (%r15,%rbx,1),%edi
call   1050 <tolower@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <lookup+0x30>
mov    %r15,%rdi
call   1030 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
lea    0xe7a(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1224 <lookup+0xf4>
lea    0xe6b(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     122d <lookup+0xfd>
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1236 <lookup+0x106>
lea    0xe61(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     123f <lookup+0x10f>
lea    0xe51(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1248 <lookup+0x118>
lea    0xe54(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1251 <lookup+0x121>
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
lea    0xe2d(%rip),%rcx
cmove  %rcx,%rax
jmp    1258 <lookup+0x128>
lea    0xdd5(%rip),%rax
jmp    1258 <lookup+0x128>
lea    0xdd5(%rip),%rax
jmp    1258 <lookup+0x128>
lea    0xdd9(%rip),%rax
jmp    1258 <lookup+0x128>
lea    0xde0(%rip),%rax
jmp    1258 <lookup+0x128>
lea    0xde5(%rip),%rax
jmp    1258 <lookup+0x128>
lea    0xde9(%rip),%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"css\00"
@.str.1 = [9 x i8] c"text/css\00"
@.str.2 = [5 x i8] c"html\00"
@.str.3 = [10 x i8] c"text/html\00"
@.str.4 = [3 x i8] c"js\00"
@.str.5 = [16 x i8] c"text/javascript\00"
@.str.6 = [4 x i8] c"gif\00"
@.str.7 = [10 x i8] c"image/gif\00"
@.str.8 = [4 x i8] c"ico\00"
@.str.9 = [13 x i8] c"image/x-icon\00"
@.str.10 = [4 x i8] c"jpg\00"
@.str.11 = [10 x i8] c"image/jpg\00"
@.str.12 = [4 x i8] c"png\00"
@.str.13 = [10 x i8] c"image/png\00"
define i8* @lookup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = add i64 %10, 1
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
store i32 0, i32* %6
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %7
br label %17
17: ; preds = %31, %1
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call signext i8 @tolower(i8 signext %26)
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %13, i64 %29
store i8 %27, i8* %30
br label %31
31: ; preds = %21
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %17
34: ; preds = %17
%35 = load i8*, i8** %3
%36 = call i64 @strlen(i8* %35)
%37 = getelementptr inbounds i8, i8* %13, i64 %36
store i8 0, i8* %37
%38 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %2
store i32 1, i32* %8
br label %66
41: ; preds = %34
%42 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %41
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %2
store i32 1, i32* %8
br label %66
45: ; preds = %41
%46 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8** %2
store i32 1, i32* %8
br label %66
49: ; preds = %45
%50 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %49
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8** %2
store i32 1, i32* %8
br label %66
53: ; preds = %49
%54 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8** %2
store i32 1, i32* %8
br label %66
57: ; preds = %53
%58 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i8** %2
store i32 1, i32* %8
br label %66
61: ; preds = %57
%62 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %61
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8** %2
store i32 1, i32* %8
br label %66
65: ; preds = %61
store i8* null, i8** %2
store i32 1, i32* %8
br label %66
66: ; preds = %65, %64, %60, %56, %52, %48, %44, %40
%67 = load i8*, i8** %4
%68 = load i8*, i8** %2
ret i8* %68
}

LLVM IR (-O2):
@.str = [4 x i8] c"css\00"
@.str.1 = [9 x i8] c"text/css\00"
@.str.2 = [5 x i8] c"html\00"
@.str.3 = [10 x i8] c"text/html\00"
@.str.4 = [3 x i8] c"js\00"
@.str.5 = [16 x i8] c"text/javascript\00"
@.str.6 = [4 x i8] c"gif\00"
@.str.7 = [10 x i8] c"image/gif\00"
@.str.8 = [4 x i8] c"ico\00"
@.str.9 = [13 x i8] c"image/x-icon\00"
@.str.10 = [4 x i8] c"jpg\00"
@.str.11 = [10 x i8] c"image/jpg\00"
@.str.12 = [4 x i8] c"png\00"
@.str.13 = [10 x i8] c"image/png\00"
define i8* @lookup(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = alloca i8, i64 %3
%5 = trunc i64 %2 to i32
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = and i64 %2, 4294967295
br label %14
9: ; preds = %14, %1
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = getelementptr inbounds i8, i8* %4, i64 %10
store i8 0, i8* %11
%12 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %41, label %22
14: ; preds = %7, %14
%15 = phi i64 [ 0, %7 ], [ %20, %14 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call signext i8 @tolower(i8 signext %17)
%19 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 %18, i8* %19
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %9, label %14
22: ; preds = %9
%23 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %41, label %25
25: ; preds = %22
%26 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %41, label %28
28: ; preds = %25
%29 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %41, label %31
31: ; preds = %28
%32 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %41, label %34
34: ; preds = %31
%35 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
%40 = select i1 %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i8* null
br label %41
41: ; preds = %37, %34, %31, %28, %25, %22, %9
%42 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %22 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), %25 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), %28 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), %31 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), %34 ], [ %40, %37 ]
ret i8* %42
}