// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movzbl -0x10(%rbp), %eax
decq %rax
movq %rax, -0x78(%rbp)
subq $0x62, %rax
ja 0x8937
movq -0x78(%rbp), %rax
leaq 0x6d72f(%rip), %rcx     # 0x75bd4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, -0x39(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x7c(%rbp)
subl $0x30, %eax
je 0x84cd
jmp 0x84c3
movl -0x7c(%rbp), %eax
subl $0x31, %eax
je 0x84d3
jmp 0x84d9
movb $0x0, -0x39(%rbp)
jmp 0x84eb
movb $0x1, -0x39(%rbp)
jmp 0x84eb
movq -0x38(%rbp), %rsi
leaq 0x6d8de(%rip), %rdi     # 0x75dc2
movb $0x0, %al
callq 0x8390
movzbl -0x39(%rbp), %edx
movl -0x1c(%rbp), %ecx
andl $0x7, %ecx
shll %cl, %edx
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl -0x1c(%rbp), %eax
andl $0x7, %eax
cmpl $0x7, %eax
jne 0x8529
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x3780
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x8950
movq -0x38(%rbp), %rdi
callq 0x3550
movb %al, -0x3a(%rbp)
movzbl -0x3a(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x1c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, %ecx
movl -0x80(%rbp), %edx
shll %ecx
shll %cl, %edx
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl -0x1c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x3, %edx
jne 0x858c
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x3780
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x8950
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x85b7
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x85b7
movq 0x18(%rbp), %rax
cvttss2si (%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x85c3
movq -0x38(%rbp), %rdi
callq 0x3550
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x40(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3780
jmp 0x8950
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x8607
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x8607
movq 0x18(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x8619
movq -0x38(%rbp), %rdi
callq 0x3300
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x44(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3780
jmp 0x8950
movq -0x38(%rbp), %rdi
callq 0x3300
movsd %xmm0, -0x50(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x866f
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x866f
movq 0x18(%rbp), %rax
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x867d
movq -0x38(%rbp), %rdi
callq 0x3300
movsd %xmm0, -0x50(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x50(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x3780
jmp 0x8950
movq -0x38(%rbp), %rdi
callq 0x3380
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x10(%rbp), %rcx
shrq $0x8, %rcx
cmpq %rcx, %rax
jbe 0x86c5
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
shrq $0x8, %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, %edx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x3780
movb $0x0, -0x55(%rbp)
movl -0x54(%rbp), %eax
movq -0x10(%rbp), %rcx
shrq $0x8, %rcx
cmpq %rcx, %rax
jae 0x8710
movq -0x18(%rbp), %rcx
leaq -0x55(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x3780
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x86e0
jmp 0x8950
movq -0x38(%rbp), %rdi
callq 0x3380
addq $0x1, %rax
movl %eax, -0x5c(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x5c(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x1, %esi
callq 0x3780
movq 0x10(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x3780
movq -0x38(%rbp), %rdi
callq 0x3380
movq %rax, %rcx
addq $0x1, %rcx
movq 0x10(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x8950
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x8798
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x8798
movq 0x18(%rbp), %rax
cvttss2si (%rax), %eax
movw %ax, -0x5e(%rbp)
jmp 0x87ae
movq -0x38(%rbp), %rdi
callq 0x3300
cvtsd2ss %xmm0, %xmm0
callq 0x8960
movw %ax, -0x5e(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x5e(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x3780
jmp 0x8950
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x87f2
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x87f2
movq 0x18(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x64(%rbp)
jmp 0x8804
movq -0x38(%rbp), %rdi
callq 0x3300
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x8838
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x8838
movq 0x18(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x64(%rbp)
jmp 0x8844
movq -0x38(%rbp), %rdi
callq 0x3550
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x64(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3780
movq -0x18(%rbp), %rcx
leaq -0x68(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3780
jmp 0x8950
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x889f
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x889f
movq 0x18(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x6c(%rbp)
jmp 0x88b1
movq -0x38(%rbp), %rdi
callq 0x3300
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x6c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x88e5
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x88e5
movq 0x18(%rbp), %rax
movss (%rax), %xmm0
movss %xmm0, -0x6c(%rbp)
jmp 0x88f7
movq -0x38(%rbp), %rdi
callq 0x3300
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x70(%rbp)
movq -0x18(%rbp), %rcx
leaq -0x6c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3780
movq -0x18(%rbp), %rcx
leaq -0x70(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3780
jmp 0x8950
leaq 0x6d4b6(%rip), %rdi     # 0x75de4
movb $0x0, %al
callq 0x8390
jmp 0x8950
movq -0x10(%rbp), %rsi
andq $0xff, %rsi
leaq 0x6ca77(%rip), %rdi     # 0x753c0
movb $0x0, %al
callq 0x8390
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)