// File: /workspace/github_c_makefile_star2_O2/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 0xb24e
movl 0x18(%r12), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rcx, %rdx
je 0xb29d
movq 0x10(%rbx), %rsi
movzwl (%rsi,%rcx,2), %esi
movq 0x20(%r12), %rdi
addw (%rdi,%rcx,8), %si
movq 0x10(%r15), %rdi
addw %si, (%rdi,%rcx,2)
incq %rcx
jmp 0xb22b
movl $0x10000, %ecx          # imm = 0x10000
cmpq %rcx, %rax
setb %sil
cmpq %rcx, %rdx
setae %bpl
setb %cl
orb %sil, %cl
jne 0xb2e7
movl 0x18(%r12), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rcx, %rdx
je 0xb29d
movq 0x10(%rbx), %rsi
movq 0x20(%r12), %rdi
movq (%rdi,%rcx,8), %rdi
addq (%rsi,%rcx,8), %rdi
movq 0x10(%r15), %rsi
addq %rdi, (%rsi,%rcx,8)
incq %rcx
jmp 0xb27a
xorl %ebp, %ebp
movq 0x8(%rbx), %rcx
movq %rcx, 0x8(%r15)
movq 0x18(%rbx), %rcx
movq %rcx, 0x18(%r15)
movb $0x1, 0x2c(%r12)
movq 0x20(%r12), %rdi
movslq %eax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x2150
testb %bpl, %bpl
je 0xb2d4
movq (%rbx), %rax
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x625f
cmpq $0x10000, %rdx          # imm = 0x10000
jb 0xb302
movq 0x10(%rbx), %rax
movq 0x10(%r15), %rcx
movq %rcx, 0x10(%rbx)
movq %rax, 0x10(%r15)
jmp 0xb315
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0xb315
movq %r15, %rdi
movq %r14, %rsi
callq 0xae60
movl 0x18(%r12), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rcx, %rdx
je 0xb29f
movq 0x10(%rbx), %rsi
movzwl (%rsi,%rcx,2), %esi
movq 0x20(%r12), %rdi
addq (%rdi,%rcx,8), %rsi
movq 0x10(%r15), %rdi
addq %rsi, (%rdi,%rcx,8)
incq %rcx
jmp 0xb326