// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
leaq 0x1c8(%rsp), %r12
movq %r12, %rdi
callq 0x4400
movq %r12, %rdi
movq %r15, %rsi
movl $0x10, %edx
callq 0x4060
movl %r13d, %ebp
testl %r13d, %r13d
jle 0xfb1a
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rbx,%rax,8), %rdx
movl (%rdx), %edx
cmpl %edx, %ecx
cmovgl %ecx, %edx
incq %rax
movl %edx, %ecx
cmpq %rax, %rbp
jne 0xfb03
jmp 0xfb1c
xorl %edx, %edx
movl %edx, 0xc(%rsp)
testl %r13d, %r13d
jle 0xfc53
leaq 0x50(%rsp), %r15
movl 0xc(%rsp), %r14d
xorl %r12d, %r12d
leaq 0x40(%rsp), %r13
movq %rbp, 0x30(%rsp)
movq %r13, %rdi
callq 0x4160
cmpl $0x0, 0xc(%rsp)
jle 0xfbcb
xorl %ebp, %ebp
movq (%rbx,%r12,8), %rax
movslq (%rax), %rax
cmpq %rax, %rbp
jge 0xfba1
xorl %edx, %edx
testq %rbp, %rbp
setne %dl
leaq 0x2603b(%rip), %rsi     # 0x35ba7
leaq 0x256fc(%rip), %rax     # 0x3526f
cmovneq %rax, %rsi
movq %r15, %rdi
callq 0x4270
movq 0x38(%rsp), %rax
movq 0x870(%rax), %rax
movq (%rbx,%r12,8), %rcx
movq 0x10(%rcx), %rcx
movslq (%rcx,%rbp,4), %rcx
movsbl (%rax,%rcx), %r13d
incl %r13d
jmp 0xfbb8
xorl %r13d, %r13d
movl $0x1, %edx
movq %r15, %rdi
leaq 0x256bc(%rip), %rsi     # 0x3526f
callq 0x4270
movq %r15, %rdi
movl %r13d, %esi
callq 0x4410
incq %rbp
cmpq %rbp, %r14
jne 0xfb51
movl $0x1, %edx
movq %r15, %rdi
leaq 0x24683(%rip), %rsi     # 0x3425d
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 0xfc26
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq 0x3037b(%rip), %rsi     # 0x3ffb0
callq 0x4180
leaq 0xc0(%rsp), %rdi
callq 0x40e0
incq %r12
cmpq %rbp, %r12
jne 0xfb40
leaq 0x1c8(%rsp), %rdi
callq 0x4320
movq 0x30369(%rip), %rax     # 0x3ffd0
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 0xfcd3
jmp 0xfcd3
jmp 0xfcd8
jmp 0xfcd8
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xfcdb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
jmp 0xfcdb
movq %rax, %rbx
jmp 0xfcf9
movq %rax, %rbx
movq 0x302ce(%rip), %rsi     # 0x3ffb0
leaq 0x40(%rsp), %rdi
callq 0x4180
leaq 0xc0(%rsp), %rdi
callq 0x40e0
leaq 0x1c8(%rsp), %rdi
callq 0x4350
movq %rbx, %rdi
callq 0x4430