// File: /workspace/github_c_makefile_star2_O2/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 0x705a
movq %rdx, %r14
cmpw $0x0, (%rdx)
jne 0x7079
andq $0x0, 0x8(%r14)
leal 0x2(%rsi), %eax
movq 0x8(%rdi), %r15
pushq $-0x1
popq %rbx
cmpq %rax, %r15
jbe 0x6fd1
movq (%rdi), %r12
movl %esi, %r13d
movzwl (%r12,%r13), %eax
rolw $0x8, %ax
movw %ax, (%r14)
testw %ax, %ax
je 0x6fc6
movzwl %ax, %ebp
leal (%rsi,%rbp), %eax
addl $0x4, %eax
cltq
cmpq %rax, %r15
jbe 0x6fd1
addq %r12, %r13
movzbl 0x2(%r13), %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 0x6fd1
addl $0x3, %esi
incl %ebp
imull %ebp, %eax
addl %esi, %eax
cmpq %rax, %r15
jbe 0x6fd1
leal (,%rbp,4), %edi
callq 0x4160
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x7000
addq $0x3, %r13
movl %ebp, %ecx
movl 0x4(%r14), %edx
pushq $0x1
popq %r8
xorl %esi, %esi
decl %edx
leaq 0x186b(%rip), %rdi      # 0x87b8
cmpq %rsi, %rcx
je 0x6fe2
cmpl $0x3, %edx
ja 0x7098
movslq (%rdi,%rdx,4), %r9
addq %rdi, %r9
jmpq *%r9
movzbl (%r13), %r9d
incq %r13
jmp 0x6fb5
movzbl (%r13), %r9d
shll $0x10, %r9d
movzbl 0x1(%r13), %r10d
shll $0x8, %r10d
orl %r9d, %r10d
movzbl 0x2(%r13), %r9d
orl %r10d, %r9d
addq $0x3, %r13
jmp 0x6fb5
movl (%r13), %r9d
bswapl %r9d
addq $0x4, %r13
jmp 0x6fb5
movzwl (%r13), %r9d
rolw $0x8, %r9w
movzwl %r9w, %r9d
addq $0x2, %r13
cmpl %r8d, %r9d
jb 0x702c
movl %r9d, (%rax,%rsi,4)
incq %rsi
movl %r9d, %r8d
jmp 0x6f4d
leaq (%r12,%r13), %rbx
addq $0x2, %rbx
subl %r12d, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x10(%r14)
movl %r8d, %eax
addq %r13, %rax
notq %r12
addq %rax, %r12
movslq %r12d, %rbx
cmpq %r15, %rbx
pushq $-0x1
popq %rax
cmoval %eax, %ebx
jmp 0x6fd1
movq 0x5fd9(%rip), %rax      # 0xcfe0
movq (%rax), %r14
callq 0x4030
movl (%rax), %edi
callq 0x4070
leaq 0x124e(%rip), %rsi      # 0x826b
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4190
jmp 0x6fd1
movq %rax, %rdi
callq 0x4140
andq $0x0, 0x8(%r14)
movq 0x5fa0(%rip), %rax      # 0xcfe0
movq (%rax), %rcx
leaq 0x1ae5(%rip), %rdi      # 0x8b2f
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
callq 0x4200
jmp 0x6fd1
leaq 0x1a84(%rip), %rdi      # 0x8ae5
leaq 0x1055(%rip), %rsi      # 0x80bd
leaq 0x1a7a(%rip), %rcx      # 0x8ae9
movl $0x18e, %edx            # imm = 0x18E
callq 0x40d0
leaq 0x1aa1(%rip), %rdi      # 0x8b21
leaq 0x1036(%rip), %rsi      # 0x80bd
leaq 0x1a5b(%rip), %rcx      # 0x8ae9
movl $0x18f, %edx            # imm = 0x18F
callq 0x40d0
leaq 0x2977(%rip), %rdi      # 0x9a16
leaq 0x1a94(%rip), %rsi      # 0x8b3a
leaq 0x1a99(%rip), %rcx      # 0x8b46
pushq $0x49
popq %rdx
callq 0x40d0
nopl (%rax)