// File: /workspace/github_c_makefile_star2_O1/felipelouza[P]egap/./blocks.h
// Function: merge_sls
static void merge_sls(solidBlock *s, liquidBlock *b, solidBlock *z, solidBlockFile *sf) {
  // showBlock(s,NULL,0); showBlock(z,NULL,0); showLiquid(b);
  assert(s && z && b && !b->empty);
  assert(s->endsAt==b->beginsAt && b->endsAt==z->beginsAt);
  customInt ssize = s->endsAt - s->beginsAt;
  customInt zsize = z->endsAt - z->beginsAt;
  bool zreduced = false;
  // --- merge occs 
  if(ssize + zsize + (b->endsAt - b->beginsAt) <= SMALLSOLID_LIMIT){
    for (int c = 0; c < b->occ_size; ++c) // all blocks are small 
      s->smallOcc[c] += z->smallOcc[c] + (smallSolidInt) b->occ[c];
  } 
  else if(ssize>SMALLSOLID_LIMIT && zsize>SMALLSOLID_LIMIT) {
      for (int c = 0; c < b->occ_size; ++c) // all blocks are large  
        s->occ[c] += z->occ[c] + b->occ[c];
  }
  else { // mixed small/large blocks
    if(zsize>SMALLSOLID_LIMIT) {// s must be  small, swap with z
      customInt *tmp = z->occ; z->smallOcc = s->smallOcc; s->occ = tmp; zreduced=true;
    }
    else {  // z is small, s can be small or large 
      if(ssize<=SMALLSOLID_LIMIT)  // if s is small enlarge it
        block_inflate(s,sf);
    }
    // now s is large and z is small
    for (int c = 0; c < b->occ_size; ++c) 
        s->occ[c] += z->smallOcc[c] + b->occ[c];
  }
  // ----  update endpoints and nextBlock
  s->endsAt = z->endsAt;
  s->nextBlock = z->nextBlock;
  // --- clear b and free z
  b->empty = true;
  memset(b->occ, 0, (b->occ_size) * sizeof(customInt));
  if(zreduced) z->endsAt = z->beginsAt; // a large z got a smallocc from s, make it appear small 
  block_free(z,sf);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %r15
movq 0x8(%rdi), %rax
subq (%rdi), %rax
movq %rdx, %rbx
movq 0x8(%rdx), %rdx
subq (%rbx), %rdx
movq %rsi, %r12
leaq (%rdx,%rax), %rsi
addq 0x8(%r12), %rsi
movq %rcx, %r14
subq (%r12), %rsi
cmpq $0xffff, %rsi           # imm = 0xFFFF
ja 0xbb91
movslq 0x18(%r12), %rax
testq %rax, %rax
jle 0xbbdd
movq 0x20(%r12), %rcx
xorl %edx, %edx
movq 0x10(%rbx), %rsi
movzwl (%rsi,%rdx,2), %esi
addw (%rcx,%rdx,8), %si
movq 0x10(%r15), %rdi
addw %si, (%rdi,%rdx,2)
incq %rdx
cmpq %rdx, %rax
jne 0xbb73
jmp 0xbbdd
movl $0x10000, %ecx          # imm = 0x10000
cmpq %rcx, %rax
setb %sil
cmpq %rcx, %rdx
setae %bpl
setb %cl
orb %sil, %cl
jne 0xbc4e
movslq 0x18(%r12), %rax
testq %rax, %rax
jle 0xbbdd
movq 0x20(%r12), %rcx
xorl %edx, %edx
movq 0x10(%rbx), %rsi
movq (%rcx,%rdx,8), %rdi
addq (%rsi,%rdx,8), %rdi
movq 0x10(%r15), %rsi
addq %rdi, (%rsi,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xbbc1
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r15)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movb $0x1, 0x2c(%r12)
movq 0x20(%r12), %rdi
movslq 0x18(%r12), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x2150
testb %bpl, %bpl
je 0xbc16
movq (%rbx), %rax
movq %rax, 0x8(%rbx)
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq (%rbx), %rax
xorl %edx, %edx
cmpq $0x10000, %rax          # imm = 0x10000
setb %dl
movq 0x20(%r14,%rdx,8), %rax
movq %rax, (%rcx)
movq %rcx, 0x20(%r14,%rdx,8)
movq 0x18(%r14), %rax
movq %rax, 0x18(%rbx)
movq %rbx, 0x18(%r14)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x10000, %rdx          # imm = 0x10000
jb 0xbc69
movq 0x10(%rbx), %rax
movq 0x10(%r15), %rcx
movq %rcx, 0x10(%rbx)
movq %rax, 0x10(%r15)
jmp 0xbc7c
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0xbc7c
movq %r15, %rdi
movq %r14, %rsi
callq 0xb796
movslq 0x18(%r12), %rax
testq %rax, %rax
jle 0xbbdf
movq 0x20(%r12), %rcx
xorl %edx, %edx
movq 0x10(%rbx), %rsi
movzwl (%rsi,%rdx,2), %esi
addq (%rcx,%rdx,8), %rsi
movq 0x10(%r15), %rdi
addq %rsi, (%rdi,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xbc91
jmp 0xbbdf