// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x1038, %rsp           # imm = 0x1038
movq %rdi, 0x1030(%rsp)
movq %rsi, 0x1028(%rsp)
movq 0x1030(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x1030(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
leaq 0x20(%rsp), %rdi
movq 0x1028(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x8, %esi
movl $0x2, %edx
callq 0x2380
movl %eax, 0x1c(%rsp)
cmpl $0x2, 0x1c(%rsp)
je 0x8e1f
leaq 0xd244(%rip), %rdi      # 0x1605e
callq 0x3ce0
movq 0x1030(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x1030(%rsp), %rcx
subq (%rcx), %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x8e92
movq 0x1030(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x1028(%rsp), %rax
movslq 0x10(%rax), %rdx
movq 0x1028(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x2, %esi
callq 0x2380
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x1028(%rsp), %rcx
cmpl 0x10(%rcx), %eax
je 0x8e8d
leaq 0xd1f7(%rip), %rdi      # 0x1607f
callq 0x3ce0
jmp 0x8fb6
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x1028(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x8f6c
movq 0x1030(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0xc(%rsp), %rcx
movabsq $0x10000000000, %rdx    # imm = 0x10000000000
cmpq %rdx, (%rax,%rcx,8)
jb 0x8f01
movq 0x10117(%rip), %rax     # 0x18ff8
movq (%rax), %rdi
leaq 0xbd5b(%rip), %rsi      # 0x14c46
movl $0x5, %edx
movb $0x0, %al
callq 0x21b0
movl $0x1, %edi
callq 0x2370
movl $0x0, 0x8(%rsp)
cmpl $0x5, 0x8(%rsp)
jge 0x8f5a
movq 0x1030(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x8(%rsp), %ecx
shll $0x3, %ecx
movl %ecx, %ecx
shrq %cl, %rax
andq $0xff, %rax
movb %al, %dl
movq 0x10(%rsp), %rax
imull $0x5, 0xc(%rsp), %ecx
addl 0x8(%rsp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x8f09
jmp 0x8f5c
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x8ea4
movq 0x10(%rsp), %rdi
movq 0x1028(%rsp), %rax
movslq 0x10(%rax), %rdx
movq 0x1028(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x5, %esi
callq 0x2380
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x1028(%rsp), %rcx
cmpl 0x10(%rcx), %eax
je 0x8fb4
leaq 0xd0f7(%rip), %rdi      # 0x160a6
callq 0x3ce0
jmp 0x8fb6
movq 0x1030(%rsp), %rdi
movq 0x1028(%rsp), %rsi
callq 0x8990
addq $0x1038, %rsp           # imm = 0x1038
retq
nopw %cs:(%rax,%rax)