// File: /workspace/github_cpp_makefile_star2_O2/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 0x20de8(%rip), %rsi     # 0x2d2fc
movq %rax, %rdi
callq 0x4280
movq %rax, %r14
pushq $0x3
popq %rdi
movq %rax, %rsi
callq 0x42d0
movl 0x8b0(%rbx), %eax
leaq 0xc(%rsp), %r15
movl %eax, (%r15)
pushq $0x4
popq %r12
pushq $0x1
popq %r13
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movl 0x8b4(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movl 0x8cc(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movsbl 0x8b9(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movl 0x8bc(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movl 0x8c4(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movl 0x8c0(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movsbl 0x8c8(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x44b0
movsbl 0x918(%rbx), %edi
movq %r14, %rsi
callq 0x42d0
movq 0x870(%rbx), %rdi
movl 0x8b0(%rbx), %esi
movq %r14, %rdx
callq 0xcdb2
movq 0x878(%rbx), %rdi
movl 0x8b0(%rbx), %esi
movq %r14, %rdx
callq 0xcdc0
movq 0x8a0(%rbx), %rdi
movl 0x8b0(%rbx), %esi
movq %r14, %rdx
callq 0xcdc0
cmpb $0x0, 0x918(%rbx)
je 0xc691
movq 0x888(%rbx), %rdi
movl 0x8b4(%rbx), %esi
movq %r14, %rdx
callq 0xcdc0
movq 0x890(%rbx), %rdi
movl 0x8b0(%rbx), %esi
movq %r14, %rdx
callq 0xcdc0
movl $0x898, %eax            # imm = 0x898
jmp 0xc696
movl $0x880, %eax            # imm = 0x880
movq (%rbx,%rax), %rdi
movl 0x8b0(%rbx), %esi
movq %r14, %rdx
callq 0xcdc0
cmpb $0x2, 0x8c8(%rbx)
jl 0xc6d3
xorl %eax, %eax
cmpb $0x0, 0x918(%rbx)
setne %al
movl 0x8b0(%rbx,%rax,4), %esi
movq 0x8a8(%rbx), %rdi
movq %r14, %rdx
callq 0xcdb2
movq 0x928(%rbx), %rax
movq 0x18(%rax), %r12
leaq 0x50(%rsp), %r15
addq $0x8, %rax
cmpq %rax, %r12
je 0xc720
leaq 0x28(%r12), %rsi
movq %r15, %rdi
callq 0x4320
movq %r14, %rdi
movq %r15, %rsi
callq 0xaf24
movq %r15, %rdi
callq 0x40f0
movq %r12, %rdi
callq 0x4140
movq %rax, %r12
movq 0x928(%rbx), %rax
jmp 0xc6e3
movq 0x948(%rbx), %rax
movq 0x18(%rax), %r12
leaq 0x30(%rsp), %r15
addq $0x8, %rax
cmpq %rax, %r12
je 0xc76d
leaq 0x28(%r12), %rsi
movq %r15, %rdi
callq 0x4320
movq %r14, %rdi
movq %r15, %rsi
callq 0xaf24
movq %r15, %rdi
callq 0x40f0
movq %r12, %rdi
callq 0x4140
movq %rax, %r12
movq 0x948(%rbx), %rax
jmp 0xc730
movq 0x938(%rbx), %rax
movq 0x18(%rax), %r12
leaq 0x10(%rsp), %r15
addq $0x8, %rax
cmpq %rax, %r12
je 0xc7ba
leaq 0x28(%r12), %rsi
movq %r15, %rdi
callq 0x4320
movq %r14, %rdi
movq %r15, %rsi
callq 0xaf24
movq %r15, %rdi
callq 0x40f0
movq %r12, %rdi
callq 0x4140
movq %rax, %r12
movq 0x938(%rbx), %rax
jmp 0xc77d
movq %r14, %rdi
callq 0x4210
movb $0x1, %al
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq