#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 */
typedef int /*<<< orphan*/ xpm;
typedef int /*<<< orphan*/ png;
typedef int /*<<< orphan*/ jpg;
typedef int /*<<< orphan*/ gif;

/* Variables and functions */
scalar_t__ match(char const *, char *, int);
const char *gettype(const char *buf) {
  char png[] = {
      0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
  };
  char gif[] = {
      0x47, 0x49, 0x46, 0x38, 0x61, 0x37, 0x39,
  };
  char jpg[] = {
      0xff, 0xd8, 0xff, 0xe0, 0xe1, 0xdb,
  };
  char xpm[] = {
      '/', '*', ' ', 'X', 'P', 'M', ' ', '*', '/',
  };
  if (match(buf, png, sizeof(png))) {
    return "image/png";
  } else if (match(buf, gif, sizeof(gif))) {
    return "image/gif";
  } else if (match(buf, jpg, sizeof(jpg))) {
    return "image/jpg";
  } else if (match(buf, xpm, sizeof(xpm))) {
    return "image/xpm";
  } else if (match(buf, "<!DOCTYPE html>", (sizeof("<!DOCTYPE html>") - 1))) {
    return "text/html";
  } else {
    return "text/plain";
  }
}


x86 assembly (clang, -O0):
<gettype>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xedb(%rip),%eax
mov    %eax,-0x1f(%rbp)
mov    0xed5(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xecd(%rip),%al
mov    %al,-0x19(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xebf(%rip),%ax
mov    %ax,-0x21(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x2e(%rbp)
mov    0xeb4(%rip),%al
mov    %al,-0x26(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1030 <match@plt>
cmp    $0x0,%rax
je     1198 <gettype+0x88>
lea    0xe8f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1256 <gettype+0x146>
mov    -0x10(%rbp),%rdi
lea    -0x1f(%rbp),%rsi
mov    $0x7,%edx
call   1030 <match@plt>
cmp    $0x0,%rax
je     11c4 <gettype+0xb4>
lea    0xe6d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1256 <gettype+0x146>
mov    -0x10(%rbp),%rdi
lea    -0x25(%rbp),%rsi
mov    $0x6,%edx
call   1030 <match@plt>
cmp    $0x0,%rax
je     11f0 <gettype+0xe0>
lea    0xe4b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1256 <gettype+0x146>
mov    -0x10(%rbp),%rdi
lea    -0x2e(%rbp),%rsi
mov    $0x9,%edx
call   1030 <match@plt>
cmp    $0x0,%rax
je     121c <gettype+0x10c>
lea    0xe29(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1256 <gettype+0x146>
mov    -0x10(%rbp),%rdi
lea    0xe1f(%rip),%rsi
mov    $0xf,%edx
call   1030 <match@plt>
cmp    $0x0,%rax
je     124b <gettype+0x13b>
lea    0xe14(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1256 <gettype+0x146>
lea    0xe0e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettype>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movabs $0xa1a0a0d474e5089,%rax
0a 1a 0a
mov    %rax,0x28(%rsp)
movl   $0x39376138,0x13(%rsp)
39
movl   $0x38464947,0x10(%rsp)
38
movw   $0xdbe1,0xc(%rsp)
movl   $0xe0ffd8ff,0x8(%rsp)
e0
movabs $0x2a204d5058202a2f,%rax
4d 20 2a
mov    %rax,0x18(%rsp)
movb   $0x2f,0x20(%rsp)
lea    0x28(%rsp),%rsi
mov    $0x8,%edx
call   1030 <match@plt>
test   %rax,%rax
je     117a <gettype+0x6a>
lea    0xea1(%rip),%rax
jmp    1203 <gettype+0xf3>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1030 <match@plt>
test   %rax,%rax
je     119a <gettype+0x8a>
lea    0xe88(%rip),%rax
jmp    1203 <gettype+0xf3>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x6,%edx
call   1030 <match@plt>
test   %rax,%rax
je     11ba <gettype+0xaa>
lea    0xe72(%rip),%rax
jmp    1203 <gettype+0xf3>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x9,%edx
call   1030 <match@plt>
test   %rax,%rax
je     11da <gettype+0xca>
lea    0xe5c(%rip),%rax
jmp    1203 <gettype+0xf3>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
mov    $0xf,%edx
call   1030 <match@plt>
test   %rax,%rax
lea    0xe60(%rip),%rcx
lea    0xe4f(%rip),%rax
cmove  %rcx,%rax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.gettype.png = [8 x i8] c"\89PNG\0D\0A\1A\0A"
@__const.gettype.gif = [7 x i8] c"GIF8a79"
@__const.gettype.jpg = [6 x i8] c"\FF\D8\FF\E0\E1\DB"
@__const.gettype.xpm = [9 x i8] c"/* XPM */"
@.str = [10 x i8] c"image/png\00"
@.str.1 = [10 x i8] c"image/gif\00"
@.str.2 = [10 x i8] c"image/jpg\00"
@.str.3 = [10 x i8] c"image/xpm\00"
@.str.4 = [16 x i8] c"<!DOCTYPE html>\00"
@.str.5 = [10 x i8] c"text/html\00"
@.str.6 = [11 x i8] c"text/plain\00"
define i8* @gettype(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [8 x i8]
%5 = alloca [7 x i8]
%6 = alloca [6 x i8]
%7 = alloca [9 x i8]
store i8* %0, i8** %3
%8 = bitcast [8 x i8]* %4 to i8*
%9 = bitcast [7 x i8]* %5 to i8*
%10 = bitcast [6 x i8]* %6 to i8*
%11 = bitcast [9 x i8]* %7 to i8*
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%14 = call i64 @match(i8* %12, i8* %13, i32 8)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
br label %41
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%20 = call i64 @match(i8* %18, i8* %19, i32 7)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %41
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%26 = call i64 @match(i8* %24, i8* %25, i32 6)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %41
29: ; preds = %23
%30 = load i8*, i8** %3
%31 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%32 = call i64 @match(i8* %30, i8* %31, i32 9)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %41
35: ; preds = %29
%36 = load i8*, i8** %3
%37 = call i64 @match(i8* %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 15)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %41
40: ; preds = %35
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %41
41: ; preds = %40, %39, %34, %28, %22, %16
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
@__const.gettype.gif = [7 x i8] c"GIF8a79"
@__const.gettype.jpg = [6 x i8] c"\FF\D8\FF\E0\E1\DB"
@__const.gettype.xpm = [9 x i8] c"/* XPM */"
@.str = [10 x i8] c"image/png\00"
@.str.1 = [10 x i8] c"image/gif\00"
@.str.2 = [10 x i8] c"image/jpg\00"
@.str.3 = [10 x i8] c"image/xpm\00"
@.str.4 = [16 x i8] c"<!DOCTYPE html>\00"
@.str.5 = [10 x i8] c"text/html\00"
@.str.6 = [11 x i8] c"text/plain\00"
define i8* @gettype(i8* %0) {
%2 = alloca i64
%3 = alloca [7 x i8]
%4 = alloca [6 x i8]
%5 = alloca [9 x i8]
%6 = bitcast i64* %2 to i8*
store i64 727905341920923785, i64* %2
%7 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%10 = call i64 @match(i8* %0, i8* %6, i32 8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %1
%13 = call i64 @match(i8* %0, i8* %7, i32 7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = call i64 @match(i8* %0, i8* %8, i32 6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = call i64 @match(i8* %0, i8* %9, i32 9)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = call i64 @match(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 15)
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0)
br label %25
25: ; preds = %21, %18, %15, %12, %1
%26 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %18 ], [ %24, %21 ]
ret i8* %26
}