#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
unsigned long comp_exec(unsigned char *, unsigned long, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fopen_s(int /*<<< orphan*/ **, char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, unsigned long,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ printf(char *, ...);
void zero_bin_read(char *infile, unsigned char **buffer,
                   unsigned long *buffer_len) {
  unsigned long ret, len;
  unsigned char *buffer1 = NULL;
  unsigned char *buffer2 = NULL;
  FILE *fp;
  *buffer = NULL;
  *buffer_len = 0;
  fopen_s(&fp, infile, "rb");
  if (!fp) {
    printf(" [BIN   ]Error : could't open file (%s) !\n", infile);
    return;
  }
  fseek(fp, 0, SEEK_END);
  len = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  buffer1 = (unsigned char *)malloc(len);
  if (!buffer1) {
    fclose(fp);
    fp = NULL;
    printf(" [BIN   ]Alloc error#1 (%d bytes) !\n", len);
    return;
  }
  fread(buffer1, 1, len, fp);
  fclose(fp);
  fp = NULL;
  buffer2 = (unsigned char *)malloc(len + 5);
  if (!buffer2) {
    free(buffer1);
    buffer1 = NULL;
    printf(" [BIN   ]Alloc error#2 (%d bytes) !\n", len + 5);
    return;
  }
  ret = comp_exec(buffer1, len, buffer2);
  printf(" [BIN   ]Compressed size = %d bytes (input size * %f %%)\n", ret,
         ((float)(100 * ret)) / len);
  free(buffer1);
  buffer1 = NULL;
  *buffer = buffer2;
  *buffer_len = ret;
}


x86 assembly (clang, -O0):
<zero_bin_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rsi
lea    -0x40(%rbp),%rdi
lea    0xe27(%rip),%rdx
call   1040 <fopen_s@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1200 <zero_bin_read+0x70>
mov    -0x8(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    13c8 <zero_bin_read+0x238>
mov    -0x40(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1275 <zero_bin_read+0xe5>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    13c8 <zero_bin_read+0x238>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x5,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12e4 <zero_bin_read+0x154>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
add    $0x5,%rsi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    13c8 <zero_bin_read+0x238>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1070 <comp_exec@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
imul   $0x64,%rax,%rax
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x48(%rbp)
mov    %rax,%rcx
shr    %rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
test   %rax,%rax
movss  %xmm0,-0x44(%rbp)
js     1336 <zero_bin_read+0x1a6>
movss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x58(%rbp)
test   %rax,%rax
movss  %xmm0,-0x54(%rbp)
js     137d <zero_bin_read+0x1ed>
movss  -0x58(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
mov    -0x50(%rbp),%rsi
movss  -0x5c(%rbp),%xmm0
movss  -0x54(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcde(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zero_bin_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
lea    0xe47(%rip),%rdx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1040 <fopen_s@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1275 <zero_bin_read+0xe5>
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    (%rsp),%rdi
call   1090 <ftell@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <malloc@plt>
mov    (%rsp),%rcx
test   %rax,%rax
je     127e <zero_bin_read+0xee>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1050 <fread@plt>
mov    (%rsp),%rdi
call   1060 <fclose@plt>
movq   $0x0,(%rsp)
lea    0x5(%rbx),%rbp
mov    %rbp,%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     129a <zero_bin_read+0x10a>
mov    %rax,%r13
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1070 <comp_exec@plt>
mov    %rax,%rbp
imul   $0x64,%rax,%rax
test   %rax,%rax
js     12b5 <zero_bin_read+0x125>
cvtsi2ss %rax,%xmm0
test   %rbx,%rbx
js     12c6 <zero_bin_read+0x136>
cvtsi2ss %rbx,%xmm1
jmp    12db <zero_bin_read+0x14b>
lea    0xd87(%rip),%rdi
jmp    1295 <zero_bin_read+0x105>
mov    %rcx,%rdi
call   1060 <fclose@plt>
movq   $0x0,(%rsp)
lea    0xd99(%rip),%rdi
mov    %rbx,%rsi
jmp    12ac <zero_bin_read+0x11c>
mov    %r12,%rdi
call   1030 <free@plt>
lea    0xdaa(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1302 <zero_bin_read+0x172>
shr    %rax
cvtsi2ss %rax,%xmm0
addss  %xmm0,%xmm0
test   %rbx,%rbx
jns    126e <zero_bin_read+0xde>
mov    %rbx,%rax
shr    %rax
and    $0x1,%ebx
or     %rax,%rbx
cvtsi2ss %rbx,%xmm1
addss  %xmm1,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd8e(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1080 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,(%r15)
mov    %rbp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [43 x i8] c" [BIN ]Error : could't open file (%s) !\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [37 x i8] c" [BIN ]Alloc error (%d bytes) !\0A\00"
@.str.3 = [37 x i8] c" [BIN ]Alloc error (%d bytes) !\0A\00"
@.str.4 = [58 x i8] c" [BIN ]Compressed size = %d bytes (input size * %f %%)\0A\00"
define void @zero_bin_read(i8* %0, i8** %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64* %2, i64** %6
store i8* null, i8** %9
store i8* null, i8** %10
%12 = load i8**, i8*** %5
store i8* null, i8** %12
%13 = load i64*, i64** %6
store i64 0, i64* %13
%14 = load i8*, i8** %4
%15 = call i32 @fopen_s(i32** %11, i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = load i32*, i32** %11
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %79
21: ; preds = %3
%22 = load i32*, i32** %11
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %11
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %8
%27 = load i32*, i32** %11
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 0, i32 %28)
%30 = load i64, i64* %8
%31 = call i64 @malloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = icmp ne i8* %33, null
br i1 %34, label %40, label %35
35: ; preds = %21
%36 = load i32*, i32** %11
%37 = call i32 @fclose(i32* %36)
store i32* null, i32** %11
%38 = load i64, i64* %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %38)
br label %79
40: ; preds = %21
%41 = load i8*, i8** %9
%42 = load i64, i64* %8
%43 = load i32*, i32** %11
%44 = call i32 @fread(i8* %41, i32 1, i64 %42, i32* %43)
%45 = load i32*, i32** %11
%46 = call i32 @fclose(i32* %45)
store i32* null, i32** %11
%47 = load i64, i64* %8
%48 = add i64 %47, 5
%49 = call i64 @malloc(i64 %48)
%50 = inttoptr i64 %49 to i8*
store i8* %50, i8** %10
%51 = load i8*, i8** %10
%52 = icmp ne i8* %51, null
br i1 %52, label %59, label %53
53: ; preds = %40
%54 = load i8*, i8** %9
%55 = call i32 @free(i8* %54)
store i8* null, i8** %9
%56 = load i64, i64* %8
%57 = add i64 %56, 5
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %57)
br label %79
59: ; preds = %40
%60 = load i8*, i8** %9
%61 = load i64, i64* %8
%62 = load i8*, i8** %10
%63 = call i64 @comp_exec(i8* %60, i64 %61, i8* %62)
store i64 %63, i64* %7
%64 = load i64, i64* %7
%65 = load i64, i64* %7
%66 = mul i64 100, %65
%67 = uitofp i64 %66 to float
%68 = load i64, i64* %8
%69 = uitofp i64 %68 to float
%70 = fdiv float %67, %69
%71 = fpext float %70 to double
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i64 %64, double %71)
%73 = load i8*, i8** %9
%74 = call i32 @free(i8* %73)
store i8* null, i8** %9
%75 = load i8*, i8** %10
%76 = load i8**, i8*** %5
store i8* %75, i8** %76
%77 = load i64, i64* %7
%78 = load i64*, i64** %6
store i64 %77, i64* %78
br label %79
79: ; preds = %59, %53, %35, %18
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [43 x i8] c" [BIN ]Error : could't open file (%s) !\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [37 x i8] c" [BIN ]Alloc error (%d bytes) !\0A\00"
@.str.3 = [37 x i8] c" [BIN ]Alloc error (%d bytes) !\0A\00"
@.str.4 = [58 x i8] c" [BIN ]Compressed size = %d bytes (input size * %f %%)\0A\00"
define void @zero_bin_read(i8* %0, i8** nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca i32*
%5 = bitcast i32** %4 to i8*
store i8* null, i8** %1
store i64 0, i64* %2
%6 = call i32 @fopen_s(i32** %4, i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %46
11: ; preds = %3
%12 = load i32, i32* @SEEK_END
%13 = call i32 @fseek(i32* %7, i32 0, i32 %12)
%14 = load i32*, i32** %4
%15 = call i64 @ftell(i32* %14)
%16 = load i32*, i32** %4
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = call i64 @malloc(i64 %15)
%20 = inttoptr i64 %19 to i8*
%21 = icmp eq i64 %19, 0
%22 = load i32*, i32** %4
br i1 %21, label %23, label %26
23: ; preds = %11
%24 = call i32 @fclose(i32* %22)
store i32* null, i32** %4
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %15)
br label %46
26: ; preds = %11
%27 = call i32 @fread(i8* %20, i32 1, i64 %15, i32* %22)
%28 = load i32*, i32** %4
%29 = call i32 @fclose(i32* %28)
store i32* null, i32** %4
%30 = add i64 %15, 5
%31 = call i64 @malloc(i64 %30)
%32 = inttoptr i64 %31 to i8*
%33 = icmp eq i64 %31, 0
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = call i32 @free(i8* %20)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i64 %30)
br label %46
37: ; preds = %26
%38 = call i64 @comp_exec(i8* %20, i64 %15, i8* %32)
%39 = mul i64 %38, 100
%40 = uitofp i64 %39 to float
%41 = uitofp i64 %15 to float
%42 = fdiv float %40, %41
%43 = fpext float %42 to double
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i64 %38, double %43)
%45 = call i32 @free(i8* %20)
store i8* %32, i8** %1
store i64 %38, i64* %2
br label %46
46: ; preds = %37, %34, %23, %9
ret void
}