#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*/ padZero(int /*<<< orphan*/ *, unsigned char *,
                           unsigned char *);
int /*<<< orphan*/ writeBit(int /*<<< orphan*/ *, int, unsigned char *,
                            unsigned char *);
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;
  }
  unsigned char whichbit = 0;
  unsigned char curbyte = 0;
  while (!feof(infptr)) {
    int onechar = fgetc(infptr);
    if (onechar != EOF) {
      int ind = mapping[onechar];
      int ind2 = 1;
      while (codebook[ind][ind2] != -1) {
        writeBit(outfptr, (codebook[ind][ind2] == 1), &whichbit, &curbyte);
        ind2++;
      }
    }
  }
  padZero(outfptr, &whichbit, &curbyte);
  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    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a3 <compress+0x43>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <compress+0x159>
mov    -0x18(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d7 <compress+0x77>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b9 <compress+0x159>
movb   $0x0,-0x39(%rbp)
movb   $0x0,-0x3a(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fd <compress+0x9d>
jmp    128f <compress+0x12f>
mov    -0x30(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%eax
je     128a <compress+0x12a>
mov    -0x28(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x48(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     1285 <compress+0x125>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x48(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    -0x39(%rbp),%rdx
lea    -0x3a(%rbp),%rcx
call   1050 <writeBit@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1230 <compress+0xd0>
jmp    128a <compress+0x12a>
jmp    11df <compress+0x7f>
mov    -0x38(%rbp),%rdi
lea    -0x39(%rbp),%rsi
lea    -0x3a(%rbp),%rdx
call   1070 <padZero@plt>
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
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,%r12
mov    %rsi,%rbx
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e3 <compress+0x83>
mov    %rax,%rbp
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e7 <compress+0x87>
mov    %rax,%rbx
movb   $0x0,0x7(%rsp)
movb   $0x0,0x6(%rsp)
mov    %rbp,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1201 <compress+0xa1>
lea    0x7(%rsp),%rsi
lea    0x6(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <padZero@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%ebx
jmp    11f0 <compress+0x90>
xor    %ebx,%ebx
jmp    11f0 <compress+0x90>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <fclose@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x6(%rsp),%r13
mov    %rbp,0x10(%rsp)
jmp    1221 <compress+0xc1>
nopl   (%rax)
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11ba <compress+0x5a>
mov    %rbp,%rdi
call   1040 <fgetc@plt>
mov    0x2db8(%rip),%rcx
cmp    (%rcx),%eax
lea    0x7(%rsp),%rbp
je     1210 <compress+0xb0>
cltq
mov    0x8(%rsp),%rcx
movslq (%rcx,%rax,4),%r14
mov    (%r12,%r14,8),%rax
mov    0x4(%rax),%eax
cmp    $0xffffffff,%eax
je     1210 <compress+0xb0>
mov    $0x8,%r15d
cs nopw 0x0(%rax,%rax,1)
xor    %esi,%esi
cmp    $0x1,%eax
sete   %sil
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %r13,%rcx
call   1050 <writeBit@plt>
mov    (%r12,%r14,8),%rax
mov    (%rax,%r15,1),%eax
add    $0x4,%r15
cmp    $0xffffffff,%eax
jne    1260 <compress+0x100>
jmp    1210 <compress+0xb0>

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

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