// File: /workspace/github_c_makefile_star2_O3/vrancurel[P]ec/ec.c
// Function: create_coding_files
void create_coding_files(char *prefix, t_mat *mat)
{
  int i, j;
  FILE *d_files[mat->n_cols];
  FILE *c_files[mat->n_rows];
  char filename[1024];
  struct stat stbuf;
  size_t size = -1, wc;
  t_vec *words = NULL;
  t_vec *output = NULL;

  if (vflag) {
    fprintf(stderr, "encoding matrix:\n");
    mat_dump(mat);
  }

  for (i = 0;i < mat->n_cols;i++) {
    snprintf(filename, sizeof (filename), "%s.d%d", prefix, i);
    if (NULL == (d_files[i] = fopen(filename, "r")))
      xerrormsg("error opening", filename);
    if (-1 == fstat(fileno(d_files[i]), &stbuf))
      xerrormsg("error stating", filename);
    if (-1 == size)
      size = stbuf.st_size;
    else if (size != stbuf.st_size)
      xmsg("bad size", filename);
  }
  
  for (i = 0;i < mat->n_rows;i++) {
    snprintf(filename, sizeof (filename), "%s.c%d", prefix, i);
    if (NULL == (c_files[i] = fopen(filename, "w")))
      xerrormsg("error opening", filename);
  }
  
  words = vec_xcalloc(mat->n_cols);
  output = vec_xcalloc(mat->n_cols);
  
  for (i = 0;i < sizew(size);i++) {
    vec_zero(words);
    for (j = 0;j < mat->n_cols;j++) {
      wc = freadw(&VEC_ITEM(words, j), d_files[j]);
      if (1 != wc)
        xperror("short read data");
    }
    mat_mult(output, mat, words);
    for (j = 0;j < mat->n_rows;j++) {
      wc = fwritew(& VEC_ITEM(output, j), c_files[j]);
      if (1 != wc)
        xperror("short write coding");
    }
  } 
    
  for (i = 0;i < mat->n_cols;i++) {
    fclose(d_files[i]);
  }
  
  for (i = 0;i < mat->n_rows;i++) {
    fclose(c_files[i]);
  }

  vec_free(words);
  vec_free(output);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movq %rsi, %rbx
movq %rdi, -0x30(%rbp)
movl 0x4(%rsi), %eax
movq %rsp, %r12
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %r12
movq %r12, %rsp
movl (%rsi), %ecx
movq %rsp, %r14
leaq 0xf(,%rcx,8), %rcx
andq $-0x10, %rcx
subq %rcx, %r14
movq %r14, %rsp
leaq 0x37bb(%rip), %rcx      # 0x50f8
cmpl $0x0, (%rcx)
jne 0x1bc9
movq %r12, -0x38(%rbp)
movq %r14, -0x40(%rbp)
movq $-0x1, %r14
testl %eax, %eax
je 0x1a19
leaq -0x4e0(%rbp), %r12
xorl %r13d, %r13d
movq %r14, %r15
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
leaq 0x17aa(%rip), %rdx      # 0x3123
movq -0x30(%rbp), %rcx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x1080
movq %r12, %rdi
leaq 0x1799(%rip), %rsi      # 0x312a
callq 0x10f0
movq %rax, %r14
movq -0x38(%rbp), %rax
movq %r14, (%rax,%r13,8)
testq %r14, %r14
jne 0x19b5
leaq 0x177f(%rip), %rdi      # 0x312c
movq %r12, %rsi
callq 0x2c98
movq %r14, %rdi
callq 0x10c0
movl %eax, %edi
leaq -0xd8(%rbp), %rsi
callq 0x1170
cmpl $-0x1, %eax
jne 0x19df
leaq 0x1763(%rip), %rdi      # 0x313a
movq %r12, %rsi
callq 0x2c98
movq -0xa8(%rbp), %rax
cmpq $-0x1, %r15
je 0x1a05
movq %r15, %r14
cmpq %rax, %r15
je 0x1a08
leaq 0x174d(%rip), %rdi      # 0x3148
movq %r12, %rsi
callq 0x2cdd
jmp 0x1a08
movq %rax, %r14
incq %r13
movl 0x4(%rbx), %edi
cmpq %rdi, %r13
jb 0x1967
jmp 0x1a1b
xorl %edi, %edi
cmpl $0x0, (%rbx)
movq %r14, -0x48(%rbp)
je 0x1a8d
leaq 0x1726(%rip), %r15      # 0x3151
leaq -0x4e0(%rbp), %r12
leaq 0x171f(%rip), %r13      # 0x3158
xorl %r14d, %r14d
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq %r15, %rdx
movq -0x30(%rbp), %rcx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1080
movq %r12, %rdi
movq %r13, %rsi
callq 0x10f0
movq -0x40(%rbp), %rcx
movq %rax, (%rcx,%r14,8)
testq %rax, %rax
jne 0x1a7c
leaq 0x16b8(%rip), %rdi      # 0x312c
movq %r12, %rsi
callq 0x2c98
incq %r14
movl (%rbx), %eax
cmpq %rax, %r14
jb 0x1a3c
movl 0x4(%rbx), %edi
movq -0x48(%rbp), %r14
callq 0x2d40
movq %rax, %r15
movl 0x4(%rbx), %edi
callq 0x2d40
movq %rax, %r12
movq %r14, %rdi
callq 0x138c
testq %rax, %rax
je 0x1b68
xorl %r14d, %r14d
movq %r14, -0x30(%rbp)
movq %r15, %rdi
callq 0x2d2c
cmpl $0x0, 0x4(%rbx)
je 0x1b01
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%r15), %rdi
addq %r14, %rdi
movq -0x38(%rbp), %rax
movq (%rax,%r13,8), %rsi
callq 0x1391
cmpq $0x1, %rax
je 0x1af2
leaq 0x166d(%rip), %rdi      # 0x315a
callq 0x2c88
incq %r13
movl 0x4(%rbx), %eax
addq $0x4, %r14
cmpq %rax, %r13
jb 0x1acc
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2bbe
cmpl $0x0, (%rbx)
je 0x1b4f
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%r12), %rdi
addq %r14, %rdi
movq -0x40(%rbp), %rax
movq (%rax,%r13,8), %rsi
callq 0x1394
cmpq $0x1, %rax
je 0x1b41
leaq 0x162e(%rip), %rdi      # 0x316a
callq 0x2c88
incq %r13
movl (%rbx), %eax
addq $0x4, %r14
cmpq %rax, %r13
jb 0x1b1a
movq -0x30(%rbp), %r14
incq %r14
movq -0x48(%rbp), %rdi
callq 0x138c
cmpq %r14, %rax
ja 0x1ab4
cmpl $0x0, 0x4(%rbx)
movq -0x38(%rbp), %r13
je 0x1b8a
xorl %r14d, %r14d
movq (%r13,%r14,8), %rdi
callq 0x1060
incq %r14
movl 0x4(%rbx), %eax
cmpq %rax, %r14
jb 0x1b75
cmpl $0x0, (%rbx)
movq -0x40(%rbp), %r13
je 0x1baa
xorl %r14d, %r14d
movq (%r13,%r14,8), %rdi
callq 0x1060
incq %r14
movl (%rbx), %eax
cmpq %rax, %r14
jb 0x1b96
movq %r15, %rdi
callq 0x2d80
movq %r12, %rdi
callq 0x2d80
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3428(%rip), %rax      # 0x4ff8
movq (%rax), %rcx
leaq 0x1537(%rip), %rdi      # 0x3111
movl $0x11, %esi
movl $0x1, %edx
callq 0x1140
movq %rbx, %rdi
callq 0x2474
movl 0x4(%rbx), %eax
jmp 0x1946