#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*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char const *, char);
void get_file_type(const char *file, char *type) {
  char *ext = strrchr(file, '.');
  if (!ext || !*(ext + 1))
    strcpy(type, "text/plain");
  else if (!strcmp(ext + 1, "txt"))
    strcpy(type, "text/plain");
  else if (!strcmp(ext + 1, "html"))
    strcpy(type, "text/html");
  else if (!strcmp(ext + 1, "jpeg") || !strcmp(ext + 1, "jpg"))
    strcpy(type, "image/jpeg");
  else if (!strcmp(ext + 1, "png"))
    strcpy(type, "image/png");
  else
    strcpy(type, "text/plain");
}


x86 assembly (clang, -O0):
<get_file_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116b <get_file_type+0x3b>
mov    -0x18(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    1180 <get_file_type+0x50>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1289 <get_file_type+0x159>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe7c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b2 <get_file_type+0x82>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1284 <get_file_type+0x154>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe53(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e4 <get_file_type+0xb4>
mov    -0x10(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1030 <strcpy@plt>
jmp    127f <get_file_type+0x14f>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe30(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     121e <get_file_type+0xee>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe09(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1233 <get_file_type+0x103>
mov    -0x10(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1030 <strcpy@plt>
jmp    127a <get_file_type+0x14a>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xdec(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1265 <get_file_type+0x135>
mov    -0x10(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1275 <get_file_type+0x145>
mov    -0x10(%rbp),%rdi
lea    0xd90(%rip),%rsi
call   1030 <strcpy@plt>
jmp    127a <get_file_type+0x14a>
jmp    127f <get_file_type+0x14f>
jmp    1284 <get_file_type+0x154>
jmp    1289 <get_file_type+0x159>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_type>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    $0x2e,%esi
call   1040 <strrchr@plt>
lea    0xeb7(%rip),%r15
test   %rax,%rax
je     11e2 <get_file_type+0xb2>
mov    %rax,%rbx
cmpb   $0x0,0x1(%rax)
je     11e2 <get_file_type+0xb2>
add    $0x1,%rbx
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11e2 <get_file_type+0xb2>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11db <get_file_type+0xab>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
lea    0xe7e(%rip),%r15
test   %eax,%eax
je     11e2 <get_file_type+0xb2>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11e2 <get_file_type+0xb2>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
lea    0xe5a(%rip),%rax
lea    0xe2b(%rip),%r15
cmove  %rax,%r15
jmp    11e2 <get_file_type+0xb2>
lea    0xe2d(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"text/plain\00"
@.str.1 = [4 x i8] c"txt\00"
@.str.2 = [5 x i8] c"html\00"
@.str.3 = [10 x i8] c"text/html\00"
@.str.4 = [5 x i8] c"jpeg\00"
@.str.5 = [4 x i8] c"jpg\00"
@.str.6 = [11 x i8] c"image/jpeg\00"
@.str.7 = [4 x i8] c"png\00"
@.str.8 = [10 x i8] c"image/png\00"
define void @get_file_type(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i8* @strrchr(i8* %6, i8 signext 46)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10, %2
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %62
18: ; preds = %10
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %61
26: ; preds = %18
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %60
34: ; preds = %26
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i32 @strcmp(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%43 = icmp ne i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %39, %34
%45 = load i8*, i8** %4
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %59
47: ; preds = %39
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %47
%53 = load i8*, i8** %4
%54 = call i32 @strcpy(i8* %53, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %58
55: ; preds = %47
%56 = load i8*, i8** %4
%57 = call i32 @strcpy(i8* %56, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
br label %59
59: ; preds = %58, %44
br label %60
60: ; preds = %59, %31
br label %61
61: ; preds = %60, %23
br label %62
62: ; preds = %61, %15
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"text/plain\00"
@.str.1 = [4 x i8] c"txt\00"
@.str.2 = [5 x i8] c"html\00"
@.str.3 = [10 x i8] c"text/html\00"
@.str.4 = [5 x i8] c"jpeg\00"
@.str.5 = [4 x i8] c"jpg\00"
@.str.6 = [11 x i8] c"image/jpeg\00"
@.str.7 = [4 x i8] c"png\00"
@.str.8 = [10 x i8] c"image/png\00"
define void @get_file_type(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %5
%10 = tail call i32 @strcmp(i8* %6, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %9
%13 = tail call i32 @strcmp(i8* %6, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = tail call i32 @strcmp(i8* %6, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = tail call i32 @strcmp(i8* %6, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i32 @strcmp(i8* %6, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0)
br label %25
25: ; preds = %21, %15, %18, %12, %9, %2, %5
%26 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %12 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %18 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %15 ], [ %24, %21 ]
%27 = tail call i32 @strcpy(i8* %1, i8* %26)
ret void
}