// File: onai[P]npio/./npio.h
// Function: npio_load_data2(npio_Array*, int)
static inline int npio_load_data2(npio_Array* array, int swap_bytes)
{
  /* These macros work on both GCC and CLANG without an additional include.
     Right now we do not support any other endianness than big and little.
     Numpy also only supports these two ('<' and '>'). */
  static const int little_endian = (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__);
  size_t data_offset;
  size_t sz;
  ssize_t nr;

  /* Check that the header_len matches the alignment requirements
     of the format */
  data_offset = array->header_len + 6 + (array->major_version == 1 ? 4 : 6);
  if (data_offset % 16)
    return EINVAL;

  if (array->_buf)
  {
    /* Check that the indicated data is within the mapped bounds. */
    /* We are also checking here that there is no trailing data. */
    if (data_offset + npio_array_memsize(array) != array->_buf_size)
      return EINVAL;

    /* Set the data pointer to the start of data */
    array->data = (char*) array->_buf + data_offset;
  }
  else
  {
    /* we must allocate memory and read in the data */
    sz = array->size * array->bit_width / 8;
    if ((ssize_t) sz < 0)
      return ERANGE;
    array->data = malloc(sz);
    if (!array->data)
      return ENOMEM;
    nr = read(array->_fd, array->data, sz);
    if (nr < 0)
      return errno;
    if (nr != (ssize_t) sz)
      return EINVAL;
  }

  /* Swap bytes if necessary */
  if (swap_bytes && little_endian != array->little_endian)
  {
    array->little_endian = little_endian;
    return npio_swap_bytes(array->size, array->bit_width, array->data);
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x6, %rax
movq -0x10(%rbp), %rcx
movsbl (%rcx), %esi
movl $0x6, %ecx
movl $0x4, %edx
cmpl $0x1, %esi
cmovel %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
andq $0xf, %rax
cmpq $0x0, %rax
je 0x2346
movl $0x16, -0x4(%rbp)
jmp 0x2481
movq -0x10(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x239b
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2490
movq %rax, %rcx
movq -0x38(%rbp), %rax
addq %rcx, %rax
movq -0x10(%rbp), %rcx
cmpq 0x60(%rcx), %rax
je 0x2382
movl $0x16, -0x4(%rbp)
jmp 0x2481
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
addq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x2439
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x40(%rcx), %rcx
imulq %rcx, %rax
shrq $0x3, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jge 0x23ca
movl $0x22, -0x4(%rbp)
jmp 0x2481
movq -0x28(%rbp), %rdi
callq 0x10e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x23f5
movl $0xc, -0x4(%rbp)
jmp 0x2481
movq -0x10(%rbp), %rax
movl 0x50(%rax), %edi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x28(%rbp), %rdx
callq 0x10f0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0x2424
callq 0x1030
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x2481
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x2437
movl $0x16, -0x4(%rbp)
jmp 0x2481
jmp 0x2439
cmpl $0x0, -0x14(%rbp)
je 0x247a
movq -0x10(%rbp), %rcx
movl $0x1, %eax
cmpl 0x34(%rcx), %eax
je 0x247a
movq -0x10(%rbp), %rax
movl $0x1, 0x34(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdx
callq 0x24c0
movl %eax, -0x4(%rbp)
jmp 0x2481
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)