// File: /workspace/github_c_makefile_star2_O3/RodionGork[P]tinyscheme/scheme.c
// Function: alloc_cellseg
static int alloc_cellseg(scheme * sc, int n) {
  pointer newp;
  pointer last;
  pointer p;
  char *cp;
  long i;
  int k;
  int adj = ADJ;

  if (adj < sizeof(struct cell)) {
    adj = sizeof(struct cell);
  }
  for (k = 0; k < n; k++) {
    if (sc->last_cell_seg >= cell_nsegment - 1)
      return k;
    cp = (char *) sc->malloc(cell_segsize * sizeof(struct cell) + adj);
    if (cp == 0)
      return k;
    i = ++sc->last_cell_seg;
    sc->alloc_seg[i] = cp;
    /* adjust in TYPE_BITS-bit boundary */
    if (((unsigned long) cp) % adj != 0) {
      cp = (char *) (adj * ((unsigned long) cp / adj + 1));
    }
    /* insert new segment in address order */
    newp = (pointer) cp;
    sc->cell_seg[i] = newp;
    while (i > 0 && sc->cell_seg[i - 1] > sc->cell_seg[i]) {
      p = sc->cell_seg[i];
      sc->cell_seg[i] = sc->cell_seg[i - 1];
      sc->cell_seg[--i] = p;
    }
    sc->fcells += cell_segsize;
    last = newp + cell_segsize - 1;
    for (p = newp; p <= last; p++) {
      typeflag(p) = 0;
      cdr(p) = p + 1;
      car(p) = sc->NIL;
    }
    /* insert new cells in address order on free list */
    if (sc->free_cell == sc->NIL || p < sc->free_cell) {
      cdr(last) = sc->free_cell;
      sc->free_cell = newp;
    } else {
      p = sc->free_cell;
      while (cdr(p) != sc->NIL && newp > cdr(p))
        p = cdr(p);
      cdr(last) = cdr(p);
      cdr(p) = newp;
    }
  }
  return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
testl %esi, %esi
jle 0x54b4
movq %rdi, %r14
leaq 0x160(%rdi), %r15
xorl %ebp, %ebp
movl 0xde0a(%rip), %eax      # 0x13198
decl %eax
cmpl %eax, 0x28(%r14)
jge 0x54b2
movslq 0xddfb(%rip), %rax      # 0x1319c
leaq (%rax,%rax,2), %rax
leaq 0x20(,%rax,8), %rdi
callq *(%r14)
testq %rax, %rax
je 0x54b2
movslq 0x28(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rax, %rcx
andq $-0x20, %rcx
addq $0x20, %rcx
testb $0x1f, %al
cmoveq %rax, %rcx
movl %esi, 0x28(%r14)
movq 0x18(%r14), %rsi
movq %rax, 0x8(%rsi,%rdx,8)
movq 0x20(%r14), %rax
movq %rcx, 0x8(%rax,%rdx,8)
testq %rdx, %rdx
js 0x541b
addq $0x2, %rdx
movq 0x20(%r14), %rax
movq -0x10(%rax,%rdx,8), %rdi
movq -0x8(%rax,%rdx,8), %rsi
cmpq %rsi, %rdi
jbe 0x541b
movq %rdi, -0x8(%rax,%rdx,8)
movq 0x20(%r14), %rax
movq %rsi, -0x10(%rax,%rdx,8)
decq %rdx
cmpq $0x1, %rdx
jg 0x53f1
movslq 0xdd7a(%rip), %rax      # 0x1319c
addq %rax, 0x168(%r14)
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rsi
addq $-0x18, %rsi
movq %rcx, %r8
cmpq %rsi, %rcx
jbe 0x5449
movq 0x90(%r14), %rdx
movq %rcx, %rdi
jmp 0x546b
movl $0x0, (%r8)
leaq 0x18(%r8), %rdi
movq %rdi, 0x10(%r8)
movq 0x90(%r14), %rdx
movq %rdx, 0x8(%r8)
movq %rdi, %r8
cmpq %rsi, %rdi
jbe 0x5449
movq (%r15), %rsi
cmpq %rdx, %rsi
sete %r8b
cmpq %rsi, %rdi
setb %dil
orb %r8b, %dil
je 0x5486
movq %r15, %rdi
jmp 0x549b
movq %rsi, %rdi
movq 0x10(%rsi), %rsi
cmpq %rdx, %rsi
je 0x5497
cmpq %rsi, %rcx
ja 0x5486
addq $0x10, %rdi
leaq (%rcx,%rax,8), %rax
movq %rsi, -0x8(%rax)
movq %rcx, (%rdi)
incl %ebp
cmpl %ebx, %ebp
jne 0x5388
jmp 0x54b4
movl %ebp, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq