// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x8cac
jmp 0x8ccb
leaq 0x1eda(%rip), %rdi      # 0xab8d
leaq 0x1403(%rip), %rsi      # 0xa0bd
movl $0x18e, %edx            # imm = 0x18E
leaq 0x1ecb(%rip), %rcx      # 0xab91
callq 0x40d0
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0x8cd9
jmp 0x8cf8
leaq 0x1ee9(%rip), %rdi      # 0xabc9
leaq 0x13d6(%rip), %rsi      # 0xa0bd
movl $0x18f, %edx            # imm = 0x18F
leaq 0x1e9e(%rip), %rcx      # 0xab91
callq 0x40d0
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movl -0x14(%rbp), %eax
addl $0x2, %eax
cltq
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x8d22
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f35
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x8f40
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0x8d69
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x4(%rbp)
jmp 0x8f35
movl -0x14(%rbp), %eax
addl $0x3, %eax
movq -0x20(%rbp), %rcx
movzwl (%rcx), %ecx
addl %ecx, %eax
addl $0x1, %eax
cltq
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x8d93
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f35
leaq -0x28(%rbp), %rdi
callq 0x8c40
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x8dbb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f35
movl -0x14(%rbp), %eax
addl $0x3, %eax
movq -0x20(%rbp), %rcx
movzwl (%rcx), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rdx
imull 0x4(%rdx), %ecx
addl %ecx, %eax
movl %eax, %eax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0x8ded
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f35
jmp 0x8def
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x4170
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x8e56
movq 0x61be(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
callq 0x4030
movl (%rax), %edi
callq 0x4070
movq -0x48(%rbp), %rdi
movq %rax, %rdx
leaq 0x142a(%rip), %rsi      # 0xa26d
movb $0x0, %al
callq 0x4190
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f35
movl $0x1, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x8ef1
movq -0x20(%rbp), %rax
movl 0x4(%rax), %esi
leaq -0x28(%rbp), %rdi
callq 0x8f80
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x8ece
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x4150
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movq 0x612c(%rip), %rax      # 0xefe0
movq (%rax), %rdi
leaq 0x1d19(%rip), %rsi      # 0xabd7
movb $0x0, %al
callq 0x4190
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f35
movl -0x38(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x38(%rbp), %edx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x8e71
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addq %rcx, %rax
addq $-0x1, %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x8f2f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f35
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop