// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/InputUtilSt.cpp
// Function: InputUtilSt::toBin(task*, char const*)
bool InputUtilSt::toBin(struct task *task, 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 = task->N;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // Nst
    i = task->Nst;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // N_null
    i = task->N_null;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nO
    i = task->nO;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nG
    i = task->nG;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nI
    i = task->nI;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nK
    i = task->nK;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // nZ
    i = task->nZ;
    fwrite (&i , sizeof(NDAT), 1, fid);
    
    // multiskill
    c = task->multiskill;
    fwrite (&c , sizeof(char), 1, fid);
    
//    NDAT nwrit;
    // dat_obs
    /*nwrit = */StripedArray<NPAR>::arrayToBinFile(task->dat_obs, task->N, fid);//task->dat_obs->toBinFile(fid);
    // dat_group
    /*nwrit = */StripedArray<NCAT>::arrayToBinFile(task->dat_group, task->N, fid);//->toBinFile(fid);
    // dat_item
    /*nwrit = */StripedArray<NCAT>::arrayToBinFile(task->dat_item, task->N, fid);//->toBinFile(fid);
    // dat_skill
    if(task->multiskill == 0)
    /*nwrit = */StripedArray<NCAT>::arrayToBinFile(task->dat_skill, task->N, fid);//->toBinFile(fid);
    else {
        //        /*nwrit = */writeMultiSkill(fid, param);
        /*nwrit = */StripedArray<NCAT>::arrayToBinFile(task->dat_skill_stacked, task->Nst, fid);//->toBinFile(fid);
        /*nwrit = */StripedArray<NCAT>::arrayToBinFile(task->dat_skill_rcount , task->N,        fid);//->toBinFile(fid);
        /*nwrit = */StripedArray<NCAT>::arrayToBinFile(task->dat_skill_rix    , task->N,        fid);//->toBinFile(fid);
    }
    // dat_slices, only of nZ > 1
    if(task->nZ > 1) {
        NDAT szZ = (task->multiskill == 0)?task->N:task->Nst;
        StripedArray<NPAR>::arrayToBinFile(task->dat_slice, szZ, fid);
    }

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

    // voc_skill
    for (it = task->map_skill_bwd->begin(); it != task->map_skill_bwd->end(); ++it) {
        writeString(fid, it->second);
    }
    
    // voc_item
    for (it =  task->map_step_bwd->begin(); it != task->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 0x8300(%rip), %rsi      # 0x111b4
movq %rax, %rdi
callq 0x3220
movq %rax, %r14
pushq $0x3
popq %rdi
movq %rax, %rsi
callq 0x3270
movl 0x8f8(%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 0x3400
movl 0x8fc(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3400
movl 0x914(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3400
movsbl 0x901(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3400
movl 0x904(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3400
movl 0x90c(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3400
movl 0x908(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3400
movsbl 0x910(%rbx), %eax
movl %eax, (%r15)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x3400
movsbl 0x920(%rbx), %edi
movq %r14, %rsi
callq 0x3270
movq 0x880(%rbx), %rdi
movl 0x8f8(%rbx), %esi
movq %r14, %rdx
callq 0x958a
movq 0x890(%rbx), %rdi
movl 0x8f8(%rbx), %esi
movq %r14, %rdx
callq 0x9598
movq 0x8b8(%rbx), %rdi
movl 0x8f8(%rbx), %esi
movq %r14, %rdx
callq 0x9598
cmpb $0x0, 0x920(%rbx)
je 0x9031
movq 0x8a0(%rbx), %rdi
movl 0x8fc(%rbx), %esi
movq %r14, %rdx
callq 0x9598
movq 0x8a8(%rbx), %rdi
movl 0x8f8(%rbx), %esi
movq %r14, %rdx
callq 0x9598
movl $0x8b0, %eax            # imm = 0x8B0
jmp 0x9036
movl $0x898, %eax            # imm = 0x898
movq (%rbx,%rax), %rdi
movl 0x8f8(%rbx), %esi
movq %r14, %rdx
callq 0x9598
cmpb $0x2, 0x910(%rbx)
jl 0x9073
xorl %eax, %eax
cmpb $0x0, 0x920(%rbx)
setne %al
movl 0x8f8(%rbx,%rax,4), %esi
movq 0x8c0(%rbx), %rdi
movq %r14, %rdx
callq 0x958a
movq 0x930(%rbx), %rax
movq 0x18(%rax), %r12
leaq 0x50(%rsp), %r15
addq $0x8, %rax
cmpq %rax, %r12
je 0x90c0
leaq 0x28(%r12), %rsi
movq %r15, %rdi
callq 0x32b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x7618
movq %r15, %rdi
callq 0x30e0
movq %r12, %rdi
callq 0x3120
movq %rax, %r12
movq 0x930(%rbx), %rax
jmp 0x9083
movq 0x950(%rbx), %rax
movq 0x18(%rax), %r12
leaq 0x30(%rsp), %r15
addq $0x8, %rax
cmpq %rax, %r12
je 0x910d
leaq 0x28(%r12), %rsi
movq %r15, %rdi
callq 0x32b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x7618
movq %r15, %rdi
callq 0x30e0
movq %r12, %rdi
callq 0x3120
movq %rax, %r12
movq 0x950(%rbx), %rax
jmp 0x90d0
movq 0x940(%rbx), %rax
movq 0x18(%rax), %r12
leaq 0x10(%rsp), %r15
addq $0x8, %rax
cmpq %rax, %r12
je 0x915a
leaq 0x28(%r12), %rsi
movq %r15, %rdi
callq 0x32b0
movq %r14, %rdi
movq %r15, %rsi
callq 0x7618
movq %r15, %rdi
callq 0x30e0
movq %r12, %rdi
callq 0x3120
movq %rax, %r12
movq 0x940(%rbx), %rax
jmp 0x911d
movq %r14, %rdi
callq 0x31b0
movb $0x1, %al
addq $0x70, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq