// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/InputUtil.cpp
// Function: InputUtil::toBin(param*, char const*)
bool InputUtil::toBin(struct param * param, const char *fn) {
    char c;
    NDAT i;
    FILE *fid = fopen(fn,"wb");

    // version
    c = bin_input_file_verstion;
    fwrite (&c , sizeof(char), 1, fid);
    
    // N
    i = param->N;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // Nstacked
    i = param->Nstacked;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // N_null
    i = param->N_null;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nO
    i = param->nO;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nG
    i = param->nG;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nI
    i = param->nI;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nK
    i = param->nK;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nZ
    i = param->nZ;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // multiskill
    c = param->multiskill;
    fwrite (&c , sizeof(char), 1, fid);
    
//    NDAT nwrit;
    // dat_obs
    /*nwrit = */StripedArray<NPAR>::arrayToBinFile(param->dat_obs, param->N, fid);//param->dat_obs->toBinFile(fid);
    // dat_group
    /*nwrit = */StripedArray<NCAT>::arrayToBinFile(param->dat_group, param->N, fid);//->toBinFile(fid);
    // dat_item
    /*nwrit = */StripedArray<NCAT>::arrayToBinFile(param->dat_item, param->N, fid);//->toBinFile(fid);
    // dat_skill
    if(param->multiskill == 0)
    /*nwrit = */StripedArray<NCAT>::arrayToBinFile(param->dat_skill, param->N, fid);//->toBinFile(fid);
    else {
        //        /*nwrit = */writeMultiSkill(fid, param);
        /*nwrit = */StripedArray<NCAT>::arrayToBinFile(param->dat_skill_stacked, param->Nstacked, fid);//->toBinFile(fid);
        /*nwrit = */StripedArray<NCAT>::arrayToBinFile(param->dat_skill_rcount , param->N,        fid);//->toBinFile(fid);
        /*nwrit = */StripedArray<NCAT>::arrayToBinFile(param->dat_skill_rix    , param->N,        fid);//->toBinFile(fid);
    }
    // dat_slices, only of nZ > 1
    if(param->nZ > 1) {
        NDAT szZ = (param->multiskill == 0)?param->N:param->Nstacked;
        StripedArray<NPAR>::arrayToBinFile(param->dat_slice, szZ, fid);
    }

    map<NCAT,string>::iterator it;
    // voc_group
    for (it = param->map_group_bwd->begin(); it != param->map_group_bwd->end(); ++it) {
        writeString(fid, it->second);
    }

    // voc_skill
    for (it = param->map_skill_bwd->begin(); it != param->map_skill_bwd->end(); ++it) {
        writeString(fid, it->second);
    }
    
    // voc_item
    for (it =  param->map_step_bwd->begin(); it != param->map_step_bwd->end(); ++it) {
        writeString(fid, it->second);
    }
    
    
    fclose(fid);
    return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x70, %rsp
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x25b28(%rip), %rsi     # 0x3526c
movq %rax, %rdi
callq 0x4290
movq %rax, %r14
movl $0x3, %edi
movq %rax, %rsi
callq 0x42e0
movl 0x8b0(%rbx), %eax
leaq 0xc(%rsp), %r15
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movl 0x8b4(%rbx), %eax
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movl 0x8cc(%rbx), %eax
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movsbl 0x8b9(%rbx), %eax
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movl 0x8bc(%rbx), %eax
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movl 0x8c4(%rbx), %eax
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movl 0x8c0(%rbx), %eax
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movsbl 0x8c8(%rbx), %eax
movl %eax, (%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x4480
movsbl 0x918(%rbx), %edi
movq %r14, %rsi
callq 0x42e0
movq 0x870(%rbx), %rdi
movslq 0x8b0(%rbx), %rdx
movl $0x1, %esi
movq %r14, %rcx
callq 0x4480
movq 0x878(%rbx), %rdi
movslq 0x8b0(%rbx), %rdx
movl $0x4, %esi
movq %r14, %rcx
callq 0x4480
movq 0x8a0(%rbx), %rdi
movslq 0x8b0(%rbx), %rdx
movl $0x4, %esi
movq %r14, %rcx
callq 0x4480
cmpb $0x0, 0x918(%rbx)
je 0xf8f9
movq 0x888(%rbx), %rdi
movslq 0x8b4(%rbx), %rdx
movl $0x4, %esi
movq %r14, %rcx
callq 0x4480
movq 0x890(%rbx), %rdi
movslq 0x8b0(%rbx), %rdx
movl $0x4, %esi
movq %r14, %rcx
callq 0x4480
movl $0x898, %eax            # imm = 0x898
jmp 0xf8fe
movl $0x880, %eax            # imm = 0x880
movq (%rbx,%rax), %rdi
movslq 0x8b0(%rbx), %rdx
movl $0x4, %esi
movq %r14, %rcx
callq 0x4480
cmpb $0x2, 0x8c8(%rbx)
jl 0xf947
xorl %eax, %eax
cmpb $0x0, 0x918(%rbx)
setne %al
movslq 0x8b0(%rbx,%rax,4), %rdx
movq 0x8a8(%rbx), %rdi
movl $0x1, %esi
movq %r14, %rcx
callq 0x4480
movq 0x928(%rbx), %rax
movq 0x18(%rax), %r15
addq $0x8, %rax
cmpq %rax, %r15
je 0xf9ba
leaq 0x60(%rsp), %r13
leaq 0x50(%rsp), %r12
movq %r13, 0x50(%rsp)
movq 0x28(%r15), %rsi
movq 0x30(%r15), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xa6c2
movq %r14, %rdi
movq %r12, %rsi
callq 0xdadc
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0xf99f
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4220
movq %r15, %rdi
callq 0x4150
movq %rax, %r15
movq 0x928(%rbx), %rax
addq $0x8, %rax
cmpq %rax, %r15
jne 0xf965
movq 0x948(%rbx), %rax
movq 0x18(%rax), %r15
addq $0x8, %rax
cmpq %rax, %r15
je 0xfa2d
leaq 0x40(%rsp), %r13
leaq 0x30(%rsp), %r12
movq %r13, 0x30(%rsp)
movq 0x28(%r15), %rsi
movq 0x30(%r15), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xa6c2
movq %r14, %rdi
movq %r12, %rsi
callq 0xdadc
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0xfa12
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4220
movq %r15, %rdi
callq 0x4150
movq %rax, %r15
movq 0x948(%rbx), %rax
addq $0x8, %rax
cmpq %rax, %r15
jne 0xf9d8
movq 0x938(%rbx), %rax
movq 0x18(%rax), %r15
addq $0x8, %rax
cmpq %rax, %r15
je 0xfaa0
leaq 0x20(%rsp), %r13
leaq 0x10(%rsp), %r12
movq %r13, 0x10(%rsp)
movq 0x28(%r15), %rsi
movq 0x30(%r15), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0xa6c2
movq %r14, %rdi
movq %r12, %rsi
callq 0xdadc
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0xfa85
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4220
movq %r15, %rdi
callq 0x4150
movq %rax, %r15
movq 0x938(%rbx), %rax
addq $0x8, %rax
cmpq %rax, %r15
jne 0xfa4b
movq %r14, %rdi
callq 0x4200
movb $0x1, %al
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq