// File: /workspace/github_c_makefile_star2_O3/zhou-lab[P]tbmate/pack.c
// Function: tbk_write
void tbk_write(
  beddata_t *bd, uint64_t dtype, FILE *out,
  int n, uint8_t *aux,
  FILE *tmp_out, uint64_t *tmp_out_offset,
  conf_pack_t *conf) {

  char *s = bd->s[0];
  switch(DATA_TYPE(dtype)) {
  case DT_INT1: {
    uint8_t d = 0;
    switch(s[0]) {
    case '0': d=0; break;
    case '1': d=1; break;
    default: wzfatal("Error, non-binary data found: %s\n", s); }
    *aux |= d << (n&0x7);
    if((n&0x7)==7) { fwrite(aux, 1, 1, out); *aux=0; }
    break;
  }
  case DT_INT2: {
    uint8_t d = atoi(s);
    *aux |= d << ((n%4)*2);
    if(n%4==3) { fwrite(aux, 1, 1, out); *aux=0; }
    break;
  }
  case DT_INT32: {
    int32_t d;
    if (s[0] == '.' && s[1] == '\0') d = conf->nan;
    else d = atoi(s);
    fwrite(&d, sizeof(int32_t), 1, out);
    break;
  }
  case DT_FLOAT: {
    float d;
    if (s[0] == '.' && s[1] == '\0') d = conf->nan;
    else d = atof(s);
    fwrite(&d, sizeof(float), 1, out);
    break;
  }
  case DT_DOUBLE: {
    double d = atof(s);
    if (s[0] == '.' && s[1] == '\0') d = conf->nan;
    else d = atof(s);
    fwrite(&d, sizeof(double), 1, out);
    break;
  }
  case DT_STRINGF: {
    unsigned n = strlen(s);
    if (n > STRING_MAX(dtype)) s[STRING_MAX(dtype)] = 0;
    fwrite(s, 1, n, out);
    char buf = '\0';
    for (;n < STRING_MAX(dtype);++n) { fwrite(&buf, 1, 1, out); }
    break;
  }
  case DT_STRINGD: {
    int n = strlen(s) + 1;
    fwrite(s, 1, n, tmp_out);
    fwrite(tmp_out_offset, 8, 1, out);
    *tmp_out_offset += strlen(s) + 1;
    break;
  }
  case DT_ONES: {
    uint16_t d;
    if (s[0] == '.' && s[1] == '\0') d = conf->nan;
    else d = float_to_uint16(atof(s));
    fwrite(&d, sizeof(uint16_t), 1, out);
    break;
  }
  case DT_FLOAT_INT: {
    float d; int d2;
    if (s[0] == '.' && s[1] == '\0') d = conf->nan; else d = atof(s);
    s = bd->s[1];
    if (s[0] == '.' && s[1] == '\0') d = conf->nan; else d2 = atoi(s);
    fwrite(&d, sizeof(float), 1, out);
    fwrite(&d2, sizeof(int32_t), 1, out);
    break;
  }
  case DT_FLOAT_FLOAT: {
    float d, d2;
    if (s[0] == '.' && s[1] == '\0') d = conf->nan; else d = atof(s);
    s = bd->s[1];
    if (s[0] == '.' && s[1] == '\0') d = conf->nan; else d2 = atof(s);
    fwrite(&d, sizeof(float), 1, out);
    fwrite(&d2, sizeof(float), 1, out);
    break;
  }
  case DT_NA: wzfatal("Fail to detect data type. Please specify -s explicity.\n"); break;
  default: wzfatal("Unrecognized data type: %d.\n", DATA_TYPE(dtype));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, (%rsp)
movq %rsi, %r12
movq 0x58(%rsp), %rdx
movq (%rdi), %r14
movzbl %r12b, %eax
cmpl $0x1d, %eax
jg 0x96a0
decl %eax
cmpl $0x6, %eax
ja 0x99ad
movq %r8, %r15
movl %ecx, %r13d
leaq 0x44402(%rip), %rcx     # 0x4da68
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl (%r14), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
je 0x9688
cmpl $0x31, %ecx
jne 0x99ba
movl $0x1, %eax
andl $0x7, %r13d
movl %r13d, %ecx
shll %cl, %eax
orb (%r15), %al
movb %al, (%r15)
cmpl $0x7, %r13d
jmp 0x9858
movq %rdi, %rbp
cmpl $0x1f, %eax
jg 0x9705
cmpl $0x1e, %eax
je 0x97ad
cmpl $0x1f, %eax
jne 0x99ad
cmpb $0x2e, (%r14)
jne 0x96cb
cmpb $0x0, 0x1(%r14)
je 0x9967
movq %rdx, %r15
movq %r14, %rdi
callq 0x32f0
cvtsd2ss %xmm0, %xmm0
movq (%rsp), %rbx
movss %xmm0, 0x8(%rsp)
movq 0x8(%rbp), %rdi
cmpb $0x2e, (%rdi)
jne 0x96f7
cmpb $0x0, 0x1(%rdi)
je 0x9916
callq 0x3550
movl %eax, 0x14(%rsp)
jmp 0x9921
cmpl $0x20, %eax
jne 0x999a
cmpb $0x2e, (%r14)
jne 0x971f
cmpb $0x0, 0x1(%r14)
je 0x9973
movq %rdx, %r15
movq %r14, %rdi
callq 0x32f0
cvtsd2ss %xmm0, %xmm0
movq (%rsp), %rbx
movss %xmm0, 0x8(%rsp)
movq 0x8(%rbp), %rdi
cmpb $0x2e, (%rdi)
jne 0x974b
cmpb $0x0, 0x1(%rdi)
je 0x9916
callq 0x32f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
jmp 0x9921
cmpb $0x2e, (%r14)
jne 0x9770
cmpb $0x0, 0x1(%r14)
je 0x995e
movq %r14, %rdi
callq 0x32f0
leaq 0x8(%rsp), %rdi
movsd %xmm0, (%rdi)
movl $0x8, %esi
jmp 0x981d
cmpb $0x2e, (%r14)
jne 0x979c
cmpb $0x0, 0x1(%r14)
je 0x997f
movq %r14, %rdi
callq 0x3550
leaq 0x8(%rsp), %rdi
movl %eax, (%rdi)
jmp 0x9818
cmpb $0x2e, (%r14)
jne 0x97be
cmpb $0x0, 0x1(%r14)
je 0x9988
movq %r14, %rdi
callq 0x32f0
cvtsd2ss %xmm0, %xmm0
addss 0x44292(%rip), %xmm0    # 0x4da64
mulss 0x43a6a(%rip), %xmm0    # 0x4d244
callq 0x30f0
cvttss2si %xmm0, %eax
leaq 0x8(%rsp), %rdi
movw %ax, (%rdi)
movl $0x2, %esi
jmp 0x981d
cmpb $0x2e, (%r14)
jne 0x9803
cmpb $0x0, 0x1(%r14)
je 0x9991
movq %r14, %rdi
callq 0x32f0
cvtsd2ss %xmm0, %xmm0
leaq 0x8(%rsp), %rdi
movss %xmm0, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq (%rsp), %rcx
jmp 0x994a
movq %r14, %rdi
callq 0x3550
leal 0x3(%r13), %ecx
testl %r13d, %r13d
cmovnsl %r13d, %ecx
andl $-0x4, %ecx
subl %ecx, %r13d
leal (,%r13,2), %ecx
shll %cl, %eax
orb (%r15), %al
movb %al, (%r15)
cmpl $0x3, %r13d
movq (%rsp), %rsi
jne 0x994f
movsbl %al, %edi
callq 0x3350
movb $0x0, (%r15)
jmp 0x994f
movq %r9, %rbx
movq 0x50(%rsp), %r15
movq %r14, %rdi
callq 0x3380
incl %eax
movslq %eax, %rdx
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, %rcx
callq 0x3770
movl $0x8, %esi
movl $0x1, %edx
movq %r15, %rdi
movq (%rsp), %rcx
callq 0x3770
movq %r14, %rdi
callq 0x3380
movq (%r15), %rcx
addq %rcx, %rax
incq %rax
movq %rax, (%r15)
jmp 0x994f
movq %r14, %rdi
callq 0x3380
movq %rax, %rbx
movl %ebx, %r15d
shrq $0x8, %r12
cmpq %r12, %r15
jbe 0x98e3
movb $0x0, (%r14,%r12)
movl $0x1, %esi
movq %r14, %rdi
movq %r15, %rdx
movq (%rsp), %r14
movq %r14, %rcx
callq 0x3770
cmpq %r15, %r12
jbe 0x994f
incl %ebx
xorl %edi, %edi
movq %r14, %rsi
callq 0x3350
movl %ebx, %eax
incl %ebx
cmpq %rax, %r12
ja 0x9901
jmp 0x994f
movss (%r15), %xmm0
movss %xmm0, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3770
leaq 0x14(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3770
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cvtss2sd (%rdx), %xmm0
jmp 0x9778
movq %rdx, %r15
movss (%rdx), %xmm0
jmp 0x96da
movq %rdx, %r15
movss (%rdx), %xmm0
jmp 0x972e
cvttss2si (%rdx), %eax
jmp 0x97a4
movss (%rdx), %xmm0
jmp 0x97df
movss (%rdx), %xmm0
jmp 0x980f
cmpl $0x63, %eax
jne 0x99ad
leaq 0x44149(%rip), %rdi     # 0x4daef
xorl %eax, %eax
callq 0x9585
movzbl %r12b, %esi
leaq 0x43988(%rip), %rdi     # 0x4d340
jmp 0x99c4
leaq 0x4410c(%rip), %rdi     # 0x4dacd
movq %r14, %rsi
xorl %eax, %eax
callq 0x9585