// File: /workspace/github_cpp_makefile_star2_O3/myudelson[P]hmm-scalable/InputUtil.cpp
// Function: InputUtil::writeInputMatrix(char const*, param*, int, data**)
void InputUtil::writeInputMatrix(const char *filename, struct param* p, NCAT xndat, struct data** x_data) {
//    FILE *fid = fopen(filename,"w");
//    if(fid == NULL) {
//        fprintf(stderr,"Can't write output model file %s\n",filename);
//        exit(1);
//    }
    
    std::ofstream file;
    file.open(filename);
    
    NDAT nmax = 0;
    for(NCAT x=0; x<xndat; x++)
        if(nmax < x_data[x]->n)
            nmax = x_data[x]->n;
    
    for(NCAT x=0; x<xndat; x++) {
        std::stringstream ss;
        for(NDAT t=0; t<nmax; t++) {
            
            if(t<x_data[x]->n) {
                ss << ((t>0)?" ":"") << (int)(1+p->dat_obs[ x_data[x]->ix[t] ]);
            } else {
                ss << " " << 0;
            }
        }
        ss << "\n";
        file << ss.str();
    } // for all groups in skill
    
//    fclose(fid);
    file.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
movq %rcx, %rbx
movl %edx, %r13d
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
leaq 0x1c8(%rsp), %r12
movq %r12, %rdi
callq 0x4400
movq %r12, %rdi
movq %r14, %rsi
movl $0x10, %edx
callq 0x4060
testl %r13d, %r13d
jle 0xfacb
movl %r13d, %ebp
xorl %eax, %eax
xorl %edx, %edx
movl %edx, %ecx
movq (%rbx,%rax,8), %rdx
movl (%rdx), %edx
cmpl %edx, %ecx
cmovgl %ecx, %edx
incq %rax
cmpq %rax, %rbp
jne 0xf97f
movl %edx, 0xc(%rsp)
testl %r13d, %r13d
jle 0xfacb
leaq 0x50(%rsp), %r12
movl 0xc(%rsp), %r15d
xorl %r14d, %r14d
leaq 0x40(%rsp), %r13
movq %rbp, 0x30(%rsp)
movq %r13, %rdi
callq 0x4160
cmpl $0x0, 0xc(%rsp)
jle 0xfa43
xorl %ebp, %ebp
movq (%rbx,%r14,8), %rax
movslq (%rax), %rax
cmpq %rax, %rbp
jge 0xfa19
xorl %edx, %edx
testq %rbp, %rbp
setne %dl
leaq 0x252a3(%rip), %rsi     # 0x34c87
leaq 0x24914(%rip), %rax     # 0x342ff
cmovneq %rax, %rsi
movq %r12, %rdi
callq 0x4270
movq 0x38(%rsp), %rax
movq 0x870(%rax), %rax
movq (%rbx,%r14,8), %rcx
movq 0x10(%rcx), %rcx
movslq (%rcx,%rbp,4), %rcx
movsbl (%rax,%rcx), %r13d
incl %r13d
jmp 0xfa30
xorl %r13d, %r13d
movl $0x1, %edx
movq %r12, %rdi
leaq 0x248d4(%rip), %rsi     # 0x342ff
callq 0x4270
movq %r12, %rdi
movl %r13d, %esi
callq 0x4410
incq %rbp
cmpq %rbp, %r15
jne 0xf9c9
movl $0x1, %edx
movq %r12, %rdi
leaq 0x2380b(%rip), %rsi     # 0x3325d
callq 0x4270
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x43d0
movq 0x30(%rsp), %rbp
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x1c8(%rsp), %rdi
callq 0x4270
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xfa9e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq 0x2f503(%rip), %rsi     # 0x3efb0
callq 0x4180
leaq 0xc0(%rsp), %rdi
callq 0x40e0
incq %r14
cmpq %rbp, %r14
jne 0xf9b8
leaq 0x1c8(%rsp), %rdi
callq 0x4320
movq 0x2f4f1(%rip), %rax     # 0x3efd0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1d0(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1c8(%rsp,%rcx)
callq 0x41d0
leaq 0x2c0(%rsp), %rdi
callq 0x40e0
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfb4b
jmp 0xfb4b
jmp 0xfb50
jmp 0xfb50
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xfb53
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0xfb53
movq %rax, %rbx
jmp 0xfb71
movq %rax, %rbx
movq 0x2f456(%rip), %rsi     # 0x3efb0
leaq 0x40(%rsp), %rdi
callq 0x4180
leaq 0xc0(%rsp), %rdi
callq 0x40e0
leaq 0x1c8(%rsp), %rdi
callq 0x4350
movq %rbx, %rdi
callq 0x4430