#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int compress(char *infile, char *outfile, int **codebook, int *mapping) {
  FILE *infptr = fopen(infile, "r");
  if (infptr == NULL) {
    return 0;
  }
  FILE *outfptr = fopen(outfile, "a");
  if (outfptr == NULL) {
    fclose(outfptr);
    return 0;
  }
  while (!feof(infptr)) {
    int onechar = fgetc(infptr);
    if (onechar != EOF) {
      int ind = mapping[onechar];
      int ind2 = 1;
      while (codebook[ind][ind2] != -1) {
        fprintf(outfptr, "%d", codebook[ind][ind2]);
        ind2++;
      }
    }
  }
  fclose(infptr);
  fclose(outfptr);
  return 1;
}


x86 assembly (clang, -O0):
<compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1193 <compress+0x43>
movl   $0x0,-0x4(%rbp)
jmp    128b <compress+0x13b>
mov    -0x18(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11c7 <compress+0x77>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    128b <compress+0x13b>
jmp    11cc <compress+0x7c>
mov    -0x30(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ea <compress+0x9a>
jmp    1272 <compress+0x122>
mov    -0x30(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%eax
je     126d <compress+0x11d>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x44(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     1268 <compress+0x118>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdaf(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    121d <compress+0xcd>
jmp    126d <compress+0x11d>
jmp    11cc <compress+0x7c>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %rdx,%r12
mov    %rsi,%rbx
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b3 <compress+0x63>
mov    %rax,%r15
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b7 <compress+0x67>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11d1 <compress+0x81>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebx
jmp    11c0 <compress+0x70>
xor    %ebx,%ebx
jmp    11c0 <compress+0x70>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2c(%rip),%r13
jmp    11ec <compress+0x9c>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    119c <compress+0x4c>
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    0x2ded(%rip),%rcx
cmp    (%rcx),%eax
je     11e0 <compress+0x90>
cltq
mov    (%rsp),%rcx
movslq (%rcx,%rax,4),%r14
mov    (%r12,%r14,8),%rax
mov    0x4(%rax),%edx
cmp    $0xffffffff,%edx
je     11e0 <compress+0x90>
mov    $0x8,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <fprintf@plt>
mov    (%r12,%r14,8),%rax
mov    (%rax,%rbp,1),%edx
add    $0x4,%rbp
cmp    $0xffffffff,%edx
jne    1220 <compress+0xd0>
jmp    11e0 <compress+0x90>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"a\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @compress(i8* %0, i8* %1, i32** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32**
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32** %2, i32*** %8
store i32* %3, i32** %9
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %10
%17 = load i32*, i32** %10
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 0, i32* %5
br label %78
20: ; preds = %4
%21 = load i8*, i8** %7
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %11
%23 = load i32*, i32** %11
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32*, i32** %11
%27 = call i32 @fclose(i32* %26)
store i32 0, i32* %5
br label %78
28: ; preds = %20
br label %29
29: ; preds = %72, %28
%30 = load i32*, i32** %10
%31 = call i32 @feof(i32* %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br i1 %33, label %34, label %73
34: ; preds = %29
%35 = load i32*, i32** %10
%36 = call i32 @fgetc(i32* %35)
store i32 %36, i32* %12
%37 = load i32, i32* %12
%38 = load i32, i32* @EOF
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %72
40: ; preds = %34
%41 = load i32*, i32** %9
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
store i32 %45, i32* %13
store i32 1, i32* %14
br label %46
46: ; preds = %57, %40
%47 = load i32**, i32*** %8
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32*, i32** %47, i64 %49
%51 = load i32*, i32** %50
%52 = load i32, i32* %14
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
%55 = load i32, i32* %54
%56 = icmp ne i32 %55, -1
br i1 %56, label %57, label %71
57: ; preds = %46
%58 = load i32*, i32** %11
%59 = load i32**, i32*** %8
%60 = load i32, i32* %13
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32*, i32** %59, i64 %61
%63 = load i32*, i32** %62
%64 = load i32, i32* %14
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = call i32 @fprintf(i32* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %14
%70 = add nsw i32 %69, 1
store i32 %70, i32* %14
br label %46
71: ; preds = %46
br label %72
72: ; preds = %71, %34
br label %29
73: ; preds = %29
%74 = load i32*, i32** %10
%75 = call i32 @fclose(i32* %74)
%76 = load i32*, i32** %11
%77 = call i32 @fclose(i32* %76)
store i32 1, i32* %5
br label %78
78: ; preds = %73, %25, %19
%79 = load i32, i32* %5
ret i32 %79
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"a\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define i32 @compress(i8* nocapture %0, i8* nocapture %1, i32** nocapture %2, i32* nocapture %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %44, label %7
7: ; preds = %4
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @feof(i32* %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %41
13: ; preds = %7
%14 = tail call i32 @fclose(i32* null)
br label %44
15: ; preds = %10, %38
%16 = tail call i32 @fgetc(i32* %5)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %38, label %19
19: ; preds = %15
%20 = sext i32 %16 to i64
%21 = getelementptr inbounds i32, i32* %3, i64 %20
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32*, i32** %2, i64 %23
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, -1
br i1 %28, label %38, label %29
29: ; preds = %19, %29
%30 = phi i64 [ %33, %29 ], [ 1, %19 ]
%31 = phi i32 [ %36, %29 ], [ %27, %19 ]
%32 = tail call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = add nuw i64 %30, 1
%34 = load i32*, i32** %24
%35 = getelementptr inbounds i32, i32* %34, i64 %33
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %29
38: ; preds = %29, %19, %15
%39 = tail call i32 @feof(i32* %5)
%40 = icmp eq i32 %39, 0
br i1 %40, label %15, label %41
41: ; preds = %38, %10
%42 = tail call i32 @fclose(i32* %5)
%43 = tail call i32 @fclose(i32* %8)
br label %44
44: ; preds = %13, %41, %4
%45 = phi i32 [ 0, %4 ], [ 0, %13 ], [ 1, %41 ]
ret i32 %45
}