// File: onai[P]npio/./npio.h
// Function: npio_ph_parse_dict_(npio_Array*, char const*, char const*)
static inline int npio_ph_parse_dict_(npio_Array* array, const char* start, const char* end)
{
  int err;
  char open_quote;
  const char *p = start;
  const char *dtbeg, *dtend;
  size_t dtsz;
  enum {k_descr, k_shape, k_fortran_order} key;

  if (p >= end)
    return EINVAL;

  if (*p++ != '{')
    return EINVAL;

  /* Go through all key-value pairs. */
  while (1)
  {
    p = npio_ph_skip_spaces_(p, end);
    if (p >= end)
      return EINVAL;

    /* are we done? */
    if (*p == '}')
    {
      ++p;
      break;
    }

    /* Expect the open quote of a key */
    if (!npio_ph_is_quote_(open_quote = *p++))
      return EINVAL;

    /* Check for one of the three possible keys */
    if (p + 5 < end && memcmp(p, "descr", 5) == 0)
    {
      key = k_descr;
      p += 5;
    }
    else if (p + 5 < end && memcmp(p, "shape", 5) == 0)
    {
      key = k_shape;
      p += 5;
    }
    else if (p + 13 < end && memcmp(p, "fortran_order", 13) == 0)
    {
      key = k_fortran_order;
      p += 13;
    }
    else
      return EINVAL;

    /* Expect the close quote of the key */
    if (p >= end || *p++ != open_quote)
      return EINVAL;

    /* Get to the colon */
    p = npio_ph_skip_spaces_(p, end);
    if (p >= end || *p++ != ':')
      return EINVAL;

    /* skip any more spaces */
    p = npio_ph_skip_spaces_(p, end);
    if (p == end)
      return EINVAL;

    switch (key)
    {
      case k_descr:
        if (!npio_ph_is_quote_(open_quote = *p++))
          return EINVAL;
        dtbeg = p;
        while (p < end && *p != open_quote)
          ++p;
        dtend = p;
        if (p == end)
          return EINVAL;
        ++p;
        dtsz = dtend - dtbeg;
        array->dtype = (char*) malloc(dtsz + 1);
        memcpy(array->dtype, dtbeg, dtsz);
        array->dtype[dtsz] = 0;
        break;

      case k_fortran_order:
        if (p + 4 < end && memcmp(p, "True", 4) == 0)
        {
          array->fortran_order = 1;
          p += 4;
        }
        else if (p + 5 < end && memcmp(p, "False", 5) == 0)
        {
          array->fortran_order = 0;
          p += 5;
        }
        else
          return EINVAL;
        break;

      case k_shape:
        if ((err = npio_ph_parse_shape_(array, p, end, &p)))
          return err;
        break;
    }

    /* skip any spaces after end of key : value */
    p = npio_ph_skip_spaces_(p, end);

    if (p == end)
      return EINVAL;

    /* grab that separating comma */
    if (*p == ',')
      ++p;

    /* next iteration takes care of any nonsense that might happen here! */
  }

  /* Parse the (very restricted) numpy dtype and return */
  return npio_ph_parse_dtype_(array);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x19c2
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movsbl (%rax), %eax
cmpl $0x7b, %eax
je 0x19e5
movl $0x16, -0x4(%rbp)
jmp 0x1dca
jmp 0x19e7
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1de0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x1a0e
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7d, %eax
jne 0x1a2b
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1dbe
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb (%rax), %al
movb %al, -0x25(%rbp)
movsbl %al, %edi
callq 0x1e40
cmpl $0x0, %eax
jne 0x1a58
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rax
addq $0x5, %rax
cmpq -0x20(%rbp), %rax
jae 0x1a98
movq -0x30(%rbp), %rdi
leaq 0x15f3(%rip), %rsi      # 0x3064
movl $0x5, %edx
callq 0x1080
cmpl $0x0, %eax
jne 0x1a98
movl $0x0, -0x4c(%rbp)
movq -0x30(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x30(%rbp)
jmp 0x1b22
movq -0x30(%rbp), %rax
addq $0x5, %rax
cmpq -0x20(%rbp), %rax
jae 0x1ad5
movq -0x30(%rbp), %rdi
leaq 0x15b9(%rip), %rsi      # 0x306a
movl $0x5, %edx
callq 0x1080
cmpl $0x0, %eax
jne 0x1ad5
movl $0x1, -0x4c(%rbp)
movq -0x30(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x30(%rbp)
jmp 0x1b20
movq -0x30(%rbp), %rax
addq $0xd, %rax
cmpq -0x20(%rbp), %rax
jae 0x1b12
movq -0x30(%rbp), %rdi
leaq 0x1582(%rip), %rsi      # 0x3070
movl $0xd, %edx
callq 0x1080
cmpl $0x0, %eax
jne 0x1b12
movl $0x2, -0x4c(%rbp)
movq -0x30(%rbp), %rax
addq $0xd, %rax
movq %rax, -0x30(%rbp)
jmp 0x1b1e
movl $0x16, -0x4(%rbp)
jmp 0x1dca
jmp 0x1b20
jmp 0x1b22
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x1b46
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movsbl (%rax), %eax
movsbl -0x25(%rbp), %ecx
cmpl %ecx, %eax
je 0x1b52
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1de0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x1b84
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movsbl (%rax), %eax
cmpl $0x3a, %eax
je 0x1b90
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1de0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x1bb7
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
testl %eax, %eax
je 0x1be2
jmp 0x1bc3
movl -0x50(%rbp), %eax
subl $0x1, %eax
je 0x1d56
jmp 0x1bd1
movl -0x50(%rbp), %eax
subl $0x2, %eax
je 0x1ccb
jmp 0x1d7d
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb (%rax), %al
movb %al, -0x25(%rbp)
movsbl %al, %edi
callq 0x1e40
cmpl $0x0, %eax
jne 0x1c0f
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x51(%rbp)
jae 0x1c39
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
movsbl -0x25(%rbp), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x1c42
jmp 0x1c50
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1c17
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x1c6e
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
addq $0x1, %rdi
callq 0x10e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x10c0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x1d7d
movq -0x30(%rbp), %rax
addq $0x4, %rax
cmpq -0x20(%rbp), %rax
jae 0x1d08
movq -0x30(%rbp), %rax
movl (%rax), %eax
subl $0x65757254, %eax       # imm = 0x65757254
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1d08
movq -0x10(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
jmp 0x1d54
movq -0x30(%rbp), %rax
addq $0x5, %rax
cmpq -0x20(%rbp), %rax
jae 0x1d49
movq -0x30(%rbp), %rdi
leaq 0x1362(%rip), %rsi      # 0x3083
movl $0x5, %edx
callq 0x1080
cmpl $0x0, %eax
jne 0x1d49
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x30(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x30(%rbp)
jmp 0x1d52
movl $0x16, -0x4(%rbp)
jmp 0x1dca
jmp 0x1d54
jmp 0x1d7d
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x1e70
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x1d7b
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1dca
jmp 0x1d7d
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x1de0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jne 0x1da1
movl $0x16, -0x4(%rbp)
jmp 0x1dca
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x1db9
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x19e7
movq -0x10(%rbp), %rdi
callq 0x2080
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)