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

/* Variables and functions */
int compute_sum(int *);
int /*<<< orphan*/ encode_frame(int *, int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ init_interleave();
int /*<<< orphan*/ init_rand();
int /*<<< orphan*/ init_rs();
int /*<<< orphan*/ init_trellis();
int *malloc(int);
int /*<<< orphan*/ repack_bytes(int *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ trellis_code(int *, int *);
int main(int argc, char *argv[]) {
  FILE *fin, *fout;
  uint8_t *bytes, *chunk_repacked, *chunk_encoded;
  uint8_t sync_byte;
  uint8_t trellis_symbols[5];
  int i;
  if (argc != 3) {
    fprintf(stderr, "Usage: qam-steps input_file output_file\n");
    exit(1);
  }
  fin = fopen(argv[1], "rb");
  if (fin == NULL) {
    fprintf(stderr, "Error: Could not read input file\n");
    exit(1);
  }
  fout = fopen(argv[2], "wb");
  if (fout == NULL) {
    fprintf(stderr, "Error: Could not write output file\n");
    fclose(fin);
    exit(1);
  }
  bytes = malloc(sizeof(uint8_t) * ((188 * 6405) + 1));
  if (bytes == NULL) {
    fprintf(stderr, "Error: Out of memory.\n");
    fclose(fin);
    fclose(fout);
    exit(1);
  }
  chunk_repacked = malloc(sizeof(uint8_t) * ((188 * 6405) * 8 / 7));
  if (chunk_repacked == NULL) {
    fprintf(stderr, "Error: Out of memory.\n");
    free(bytes);
    fclose(fin);
    fclose(fout);
    exit(1);
  }
  chunk_encoded = malloc(sizeof(uint8_t) *
                         ((188 * 6405) * 8 / 7 / 60 / 122 * (60 * 128 + 6)));
  if (chunk_encoded == NULL) {
    fprintf(stderr, "Error: Out of memory.\n");
    free(bytes);
    free(chunk_repacked);
    fclose(fin);
    fclose(fout);
    exit(1);
  }
  init_rand();
  init_rs();
  init_interleave();
  init_trellis();
  while ((188 * 6405) == fread(bytes, sizeof(uint8_t), (188 * 6405), fin)) {
    sync_byte = bytes[0];
    for (i = 0; i < (188 * 6405); i += 188) {
      if (sync_byte != 0x47) {
        fprintf(stderr, "Error: MPEG packet didn't begin with 0x47\n");
        free(bytes);
        free(chunk_repacked);
        free(chunk_encoded);
        fclose(fin);
        fclose(fout);
        exit(1);
      }
      sync_byte = bytes[i + 188];
      bytes[i + 188] = compute_sum(bytes + (i + 1));
    }
    for (i = 0; i < (188 * 6405) / 7; i++) {
      repack_bytes(bytes + 1 + (i * 7), chunk_repacked + (i * 8));
    }
    for (i = 0; i < 188; i++) {
      encode_frame(chunk_repacked + i * 60 * 122,
                   chunk_encoded + i * (60 * 128 + 6));
    }
    for (i = 0; i < ((188 * 6405) * 8 / 7 / 60 / 122 * (60 * 128 + 6));
         i += 4) {
      trellis_code(chunk_encoded + i, trellis_symbols);
      fwrite(trellis_symbols, sizeof(uint8_t), 5, fout);
    }
  }
  free(bytes);
  free(chunk_repacked);
  free(chunk_encoded);
  fclose(fin);
  fclose(fout);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     123f <main+0x3f>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddb(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1281 <main+0x81>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdbe(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12cc <main+0xcc>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    $0x497eb4,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1316 <main+0x116>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    $0x53fe80,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1369 <main+0x169>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    $0x5831a0,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    13c5 <main+0x1c5>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    0xce3(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    $0x0,%al
call   10f0 <init_rand@plt>
mov    $0x0,%al
call   10c0 <init_rs@plt>
mov    $0x0,%al
call   10a0 <init_interleave@plt>
mov    $0x0,%al
call   1050 <init_trellis@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x125fac,%edx
call   1040 <fread@plt>
mov    %eax,%ecx
mov    $0x125fac,%eax
cmp    %ecx,%eax
jne    15c1 <main+0x3c1>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x125fac,-0x54(%rbp)
jge    14cd <main+0x2cd>
cmpl   $0x47,-0x3c(%rbp)
je     147a <main+0x27a>
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
lea    0xc4e(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x28(%rbp),%rax
mov    -0x54(%rbp),%ecx
add    $0xbc,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x54(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1080 <compute_sum@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    -0x54(%rbp),%ecx
add    $0xbc,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x54(%rbp),%eax
add    $0xbc,%eax
mov    %eax,-0x54(%rbp)
jmp    1417 <main+0x217>
movl   $0x0,-0x54(%rbp)
cmpl   $0x29ff4,-0x54(%rbp)
jge    151c <main+0x31c>
mov    -0x28(%rbp),%rdi
add    $0x4,%rdi
imul   $0x7,-0x54(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x54(%rbp),%eax
shl    $0x3,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1100 <repack_bytes@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    14d4 <main+0x2d4>
movl   $0x0,-0x54(%rbp)
cmpl   $0xbc,-0x54(%rbp)
jge    156b <main+0x36b>
mov    -0x30(%rbp),%rdi
imul   $0x3c,-0x54(%rbp),%eax
imul   $0x7a,%eax,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%rsi
imul   $0x1e06,-0x54(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   1070 <encode_frame@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1523 <main+0x323>
movl   $0x0,-0x54(%rbp)
cmpl   $0x160c68,-0x54(%rbp)
jge    15bc <main+0x3bc>
mov    -0x38(%rbp),%rdi
movslq -0x54(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
call   1090 <trellis_code@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x5,%edx
call   1120 <fwrite@plt>
mov    -0x54(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x54(%rbp)
jmp    1572 <main+0x372>
jmp    13e1 <main+0x1e1>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x4(%rbp),%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    $0x38,%rsp
cmp    $0x3,%edi
jne    147a <main+0x27a>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe04(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     148c <main+0x28c>
mov    0x10(%rbx),%rdi
lea    0xe0c(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     14ab <main+0x2ab>
mov    %rax,%r14
mov    $0x497eb4,%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     14c6 <main+0x2c6>
mov    %rax,%r15
mov    $0x53fe80,%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     14dd <main+0x2dd>
mov    %rax,%r12
mov    $0x5831a0,%edi
call   10d0 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     14f7 <main+0x2f7>
xor    %eax,%eax
call   10f0 <init_rand@plt>
xor    %eax,%eax
call   10c0 <init_rs@plt>
xor    %eax,%eax
call   10a0 <init_interleave@plt>
xor    %eax,%eax
call   1050 <init_trellis@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x125fac,%edx
mov    (%rsp),%rcx
call   1040 <fread@plt>
cmp    $0x125fac,%eax
jne    13f2 <main+0x1f2>
lea    0x4(%r15),%rax
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%r13
mov    %r14,0x10(%rsp)
nopw   0x0(%rax,%rax,1)
mov    (%r15),%ebx
mov    $0xffffffffffffff44,%rbp
mov    0x18(%rsp),%r14
nop
cmp    $0x47,%ebx
jne    142e <main+0x22e>
mov    0x5e0(%r15,%rbp,4),%ebx
mov    %r14,%rdi
call   1080 <compute_sum@plt>
mov    %eax,0x5e0(%r15,%rbp,4)
add    $0xbc,%rbp
add    $0x2f0,%r14
cmp    $0x125ef0,%rbp
jb     1300 <main+0x100>
mov    $0x4,%ebx
mov    %r12,%rbp
lea    (%r15,%rbx,1),%rdi
mov    %rbp,%rsi
call   1100 <repack_bytes@plt>
add    $0x1c,%rbx
add    $0x20,%rbp
cmp    $0x497eb4,%rbx
jne    1340 <main+0x140>
xor    %ebx,%ebx
mov    0x8(%rsp),%rbp
mov    0x10(%rsp),%r14
nopl   0x0(%rax)
lea    (%r12,%rbx,1),%rdi
mov    %rbp,%rsi
call   1070 <encode_frame@plt>
add    $0x7818,%rbp
add    $0x7260,%rbx
cmp    $0x53fe80,%rbx
jne    1370 <main+0x170>
mov    $0xfffffffffffffffc,%rbx
mov    0x8(%rsp),%rbp
nop
mov    %rbp,%rdi
mov    %r13,%rsi
call   1090 <trellis_code@plt>
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x5,%edx
mov    %r14,%rcx
call   1120 <fwrite@plt>
add    $0x4,%rbx
add    $0x10,%rbp
cmp    $0x160c64,%rbx
jb     13a0 <main+0x1a0>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x125fac,%edx
mov    (%rsp),%rcx
call   1040 <fread@plt>
cmp    $0x125fac,%eax
je     12f0 <main+0xf0>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
lea    0xc4e(%rip),%rsi
call   10b0 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1060 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1060 <fclose@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2b5f(%rip),%rax
mov    (%rax),%edi
lea    0xb76(%rip),%rsi
jmp    149c <main+0x29c>
mov    0x2b4d(%rip),%rax
mov    (%rax),%edi
lea    0xb90(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
lea    0xb96(%rip),%rsi
call   10b0 <fprintf@plt>
mov    (%rsp),%rdi
jmp    146b <main+0x26b>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
lea    0xb9f(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    151c <main+0x31c>
mov    0x2afc(%rip),%rax
mov    (%rax),%edi
lea    0xb88(%rip),%rsi
call   10b0 <fprintf@plt>
mov    %r15,%rdi
jmp    1517 <main+0x317>
mov    0x2ae2(%rip),%rax
mov    (%rax),%edi
lea    0xb6e(%rip),%rsi
call   10b0 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
jmp    146b <main+0x26b>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: qam-steps input_file output_file\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [34 x i8] c"Error: Could not read input file\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [36 x i8] c"Error: Could not write output file\0A\00"
@.str.5 = [23 x i8] c"Error: Out of memory.\0A\00"
@.str.6 = [43 x i8] c"Error: MPEG packet didn't begin with 0x47\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [5 x i32]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 3
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %20
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %7
%36 = load i32*, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %31
%45 = call i32* @malloc(i32 4816564)
store i32* %45, i32** %8
%46 = load i32*, i32** %8
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %44
%57 = call i32* @malloc(i32 5504640)
store i32* %57, i32** %9
%58 = load i32*, i32** %9
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %70
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%63 = load i32*, i32** %8
%64 = call i32 @free(i32* %63)
%65 = load i32*, i32** %6
%66 = call i32 @fclose(i32* %65)
%67 = load i32*, i32** %7
%68 = call i32 @fclose(i32* %67)
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %56
%71 = call i32* @malloc(i32 5779872)
store i32* %71, i32** %10
%72 = load i32*, i32** %10
%73 = icmp eq i32* %72, null
br i1 %73, label %74, label %86
74: ; preds = %70
%75 = load i32, i32* @stderr
%76 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32*, i32** %8
%78 = call i32 @free(i32* %77)
%79 = load i32*, i32** %9
%80 = call i32 @free(i32* %79)
%81 = load i32*, i32** %6
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %70
%87 = call i32 (...) @init_rand()
%88 = call i32 (...) @init_rs()
%89 = call i32 (...) @init_interleave()
%90 = call i32 (...) @init_trellis()
br label %91
91: ; preds = %198, %86
%92 = load i32*, i32** %8
%93 = load i32*, i32** %6
%94 = call i32 @fread(i32* %92, i32 4, i32 1204140, i32* %93)
%95 = icmp eq i32 1204140, %94
br i1 %95, label %96, label %199
96: ; preds = %91
%97 = load i32*, i32** %8
%98 = getelementptr inbounds i32, i32* %97, i64 0
%99 = load i32, i32* %98
store i32 %99, i32* %11
store i32 0, i32* %13
br label %100
100: ; preds = %138, %96
%101 = load i32, i32* %13
%102 = icmp slt i32 %101, 1204140
br i1 %102, label %103, label %141
103: ; preds = %100
%104 = load i32, i32* %11
%105 = icmp ne i32 %104, 71
br i1 %105, label %106, label %120
106: ; preds = %103
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
%109 = load i32*, i32** %8
%110 = call i32 @free(i32* %109)
%111 = load i32*, i32** %9
%112 = call i32 @free(i32* %111)
%113 = load i32*, i32** %10
%114 = call i32 @free(i32* %113)
%115 = load i32*, i32** %6
%116 = call i32 @fclose(i32* %115)
%117 = load i32*, i32** %7
%118 = call i32 @fclose(i32* %117)
%119 = call i32 @exit(i32 1)
unreachable
120: ; preds = %103
%121 = load i32*, i32** %8
%122 = load i32, i32* %13
%123 = add nsw i32 %122, 188
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i32, i32* %121, i64 %124
%126 = load i32, i32* %125
store i32 %126, i32* %11
%127 = load i32*, i32** %8
%128 = load i32, i32* %13
%129 = add nsw i32 %128, 1
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i32, i32* %127, i64 %130
%132 = call i32 @compute_sum(i32* %131)
%133 = load i32*, i32** %8
%134 = load i32, i32* %13
%135 = add nsw i32 %134, 188
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i32, i32* %133, i64 %136
store i32 %132, i32* %137
br label %138
138: ; preds = %120
%139 = load i32, i32* %13
%140 = add nsw i32 %139, 188
store i32 %140, i32* %13
br label %100
141: ; preds = %100
store i32 0, i32* %13
br label %142
142: ; preds = %158, %141
%143 = load i32, i32* %13
%144 = icmp slt i32 %143, 172020
br i1 %144, label %145, label %161
145: ; preds = %142
%146 = load i32*, i32** %8
%147 = getelementptr inbounds i32, i32* %146, i64 1
%148 = load i32, i32* %13
%149 = mul nsw i32 %148, 7
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i32, i32* %147, i64 %150
%152 = load i32*, i32** %9
%153 = load i32, i32* %13
%154 = mul nsw i32 %153, 8
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i32, i32* %152, i64 %155
%157 = call i32 @repack_bytes(i32* %151, i32* %156)
br label %158
158: ; preds = %145
%159 = load i32, i32* %13
%160 = add nsw i32 %159, 1
store i32 %160, i32* %13
br label %142
161: ; preds = %142
store i32 0, i32* %13
br label %162
162: ; preds = %178, %161
%163 = load i32, i32* %13
%164 = icmp slt i32 %163, 188
br i1 %164, label %165, label %181
165: ; preds = %162
%166 = load i32*, i32** %9
%167 = load i32, i32* %13
%168 = mul nsw i32 %167, 60
%169 = mul nsw i32 %168, 122
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds i32, i32* %166, i64 %170
%172 = load i32*, i32** %10
%173 = load i32, i32* %13
%174 = mul nsw i32 %173, 7686
%175 = sext i32 %174 to i64
%176 = getelementptr inbounds i32, i32* %172, i64 %175
%177 = call i32 @encode_frame(i32* %171, i32* %176)
br label %178
178: ; preds = %165
%179 = load i32, i32* %13
%180 = add nsw i32 %179, 1
store i32 %180, i32* %13
br label %162
181: ; preds = %162
store i32 0, i32* %13
br label %182
182: ; preds = %195, %181
%183 = load i32, i32* %13
%184 = icmp slt i32 %183, 1444968
br i1 %184, label %185, label %198
185: ; preds = %182
%186 = load i32*, i32** %10
%187 = load i32, i32* %13
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i32, i32* %186, i64 %188
%190 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%191 = call i32 @trellis_code(i32* %189, i32* %190)
%192 = getelementptr inbounds [5 x i32], [5 x i32]* %12, i64 0, i64 0
%193 = load i32*, i32** %7
%194 = call i32 @fwrite(i32* %192, i32 4, i32 5, i32* %193)
br label %195
195: ; preds = %185
%196 = load i32, i32* %13
%197 = add nsw i32 %196, 4
store i32 %197, i32* %13
br label %182
198: ; preds = %182
br label %91
199: ; preds = %91
%200 = load i32*, i32** %8
%201 = call i32 @free(i32* %200)
%202 = load i32*, i32** %9
%203 = call i32 @free(i32* %202)
%204 = load i32*, i32** %10
%205 = call i32 @free(i32* %204)
%206 = load i32*, i32** %6
%207 = call i32 @fclose(i32* %206)
%208 = load i32*, i32** %7
%209 = call i32 @fclose(i32* %208)
%210 = load i32, i32* %3
ret i32 %210
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [41 x i8] c"Usage: qam-steps input_file output_file\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [34 x i8] c"Error: Could not read input file\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [36 x i8] c"Error: Could not write output file\0A\00"
@.str.5 = [23 x i8] c"Error: Out of memory.\0A\00"
@.str.6 = [43 x i8] c"Error: MPEG packet didn't begin with 0x47\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i32]
%4 = bitcast [5 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%27 = tail call i32 @fclose(i32* %13)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %19
%30 = tail call i32* @malloc(i32 4816564)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%35 = tail call i32 @fclose(i32* %13)
%36 = tail call i32 @fclose(i32* %22)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %29
%39 = tail call i32* @malloc(i32 5504640)
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = tail call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%44 = tail call i32 @free(i32* %30)
%45 = tail call i32 @fclose(i32* %13)
%46 = tail call i32 @fclose(i32* %22)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = tail call i32* @malloc(i32 5779872)
%50 = icmp eq i32* %49, null
br i1 %50, label %51, label %59
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = tail call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%54 = tail call i32 @free(i32* %30)
%55 = tail call i32 @free(i32* %39)
%56 = tail call i32 @fclose(i32* %13)
%57 = tail call i32 @fclose(i32* %22)
%58 = tail call i32 @exit(i32 1)
unreachable
59: ; preds = %48
%60 = tail call i32 (...) @init_rand()
%61 = tail call i32 (...) @init_rs()
%62 = tail call i32 (...) @init_interleave()
%63 = tail call i32 (...) @init_trellis()
%64 = call i32 @fread(i32* %30, i32 4, i32 1204140, i32* %13)
%65 = icmp eq i32 %64, 1204140
br i1 %65, label %66, label %120
66: ; preds = %59
%67 = getelementptr inbounds i32, i32* %30, i64 1
%68 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 0
br label %72
69: ; preds = %113
%70 = call i32 @fread(i32* %30, i32 4, i32 1204140, i32* %13)
%71 = icmp eq i32 %70, 1204140
br i1 %71, label %72, label %120
72: ; preds = %66, %69
%73 = load i32, i32* %30
br label %74
74: ; preds = %72, %87
%75 = phi i64 [ 0, %72 ], [ %88, %87 ]
%76 = phi i32 [ %73, %72 ], [ %90, %87 ]
%77 = icmp eq i32 %76, 71
br i1 %77, label %87, label %78
78: ; preds = %74
%79 = load i32, i32* @stderr
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
%81 = call i32 @free(i32* %30)
%82 = call i32 @free(i32* %39)
%83 = call i32 @free(i32* %49)
%84 = call i32 @fclose(i32* %13)
%85 = call i32 @fclose(i32* %22)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %74
%88 = add nuw nsw i64 %75, 188
%89 = getelementptr inbounds i32, i32* %30, i64 %88
%90 = load i32, i32* %89
%91 = or i64 %75, 1
%92 = getelementptr inbounds i32, i32* %30, i64 %91
%93 = call i32 @compute_sum(i32* %92)
store i32 %93, i32* %89
%94 = icmp ult i64 %75, 1203952
br i1 %94, label %74, label %95
95: ; preds = %87, %95
%96 = phi i64 [ %102, %95 ], [ 0, %87 ]
%97 = mul nuw nsw i64 %96, 7
%98 = getelementptr inbounds i32, i32* %67, i64 %97
%99 = shl nuw nsw i64 %96, 3
%100 = getelementptr inbounds i32, i32* %39, i64 %99
%101 = call i32 @repack_bytes(i32* %98, i32* %100)
%102 = add nuw nsw i64 %96, 1
%103 = icmp eq i64 %102, 172020
br i1 %103, label %104, label %95
104: ; preds = %95, %104
%105 = phi i64 [ %111, %104 ], [ 0, %95 ]
%106 = mul nuw nsw i64 %105, 7320
%107 = getelementptr inbounds i32, i32* %39, i64 %106
%108 = mul nuw nsw i64 %105, 7686
%109 = getelementptr inbounds i32, i32* %49, i64 %108
%110 = call i32 @encode_frame(i32* %107, i32* %109)
%111 = add nuw nsw i64 %105, 1
%112 = icmp eq i64 %111, 188
br i1 %112, label %113, label %104
113: ; preds = %104, %113
%114 = phi i64 [ %118, %113 ], [ 0, %104 ]
%115 = getelementptr inbounds i32, i32* %49, i64 %114
%116 = call i32 @trellis_code(i32* %115, i32* %68)
%117 = call i32 @fwrite(i32* %68, i32 4, i32 5, i32* %22)
%118 = add nuw nsw i64 %114, 4
%119 = icmp ult i64 %114, 1444964
br i1 %119, label %113, label %69
120: ; preds = %69, %59
%121 = call i32 @free(i32* %30)
%122 = call i32 @free(i32* %39)
%123 = call i32 @free(i32* %49)
%124 = call i32 @fclose(i32* %13)
%125 = call i32 @fclose(i32* %22)
ret i32 0
}