#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*/ mpz_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ gmp_fprintf(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int /*<<< orphan*/);
unsigned long mpz_fdiv_q_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
size_t mpz_inp_raw(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, size_t);
void decompress(char *file1, char *file2) {
  mpz_t data;
  mpz_init(data);
  FILE *inFile = fopen(file1, "rb");
  int base = fgetc(inFile) + 1;
  printf("Base is %i\n", base);
  char tab[base];
  for (int i = 0; i < base; i++) {
    tab[i] = fgetc(inFile);
  }
  size_t a = mpz_inp_raw(data, inFile);
  printf("%d bytes read\n", a);
  fclose(inFile);
  FILE *log = fopen("log2", "wb");
  gmp_fprintf(log, "%Zd\n", data);
  fclose(log);
  int i = 0;
  unsigned long int remainder;
  FILE *outFile = fopen(file2, "wb");
  while (mpz_cmp_ui(data, 0) > 0) {
    remainder = mpz_fdiv_q_ui(data, data, base);
    fputc(tab[remainder], outFile);
  }
  fclose(outFile);
  mpz_clear(data);
}


x86 assembly (clang, -O0):
<decompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0x8(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    125a <decompress+0xaa>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
mov    %cl,%dl
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1228 <decompress+0x78>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <mpz_inp_raw@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xd9a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd94(%rip),%rdi
lea    0xd92(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd7e(%rip),%rsi
call   10d0 <gmp_fprintf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd5b(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x68(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jle    1316 <decompress+0x166>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
call   10a0 <mpz_fdiv_q_ui@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
mov    %rcx,-0x60(%rbp)
mov    -0x60(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x68(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    12d1 <decompress+0x121>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%edi
call   10b0 <mpz_clear@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decompress>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1070 <mpz_init@plt>
lea    0xe30(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
lea    0x1(%rbx),%r12d
movslq %r12d,%rsi
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
test   %ebx,%ebx
js     1226 <decompress+0x76>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1210 <decompress+0x60>
mov    %r15,%rsi
call   1080 <mpz_inp_raw@plt>
lea    0xdda(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
lea    0xdd2(%rip),%rdi
lea    0xdd0(%rip),%r15
mov    %r15,%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xdc1(%rip),%rsi
mov    %rax,%rdi
call   10d0 <gmp_fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %esi,%esi
call   1090 <mpz_cmp_ui@plt>
test   %rax,%rax
jle    12b4 <decompress+0x104>
mov    %r12d,%edx
call   10a0 <mpz_fdiv_q_ui@plt>
movsbl 0x0(%r13,%rax,1),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
jmp    1290 <decompress+0xe0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <mpz_clear@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [12 x i8] c"Base is %i\0A\00"
@.str.2 = [15 x i8] c"%d bytes read\0A\00"
@.str.3 = [5 x i8] c"log2\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [5 x i8] c"%Zd\0A\00"
define void @decompress(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%16 = load i32, i32* %5
%17 = call i32 @mpz_init(i32 %16)
%18 = load i8*, i8** %3
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = call i32 @fgetc(i32* %20)
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%26 = load i32, i32* %7
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %8
%29 = alloca i8, i64 %27
store i64 %27, i64* %9
store i32 0, i32* %10
br label %30
30: ; preds = %41, %2
%31 = load i32, i32* %10
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = load i32*, i32** %6
%36 = call i32 @fgetc(i32* %35)
%37 = trunc i32 %36 to i8
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %29, i64 %39
store i8 %37, i8* %40
br label %41
41: ; preds = %34
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %30
44: ; preds = %30
%45 = load i32, i32* %5
%46 = load i32*, i32** %6
%47 = call i64 @mpz_inp_raw(i32 %45, i32* %46)
store i64 %47, i64* %11
%48 = load i64, i64* %11
%49 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %48)
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
%52 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %52, i32** %12
%53 = load i32*, i32** %12
%54 = load i32, i32* %5
%55 = call i32 @gmp_fprintf(i32* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %54)
%56 = load i32*, i32** %12
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %13
%58 = load i8*, i8** %4
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %59, i32** %15
br label %60
60: ; preds = %64, %44
%61 = load i32, i32* %5
%62 = call i64 @mpz_cmp_ui(i32 %61, i32 0)
%63 = icmp sgt i64 %62, 0
br i1 %63, label %64, label %74
64: ; preds = %60
%65 = load i32, i32* %5
%66 = load i32, i32* %5
%67 = load i32, i32* %7
%68 = call i64 @mpz_fdiv_q_ui(i32 %65, i32 %66, i32 %67)
store i64 %68, i64* %14
%69 = load i64, i64* %14
%70 = getelementptr inbounds i8, i8* %29, i64 %69
%71 = load i8, i8* %70
%72 = load i32*, i32** %15
%73 = call i32 @fputc(i8 signext %71, i32* %72)
br label %60
74: ; preds = %60
%75 = load i32*, i32** %15
%76 = call i32 @fclose(i32* %75)
%77 = load i32, i32* %5
%78 = call i32 @mpz_clear(i32 %77)
%79 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [12 x i8] c"Base is %i\0A\00"
@.str.2 = [15 x i8] c"%d bytes read\0A\00"
@.str.3 = [5 x i8] c"log2\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [5 x i8] c"%Zd\0A\00"
define void @decompress(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @fgetc(i32* %4)
%6 = add i32 %5, 1
%7 = sext i32 %6 to i64
%8 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%9 = zext i32 %6 to i64
%10 = alloca i8, i64 %9
%11 = icmp slt i32 %5, 0
br i1 %11, label %12, label %22
12: ; preds = %22, %2
%13 = tail call i64 @mpz_inp_raw(i32 undef, i32* %4)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i64 %13)
%15 = tail call i32 @fclose(i32* %4)
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = tail call i32 @gmp_fprintf(i32* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 undef)
%18 = tail call i32 @fclose(i32* %16)
%19 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %29, label %36
22: ; preds = %2, %22
%23 = phi i64 [ %27, %22 ], [ 0, %2 ]
%24 = tail call i32 @fgetc(i32* %4)
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds i8, i8* %10, i64 %23
store i8 %25, i8* %26
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %12, label %22
29: ; preds = %12, %29
%30 = tail call i64 @mpz_fdiv_q_ui(i32 undef, i32 undef, i32 %6)
%31 = getelementptr inbounds i8, i8* %10, i64 %30
%32 = load i8, i8* %31
%33 = tail call i32 @fputc(i8 signext %32, i32* %19)
%34 = tail call i64 @mpz_cmp_ui(i32 undef, i32 0)
%35 = icmp sgt i64 %34, 0
br i1 %35, label %29, label %36
36: ; preds = %29, %12
%37 = tail call i32 @fclose(i32* %19)
%38 = tail call i32 @mpz_clear(i32 undef)
ret void
}