#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*/ uint8_t;
struct timespec {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ encode_chunk(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *, int, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gen_encoding_matrix(int /*<<< orphan*/ *, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ write_metadata(int, int, int, int /*<<< orphan*/ *);
void encode_file(char *file, int nativeBlockNum, int parityBlockNum) {
  int chunkSize = 1;
  int totalSize;
  FILE *fp_in;
  FILE *fp_out;
  if ((fp_in = fopen(file, "rb")) == NULL) {
    printf("Can not open source file!\n");
    exit(0);
  }
  fseek(fp_in, 0L, SEEK_END);
  totalSize = ftell(fp_in);
  chunkSize = (totalSize / nativeBlockNum) + (totalSize % nativeBlockNum != 0);
  uint8_t *dataBuf;
  uint8_t *codeBuf;
  int dataSize = nativeBlockNum * chunkSize * sizeof(uint8_t);
  int codeSize = parityBlockNum * chunkSize * sizeof(uint8_t);
  dataBuf = (uint8_t *)malloc(nativeBlockNum * chunkSize * sizeof(uint8_t));
  memset(dataBuf, 0, dataSize);
  codeBuf = (uint8_t *)malloc(parityBlockNum * chunkSize * sizeof(uint8_t));
  memset(codeBuf, 0, codeSize);
  int i;
  for (i = 0; i < nativeBlockNum; i++) {
    if (fseek(fp_in, i * chunkSize, SEEK_SET) == -1) {
      printf("fseek error!\n");
      exit(0);
    }
    if (fread(dataBuf + i * chunkSize, sizeof(uint8_t), chunkSize, fp_in) ==
        EOF) {
      printf("fread error!\n");
      exit(0);
    }
  }
  fclose(fp_in);
  struct timespec start, end;
  double totalTime;
  clock_gettime(CLOCK_REALTIME, &start);
  uint8_t *encodingMatrix;
  encodingMatrix =
      (uint8_t *)malloc(parityBlockNum * nativeBlockNum * sizeof(uint8_t));
  gen_encoding_matrix(encodingMatrix, parityBlockNum, nativeBlockNum);
  write_metadata(totalSize, parityBlockNum, nativeBlockNum, encodingMatrix);
  encode_chunk(dataBuf, encodingMatrix, codeBuf, nativeBlockNum, parityBlockNum,
               chunkSize);
  clock_gettime(CLOCK_REALTIME, &end);
  totalTime = (double)(end.tv_sec - start.tv_sec) * 1000 +
              (double)(end.tv_nsec - start.tv_nsec) / (double)1000000L;
  printf("Total CPU encoding time: %fms\n", totalTime);
  char output_file_name[100];
  for (i = 0; i < nativeBlockNum; i++) {
    sprintf(output_file_name, "_%d_", i);
    strcat(output_file_name, file);
    if ((fp_out = fopen(output_file_name, "wb")) == NULL) {
      printf("Can not open source file!\n");
      exit(0);
    }
    if (fwrite(dataBuf + i * chunkSize, sizeof(uint8_t), chunkSize, fp_out) !=
        sizeof(uint8_t) * chunkSize) {
      printf("fwrite error!\n");
      exit(0);
    }
    fclose(fp_out);
  }
  for (i = 0; i < parityBlockNum; i++) {
    sprintf(output_file_name, "_%d_", i + nativeBlockNum);
    strcat(output_file_name, file);
    if ((fp_out = fopen(output_file_name, "wb")) == NULL) {
      printf("Can not open source file!\n");
      exit(0);
    }
    if (fwrite(codeBuf + i * chunkSize, sizeof(uint8_t), chunkSize, fp_out) !=
        sizeof(uint8_t) * chunkSize) {
      printf("fwrite error!\n");
      exit(0);
    }
    fclose(fp_out);
  }
  free(dataBuf);
  free(codeBuf);
  free(encodingMatrix);
}


x86 assembly (clang, -O0):
<encode_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    125f <encode_file+0x4f>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0xe4(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    -0xe4(%rbp),%eax
cmp    $0x0,%edx
setne  %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13bd <encode_file+0x1ad>
mov    -0x20(%rbp),%rdi
mov    -0x44(%rbp),%esi
imul   -0x14(%rbp),%esi
mov    0x2c95(%rip),%rax
mov    (%rax),%edx
call   10c0 <fseek@plt>
cmp    $0xffffffff,%eax
jne    1360 <encode_file+0x150>
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x44(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1040 <fread@plt>
mov    0x2c54(%rip),%rcx
cmp    (%rcx),%rax
jne    13aa <encode_file+0x19a>
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
jmp    13af <encode_file+0x19f>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    131d <encode_file+0x10d>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
lea    -0x58(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1130 <gen_encoding_matrix@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x78(%rbp),%rcx
call   1090 <write_metadata@plt>
mov    -0x30(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
call   10e0 <encode_chunk@plt>
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
lea    -0x68(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x60(%rbp),%rax
sub    -0x50(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    -0x68(%rbp),%rax
sub    -0x58(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  0xba7(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xb93(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
lea    0xbc4(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1560 <encode_file+0x350>
lea    -0xe0(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    0xbb8(%rip),%rsi
call   1100 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10f0 <strcat@plt>
lea    -0xe0(%rbp),%rdi
lea    0xb9a(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    14fc <encode_file+0x2ec>
lea    0xb25(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x44(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
call   1120 <fwrite@plt>
cltq
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
cmp    %rcx,%rax
je     1549 <encode_file+0x339>
lea    0xb36(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1494 <encode_file+0x284>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1636 <encode_file+0x426>
lea    -0xe0(%rbp),%rdi
mov    -0x44(%rbp),%edx
add    -0xc(%rbp),%edx
lea    0xae2(%rip),%rsi
call   1100 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10f0 <strcat@plt>
lea    -0xe0(%rbp),%rdi
lea    0xac4(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    15d2 <encode_file+0x3c2>
lea    0xa4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x44(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x4,%esi
call   1120 <fwrite@plt>
cltq
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
cmp    %rcx,%rax
je     161f <encode_file+0x40f>
lea    0xa60(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1567 <encode_file+0x357>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %edx,%ebx
mov    %esi,%r15d
lea    0xdd3(%rip),%rsi
mov    %rdi,0x38(%rsp)
call   10e0 <fopen@plt>
test   %rax,%rax
je     1565 <encode_file+0x345>
mov    %rax,%r12
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %r12,%rdi
call   10b0 <ftell@plt>
mov    %eax,0x2c(%rsp)
cltd
idiv   %r15d
mov    %eax,%r13d
cmp    $0x1,%edx
sbb    $0xffffffff,%r13d
lea    0x0(,%r15,4),%r14d
mov    %r14d,0x28(%rsp)
imul   %r13d,%r14d
mov    %ebx,0x4(%rsp)
imul   %r13d,%ebx
shl    $0x2,%ebx
mov    %r14d,%edi
call   10c0 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1090 <memset@plt>
mov    %ebx,%edi
call   10c0 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1090 <memset@plt>
mov    %r13d,(%rsp)
movslq %r13d,%rax
mov    %rax,0x10(%rsp)
mov    %r15d,%eax
mov    %rax,0x30(%rsp)
test   %r15d,%r15d
jle    135d <encode_file+0x13d>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,4),%rax
mov    %rax,0x20(%rsp)
mov    0x30(%rsp),%r13
mov    0x8(%rsp),%rbx
mov    (%rsp),%r14d
nopl   0x0(%rax)
mov    0x2cb9(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   10d0 <fseek@plt>
cmp    $0xffffffff,%eax
je     1577 <encode_file+0x357>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14d,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    0x2c9a(%rip),%rcx
cmp    (%rcx),%rax
je     1580 <encode_file+0x360>
add    0x20(%rsp),%rbx
add    %r14d,%ebp
add    $0xffffffffffffffff,%r13
jne    1310 <encode_file+0xf0>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    0x2c5c(%rip),%r14
mov    (%r14),%edi
lea    0x50(%rsp),%rsi
call   1060 <clock_gettime@plt>
mov    0x4(%rsp),%ebp
mov    0x28(%rsp),%edi
imul   %ebp,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
call   1140 <gen_encoding_matrix@plt>
mov    0x2c(%rsp),%edi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   10a0 <write_metadata@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,0x20(%rsp)
mov    %rbx,%rsi
mov    0x18(%rsp),%rdx
mov    %r15d,%ecx
mov    %ebp,%r8d
mov    (%rsp),%r9d
call   10f0 <encode_chunk@plt>
mov    (%r14),%edi
lea    0x40(%rsp),%rsi
call   1060 <clock_gettime@plt>
mov    0x40(%rsp),%rax
mov    0x48(%rsp),%rcx
sub    0x58(%rsp),%rcx
cvtsi2sd %rcx,%xmm0
sub    0x50(%rsp),%rax
cvtsi2sd %rax,%xmm1
divsd  0xc02(%rip),%xmm1
mulsd  0xc02(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xc02(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
test   %r15d,%r15d
jle    14ad <encode_file+0x28d>
mov    0x10(%rsp),%rax
lea    0x0(,%rax,4),%r14
xor    %ebp,%ebp
lea    0x60(%rsp),%r13
mov    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
lea    0xbe8(%rip),%rsi
mov    %ebp,%edx
call   1110 <sprintf@plt>
mov    %r13,%rdi
mov    0x38(%rsp),%rsi
call   1100 <strcat@plt>
mov    %r13,%rdi
lea    0xbcf(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1565 <encode_file+0x345>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0x4,%esi
mov    (%rsp),%edx
mov    %rax,%rcx
call   1130 <fwrite@plt>
cltq
cmp    %rax,%r14
jne    156e <encode_file+0x34e>
mov    %rbx,%rdi
call   1070 <fclose@plt>
add    $0x1,%rbp
add    %r14,%r12
cmp    %rbp,0x30(%rsp)
jne    1440 <encode_file+0x220>
mov    0x4(%rsp),%eax
test   %eax,%eax
mov    0x10(%rsp),%r12
jle    1535 <encode_file+0x315>
shl    $0x2,%r12
mov    %eax,%r13d
lea    0x60(%rsp),%rbp
mov    0x18(%rsp),%r14
nop
mov    %rbp,%rdi
lea    0xb58(%rip),%rsi
mov    %r15d,%edx
call   1110 <sprintf@plt>
mov    %rbp,%rdi
mov    0x38(%rsp),%rsi
call   1100 <strcat@plt>
mov    %rbp,%rdi
lea    0xb3e(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1565 <encode_file+0x345>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x4,%esi
mov    (%rsp),%edx
mov    %rax,%rcx
call   1130 <fwrite@plt>
cltq
cmp    %rax,%r12
jne    156e <encode_file+0x34e>
mov    %rbx,%rdi
call   1070 <fclose@plt>
add    $0x1,%r15d
add    %r12,%r14
add    $0xffffffffffffffff,%r13
jne    14d0 <encode_file+0x2b0>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xaf6(%rip),%rdi
jmp    1587 <encode_file+0x367>
lea    0xac5(%rip),%rdi
jmp    1587 <encode_file+0x367>
lea    0xad7(%rip),%rdi
jmp    1587 <encode_file+0x367>
lea    0xac1(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [3 x i8] c"rb\00"
@.str.1 = [27 x i8] c"Can not open source file!\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [14 x i8] c"fseek error!\0A\00"
@EOF = global i64 0
@.str.3 = [14 x i8] c"fread error!\0A\00"
@CLOCK_REALTIME = global i32 0
@.str.4 = [31 x i8] c"Total CPU encoding time: %fms\0A\00"
@.str.5 = [5 x i8] c"_%d_\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [15 x i8] c"fwrite error!\0A\00"
define void @encode_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.timespec
%17 = alloca %struct.timespec
%18 = alloca double
%19 = alloca i32*
%20 = alloca [100 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 1, i32* %7
%21 = load i8*, i8** %4
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %9
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %3
%28 = load i32*, i32** %9
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseek(i32* %28, i32 0, i32 %29)
%31 = load i32*, i32** %9
%32 = call i32 @ftell(i32* %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = load i32, i32* %5
%35 = sdiv i32 %33, %34
%36 = load i32, i32* %8
%37 = load i32, i32* %5
%38 = srem i32 %36, %37
%39 = icmp ne i32 %38, 0
%40 = zext i1 %39 to i32
%41 = add nsw i32 %35, %40
store i32 %41, i32* %7
%42 = load i32, i32* %5
%43 = load i32, i32* %7
%44 = mul nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 4
%47 = trunc i64 %46 to i32
store i32 %47, i32* %13
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = mul nsw i32 %48, %49
%51 = sext i32 %50 to i64
%52 = mul i64 %51, 4
%53 = trunc i64 %52 to i32
store i32 %53, i32* %14
%54 = load i32, i32* %5
%55 = load i32, i32* %7
%56 = mul nsw i32 %54, %55
%57 = sext i32 %56 to i64
%58 = mul i64 %57, 4
%59 = trunc i64 %58 to i32
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i32*
store i32* %61, i32** %11
%62 = load i32*, i32** %11
%63 = load i32, i32* %13
%64 = call i32 @memset(i32* %62, i32 0, i32 %63)
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = mul nsw i32 %65, %66
%68 = sext i32 %67 to i64
%69 = mul i64 %68, 4
%70 = trunc i64 %69 to i32
%71 = call i64 @malloc(i32 %70)
%72 = inttoptr i64 %71 to i32*
store i32* %72, i32** %12
%73 = load i32*, i32** %12
%74 = load i32, i32* %14
%75 = call i32 @memset(i32* %73, i32 0, i32 %74)
store i32 0, i32* %15
br label %76
76: ; preds = %107, %27
%77 = load i32, i32* %15
%78 = load i32, i32* %5
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %110
80: ; preds = %76
%81 = load i32*, i32** %9
%82 = load i32, i32* %15
%83 = load i32, i32* %7
%84 = mul nsw i32 %82, %83
%85 = load i32, i32* @SEEK_SET
%86 = call i32 @fseek(i32* %81, i32 %84, i32 %85)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %91
88: ; preds = %80
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%90 = call i32 @exit(i32 0)
unreachable
91: ; preds = %80
%92 = load i32*, i32** %11
%93 = load i32, i32* %15
%94 = load i32, i32* %7
%95 = mul nsw i32 %93, %94
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32, i32* %92, i64 %96
%98 = load i32, i32* %7
%99 = load i32*, i32** %9
%100 = call i64 @fread(i32* %97, i32 4, i32 %98, i32* %99)
%101 = load i64, i64* @EOF
%102 = icmp eq i64 %100, %101
br i1 %102, label %103, label %106
103: ; preds = %91
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%105 = call i32 @exit(i32 0)
unreachable
106: ; preds = %91
br label %107
107: ; preds = %106
%108 = load i32, i32* %15
%109 = add nsw i32 %108, 1
store i32 %109, i32* %15
br label %76
110: ; preds = %76
%111 = load i32*, i32** %9
%112 = call i32 @fclose(i32* %111)
%113 = load i32, i32* @CLOCK_REALTIME
%114 = call i32 @clock_gettime(i32 %113, %struct.timespec* %16)
%115 = load i32, i32* %6
%116 = load i32, i32* %5
%117 = mul nsw i32 %115, %116
%118 = sext i32 %117 to i64
%119 = mul i64 %118, 4
%120 = trunc i64 %119 to i32
%121 = call i64 @malloc(i32 %120)
%122 = inttoptr i64 %121 to i32*
store i32* %122, i32** %19
%123 = load i32*, i32** %19
%124 = load i32, i32* %6
%125 = load i32, i32* %5
%126 = call i32 @gen_encoding_matrix(i32* %123, i32 %124, i32 %125)
%127 = load i32, i32* %8
%128 = load i32, i32* %6
%129 = load i32, i32* %5
%130 = load i32*, i32** %19
%131 = call i32 @write_metadata(i32 %127, i32 %128, i32 %129, i32* %130)
%132 = load i32*, i32** %11
%133 = load i32*, i32** %19
%134 = load i32*, i32** %12
%135 = load i32, i32* %5
%136 = load i32, i32* %6
%137 = load i32, i32* %7
%138 = call i32 @encode_chunk(i32* %132, i32* %133, i32* %134, i32 %135, i32 %136, i32 %137)
%139 = load i32, i32* @CLOCK_REALTIME
%140 = call i32 @clock_gettime(i32 %139, %struct.timespec* %17)
%141 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 1
%142 = load i64, i64* %141
%143 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%144 = load i64, i64* %143
%145 = sub nsw i64 %142, %144
%146 = sitofp i64 %145 to double
%147 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 0
%148 = load i64, i64* %147
%149 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
%150 = load i64, i64* %149
%151 = sub nsw i64 %148, %150
%152 = sitofp i64 %151 to double
%153 = fdiv double %152, 1.000000e+06
%154 = call double @llvm.fmuladd.f64(double %146, double 1.000000e+03, double %153)
store double %154, double* %18
%155 = load double, double* %18
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), double %155)
store i32 0, i32* %15
br label %157
157: ; preds = %195, %110
%158 = load i32, i32* %15
%159 = load i32, i32* %5
%160 = icmp slt i32 %158, %159
br i1 %160, label %161, label %198
161: ; preds = %157
%162 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i64 0, i64 0
%163 = load i32, i32* %15
%164 = call i32 @sprintf(i8* %162, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %163)
%165 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i64 0, i64 0
%166 = load i8*, i8** %4
%167 = call i32 @strcat(i8* %165, i8* %166)
%168 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i64 0, i64 0
%169 = call i32* @fopen(i8* %168, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %169, i32** %10
%170 = icmp eq i32* %169, null
br i1 %170, label %171, label %174
171: ; preds = %161
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%173 = call i32 @exit(i32 0)
unreachable
174: ; preds = %161
%175 = load i32*, i32** %11
%176 = load i32, i32* %15
%177 = load i32, i32* %7
%178 = mul nsw i32 %176, %177
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds i32, i32* %175, i64 %179
%181 = load i32, i32* %7
%182 = load i32*, i32** %10
%183 = call i32 @fwrite(i32* %180, i32 4, i32 %181, i32* %182)
%184 = sext i32 %183 to i64
%185 = load i32, i32* %7
%186 = sext i32 %185 to i64
%187 = mul i64 4, %186
%188 = icmp ne i64 %184, %187
br i1 %188, label %189, label %192
189: ; preds = %174
%190 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%191 = call i32 @exit(i32 0)
unreachable
192: ; preds = %174
%193 = load i32*, i32** %10
%194 = call i32 @fclose(i32* %193)
br label %195
195: ; preds = %192
%196 = load i32, i32* %15
%197 = add nsw i32 %196, 1
store i32 %197, i32* %15
br label %157
198: ; preds = %157
store i32 0, i32* %15
br label %199
199: ; preds = %239, %198
%200 = load i32, i32* %15
%201 = load i32, i32* %6
%202 = icmp slt i32 %200, %201
br i1 %202, label %203, label %242
203: ; preds = %199
%204 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i64 0, i64 0
%205 = load i32, i32* %15
%206 = load i32, i32* %5
%207 = add nsw i32 %205, %206
%208 = call i32 @sprintf(i8* %204, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %207)
%209 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i64 0, i64 0
%210 = load i8*, i8** %4
%211 = call i32 @strcat(i8* %209, i8* %210)
%212 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i64 0, i64 0
%213 = call i32* @fopen(i8* %212, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %213, i32** %10
%214 = icmp eq i32* %213, null
br i1 %214, label %215, label %218
215: ; preds = %203
%216 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%217 = call i32 @exit(i32 0)
unreachable
218: ; preds = %203
%219 = load i32*, i32** %12
%220 = load i32, i32* %15
%221 = load i32, i32* %7
%222 = mul nsw i32 %220, %221
%223 = sext i32 %222 to i64
%224 = getelementptr inbounds i32, i32* %219, i64 %223
%225 = load i32, i32* %7
%226 = load i32*, i32** %10
%227 = call i32 @fwrite(i32* %224, i32 4, i32 %225, i32* %226)
%228 = sext i32 %227 to i64
%229 = load i32, i32* %7
%230 = sext i32 %229 to i64
%231 = mul i64 4, %230
%232 = icmp ne i64 %228, %231
br i1 %232, label %233, label %236
233: ; preds = %218
%234 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%235 = call i32 @exit(i32 0)
unreachable
236: ; preds = %218
%237 = load i32*, i32** %10
%238 = call i32 @fclose(i32* %237)
br label %239
239: ; preds = %236
%240 = load i32, i32* %15
%241 = add nsw i32 %240, 1
store i32 %241, i32* %15
br label %199
242: ; preds = %199
%243 = load i32*, i32** %11
%244 = call i32 @free(i32* %243)
%245 = load i32*, i32** %12
%246 = call i32 @free(i32* %245)
%247 = load i32*, i32** %19
%248 = call i32 @free(i32* %247)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i64 0
@CLOCK_REALTIME = global i32 0
@.str.4 = [31 x i8] c"Total CPU encoding time: %fms\0A\00"
@.str.5 = [5 x i8] c"_%d_\00"
@.str.6 = [3 x i8] c"wb\00"
@str.9 = [14 x i8] c"fwrite error!\00"
@str.11 = [13 x i8] c"fread error!\00"
@str.12 = [13 x i8] c"fseek error!\00"
@str.13 = [26 x i8] c"Can not open source file!\00"
define void @encode_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca [100 x i8]
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %3
%13 = load i32, i32* @SEEK_END
%14 = tail call i32 @fseek(i32* %7, i32 0, i32 %13)
%15 = tail call i32 @ftell(i32* %7)
%16 = sdiv i32 %15, %1
%17 = srem i32 %15, %1
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
%20 = add nsw i32 %16, %19
%21 = shl i32 %1, 2
%22 = mul i32 %21, %20
%23 = shl i32 %2, 2
%24 = mul i32 %23, %20
%25 = tail call i64 @malloc(i32 %22)
%26 = inttoptr i64 %25 to i32*
%27 = tail call i32 @memset(i32* %26, i32 0, i32 %22)
%28 = tail call i64 @malloc(i32 %24)
%29 = inttoptr i64 %28 to i32*
%30 = tail call i32 @memset(i32* %29, i32 0, i32 %24)
%31 = icmp sgt i32 %1, 0
br i1 %31, label %32, label %56
32: ; preds = %12
%33 = sext i32 %20 to i64
%34 = zext i32 %1 to i64
br label %37
35: ; preds = %47
%36 = icmp eq i64 %52, %34
br i1 %36, label %56, label %37
37: ; preds = %32, %35
%38 = phi i64 [ 0, %32 ], [ %52, %35 ]
%39 = mul nsw i64 %38, %33
%40 = load i32, i32* @SEEK_SET
%41 = trunc i64 %39 to i32
%42 = tail call i32 @fseek(i32* %7, i32 %41, i32 %40)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%46 = tail call i32 @exit(i32 0)
unreachable
47: ; preds = %37
%48 = getelementptr inbounds i32, i32* %26, i64 %39
%49 = tail call i64 @fread(i32* %48, i32 4, i32 %20, i32* %7)
%50 = load i64, i64* @EOF
%51 = icmp eq i64 %49, %50
%52 = add nuw nsw i64 %38, 1
br i1 %51, label %53, label %35
53: ; preds = %47
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.11, i64 0, i64 0))
%55 = tail call i32 @exit(i32 0)
unreachable
56: ; preds = %35, %12
%57 = tail call i32 @fclose(i32* %7)
%58 = bitcast %struct.timespec* %4 to i8*
%59 = bitcast %struct.timespec* %5 to i8*
%60 = load i32, i32* @CLOCK_REALTIME
%61 = call i32 @clock_gettime(i32 %60, %struct.timespec* %4)
%62 = mul i32 %21, %2
%63 = call i64 @malloc(i32 %62)
%64 = inttoptr i64 %63 to i32*
%65 = call i32 @gen_encoding_matrix(i32* %64, i32 %2, i32 %1)
%66 = call i32 @write_metadata(i32 %15, i32 %2, i32 %1, i32* %64)
%67 = call i32 @encode_chunk(i32* %26, i32* %64, i32* %29, i32 %1, i32 %2, i32 %20)
%68 = load i32, i32* @CLOCK_REALTIME
%69 = call i32 @clock_gettime(i32 %68, %struct.timespec* %5)
%70 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
%71 = load i64, i64* %70
%72 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 1
%73 = load i64, i64* %72
%74 = sub nsw i64 %71, %73
%75 = sitofp i64 %74 to double
%76 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 0
%77 = load i64, i64* %76
%78 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%79 = load i64, i64* %78
%80 = sub nsw i64 %77, %79
%81 = sitofp i64 %80 to double
%82 = fdiv double %81, 1.000000e+06
%83 = call double @llvm.fmuladd.f64(double %75, double 1.000000e+03, double %82)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), double %83)
%85 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
br i1 %31, label %86, label %90
86: ; preds = %56
%87 = sext i32 %20 to i64
%88 = shl nsw i64 %87, 2
%89 = zext i32 %1 to i64
br label %96
90: ; preds = %115, %56
%91 = icmp sgt i32 %2, 0
br i1 %91, label %92, label %143
92: ; preds = %90
%93 = sext i32 %20 to i64
%94 = shl nsw i64 %93, 2
%95 = zext i32 %2 to i64
br label %119
96: ; preds = %86, %115
%97 = phi i64 [ 0, %86 ], [ %117, %115 ]
%98 = trunc i64 %97 to i32
%99 = call i32 @sprintf(i8* %85, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %98)
%100 = call i32 @strcat(i8* %85, i8* %0)
%101 = call i32* @fopen(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%102 = icmp eq i32* %101, null
br i1 %102, label %103, label %106
103: ; preds = %96
%104 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
%105 = call i32 @exit(i32 0)
unreachable
106: ; preds = %96
%107 = mul nsw i64 %97, %87
%108 = getelementptr inbounds i32, i32* %26, i64 %107
%109 = call i32 @fwrite(i32* %108, i32 4, i32 %20, i32* %101)
%110 = sext i32 %109 to i64
%111 = icmp eq i64 %88, %110
br i1 %111, label %115, label %112
112: ; preds = %106
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
%114 = call i32 @exit(i32 0)
unreachable
115: ; preds = %106
%116 = call i32 @fclose(i32* %101)
%117 = add nuw nsw i64 %97, 1
%118 = icmp eq i64 %117, %89
br i1 %118, label %90, label %96
119: ; preds = %92, %139
%120 = phi i64 [ 0, %92 ], [ %141, %139 ]
%121 = trunc i64 %120 to i32
%122 = add i32 %121, %1
%123 = call i32 @sprintf(i8* %85, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %122)
%124 = call i32 @strcat(i8* %85, i8* %0)
%125 = call i32* @fopen(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%126 = icmp eq i32* %125, null
br i1 %126, label %127, label %130
127: ; preds = %119
%128 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
%129 = call i32 @exit(i32 0)
unreachable
130: ; preds = %119
%131 = mul nsw i64 %120, %93
%132 = getelementptr inbounds i32, i32* %29, i64 %131
%133 = call i32 @fwrite(i32* %132, i32 4, i32 %20, i32* %125)
%134 = sext i32 %133 to i64
%135 = icmp eq i64 %94, %134
br i1 %135, label %139, label %136
136: ; preds = %130
%137 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
%138 = call i32 @exit(i32 0)
unreachable
139: ; preds = %130
%140 = call i32 @fclose(i32* %125)
%141 = add nuw nsw i64 %120, 1
%142 = icmp eq i64 %141, %95
br i1 %142, label %143, label %119
143: ; preds = %139, %90
%144 = call i32 @free(i32* %26)
%145 = call i32 @free(i32* %29)
%146 = call i32 @free(i32* %64)
ret void
}