// File: /workspace/github_c_makefile_star2_O1/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, %r15
movl 0x4(%rsi), %eax
movq %rsp, %r12
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movl (%rsi), %eax
movq %rsp, %r14
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
leaq 0x378c(%rip), %rax      # 0x50f8
cmpl $0x0, (%rax)
jne 0x1bf8
movq %r12, -0x38(%rbp)
movq %r14, -0x40(%rbp)
cmpl $0x0, 0x4(%rbx)
je 0x1a4d
movq $-0x1, -0x30(%rbp)
leaq -0x4e0(%rbp), %r12
xorl %r13d, %r13d
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
leaq 0x177b(%rip), %rdx      # 0x3123
movq %r15, %rcx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x1080
movq %r12, %rdi
leaq 0x176b(%rip), %rsi      # 0x312a
callq 0x10f0
movq %rax, %r14
movq -0x38(%rbp), %rax
movq %r14, (%rax,%r13,8)
testq %r14, %r14
jne 0x19e3
leaq 0x1751(%rip), %rdi      # 0x312c
movq %r12, %rsi
callq 0x2c90
movq %r14, %rdi
callq 0x10c0
movl %eax, %edi
leaq -0xd8(%rbp), %rsi
callq 0x1170
cmpl $-0x1, %eax
jne 0x1a0d
leaq 0x1735(%rip), %rdi      # 0x313a
movq %r12, %rsi
callq 0x2c90
movq -0x30(%rbp), %r14
cmpq $-0x1, %r14
je 0x1a31
cmpq -0xa8(%rbp), %r14
je 0x1a38
leaq 0x1721(%rip), %rdi      # 0x3148
movq %r12, %rsi
callq 0x2cd5
jmp 0x1a38
movq -0xa8(%rbp), %r14
movq %r14, -0x30(%rbp)
incq %r13
movl 0x4(%rbx), %eax
cmpq %rax, %r13
jb 0x1999
jmp 0x1a55
movq $-0x1, -0x30(%rbp)
cmpl $0x0, (%rbx)
je 0x1ab8
leaq -0x4e0(%rbp), %r12
leaq 0x16f0(%rip), %r13      # 0x3158
xorl %r14d, %r14d
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
leaq 0x16d7(%rip), %rdx      # 0x3151
movq %r15, %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 0x1aae
leaq 0x1686(%rip), %rdi      # 0x312c
movq %r12, %rsi
callq 0x2c90
incq %r14
movl (%rbx), %eax
cmpq %rax, %r14
jb 0x1a6b
movl 0x4(%rbx), %edi
callq 0x2d38
movq %rax, %r15
movl 0x4(%rbx), %edi
callq 0x2d38
movq %rax, %r12
movq -0x30(%rbp), %rdi
callq 0x13bc
testq %rax, %rax
je 0x1b97
xorl %r14d, %r14d
movq %r14, -0x48(%rbp)
movq %r15, %rdi
callq 0x2d24
cmpl $0x0, 0x4(%rbx)
je 0x1b30
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%r15), %rdi
addq %r14, %rdi
movq -0x38(%rbp), %rax
movq (%rax,%r13,8), %rsi
callq 0x13c1
cmpq $0x1, %rax
je 0x1b21
leaq 0x163e(%rip), %rdi      # 0x315a
callq 0x2c80
incq %r13
movl 0x4(%rbx), %eax
addq $0x4, %r14
cmpq %rax, %r13
jb 0x1afb
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2bb9
cmpl $0x0, (%rbx)
je 0x1b7e
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x8(%r12), %rdi
addq %r14, %rdi
movq -0x40(%rbp), %rax
movq (%rax,%r13,8), %rsi
callq 0x13c4
cmpq $0x1, %rax
je 0x1b70
leaq 0x15ff(%rip), %rdi      # 0x316a
callq 0x2c80
incq %r13
movl (%rbx), %eax
addq $0x4, %r14
cmpq %rax, %r13
jb 0x1b49
movq -0x48(%rbp), %r14
incq %r14
movq -0x30(%rbp), %rdi
callq 0x13bc
cmpq %r14, %rax
ja 0x1ae3
cmpl $0x0, 0x4(%rbx)
movq -0x38(%rbp), %r13
je 0x1bb9
xorl %r14d, %r14d
movq (%r13,%r14,8), %rdi
callq 0x1060
incq %r14
movl 0x4(%rbx), %eax
cmpq %rax, %r14
jb 0x1ba4
cmpl $0x0, (%rbx)
movq -0x40(%rbp), %r13
je 0x1bd9
xorl %r14d, %r14d
movq (%r13,%r14,8), %rdi
callq 0x1060
incq %r14
movl (%rbx), %eax
cmpq %rax, %r14
jb 0x1bc5
movq %r15, %rdi
callq 0x2d78
movq %r12, %rdi
callq 0x2d78
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x1190
jmp 0x1975