#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 */
unsigned char *BLZ_Code(unsigned char *, unsigned int, unsigned int *, int);
unsigned char *Load(char *, unsigned int *, int, int);
int /*<<< orphan*/ Save(char *, unsigned char *, unsigned int);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
void BLZ_Encode(char *filename, int mode) {
  unsigned char *raw_buffer, *pak_buffer, *new_buffer;
  unsigned int raw_len, pak_len, new_len;
  printf("- encoding '%s'", filename);
  raw_buffer = Load(filename, &raw_len, 0x00000000, 0x00FFFFFF);
  pak_buffer = NULL;
  pak_len = 0x01400000 + 1;
  new_buffer = BLZ_Code(raw_buffer, raw_len, &new_len, mode);
  if (new_len < pak_len) {
    if (pak_buffer != NULL)
      free(pak_buffer);
    pak_buffer = new_buffer;
    pak_len = new_len;
  }
  Save(filename, pak_buffer, pak_len);
  free(pak_buffer);
  free(raw_buffer);
  printf("\n");
}


x86 assembly (clang, -O0):
<BLZ_Encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
mov    $0xffffff,%ecx
call   1040 <Load@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1400001,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    -0x34(%rbp),%rdx
call   1050 <BLZ_Code@plt>
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jae    11dd <BLZ_Encode+0x8d>
cmpq   $0x0,-0x20(%rbp)
je     11cf <BLZ_Encode+0x7f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1070 <Save@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BLZ_Encode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xe8c(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
mov    $0xffffff,%ecx
call   1050 <Load@plt>
mov    %rax,%rbp
mov    0x4(%rsp),%esi
mov    %rsp,%rdx
mov    %rax,%rdi
mov    %r15d,%ecx
call   1060 <BLZ_Code@plt>
mov    (%rsp),%ecx
cmp    $0x1400001,%ecx
cmovb  %rax,%rbx
mov    $0x1400001,%edx
cmovb  %ecx,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <Save@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"- encoding '%s'\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @BLZ_Encode(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %3
%14 = call i8* @Load(i8* %13, i32* %8, i32 0, i32 16777215)
store i8* %14, i8** %5
store i8* null, i8** %6
store i32 20971521, i32* %9
%15 = load i8*, i8** %5
%16 = load i32, i32* %8
%17 = load i32, i32* %4
%18 = call i8* @BLZ_Code(i8* %15, i32 %16, i32* %10, i32 %17)
store i8* %18, i8** %7
%19 = load i32, i32* %10
%20 = load i32, i32* %9
%21 = icmp ult i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %2
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %25, %22
%29 = load i8*, i8** %7
store i8* %29, i8** %6
%30 = load i32, i32* %10
store i32 %30, i32* %9
br label %31
31: ; preds = %28, %2
%32 = load i8*, i8** %3
%33 = load i8*, i8** %6
%34 = load i32, i32* %9
%35 = call i32 @Save(i8* %32, i8* %33, i32 %34)
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %5
%39 = call i32 @free(i8* %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"- encoding '%s'\00"
define void @BLZ_Encode(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i8* @Load(i8* %0, i32* %3, i32 0, i32 16777215)
%9 = load i32, i32* %3
%10 = call i8* @BLZ_Code(i8* %8, i32 %9, i32* %4, i32 %1)
%11 = load i32, i32* %4
%12 = icmp ult i32 %11, 20971521
%13 = select i1 %12, i8* %10, i8* null
%14 = select i1 %12, i32 %11, i32 20971521
%15 = call i32 @Save(i8* %0, i8* %13, i32 %14)
%16 = call i32 @free(i8* %13)
%17 = call i32 @free(i8* %8)
%18 = call i32 @putchar(i32 10)
ret void
}