#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 */
struct MEMMAN {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ file_loadfile(int, int, char *, int *, char *);
scalar_t__ memman_alloc_4k(struct MEMMAN *, int);
int /*<<< orphan*/ memman_free_4k(struct MEMMAN *, int, int);
int /*<<< orphan*/ tek_decomp(char *, char *, int);
int tek_getsize(char *);
char *file_loadfile2(int clustno, int *psize, int *fat) {
  int size = *psize, size2;
  struct MEMMAN *memman = (struct MEMMAN *)0x003c0000;
  char *buf, *buf2;
  buf = (char *)memman_alloc_4k(memman, size);
  file_loadfile(clustno, size, buf, fat, (char *)(0x00100000 + 0x003e00));
  if (size >= 17) {
    size2 = tek_getsize(buf);
    if (size2 > 0) {
      buf2 = (char *)memman_alloc_4k(memman, size2);
      tek_decomp(buf, buf2, size2);
      memman_free_4k(memman, (int)buf, size);
      buf = buf2;
      *psize = size2;
    }
  }
  return buf;
}


x86 assembly (clang, -O0):
<file_loadfile2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x3c0000,%eax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <memman_alloc_4k@plt>
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x103e00,%r8d
call   1050 <file_loadfile@plt>
cmpl   $0x11,-0x1c(%rbp)
jl     1206 <file_loadfile2+0xb6>
mov    -0x30(%rbp),%rdi
call   1070 <tek_getsize@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1201 <file_loadfile2+0xb1>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <memman_alloc_4k@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <tek_decomp@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   1040 <memman_free_4k@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1206 <file_loadfile2+0xb6>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_loadfile2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%r12d
mov    (%rsi),%ebp
mov    $0x3c0000,%edi
mov    %ebp,%esi
call   1060 <memman_alloc_4k@plt>
mov    %rax,%rbx
mov    $0x103e00,%r8d
mov    %r12d,%edi
mov    %ebp,%esi
mov    %rax,%rdx
mov    %r15,%rcx
call   1050 <file_loadfile@plt>
cmp    $0x11,%ebp
jl     11cd <file_loadfile2+0x7d>
mov    %rbx,%rdi
call   1070 <tek_getsize@plt>
test   %eax,%eax
jle    11cd <file_loadfile2+0x7d>
mov    %eax,%r15d
mov    $0x3c0000,%edi
mov    %eax,%esi
call   1060 <memman_alloc_4k@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1030 <tek_decomp@plt>
mov    $0x3c0000,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1040 <memman_free_4k@plt>
mov    %r15d,(%r14)
mov    %r12,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.MEMMAN = type { i32 }
define i8* @file_loadfile2(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.MEMMAN*
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
store i32 %13, i32* %7
store %struct.MEMMAN* inttoptr (i64 3932160 to %struct.MEMMAN*), %struct.MEMMAN** %9
%14 = load %struct.MEMMAN*, %struct.MEMMAN** %9
%15 = load i32, i32* %7
%16 = call i64 @memman_alloc_4k(%struct.MEMMAN* %14, i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %10
%18 = load i32, i32* %4
%19 = load i32, i32* %7
%20 = load i8*, i8** %10
%21 = load i32*, i32** %6
%22 = call i32 @file_loadfile(i32 %18, i32 %19, i8* %20, i32* %21, i8* inttoptr (i64 1064448 to i8*))
%23 = load i32, i32* %7
%24 = icmp sge i32 %23, 17
br i1 %24, label %25, label %48
25: ; preds = %3
%26 = load i8*, i8** %10
%27 = call i32 @tek_getsize(i8* %26)
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %47
30: ; preds = %25
%31 = load %struct.MEMMAN*, %struct.MEMMAN** %9
%32 = load i32, i32* %8
%33 = call i64 @memman_alloc_4k(%struct.MEMMAN* %31, i32 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %11
%35 = load i8*, i8** %10
%36 = load i8*, i8** %11
%37 = load i32, i32* %8
%38 = call i32 @tek_decomp(i8* %35, i8* %36, i32 %37)
%39 = load %struct.MEMMAN*, %struct.MEMMAN** %9
%40 = load i8*, i8** %10
%41 = ptrtoint i8* %40 to i32
%42 = load i32, i32* %7
%43 = call i32 @memman_free_4k(%struct.MEMMAN* %39, i32 %41, i32 %42)
%44 = load i8*, i8** %11
store i8* %44, i8** %10
%45 = load i32, i32* %8
%46 = load i32*, i32** %5
store i32 %45, i32* %46
br label %47
47: ; preds = %30, %25
br label %48
48: ; preds = %47, %3
%49 = load i8*, i8** %10
ret i8* %49
}

LLVM IR (-O2):
%struct.MEMMAN = type { i32 }
define i8* @file_loadfile2(i32 %0, i32* nocapture %1, i32* %2) {
%4 = load i32, i32* %1
%5 = tail call i64 @memman_alloc_4k(%struct.MEMMAN* inttoptr (i64 3932160 to %struct.MEMMAN*), i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @file_loadfile(i32 %0, i32 %4, i8* %6, i32* %2, i8* inttoptr (i64 1064448 to i8*))
%8 = icmp sgt i32 %4, 16
br i1 %8, label %9, label %18
9: ; preds = %3
%10 = tail call i32 @tek_getsize(i8* %6)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = tail call i64 @memman_alloc_4k(%struct.MEMMAN* inttoptr (i64 3932160 to %struct.MEMMAN*), i32 %10)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @tek_decomp(i8* %6, i8* %14, i32 %10)
%16 = trunc i64 %5 to i32
%17 = tail call i32 @memman_free_4k(%struct.MEMMAN* inttoptr (i64 3932160 to %struct.MEMMAN*), i32 %16, i32 %4)
store i32 %10, i32* %1
br label %18
18: ; preds = %9, %12, %3
%19 = phi i8* [ %14, %12 ], [ %6, %9 ], [ %6, %3 ]
ret i8* %19
}