// File: /workspace/github_c_makefile_star2_O1/felipelouza[P]egap/./blocks.h
// Function: writeBlock
static void writeBlock(solidBlock *s, solidBlockFile *sf)
{
  assert(s!=NULL);
  assert(sf!=NULL && sf->fout!=NULL);
  customInt buffer[SIZE_OF_ALPHABET+MAX_NUMBER_OF_BWTS];
  buffer[0] = s->beginsAt;
  buffer[1] = s->endsAt;
  int e = fwrite(buffer,sizeof(customInt),2,sf->fout);
  if(e!=2) die("tmp file write in writeBlock (1)");
  if (s->endsAt - s->beginsAt <= SMALLSOLID_LIMIT) {
    // small solid block
    e = fwrite(s->smallOcc,sizeof(smallSolidInt),sf->occ_size,sf->fout);
    if(e!=sf->occ_size) die("tmp file write error in writeBlock (2)");
  }  
  else { // large solid block 
    uint8_t *byteBuffer = (uint8_t *) buffer;
    // fill newB->occ using five bytes for entry
    for(int j=0;j<sf->occ_size;j++) {
      if(s->occ[j]>= (1Ull<<(8*POS_SIZE))) {
        fprintf(stderr,"%d bytes per position are not enough. Increase POS_SIZE and recompile\n",POS_SIZE); 
        exit(EXIT_FAILURE);
      }
      for(int i=0;i<POS_SIZE;i++)
        byteBuffer[j*POS_SIZE+i] = (s->occ[j]>>(8*i)) & 0xFF;  
    }
    e= fwrite(byteBuffer,POS_SIZE,sf->occ_size,sf->fout); // read POS_SIZE bytes for customInt
    if(e!=sf->occ_size) die("tmp file write error in writeBlock (3)");
  }
  block_free(s,sf);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movq %rsi, %rbx
movq %rdi, %r14
movdqu (%rdi), %xmm0
movq %rsp, %rdi
movdqa %xmm0, (%rdi)
movq 0x8(%rsi), %rcx
movl $0x8, %esi
movl $0x2, %edx
callq 0x2390
cmpl $0x2, %eax
je 0x698f
leaq 0x9688(%rip), %rdi      # 0x10012
callq 0x3973
movq 0x8(%r14), %rax
subq (%r14), %rax
cmpq $0x10000, %rax          # imm = 0x10000
jae 0x69c9
movq 0x10(%r14), %rdi
movslq 0x10(%rbx), %rdx
movq 0x8(%rbx), %rcx
movl $0x2, %esi
callq 0x2390
cmpl %eax, 0x10(%rbx)
je 0x6ab0
leaq 0x966f(%rip), %rdi      # 0x10033
jmp 0x6aab
movslq 0x10(%rbx), %rdx
testq %rdx, %rdx
jle 0x6a8e
movq 0x10(%r14), %rsi
leaq 0x1(%rsp), %rdi
xorl %r8d, %r8d
movdqa 0x8116(%rip), %xmm0     # 0xeb00
movdqa 0x811e(%rip), %xmm1     # 0xeb10
movdqa 0x8ef6(%rip), %xmm2     # 0xf8f0
pshufd $0xf5, %xmm2, %xmm3     # xmm3 = xmm2[1,1,3,3]
movdqa 0x8119(%rip), %xmm4     # 0xeb20
movq (%rsi,%r8,8), %r9
movq %r9, %rax
shrq $0x28, %rax
jne 0x6aea
movl $0x8, %eax
movq %rdi, %r10
movdqa %xmm0, %xmm5
movdqa %xmm5, %xmm6
pxor %xmm1, %xmm6
movdqa %xmm2, %xmm7
pcmpgtd %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm6     # xmm6 = xmm6[1,1,3,3]
pcmpeqd %xmm3, %xmm6
pand %xmm7, %xmm6
movd %xmm6, %ecx
testb $0x1, %cl
je 0x6a57
leal -0x8(%rax), %ecx
movq %r9, %r11
shrq %cl, %r11
movb %r11b, -0x1(%r10)
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x6a6c
movq %r9, %r11
movl %eax, %ecx
shrq %cl, %r11
movb %r11b, (%r10)
paddq %xmm4, %xmm5
addq $0x2, %r10
addq $0x10, %rax
cmpq $0x38, %rax
jne 0x6a24
incq %r8
addq $0x5, %rdi
cmpq %rdx, %r8
jne 0x6a07
movq 0x8(%rbx), %rcx
movq %rsp, %rdi
movl $0x5, %esi
callq 0x2390
cmpl %eax, 0x10(%rbx)
je 0x6ab0
leaq 0x95af(%rip), %rdi      # 0x1005a
callq 0x3973
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq (%r14), %rax
xorl %edx, %edx
cmpq $0x10000, %rax          # imm = 0x10000
setb %dl
movq 0x20(%rbx,%rdx,8), %rax
movq %rax, (%rcx)
movq %rcx, 0x20(%rbx,%rdx,8)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r14)
movq %r14, 0x18(%rbx)
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r14
retq
callq 0x24e7