// File: /workspace/github_c_makefile_star2_O3/smilingthax[P]libfontembed/cff.c
// Function: cff_load_index
static int cff_load_index(CFF_FILE *cff,int pos,struct CFF_Index *idx) // {{{
{
  assert(idx);
  assert(idx->count==0); // not already initialized

  idx->offset=NULL;
  if (pos+2>=cff->length) {
    return -1;
  }
  const char *buf=cff->font+pos;
  idx->count=cff_read_Card16(&buf);
  if (idx->count==0) {
    return buf-cff->font; // pos+2
  }

  if (pos+3+idx->count+1>=cff->length) {
    return -1;
  }
  idx->offSize=cff_read_OffSize(&buf);
  if (idx->offSize==OFFERR) {
    return -1;
  } else if (pos+3+(idx->count+1)*idx->offSize>=cff->length) {
    return -1;
  }

  idx->offset=malloc((idx->count+1)*sizeof(*idx->offset));
  if (!idx->offset) {
    fprintf(stderr,"Bad alloc: %s\n", strerror(errno));
    return -1;
  }

  uint32_t last=1;
  int iA;
  const int len=idx->count+1;
  for (iA=0;iA<len;iA++) {
    const uint32_t res=cff_read_Offset(&buf,idx->offSize);
    if (res<last) {
      free(idx->offset);
      idx->offset=NULL;
      fprintf(stderr,"Bad INDEX\n");
      return -1;
    }
    last=res;
    idx->offset[iA]=res;
  }

  idx->dataStart=buf;

  // pos+3+(idx->count+1)*idx->offSize+last-1;
  const int ret=buf+last-1-cff->font;
  if (ret>cff->length) { // == is ok (file ends directly after us)
    return -1;
  }
  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdx, %rdx
je 0x73c0
movq %rdx, %r14
cmpw $0x0, (%rdx)
jne 0x73df
movq $0x0, 0x8(%r14)
leal 0x2(%rsi), %eax
movq 0x8(%rdi), %r12
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq %rax, %r12
jbe 0x739e
movq (%rdi), %r13
movl %esi, %ebp
movzwl (%r13,%rbp), %eax
rolw $0x8, %ax
movw %ax, (%r14)
testw %ax, %ax
je 0x7390
movzwl %ax, %r15d
leal (%r15,%rsi), %eax
addl $0x4, %eax
cltq
cmpq %rax, %r12
jbe 0x739e
addq %r13, %rbp
movzbl 0x2(%rbp), %eax
leal -0x5(%rax), %ecx
xorl %edx, %edx
cmpb $-0x4, %cl
cmovael %eax, %edx
movzbl %dl, %eax
movl %eax, 0x4(%r14)
testb %al, %al
je 0x739e
addl $0x3, %esi
incl %r15d
imull %r15d, %eax
addl %esi, %eax
cmpq %rax, %r12
jbe 0x739e
leaq 0x8(%r14), %rax
movq %rax, (%rsp)
leal (,%r15,4), %edi
callq 0x4150
movq (%rsp), %rsi
movq %rax, (%rsi)
testq %rax, %rax
je 0x73af
addq $0x3, %rbp
movl %r15d, %ecx
movl 0x4(%r14), %edx
movl $0x1, %r8d
xorl %r11d, %r11d
decl %edx
leaq 0x14bb(%rip), %rdi      # 0x87b8
cmpl $0x3, %edx
ja 0x73fe
movslq (%rdi,%rdx,4), %r9
addq %rdi, %r9
jmpq *%r9
movzbl (%rbp), %r9d
incq %rbp
jmp 0x735c
movzbl (%rbp), %r9d
shll $0x10, %r9d
movzbl 0x1(%rbp), %r10d
shll $0x8, %r10d
orl %r9d, %r10d
movzbl 0x2(%rbp), %r9d
orl %r10d, %r9d
addq $0x3, %rbp
jmp 0x735c
movl (%rbp), %r9d
bswapl %r9d
addq $0x4, %rbp
jmp 0x735c
movzwl (%rbp), %r9d
rolw $0x8, %r9w
movzwl %r9w, %r9d
addq $0x2, %rbp
cmpl %r8d, %r9d
jb 0x73b6
movl %r9d, (%rax,%r11,4)
incq %r11
movl %r9d, %r8d
cmpq %r11, %rcx
jne 0x72fd
movq %rbp, 0x10(%r14)
movl %r9d, %eax
notq %r13
addq %rbp, %r13
addq %rax, %r13
movslq %r13d, %rbx
cmpq %r12, %rbx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmoval %eax, %ebx
jmp 0x739e
leaq 0x2(,%rbp), %rbx
addq %r13, %rbx
subl %r13d, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4ac3
jmp 0x739e
movq %rax, %rdi
callq 0x4a99
jmp 0x739e
leaq 0x171e(%rip), %rdi      # 0x8ae5
leaq 0xcef(%rip), %rsi       # 0x80bd
leaq 0x1714(%rip), %rcx      # 0x8ae9
movl $0x18e, %edx            # imm = 0x18E
callq 0x40c0
leaq 0x173b(%rip), %rdi      # 0x8b21
leaq 0xcd0(%rip), %rsi       # 0x80bd
leaq 0x16f5(%rip), %rcx      # 0x8ae9
movl $0x18f, %edx            # imm = 0x18F
callq 0x40c0
leaq 0x2629(%rip), %rdi      # 0x9a2e
leaq 0x172e(%rip), %rsi      # 0x8b3a
leaq 0x1733(%rip), %rcx      # 0x8b46
movl $0x49, %edx
callq 0x40c0
nopl (%rax)