// File: /workspace/github_c_makefile_star2_O1/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 0x54fc
movq %rdi, %r14
leaq 0x160(%rdi), %r15
xorl %ebp, %ebp
movl 0xddc3(%rip), %eax      # 0x13198
decl %eax
cmpl %eax, 0x28(%r14)
jge 0x54fa
movslq 0xddb4(%rip), %rax      # 0x1319c
leaq (%rax,%rax,2), %rax
leaq 0x20(,%rax,8), %rdi
callq *(%r14)
testq %rax, %rax
je 0x54fa
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 0x5462
addq $0x2, %rdx
movq 0x20(%r14), %rax
movq -0x10(%rax,%rdx,8), %rdi
movq -0x8(%rax,%rdx,8), %rsi
cmpq %rsi, %rdi
jbe 0x5462
movq %rdi, -0x8(%rax,%rdx,8)
movq 0x20(%r14), %rax
movq %rsi, -0x10(%rax,%rdx,8)
decq %rdx
cmpq $0x1, %rdx
jg 0x5438
movslq 0xdd33(%rip), %rax      # 0x1319c
addq %rax, 0x168(%r14)
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdx
addq $-0x18, %rdx
movq %rcx, %rdi
cmpq %rdx, %rcx
ja 0x54a8
movq %rcx, %rsi
movl $0x0, (%rsi)
leaq 0x18(%rsi), %rdi
movq %rdi, 0x10(%rsi)
movq 0x90(%r14), %r8
movq %r8, 0x8(%rsi)
movq %rdi, %rsi
cmpq %rdx, %rdi
jbe 0x5487
movq 0x90(%r14), %rsi
movq 0x160(%r14), %rdx
cmpq %rsi, %rdx
sete %r8b
cmpq %rdx, %rdi
setb %dil
orb %r8b, %dil
je 0x54ce
movq %r15, %rdi
jmp 0x54e3
movq %rdx, %rdi
movq 0x10(%rdx), %rdx
cmpq %rsi, %rdx
je 0x54df
cmpq %rdx, %rcx
ja 0x54ce
addq $0x10, %rdi
leaq (%rcx,%rax,8), %rax
movq %rdx, -0x8(%rax)
movq %rcx, (%rdi)
incl %ebp
cmpl %ebx, %ebp
jne 0x53cf
jmp 0x54fc
movl %ebp, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq