#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lua(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ py(char *);
scalar_t__ starts_with(char *, char *);
int /*<<< orphan*/ stderr;
void heuristics(char *file) {
  char *content = NULL;
  FILE *f = fopen(file, "r");
  size_t unused;
  if (!f)
    die("Could not open file.");
  content = (char *)malloc(10 * sizeof(char));
  if (!content)
    die("Could not allocate enough memory.");
  unused = fread(content, 9, 1, f);
  if (unused != 1)
    fprintf(stderr, "Reading the file in may have failed.\n");
  fclose(f);
  content[9] = 0;
  if (starts_with(content, "\x1B\x4C\x75\x61"))
    lua(file);
  else if (starts_with(content, "\x16\r\r\n"))
    py(file);
  else
    puts("Could not match magic numbers. decode only support Lua 5.1/Python "
         "3.4.");
  free(content);
}


x86 assembly (clang, -O0):
<heuristics>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ef <heuristics+0x3f>
lea    0xe18(%rip),%rdi
call   10c0 <die@plt>
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1214 <heuristics+0x64>
lea    0xe08(%rip),%rdi
call   10c0 <die@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x9,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x1,-0x20(%rbp)
je     124f <heuristics+0x9f>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x9(%rax)
mov    -0x10(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   10a0 <starts_with@plt>
cmp    $0x0,%rax
je     1288 <heuristics+0xd8>
mov    -0x8(%rbp),%rdi
call   1070 <lua@plt>
jmp    12c1 <heuristics+0x111>
mov    -0x10(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   10a0 <starts_with@plt>
cmp    $0x0,%rax
je     12b0 <heuristics+0x100>
mov    -0x8(%rbp),%rdi
call   10d0 <py@plt>
jmp    12bc <heuristics+0x10c>
lea    0xdb2(%rip),%rdi
call   1040 <puts@plt>
jmp    12c1 <heuristics+0x111>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heuristics>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe41(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11d8 <heuristics+0x28>
lea    0xe2f(%rip),%rdi
call   10c0 <die@plt>
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11f6 <heuristics+0x46>
lea    0xe26(%rip),%rdi
call   10c0 <die@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
cmp    $0x1,%rax
je     1226 <heuristics+0x76>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1080 <fprintf@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
movb   $0x0,0x9(%rbx)
lea    0xe26(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <starts_with@plt>
test   %rax,%rax
je     1250 <heuristics+0xa0>
mov    %r14,%rdi
call   1070 <lua@plt>
jmp    127a <heuristics+0xca>
lea    0xe0d(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <starts_with@plt>
test   %rax,%rax
je     126e <heuristics+0xbe>
mov    %r14,%rdi
call   10d0 <py@plt>
jmp    127a <heuristics+0xca>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"Could not open file.\00"
@.str.2 = [34 x i8] c"Could not allocate enough memory.\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"Reading the file in may have failed.\0A\00"
@.str.4 = [5 x i8] c"\1BLua\00"
@.str.5 = [5 x i8] c"\16\0D\0D\0A\00"
@.str.6 = [71 x i8] c"Could not match magic numbers. decode only support Lua 5.1/Python 3.4.\00"
define void @heuristics(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = call i64 @malloc(i32 10)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = load i8*, i8** %3
%21 = load i32*, i32** %4
%22 = call i64 @fread(i8* %20, i32 9, i32 1, i32* %21)
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = icmp ne i64 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %25, %19
%29 = load i32*, i32** %4
%30 = call i32 @fclose(i32* %29)
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 9
store i8 0, i8* %32
%33 = load i8*, i8** %3
%34 = call i64 @starts_with(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i8*, i8** %2
%38 = call i32 @lua(i8* %37)
br label %49
39: ; preds = %28
%40 = load i8*, i8** %3
%41 = call i64 @starts_with(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i8*, i8** %2
%45 = call i32 @py(i8* %44)
br label %48
46: ; preds = %39
%47 = call i32 @puts(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
br label %49
49: ; preds = %48, %36
%50 = load i8*, i8** %3
%51 = call i32 @free(i8* %50)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"Could not open file.\00"
@.str.2 = [34 x i8] c"Could not allocate enough memory.\00"
@stderr = global i32 0
@.str.3 = [38 x i8] c"Reading the file in may have failed.\0A\00"
@.str.4 = [5 x i8] c"\1BLua\00"
@.str.5 = [5 x i8] c"\16\0D\0D\0A\00"
@.str.6 = [71 x i8] c"Could not match magic numbers. decode only support Lua 5.1/Python 3.4.\00"
define void @heuristics(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @die(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i64 @malloc(i32 10)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = tail call i64 @fread(i8* %8, i32 9, i32 1, i32* %2)
%14 = icmp eq i64 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %15, %12
%19 = tail call i32 @fclose(i32* %2)
%20 = getelementptr inbounds i8, i8* %8, i64 9
store i8 0, i8* %20
%21 = tail call i64 @starts_with(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = tail call i32 @lua(i8* %0)
br label %32
25: ; preds = %18
%26 = tail call i64 @starts_with(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 @py(i8* %0)
br label %32
30: ; preds = %25
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0))
br label %32
32: ; preds = %28, %30, %23
%33 = tail call i32 @free(i8* %8)
ret void
}