#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;
int base64_decode(char *, char *);
int /*<<< orphan*/ base64_encode(char *, char *, unsigned long);
int compress2(char *, unsigned long *, char *, unsigned long, int);
unsigned long compressBound(unsigned long);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
char *malloc(unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ uncompress(char *, unsigned long *, char *, int);
int main() {
  FILE *in = fopen("./test.txt", "r");
  unsigned long size = 0;
  fseek(in, 0, SEEK_SET);
  fseek(in, 0, SEEK_END);
  size = ftell(in);
  fseek(in, 0, SEEK_SET);
  ;
  char *read = malloc(size + 1);
  fread(read, 1, size, in);
  unsigned long bufLen = compressBound(size);
  unsigned long dstLen = size;
  char *buf = malloc(bufLen);
  ;
  char *dst = malloc(size + 1);
  printf("Src string:%s\nLength:%ld\n", read, size);
  int ret = compress2(buf, &bufLen, read, size, 9);
  printf("After Compressed Length:%ld\n", bufLen);
  char *base64 = malloc(size);
  base64_encode(buf, base64, bufLen);
  printf("base64 length:%d", strlen(base64));
  char *base64_decode_str = malloc(size + 1);
  int size_decode = base64_decode(base64, base64_decode_str);
  printf("decode length:%d", size_decode);
  uncompress(dst, &dstLen, base64_decode_str, size_decode);
  printf("After UnCompressed Length:%ld\n", dstLen);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2a(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1070 <compressBound@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x28(%rbp),%rsi
mov    $0x9,%r8d
call   10c0 <compress2@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   10a0 <base64_encode@plt>
mov    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   10e0 <base64_decode@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%esi
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    -0x5c(%rbp),%ecx
lea    -0x30(%rbp),%rsi
call   1040 <uncompress@plt>
mov    -0x30(%rbp),%rsi
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe2b(%rip),%rdi
lea    0xe2f(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
mov    0x2ded(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r12
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
lea    0x1(%r12),%r15
mov    %r15,%rdi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r12,%rdi
call   1070 <compressBound@plt>
mov    %rax,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %rax,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xd98(%rip),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    $0x9,%r8d
call   10c0 <compress2@plt>
mov    0x8(%rsp),%rsi
lea    0xd80(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdx
mov    %rbp,%rdi
mov    %rax,%rsi
call   10a0 <base64_encode@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xd6c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   10e0 <base64_decode@plt>
mov    %eax,%ebx
lea    0xd55(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    %rbp,%rdx
mov    %ebx,%ecx
call   1040 <uncompress@plt>
mov    0x10(%rsp),%rsi
lea    0xd3f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"./test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@SEEK_END = global i32 0
@.str.2 = [26 x i8] c"Src string:%s\0ALength:%ld\0A\00"
@.str.3 = [29 x i8] c"After Compressed Length:%ld\0A\00"
@.str.4 = [17 x i8] c"base64 length:%d\00"
@.str.5 = [17 x i8] c"decode length:%d\00"
@.str.6 = [31 x i8] c"After UnCompressed Length:%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %2
store i64 0, i64* %3
%14 = load i32*, i32** %2
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %2
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i32 0, i32 %18)
%20 = load i32*, i32** %2
%21 = call i64 @ftell(i32* %20)
store i64 %21, i64* %3
%22 = load i32*, i32** %2
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i64, i64* %3
%26 = add i64 %25, 1
%27 = call i8* @malloc(i64 %26)
store i8* %27, i8** %4
%28 = load i8*, i8** %4
%29 = load i64, i64* %3
%30 = load i32*, i32** %2
%31 = call i32 @fread(i8* %28, i32 1, i64 %29, i32* %30)
%32 = load i64, i64* %3
%33 = call i64 @compressBound(i64 %32)
store i64 %33, i64* %5
%34 = load i64, i64* %3
store i64 %34, i64* %6
%35 = load i64, i64* %5
%36 = call i8* @malloc(i64 %35)
store i8* %36, i8** %7
%37 = load i64, i64* %3
%38 = add i64 %37, 1
%39 = call i8* @malloc(i64 %38)
store i8* %39, i8** %8
%40 = load i8*, i8** %4
%41 = load i64, i64* %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %40, i64 %41)
%43 = load i8*, i8** %7
%44 = load i8*, i8** %4
%45 = load i64, i64* %3
%46 = call i32 @compress2(i8* %43, i64* %5, i8* %44, i64 %45, i32 9)
store i32 %46, i32* %9
%47 = load i64, i64* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %47)
%49 = load i64, i64* %3
%50 = call i8* @malloc(i64 %49)
store i8* %50, i8** %10
%51 = load i8*, i8** %7
%52 = load i8*, i8** %10
%53 = load i64, i64* %5
%54 = call i32 @base64_encode(i8* %51, i8* %52, i64 %53)
%55 = load i8*, i8** %10
%56 = call i32 @strlen(i8* %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = load i64, i64* %3
%59 = add i64 %58, 1
%60 = call i8* @malloc(i64 %59)
store i8* %60, i8** %11
%61 = load i8*, i8** %10
%62 = load i8*, i8** %11
%63 = call i32 @base64_decode(i8* %61, i8* %62)
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %64)
%66 = load i8*, i8** %8
%67 = load i8*, i8** %11
%68 = load i32, i32* %12
%69 = call i32 @uncompress(i8* %66, i64* %6, i8* %67, i32 %68)
%70 = load i64, i64* %6
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i64 %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"./test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@SEEK_END = global i32 0
@.str.2 = [26 x i8] c"Src string:%s\0ALength:%ld\0A\00"
@.str.3 = [29 x i8] c"After Compressed Length:%ld\0A\00"
@.str.4 = [17 x i8] c"base64 length:%d\00"
@.str.5 = [17 x i8] c"decode length:%d\00"
@.str.6 = [31 x i8] c"After UnCompressed Length:%ld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @SEEK_SET
%5 = tail call i32 @fseek(i32* %3, i32 0, i32 %4)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %3, i32 0, i32 %6)
%8 = tail call i64 @ftell(i32* %3)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %3, i32 0, i32 %9)
%11 = add i64 %8, 1
%12 = tail call i8* @malloc(i64 %11)
%13 = tail call i32 @fread(i8* %12, i32 1, i64 %8, i32* %3)
%14 = bitcast i64* %1 to i8*
%15 = tail call i64 @compressBound(i64 %8)
store i64 %15, i64* %1
%16 = bitcast i64* %2 to i8*
store i64 %8, i64* %2
%17 = tail call i8* @malloc(i64 %15)
%18 = tail call i8* @malloc(i64 %11)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %12, i64 %8)
%20 = call i32 @compress2(i8* %17, i64* %1, i8* %12, i64 %8, i32 9)
%21 = load i64, i64* %1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %21)
%23 = call i8* @malloc(i64 %8)
%24 = load i64, i64* %1
%25 = call i32 @base64_encode(i8* %17, i8* %23, i64 %24)
%26 = call i32 @strlen(i8* %23)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = call i8* @malloc(i64 %11)
%29 = call i32 @base64_decode(i8* %23, i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = call i32 @uncompress(i8* %18, i64* %2, i8* %28, i32 %29)
%32 = load i64, i64* %2
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i64 %32)
ret i32 0
}