#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*/ strcasecmp(char *, char *);
char *strrchr(char const *, char);
const char *mimetype_from_ext(const char *filename) {
  char *ext = strrchr(filename, '.');
  if (!ext)
    return "";
  if (!strcasecmp(ext + 1, "jpg") || !strcasecmp(ext + 1, "jpeg"))
    return "image/jpeg";
  if (!strcasecmp(ext + 1, "png"))
    return "image/png";
  if (!strcasecmp(ext + 1, "y4m"))
    return "video/yuv4mpeg";
  if (!strcasecmp(ext + 1, "pgm"))
    return "image/x-portable-graymap";
  return "";
}


x86 assembly (clang, -O0):
<mimetype_from_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1159 <mimetype_from_ext+0x39>
lea    0xebe(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <mimetype_from_ext+0x115>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe98(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
je     1193 <mimetype_from_ext+0x73>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe85(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11a3 <mimetype_from_ext+0x83>
lea    0xe6a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <mimetype_from_ext+0x115>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe63(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11d0 <mimetype_from_ext+0xb0>
lea    0xe48(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <mimetype_from_ext+0x115>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe3a(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11fd <mimetype_from_ext+0xdd>
lea    0xe29(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <mimetype_from_ext+0x115>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe20(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    122a <mimetype_from_ext+0x10a>
lea    0xe0f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1235 <mimetype_from_ext+0x115>
lea    0xddd(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mimetype_from_ext>:
push   %r14
push   %rbx
push   %rax
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11b2 <mimetype_from_ext+0x92>
mov    %rax,%rbx
add    $0x1,%rbx
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
lea    0xeb4(%rip),%r14
test   %eax,%eax
je     11b9 <mimetype_from_ext+0x99>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11b9 <mimetype_from_ext+0x99>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11c4 <mimetype_from_ext+0xa4>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     11cd <mimetype_from_ext+0xad>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
lea    0xe8b(%rip),%rax
lea    0xe62(%rip),%r14
cmove  %rax,%r14
jmp    11b9 <mimetype_from_ext+0x99>
lea    0xe55(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe44(%rip),%r14
jmp    11b9 <mimetype_from_ext+0x99>
lea    0xe49(%rip),%r14
jmp    11b9 <mimetype_from_ext+0x99>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"jpg\00"
@.str.2 = [5 x i8] c"jpeg\00"
@.str.3 = [11 x i8] c"image/jpeg\00"
@.str.4 = [4 x i8] c"png\00"
@.str.5 = [10 x i8] c"image/png\00"
@.str.6 = [4 x i8] c"y4m\00"
@.str.7 = [15 x i8] c"video/yuv4mpeg\00"
@.str.8 = [4 x i8] c"pgm\00"
@.str.9 = [25 x i8] c"image/x-portable-graymap\00"
define i8* @mimetype_from_ext(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strrchr(i8* %5, i8 signext 46)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %40
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = call i32 @strcasecmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = call i32 @strcasecmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %15, %10
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %40
21: ; preds = %15
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i32 @strcasecmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %21
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %40
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = call i32 @strcasecmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %40
33: ; preds = %27
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = call i32 @strcasecmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %33
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %40
39: ; preds = %33
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %40
40: ; preds = %39, %38, %32, %26, %20, %9
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"jpg\00"
@.str.2 = [5 x i8] c"jpeg\00"
@.str.3 = [11 x i8] c"image/jpeg\00"
@.str.4 = [4 x i8] c"png\00"
@.str.5 = [10 x i8] c"image/png\00"
@.str.6 = [4 x i8] c"y4m\00"
@.str.7 = [15 x i8] c"video/yuv4mpeg\00"
@.str.8 = [4 x i8] c"pgm\00"
@.str.9 = [25 x i8] c"image/x-portable-graymap\00"
define i8* @mimetype_from_ext(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = tail call i32 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %4
%9 = tail call i32 @strcasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = tail call i32 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = tail call i32 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = tail call i32 @strcasecmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br label %21
21: ; preds = %17, %14, %11, %4, %8, %1
%22 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), %11 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), %14 ], [ %20, %17 ]
ret i8* %22
}