// File: /workspace/github_c_makefile_star2_O0/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
subq $0x500, %rsp            # imm = 0x500
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x4f0(%rbp)
movq %rcx, %rsp
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x4e8(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
movq $-0x1, -0x4c8(%rbp)
movq $0x0, -0x4d8(%rbp)
movq $0x0, -0x4e0(%rbp)
leaq 0x4619(%rip), %rax      # 0x60e8
cmpl $0x0, (%rax)
je 0x1af5
movq 0x451d(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x262c(%rip), %rsi      # 0x4111
movb $0x0, %al
callq 0x10a0
movq -0x10(%rbp), %rdi
callq 0x2ab0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x1c02
leaq -0x430(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl -0x14(%rbp), %r8d
movl $0x400, %esi            # imm = 0x400
leaq 0x25fc(%rip), %rdx      # 0x4123
movb $0x0, %al
callq 0x1070
leaq -0x430(%rbp), %rdi
leaq 0x25ee(%rip), %rsi      # 0x412a
callq 0x10e0
movq %rax, %rcx
movq -0x4f0(%rbp), %rax
movslq -0x14(%rbp), %rdx
movq %rcx, (%rax,%rdx,8)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x1b6d
leaq -0x430(%rbp), %rsi
leaq 0x25c4(%rip), %rdi      # 0x412c
callq 0x37f0
movq -0x4f0(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10b0
movl %eax, %edi
leaq -0x4c0(%rbp), %rsi
callq 0x1150
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x1bad
leaq -0x430(%rbp), %rsi
leaq 0x2592(%rip), %rdi      # 0x413a
callq 0x37f0
movq $-0x1, %rax
cmpq -0x4c8(%rbp), %rax
jne 0x1bcd
movq -0x490(%rbp), %rax
movq %rax, -0x4c8(%rbp)
jmp 0x1bf2
movq -0x4c8(%rbp), %rax
cmpq -0x490(%rbp), %rax
je 0x1bf0
leaq -0x430(%rbp), %rsi
leaq 0x255d(%rip), %rdi      # 0x4148
callq 0x3860
jmp 0x1bf2
jmp 0x1bf4
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1afc
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x1c82
leaq -0x430(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl -0x14(%rbp), %r8d
movl $0x400, %esi            # imm = 0x400
leaq 0x2522(%rip), %rdx      # 0x4151
movb $0x0, %al
callq 0x1070
leaq -0x430(%rbp), %rdi
leaq 0x2514(%rip), %rsi      # 0x4158
callq 0x10e0
movq %rax, %rcx
movq -0x4e8(%rbp), %rax
movslq -0x14(%rbp), %rdx
movq %rcx, (%rax,%rdx,8)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x1c75
leaq -0x430(%rbp), %rsi
leaq 0x24bc(%rip), %rdi      # 0x412c
callq 0x37f0
jmp 0x1c77
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1c09
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x3950
movq %rax, -0x4d8(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x3950
movq %rax, -0x4e0(%rbp)
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x4f8(%rbp)
movq -0x4c8(%rbp), %rdi
callq 0x1260
movq %rax, %rcx
movq -0x4f8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1de1
movq -0x4d8(%rbp), %rdi
callq 0x3920
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x1d50
movq -0x4f0(%rbp), %rax
movq -0x4d8(%rbp), %rcx
movq 0x8(%rcx), %rdi
movslq -0x18(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1280
movq %rax, -0x4d0(%rbp)
movl $0x1, %eax
cmpq -0x4d0(%rbp), %rax
je 0x1d43
leaq 0x241c(%rip), %rdi      # 0x415a
callq 0x37d0
jmp 0x1d45
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1cec
movq -0x4e0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x4d8(%rbp), %rdx
callq 0x36a0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x1dd1
movq -0x4e8(%rbp), %rax
movq -0x4e0(%rbp), %rcx
movq 0x8(%rcx), %rdi
movslq -0x18(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1290
movq %rax, -0x4d0(%rbp)
movl $0x1, %eax
cmpq -0x4d0(%rbp), %rax
je 0x1dc4
leaq 0x23ab(%rip), %rdi      # 0x416a
callq 0x37d0
jmp 0x1dc6
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1d6e
jmp 0x1dd3
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1caf
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x1e13
movq -0x4f0(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1050
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1de8
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x1e44
movq -0x4e8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1050
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1e1a
movq -0x4d8(%rbp), %rdi
callq 0x39a0
movq -0x4e0(%rbp), %rdi
callq 0x39a0
movq -0x20(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)