#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 */
char *basename(char *);
int /*<<< orphan*/ lowercase(char *);
char *mime_from_ext(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
const char *get_mime(char *path) {
  char temp[strlen(path) + 1], *fname, *ext;
  strcpy(temp, path);
  fname = basename(temp);
  ext = strchr(fname, '.');
  if (ext == NULL)
    ext = fname;
  else
    ext++;
  lowercase(ext);
  const char *ret = mime_from_ext(ext);
  return ret;
}


x86 assembly (clang, -O0):
<get_mime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11db <get_mime+0x7b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11e7 <get_mime+0x87>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <lowercase@plt>
mov    -0x28(%rbp),%rdi
call   1080 <mime_from_ext@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mime>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <basename@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r14,%rbx
mov    %rbx,%rdi
call   1070 <lowercase@plt>
mov    %rbx,%rdi
call   1080 <mime_from_ext@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @get_mime(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i8, i64 %11
store i64 %11, i64* %4
%14 = load i8*, i8** %2
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = call i8* @basename(i8* %13)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i8* @strchr(i8* %17, i8 signext 46)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = load i8*, i8** %5
store i8* %22, i8** %6
br label %26
23: ; preds = %1
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
br label %26
26: ; preds = %23, %21
%27 = load i8*, i8** %6
%28 = call i32 @lowercase(i8* %27)
%29 = load i8*, i8** %6
%30 = call i8* @mime_from_ext(i8* %29)
store i8* %30, i8** %7
%31 = load i8*, i8** %7
%32 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
define i8* @get_mime(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @strcpy(i8* %5, i8* %0)
%7 = call i8* @basename(i8* %5)
%8 = call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 46)
%9 = icmp eq i8* %8, null
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = select i1 %9, i8* %7, i8* %10
%12 = call i32 @lowercase(i8* %11)
%13 = call i8* @mime_from_ext(i8* %11)
ret i8* %13
}