// File: 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 %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x3a542(%rip), %rsi     # 0x50340
callq 0x5370
movq %rax, -0x20(%rbp)
movb $0x3, -0x11(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x11(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x55a0
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movl 0x8b4(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movl 0x8cc(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movsbl 0x8b9(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movl 0x8bc(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movl 0x8c4(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movl 0x8c0(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movsbl 0x8c8(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x55a0
movq -0x8(%rbp), %rax
movb 0x918(%rax), %al
movb %al, -0x11(%rbp)
movq -0x20(%rbp), %rcx
leaq -0x11(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x55a0
movq -0x8(%rbp), %rax
movq 0x870(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x17050
movq -0x8(%rbp), %rax
movq 0x878(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x17080
movq -0x8(%rbp), %rax
movq 0x8a0(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x17080
movq -0x8(%rbp), %rax
movsbl 0x918(%rax), %eax
cmpl $0x0, %eax
jne 0x15fee
movq -0x8(%rbp), %rax
movq 0x880(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x17080
jmp 0x16048
movq -0x8(%rbp), %rax
movq 0x888(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8b4(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x17080
movq -0x8(%rbp), %rax
movq 0x890(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x17080
movq -0x8(%rbp), %rax
movq 0x898(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %esi
movq -0x20(%rbp), %rdx
callq 0x17080
movq -0x8(%rbp), %rax
movsbl 0x8c8(%rax), %eax
cmpl $0x1, %eax
jle 0x160aa
movq -0x8(%rbp), %rax
movsbl 0x918(%rax), %eax
cmpl $0x0, %eax
jne 0x1607a
movq -0x8(%rbp), %rax
movl 0x8b0(%rax), %eax
movl %eax, -0xd4(%rbp)
jmp 0x1608a
movq -0x8(%rbp), %rax
movl 0x8b4(%rax), %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x8a8(%rax), %rdi
movl -0x24(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x17050
leaq -0x30(%rbp), %rdi
callq 0x170b0
movq -0x8(%rbp), %rax
movq 0x928(%rax), %rdi
callq 0x170d0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x928(%rax), %rdi
callq 0x17130
movq %rax, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x17100
testb $0x1, %al
jne 0x160f6
jmp 0x16164
movq -0x20(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x17160
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x5120
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x13160
jmp 0x16136
leaq -0x60(%rbp), %rdi
callq 0x5170
leaq -0x30(%rbp), %rdi
callq 0x17180
jmp 0x160cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x5170
jmp 0x162fd
movq -0x8(%rbp), %rax
movq 0x948(%rax), %rdi
callq 0x170d0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x948(%rax), %rdi
callq 0x17130
movq %rax, -0x80(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x17100
testb $0x1, %al
jne 0x161a7
jmp 0x16221
movq -0x20(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x17160
movq %rax, %rsi
addq $0x8, %rsi
leaq -0xa0(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x5120
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x13160
jmp 0x161ea
leaq -0xa0(%rbp), %rdi
callq 0x5170
leaq -0x30(%rbp), %rdi
callq 0x17180
jmp 0x16180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5170
jmp 0x162fd
movq -0x8(%rbp), %rax
movq 0x938(%rax), %rdi
callq 0x170d0
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x938(%rax), %rdi
callq 0x17130
movq %rax, -0xb0(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x17100
testb $0x1, %al
jne 0x16270
jmp 0x162e7
movq -0x20(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x17160
movq %rax, %rsi
addq $0x8, %rsi
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x5120
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x13160
jmp 0x162b3
leaq -0xd0(%rbp), %rdi
callq 0x5170
leaq -0x30(%rbp), %rdi
callq 0x17180
jmp 0x16243
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x5170
jmp 0x162fd
movq -0x20(%rbp), %rdi
callq 0x52c0
movb $0x1, %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x5540
nopw %cs:(%rax,%rax)