#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;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ copy_matrix(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                               int, int);
int /*<<< orphan*/ decode_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 *);
int /*<<< orphan*/ fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gen_total_encoding_matrix(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ invert_matrix(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
void decode_file(char *inFile, char *confFile, char *outFile) {
  int chunkSize = 1;
  int totalSize;
  int parityBlockNum;
  int nativeBlockNum;
  uint8_t *dataBuf;
  uint8_t *codeBuf;
  int dataSize;
  int codeSize;
  FILE *fp_in;
  FILE *fp_out;
  int totalMatrixSize;
  int matrixSize;
  uint8_t *totalEncodingMatrix;
  uint8_t *encodingMatrix;
  char metadata_file_name[strlen(inFile) + 15];
  sprintf(metadata_file_name, "%s.METADATA", inFile);
  if ((fp_in = fopen(metadata_file_name, "rb")) == NULL) {
    printf("Can not open metadata file!\n");
    exit(0);
  }
  fscanf(fp_in, "%d", &totalSize);
  fscanf(fp_in, "%d %d", &parityBlockNum, &nativeBlockNum);
  fclose(fp_in);
  chunkSize = (totalSize / nativeBlockNum) + (totalSize % nativeBlockNum != 0);
  totalMatrixSize = nativeBlockNum * (nativeBlockNum + parityBlockNum);
  totalEncodingMatrix = (uint8_t *)malloc(totalMatrixSize);
  matrixSize = nativeBlockNum * nativeBlockNum;
  encodingMatrix = (uint8_t *)malloc(matrixSize);
  gen_total_encoding_matrix(totalEncodingMatrix, nativeBlockNum,
                            parityBlockNum);
  dataSize = nativeBlockNum * chunkSize * sizeof(uint8_t);
  codeSize = nativeBlockNum * chunkSize * sizeof(uint8_t);
  dataBuf = (uint8_t *)malloc(dataSize);
  memset(dataBuf, 0, dataSize);
  codeBuf = (uint8_t *)malloc(codeSize);
  memset(codeBuf, 0, codeSize);
  FILE *fp_conf;
  char input_file_name[strlen(inFile) + 20];
  int index;
  fp_conf = fopen(confFile, "r");
  int i;
  for (i = 0; i < nativeBlockNum; i++) {
    fscanf(fp_conf, "%s", input_file_name);
    index = atoi(input_file_name + 1);
    copy_matrix(totalEncodingMatrix, encodingMatrix, index, i, nativeBlockNum);
    fp_in = fopen(input_file_name, "rb");
    fseek(fp_in, 0L, SEEK_SET);
    fread(codeBuf + i * chunkSize, sizeof(uint8_t), chunkSize, fp_in);
    fclose(fp_in);
  }
  fclose(fp_conf);
  struct timespec start, end;
  double totalTime;
  clock_gettime(CLOCK_REALTIME, &start);
  uint8_t *decodingMatrix;
  decodingMatrix = (uint8_t *)malloc(matrixSize);
  invert_matrix(encodingMatrix, decodingMatrix, nativeBlockNum);
  decode_chunk(dataBuf, decodingMatrix, 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 decoding time: %fms\n", totalTime);
  if (outFile == NULL) {
    fp_out = fopen(inFile, "wb");
  } else {
    fp_out = fopen(outFile, "wb");
  }
  fwrite(dataBuf, sizeof(uint8_t), totalSize, fp_out);
  fclose(fp_out);
  free(dataBuf);
  free(codeBuf);
}


x86 assembly (clang, -O0):
<decode_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
add    $0xf,%eax
mov    %rsp,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xc8(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%rdx
lea    0xd85(%rip),%rsi
call   1130 <sprintf@plt>
mov    -0xc8(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    12c6 <decode_file+0x96>
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
mov    -0x48(%rbp),%rdi
lea    0xd6e(%rip),%rsi
xor    %eax,%eax
mov    %eax,-0xd4(%rbp)
mov    %al,-0xd5(%rbp)
lea    -0x20(%rbp),%rdx
call   10b0 <fscanf@plt>
mov    -0xd5(%rbp),%al
mov    -0x48(%rbp),%rdi
lea    0xd43(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   10b0 <fscanf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%eax
mov    -0x28(%rbp),%ecx
cltd
idiv   %ecx
sub    $0x1,%edx
sbb    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
add    %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%eax
imul   %eax,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%edi
call   10e0 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
call   10d0 <gen_total_encoding_matrix@plt>
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   %ecx,%eax
shl    $0x2,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   %ecx,%eax
shl    $0x2,%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%edi
call   10e0 <malloc@plt>
mov    -0xd4(%rbp),%esi
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%edx
call   10a0 <memset@plt>
mov    -0x40(%rbp),%edi
call   10e0 <malloc@plt>
mov    -0xd4(%rbp),%esi
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%edx
call   10a0 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
add    $0x14,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xc4e(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x90(%rbp)
mov    -0x90(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    14d4 <decode_file+0x2a4>
mov    -0xd0(%rbp),%rdx
mov    -0x80(%rbp),%rdi
lea    0xc1c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fscanf@plt>
mov    -0xd0(%rbp),%rdi
add    $0x1,%rdi
call   1120 <atoi@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x8c(%rbp),%edx
mov    -0x90(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1100 <copy_matrix@plt>
mov    -0xd0(%rbp),%rdi
lea    0xbac(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2b5c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10f0 <fseek@plt>
mov    -0x38(%rbp),%rdi
mov    -0x90(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x1c(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x4,%esi
call   1040 <fread@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
jmp    1407 <decode_file+0x1d7>
mov    -0x80(%rbp),%rdi
call   1060 <fclose@plt>
mov    0x2af4(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x58(%rbp),%edi
call   10e0 <malloc@plt>
mov    %rax,-0xc0(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   10c0 <invert_matrix@plt>
mov    -0x30(%rbp),%rdi
mov    -0xc0(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
call   1080 <decode_chunk@plt>
mov    0x2a9e(%rip),%rax
mov    (%rax),%edi
lea    -0xb0(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0xa8(%rbp),%rax
sub    -0x98(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    -0xb0(%rbp),%rax
sub    -0xa0(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  0xa92(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xa7e(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
movsd  -0xb8(%rbp),%xmm0
ff
lea    0xaa6(%rip),%rdi
mov    $0x1,%al
call   1090 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    15cc <decode_file+0x39c>
mov    -0x8(%rbp),%rdi
lea    0xaa8(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x50(%rbp)
jmp    15e0 <decode_file+0x3b0>
mov    -0x18(%rbp),%rdi
lea    0xa8f(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x4,%esi
call   1150 <fwrite@plt>
mov    -0x50(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x70(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
call   1080 <strlen@plt>
mov    %rsp,-0x48(%rbp)
add    $0xf,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xd8f(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1140 <sprintf@plt>
lea    0xd89(%rip),%rsi
mov    %rbx,%rdi
call   1120 <fopen@plt>
test   %rax,%rax
je     1558 <decode_file+0x318>
mov    %rax,%rbx
mov    %r14,-0x70(%rbp)
lea    0xd70(%rip),%rsi
lea    -0x38(%rbp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   10c0 <fscanf@plt>
lea    0xd58(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   10c0 <fscanf@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    -0x38(%rbp),%eax
mov    -0x2c(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,%r14d
cmp    $0x1,%edx
sbb    $0xffffffff,%r14d
mov    -0x34(%rbp),%edi
add    %ecx,%edi
imul   %ecx,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    -0x2c(%rbp),%edi
imul   %edi,%edi
mov    %edi,-0x3c(%rbp)
call   10f0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    %rbx,-0x88(%rbp)
mov    %rbx,%rdi
call   10e0 <gen_total_encoding_matrix@plt>
mov    -0x2c(%rbp),%ebx
mov    %r14d,-0x30(%rbp)
imul   %r14d,%ebx
shl    $0x2,%ebx
mov    %ebx,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   10b0 <memset@plt>
mov    %ebx,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   10b0 <memset@plt>
mov    %r15,-0x60(%rbp)
mov    %r15,%rdi
call   1080 <strlen@plt>
add    $0x14,%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xc97(%rip),%rsi
mov    %r12,%rdi
call   1120 <fopen@plt>
mov    %rax,%rbx
cmpl   $0x0,-0x2c(%rbp)
jle    144b <decode_file+0x20b>
lea    0x1(%r13),%rax
mov    %rax,-0x80(%rbp)
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x78(%rbp)
mov    -0x50(%rbp),%r15
xor    %r12d,%r12d
xchg   %ax,%ax
mov    %rbx,%rdi
lea    0xc5d(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   10c0 <fscanf@plt>
mov    -0x80(%rbp),%rdi
call   1130 <atoi@plt>
mov    -0x2c(%rbp),%r8d
mov    -0x88(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
mov    %r12d,%ecx
call   1110 <copy_matrix@plt>
mov    %r13,%rdi
lea    0xc1c(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,%r14
mov    0x2bd1(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1100 <fseek@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    -0x30(%rbp),%edx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
add    $0x1,%r12
movslq -0x2c(%rbp),%rax
add    -0x78(%rbp),%r15
cmp    %rax,%r12
jl     13c0 <decode_file+0x180>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    0x2b7e(%rip),%r14
mov    (%r14),%edi
lea    -0xa8(%rbp),%rsi
call   1060 <clock_gettime@plt>
mov    -0x3c(%rbp),%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    -0x2c(%rbp),%edx
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
call   10d0 <invert_matrix@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x68(%rbp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    -0x50(%rbp),%r12
mov    %r12,%rdx
mov    -0x30(%rbp),%r9d
call   1090 <decode_chunk@plt>
mov    (%r14),%edi
lea    -0x98(%rbp),%rsi
call   1060 <clock_gettime@plt>
mov    -0x98(%rbp),%rax
mov    -0x90(%rbp),%rcx
sub    -0xa0(%rbp),%rcx
cvtsi2sd %rcx,%xmm0
sub    -0xa8(%rbp),%rax
cvtsi2sd %rax,%xmm1
divsd  0xb1f(%rip),%xmm1
mulsd  0xb1f(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xb36(%rip),%rdi
mov    $0x1,%al
call   10a0 <printf@plt>
mov    -0x70(%rbp),%rdi
lea    0xb43(%rip),%rsi
test   %rdi,%rdi
jne    150f <decode_file+0x2cf>
mov    -0x60(%rbp),%rdi
call   1120 <fopen@plt>
mov    %rax,%rbx
mov    -0x48(%rbp),%r14
mov    -0x38(%rbp),%edx
mov    %r15,%rdi
mov    $0x4,%esi
mov    %rax,%rcx
call   1160 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xaed(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [12 x i8] c"%s.METADATA\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"Can not open metadata file!\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%s\00"
@SEEK_SET = global i32 0
@CLOCK_REALTIME = global i32 0
@.str.7 = [31 x i8] c"Total CPU decoding time: %fms\0A\00"
@.str.8 = [3 x i8] c"wb\00"
define void @decode_file(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%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 i32*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i8*
%22 = alloca i64
%23 = alloca i32*
%24 = alloca i64
%25 = alloca i32
%26 = alloca i32
%27 = alloca %struct.timespec
%28 = alloca %struct.timespec
%29 = alloca double
%30 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 1, i32* %7
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = add nsw i32 %32, 15
%34 = zext i32 %33 to i64
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %21
%36 = alloca i8, i64 %34
store i64 %34, i64* %22
%37 = load i8*, i8** %4
%38 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %15
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %3
%45 = load i32*, i32** %15
%46 = call i32 (i32*, i8*, ...) @fscanf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%47 = load i32*, i32** %15
%48 = call i32 (i32*, i8*, ...) @fscanf(i32* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %9, i32* %10)
%49 = load i32*, i32** %15
%50 = call i32 @fclose(i32* %49)
%51 = load i32, i32* %8
%52 = load i32, i32* %10
%53 = sdiv i32 %51, %52
%54 = load i32, i32* %8
%55 = load i32, i32* %10
%56 = srem i32 %54, %55
%57 = icmp ne i32 %56, 0
%58 = zext i1 %57 to i32
%59 = add nsw i32 %53, %58
store i32 %59, i32* %7
%60 = load i32, i32* %10
%61 = load i32, i32* %10
%62 = load i32, i32* %9
%63 = add nsw i32 %61, %62
%64 = mul nsw i32 %60, %63
store i32 %64, i32* %17
%65 = load i32, i32* %17
%66 = call i64 @malloc(i32 %65)
%67 = inttoptr i64 %66 to i32*
store i32* %67, i32** %19
%68 = load i32, i32* %10
%69 = load i32, i32* %10
%70 = mul nsw i32 %68, %69
store i32 %70, i32* %18
%71 = load i32, i32* %18
%72 = call i64 @malloc(i32 %71)
%73 = inttoptr i64 %72 to i32*
store i32* %73, i32** %20
%74 = load i32*, i32** %19
%75 = load i32, i32* %10
%76 = load i32, i32* %9
%77 = call i32 @gen_total_encoding_matrix(i32* %74, i32 %75, i32 %76)
%78 = load i32, i32* %10
%79 = load i32, i32* %7
%80 = mul nsw i32 %78, %79
%81 = sext i32 %80 to i64
%82 = mul i64 %81, 4
%83 = trunc i64 %82 to i32
store i32 %83, i32* %13
%84 = load i32, i32* %10
%85 = load i32, i32* %7
%86 = mul nsw i32 %84, %85
%87 = sext i32 %86 to i64
%88 = mul i64 %87, 4
%89 = trunc i64 %88 to i32
store i32 %89, i32* %14
%90 = load i32, i32* %13
%91 = call i64 @malloc(i32 %90)
%92 = inttoptr i64 %91 to i32*
store i32* %92, i32** %11
%93 = load i32*, i32** %11
%94 = load i32, i32* %13
%95 = call i32 @memset(i32* %93, i32 0, i32 %94)
%96 = load i32, i32* %14
%97 = call i64 @malloc(i32 %96)
%98 = inttoptr i64 %97 to i32*
store i32* %98, i32** %12
%99 = load i32*, i32** %12
%100 = load i32, i32* %14
%101 = call i32 @memset(i32* %99, i32 0, i32 %100)
%102 = load i8*, i8** %4
%103 = call i32 @strlen(i8* %102)
%104 = add nsw i32 %103, 20
%105 = zext i32 %104 to i64
%106 = alloca i8, i64 %105
store i64 %105, i64* %24
%107 = load i8*, i8** %5
%108 = call i32* @fopen(i8* %107, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %108, i32** %23
store i32 0, i32* %26
br label %109
109: ; preds = %139, %44
%110 = load i32, i32* %26
%111 = load i32, i32* %10
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %142
113: ; preds = %109
%114 = load i32*, i32** %23
%115 = call i32 (i32*, i8*, ...) @fscanf(i32* %114, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %106)
%116 = getelementptr inbounds i8, i8* %106, i64 1
%117 = call i32 @atoi(i8* %116)
store i32 %117, i32* %25
%118 = load i32*, i32** %19
%119 = load i32*, i32** %20
%120 = load i32, i32* %25
%121 = load i32, i32* %26
%122 = load i32, i32* %10
%123 = call i32 @copy_matrix(i32* %118, i32* %119, i32 %120, i32 %121, i32 %122)
%124 = call i32* @fopen(i8* %106, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %124, i32** %15
%125 = load i32*, i32** %15
%126 = load i32, i32* @SEEK_SET
%127 = call i32 @fseek(i32* %125, i64 0, i32 %126)
%128 = load i32*, i32** %12
%129 = load i32, i32* %26
%130 = load i32, i32* %7
%131 = mul nsw i32 %129, %130
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i32, i32* %128, i64 %132
%134 = load i32, i32* %7
%135 = load i32*, i32** %15
%136 = call i32 @fread(i32* %133, i32 4, i32 %134, i32* %135)
%137 = load i32*, i32** %15
%138 = call i32 @fclose(i32* %137)
br label %139
139: ; preds = %113
%140 = load i32, i32* %26
%141 = add nsw i32 %140, 1
store i32 %141, i32* %26
br label %109
142: ; preds = %109
%143 = load i32*, i32** %23
%144 = call i32 @fclose(i32* %143)
%145 = load i32, i32* @CLOCK_REALTIME
%146 = call i32 @clock_gettime(i32 %145, %struct.timespec* %27)
%147 = load i32, i32* %18
%148 = call i64 @malloc(i32 %147)
%149 = inttoptr i64 %148 to i32*
store i32* %149, i32** %30
%150 = load i32*, i32** %20
%151 = load i32*, i32** %30
%152 = load i32, i32* %10
%153 = call i32 @invert_matrix(i32* %150, i32* %151, i32 %152)
%154 = load i32*, i32** %11
%155 = load i32*, i32** %30
%156 = load i32*, i32** %12
%157 = load i32, i32* %10
%158 = load i32, i32* %9
%159 = load i32, i32* %7
%160 = call i32 @decode_chunk(i32* %154, i32* %155, i32* %156, i32 %157, i32 %158, i32 %159)
%161 = load i32, i32* @CLOCK_REALTIME
%162 = call i32 @clock_gettime(i32 %161, %struct.timespec* %28)
%163 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 1
%164 = load i64, i64* %163
%165 = getelementptr inbounds %struct.timespec, %struct.timespec* %27, i32 0, i32 1
%166 = load i64, i64* %165
%167 = sub nsw i64 %164, %166
%168 = sitofp i64 %167 to double
%169 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 0
%170 = load i64, i64* %169
%171 = getelementptr inbounds %struct.timespec, %struct.timespec* %27, i32 0, i32 0
%172 = load i64, i64* %171
%173 = sub nsw i64 %170, %172
%174 = sitofp i64 %173 to double
%175 = fdiv double %174, 1.000000e+06
%176 = call double @llvm.fmuladd.f64(double %168, double 1.000000e+03, double %175)
store double %176, double* %29
%177 = load double, double* %29
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), double %177)
%179 = load i8*, i8** %6
%180 = icmp eq i8* %179, null
br i1 %180, label %181, label %184
181: ; preds = %142
%182 = load i8*, i8** %4
%183 = call i32* @fopen(i8* %182, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %183, i32** %16
br label %187
184: ; preds = %142
%185 = load i8*, i8** %6
%186 = call i32* @fopen(i8* %185, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %186, i32** %16
br label %187
187: ; preds = %184, %181
%188 = load i32*, i32** %11
%189 = load i32, i32* %8
%190 = load i32*, i32** %16
%191 = call i32 @fwrite(i32* %188, i32 4, i32 %189, i32* %190)
%192 = load i32*, i32** %16
%193 = call i32 @fclose(i32* %192)
%194 = load i32*, i32** %11
%195 = call i32 @free(i32* %194)
%196 = load i32*, i32** %12
%197 = call i32 @free(i32* %196)
%198 = load i8*, i8** %21
ret void
}

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