/* Generated by Cython 3.0.11 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "/home/runner/work/pysam/pysam/htslib/htslib/bgzf.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/cram.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/faidx.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/hfile.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/hts.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/kstring.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/sam.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/tbx.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/vcf.h",
            "/home/runner/work/pysam/pysam/htslib/htslib/vcfutils.h",
            "/home/runner/work/pysam/pysam/pysam/htslib_util.h",
            "/home/runner/work/pysam/pysam/pysam/pysam_stream.h"
        ],
        "extra_compile_args": [
            "-Wno-unused",
            "-Wno-strict-prototypes",
            "-Wno-sign-compare",
            "-Wno-error=declaration-after-statement"
        ],
        "include_dirs": [
            "pysam",
            "/home/runner/work/pysam/pysam/pysam",
            "/home/runner/work/pysam/pysam/htslib",
            "/home/runner/work/pysam/pysam/samtools",
            "/home/runner/work/pysam/pysam/samtools/lz4",
            "/home/runner/work/pysam/pysam/bcftools",
            "/home/runner/work/pysam/pysam"
        ],
        "language": "c",
        "libraries": [
            "z",
            "lzma",
            "bz2",
            "z",
            "m",
            "curl",
            "crypto",
            "chtslib.cpython-310-x86_64-linux-gnu",
            "cutils.cpython-310-x86_64-linux-gnu"
        ],
        "library_dirs": [
            "/home/runner/work/pysam/pysam/pysam",
            "/home/runner/work/pysam/pysam"
        ],
        "name": "pysam.libcalignmentfile",
        "sources": [
            "pysam/libcalignmentfile.pyx"
        ]
    },
    "module_name": "pysam.libcalignmentfile"
}
END: Cython Metadata */

#ifndef PY_SSIZE_T_CLEAN
#define PY_SSIZE_T_CLEAN
#endif /* PY_SSIZE_T_CLEAN */
#if defined(CYTHON_LIMITED_API) && 0
  #ifndef Py_LIMITED_API
    #if CYTHON_LIMITED_API+0 > 0x03030000
      #define Py_LIMITED_API CYTHON_LIMITED_API
    #else
      #define Py_LIMITED_API 0x03030000
    #endif
  #endif
#endif

#include "Python.h"

    #if PY_MAJOR_VERSION >= 3
      #define __Pyx_PyFloat_FromString(obj)  PyFloat_FromString(obj)
    #else
      #define __Pyx_PyFloat_FromString(obj)  PyFloat_FromString(obj, NULL)
    #endif
    

    #if PY_MAJOR_VERSION <= 2
    #define PyDict_GetItemWithError _PyDict_GetItemWithError
    #endif
    

    #if (PY_VERSION_HEX < 0x030700b1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030600)) && !defined(PyContextVar_Get)
    #define PyContextVar_Get(var, d, v)         ((d) ?             ((void)(var), Py_INCREF(d), (v)[0] = (d), 0) :             ((v)[0] = NULL, 0)         )
    #endif
    
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02070000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.7+ or Python 3.3+.
#else
#if defined(CYTHON_LIMITED_API) && CYTHON_LIMITED_API
#define __PYX_EXTRA_ABI_MODULE_NAME "limited"
#else
#define __PYX_EXTRA_ABI_MODULE_NAME ""
#endif
#define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME
#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
#define CYTHON_HEX_VERSION 0x03000BF0
#define CYTHON_FUTURE_DIVISION 1
#include <stddef.h>
#ifndef offsetof
  #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(_WIN32) && !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #define HAVE_LONG_LONG
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#define __PYX_LIMITED_VERSION_HEX PY_VERSION_HEX
#if defined(GRAALVM_PYTHON)
  /* For very preliminary testing purposes. Most variables are set the same as PyPy.
     The existence of this section does not imply that anything works or is even tested */
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 1
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_TYPE_SPECS
  #define CYTHON_USE_TYPE_SPECS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_GIL
  #define CYTHON_FAST_GIL 0
  #undef CYTHON_METH_FASTCALL
  #define CYTHON_METH_FASTCALL 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3)
  #endif
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #undef CYTHON_USE_MODULE_STATE
  #define CYTHON_USE_MODULE_STATE 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
  #undef CYTHON_USE_FREELISTS
  #define CYTHON_USE_FREELISTS 0
#elif defined(PYPY_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #ifndef CYTHON_USE_TYPE_SPECS
    #define CYTHON_USE_TYPE_SPECS 0
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_GIL
  #define CYTHON_FAST_GIL 0
  #undef CYTHON_METH_FASTCALL
  #define CYTHON_METH_FASTCALL 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3)
  #endif
  #if PY_VERSION_HEX < 0x03090000
    #undef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT)
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #undef CYTHON_USE_MODULE_STATE
  #define CYTHON_USE_MODULE_STATE 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00)
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
  #undef CYTHON_USE_FREELISTS
  #define CYTHON_USE_FREELISTS 0
#elif defined(CYTHON_LIMITED_API)
  #ifdef Py_LIMITED_API
    #undef __PYX_LIMITED_VERSION_HEX
    #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API
  #endif
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 1
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #undef CYTHON_CLINE_IN_TRACEBACK
  #define CYTHON_CLINE_IN_TRACEBACK 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_TYPE_SPECS
  #define CYTHON_USE_TYPE_SPECS 1
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #endif
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_GIL
  #define CYTHON_FAST_GIL 0
  #undef CYTHON_METH_FASTCALL
  #define CYTHON_METH_FASTCALL 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS 1
  #endif
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_MODULE_STATE
  #define CYTHON_USE_MODULE_STATE 1
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 0
  #endif
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 0
  #endif
  #undef CYTHON_USE_FREELISTS
  #define CYTHON_USE_FREELISTS 0
#elif defined(Py_GIL_DISABLED) || defined(Py_NOGIL)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #ifndef CYTHON_USE_TYPE_SPECS
    #define CYTHON_USE_TYPE_SPECS 0
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #ifndef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #ifndef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #endif
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_GIL
  #define CYTHON_FAST_GIL 0
  #ifndef CYTHON_METH_FASTCALL
    #define CYTHON_METH_FASTCALL 1
  #endif
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS 1
  #endif
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #ifndef CYTHON_USE_MODULE_STATE
    #define CYTHON_USE_MODULE_STATE 0
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 0
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 1
  #endif
  #ifndef CYTHON_USE_FREELISTS
    #define CYTHON_USE_FREELISTS 0
  #endif
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #define CYTHON_COMPILING_IN_LIMITED_API 0
  #define CYTHON_COMPILING_IN_GRAAL 0
  #define CYTHON_COMPILING_IN_NOGIL 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #ifndef CYTHON_USE_TYPE_SPECS
    #define CYTHON_USE_TYPE_SPECS 0
  #endif
  #ifndef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #ifndef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_GIL
    #define CYTHON_FAST_GIL (PY_MAJOR_VERSION < 3 || PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x030C00A6)
  #endif
  #ifndef CYTHON_METH_FASTCALL
    #define CYTHON_METH_FASTCALL (PY_VERSION_HEX >= 0x030700A1)
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
  #ifndef CYTHON_PEP487_INIT_SUBCLASS
    #define CYTHON_PEP487_INIT_SUBCLASS 1
  #endif
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT)
    #define CYTHON_PEP489_MULTI_PHASE_INIT 1
  #endif
  #ifndef CYTHON_USE_MODULE_STATE
    #define CYTHON_USE_MODULE_STATE 0
  #endif
  #if PY_VERSION_HEX < 0x030400a1
    #undef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE 0
  #elif !defined(CYTHON_USE_TP_FINALIZE)
    #define CYTHON_USE_TP_FINALIZE 1
  #endif
  #if PY_VERSION_HEX < 0x030600B1
    #undef CYTHON_USE_DICT_VERSIONS
    #define CYTHON_USE_DICT_VERSIONS 0
  #elif !defined(CYTHON_USE_DICT_VERSIONS)
    #define CYTHON_USE_DICT_VERSIONS  (PY_VERSION_HEX < 0x030C00A5)
  #endif
  #if PY_VERSION_HEX < 0x030700A3
    #undef CYTHON_USE_EXC_INFO_STACK
    #define CYTHON_USE_EXC_INFO_STACK 0
  #elif !defined(CYTHON_USE_EXC_INFO_STACK)
    #define CYTHON_USE_EXC_INFO_STACK 1
  #endif
  #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC
    #define CYTHON_UPDATE_DESCRIPTOR_DOC 1
  #endif
  #ifndef CYTHON_USE_FREELISTS
    #define CYTHON_USE_FREELISTS 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if !defined(CYTHON_VECTORCALL)
#define CYTHON_VECTORCALL  (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1)
#endif
#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1)
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_MAJOR_VERSION < 3
    #include "longintrepr.h"
  #endif
  #undef SHIFT
  #undef BASE
  #undef MASK
  #ifdef SIZEOF_VOID_P
    enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
  #endif
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifndef CYTHON_UNUSED
  #if defined(__cplusplus)
    /* for clang __has_cpp_attribute(maybe_unused) is true even before C++17
     * but leads to warnings with -pedantic, since it is a C++17 feature */
    #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
      #if __has_cpp_attribute(maybe_unused)
        #define CYTHON_UNUSED [[maybe_unused]]
      #endif
    #endif
  #endif
#endif
#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_MAYBE_UNUSED_VAR
  #define CYTHON_MAYBE_UNUSED_VAR(x) CYTHON_UNUSED_VAR(x)
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_USE_CPP_STD_MOVE
  #if defined(__cplusplus) && (\
    __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600))
    #define CYTHON_USE_CPP_STD_MOVE 1
  #else
    #define CYTHON_USE_CPP_STD_MOVE 0
  #endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
            typedef unsigned char     uint8_t;
            typedef unsigned short    uint16_t;
            typedef unsigned int      uint32_t;
        #else
            typedef unsigned __int8   uint8_t;
            typedef unsigned __int16  uint16_t;
            typedef unsigned __int32  uint32_t;
        #endif
    #endif
    #if _MSC_VER < 1300
        #ifdef _WIN64
            typedef unsigned long long  __pyx_uintptr_t;
        #else
            typedef unsigned int        __pyx_uintptr_t;
        #endif
    #else
        #ifdef _WIN64
            typedef unsigned __int64    __pyx_uintptr_t;
        #else
            typedef unsigned __int32    __pyx_uintptr_t;
        #endif
    #endif
#else
    #include <stdint.h>
    typedef uintptr_t  __pyx_uintptr_t;
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus)
    /* for clang __has_cpp_attribute(fallthrough) is true even before C++17
     * but leads to warnings with -pedantic, since it is a C++17 feature */
    #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
      #if __has_cpp_attribute(fallthrough)
        #define CYTHON_FALLTHROUGH [[fallthrough]]
      #endif
    #endif
    #ifndef CYTHON_FALLTHROUGH
      #if __has_cpp_attribute(clang::fallthrough)
        #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
      #elif __has_cpp_attribute(gnu::fallthrough)
        #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
      #endif
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif
#ifdef __cplusplus
  template <typename T>
  struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);};
  #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL<type>::value)
#else
  #define __PYX_IS_UNSIGNED(type) (((type)-1) > 0)
#endif
#if CYTHON_COMPILING_IN_PYPY == 1
  #define __PYX_NEED_TP_PRINT_SLOT  (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x030A0000)
#else
  #define __PYX_NEED_TP_PRINT_SLOT  (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000)
#endif
#define __PYX_REINTERPRET_FUNCION(func_pointer, other_pointer) ((func_pointer)(void(*)(void))(other_pointer))

#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_DefaultClassType PyClass_Type
  #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_DefaultClassType PyType_Type
#if CYTHON_COMPILING_IN_LIMITED_API
    static CYTHON_INLINE PyObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f,
                                                    PyObject *code, PyObject *c, PyObject* n, PyObject *v,
                                                    PyObject *fv, PyObject *cell, PyObject* fn,
                                                    PyObject *name, int fline, PyObject *lnos) {
        PyObject *exception_table = NULL;
        PyObject *types_module=NULL, *code_type=NULL, *result=NULL;
        #if __PYX_LIMITED_VERSION_HEX < 0x030B0000
        PyObject *version_info;
        PyObject *py_minor_version = NULL;
        #endif
        long minor_version = 0;
        PyObject *type, *value, *traceback;
        PyErr_Fetch(&type, &value, &traceback);
        #if __PYX_LIMITED_VERSION_HEX >= 0x030B0000
        minor_version = 11;
        #else
        if (!(version_info = PySys_GetObject("version_info"))) goto end;
        if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end;
        minor_version = PyLong_AsLong(py_minor_version);
        Py_DECREF(py_minor_version);
        if (minor_version == -1 && PyErr_Occurred()) goto end;
        #endif
        if (!(types_module = PyImport_ImportModule("types"))) goto end;
        if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end;
        if (minor_version <= 7) {
            (void)p;
            result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOO", a, k, l, s, f, code,
                          c, n, v, fn, name, fline, lnos, fv, cell);
        } else if (minor_version <= 10) {
            result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOO", a,p, k, l, s, f, code,
                          c, n, v, fn, name, fline, lnos, fv, cell);
        } else {
            if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end;
            result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOO", a,p, k, l, s, f, code,
                          c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell);
        }
    end:
        Py_XDECREF(code_type);
        Py_XDECREF(exception_table);
        Py_XDECREF(types_module);
        if (type) {
            PyErr_Restore(type, value, traceback);
        }
        return result;
    }
    #ifndef CO_OPTIMIZED
    #define CO_OPTIMIZED 0x0001
    #endif
    #ifndef CO_NEWLOCALS
    #define CO_NEWLOCALS 0x0002
    #endif
    #ifndef CO_VARARGS
    #define CO_VARARGS 0x0004
    #endif
    #ifndef CO_VARKEYWORDS
    #define CO_VARKEYWORDS 0x0008
    #endif
    #ifndef CO_ASYNC_GENERATOR
    #define CO_ASYNC_GENERATOR 0x0200
    #endif
    #ifndef CO_GENERATOR
    #define CO_GENERATOR 0x0020
    #endif
    #ifndef CO_COROUTINE
    #define CO_COROUTINE 0x0080
    #endif
#elif PY_VERSION_HEX >= 0x030B0000
  static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f,
                                                    PyObject *code, PyObject *c, PyObject* n, PyObject *v,
                                                    PyObject *fv, PyObject *cell, PyObject* fn,
                                                    PyObject *name, int fline, PyObject *lnos) {
    PyCodeObject *result;
    PyObject *empty_bytes = PyBytes_FromStringAndSize("", 0);
    if (!empty_bytes) return NULL;
    result =
      #if PY_VERSION_HEX >= 0x030C0000
        PyUnstable_Code_NewWithPosOnlyArgs
      #else
        PyCode_NewWithPosOnlyArgs
      #endif
        (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, empty_bytes);
    Py_DECREF(empty_bytes);
    return result;
  }
#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#else
  #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#endif
#endif
#if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE)
  #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type)
#else
  #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type))
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is)
  #define __Pyx_Py_Is(x, y)  Py_Is(x, y)
#else
  #define __Pyx_Py_Is(x, y) ((x) == (y))
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsNone)
  #define __Pyx_Py_IsNone(ob) Py_IsNone(ob)
#else
  #define __Pyx_Py_IsNone(ob) __Pyx_Py_Is((ob), Py_None)
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsTrue)
  #define __Pyx_Py_IsTrue(ob) Py_IsTrue(ob)
#else
  #define __Pyx_Py_IsTrue(ob) __Pyx_Py_Is((ob), Py_True)
#endif
#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsFalse)
  #define __Pyx_Py_IsFalse(ob) Py_IsFalse(ob)
#else
  #define __Pyx_Py_IsFalse(ob) __Pyx_Py_Is((ob), Py_False)
#endif
#define __Pyx_NoneAsNull(obj)  (__Pyx_Py_IsNone(obj) ? NULL : (obj))
#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o)
#else
  #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o)
#endif
#ifndef CO_COROUTINE
  #define CO_COROUTINE 0x80
#endif
#ifndef CO_ASYNC_GENERATOR
  #define CO_ASYNC_GENERATOR 0x200
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#ifndef Py_TPFLAGS_SEQUENCE
  #define Py_TPFLAGS_SEQUENCE 0
#endif
#ifndef Py_TPFLAGS_MAPPING
  #define Py_TPFLAGS_MAPPING 0
#endif
#ifndef METH_STACKLESS
  #define METH_STACKLESS 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #if PY_VERSION_HEX >= 0x030d00A4
  #  define __Pyx_PyCFunctionFast PyCFunctionFast
  #  define __Pyx_PyCFunctionFastWithKeywords PyCFunctionFastWithKeywords
  #else
  #  define __Pyx_PyCFunctionFast _PyCFunctionFast
  #  define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
  #endif
#endif
#if CYTHON_METH_FASTCALL
  #define __Pyx_METH_FASTCALL METH_FASTCALL
  #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast
  #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords
#else
  #define __Pyx_METH_FASTCALL METH_VARARGS
  #define __Pyx_PyCFunction_FastCall PyCFunction
  #define __Pyx_PyCFunction_FastCallWithKeywords PyCFunctionWithKeywords
#endif
#if CYTHON_VECTORCALL
  #define __pyx_vectorcallfunc vectorcallfunc
  #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET  PY_VECTORCALL_ARGUMENTS_OFFSET
  #define __Pyx_PyVectorcall_NARGS(n)  PyVectorcall_NARGS((size_t)(n))
#elif CYTHON_BACKPORT_VECTORCALL
  typedef PyObject *(*__pyx_vectorcallfunc)(PyObject *callable, PyObject *const *args,
                                            size_t nargsf, PyObject *kwnames);
  #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET  ((size_t)1 << (8 * sizeof(size_t) - 1))
  #define __Pyx_PyVectorcall_NARGS(n)  ((Py_ssize_t)(((size_t)(n)) & ~__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET))
#else
  #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET  0
  #define __Pyx_PyVectorcall_NARGS(n)  ((Py_ssize_t)(n))
#endif
#if PY_MAJOR_VERSION >= 0x030900B1
#define __Pyx_PyCFunction_CheckExact(func)  PyCFunction_CheckExact(func)
#else
#define __Pyx_PyCFunction_CheckExact(func)  PyCFunction_Check(func)
#endif
#define __Pyx_CyOrPyCFunction_Check(func)  PyCFunction_Check(func)
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func)  (((PyCFunctionObject*)(func))->m_ml->ml_meth)
#elif !CYTHON_COMPILING_IN_LIMITED_API
#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func)  PyCFunction_GET_FUNCTION(func)
#endif
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CyOrPyCFunction_GET_FLAGS(func)  (((PyCFunctionObject*)(func))->m_ml->ml_flags)
static CYTHON_INLINE PyObject* __Pyx_CyOrPyCFunction_GET_SELF(PyObject *func) {
    return (__Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_STATIC) ? NULL : ((PyCFunctionObject*)func)->m_self;
}
#endif
static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void *cfunc) {
#if CYTHON_COMPILING_IN_LIMITED_API
    return PyCFunction_Check(func) && PyCFunction_GetFunction(func) == (PyCFunction) cfunc;
#else
    return PyCFunction_Check(func) && PyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc;
#endif
}
#define __Pyx_IsSameCFunction(func, cfunc)   __Pyx__IsSameCFunction(func, cfunc)
#if __PYX_LIMITED_VERSION_HEX < 0x030900B1
  #define __Pyx_PyType_FromModuleAndSpec(m, s, b)  ((void)m, PyType_FromSpecWithBases(s, b))
  typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *);
#else
  #define __Pyx_PyType_FromModuleAndSpec(m, s, b)  PyType_FromModuleAndSpec(m, s, b)
  #define __Pyx_PyCMethod  PyCMethod
#endif
#ifndef METH_METHOD
  #define METH_METHOD 0x200
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_PyThreadState_Current PyThreadState_Get()
#elif !CYTHON_FAST_THREAD_STATE
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x030d00A1
  #define __Pyx_PyThreadState_Current PyThreadState_GetUnchecked()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
static CYTHON_INLINE void *__Pyx_PyModule_GetState(PyObject *op)
{
    void *result;
    result = PyModule_GetState(op);
    if (!result)
        Py_FatalError("Couldn't find the module state");
    return result;
}
#endif
#define __Pyx_PyObject_GetSlot(obj, name, func_ctype)  __Pyx_PyType_GetSlot(Py_TYPE(obj), name, func_ctype)
#if CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_PyType_GetSlot(type, name, func_ctype)  ((func_ctype) PyType_GetSlot((type), Py_##name))
#else
  #define __Pyx_PyType_GetSlot(type, name, func_ctype)  ((type)->name)
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0;
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif
#if PY_MAJOR_VERSION < 3
    #if CYTHON_COMPILING_IN_PYPY
        #if PYPY_VERSION_NUM < 0x07030600
            #if defined(__cplusplus) && __cplusplus >= 201402L
                [[deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")]]
            #elif defined(__GNUC__) || defined(__clang__)
                __attribute__ ((__deprecated__("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")))
            #elif defined(_MSC_VER)
                __declspec(deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6"))
            #endif
            static CYTHON_INLINE int PyGILState_Check(void) {
                return 0;
            }
        #else  // PYPY_VERSION_NUM < 0x07030600
        #endif  // PYPY_VERSION_NUM < 0x07030600
    #else
        static CYTHON_INLINE int PyGILState_Check(void) {
            PyThreadState * tstate = _PyThreadState_Current;
            return tstate && (tstate == PyGILState_GetThisThreadState());
        }
    #endif
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B4 && PY_VERSION_HEX < 0x030d0000 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStrWithError(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) {
    PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name);
    if (res == NULL) PyErr_Clear();
    return res;
}
#elif PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000)
#define __Pyx_PyDict_GetItemStrWithError  PyDict_GetItemWithError
#define __Pyx_PyDict_GetItemStr           PyDict_GetItem
#else
static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, PyObject *name) {
#if CYTHON_COMPILING_IN_PYPY
    return PyDict_GetItem(dict, name);
#else
    PyDictEntry *ep;
    PyDictObject *mp = (PyDictObject*) dict;
    long hash = ((PyStringObject *) name)->ob_shash;
    assert(hash != -1);
    ep = (mp->ma_lookup)(mp, name, hash);
    if (ep == NULL) {
        return NULL;
    }
    return ep->me_value;
#endif
}
#define __Pyx_PyDict_GetItemStr           PyDict_GetItem
#endif
#if CYTHON_USE_TYPE_SLOTS
  #define __Pyx_PyType_GetFlags(tp)   (((PyTypeObject *)tp)->tp_flags)
  #define __Pyx_PyType_HasFeature(type, feature)  ((__Pyx_PyType_GetFlags(type) & (feature)) != 0)
  #define __Pyx_PyObject_GetIterNextFunc(obj)  (Py_TYPE(obj)->tp_iternext)
#else
  #define __Pyx_PyType_GetFlags(tp)   (PyType_GetFlags((PyTypeObject *)tp))
  #define __Pyx_PyType_HasFeature(type, feature)  PyType_HasFeature(type, feature)
  #define __Pyx_PyObject_GetIterNextFunc(obj)  PyIter_Next
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_SetItemOnTypeDict(tp, k, v) PyObject_GenericSetAttr((PyObject*)tp, k, v)
#else
  #define __Pyx_SetItemOnTypeDict(tp, k, v) PyDict_SetItem(tp->tp_dict, k, v)
#endif
#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000
#define __Pyx_PyHeapTypeObject_GC_Del(obj)  {\
    PyTypeObject *type = Py_TYPE((PyObject*)obj);\
    assert(__Pyx_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE));\
    PyObject_GC_Del(obj);\
    Py_DECREF(type);\
}
#else
#define __Pyx_PyHeapTypeObject_GC_Del(obj)  PyObject_GC_Del(obj)
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GetLength(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((void)u, 1114111U)
  #define __Pyx_PyUnicode_KIND(u)         ((void)u, (0))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)u)
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)k, PyUnicode_ReadChar((PyObject*)(d), i))
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GetLength(u))
#elif PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #if PY_VERSION_HEX >= 0x030C0000
    #define __Pyx_PyUnicode_READY(op)       (0)
  #else
    #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                                0 : _PyUnicode_Ready((PyObject *)(op)))
  #endif
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         ((int)PyUnicode_KIND(u))
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, (Py_UCS4) ch)
  #if PY_VERSION_HEX >= 0x030C0000
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
  #else
    #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length))
    #else
    #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
    #endif
  #endif
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535U : 1114111U)
  #define __Pyx_PyUnicode_KIND(u)         ((int)sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = (Py_UNICODE) ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #if !defined(PyUnicode_DecodeUnicodeEscape)
    #define PyUnicode_DecodeUnicodeEscape(s, size, errors)  PyUnicode_Decode(s, size, "unicode_escape", errors)
  #endif
  #if !defined(PyUnicode_Contains) || (PY_MAJOR_VERSION == 2 && PYPY_VERSION_NUM < 0x07030500)
    #undef PyUnicode_Contains
    #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
  #endif
  #if !defined(PyByteArray_Check)
    #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
  #endif
  #if !defined(PyObject_Format)
    #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
  #endif
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#ifndef PyObject_Unicode
  #define PyObject_Unicode             PyObject_Str
#endif
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#if CYTHON_COMPILING_IN_CPYTHON
  #define __Pyx_PySequence_ListKeepNew(obj)\
    (likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj))
#else
  #define __Pyx_PySequence_ListKeepNew(obj)  PySequence_List(obj)
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        __Pyx_IS_TYPE(obj, &PySet_Type)
#endif
#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_ITEM(o, i) PySequence_ITEM(o, i)
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
  #define __Pyx_PyTuple_SET_ITEM(o, i, v) (PyTuple_SET_ITEM(o, i, v), (0))
  #define __Pyx_PyList_SET_ITEM(o, i, v) (PyList_SET_ITEM(o, i, v), (0))
  #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o)
  #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o)
  #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o)
  #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o)
  #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o)
#else
  #define __Pyx_PySequence_ITEM(o, i) PySequence_GetItem(o, i)
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
  #define __Pyx_PyTuple_SET_ITEM(o, i, v) PyTuple_SetItem(o, i, v)
  #define __Pyx_PyList_SET_ITEM(o, i, v) PyList_SetItem(o, i, v)
  #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o)
  #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o)
  #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o)
  #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o)
  #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o)
#endif
#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1
  #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name)
#else
  static CYTHON_INLINE PyObject *__Pyx_PyImport_AddModuleRef(const char *name) {
      PyObject *module = PyImport_AddModule(name);
      Py_XINCREF(module);
      return module;
  }
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define __Pyx_Py3Int_Check(op)       PyLong_Check(op)
  #define __Pyx_Py3Int_CheckExact(op)  PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#else
  #define __Pyx_Py3Int_Check(op)       (PyLong_Check(op) || PyInt_Check(op))
  #define __Pyx_Py3Int_CheckExact(op)  (PyLong_CheckExact(op) || PyInt_CheckExact(op))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsHash_t
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   __Pyx_PyIndex_AsSsize_t
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#endif

#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS)
  #if !defined(_USE_MATH_DEFINES)
    #define _USE_MATH_DEFINES
  #endif
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif

#define __PYX_MARK_ERR_POS(f_index, lineno) \
    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__;  (void)__pyx_clineno; }
#define __PYX_ERR(f_index, lineno, Ln_error) \
    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }

#ifdef CYTHON_EXTERN_C
    #undef __PYX_EXTERN_C
    #define __PYX_EXTERN_C CYTHON_EXTERN_C
#elif defined(__PYX_EXTERN_C)
    #ifdef _MSC_VER
    #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.")
    #else
    #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.
    #endif
#else
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__pysam__libcalignmentfile
#define __PYX_HAVE_API__pysam__libcalignmentfile
/* Early includes */
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include "pythread.h"

    #if CYTHON_COMPILING_IN_PYPY
    #ifdef _MSC_VER
    #pragma message ("This module uses CPython specific internals of 'array.array', which are not available in PyPy.")
    #else
    #warning This module uses CPython specific internals of 'array.array', which are not available in PyPy.
    #endif
    #endif
    
#include <sys/types.h>
#include "stdarg.h"
#include "htslib/kstring.h"
#include "htslib_util.h"
#include "htslib/hfile.h"
#include "htslib/bgzf.h"
#include "htslib/hts.h"
#include "htslib/sam.h"
#include "htslib/faidx.h"
#include "htslib/tbx.h"
#include "htslib/vcf.h"
#include "htslib/vcfutils.h"
#include "htslib/cram.h"
#include "pysam_stream.h"
#include <errno.h>
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s);
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*);
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#define __Pyx_PyUnicode_FromOrdinal(o)       PyUnicode_FromOrdinal((int)o)
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*);
#if CYTHON_ASSUME_SAFE_MACROS
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #if PY_VERSION_HEX >= 0x030C00A7
  #ifndef _PyLong_SIGN_MASK
    #define _PyLong_SIGN_MASK 3
  #endif
  #ifndef _PyLong_NON_SIZE_BITS
    #define _PyLong_NON_SIZE_BITS 3
  #endif
  #define __Pyx_PyLong_Sign(x)  (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK)
  #define __Pyx_PyLong_IsNeg(x)  ((__Pyx_PyLong_Sign(x) & 2) != 0)
  #define __Pyx_PyLong_IsNonNeg(x)  (!__Pyx_PyLong_IsNeg(x))
  #define __Pyx_PyLong_IsZero(x)  (__Pyx_PyLong_Sign(x) & 1)
  #define __Pyx_PyLong_IsPos(x)  (__Pyx_PyLong_Sign(x) == 0)
  #define __Pyx_PyLong_CompactValueUnsigned(x)  (__Pyx_PyLong_Digits(x)[0])
  #define __Pyx_PyLong_DigitCount(x)  ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS))
  #define __Pyx_PyLong_SignedDigitCount(x)\
        ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x))
  #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
    #define __Pyx_PyLong_IsCompact(x)     PyUnstable_Long_IsCompact((PyLongObject*) x)
    #define __Pyx_PyLong_CompactValue(x)  PyUnstable_Long_CompactValue((PyLongObject*) x)
  #else
    #define __Pyx_PyLong_IsCompact(x)     (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS))
    #define __Pyx_PyLong_CompactValue(x)  ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0])
  #endif
  typedef Py_ssize_t  __Pyx_compact_pylong;
  typedef size_t  __Pyx_compact_upylong;
  #else
  #define __Pyx_PyLong_IsNeg(x)  (Py_SIZE(x) < 0)
  #define __Pyx_PyLong_IsNonNeg(x)  (Py_SIZE(x) >= 0)
  #define __Pyx_PyLong_IsZero(x)  (Py_SIZE(x) == 0)
  #define __Pyx_PyLong_IsPos(x)  (Py_SIZE(x) > 0)
  #define __Pyx_PyLong_CompactValueUnsigned(x)  ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0])
  #define __Pyx_PyLong_DigitCount(x)  __Pyx_sst_abs(Py_SIZE(x))
  #define __Pyx_PyLong_SignedDigitCount(x)  Py_SIZE(x)
  #define __Pyx_PyLong_IsCompact(x)  (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
  #define __Pyx_PyLong_CompactValue(x)\
        ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0]))
  typedef sdigit  __Pyx_compact_pylong;
  typedef digit  __Pyx_compact_upylong;
  #endif
  #if PY_VERSION_HEX >= 0x030C00A5
  #define __Pyx_PyLong_Digits(x)  (((PyLongObject*)x)->long_value.ob_digit)
  #else
  #define __Pyx_PyLong_Digits(x)  (((PyLongObject*)x)->ob_digit)
  #endif
#endif
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
#include <string.h>
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = (char) c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#include <string.h>
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1);
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

#if !CYTHON_USE_MODULE_STATE
static PyObject *__pyx_m = NULL;
#endif
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm = __FILE__;
static const char *__pyx_filename;

/* #### Code section: filename_table ### */

static const char *__pyx_f[] = {
  "pysam/libcalignmentfile.pyx",
  "contextvars.pxd",
  "array.pxd",
  "<stringsource>",
  "pysam/libcalignmentfile.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
  "pysam/libcfaidx.pxd",
  "pysam/libcalignedsegment.pxd",
};
/* #### Code section: utility_code_proto_before_types ### */
/* ForceInitThreads.proto */
#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif

/* NoFastGil.proto */
#define __Pyx_PyGILState_Ensure PyGILState_Ensure
#define __Pyx_PyGILState_Release PyGILState_Release
#define __Pyx_FastGIL_Remember()
#define __Pyx_FastGIL_Forget()
#define __Pyx_FastGilFuncInit()

/* #### Code section: numeric_typedefs ### */
/* #### Code section: complex_type_declarations ### */
/* #### Code section: type_declarations ### */

/*--- Type declarations ---*/
#ifndef _ARRAYARRAY_H
struct arrayobject;
typedef struct arrayobject arrayobject;
#endif
struct __pyx_obj_5pysam_10libchtslib_HTSFile;
struct __pyx_obj_5pysam_9libcfaidx_FastaFile;
struct __pyx_obj_5pysam_9libcfaidx_FastqProxy;
struct __pyx_obj_5pysam_9libcfaidx_FastxRecord;
struct __pyx_obj_5pysam_9libcfaidx_FastxFile;
struct __pyx_obj_5pysam_9libcfaidx_FastqFile;
struct __pyx_obj_5pysam_9libcfaidx_Fastafile;
struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment;
struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn;
struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead;
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader;
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll;
struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads;
struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall;
struct __pyx_opt_args_7cpython_11contextvars_get_value;
struct __pyx_opt_args_7cpython_11contextvars_get_value_no_default;

/* "cpython/contextvars.pxd":112
 * 
 * 
 * cdef inline object get_value(var, default_value=None):             # <<<<<<<<<<<<<<
 *     """Return a new reference to the value of the context variable,
 *     or the default value of the context variable,
 */
struct __pyx_opt_args_7cpython_11contextvars_get_value {
  int __pyx_n;
  PyObject *default_value;
};

/* "cpython/contextvars.pxd":129
 * 
 * 
 * cdef inline object get_value_no_default(var, default_value=None):             # <<<<<<<<<<<<<<
 *     """Return a new reference to the value of the context variable,
 *     or the provided default value if no such value was found.
 */
struct __pyx_opt_args_7cpython_11contextvars_get_value_no_default {
  int __pyx_n;
  PyObject *default_value;
};
struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array;
struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array;

/* "pysam/libcfaidx.pxd":50
 *     cdef cython.str to_string(self)
 *     cdef cython.str tostring(self)
 *     cpdef array.array get_quality_array(self, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array {
  int __pyx_n;
  int offset;
};

/* "pysam/libcfaidx.pxd":60
 *     cdef cython.str to_string(self)
 *     cdef cython.str tostring(self)
 *     cpdef array.array get_quality_array(self, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * cdef class FastxFile:
 */
struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array {
  int __pyx_n;
  int offset;
};
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag;
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag;
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring;

/* "pysam/libcalignedsegment.pxd":31
 * 
 * from pysam.libcalignmentfile cimport AlignmentFile, AlignmentHeader
 * ctypedef AlignmentFile AlignmentFile_t             # <<<<<<<<<<<<<<
 * 
 * 
 */
typedef struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_t_5pysam_18libcalignedsegment_AlignmentFile_t;

/* "pysam/libcalignedsegment.pxd":51
 *     # add an alignment tag with value to the AlignedSegment
 *     # an existing tag of the same name will be replaced.
 *     cpdef set_tag(self, tag, value, value_type=?, replace=?)             # <<<<<<<<<<<<<<
 * 
 *     # get an alignment tag from the AlignedSegment
 */
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag {
  int __pyx_n;
  PyObject *value_type;
  PyObject *replace;
};

/* "pysam/libcalignedsegment.pxd":54
 * 
 *     # get an alignment tag from the AlignedSegment
 *     cpdef get_tag(self, tag, with_value_type=?)             # <<<<<<<<<<<<<<
 * 
 *     # return true if tag exists
 */
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag {
  int __pyx_n;
  PyObject *with_value_type;
};

/* "pysam/libcalignedsegment.pxd":63
 * 
 *     # returns a valid sam alignment string (deprecated)
 *     cpdef tostring(self, htsfile=*)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring {
  int __pyx_n;
  PyObject *htsfile;
};
struct __pyx_opt_args_5pysam_9libcutils_parse_region;
struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array;
struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring;
struct __pyx_opt_args_5pysam_9libcutils_qualities_to_qualitystring;
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str;
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_bytes;
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str_w_len;
struct __pyx_opt_args_5pysam_9libcutils_force_str;
struct __pyx_opt_args_5pysam_9libcutils_force_bytes;
struct __pyx_opt_args_5pysam_9libcutils_decode_bytes;

/* "pysam/libcutils.pxd":8
 * from cpython cimport array as c_array
 * 
 * cpdef parse_region(contig=*, start=*, stop=*, region=*, reference=*, end=*)             # <<<<<<<<<<<<<<
 * 
 * cdef int libc_whence_from_io(int whence)
 */
struct __pyx_opt_args_5pysam_9libcutils_parse_region {
  int __pyx_n;
  PyObject *contig;
  PyObject *start;
  PyObject *stop;
  PyObject *region;
  PyObject *reference;
  PyObject *end;
};

/* "pysam/libcutils.pxd":15
 * # Utility functions for quality string conversions
 * 
 * cpdef c_array.array qualitystring_to_array(input_str, int offset=*)             # <<<<<<<<<<<<<<
 * cpdef array_to_qualitystring(c_array.array arr, int offset=*)
 * cpdef qualities_to_qualitystring(qualities, int offset=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_qualitystring_to_array {
  int __pyx_n;
  int offset;
};

/* "pysam/libcutils.pxd":16
 * 
 * cpdef c_array.array qualitystring_to_array(input_str, int offset=*)
 * cpdef array_to_qualitystring(c_array.array arr, int offset=*)             # <<<<<<<<<<<<<<
 * cpdef qualities_to_qualitystring(qualities, int offset=*)
 * 
 */
struct __pyx_opt_args_5pysam_9libcutils_array_to_qualitystring {
  int __pyx_n;
  int offset;
};

/* "pysam/libcutils.pxd":17
 * cpdef c_array.array qualitystring_to_array(input_str, int offset=*)
 * cpdef array_to_qualitystring(c_array.array arr, int offset=*)
 * cpdef qualities_to_qualitystring(qualities, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * ########################################################################
 */
struct __pyx_opt_args_5pysam_9libcutils_qualities_to_qualitystring {
  int __pyx_n;
  int offset;
};

/* "pysam/libcutils.pxd":29
 * ## Python 3 compatibility functions
 * ########################################################################
 * cdef charptr_to_str(const char *s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":30
 * ########################################################################
 * cdef charptr_to_str(const char *s, encoding=*, errors=*)
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 * cdef force_str(object s, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_bytes {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":31
 * cdef charptr_to_str(const char *s, encoding=*, errors=*)
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef force_str(object s, encoding=*, errors=*)
 * cdef bytes force_bytes(object s, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str_w_len {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":32
 * cdef bytes charptr_to_bytes(const char *s, encoding=*, errors=*)
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 * cdef force_str(object s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef bytes force_bytes(object s, encoding=*, errors=*)
 * cdef decode_bytes(bytes s, encoding=*, errors=*)
 */
struct __pyx_opt_args_5pysam_9libcutils_force_str {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":33
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*, errors=*)
 * cdef force_str(object s, encoding=*, errors=*)
 * cdef bytes force_bytes(object s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef decode_bytes(bytes s, encoding=*, errors=*)
 * cdef bytes encode_filename(object filename)
 */
struct __pyx_opt_args_5pysam_9libcutils_force_bytes {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};

/* "pysam/libcutils.pxd":34
 * cdef force_str(object s, encoding=*, errors=*)
 * cdef bytes force_bytes(object s, encoding=*, errors=*)
 * cdef decode_bytes(bytes s, encoding=*, errors=*)             # <<<<<<<<<<<<<<
 * cdef bytes encode_filename(object filename)
 * cdef from_string_and_size(const char *s, size_t length)
 */
struct __pyx_opt_args_5pysam_9libcutils_decode_bytes {
  int __pyx_n;
  PyObject *encoding;
  PyObject *errors;
};
struct __pyx_t_5pysam_17libcalignmentfile___iterdata;
typedef struct __pyx_t_5pysam_17libcalignmentfile___iterdata __pyx_t_5pysam_17libcalignmentfile___iterdata;
struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator;
struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list;

/* "pysam/libcalignmentfile.pxd":25
 * # Utility types
 * 
 * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
 *     htsFile * htsfile
 *     bam_hdr_t * header
 */
struct __pyx_t_5pysam_17libcalignmentfile___iterdata {
  htsFile *htsfile;
  bam_hdr_t *header;
  hts_itr_t *iter;
  faidx_t *fastafile;
  int tid;
  char *seq;
  int seq_len;
  int min_mapping_quality;
  int flag_require;
  int flag_filter;
  int compute_baq;
  int redo_baq;
  int ignore_orphans;
  int adjust_capq_threshold;
};

/* "pysam/libcalignmentfile.pxd":121
 *     cdef int cnext(self)
 *     cdef char * get_sequence(self)
 *     cdef _setup_iterator(self,             # <<<<<<<<<<<<<<
 *                          int tid,
 *                          int start,
 */
struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator {
  int __pyx_n;
  int multiple_iterators;
};

/* "pysam/libcalignmentfile.pyx":187
 * # the following should be class-method for VariantHeader, but cdef @classmethods
 * # are not implemented in cython.
 * cdef int fill_AlignmentHeader_from_list(bam_hdr_t *dest,             # <<<<<<<<<<<<<<
 *                                         reference_names,
 *                                         reference_lengths,
 */
struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list {
  int __pyx_n;
  PyObject *add_sq_text;
  PyObject *text;
};

/* "pysam/libchtslib.pxd":2706
 * 
 * 
 * cdef class HTSFile(object):             # <<<<<<<<<<<<<<
 *     cdef          htsFile *htsfile       # pointer to htsFile structure
 *     cdef          int64_t start_offset   # BGZF offset of first record
 */
struct __pyx_obj_5pysam_10libchtslib_HTSFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtab;
  htsFile *htsfile;
  int64_t start_offset;
  PyObject *filename;
  PyObject *mode;
  PyObject *threads;
  PyObject *index_filename;
  int is_stream;
  int is_remote;
  int duplicate_filehandle;
};


/* "pysam/libcfaidx.pxd":38
 *                     int * dret)
 * 
 * cdef class FastaFile:             # <<<<<<<<<<<<<<
 *     cdef bint is_remote
 *     cdef object _filename, _references, _lengths, reference2length
 */
struct __pyx_obj_5pysam_9libcfaidx_FastaFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtab;
  int is_remote;
  PyObject *_filename;
  PyObject *_references;
  PyObject *_lengths;
  PyObject *reference2length;
  faidx_t *fastafile;
};


/* "pysam/libcfaidx.pxd":46
 * 
 * 
 * cdef class FastqProxy:             # <<<<<<<<<<<<<<
 *     cdef kseq_t * _delegate
 *     cdef cython.str to_string(self)
 */
struct __pyx_obj_5pysam_9libcfaidx_FastqProxy {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtab;
  kseq_t *_delegate;
};


/* "pysam/libcfaidx.pxd":53
 * 
 * 
 * cdef class FastxRecord:             # <<<<<<<<<<<<<<
 *     """
 *     Python container for pysam.libcfaidx.FastqProxy with persistence.
 */
struct __pyx_obj_5pysam_9libcfaidx_FastxRecord {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtab;
  PyObject *comment;
  PyObject *quality;
  PyObject *sequence;
  PyObject *name;
};


/* "pysam/libcfaidx.pxd":62
 *     cpdef array.array get_quality_array(self, int offset=*)
 * 
 * cdef class FastxFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef BGZF * fastqfile
 */
struct __pyx_obj_5pysam_9libcfaidx_FastxFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtab;
  PyObject *_filename;
  BGZF *fastqfile;
  kseq_t *entry;
  int persist;
  int is_remote;
};


/* "pysam/libcfaidx.pxd":74
 * 
 * # Compatibility Layer for pysam 0.8.1
 * cdef class FastqFile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_9libcfaidx_FastqFile {
  struct __pyx_obj_5pysam_9libcfaidx_FastxFile __pyx_base;
};


/* "pysam/libcfaidx.pxd":79
 * 
 * # Compatibility Layer for pysam < 0.8
 * cdef class Fastafile(FastaFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_9libcfaidx_Fastafile {
  struct __pyx_obj_5pysam_9libcfaidx_FastaFile __pyx_base;
};


/* "pysam/libcalignedsegment.pxd":35
 * 
 * # Note: need to declare all C fields and methods here
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedSegment represents
 */
struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtab;
  bam1_t *_delegate;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  PyObject *cache_query_qualities;
  PyObject *cache_query_alignment_qualities;
  PyObject *cache_query_sequence;
  PyObject *cache_query_alignment_sequence;
};


/* "pysam/libcalignedsegment.pxd":66
 * 
 * 
 * cdef class PileupColumn:             # <<<<<<<<<<<<<<
 *     cdef const bam_pileup1_t ** plp
 *     cdef int tid
 */
struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn {
  PyObject_HEAD
  bam_pileup1_t const **plp;
  int tid;
  int pos;
  int n_pu;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  uint32_t min_base_quality;
  kstring_t buf;
  char *reference_sequence;
};


/* "pysam/libcalignedsegment.pxd":76
 *     cdef char * reference_sequence
 * 
 * cdef class PileupRead:             # <<<<<<<<<<<<<<
 *     cdef int32_t  _qpos
 *     cdef AlignedSegment _alignment
 */
struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead {
  PyObject_HEAD
  int32_t _qpos;
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *_alignment;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
  uint32_t _is_refskip;
};


/* "pysam/libcalignmentfile.pxd":42
 * 
 * 
 * cdef class AlignmentHeader(object):             # <<<<<<<<<<<<<<
 *     cdef bam_hdr_t *ptr
 * 
 */
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader {
  PyObject_HEAD
  bam_hdr_t *ptr;
};


/* "pysam/libcalignmentfile.pxd":45
 *     cdef bam_hdr_t *ptr
 * 
 * cdef class AlignmentFile(HTSFile):             # <<<<<<<<<<<<<<
 *     cdef readonly object reference_filename
 *     cdef readonly AlignmentHeader header
 */
struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile {
  struct __pyx_obj_5pysam_10libchtslib_HTSFile __pyx_base;
  PyObject *reference_filename;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  hts_idx_t *index;
  bam1_t *b;
};


/* "pysam/libcalignmentfile.pxd":62
 * 
 * 
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     cdef int retval
 *     cdef bam1_t * b
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow {
  PyObject_HEAD
  int retval;
  bam1_t *b;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  hts_idx_t *index;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
  int owns_samfile;
};


/* "pysam/libcalignmentfile.pxd":72
 * 
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef hts_itr_t * iter
 *     cdef bam1_t * getCurrent(self)
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_vtab;
  hts_itr_t *iter;
};


/* "pysam/libcalignmentfile.pxd":78
 * 
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int max_rows
 *     cdef int current_row
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_vtab;
  int max_rows;
  int current_row;
};


/* "pysam/libcalignmentfile.pxd":85
 * 
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * getCurrent(self)
 *     cdef int cnext(self)
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_vtab;
};


/* "pysam/libcalignmentfile.pxd":90
 * 
 * 
 * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int         tid
 *     cdef IteratorRowRegion rowiter
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  int tid;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *rowiter;
};


/* "pysam/libcalignmentfile.pxd":95
 * 
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int current_pos
 *     cdef positions
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_vtab;
  int current_pos;
  PyObject *positions;
};


/* "pysam/libcalignmentfile.pxd":102
 * 
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *__pyx_vtab;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *iter;
  int tid;
  int pos;
  int n_plp;
  uint32_t min_base_quality;
  bam_pileup1_t const *plp;
  bam_mplp_t pileup_iter;
  __pyx_t_5pysam_17libcalignmentfile___iterdata iterdata;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile;
  struct __pyx_obj_5pysam_9libcfaidx_FastaFile *fastafile;
  PyObject *stepper;
  int max_depth;
  int ignore_overlaps;
};


/* "pysam/libcalignmentfile.pxd":134
 * 
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int stop
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
  int start;
  int stop;
  int truncate;
};


/* "pysam/libcalignmentfile.pxd":140
 * 
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};


/* "pysam/libcalignmentfile.pxd":144
 * 
 * 
 * cdef class IteratorColumnAll(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};


/* "pysam/libcalignmentfile.pxd":148
 * 
 * 
 * cdef class IndexedReads:             # <<<<<<<<<<<<<<
 *     cdef AlignmentFile samfile
 *     cdef htsFile * htsfile
 */
struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads {
  PyObject_HEAD
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  PyObject *index;
  int owns_samfile;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *header;
};


/* "pysam/libcalignmentfile.pyx":2817
 * 
 * 
 * cdef class SNPCall:             # <<<<<<<<<<<<<<
 *     '''the results of a SNP call.'''
 *     cdef int _tid
 */
struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall {
  PyObject_HEAD
  int _tid;
  int _pos;
  char _reference_base;
  char _genotype;
  int _consensus_quality;
  int _snp_quality;
  int _rms_mapping_quality;
  int _coverage;
};



/* "pysam/libchtslib.pxd":2706
 * 
 * 
 * cdef class HTSFile(object):             # <<<<<<<<<<<<<<
 *     cdef          htsFile *htsfile       # pointer to htsFile structure
 *     cdef          int64_t start_offset   # BGZF offset of first record
 */

struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile {
  htsFile *(*_open_htsfile)(struct __pyx_obj_5pysam_10libchtslib_HTSFile *);
};
static struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile *__pyx_vtabptr_5pysam_10libchtslib_HTSFile;


/* "pysam/libcfaidx.pxd":38
 *                     int * dret)
 * 
 * cdef class FastaFile:             # <<<<<<<<<<<<<<
 *     cdef bint is_remote
 *     cdef object _filename, _references, _lengths, reference2length
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile {
  char *(*_fetch)(struct __pyx_obj_5pysam_9libcfaidx_FastaFile *, char *, int, int, int *);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile *__pyx_vtabptr_5pysam_9libcfaidx_FastaFile;


/* "pysam/libcfaidx.pxd":46
 * 
 * 
 * cdef class FastqProxy:             # <<<<<<<<<<<<<<
 *     cdef kseq_t * _delegate
 *     cdef cython.str to_string(self)
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy {
  PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *);
  PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *);
  arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_10FastqProxy_get_quality_array *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy *__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy;


/* "pysam/libcfaidx.pxd":53
 * 
 * 
 * cdef class FastxRecord:             # <<<<<<<<<<<<<<
 *     """
 *     Python container for pysam.libcfaidx.FastqProxy with persistence.
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord {
  PyObject *(*to_string)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *);
  PyObject *(*tostring)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *);
  arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_9libcfaidx_11FastxRecord_get_quality_array *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord *__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord;


/* "pysam/libcfaidx.pxd":62
 *     cpdef array.array get_quality_array(self, int offset=*)
 * 
 * cdef class FastxFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef BGZF * fastqfile
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile {
  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *);
  int (*cnext)(struct __pyx_obj_5pysam_9libcfaidx_FastxFile *);
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile *__pyx_vtabptr_5pysam_9libcfaidx_FastxFile;


/* "pysam/libcfaidx.pxd":74
 * 
 * # Compatibility Layer for pysam 0.8.1
 * cdef class FastqFile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile {
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile *__pyx_vtabptr_5pysam_9libcfaidx_FastqFile;


/* "pysam/libcfaidx.pxd":79
 * 
 * # Compatibility Layer for pysam < 0.8
 * cdef class Fastafile(FastaFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */

struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile {
  struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile *__pyx_vtabptr_5pysam_9libcfaidx_Fastafile;


/* "pysam/libcalignedsegment.pxd":35
 * 
 * # Note: need to declare all C fields and methods here
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedSegment represents
 */

struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment {
  PyObject *(*set_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_set_tag *__pyx_optional_args);
  PyObject *(*get_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_get_tag *__pyx_optional_args);
  PyObject *(*has_tag)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*to_string)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch);
  PyObject *(*tostring)(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_18libcalignedsegment_14AlignedSegment_tostring *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment *__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment;


/* "pysam/libcalignmentfile.pyx":582
 * 
 * 
 * cdef class AlignmentFile(HTSFile):             # <<<<<<<<<<<<<<
 *     """AlignmentFile(filepath_or_object, mode=None, template=None,
 *     reference_names=None, reference_lengths=None, text=NULL,
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile {
  struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile __pyx_base;
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *);
  int (*write)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile;


/* "pysam/libcalignmentfile.pyx":2058
 * 
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile, int tid, int beg, int stop,
 *     int multiple_iterators=False)*
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion;


/* "pysam/libcalignmentfile.pyx":2119
 * 
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile, n, int multiple_iterators=False)*
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead;


/* "pysam/libcalignmentfile.pyx":2170
 * 
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile, int multiple_iterators=False)*
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll;


/* "pysam/libcalignmentfile.pyx":2274
 * 
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     """*(AlignmentFile samfile)*
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *);
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection;


/* "pysam/libcalignmentfile.pyx":2446
 * 
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 *     '''abstract base class for iterators over columns.
 * 
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn {
  int (*cnext)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  char *(*get_sequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  PyObject *(*_setup_iterator)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args);
  PyObject *(*_setup_raw_rest_iterator)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  PyObject *(*reset)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *);
  PyObject *(*_free_pileup_iter)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
  char *(*getSequence)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *);
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;


/* "pysam/libcalignmentfile.pyx":2696
 * 
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     '''iterates over a region only.
 *     '''
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion {
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion;


/* "pysam/libcalignmentfile.pyx":2746
 * 
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     """iterates over all columns by chaining iterators over each reference
 *     """
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs {
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs;


/* "pysam/libcalignmentfile.pyx":2788
 * 
 * 
 * cdef class IteratorColumnAll(IteratorColumn):             # <<<<<<<<<<<<<<
 *     """iterates over all columns, without using an index
 *     """
 */

struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll {
  struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll;
/* #### Code section: utility_code_proto ### */

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, Py_ssize_t);
    void (*DECREF)(void*, PyObject*, Py_ssize_t);
    void (*GOTREF)(void*, PyObject*, Py_ssize_t);
    void (*GIVEREF)(void*, PyObject*, Py_ssize_t);
    void* (*SetupContext)(const char*, Py_ssize_t, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\
          }
  #define __Pyx_RefNannyFinishContextNogil() {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __Pyx_RefNannyFinishContext();\
              PyGILState_Release(__pyx_gilstate_save);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__))
  #define __Pyx_RefNannyFinishContextNogil() __Pyx_RefNannyFinishContext()
#endif
  #define __Pyx_RefNannyFinishContextNogil() {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __Pyx_RefNannyFinishContext();\
              PyGILState_Release(__pyx_gilstate_save);\
          }
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), (__LINE__))
  #define __Pyx_XINCREF(r)  do { if((r) == NULL); else {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) == NULL); else {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) == NULL); else {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) == NULL); else {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContextNogil()
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_Py_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; Py_XDECREF(tmp);\
    } while (0)
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#if PY_VERSION_HEX >= 0x030C00A6
#define __Pyx_PyErr_Occurred()  (__pyx_tstate->current_exception != NULL)
#define __Pyx_PyErr_CurrentExceptionType()  (__pyx_tstate->current_exception ? (PyObject*) Py_TYPE(__pyx_tstate->current_exception) : (PyObject*) NULL)
#else
#define __Pyx_PyErr_Occurred()  (__pyx_tstate->curexc_type != NULL)
#define __Pyx_PyErr_CurrentExceptionType()  (__pyx_tstate->curexc_type)
#endif
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  (PyErr_Occurred() != NULL)
#define __Pyx_PyErr_CurrentExceptionType()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A6
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* PyObjectGetAttrStrNoError.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* TupleAndListFromArray.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n);
static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n);
#endif

/* IncludeStringH.proto */
#include <string.h>

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* fastcall.proto */
#if CYTHON_AVOID_BORROWED_REFS
    #define __Pyx_Arg_VARARGS(args, i) PySequence_GetItem(args, i)
#elif CYTHON_ASSUME_SAFE_MACROS
    #define __Pyx_Arg_VARARGS(args, i) PyTuple_GET_ITEM(args, i)
#else
    #define __Pyx_Arg_VARARGS(args, i) PyTuple_GetItem(args, i)
#endif
#if CYTHON_AVOID_BORROWED_REFS
    #define __Pyx_Arg_NewRef_VARARGS(arg) __Pyx_NewRef(arg)
    #define __Pyx_Arg_XDECREF_VARARGS(arg) Py_XDECREF(arg)
#else
    #define __Pyx_Arg_NewRef_VARARGS(arg) arg
    #define __Pyx_Arg_XDECREF_VARARGS(arg)
#endif
#define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds)
#define __Pyx_KwValues_VARARGS(args, nargs) NULL
#define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s)
#define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw)
#if CYTHON_METH_FASTCALL
    #define __Pyx_Arg_FASTCALL(args, i) args[i]
    #define __Pyx_NumKwargs_FASTCALL(kwds) PyTuple_GET_SIZE(kwds)
    #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs))
    static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s);
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
    CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues);
  #else
    #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw)
  #endif
    #define __Pyx_Arg_NewRef_FASTCALL(arg) arg  /* no-op, __Pyx_Arg_FASTCALL is direct and this needs
                                                   to have the same reference counting */
    #define __Pyx_Arg_XDECREF_FASTCALL(arg)
#else
    #define __Pyx_Arg_FASTCALL __Pyx_Arg_VARARGS
    #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS
    #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS
    #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS
    #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS
    #define __Pyx_Arg_NewRef_FASTCALL(arg) __Pyx_Arg_NewRef_VARARGS(arg)
    #define __Pyx_Arg_XDECREF_FASTCALL(arg) __Pyx_Arg_XDECREF_VARARGS(arg)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
#define __Pyx_ArgsSlice_VARARGS(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_VARARGS(args, start), stop - start)
#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_FASTCALL(args, start), stop - start)
#else
#define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop)
#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop)
#endif

/* RaiseArgTupleInvalid.proto */
static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject *const *kwvalues,
    PyObject **argnames[],
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,
    const char* function_name);

/* Profile.proto */
#ifndef CYTHON_PROFILE
#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
  #define CYTHON_PROFILE 0
#else
  #define CYTHON_PROFILE 1
#endif
#endif
#ifndef CYTHON_TRACE_NOGIL
  #define CYTHON_TRACE_NOGIL 0
#else
  #if CYTHON_TRACE_NOGIL && !defined(CYTHON_TRACE)
    #define CYTHON_TRACE 1
  #endif
#endif
#ifndef CYTHON_TRACE
  #define CYTHON_TRACE 0
#endif
#if CYTHON_TRACE
  #undef CYTHON_PROFILE_REUSE_FRAME
#endif
#ifndef CYTHON_PROFILE_REUSE_FRAME
  #define CYTHON_PROFILE_REUSE_FRAME 0
#endif
#if CYTHON_PROFILE || CYTHON_TRACE
  #include "compile.h"
  #include "frameobject.h"
  #include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
  #if CYTHON_PROFILE_REUSE_FRAME
    #define CYTHON_FRAME_MODIFIER static
    #define CYTHON_FRAME_DEL(frame)
  #else
    #define CYTHON_FRAME_MODIFIER
    #define CYTHON_FRAME_DEL(frame) Py_CLEAR(frame)
  #endif
  #define __Pyx_TraceDeclarations\
      static PyCodeObject *__pyx_frame_code = NULL;\
      CYTHON_FRAME_MODIFIER PyFrameObject *__pyx_frame = NULL;\
      int __Pyx_use_tracing = 0;
  #define __Pyx_TraceFrameInit(codeobj)\
      if (codeobj) __pyx_frame_code = (PyCodeObject*) codeobj;
#if PY_VERSION_HEX >= 0x030b00a2
  #if PY_VERSION_HEX >= 0x030C00b1
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     ((!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #else
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->cframe->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #endif
  #define __Pyx_EnterTracing(tstate)  PyThreadState_EnterTracing(tstate)
  #define __Pyx_LeaveTracing(tstate)  PyThreadState_LeaveTracing(tstate)
#elif PY_VERSION_HEX >= 0x030a00b1
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->cframe->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate)\
      do { tstate->tracing++; tstate->cframe->use_tracing = 0; } while (0)
  #define __Pyx_LeaveTracing(tstate)\
      do {\
          tstate->tracing--;\
          tstate->cframe->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL)\
                                 || tstate->c_profilefunc != NULL);\
      } while (0)
#else
  #define __Pyx_IsTracing(tstate, check_tracing, check_funcs)\
     (unlikely((tstate)->use_tracing) &&\
         (!(check_tracing) || !(tstate)->tracing) &&\
         (!(check_funcs) || (tstate)->c_profilefunc || (CYTHON_TRACE && (tstate)->c_tracefunc)))
  #define __Pyx_EnterTracing(tstate)\
      do { tstate->tracing++; tstate->use_tracing = 0; } while (0)
  #define __Pyx_LeaveTracing(tstate)\
      do {\
          tstate->tracing--;\
          tstate->use_tracing = ((CYTHON_TRACE && tstate->c_tracefunc != NULL)\
                                         || tstate->c_profilefunc != NULL);\
      } while (0)
#endif
  #ifdef WITH_THREAD
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  if (nogil) {\
      if (CYTHON_TRACE_NOGIL) {\
          PyThreadState *tstate;\
          PyGILState_STATE state = PyGILState_Ensure();\
          tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 1, 1)) {\
              __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          }\
          PyGILState_Release(state);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  } else {\
      PyThreadState* tstate = PyThreadState_GET();\
      if (__Pyx_IsTracing(tstate, 1, 1)) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  }
  #else
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  {   PyThreadState* tstate = PyThreadState_GET();\
      if (__Pyx_IsTracing(tstate, 1, 1)) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  }
  #endif
  #define __Pyx_TraceException()\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 1)) {\
          __Pyx_EnterTracing(tstate);\
          PyObject *exc_info = __Pyx_GetExceptionTuple(tstate);\
          if (exc_info) {\
              if (CYTHON_TRACE && tstate->c_tracefunc)\
                  tstate->c_tracefunc(\
                      tstate->c_traceobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);\
              tstate->c_profilefunc(\
                  tstate->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);\
              Py_DECREF(exc_info);\
          }\
          __Pyx_LeaveTracing(tstate);\
      }\
  }
  static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
      PyObject *type, *value, *traceback;
      __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
      __Pyx_EnterTracing(tstate);
      if (CYTHON_TRACE && tstate->c_tracefunc)
          tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result);
      if (tstate->c_profilefunc)
          tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result);
      CYTHON_FRAME_DEL(frame);
      __Pyx_LeaveTracing(tstate);
      __Pyx_ErrRestoreInState(tstate, type, value, traceback);
  }
  #ifdef WITH_THREAD
  #define __Pyx_TraceReturn(result, nogil)\
  if (likely(!__Pyx_use_tracing)); else {\
      if (nogil) {\
          if (CYTHON_TRACE_NOGIL) {\
              PyThreadState *tstate;\
              PyGILState_STATE state = PyGILState_Ensure();\
              tstate = __Pyx_PyThreadState_Current;\
              if (__Pyx_IsTracing(tstate, 0, 0)) {\
                  __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
              }\
              PyGILState_Release(state);\
          }\
      } else {\
          PyThreadState* tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 0, 0)) {\
              __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
          }\
      }\
  }
  #else
  #define __Pyx_TraceReturn(result, nogil)\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 0)) {\
          __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
      }\
  }
  #endif
  static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno);
  static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, PyThreadState* tstate, const char *funcname, const char *srcfile, int firstlineno);
#else
  #define __Pyx_TraceDeclarations
  #define __Pyx_TraceFrameInit(codeobj)
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)   if ((1)); else goto_error;
  #define __Pyx_TraceException()
  #define __Pyx_TraceReturn(result, nogil)
#endif
#if CYTHON_TRACE
  static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) {
      int ret;
      PyObject *type, *value, *traceback;
      __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
      __Pyx_PyFrame_SetLineNumber(frame, lineno);
      __Pyx_EnterTracing(tstate);
      ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
      __Pyx_LeaveTracing(tstate);
      if (likely(!ret)) {
          __Pyx_ErrRestoreInState(tstate, type, value, traceback);
      } else {
          Py_XDECREF(type);
          Py_XDECREF(value);
          Py_XDECREF(traceback);
      }
      return ret;
  }
  #ifdef WITH_THREAD
  #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  if (likely(!__Pyx_use_tracing)); else {\
      if (nogil) {\
          if (CYTHON_TRACE_NOGIL) {\
              int ret = 0;\
              PyThreadState *tstate;\
              PyGILState_STATE state = __Pyx_PyGILState_Ensure();\
              tstate = __Pyx_PyThreadState_Current;\
              if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
                  ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
              }\
              __Pyx_PyGILState_Release(state);\
              if (unlikely(ret)) goto_error;\
          }\
      } else {\
          PyThreadState* tstate = __Pyx_PyThreadState_Current;\
          if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
              int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
              if (unlikely(ret)) goto_error;\
          }\
      }\
  }
  #else
  #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = __Pyx_PyThreadState_Current;\
      if (__Pyx_IsTracing(tstate, 0, 0) && tstate->c_tracefunc && __pyx_frame->f_trace) {\
          int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
          if (unlikely(ret)) goto_error;\
      }\
  }
  #endif
#else
  #define __Pyx_TraceLine(lineno, nogil, goto_error)   if ((1)); else goto_error;
#endif

/* ListAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
        L->ob_item[len] = x;
        #else
        PyList_SET_ITEM(list, len, x);
        #endif
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#if !CYTHON_VECTORCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
#endif
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
    (sizeof(char [1 - 2*!(cond)]) - 1)
#ifndef Py_MEMBER_SIZE
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#endif
#if !CYTHON_VECTORCALL
#if PY_VERSION_HEX >= 0x03080000
  #include "frameobject.h"
#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
  #define __Pxy_PyFrame_Initialize_Offsets()
  #define __Pyx_PyFrame_GetLocalsplus(frame)  ((frame)->f_localsplus)
#else
  static size_t __pyx_pyframe_localsplus_offset = 0;
  #include "frameobject.h"
  #define __Pxy_PyFrame_Initialize_Offsets()\
    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
     (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  #define __Pyx_PyFrame_GetLocalsplus(frame)\
    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
#endif
#endif
#endif

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectFastCall.proto */
#define __Pyx_PyObject_FastCall(func, args, nargs)  __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL)
static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs);

/* PyObjectFormatAndDecref.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f);
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f);

/* PyObject_Unicode.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyObject_Unicode(obj)\
    (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj))
#else
#define __Pyx_PyObject_Unicode(obj)\
    (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Unicode(obj))
#endif

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject *key);
#else
#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
#endif

/* JoinPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char);

/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
    (version_var) = __PYX_GET_DICT_VERSION(dict);\
    (cache_var) = (value);
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
        (VAR) = __pyx_dict_cached_value;\
    } else {\
        (VAR) = __pyx_dict_cached_value = (LOOKUP);\
        __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
    }\
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
#else
#define __PYX_GET_DICT_VERSION(dict)  (0)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
#endif

/* GetModuleGlobalName.proto */
#if CYTHON_USE_DICT_VERSIONS
#define __Pyx_GetModuleGlobalName(var, name)  do {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
} while(0)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  do {\
    PY_UINT64_T __pyx_dict_version;\
    PyObject *__pyx_dict_cached_value;\
    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
} while(0)
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
#else
#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
#endif

/* PySequenceContains.proto */
static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* PyIntCompare.proto */
static CYTHON_INLINE int __Pyx_PyInt_BoolEqObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* KeywordStringCheck.proto */
static int __Pyx_CheckKeywordStrings(PyObject *kw, const char* function_name, int kw_allowed);

/* PyObjectCallNoArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);

/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
        L->ob_item[len] = x;
        #else
        PyList_SET_ITEM(list, len, x);
        #endif
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

/* SliceObject.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);
#define __Pyx_PyObject_Dict_GetItem(obj, name)\
    (likely(PyDict_CheckExact(obj)) ?\
     __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
#else
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyObject_Dict_GetItem(obj, name)  PyObject_GetItem(obj, name)
#endif

/* GetTopmostException.proto */
#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE
static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate);
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* UnicodeConcatInPlace.proto */
# if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
    #if CYTHON_REFNANNY
        #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right, __pyx_refnanny)
    #else
        #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right)
    #endif
    static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right
        #if CYTHON_REFNANNY
        , void* __pyx_refnanny
        #endif
    );
#else
#define __Pyx_PyUnicode_ConcatInPlace __Pyx_PyUnicode_Concat
#endif
#define __Pyx_PyUnicode_ConcatInPlaceSafe(left, right) ((unlikely((left) == Py_None) || unlikely((right) == Py_None)) ?\
    PyNumber_InPlaceAdd(left, right) : __Pyx_PyUnicode_ConcatInPlace(left, right))

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

/* AssertionsEnabled.proto */
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define __Pyx_init_assertions_enabled()  (0)
  #define __pyx_assertions_enabled()  (1)
#elif CYTHON_COMPILING_IN_LIMITED_API  ||  (CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030C0000)
  static int __pyx_assertions_enabled_flag;
  #define __pyx_assertions_enabled() (__pyx_assertions_enabled_flag)
  static int __Pyx_init_assertions_enabled(void) {
    PyObject *builtins, *debug, *debug_str;
    int flag;
    builtins = PyEval_GetBuiltins();
    if (!builtins) goto bad;
    debug_str = PyUnicode_FromStringAndSize("__debug__", 9);
    if (!debug_str) goto bad;
    debug = PyObject_GetItem(builtins, debug_str);
    Py_DECREF(debug_str);
    if (!debug) goto bad;
    flag = PyObject_IsTrue(debug);
    Py_DECREF(debug);
    if (flag == -1) goto bad;
    __pyx_assertions_enabled_flag = flag;
    return 0;
  bad:
    __pyx_assertions_enabled_flag = 1;
    return -1;
  }
#else
  #define __Pyx_init_assertions_enabled()  (0)
  #define __pyx_assertions_enabled()  (!Py_OptimizeFlag)
#endif

/* PyObjectCall2Args.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);

/* PyObjectGetMethod.proto */
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);

/* PyObjectCallMethod1.proto */
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

/* append.proto */
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* PyDictContains.proto */
static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
    int result = PyDict_Contains(dict, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* ArgTypeTest.proto */
#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
    ((likely(__Pyx_IS_TYPE(obj, type) | (none_allowed && (obj == Py_None)))) ? 1 :\
        __Pyx__ArgTypeTest(obj, type, name, exact))
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);

/* GetAttr.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);

/* HasAttr.proto */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *);

/* ExtTypeTest.proto */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

/* PyIntCompare.proto */
static CYTHON_INLINE int __Pyx_PyInt_BoolNeObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* PyObjectCallMethod0.proto */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);

/* RaiseNoneIterError.proto */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

/* UnpackTupleError.proto */
static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index);

/* UnpackTuple2.proto */
#define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple)\
    (likely(is_tuple || PyTuple_Check(tuple)) ?\
        (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ?\
            __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) :\
            (__Pyx_UnpackTupleError(tuple, 2), -1)) :\
        __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple))
static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
    PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple);
static int __Pyx_unpack_tuple2_generic(
    PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple);

/* dict_iter.proto */
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_is_dict);
static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
                                              PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);

/* MergeKeywords.proto */
static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AndObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAnd(op1, op2) : PyNumber_And(op1, op2))
#endif

/* RaiseUnexpectedTypeError.proto */
static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj);

/* GetItemIntUnicode.proto */
#define __Pyx_GetItemInt_Unicode(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Unicode_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "string index out of range"), (Py_UCS4)-1))
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i,
                                                           int wraparound, int boundscheck);

/* RaiseUnboundLocalError.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* pyfrozenset_new.proto */
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it);

/* PySetContains.proto */
static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq);

/* dict_getitem_default.proto */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value);

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

/* CallUnboundCMethod1.proto */
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#else
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg)  __Pyx__CallUnboundCMethod1(cfunc, self, arg)
#endif

/* CallUnboundCMethod2.proto */
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2);
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2);
#else
#define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2)  __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2)
#endif

/* GetAttr3.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* CallNextTpDealloc.proto */
static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc);

/* CallNextTpTraverse.proto */
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse);

/* CallNextTpClear.proto */
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear);

/* IncludeStructmemberH.proto */
#include <structmember.h>

/* FixUpExtensionType.proto */
#if CYTHON_USE_TYPE_SPECS
static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type);
#endif

/* ValidateBasesTuple.proto */
#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS
static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases);
#endif

/* PyType_Ready.proto */
CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t);

/* PyObject_GenericGetAttrNoDict.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
#endif

/* PyObject_GenericGetAttr.proto */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
#else
#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
#endif

/* SetupReduce.proto */
#if !CYTHON_COMPILING_IN_LIMITED_API
static int __Pyx_setup_reduce(PyObject* type_obj);
#endif

/* TypeImport.proto */
#ifndef __PYX_HAVE_RT_ImportType_proto_3_0_11
#define __PYX_HAVE_RT_ImportType_proto_3_0_11
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#include <stdalign.h>
#endif
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || __cplusplus >= 201103L
#define __PYX_GET_STRUCT_ALIGNMENT_3_0_11(s) alignof(s)
#else
#define __PYX_GET_STRUCT_ALIGNMENT_3_0_11(s) sizeof(void*)
#endif
enum __Pyx_ImportType_CheckSize_3_0_11 {
   __Pyx_ImportType_CheckSize_Error_3_0_11 = 0,
   __Pyx_ImportType_CheckSize_Warn_3_0_11 = 1,
   __Pyx_ImportType_CheckSize_Ignore_3_0_11 = 2
};
static PyTypeObject *__Pyx_ImportType_3_0_11(PyObject* module, const char *module_name, const char *class_name, size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_11 check_size);
#endif

/* GetVTable.proto */
static void* __Pyx_GetVtable(PyTypeObject *type);

/* SetVTable.proto */
static int __Pyx_SetVtable(PyTypeObject* typeptr , void* vtable);

/* MergeVTables.proto */
#if !CYTHON_COMPILING_IN_LIMITED_API
static int __Pyx_MergeVtables(PyTypeObject *type);
#endif

/* ImportDottedModule.proto */
static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple);
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple);
#endif

/* FetchSharedCythonModule.proto */
static PyObject *__Pyx_FetchSharedCythonABIModule(void);

/* FetchCommonType.proto */
#if !CYTHON_USE_TYPE_SPECS
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
#else
static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases);
#endif

/* PyMethodNew.proto */
#if CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) {
    PyObject *typesModule=NULL, *methodType=NULL, *result=NULL;
    CYTHON_UNUSED_VAR(typ);
    if (!self)
        return __Pyx_NewRef(func);
    typesModule = PyImport_ImportModule("types");
    if (!typesModule) return NULL;
    methodType = PyObject_GetAttrString(typesModule, "MethodType");
    Py_DECREF(typesModule);
    if (!methodType) return NULL;
    result = PyObject_CallFunctionObjArgs(methodType, func, self, NULL);
    Py_DECREF(methodType);
    return result;
}
#elif PY_MAJOR_VERSION >= 3
static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) {
    CYTHON_UNUSED_VAR(typ);
    if (!self)
        return __Pyx_NewRef(func);
    return PyMethod_New(func, self);
}
#else
    #define __Pyx_PyMethod_New PyMethod_New
#endif

/* PyVectorcallFastCallDict.proto */
#if CYTHON_METH_FASTCALL
static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw);
#endif

/* CythonFunctionShared.proto */
#define __Pyx_CyFunction_USED
#define __Pyx_CYFUNCTION_STATICMETHOD  0x01
#define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
#define __Pyx_CYFUNCTION_CCLASS        0x04
#define __Pyx_CYFUNCTION_COROUTINE     0x08
#define __Pyx_CyFunction_GetClosure(f)\
    (((__pyx_CyFunctionObject *) (f))->func_closure)
#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API
  #define __Pyx_CyFunction_GetClassObj(f)\
      (((__pyx_CyFunctionObject *) (f))->func_classobj)
#else
  #define __Pyx_CyFunction_GetClassObj(f)\
      ((PyObject*) ((PyCMethodObject *) (f))->mm_class)
#endif
#define __Pyx_CyFunction_SetClassObj(f, classobj)\
    __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj))
#define __Pyx_CyFunction_Defaults(type, f)\
    ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
    ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
typedef struct {
#if CYTHON_COMPILING_IN_LIMITED_API
    PyObject_HEAD
    PyObject *func;
#elif PY_VERSION_HEX < 0x030900B1
    PyCFunctionObject func;
#else
    PyCMethodObject func;
#endif
#if CYTHON_BACKPORT_VECTORCALL
    __pyx_vectorcallfunc func_vectorcall;
#endif
#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API
    PyObject *func_weakreflist;
#endif
    PyObject *func_dict;
    PyObject *func_name;
    PyObject *func_qualname;
    PyObject *func_doc;
    PyObject *func_globals;
    PyObject *func_code;
    PyObject *func_closure;
#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API
    PyObject *func_classobj;
#endif
    void *defaults;
    int defaults_pyobjects;
    size_t defaults_size;
    int flags;
    PyObject *defaults_tuple;
    PyObject *defaults_kwdict;
    PyObject *(*defaults_getter)(PyObject *);
    PyObject *func_annotations;
    PyObject *func_is_coroutine;
} __pyx_CyFunctionObject;
#undef __Pyx_CyOrPyCFunction_Check
#define __Pyx_CyFunction_Check(obj)  __Pyx_TypeCheck(obj, __pyx_CyFunctionType)
#define __Pyx_CyOrPyCFunction_Check(obj)  __Pyx_TypeCheck2(obj, __pyx_CyFunctionType, &PyCFunction_Type)
#define __Pyx_CyFunction_CheckExact(obj)  __Pyx_IS_TYPE(obj, __pyx_CyFunctionType)
static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc);
#undef __Pyx_IsSameCFunction
#define __Pyx_IsSameCFunction(func, cfunc)   __Pyx__IsSameCyOrCFunction(func, cfunc)
static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *closure,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);
static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj);
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
                                                         size_t size,
                                                         int pyobjects);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
                                                            PyObject *tuple);
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
                                                             PyObject *dict);
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
                                                              PyObject *dict);
static int __pyx_CyFunction_init(PyObject *module);
#if CYTHON_METH_FASTCALL
static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames);
#if CYTHON_BACKPORT_VECTORCALL
#define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall)
#else
#define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall)
#endif
#endif

/* CythonFunction.proto */
static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *closure,
                                      PyObject *module, PyObject *globals,
                                      PyObject* code);

/* ClassMethod.proto */
#include "descrobject.h"
CYTHON_UNUSED static PyObject* __Pyx_Method_ClassMethod(PyObject *method);

/* GetNameInClass.proto */
#define __Pyx_GetNameInClass(var, nmspace, name)  (var) = __Pyx__GetNameInClass(nmspace, name)
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name);

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#endif

/* CodeObjectCache.proto */
#if !CYTHON_COMPILING_IN_LIMITED_API
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
#endif

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* ArrayAPI.proto */
#ifndef _ARRAYARRAY_H
#define _ARRAYARRAY_H
typedef struct arraydescr {
    int typecode;
    int itemsize;
    PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
    int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
#if PY_MAJOR_VERSION >= 3
    char *formats;
#endif
} arraydescr;
struct arrayobject {
    PyObject_HEAD
    Py_ssize_t ob_size;
    union {
        char *ob_item;
        float *as_floats;
        double *as_doubles;
        int *as_ints;
        unsigned int *as_uints;
        unsigned char *as_uchars;
        signed char *as_schars;
        char *as_chars;
        unsigned long *as_ulongs;
        long *as_longs;
#if PY_MAJOR_VERSION >= 3
        unsigned long long *as_ulonglongs;
        long long *as_longlongs;
#endif
        short *as_shorts;
        unsigned short *as_ushorts;
        Py_UNICODE *as_pyunicodes;
        void *as_voidptr;
    } data;
    Py_ssize_t allocated;
    struct arraydescr *ob_descr;
    PyObject *weakreflist;
#if PY_MAJOR_VERSION >= 3
        int ob_exports;
#endif
};
#ifndef NO_NEWARRAY_INLINE
static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t size,
    struct arraydescr *descr) {
    arrayobject *op;
    size_t nbytes;
    if (size < 0) {
        PyErr_BadInternalCall();
        return NULL;
    }
    nbytes = size * descr->itemsize;
    if (nbytes / descr->itemsize != (size_t)size) {
        return PyErr_NoMemory();
    }
    op = (arrayobject *) type->tp_alloc(type, 0);
    if (op == NULL) {
        return NULL;
    }
    op->ob_descr = descr;
    op->allocated = size;
    op->weakreflist = NULL;
    __Pyx_SET_SIZE(op, size);
    if (size <= 0) {
        op->data.ob_item = NULL;
    }
    else {
        op->data.ob_item = PyMem_NEW(char, nbytes);
        if (op->data.ob_item == NULL) {
            Py_DECREF(op);
            return PyErr_NoMemory();
        }
    }
    return (PyObject *) op;
}
#else
PyObject* newarrayobject(PyTypeObject *type, Py_ssize_t size,
    struct arraydescr *descr);
#endif
static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
    void *items = (void*) self->data.ob_item;
    PyMem_Resize(items, char, (size_t)(n * self->ob_descr->itemsize));
    if (items == NULL) {
        PyErr_NoMemory();
        return -1;
    }
    self->data.ob_item = (char*) items;
    __Pyx_SET_SIZE(self, n);
    self->allocated = n;
    return 0;
}
static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
    void *items = (void*) self->data.ob_item;
    Py_ssize_t newsize;
    if (n < self->allocated && n*4 > self->allocated) {
        __Pyx_SET_SIZE(self, n);
        return 0;
    }
    newsize = n + (n / 2) + 1;
    if (newsize <= n) {
        PyErr_NoMemory();
        return -1;
    }
    PyMem_Resize(items, char, (size_t)(newsize * self->ob_descr->itemsize));
    if (items == NULL) {
        PyErr_NoMemory();
        return -1;
    }
    self->data.ob_item = (char*) items;
    __Pyx_SET_SIZE(self, n);
    self->allocated = newsize;
    return 0;
}
#endif

/* GCCDiagnostics.proto */
#if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define __Pyx_HAS_GCC_DIAGNOSTIC
#endif

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);

/* CIntFromPy.proto */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntFromPy.proto */
static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);

/* CIntFromPy.proto */
static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value);

/* CIntFromPy.proto */
static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *);

/* FormatTypeName.proto */
#if CYTHON_COMPILING_IN_LIMITED_API
typedef PyObject *__Pyx_TypeName;
#define __Pyx_FMT_TYPENAME "%U"
static __Pyx_TypeName __Pyx_PyType_GetName(PyTypeObject* tp);
#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj)
#else
typedef const char *__Pyx_TypeName;
#define __Pyx_FMT_TYPENAME "%.200s"
#define __Pyx_PyType_GetName(tp) ((tp)->tp_name)
#define __Pyx_DECREF_TypeName(obj)
#endif

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
#define __Pyx_TypeCheck2(obj, type1, type2) __Pyx_IsAnySubtype2(Py_TYPE(obj), (PyTypeObject *)type1, (PyTypeObject *)type2)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_TypeCheck2(obj, type1, type2) (PyObject_TypeCheck(obj, (PyTypeObject *)type1) || PyObject_TypeCheck(obj, (PyTypeObject *)type2))
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyErr_ExceptionMatches2(err1, err2)  __Pyx_PyErr_GivenExceptionMatches2(__Pyx_PyErr_CurrentExceptionType(), err1, err2)
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

/* CheckBinaryVersion.proto */
static unsigned long __Pyx_get_runtime_version(void);
static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer);

/* FunctionImport.proto */
static int __Pyx_ImportFunction_3_0_11(PyObject *module, const char *funcname, void (**f)(void), const char *sig);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

/* #### Code section: module_declarations ### */
static CYTHON_INLINE double __pyx_f_7cpython_7complex_7complex_4real_real(PyComplexObject *__pyx_v_self); /* proto*/
static CYTHON_INLINE double __pyx_f_7cpython_7complex_7complex_4imag_imag(PyComplexObject *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read, int __pyx_skip_dispatch); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_raw_rest_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_stop); /* proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto*/

/* Module declarations from "libc.stdint" */

/* Module declarations from "libc.string" */

/* Module declarations from "libc.stdlib" */

/* Module declarations from "libc.stdio" */

/* Module declarations from "cython" */

/* Module declarations from "cpython.version" */

/* Module declarations from "__builtin__" */

/* Module declarations from "cpython.type" */

/* Module declarations from "cpython.object" */

/* Module declarations from "cpython.ref" */

/* Module declarations from "cpython.exc" */

/* Module declarations from "cpython.module" */

/* Module declarations from "cpython.mem" */

/* Module declarations from "cpython.tuple" */

/* Module declarations from "cpython.list" */

/* Module declarations from "cpython.sequence" */

/* Module declarations from "cpython.mapping" */

/* Module declarations from "cpython.iterator" */

/* Module declarations from "cpython.number" */

/* Module declarations from "cpython.int" */

/* Module declarations from "__builtin__" */

/* Module declarations from "cpython.bool" */

/* Module declarations from "cpython.long" */

/* Module declarations from "cpython.float" */

/* Module declarations from "__builtin__" */

/* Module declarations from "cpython.complex" */

/* Module declarations from "cpython.string" */

/* Module declarations from "libc.stddef" */

/* Module declarations from "cpython.unicode" */

/* Module declarations from "cpython.pyport" */

/* Module declarations from "cpython.dict" */

/* Module declarations from "cpython.instance" */

/* Module declarations from "cpython.function" */

/* Module declarations from "cpython.method" */

/* Module declarations from "cpython.weakref" */

/* Module declarations from "cpython.getargs" */

/* Module declarations from "cpython.pythread" */

/* Module declarations from "cpython.pystate" */

/* Module declarations from "cpython.cobject" */

/* Module declarations from "cpython.oldbuffer" */

/* Module declarations from "cpython.set" */

/* Module declarations from "cpython.buffer" */

/* Module declarations from "cpython.bytes" */

/* Module declarations from "cpython.pycapsule" */

/* Module declarations from "cpython.contextvars" */

/* Module declarations from "cpython" */

/* Module declarations from "array" */

/* Module declarations from "cpython.array" */
static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *, Py_ssize_t, int); /*proto*/
static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, char *, Py_ssize_t); /*proto*/

/* Module declarations from "posix.types" */

/* Module declarations from "pysam.libchtslib" */

/* Module declarations from "pysam.libcfaidx" */

/* Module declarations from "pysam.libcalignedsegment" */
static struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *(*__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment)(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/
static struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *(*__pyx_f_5pysam_18libcalignedsegment_makePileupColumn)(bam_pileup1_t const **, int, int, int, uint32_t, char *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *); /*proto*/

/* Module declarations from "libc.errno" */

/* Module declarations from "pysam.libcutils" */
static PyObject *(*__pyx_f_5pysam_9libcutils_charptr_to_str)(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_force_str)(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_force_bytes)(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_encode_filename)(PyObject *); /*proto*/
static PyObject *(*__pyx_f_5pysam_9libcutils_from_string_and_size)(char const *, size_t); /*proto*/

/* Module declarations from "pysam.libcalignmentfile" */
static int __pyx_v_5pysam_17libcalignmentfile_MAX_POS;
static struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_nofilter(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_all(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile___advance_samtools(void *, bam1_t *); /*proto*/
static PyObject *__pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *, PyObject *); /*proto*/
/* #### Code section: typeinfo ### */
/* #### Code section: before_global_var ### */
#define __Pyx_MODULE_NAME "pysam.libcalignmentfile"
extern int __pyx_module_is_main_pysam__libcalignmentfile;
int __pyx_module_is_main_pysam__libcalignmentfile = 0;

/* Implementation of "pysam.libcalignmentfile" */
/* #### Code section: global_var ### */
static PyObject *__pyx_builtin_ImportError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_sum;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_AssertionError;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_NotImplementedError;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_super;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_OSError;
/* #### Code section: string_decls ### */
static const char __pyx_k_L[] = "L";
static const char __pyx_k_N[] = "N";
static const char __pyx_k_b[] = "b";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_h[] = "h";
static const char __pyx_k_n[] = "n";
static const char __pyx_k_r[] = "r";
static const char __pyx_k_s[] = "@%s";
static const char __pyx_k_t[] = "t";
static const char __pyx_k_w[] = "w";
static const char __pyx_k_x[] = "x";
static const char __pyx_k_y[] = "y";
static const char __pyx_k_AH[] = "AH";
static const char __pyx_k_AN[] = "AN";
static const char __pyx_k_AS[] = "AS";
static const char __pyx_k_BC[] = "BC";
static const char __pyx_k_CL[] = "CL";
static const char __pyx_k_CN[] = "CN";
static const char __pyx_k_CO[] = "CO";
static const char __pyx_k_DS[] = "DS";
static const char __pyx_k_DT[] = "DT";
static const char __pyx_k_FO[] = "FO";
static const char __pyx_k_GO[] = "GO";
static const char __pyx_k_HD[] = "HD";
static const char __pyx_k_ID[] = "ID";
static const char __pyx_k_KS[] = "KS";
static const char __pyx_k_LB[] = "LB";
static const char __pyx_k_LN[] = "LN";
static const char __pyx_k_M5[] = "M5";
static const char __pyx_k_PG[] = "PG";
static const char __pyx_k_PI[] = "PI";
static const char __pyx_k_PL[] = "PL";
static const char __pyx_k_PM[] = "PM";
static const char __pyx_k_PN[] = "PN";
static const char __pyx_k_PP[] = "PP";
static const char __pyx_k_PU[] = "PU";
static const char __pyx_k_RG[] = "RG";
static const char __pyx_k_SM[] = "SM";
static const char __pyx_k_SN[] = "SN";
static const char __pyx_k_SO[] = "SO";
static const char __pyx_k_SP[] = "SP";
static const char __pyx_k_SQ[] = "@SQ";
static const char __pyx_k_SS[] = "SS";
static const char __pyx_k_TP[] = "TP";
static const char __pyx_k_UR[] = "UR";
static const char __pyx_k_VN[] = "VN";
static const char __pyx_k__2[] = ":";
static const char __pyx_k__3[] = "\t";
static const char __pyx_k_gc[] = "gc";
static const char __pyx_k_io[] = "io";
static const char __pyx_k_nt[] = "nt";
static const char __pyx_k_op[] = "op";
static const char __pyx_k_os[] = "os";
static const char __pyx_k_rU[] = "rU";
static const char __pyx_k_rb[] = "rb";
static const char __pyx_k_rc[] = "rc";
static const char __pyx_k_re[] = "re";
static const char __pyx_k_sq[] = "sq";
static const char __pyx_k_wb[] = "wb";
static const char __pyx_k_wc[] = "wc";
static const char __pyx_k_wh[] = "wh";
static const char __pyx_k__12[] = "\n";
static const char __pyx_k__15[] = "";
static const char __pyx_k__19[] = " \000";
static const char __pyx_k__20[] = "@";
static const char __pyx_k__21[] = "': '";
static const char __pyx_k__22[] = "'";
static const char __pyx_k__46[] = "-";
static const char __pyx_k_all[] = "all";
static const char __pyx_k_beg[] = "beg";
static const char __pyx_k_cls[] = "cls";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_hdr[] = "hdr";
static const char __pyx_k_idx[] = "idx";
static const char __pyx_k_key[] = "key";
static const char __pyx_k_len[] = "__len__";
static const char __pyx_k_map[] = "map";
static const char __pyx_k_new[] = "__new__";
static const char __pyx_k_pos[] = "pos";
static const char __pyx_k_ref[] = "ref";
static const char __pyx_k_res[] = "res";
static const char __pyx_k_ret[] = "ret";
static const char __pyx_k_seq[] = "seq";
static const char __pyx_k_str[] = "__str__";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_tid[] = "tid";
static const char __pyx_k_wb0[] = "wb0";
static const char __pyx_k_wbu[] = "wbu";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_SQ_2[] = "SQ";
static const char __pyx_k__124[] = ".";
static const char __pyx_k__125[] = "*";
static const char __pyx_k__172[] = "?";
static const char __pyx_k_args[] = "args";
static const char __pyx_k_code[] = "code";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_data[] = "data";
static const char __pyx_k_dict[] = "__dict__";
static const char __pyx_k_exit[] = "__exit__";
static const char __pyx_k_find[] = "find";
static const char __pyx_k_flag[] = "flag";
static const char __pyx_k_head[] = "head";
static const char __pyx_k_init[] = "__init__";
static const char __pyx_k_keys[] = "keys";
static const char __pyx_k_line[] = "line";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_make[] = "_make";
static const char __pyx_k_mate[] = "mate";
static const char __pyx_k_mode[] = "mode";
static const char __pyx_k_name[] = "name";
static const char __pyx_k_open[] = "_open";
static const char __pyx_k_port[] = "port";
static const char __pyx_k_qpos[] = "qpos";
static const char __pyx_k_read[] = "read";
static const char __pyx_k_rtid[] = "rtid";
static const char __pyx_k_self[] = "self";
static const char __pyx_k_spec[] = "__spec__";
static const char __pyx_k_stop[] = "stop";
static const char __pyx_k_tell[] = "tell";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_text[] = "text";
static const char __pyx_k_warn[] = "warn";
static const char __pyx_k_all_2[] = "__all__";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_btext[] = "btext";
static const char __pyx_k_build[] = "build";
static const char __pyx_k_cigar[] = "cigar";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_cmode[] = "cmode";
static const char __pyx_k_count[] = "count";
static const char __pyx_k_ctext[] = "ctext";
static const char __pyx_k_enter[] = "__enter__";
static const char __pyx_k_fetch[] = "fetch";
static const char __pyx_k_field[] = "field";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_lines[] = "lines";
static const char __pyx_k_qname[] = "qname";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_rstop[] = "rstop";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_start[] = "start";
static const char __pyx_k_state[] = "state";
static const char __pyx_k_strip[] = "strip";
static const char __pyx_k_super[] = "super";
static const char __pyx_k_total[] = "total";
static const char __pyx_k_value[] = "value";
static const char __pyx_k_write[] = "write";
static const char __pyx_k_append[] = "append";
static const char __pyx_k_closed[] = "closed";
static const char __pyx_k_contig[] = "contig";
static const char __pyx_k_dict_2[] = "_dict";
static const char __pyx_k_enable[] = "enable";
static const char __pyx_k_fields[] = "fields";
static const char __pyx_k_fileno[] = "fileno";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_gettid[] = "gettid";
static const char __pyx_k_header[] = "header";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_is_bam[] = "is_bam";
static const char __pyx_k_kwargs[] = "kwargs";
static const char __pyx_k_l_text[] = "l_text";
static const char __pyx_k_length[] = "length";
static const char __pyx_k_mapped[] = "mapped";
static const char __pyx_k_name_2[] = "__name__";
static const char __pyx_k_pickle[] = "pickle";
static const char __pyx_k_pileup[] = "pileup";
static const char __pyx_k_record[] = "record";
static const char __pyx_k_reduce[] = "__reduce__";
static const char __pyx_k_refpos[] = "refpos";
static const char __pyx_k_region[] = "region";
static const char __pyx_k_result[] = "result";
static const char __pyx_k_rstart[] = "rstart";
static const char __pyx_k_stop_2[] = "_stop";
static const char __pyx_k_update[] = "update";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_Counter[] = "Counter";
static const char __pyx_k_IOError[] = "IOError";
static const char __pyx_k_Mapping[] = "Mapping";
static const char __pyx_k_OSError[] = "OSError";
static const char __pyx_k_SNPCall[] = "SNPCall";
static const char __pyx_k_as_dict[] = "as_dict";
static const char __pyx_k_count_a[] = "count_a";
static const char __pyx_k_count_c[] = "count_c";
static const char __pyx_k_count_g[] = "count_g";
static const char __pyx_k_count_t[] = "count_t";
static const char __pyx_k_counter[] = "counter";
static const char __pyx_k_disable[] = "disable";
static const char __pyx_k_get_tid[] = "get_tid";
static const char __pyx_k_getitem[] = "__getitem__";
static const char __pyx_k_is_cram[] = "is_cram";
static const char __pyx_k_is_open[] = "is_open";
static const char __pyx_k_islower[] = "islower";
static const char __pyx_k_isupper[] = "isupper";
static const char __pyx_k_lengths[] = "lengths";
static const char __pyx_k_quality[] = "quality";
static const char __pyx_k_results[] = "results";
static const char __pyx_k_samfile[] = "samfile";
static const char __pyx_k_start_2[] = "_start";
static const char __pyx_k_stepper[] = "stepper";
static const char __pyx_k_threads[] = "threads";
static const char __pyx_k_to_dict[] = "to_dict";
static const char __pyx_k_KeyError[] = "KeyError";
static const char __pyx_k_SQ_SN_LN[] = "@SQ\tSN:{}\tLN:{}\n";
static const char __pyx_k_Sequence[] = "Sequence";
static const char __pyx_k_StringIO[] = "StringIO";
static const char __pyx_k_check_sq[] = "check_sq";
static const char __pyx_k_contains[] = "__contains__";
static const char __pyx_k_coverage[] = "coverage";
static const char __pyx_k_exc_type[] = "exc_type";
static const char __pyx_k_filename[] = "filename";
static const char __pyx_k_genotype[] = "genotype";
static const char __pyx_k_getrname[] = "getrname";
static const char __pyx_k_getstate[] = "__getstate__";
static const char __pyx_k_nextiter[] = "nextiter";
static const char __pyx_k_nofilter[] = "nofilter";
static const char __pyx_k_pyx_type[] = "__pyx_type";
static const char __pyx_k_read_loc[] = "read_loc";
static const char __pyx_k_redo_baq[] = "redo_baq";
static const char __pyx_k_samtools[] = "samtools";
static const char __pyx_k_setstate[] = "__setstate__";
static const char __pyx_k_template[] = "template";
static const char __pyx_k_truncate[] = "truncate";
static const char __pyx_k_unmapped[] = "unmapped";
static const char __pyx_k_warnings[] = "warnings";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_cfilename[] = "cfilename";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_exc_value[] = "exc_value";
static const char __pyx_k_fastafile[] = "fastafile";
static const char __pyx_k_from_dict[] = "from_dict";
static const char __pyx_k_from_text[] = "from_text";
static const char __pyx_k_has_coord[] = "has_coord";
static const char __pyx_k_has_index[] = "has_index";
static const char __pyx_k_isenabled[] = "isenabled";
static const char __pyx_k_iteritems[] = "iteritems";
static const char __pyx_k_max_depth[] = "max_depth";
static const char __pyx_k_positions[] = "positions";
static const char __pyx_k_pyx_state[] = "__pyx_state";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
static const char __pyx_k_reference[] = "reference";
static const char __pyx_k_threshold[] = "_threshold";
static const char __pyx_k_traceback[] = "traceback";
static const char __pyx_k_until_eof[] = "until_eof";
static const char __pyx_k_IndexStats[] = "IndexStats";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_bfile_name[] = "bfile_name";
static const char __pyx_k_cindexname[] = "cindexname";
static const char __pyx_k_genome_loc[] = "genome_loc";
static const char __pyx_k_junc_start[] = "junc_start";
static const char __pyx_k_namedtuple[] = "namedtuple";
static const char __pyx_k_pyx_result[] = "__pyx_result";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_query_name[] = "query_name";
static const char __pyx_k_references[] = "references";
static const char __pyx_k_splitlines[] = "splitlines";
static const char __pyx_k_startswith[] = "startswith";
static const char __pyx_k_ImportError[] = "ImportError";
static const char __pyx_k_IteratorRow[] = "IteratorRow";
static const char __pyx_k_MemoryError[] = "MemoryError";
static const char __pyx_k_OrderedDict[] = "OrderedDict";
static const char __pyx_k_PickleError[] = "PickleError";
static const char __pyx_k_add_sq_text[] = "add_sq_text";
static const char __pyx_k_check_index[] = "check_index";
static const char __pyx_k_cigarstring[] = "cigarstring";
static const char __pyx_k_cigartuples[] = "cigartuples";
static const char __pyx_k_collections[] = "collections";
static const char __pyx_k_compute_baq[] = "compute_baq";
static const char __pyx_k_defaultdict[] = "defaultdict";
static const char __pyx_k_flag_filter[] = "flag_filter";
static const char __pyx_k_header_dict[] = "header_dict";
static const char __pyx_k_nreferences[] = "nreferences";
static const char __pyx_k_snp_quality[] = "snp_quality";
static const char __pyx_k_IndexedReads[] = "IndexedReads";
static const char __pyx_k_addReference[] = "addReference";
static const char __pyx_k_check_header[] = "check_header";
static const char __pyx_k_find_introns[] = "find_introns";
static const char __pyx_k_flag_require[] = "flag_require";
static const char __pyx_k_hasReference[] = "hasReference";
static const char __pyx_k_initializing[] = "_initializing";
static const char __pyx_k_is_coroutine[] = "_is_coroutine";
static const char __pyx_k_is_valid_tid[] = "is_valid_tid";
static const char __pyx_k_parse_region[] = "parse_region";
static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
static const char __pyx_k_stringsource[] = "<stringsource>";
static const char __pyx_k_use_setstate[] = "use_setstate";
static const char __pyx_k_AlignmentFile[] = "AlignmentFile";
static const char __pyx_k_BAM_CREF_SKIP[] = "BAM_CREF_SKIP";
static const char __pyx_k_StopIteration[] = "StopIteration";
static const char __pyx_k_VALID_HEADERS[] = "VALID_HEADERS";
static const char __pyx_k_add_reference[] = "add_reference";
static const char __pyx_k_base_position[] = "base_position";
static const char __pyx_k_class_getitem[] = "__class_getitem__";
static const char __pyx_k_contig_length[] = "contig_length";
static const char __pyx_k_filter_method[] = "filter_method";
static const char __pyx_k_has_reference[] = "has_reference";
static const char __pyx_k_last_read_pos[] = "last_read_pos";
static const char __pyx_k_read_callback[] = "read_callback";
static const char __pyx_k_read_iterator[] = "read_iterator";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
static const char __pyx_k_require_index[] = "require_index";
static const char __pyx_k_AssertionError[] = "AssertionError";
static const char __pyx_k_AttributeError[] = "AttributeError";
static const char __pyx_k_IteratorColumn[] = "IteratorColumn";
static const char __pyx_k_IteratorRowAll[] = "IteratorRowAll";
static const char __pyx_k_add_sam_header[] = "add_sam_header";
static const char __pyx_k_count_coverage[] = "count_coverage";
static const char __pyx_k_filepath_index[] = "filepath_index";
static const char __pyx_k_format_options[] = "format_options";
static const char __pyx_k_ignore_orphans[] = "ignore_orphans";
static const char __pyx_k_index_filename[] = "index_filename";
static const char __pyx_k_mate_not_found[] = "mate not found";
static const char __pyx_k_reference_base[] = "reference_base";
static const char __pyx_k_referencenames[] = "referencenames";
static const char __pyx_k_truncated_file[] = "truncated file";
static const char __pyx_k_AlignmentHeader[] = "AlignmentHeader";
static const char __pyx_k_IteratorRowHead[] = "IteratorRowHead";
static const char __pyx_k_add_hts_options[] = "add_hts_options";
static const char __pyx_k_collections_abc[] = "collections.abc";
static const char __pyx_k_from_references[] = "from_references";
static const char __pyx_k_ignore_overlaps[] = "ignore_overlaps";
static const char __pyx_k_mapping_quality[] = "mapping_quality";
static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
static const char __pyx_k_query_qualities[] = "query_qualities";
static const char __pyx_k_reference_names[] = "reference_names";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
static const char __pyx_k_check_truncation[] = "check_truncation";
static const char __pyx_k_min_base_quality[] = "min_base_quality";
static const char __pyx_k_read_s_not_found[] = "read %s not found";
static const char __pyx_k_referencelengths[] = "referencelengths";
static const char __pyx_k_IndexedReads_find[] = "IndexedReads.find";
static const char __pyx_k_IteratorColumnAll[] = "IteratorColumnAll";
static const char __pyx_k_IteratorRowRegion[] = "IteratorRowRegion";
static const char __pyx_k_build_header_line[] = "build_header_line";
static const char __pyx_k_consensus_quality[] = "consensus_quality";
static const char __pyx_k_find_introns_slow[] = "find_introns_slow";
static const char __pyx_k_get_aligned_pairs[] = "get_aligned_pairs";
static const char __pyx_k_ignore_truncation[] = "ignore_truncation";
static const char __pyx_k_match_or_deletion[] = "match_or_deletion";
static const char __pyx_k_quality_threshold[] = "quality_threshold";
static const char __pyx_k_reference_lengths[] = "reference_lengths";
static const char __pyx_k_unknown_reference[] = "unknown reference {}";
static const char __pyx_k_AlignmentFile_head[] = "AlignmentFile.head";
static const char __pyx_k_AlignmentFile_mate[] = "AlignmentFile.mate";
static const char __pyx_k_IndexedReads_build[] = "IndexedReads.build";
static const char __pyx_k_IteratorRowAllRefs[] = "IteratorRowAllRefs";
static const char __pyx_k_VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER";
static const char __pyx_k_VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES";
static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_filepath_or_object[] = "filepath_or_object";
static const char __pyx_k_get_reference_name[] = "get_reference_name";
static const char __pyx_k_int_array_template[] = "int_array_template";
static const char __pyx_k_interval_of_size_0[] = "interval of size 0";
static const char __pyx_k_mate_s_is_unmapped[] = "mate %s: is unmapped";
static const char __pyx_k_multiple_iterators[] = "multiple_iterators";
static const char __pyx_k_read_s_is_unpaired[] = "read %s: is unpaired";
static const char __pyx_k_reference_filename[] = "reference_filename";
static const char __pyx_k_AlignmentFile__open[] = "AlignmentFile._open";
static const char __pyx_k_AlignmentFile_close[] = "AlignmentFile.close";
static const char __pyx_k_AlignmentFile_count[] = "AlignmentFile.count";
static const char __pyx_k_AlignmentFile_fetch[] = "AlignmentFile.fetch";
static const char __pyx_k_AlignmentFile_write[] = "AlignmentFile.write";
static const char __pyx_k_AlignmentHeader_get[] = "AlignmentHeader.get";
static const char __pyx_k_KNOWN_HEADER_FIELDS[] = "KNOWN_HEADER_FIELDS";
static const char __pyx_k_NotImplementedError[] = "NotImplementedError";
static const char __pyx_k_creference_filename[] = "creference_filename";
static const char __pyx_k_min_mapping_quality[] = "min_mapping_quality";
static const char __pyx_k_read_failure_reason[] = "read_failure_reason";
static const char __pyx_k_AlignmentFile___exit[] = "AlignmentFile.__exit__";
static const char __pyx_k_AlignmentFile_gettid[] = "AlignmentFile.gettid";
static const char __pyx_k_AlignmentFile_pileup[] = "AlignmentFile.pileup";
static const char __pyx_k_AlignmentHeader_copy[] = "AlignmentHeader.copy";
static const char __pyx_k_AlignmentHeader_keys[] = "AlignmentHeader.keys";
static const char __pyx_k_IteratorColumnRegion[] = "IteratorColumnRegion";
static const char __pyx_k_IteratorRowSelection[] = "IteratorRowSelection";
static const char __pyx_k_duplicate_filehandle[] = "duplicate_filehandle";
static const char __pyx_k_get_index_statistics[] = "get_index_statistics";
static const char __pyx_k_get_reference_length[] = "get_reference_length";
static const char __pyx_k_pyx_unpickle_SNPCall[] = "__pyx_unpickle_SNPCall";
static const char __pyx_k_AlignmentFile___enter[] = "AlignmentFile.__enter__";
static const char __pyx_k_AlignmentFile_get_tid[] = "AlignmentFile.get_tid";
static const char __pyx_k_AlignmentHeader_items[] = "AlignmentHeader.items";
static const char __pyx_k_IteratorColumnAllRefs[] = "IteratorColumnAllRefs";
static const char __pyx_k_adjust_capq_threshold[] = "adjust_capq_threshold";
static const char __pyx_k_from_text_and_lengths[] = "_from_text_and_lengths";
static const char __pyx_k_header_line_without_s[] = "header line without '@': '%s'";
static const char __pyx_k_AlignmentFile_getrname[] = "AlignmentFile.getrname";
static const char __pyx_k_AlignmentHeader_values[] = "AlignmentHeader.values";
static const char __pyx_k_build_sequence_section[] = "_build_sequence_section";
static const char __pyx_k_could_not_parse_header[] = "could not parse header";
static const char __pyx_k_error_during_iteration[] = "error during iteration";
static const char __pyx_k_AlignmentFile_has_index[] = "AlignmentFile.has_index";
static const char __pyx_k_AlignmentHeader_as_dict[] = "AlignmentHeader.as_dict";
static const char __pyx_k_AlignmentHeader_get_tid[] = "AlignmentHeader.get_tid";
static const char __pyx_k_AlignmentHeader_to_dict[] = "AlignmentHeader.to_dict";
static const char __pyx_k_SNPCall___reduce_cython[] = "SNPCall.__reduce_cython__";
static const char __pyx_k_could_not_create_header[] = "could not create header";
static const char __pyx_k_pysam_libcalignmentfile[] = "pysam.libcalignmentfile";
static const char __pyx_k_could_not_allocate_bytes[] = "could not allocate {} bytes";
static const char __pyx_k_error_while_reading_file[] = "error {} while reading file";
static const char __pyx_k_unable_to_reopen_htsfile[] = "unable to reopen htsfile";
static const char __pyx_k_AlignmentFile_check_index[] = "AlignmentFile.check_index";
static const char __pyx_k_AlignmentHeader_from_dict[] = "AlignmentHeader.from_dict";
static const char __pyx_k_AlignmentHeader_from_text[] = "AlignmentHeader.from_text";
static const char __pyx_k_AlignmentHeader_iteritems[] = "AlignmentHeader.iteritems";
static const char __pyx_k_SNPCall___setstate_cython[] = "SNPCall.__setstate_cython__";
static const char __pyx_k_unable_to_open_index_file[] = "unable to open index file";
static const char __pyx_k_AlignmentFile_find_introns[] = "AlignmentFile.find_introns";
static const char __pyx_k_AlignmentFile_is_valid_tid[] = "AlignmentFile.is_valid_tid";
static const char __pyx_k_error_while_reading_file_2[] = "error while reading file {}: {}";
static const char __pyx_k_IteratorColumn_addReference[] = "IteratorColumn.addReference";
static const char __pyx_k_IteratorColumn_hasReference[] = "IteratorColumn.hasReference";
static const char __pyx_k_IteratorRowAllRefs_nextiter[] = "IteratorRowAllRefs.nextiter";
static const char __pyx_k_IteratorRow___reduce_cython[] = "IteratorRow.__reduce_cython__";
static const char __pyx_k_invalid_file_opening_mode_s[] = "invalid file opening mode `%s`";
static const char __pyx_k_pysam_libcalignmentfile_pyx[] = "pysam/libcalignmentfile.pyx";
static const char __pyx_k_unable_to_open_index_file_s[] = "unable to open index file `%s`";
static const char __pyx_k_AlignmentFile_count_coverage[] = "AlignmentFile.count_coverage";
static const char __pyx_k_AlignmentHeader_is_valid_tid[] = "AlignmentHeader.is_valid_tid";
static const char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file";
static const char __pyx_k_IndexedReads___reduce_cython[] = "IndexedReads.__reduce_cython__";
static const char __pyx_k_IteratorColumn_add_reference[] = "IteratorColumn.add_reference";
static const char __pyx_k_IteratorColumn_has_reference[] = "IteratorColumn.has_reference";
static const char __pyx_k_interval_of_size_less_than_0[] = "interval of size less than 0";
static const char __pyx_k_no_index_available_for_fetch[] = "no index available for fetch";
static const char __pyx_k_AlignmentFile___reduce_cython[] = "AlignmentFile.__reduce_cython__";
static const char __pyx_k_IteratorRow___setstate_cython[] = "IteratorRow.__setstate_cython__";
static const char __pyx_k_could_not_open_alignment_file[] = "could not open alignment file `{}`: {}";
static const char __pyx_k_header_line_with_invalid_type[] = "header line with invalid type '";
static const char __pyx_k_no_index_available_for_pileup[] = "no index available for pileup";
static const char __pyx_k_IndexedReads___setstate_cython[] = "IndexedReads.__setstate_cython__";
static const char __pyx_k_IteratorColumn___reduce_cython[] = "IteratorColumn.__reduce_cython__";
static const char __pyx_k_IteratorRowAll___reduce_cython[] = "IteratorRowAll.__reduce_cython__";
static const char __pyx_k_AlignmentFile___setstate_cython[] = "AlignmentFile.__setstate_cython__";
static const char __pyx_k_AlignmentFile_find_introns_slow[] = "AlignmentFile.find_introns_slow";
static const char __pyx_k_AlignmentHeader___reduce_cython[] = "AlignmentHeader.__reduce_cython__";
static const char __pyx_k_AlignmentHeader__build_sequence[] = "AlignmentHeader._build_sequence_section";
static const char __pyx_k_AlignmentHeader_from_references[] = "AlignmentHeader.from_references";
static const char __pyx_k_IteratorColumnRegion___setstate[] = "IteratorColumnRegion.__setstate_cython__";
static const char __pyx_k_IteratorRowHead___reduce_cython[] = "IteratorRowHead.__reduce_cython__";
static const char __pyx_k_IteratorRowSelection___setstate[] = "IteratorRowSelection.__setstate_cython__";
static const char __pyx_k_could_not_open_alignment_file_2[] = "could not open alignment file `{}`";
static const char __pyx_k_fetch_called_on_bamfile_without[] = "fetch called on bamfile without index";
static const char __pyx_k_file_does_not_contain_alignment[] = "file does not contain alignment data";
static const char __pyx_k_incomplete_sequence_information[] = "incomplete sequence information in '%s'";
static const char __pyx_k_malformatted_header_no_in_field[] = "malformatted header: no ':' in field";
static const char __pyx_k_wrong_sequence_information_in_s[] = "wrong sequence information in '%s'";
static const char __pyx_k_AlignedSegment_refers_to_referen[] = "AlignedSegment refers to reference number {} that is larger than the number of references ({}) in the header";
static const char __pyx_k_AlignmentFile_get_index_statisti[] = "AlignmentFile.get_index_statistics";
static const char __pyx_k_AlignmentFile_get_reference_leng[] = "AlignmentFile.get_reference_length";
static const char __pyx_k_AlignmentFile_get_reference_name[] = "AlignmentFile.get_reference_name";
static const char __pyx_k_AlignmentFile_mapped_only_availa[] = "AlignmentFile.mapped only available in bam files";
static const char __pyx_k_AlignmentHeader___setstate_cytho[] = "AlignmentHeader.__setstate_cython__";
static const char __pyx_k_AlignmentHeader__from_text_and_l[] = "AlignmentHeader._from_text_and_lengths";
static const char __pyx_k_AlignmentHeader_does_not_support[] = "AlignmentHeader does not support item assignment (use header.to_dict()";
static const char __pyx_k_AlignmentHeader_get_reference_le[] = "AlignmentHeader.get_reference_length";
static const char __pyx_k_AlignmentHeader_get_reference_na[] = "AlignmentHeader.get_reference_name";
static const char __pyx_k_Cannot_add_extra_threads_when_ig[] = "Cannot add extra threads when \"ignore_truncation\" is True";
static const char __pyx_k_Incompatible_checksums_0x_x_vs_0[] = "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))";
static const char __pyx_k_IteratorColumnAllRefs___reduce_c[] = "IteratorColumnAllRefs.__reduce_cython__";
static const char __pyx_k_IteratorColumnAllRefs___setstate[] = "IteratorColumnAllRefs.__setstate_cython__";
static const char __pyx_k_IteratorColumnAll___reduce_cytho[] = "IteratorColumnAll.__reduce_cython__";
static const char __pyx_k_IteratorColumnAll___setstate_cyt[] = "IteratorColumnAll.__setstate_cython__";
static const char __pyx_k_IteratorColumnRegion___reduce_cy[] = "IteratorColumnRegion.__reduce_cython__";
static const char __pyx_k_IteratorColumn___setstate_cython[] = "IteratorColumn.__setstate_cython__";
static const char __pyx_k_IteratorRowAllRefs___reduce_cyth[] = "IteratorRowAllRefs.__reduce_cython__";
static const char __pyx_k_IteratorRowAllRefs___setstate_cy[] = "IteratorRowAllRefs.__setstate_cython__";
static const char __pyx_k_IteratorRowAll___setstate_cython[] = "IteratorRowAll.__setstate_cython__";
static const char __pyx_k_IteratorRowHead___setstate_cytho[] = "IteratorRowHead.__setstate_cython__";
static const char __pyx_k_IteratorRowRegion___reduce_cytho[] = "IteratorRowRegion.__reduce_cython__";
static const char __pyx_k_IteratorRowRegion___setstate_cyt[] = "IteratorRowRegion.__setstate_cython__";
static const char __pyx_k_IteratorRowSelection___reduce_cy[] = "IteratorRowSelection.__reduce_cython__";
static const char __pyx_k_Raw_iterator_set_up_without_regi[] = "Raw iterator set up without region cannot be reset";
static const char __pyx_k_SAM_file_does_not_have_a_valid_h[] = "SAM? file does not have a valid header (mode='%s'), please provide reference_names and reference_lengths";
static const char __pyx_k_access_from_StringIO_objects_not[] = "access from StringIO objects not supported";
static const char __pyx_k_can_not_iterate_over_samfile_wit[] = "can not iterate over samfile without header";
static const char __pyx_k_can_only_apply_IndexReads_on_bam[] = "can only apply IndexReads on bam files";
static const char __pyx_k_cannot_create_AlignmentHeader_re[] = "cannot create AlignmentHeader, received NULL pointer";
static const char __pyx_k_could_not_allocate_memory_of_siz[] = "could not allocate memory of size {}";
static const char __pyx_k_either_supply_options_template_h[] = "either supply options `template`, `header`, `text` or  both `reference_names` and `reference_lengths` for writing";
static const char __pyx_k_failure_when_setting_reference_f[] = "failure when setting reference filename";
static const char __pyx_k_fetching_by_region_is_not_availa[] = "fetching by region is not available for SAM files";
static const char __pyx_k_file_does_not_have_a_valid_heade[] = "file does not have a valid header (mode='%s') - is it BAM/CRAM format?";
static const char __pyx_k_file_has_no_sequences_defined_mo[] = "file has no sequences defined (mode='%s') - is it SAM/BAM format? Consider opening with check_sq=False";
static const char __pyx_k_header_not_available_in_closed_f[] = "header not available in closed files";
static const char __pyx_k_invalid_type_for_record_s_s_expe[] = "invalid type for record %s: %s, expected %s";
static const char __pyx_k_mapping_information_not_recorded[] = "mapping information not recorded in index or index not available";
static const char __pyx_k_multiple_iterators_not_implement[] = "multiple iterators not implemented for SAM files";
static const char __pyx_k_multiple_s_lines_are_not_permitt[] = "multiple '%s' lines are not permitted";
static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__";
static const char __pyx_k_no_index_available_for_iteration[] = "no index available for iteration";
static const char __pyx_k_not_enough_information_to_constr[] = "not enough information to construct header. Please provide template, header, text or reference_names/reference_lengths";
static const char __pyx_k_number_of_reference_names_and_le[] = "number of reference names and lengths do not match";
static const char __pyx_k_reference_id_i_out_of_range_0_ti[] = "reference_id %i out of range 0<=tid<%i";
static const char __pyx_k_reference_sequence_for_tid_not_f[] = "reference sequence for '{}' (tid={}) not found";
static const char __pyx_k_sam_write1_failed_with_error_cod[] = "sam_write1 failed with error code {}";
static const char __pyx_k_self_b_self_htsfile_self_index_c[] = "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling";
static const char __pyx_k_self_b_self_htsfile_self_index_s[] = "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling";
static const char __pyx_k_self_htsfile_cannot_be_converted[] = "self.htsfile cannot be converted to a Python object for pickling";
static const char __pyx_k_unable_to_read_header_informatio[] = "unable to read header information";
static const char __pyx_k_unknown_stepper_option_s_in_Iter[] = "unknown stepper option `%s` in IteratorColumn";
static const char __pyx_k_multiple_iterators_not_implement_2[] = "multiple_iterators not implemented for CRAM";
/* #### Code section: decls ### */
static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */
static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_2read_failure_reason(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_code); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_header_dict); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_text, PyObject *__pyx_v_add_sq_text); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, int __pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_key, CYTHON_UNUSED PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_args); /* proto */
static Py_ssize_t __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_add_sam_header, CYTHON_UNUSED PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_index_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_require_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_format_options, PyObject *__pyx_v_threads); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reference, PyObject *__pyx_v_end, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, int __pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_stop, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, int __pyx_v_truncate, int __pyx_v_multiple_iterators, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_query_name); /* proto */
static void __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAll(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IndexedReads(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_SNPCall(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_get = {0, 0, 0, 0, 0};
/* #### Code section: late_includes ### */
/* #### Code section: module_state ### */
typedef struct {
  PyObject *__pyx_d;
  PyObject *__pyx_b;
  PyObject *__pyx_cython_runtime;
  PyObject *__pyx_empty_tuple;
  PyObject *__pyx_empty_bytes;
  PyObject *__pyx_empty_unicode;
  #ifdef __Pyx_CyFunction_USED
  PyTypeObject *__pyx_CyFunctionType;
  #endif
  #ifdef __Pyx_FusedFunction_USED
  PyTypeObject *__pyx_FusedFunctionType;
  #endif
  #ifdef __Pyx_Generator_USED
  PyTypeObject *__pyx_GeneratorType;
  #endif
  #ifdef __Pyx_IterableCoroutine_USED
  PyTypeObject *__pyx_IterableCoroutineType;
  #endif
  #ifdef __Pyx_Coroutine_USED
  PyTypeObject *__pyx_CoroutineAwaitType;
  #endif
  #ifdef __Pyx_Coroutine_USED
  PyTypeObject *__pyx_CoroutineType;
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_7cpython_4type_type;
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_7cpython_4bool_bool;
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_7cpython_7complex_complex;
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_7cpython_5array_array;
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_5pysam_10libchtslib_HTSFile;
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastaFile;
  PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqProxy;
  PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxRecord;
  PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastxFile;
  PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_FastqFile;
  PyTypeObject *__pyx_ptype_5pysam_9libcfaidx_Fastafile;
  #if CYTHON_USE_MODULE_STATE
  #endif
  PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment;
  PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn;
  PyTypeObject *__pyx_ptype_5pysam_18libcalignedsegment_PileupRead;
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  #endif
  #if CYTHON_USE_MODULE_STATE
  PyObject *__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_AlignmentFile;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorRow;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorColumn;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_IndexedReads;
  PyObject *__pyx_type_5pysam_17libcalignmentfile_SNPCall;
  #endif
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads;
  PyTypeObject *__pyx_ptype_5pysam_17libcalignmentfile_SNPCall;
  PyObject *__pyx_n_u_AH;
  PyObject *__pyx_n_u_AN;
  PyObject *__pyx_n_u_AS;
  PyObject *__pyx_kp_u_AlignedSegment_refers_to_referen;
  PyObject *__pyx_n_s_AlignmentFile;
  PyObject *__pyx_n_u_AlignmentFile;
  PyObject *__pyx_n_s_AlignmentFile___enter;
  PyObject *__pyx_n_s_AlignmentFile___exit;
  PyObject *__pyx_n_s_AlignmentFile___reduce_cython;
  PyObject *__pyx_n_s_AlignmentFile___setstate_cython;
  PyObject *__pyx_n_s_AlignmentFile__open;
  PyObject *__pyx_n_s_AlignmentFile_check_index;
  PyObject *__pyx_n_s_AlignmentFile_close;
  PyObject *__pyx_n_s_AlignmentFile_count;
  PyObject *__pyx_n_s_AlignmentFile_count_coverage;
  PyObject *__pyx_n_s_AlignmentFile_fetch;
  PyObject *__pyx_n_s_AlignmentFile_find_introns;
  PyObject *__pyx_n_s_AlignmentFile_find_introns_slow;
  PyObject *__pyx_n_s_AlignmentFile_get_index_statisti;
  PyObject *__pyx_n_s_AlignmentFile_get_reference_leng;
  PyObject *__pyx_n_s_AlignmentFile_get_reference_name;
  PyObject *__pyx_n_s_AlignmentFile_get_tid;
  PyObject *__pyx_n_s_AlignmentFile_getrname;
  PyObject *__pyx_n_s_AlignmentFile_gettid;
  PyObject *__pyx_n_s_AlignmentFile_has_index;
  PyObject *__pyx_n_s_AlignmentFile_head;
  PyObject *__pyx_n_s_AlignmentFile_is_valid_tid;
  PyObject *__pyx_kp_u_AlignmentFile_mapped_only_availa;
  PyObject *__pyx_n_s_AlignmentFile_mate;
  PyObject *__pyx_n_s_AlignmentFile_pileup;
  PyObject *__pyx_n_s_AlignmentFile_write;
  PyObject *__pyx_n_s_AlignmentHeader;
  PyObject *__pyx_n_u_AlignmentHeader;
  PyObject *__pyx_n_s_AlignmentHeader___reduce_cython;
  PyObject *__pyx_n_s_AlignmentHeader___setstate_cytho;
  PyObject *__pyx_n_s_AlignmentHeader__build_sequence;
  PyObject *__pyx_n_s_AlignmentHeader__from_text_and_l;
  PyObject *__pyx_n_s_AlignmentHeader_as_dict;
  PyObject *__pyx_n_s_AlignmentHeader_copy;
  PyObject *__pyx_kp_u_AlignmentHeader_does_not_support;
  PyObject *__pyx_n_s_AlignmentHeader_from_dict;
  PyObject *__pyx_n_s_AlignmentHeader_from_references;
  PyObject *__pyx_n_s_AlignmentHeader_from_text;
  PyObject *__pyx_n_s_AlignmentHeader_get;
  PyObject *__pyx_n_s_AlignmentHeader_get_reference_le;
  PyObject *__pyx_n_s_AlignmentHeader_get_reference_na;
  PyObject *__pyx_n_s_AlignmentHeader_get_tid;
  PyObject *__pyx_n_s_AlignmentHeader_is_valid_tid;
  PyObject *__pyx_n_s_AlignmentHeader_items;
  PyObject *__pyx_n_s_AlignmentHeader_iteritems;
  PyObject *__pyx_n_s_AlignmentHeader_keys;
  PyObject *__pyx_n_s_AlignmentHeader_to_dict;
  PyObject *__pyx_n_s_AlignmentHeader_values;
  PyObject *__pyx_n_s_AssertionError;
  PyObject *__pyx_n_s_AttributeError;
  PyObject *__pyx_n_s_BAM_CREF_SKIP;
  PyObject *__pyx_n_u_BC;
  PyObject *__pyx_n_u_CL;
  PyObject *__pyx_n_u_CN;
  PyObject *__pyx_n_u_CO;
  PyObject *__pyx_kp_u_Cannot_add_extra_threads_when_ig;
  PyObject *__pyx_n_s_Counter;
  PyObject *__pyx_n_u_DS;
  PyObject *__pyx_n_u_DT;
  PyObject *__pyx_n_u_FO;
  PyObject *__pyx_n_u_GO;
  PyObject *__pyx_n_u_HD;
  PyObject *__pyx_n_u_ID;
  PyObject *__pyx_n_s_IOError;
  PyObject *__pyx_kp_u_I_O_operation_on_closed_file;
  PyObject *__pyx_n_s_ImportError;
  PyObject *__pyx_kp_s_Incompatible_checksums_0x_x_vs_0;
  PyObject *__pyx_n_s_IndexStats;
  PyObject *__pyx_n_u_IndexStats;
  PyObject *__pyx_n_s_IndexedReads;
  PyObject *__pyx_n_u_IndexedReads;
  PyObject *__pyx_n_s_IndexedReads___reduce_cython;
  PyObject *__pyx_n_s_IndexedReads___setstate_cython;
  PyObject *__pyx_n_s_IndexedReads_build;
  PyObject *__pyx_n_s_IndexedReads_find;
  PyObject *__pyx_n_s_IteratorColumn;
  PyObject *__pyx_n_u_IteratorColumn;
  PyObject *__pyx_n_s_IteratorColumnAll;
  PyObject *__pyx_n_s_IteratorColumnAllRefs;
  PyObject *__pyx_n_s_IteratorColumnAllRefs___reduce_c;
  PyObject *__pyx_n_s_IteratorColumnAllRefs___setstate;
  PyObject *__pyx_n_s_IteratorColumnAll___reduce_cytho;
  PyObject *__pyx_n_s_IteratorColumnAll___setstate_cyt;
  PyObject *__pyx_n_s_IteratorColumnRegion;
  PyObject *__pyx_n_s_IteratorColumnRegion___reduce_cy;
  PyObject *__pyx_n_s_IteratorColumnRegion___setstate;
  PyObject *__pyx_n_s_IteratorColumn___reduce_cython;
  PyObject *__pyx_n_s_IteratorColumn___setstate_cython;
  PyObject *__pyx_n_s_IteratorColumn_addReference;
  PyObject *__pyx_n_s_IteratorColumn_add_reference;
  PyObject *__pyx_n_s_IteratorColumn_hasReference;
  PyObject *__pyx_n_s_IteratorColumn_has_reference;
  PyObject *__pyx_n_s_IteratorRow;
  PyObject *__pyx_n_u_IteratorRow;
  PyObject *__pyx_n_s_IteratorRowAll;
  PyObject *__pyx_n_s_IteratorRowAllRefs;
  PyObject *__pyx_n_s_IteratorRowAllRefs___reduce_cyth;
  PyObject *__pyx_n_s_IteratorRowAllRefs___setstate_cy;
  PyObject *__pyx_n_s_IteratorRowAllRefs_nextiter;
  PyObject *__pyx_n_s_IteratorRowAll___reduce_cython;
  PyObject *__pyx_n_s_IteratorRowAll___setstate_cython;
  PyObject *__pyx_n_s_IteratorRowHead;
  PyObject *__pyx_n_s_IteratorRowHead___reduce_cython;
  PyObject *__pyx_n_s_IteratorRowHead___setstate_cytho;
  PyObject *__pyx_n_s_IteratorRowRegion;
  PyObject *__pyx_n_s_IteratorRowRegion___reduce_cytho;
  PyObject *__pyx_n_s_IteratorRowRegion___setstate_cyt;
  PyObject *__pyx_n_s_IteratorRowSelection;
  PyObject *__pyx_n_s_IteratorRowSelection___reduce_cy;
  PyObject *__pyx_n_s_IteratorRowSelection___setstate;
  PyObject *__pyx_n_s_IteratorRow___reduce_cython;
  PyObject *__pyx_n_s_IteratorRow___setstate_cython;
  PyObject *__pyx_n_s_KNOWN_HEADER_FIELDS;
  PyObject *__pyx_n_u_KS;
  PyObject *__pyx_n_s_KeyError;
  PyObject *__pyx_n_u_L;
  PyObject *__pyx_n_u_LB;
  PyObject *__pyx_n_u_LN;
  PyObject *__pyx_n_u_M5;
  PyObject *__pyx_n_s_Mapping;
  PyObject *__pyx_n_s_MemoryError;
  PyObject *__pyx_n_u_N;
  PyObject *__pyx_n_s_NotImplementedError;
  PyObject *__pyx_n_s_OSError;
  PyObject *__pyx_n_s_OrderedDict;
  PyObject *__pyx_n_u_PG;
  PyObject *__pyx_n_u_PI;
  PyObject *__pyx_n_u_PL;
  PyObject *__pyx_n_u_PM;
  PyObject *__pyx_n_u_PN;
  PyObject *__pyx_n_u_PP;
  PyObject *__pyx_n_u_PU;
  PyObject *__pyx_n_s_PickleError;
  PyObject *__pyx_n_u_RG;
  PyObject *__pyx_kp_u_Raw_iterator_set_up_without_regi;
  PyObject *__pyx_kp_u_SAM_file_does_not_have_a_valid_h;
  PyObject *__pyx_n_u_SM;
  PyObject *__pyx_n_u_SN;
  PyObject *__pyx_n_s_SNPCall;
  PyObject *__pyx_n_s_SNPCall___reduce_cython;
  PyObject *__pyx_n_s_SNPCall___setstate_cython;
  PyObject *__pyx_n_u_SO;
  PyObject *__pyx_n_u_SP;
  PyObject *__pyx_kp_u_SQ;
  PyObject *__pyx_n_u_SQ_2;
  PyObject *__pyx_kp_u_SQ_SN_LN;
  PyObject *__pyx_n_u_SS;
  PyObject *__pyx_n_s_Sequence;
  PyObject *__pyx_n_s_StopIteration;
  PyObject *__pyx_n_s_StringIO;
  PyObject *__pyx_n_u_TP;
  PyObject *__pyx_n_s_TypeError;
  PyObject *__pyx_n_u_UR;
  PyObject *__pyx_n_s_VALID_HEADERS;
  PyObject *__pyx_n_s_VALID_HEADER_ORDER;
  PyObject *__pyx_n_s_VALID_HEADER_TYPES;
  PyObject *__pyx_n_u_VN;
  PyObject *__pyx_n_s_ValueError;
  PyObject *__pyx_kp_u__12;
  PyObject *__pyx_kp_u__124;
  PyObject *__pyx_n_s__125;
  PyObject *__pyx_kp_u__15;
  PyObject *__pyx_n_s__172;
  PyObject *__pyx_kp_u__19;
  PyObject *__pyx_kp_u__2;
  PyObject *__pyx_kp_u__20;
  PyObject *__pyx_kp_u__21;
  PyObject *__pyx_kp_u__22;
  PyObject *__pyx_kp_u__3;
  PyObject *__pyx_kp_b__46;
  PyObject *__pyx_kp_u_access_from_StringIO_objects_not;
  PyObject *__pyx_n_s_addReference;
  PyObject *__pyx_n_s_add_hts_options;
  PyObject *__pyx_n_s_add_reference;
  PyObject *__pyx_n_s_add_sam_header;
  PyObject *__pyx_n_s_add_sq_text;
  PyObject *__pyx_n_u_adjust_capq_threshold;
  PyObject *__pyx_n_u_all;
  PyObject *__pyx_n_s_all_2;
  PyObject *__pyx_n_s_append;
  PyObject *__pyx_n_s_args;
  PyObject *__pyx_n_s_array;
  PyObject *__pyx_n_s_as_dict;
  PyObject *__pyx_n_s_asyncio_coroutines;
  PyObject *__pyx_n_s_b;
  PyObject *__pyx_n_u_b;
  PyObject *__pyx_n_s_base_position;
  PyObject *__pyx_n_s_beg;
  PyObject *__pyx_n_s_bfile_name;
  PyObject *__pyx_n_s_btext;
  PyObject *__pyx_n_s_build;
  PyObject *__pyx_n_s_build_header_line;
  PyObject *__pyx_n_s_build_sequence_section;
  PyObject *__pyx_n_s_c;
  PyObject *__pyx_n_u_c;
  PyObject *__pyx_kp_u_can_not_iterate_over_samfile_wit;
  PyObject *__pyx_kp_u_can_only_apply_IndexReads_on_bam;
  PyObject *__pyx_kp_u_cannot_create_AlignmentHeader_re;
  PyObject *__pyx_n_s_cfilename;
  PyObject *__pyx_n_s_check_header;
  PyObject *__pyx_n_s_check_index;
  PyObject *__pyx_n_s_check_sq;
  PyObject *__pyx_n_s_check_truncation;
  PyObject *__pyx_n_s_cigar;
  PyObject *__pyx_n_s_cigarstring;
  PyObject *__pyx_n_s_cigartuples;
  PyObject *__pyx_n_s_cindexname;
  PyObject *__pyx_n_s_class_getitem;
  PyObject *__pyx_n_s_cline_in_traceback;
  PyObject *__pyx_n_s_close;
  PyObject *__pyx_n_s_closed;
  PyObject *__pyx_n_s_cls;
  PyObject *__pyx_n_s_cmode;
  PyObject *__pyx_n_s_code;
  PyObject *__pyx_n_s_collections;
  PyObject *__pyx_n_s_collections_abc;
  PyObject *__pyx_n_u_compute_baq;
  PyObject *__pyx_n_s_consensus_quality;
  PyObject *__pyx_n_s_contains;
  PyObject *__pyx_n_s_contig;
  PyObject *__pyx_n_u_contig;
  PyObject *__pyx_n_s_contig_length;
  PyObject *__pyx_n_s_copy;
  PyObject *__pyx_kp_u_could_not_allocate_bytes;
  PyObject *__pyx_kp_u_could_not_allocate_memory_of_siz;
  PyObject *__pyx_kp_u_could_not_create_header;
  PyObject *__pyx_kp_u_could_not_open_alignment_file;
  PyObject *__pyx_kp_u_could_not_open_alignment_file_2;
  PyObject *__pyx_kp_u_could_not_parse_header;
  PyObject *__pyx_n_s_count;
  PyObject *__pyx_n_s_count_a;
  PyObject *__pyx_n_s_count_c;
  PyObject *__pyx_n_s_count_coverage;
  PyObject *__pyx_n_s_count_g;
  PyObject *__pyx_n_s_count_t;
  PyObject *__pyx_n_s_counter;
  PyObject *__pyx_n_s_coverage;
  PyObject *__pyx_n_s_creference_filename;
  PyObject *__pyx_n_s_ctext;
  PyObject *__pyx_n_s_data;
  PyObject *__pyx_n_s_defaultdict;
  PyObject *__pyx_n_s_dict;
  PyObject *__pyx_n_s_dict_2;
  PyObject *__pyx_kp_u_disable;
  PyObject *__pyx_n_s_duplicate_filehandle;
  PyObject *__pyx_kp_u_either_supply_options_template_h;
  PyObject *__pyx_kp_u_enable;
  PyObject *__pyx_n_s_end;
  PyObject *__pyx_n_s_enter;
  PyObject *__pyx_n_s_enumerate;
  PyObject *__pyx_kp_u_error_during_iteration;
  PyObject *__pyx_kp_u_error_while_reading_file;
  PyObject *__pyx_kp_u_error_while_reading_file_2;
  PyObject *__pyx_n_s_exc_type;
  PyObject *__pyx_n_s_exc_value;
  PyObject *__pyx_n_s_exit;
  PyObject *__pyx_kp_u_failure_when_setting_reference_f;
  PyObject *__pyx_n_s_fastafile;
  PyObject *__pyx_n_u_fastafile;
  PyObject *__pyx_n_s_fetch;
  PyObject *__pyx_kp_u_fetch_called_on_bamfile_without;
  PyObject *__pyx_kp_u_fetching_by_region_is_not_availa;
  PyObject *__pyx_n_s_field;
  PyObject *__pyx_n_s_fields;
  PyObject *__pyx_kp_u_file_does_not_contain_alignment;
  PyObject *__pyx_kp_u_file_does_not_have_a_valid_heade;
  PyObject *__pyx_kp_u_file_has_no_sequences_defined_mo;
  PyObject *__pyx_n_s_filename;
  PyObject *__pyx_n_u_filename;
  PyObject *__pyx_n_u_fileno;
  PyObject *__pyx_n_s_filepath_index;
  PyObject *__pyx_n_s_filepath_or_object;
  PyObject *__pyx_n_s_filter_method;
  PyObject *__pyx_n_s_find;
  PyObject *__pyx_n_s_find_introns;
  PyObject *__pyx_n_s_find_introns_slow;
  PyObject *__pyx_n_s_flag;
  PyObject *__pyx_n_u_flag_filter;
  PyObject *__pyx_n_u_flag_require;
  PyObject *__pyx_n_s_format;
  PyObject *__pyx_n_s_format_options;
  PyObject *__pyx_n_s_from_dict;
  PyObject *__pyx_n_s_from_references;
  PyObject *__pyx_n_s_from_text;
  PyObject *__pyx_n_s_from_text_and_lengths;
  PyObject *__pyx_kp_u_gc;
  PyObject *__pyx_n_s_genome_loc;
  PyObject *__pyx_n_s_genotype;
  PyObject *__pyx_n_s_get;
  PyObject *__pyx_n_s_get_aligned_pairs;
  PyObject *__pyx_n_s_get_index_statistics;
  PyObject *__pyx_n_s_get_reference_length;
  PyObject *__pyx_n_s_get_reference_name;
  PyObject *__pyx_n_s_get_tid;
  PyObject *__pyx_n_s_getitem;
  PyObject *__pyx_n_s_getrname;
  PyObject *__pyx_n_s_getstate;
  PyObject *__pyx_n_s_gettid;
  PyObject *__pyx_n_u_h;
  PyObject *__pyx_n_s_hasReference;
  PyObject *__pyx_n_s_has_coord;
  PyObject *__pyx_n_s_has_index;
  PyObject *__pyx_n_s_has_reference;
  PyObject *__pyx_n_s_hdr;
  PyObject *__pyx_n_s_head;
  PyObject *__pyx_n_s_header;
  PyObject *__pyx_n_s_header_dict;
  PyObject *__pyx_kp_u_header_line_with_invalid_type;
  PyObject *__pyx_kp_u_header_line_without_s;
  PyObject *__pyx_kp_u_header_not_available_in_closed_f;
  PyObject *__pyx_n_s_idx;
  PyObject *__pyx_n_u_ignore_orphans;
  PyObject *__pyx_n_u_ignore_overlaps;
  PyObject *__pyx_n_s_ignore_truncation;
  PyObject *__pyx_n_s_import;
  PyObject *__pyx_kp_u_incomplete_sequence_information;
  PyObject *__pyx_n_s_index_filename;
  PyObject *__pyx_n_s_init;
  PyObject *__pyx_n_s_initializing;
  PyObject *__pyx_n_s_int_array_template;
  PyObject *__pyx_kp_u_interval_of_size_0;
  PyObject *__pyx_kp_u_interval_of_size_less_than_0;
  PyObject *__pyx_kp_u_invalid_file_opening_mode_s;
  PyObject *__pyx_kp_u_invalid_type_for_record_s_s_expe;
  PyObject *__pyx_n_s_io;
  PyObject *__pyx_n_s_is_bam;
  PyObject *__pyx_n_s_is_coroutine;
  PyObject *__pyx_n_s_is_cram;
  PyObject *__pyx_n_s_is_open;
  PyObject *__pyx_n_s_is_valid_tid;
  PyObject *__pyx_kp_u_isenabled;
  PyObject *__pyx_n_s_islower;
  PyObject *__pyx_n_s_isupper;
  PyObject *__pyx_n_s_items;
  PyObject *__pyx_n_s_iteritems;
  PyObject *__pyx_n_s_junc_start;
  PyObject *__pyx_n_s_key;
  PyObject *__pyx_n_s_keys;
  PyObject *__pyx_n_s_kwargs;
  PyObject *__pyx_n_s_l_text;
  PyObject *__pyx_n_s_last_read_pos;
  PyObject *__pyx_n_s_len;
  PyObject *__pyx_n_s_length;
  PyObject *__pyx_n_s_lengths;
  PyObject *__pyx_n_s_line;
  PyObject *__pyx_n_s_lines;
  PyObject *__pyx_n_s_main;
  PyObject *__pyx_n_s_make;
  PyObject *__pyx_kp_u_malformatted_header_no_in_field;
  PyObject *__pyx_n_s_map;
  PyObject *__pyx_n_s_mapped;
  PyObject *__pyx_n_u_mapped;
  PyObject *__pyx_kp_u_mapping_information_not_recorded;
  PyObject *__pyx_n_s_mapping_quality;
  PyObject *__pyx_n_s_match_or_deletion;
  PyObject *__pyx_n_s_mate;
  PyObject *__pyx_kp_u_mate_not_found;
  PyObject *__pyx_kp_u_mate_s_is_unmapped;
  PyObject *__pyx_n_u_max_depth;
  PyObject *__pyx_n_u_min_base_quality;
  PyObject *__pyx_n_u_min_mapping_quality;
  PyObject *__pyx_n_s_mode;
  PyObject *__pyx_n_s_multiple_iterators;
  PyObject *__pyx_kp_u_multiple_iterators_not_implement;
  PyObject *__pyx_kp_u_multiple_iterators_not_implement_2;
  PyObject *__pyx_kp_u_multiple_s_lines_are_not_permitt;
  PyObject *__pyx_n_s_n;
  PyObject *__pyx_n_s_name;
  PyObject *__pyx_n_s_name_2;
  PyObject *__pyx_n_s_namedtuple;
  PyObject *__pyx_n_s_new;
  PyObject *__pyx_n_s_nextiter;
  PyObject *__pyx_kp_s_no_default___reduce___due_to_non;
  PyObject *__pyx_kp_u_no_index_available_for_fetch;
  PyObject *__pyx_kp_u_no_index_available_for_iteration;
  PyObject *__pyx_kp_u_no_index_available_for_pileup;
  PyObject *__pyx_n_u_nofilter;
  PyObject *__pyx_kp_u_not_enough_information_to_constr;
  PyObject *__pyx_n_s_nreferences;
  PyObject *__pyx_n_s_nt;
  PyObject *__pyx_kp_u_number_of_reference_names_and_le;
  PyObject *__pyx_n_s_op;
  PyObject *__pyx_n_s_open;
  PyObject *__pyx_n_s_os;
  PyObject *__pyx_n_s_parse_region;
  PyObject *__pyx_n_s_pickle;
  PyObject *__pyx_n_s_pileup;
  PyObject *__pyx_n_s_port;
  PyObject *__pyx_n_s_pos;
  PyObject *__pyx_n_s_positions;
  PyObject *__pyx_n_s_pysam_libcalignmentfile;
  PyObject *__pyx_kp_s_pysam_libcalignmentfile_pyx;
  PyObject *__pyx_n_s_pyx_PickleError;
  PyObject *__pyx_n_s_pyx_checksum;
  PyObject *__pyx_n_s_pyx_result;
  PyObject *__pyx_n_s_pyx_state;
  PyObject *__pyx_n_s_pyx_type;
  PyObject *__pyx_n_s_pyx_unpickle_SNPCall;
  PyObject *__pyx_n_s_pyx_vtable;
  PyObject *__pyx_n_s_qname;
  PyObject *__pyx_n_s_qpos;
  PyObject *__pyx_n_s_quality;
  PyObject *__pyx_n_s_quality_threshold;
  PyObject *__pyx_n_s_query_name;
  PyObject *__pyx_n_s_query_qualities;
  PyObject *__pyx_n_s_r;
  PyObject *__pyx_n_u_r;
  PyObject *__pyx_n_u_rU;
  PyObject *__pyx_n_s_range;
  PyObject *__pyx_n_u_rb;
  PyObject *__pyx_n_u_rc;
  PyObject *__pyx_n_s_re;
  PyObject *__pyx_n_s_read;
  PyObject *__pyx_n_s_read_callback;
  PyObject *__pyx_n_s_read_failure_reason;
  PyObject *__pyx_n_s_read_iterator;
  PyObject *__pyx_n_s_read_loc;
  PyObject *__pyx_kp_u_read_s_is_unpaired;
  PyObject *__pyx_kp_u_read_s_not_found;
  PyObject *__pyx_n_s_record;
  PyObject *__pyx_n_u_redo_baq;
  PyObject *__pyx_n_s_reduce;
  PyObject *__pyx_n_s_reduce_cython;
  PyObject *__pyx_n_s_reduce_ex;
  PyObject *__pyx_n_s_ref;
  PyObject *__pyx_n_s_reference;
  PyObject *__pyx_n_s_reference_base;
  PyObject *__pyx_n_s_reference_filename;
  PyObject *__pyx_kp_u_reference_id_i_out_of_range_0_ti;
  PyObject *__pyx_n_s_reference_lengths;
  PyObject *__pyx_n_s_reference_names;
  PyObject *__pyx_kp_u_reference_sequence_for_tid_not_f;
  PyObject *__pyx_n_s_referencelengths;
  PyObject *__pyx_n_s_referencenames;
  PyObject *__pyx_n_s_references;
  PyObject *__pyx_n_s_refpos;
  PyObject *__pyx_n_s_region;
  PyObject *__pyx_n_s_require_index;
  PyObject *__pyx_n_s_res;
  PyObject *__pyx_n_s_result;
  PyObject *__pyx_n_s_results;
  PyObject *__pyx_n_s_ret;
  PyObject *__pyx_n_s_rstart;
  PyObject *__pyx_n_s_rstop;
  PyObject *__pyx_n_s_rtid;
  PyObject *__pyx_kp_u_s;
  PyObject *__pyx_kp_u_sam_write1_failed_with_error_cod;
  PyObject *__pyx_n_s_samfile;
  PyObject *__pyx_n_u_samtools;
  PyObject *__pyx_n_s_self;
  PyObject *__pyx_kp_s_self_b_self_htsfile_self_index_c;
  PyObject *__pyx_kp_s_self_b_self_htsfile_self_index_s;
  PyObject *__pyx_kp_s_self_htsfile_cannot_be_converted;
  PyObject *__pyx_n_s_seq;
  PyObject *__pyx_n_s_setstate;
  PyObject *__pyx_n_s_setstate_cython;
  PyObject *__pyx_n_s_snp_quality;
  PyObject *__pyx_n_s_spec;
  PyObject *__pyx_n_s_split;
  PyObject *__pyx_n_s_splitlines;
  PyObject *__pyx_n_s_sq;
  PyObject *__pyx_n_s_start;
  PyObject *__pyx_n_s_start_2;
  PyObject *__pyx_n_s_startswith;
  PyObject *__pyx_n_s_state;
  PyObject *__pyx_n_u_stepper;
  PyObject *__pyx_n_s_stop;
  PyObject *__pyx_n_s_stop_2;
  PyObject *__pyx_n_s_str;
  PyObject *__pyx_kp_s_stringsource;
  PyObject *__pyx_n_s_strip;
  PyObject *__pyx_n_s_sum;
  PyObject *__pyx_n_s_super;
  PyObject *__pyx_n_s_t;
  PyObject *__pyx_n_s_tell;
  PyObject *__pyx_n_s_template;
  PyObject *__pyx_n_s_test;
  PyObject *__pyx_n_s_text;
  PyObject *__pyx_n_s_threads;
  PyObject *__pyx_n_s_threshold;
  PyObject *__pyx_n_s_tid;
  PyObject *__pyx_n_s_to_dict;
  PyObject *__pyx_n_u_total;
  PyObject *__pyx_n_s_traceback;
  PyObject *__pyx_n_s_truncate;
  PyObject *__pyx_kp_u_truncated_file;
  PyObject *__pyx_kp_u_unable_to_open_index_file;
  PyObject *__pyx_kp_u_unable_to_open_index_file_s;
  PyObject *__pyx_kp_u_unable_to_read_header_informatio;
  PyObject *__pyx_kp_u_unable_to_reopen_htsfile;
  PyObject *__pyx_kp_u_unknown_reference;
  PyObject *__pyx_kp_u_unknown_stepper_option_s_in_Iter;
  PyObject *__pyx_n_s_unmapped;
  PyObject *__pyx_n_u_unmapped;
  PyObject *__pyx_n_s_until_eof;
  PyObject *__pyx_n_s_update;
  PyObject *__pyx_n_s_use_setstate;
  PyObject *__pyx_n_s_value;
  PyObject *__pyx_n_s_values;
  PyObject *__pyx_n_u_w;
  PyObject *__pyx_n_s_warn;
  PyObject *__pyx_n_s_warnings;
  PyObject *__pyx_n_u_wb;
  PyObject *__pyx_n_u_wb0;
  PyObject *__pyx_n_u_wbu;
  PyObject *__pyx_n_u_wc;
  PyObject *__pyx_n_u_wh;
  PyObject *__pyx_n_s_write;
  PyObject *__pyx_kp_u_wrong_sequence_information_in_s;
  PyObject *__pyx_n_s_x;
  PyObject *__pyx_n_s_y;
  PyObject *__pyx_n_s_zip;
  PyObject *__pyx_int_0;
  PyObject *__pyx_int_1;
  PyObject *__pyx_int_2;
  PyObject *__pyx_int_7;
  PyObject *__pyx_int_8;
  PyObject *__pyx_int_13;
  PyObject *__pyx_int_15;
  PyObject *__pyx_int_1796;
  PyObject *__pyx_int_8000;
  PyObject *__pyx_int_18041500;
  PyObject *__pyx_int_84615809;
  PyObject *__pyx_int_239452417;
  PyObject *__pyx_int_neg_1;
  PyObject *__pyx_int_neg_2;
  int __pyx_k__107;
  PyObject *__pyx_codeobj_;
  PyObject *__pyx_slice__9;
  PyObject *__pyx_tuple__4;
  PyObject *__pyx_tuple__6;
  PyObject *__pyx_tuple__10;
  PyObject *__pyx_tuple__14;
  PyObject *__pyx_tuple__23;
  PyObject *__pyx_tuple__29;
  PyObject *__pyx_tuple__30;
  PyObject *__pyx_tuple__40;
  PyObject *__pyx_tuple__41;
  PyObject *__pyx_tuple__42;
  PyObject *__pyx_tuple__44;
  PyObject *__pyx_tuple__45;
  PyObject *__pyx_tuple__47;
  PyObject *__pyx_tuple__48;
  PyObject *__pyx_tuple__49;
  PyObject *__pyx_tuple__50;
  PyObject *__pyx_tuple__51;
  PyObject *__pyx_tuple__52;
  PyObject *__pyx_tuple__54;
  PyObject *__pyx_tuple__55;
  PyObject *__pyx_tuple__56;
  PyObject *__pyx_tuple__59;
  PyObject *__pyx_tuple__61;
  PyObject *__pyx_tuple__64;
  PyObject *__pyx_tuple__65;
  PyObject *__pyx_tuple__73;
  PyObject *__pyx_tuple__75;
  PyObject *__pyx_tuple__83;
  PyObject *__pyx_tuple__86;
  PyObject *__pyx_tuple__87;
  PyObject *__pyx_tuple__94;
  PyObject *__pyx_codeobj__5;
  PyObject *__pyx_codeobj__7;
  PyObject *__pyx_codeobj__8;
  PyObject *__pyx_tuple__102;
  PyObject *__pyx_tuple__108;
  PyObject *__pyx_tuple__117;
  PyObject *__pyx_tuple__123;
  PyObject *__pyx_tuple__126;
  PyObject *__pyx_tuple__127;
  PyObject *__pyx_tuple__128;
  PyObject *__pyx_tuple__129;
  PyObject *__pyx_tuple__130;
  PyObject *__pyx_tuple__131;
  PyObject *__pyx_tuple__132;
  PyObject *__pyx_tuple__133;
  PyObject *__pyx_tuple__134;
  PyObject *__pyx_tuple__135;
  PyObject *__pyx_tuple__136;
  PyObject *__pyx_tuple__137;
  PyObject *__pyx_tuple__138;
  PyObject *__pyx_tuple__139;
  PyObject *__pyx_tuple__140;
  PyObject *__pyx_tuple__141;
  PyObject *__pyx_tuple__142;
  PyObject *__pyx_tuple__143;
  PyObject *__pyx_tuple__144;
  PyObject *__pyx_tuple__145;
  PyObject *__pyx_tuple__146;
  PyObject *__pyx_tuple__147;
  PyObject *__pyx_tuple__148;
  PyObject *__pyx_tuple__149;
  PyObject *__pyx_tuple__150;
  PyObject *__pyx_tuple__151;
  PyObject *__pyx_tuple__152;
  PyObject *__pyx_tuple__153;
  PyObject *__pyx_tuple__154;
  PyObject *__pyx_tuple__155;
  PyObject *__pyx_tuple__156;
  PyObject *__pyx_tuple__157;
  PyObject *__pyx_tuple__158;
  PyObject *__pyx_tuple__159;
  PyObject *__pyx_tuple__160;
  PyObject *__pyx_tuple__161;
  PyObject *__pyx_tuple__162;
  PyObject *__pyx_tuple__163;
  PyObject *__pyx_tuple__164;
  PyObject *__pyx_tuple__165;
  PyObject *__pyx_tuple__166;
  PyObject *__pyx_tuple__167;
  PyObject *__pyx_tuple__168;
  PyObject *__pyx_tuple__169;
  PyObject *__pyx_tuple__170;
  PyObject *__pyx_tuple__171;
  PyObject *__pyx_codeobj__11;
  PyObject *__pyx_codeobj__13;
  PyObject *__pyx_codeobj__16;
  PyObject *__pyx_codeobj__17;
  PyObject *__pyx_codeobj__18;
  PyObject *__pyx_codeobj__24;
  PyObject *__pyx_codeobj__25;
  PyObject *__pyx_codeobj__26;
  PyObject *__pyx_codeobj__27;
  PyObject *__pyx_codeobj__28;
  PyObject *__pyx_codeobj__31;
  PyObject *__pyx_codeobj__32;
  PyObject *__pyx_codeobj__33;
  PyObject *__pyx_codeobj__34;
  PyObject *__pyx_codeobj__35;
  PyObject *__pyx_codeobj__36;
  PyObject *__pyx_codeobj__37;
  PyObject *__pyx_codeobj__38;
  PyObject *__pyx_codeobj__39;
  PyObject *__pyx_codeobj__43;
  PyObject *__pyx_codeobj__53;
  PyObject *__pyx_codeobj__57;
  PyObject *__pyx_codeobj__58;
  PyObject *__pyx_codeobj__60;
  PyObject *__pyx_codeobj__62;
  PyObject *__pyx_codeobj__63;
  PyObject *__pyx_codeobj__66;
  PyObject *__pyx_codeobj__67;
  PyObject *__pyx_codeobj__68;
  PyObject *__pyx_codeobj__69;
  PyObject *__pyx_codeobj__70;
  PyObject *__pyx_codeobj__71;
  PyObject *__pyx_codeobj__72;
  PyObject *__pyx_codeobj__74;
  PyObject *__pyx_codeobj__76;
  PyObject *__pyx_codeobj__77;
  PyObject *__pyx_codeobj__78;
  PyObject *__pyx_codeobj__79;
  PyObject *__pyx_codeobj__80;
  PyObject *__pyx_codeobj__81;
  PyObject *__pyx_codeobj__82;
  PyObject *__pyx_codeobj__84;
  PyObject *__pyx_codeobj__85;
  PyObject *__pyx_codeobj__88;
  PyObject *__pyx_codeobj__89;
  PyObject *__pyx_codeobj__90;
  PyObject *__pyx_codeobj__91;
  PyObject *__pyx_codeobj__92;
  PyObject *__pyx_codeobj__93;
  PyObject *__pyx_codeobj__95;
  PyObject *__pyx_codeobj__96;
  PyObject *__pyx_codeobj__97;
  PyObject *__pyx_codeobj__98;
  PyObject *__pyx_codeobj__99;
  PyObject *__pyx_codeobj__100;
  PyObject *__pyx_codeobj__101;
  PyObject *__pyx_codeobj__103;
  PyObject *__pyx_codeobj__104;
  PyObject *__pyx_codeobj__105;
  PyObject *__pyx_codeobj__106;
  PyObject *__pyx_codeobj__109;
  PyObject *__pyx_codeobj__110;
  PyObject *__pyx_codeobj__111;
  PyObject *__pyx_codeobj__112;
  PyObject *__pyx_codeobj__113;
  PyObject *__pyx_codeobj__114;
  PyObject *__pyx_codeobj__115;
  PyObject *__pyx_codeobj__116;
  PyObject *__pyx_codeobj__118;
  PyObject *__pyx_codeobj__119;
  PyObject *__pyx_codeobj__120;
  PyObject *__pyx_codeobj__121;
  PyObject *__pyx_codeobj__122;
} __pyx_mstate;

#if CYTHON_USE_MODULE_STATE
#ifdef __cplusplus
namespace {
  extern struct PyModuleDef __pyx_moduledef;
} /* anonymous namespace */
#else
static struct PyModuleDef __pyx_moduledef;
#endif

#define __pyx_mstate(o) ((__pyx_mstate *)__Pyx_PyModule_GetState(o))

#define __pyx_mstate_global (__pyx_mstate(PyState_FindModule(&__pyx_moduledef)))

#define __pyx_m (PyState_FindModule(&__pyx_moduledef))
#else
static __pyx_mstate __pyx_mstate_global_static =
#ifdef __cplusplus
    {};
#else
    {0};
#endif
static __pyx_mstate *__pyx_mstate_global = &__pyx_mstate_global_static;
#endif
/* #### Code section: module_state_clear ### */
#if CYTHON_USE_MODULE_STATE
static int __pyx_m_clear(PyObject *m) {
  __pyx_mstate *clear_module_state = __pyx_mstate(m);
  if (!clear_module_state) return 0;
  Py_CLEAR(clear_module_state->__pyx_d);
  Py_CLEAR(clear_module_state->__pyx_b);
  Py_CLEAR(clear_module_state->__pyx_cython_runtime);
  Py_CLEAR(clear_module_state->__pyx_empty_tuple);
  Py_CLEAR(clear_module_state->__pyx_empty_bytes);
  Py_CLEAR(clear_module_state->__pyx_empty_unicode);
  #ifdef __Pyx_CyFunction_USED
  Py_CLEAR(clear_module_state->__pyx_CyFunctionType);
  #endif
  #ifdef __Pyx_FusedFunction_USED
  Py_CLEAR(clear_module_state->__pyx_FusedFunctionType);
  #endif
  Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_4type_type);
  Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_4bool_bool);
  Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_7complex_complex);
  Py_CLEAR(clear_module_state->__pyx_ptype_7cpython_5array_array);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_10libchtslib_HTSFile);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_9libcfaidx_FastaFile);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_9libcfaidx_FastqProxy);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_9libcfaidx_FastxRecord);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_9libcfaidx_FastxFile);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_9libcfaidx_FastqFile);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_9libcfaidx_Fastafile);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_18libcalignedsegment_PileupRead);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_AlignmentFile);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRow);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumn);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_IndexedReads);
  Py_CLEAR(clear_module_state->__pyx_ptype_5pysam_17libcalignmentfile_SNPCall);
  Py_CLEAR(clear_module_state->__pyx_type_5pysam_17libcalignmentfile_SNPCall);
  Py_CLEAR(clear_module_state->__pyx_n_u_AH);
  Py_CLEAR(clear_module_state->__pyx_n_u_AN);
  Py_CLEAR(clear_module_state->__pyx_n_u_AS);
  Py_CLEAR(clear_module_state->__pyx_kp_u_AlignedSegment_refers_to_referen);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile);
  Py_CLEAR(clear_module_state->__pyx_n_u_AlignmentFile);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile___enter);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile___exit);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile___setstate_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile__open);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_check_index);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_close);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_count);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_count_coverage);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_fetch);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_find_introns);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_find_introns_slow);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_get_index_statisti);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_get_reference_leng);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_get_reference_name);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_get_tid);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_getrname);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_gettid);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_has_index);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_head);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_is_valid_tid);
  Py_CLEAR(clear_module_state->__pyx_kp_u_AlignmentFile_mapped_only_availa);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_mate);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_pileup);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentFile_write);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader);
  Py_CLEAR(clear_module_state->__pyx_n_u_AlignmentHeader);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader___setstate_cytho);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader__build_sequence);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader__from_text_and_l);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_as_dict);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_copy);
  Py_CLEAR(clear_module_state->__pyx_kp_u_AlignmentHeader_does_not_support);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_from_dict);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_from_references);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_from_text);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_get);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_get_reference_le);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_get_reference_na);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_get_tid);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_is_valid_tid);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_items);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_iteritems);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_keys);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_to_dict);
  Py_CLEAR(clear_module_state->__pyx_n_s_AlignmentHeader_values);
  Py_CLEAR(clear_module_state->__pyx_n_s_AssertionError);
  Py_CLEAR(clear_module_state->__pyx_n_s_AttributeError);
  Py_CLEAR(clear_module_state->__pyx_n_s_BAM_CREF_SKIP);
  Py_CLEAR(clear_module_state->__pyx_n_u_BC);
  Py_CLEAR(clear_module_state->__pyx_n_u_CL);
  Py_CLEAR(clear_module_state->__pyx_n_u_CN);
  Py_CLEAR(clear_module_state->__pyx_n_u_CO);
  Py_CLEAR(clear_module_state->__pyx_kp_u_Cannot_add_extra_threads_when_ig);
  Py_CLEAR(clear_module_state->__pyx_n_s_Counter);
  Py_CLEAR(clear_module_state->__pyx_n_u_DS);
  Py_CLEAR(clear_module_state->__pyx_n_u_DT);
  Py_CLEAR(clear_module_state->__pyx_n_u_FO);
  Py_CLEAR(clear_module_state->__pyx_n_u_GO);
  Py_CLEAR(clear_module_state->__pyx_n_u_HD);
  Py_CLEAR(clear_module_state->__pyx_n_u_ID);
  Py_CLEAR(clear_module_state->__pyx_n_s_IOError);
  Py_CLEAR(clear_module_state->__pyx_kp_u_I_O_operation_on_closed_file);
  Py_CLEAR(clear_module_state->__pyx_n_s_ImportError);
  Py_CLEAR(clear_module_state->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0);
  Py_CLEAR(clear_module_state->__pyx_n_s_IndexStats);
  Py_CLEAR(clear_module_state->__pyx_n_u_IndexStats);
  Py_CLEAR(clear_module_state->__pyx_n_s_IndexedReads);
  Py_CLEAR(clear_module_state->__pyx_n_u_IndexedReads);
  Py_CLEAR(clear_module_state->__pyx_n_s_IndexedReads___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IndexedReads___setstate_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IndexedReads_build);
  Py_CLEAR(clear_module_state->__pyx_n_s_IndexedReads_find);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumn);
  Py_CLEAR(clear_module_state->__pyx_n_u_IteratorColumn);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnAll);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnAllRefs);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnAllRefs___reduce_c);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnAllRefs___setstate);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnAll___reduce_cytho);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnAll___setstate_cyt);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnRegion);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnRegion___reduce_cy);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumnRegion___setstate);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumn___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumn___setstate_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumn_addReference);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumn_add_reference);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumn_hasReference);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorColumn_has_reference);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRow);
  Py_CLEAR(clear_module_state->__pyx_n_u_IteratorRow);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowAll);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowAllRefs);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowAllRefs___reduce_cyth);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowAllRefs___setstate_cy);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowAllRefs_nextiter);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowAll___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowAll___setstate_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowHead);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowHead___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowHead___setstate_cytho);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowRegion);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowRegion___reduce_cytho);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowRegion___setstate_cyt);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowSelection);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowSelection___reduce_cy);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRowSelection___setstate);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRow___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_IteratorRow___setstate_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_KNOWN_HEADER_FIELDS);
  Py_CLEAR(clear_module_state->__pyx_n_u_KS);
  Py_CLEAR(clear_module_state->__pyx_n_s_KeyError);
  Py_CLEAR(clear_module_state->__pyx_n_u_L);
  Py_CLEAR(clear_module_state->__pyx_n_u_LB);
  Py_CLEAR(clear_module_state->__pyx_n_u_LN);
  Py_CLEAR(clear_module_state->__pyx_n_u_M5);
  Py_CLEAR(clear_module_state->__pyx_n_s_Mapping);
  Py_CLEAR(clear_module_state->__pyx_n_s_MemoryError);
  Py_CLEAR(clear_module_state->__pyx_n_u_N);
  Py_CLEAR(clear_module_state->__pyx_n_s_NotImplementedError);
  Py_CLEAR(clear_module_state->__pyx_n_s_OSError);
  Py_CLEAR(clear_module_state->__pyx_n_s_OrderedDict);
  Py_CLEAR(clear_module_state->__pyx_n_u_PG);
  Py_CLEAR(clear_module_state->__pyx_n_u_PI);
  Py_CLEAR(clear_module_state->__pyx_n_u_PL);
  Py_CLEAR(clear_module_state->__pyx_n_u_PM);
  Py_CLEAR(clear_module_state->__pyx_n_u_PN);
  Py_CLEAR(clear_module_state->__pyx_n_u_PP);
  Py_CLEAR(clear_module_state->__pyx_n_u_PU);
  Py_CLEAR(clear_module_state->__pyx_n_s_PickleError);
  Py_CLEAR(clear_module_state->__pyx_n_u_RG);
  Py_CLEAR(clear_module_state->__pyx_kp_u_Raw_iterator_set_up_without_regi);
  Py_CLEAR(clear_module_state->__pyx_kp_u_SAM_file_does_not_have_a_valid_h);
  Py_CLEAR(clear_module_state->__pyx_n_u_SM);
  Py_CLEAR(clear_module_state->__pyx_n_u_SN);
  Py_CLEAR(clear_module_state->__pyx_n_s_SNPCall);
  Py_CLEAR(clear_module_state->__pyx_n_s_SNPCall___reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_SNPCall___setstate_cython);
  Py_CLEAR(clear_module_state->__pyx_n_u_SO);
  Py_CLEAR(clear_module_state->__pyx_n_u_SP);
  Py_CLEAR(clear_module_state->__pyx_kp_u_SQ);
  Py_CLEAR(clear_module_state->__pyx_n_u_SQ_2);
  Py_CLEAR(clear_module_state->__pyx_kp_u_SQ_SN_LN);
  Py_CLEAR(clear_module_state->__pyx_n_u_SS);
  Py_CLEAR(clear_module_state->__pyx_n_s_Sequence);
  Py_CLEAR(clear_module_state->__pyx_n_s_StopIteration);
  Py_CLEAR(clear_module_state->__pyx_n_s_StringIO);
  Py_CLEAR(clear_module_state->__pyx_n_u_TP);
  Py_CLEAR(clear_module_state->__pyx_n_s_TypeError);
  Py_CLEAR(clear_module_state->__pyx_n_u_UR);
  Py_CLEAR(clear_module_state->__pyx_n_s_VALID_HEADERS);
  Py_CLEAR(clear_module_state->__pyx_n_s_VALID_HEADER_ORDER);
  Py_CLEAR(clear_module_state->__pyx_n_s_VALID_HEADER_TYPES);
  Py_CLEAR(clear_module_state->__pyx_n_u_VN);
  Py_CLEAR(clear_module_state->__pyx_n_s_ValueError);
  Py_CLEAR(clear_module_state->__pyx_kp_u__12);
  Py_CLEAR(clear_module_state->__pyx_kp_u__124);
  Py_CLEAR(clear_module_state->__pyx_n_s__125);
  Py_CLEAR(clear_module_state->__pyx_kp_u__15);
  Py_CLEAR(clear_module_state->__pyx_n_s__172);
  Py_CLEAR(clear_module_state->__pyx_kp_u__19);
  Py_CLEAR(clear_module_state->__pyx_kp_u__2);
  Py_CLEAR(clear_module_state->__pyx_kp_u__20);
  Py_CLEAR(clear_module_state->__pyx_kp_u__21);
  Py_CLEAR(clear_module_state->__pyx_kp_u__22);
  Py_CLEAR(clear_module_state->__pyx_kp_u__3);
  Py_CLEAR(clear_module_state->__pyx_kp_b__46);
  Py_CLEAR(clear_module_state->__pyx_kp_u_access_from_StringIO_objects_not);
  Py_CLEAR(clear_module_state->__pyx_n_s_addReference);
  Py_CLEAR(clear_module_state->__pyx_n_s_add_hts_options);
  Py_CLEAR(clear_module_state->__pyx_n_s_add_reference);
  Py_CLEAR(clear_module_state->__pyx_n_s_add_sam_header);
  Py_CLEAR(clear_module_state->__pyx_n_s_add_sq_text);
  Py_CLEAR(clear_module_state->__pyx_n_u_adjust_capq_threshold);
  Py_CLEAR(clear_module_state->__pyx_n_u_all);
  Py_CLEAR(clear_module_state->__pyx_n_s_all_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_append);
  Py_CLEAR(clear_module_state->__pyx_n_s_args);
  Py_CLEAR(clear_module_state->__pyx_n_s_array);
  Py_CLEAR(clear_module_state->__pyx_n_s_as_dict);
  Py_CLEAR(clear_module_state->__pyx_n_s_asyncio_coroutines);
  Py_CLEAR(clear_module_state->__pyx_n_s_b);
  Py_CLEAR(clear_module_state->__pyx_n_u_b);
  Py_CLEAR(clear_module_state->__pyx_n_s_base_position);
  Py_CLEAR(clear_module_state->__pyx_n_s_beg);
  Py_CLEAR(clear_module_state->__pyx_n_s_bfile_name);
  Py_CLEAR(clear_module_state->__pyx_n_s_btext);
  Py_CLEAR(clear_module_state->__pyx_n_s_build);
  Py_CLEAR(clear_module_state->__pyx_n_s_build_header_line);
  Py_CLEAR(clear_module_state->__pyx_n_s_build_sequence_section);
  Py_CLEAR(clear_module_state->__pyx_n_s_c);
  Py_CLEAR(clear_module_state->__pyx_n_u_c);
  Py_CLEAR(clear_module_state->__pyx_kp_u_can_not_iterate_over_samfile_wit);
  Py_CLEAR(clear_module_state->__pyx_kp_u_can_only_apply_IndexReads_on_bam);
  Py_CLEAR(clear_module_state->__pyx_kp_u_cannot_create_AlignmentHeader_re);
  Py_CLEAR(clear_module_state->__pyx_n_s_cfilename);
  Py_CLEAR(clear_module_state->__pyx_n_s_check_header);
  Py_CLEAR(clear_module_state->__pyx_n_s_check_index);
  Py_CLEAR(clear_module_state->__pyx_n_s_check_sq);
  Py_CLEAR(clear_module_state->__pyx_n_s_check_truncation);
  Py_CLEAR(clear_module_state->__pyx_n_s_cigar);
  Py_CLEAR(clear_module_state->__pyx_n_s_cigarstring);
  Py_CLEAR(clear_module_state->__pyx_n_s_cigartuples);
  Py_CLEAR(clear_module_state->__pyx_n_s_cindexname);
  Py_CLEAR(clear_module_state->__pyx_n_s_class_getitem);
  Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback);
  Py_CLEAR(clear_module_state->__pyx_n_s_close);
  Py_CLEAR(clear_module_state->__pyx_n_s_closed);
  Py_CLEAR(clear_module_state->__pyx_n_s_cls);
  Py_CLEAR(clear_module_state->__pyx_n_s_cmode);
  Py_CLEAR(clear_module_state->__pyx_n_s_code);
  Py_CLEAR(clear_module_state->__pyx_n_s_collections);
  Py_CLEAR(clear_module_state->__pyx_n_s_collections_abc);
  Py_CLEAR(clear_module_state->__pyx_n_u_compute_baq);
  Py_CLEAR(clear_module_state->__pyx_n_s_consensus_quality);
  Py_CLEAR(clear_module_state->__pyx_n_s_contains);
  Py_CLEAR(clear_module_state->__pyx_n_s_contig);
  Py_CLEAR(clear_module_state->__pyx_n_u_contig);
  Py_CLEAR(clear_module_state->__pyx_n_s_contig_length);
  Py_CLEAR(clear_module_state->__pyx_n_s_copy);
  Py_CLEAR(clear_module_state->__pyx_kp_u_could_not_allocate_bytes);
  Py_CLEAR(clear_module_state->__pyx_kp_u_could_not_allocate_memory_of_siz);
  Py_CLEAR(clear_module_state->__pyx_kp_u_could_not_create_header);
  Py_CLEAR(clear_module_state->__pyx_kp_u_could_not_open_alignment_file);
  Py_CLEAR(clear_module_state->__pyx_kp_u_could_not_open_alignment_file_2);
  Py_CLEAR(clear_module_state->__pyx_kp_u_could_not_parse_header);
  Py_CLEAR(clear_module_state->__pyx_n_s_count);
  Py_CLEAR(clear_module_state->__pyx_n_s_count_a);
  Py_CLEAR(clear_module_state->__pyx_n_s_count_c);
  Py_CLEAR(clear_module_state->__pyx_n_s_count_coverage);
  Py_CLEAR(clear_module_state->__pyx_n_s_count_g);
  Py_CLEAR(clear_module_state->__pyx_n_s_count_t);
  Py_CLEAR(clear_module_state->__pyx_n_s_counter);
  Py_CLEAR(clear_module_state->__pyx_n_s_coverage);
  Py_CLEAR(clear_module_state->__pyx_n_s_creference_filename);
  Py_CLEAR(clear_module_state->__pyx_n_s_ctext);
  Py_CLEAR(clear_module_state->__pyx_n_s_data);
  Py_CLEAR(clear_module_state->__pyx_n_s_defaultdict);
  Py_CLEAR(clear_module_state->__pyx_n_s_dict);
  Py_CLEAR(clear_module_state->__pyx_n_s_dict_2);
  Py_CLEAR(clear_module_state->__pyx_kp_u_disable);
  Py_CLEAR(clear_module_state->__pyx_n_s_duplicate_filehandle);
  Py_CLEAR(clear_module_state->__pyx_kp_u_either_supply_options_template_h);
  Py_CLEAR(clear_module_state->__pyx_kp_u_enable);
  Py_CLEAR(clear_module_state->__pyx_n_s_end);
  Py_CLEAR(clear_module_state->__pyx_n_s_enter);
  Py_CLEAR(clear_module_state->__pyx_n_s_enumerate);
  Py_CLEAR(clear_module_state->__pyx_kp_u_error_during_iteration);
  Py_CLEAR(clear_module_state->__pyx_kp_u_error_while_reading_file);
  Py_CLEAR(clear_module_state->__pyx_kp_u_error_while_reading_file_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_exc_type);
  Py_CLEAR(clear_module_state->__pyx_n_s_exc_value);
  Py_CLEAR(clear_module_state->__pyx_n_s_exit);
  Py_CLEAR(clear_module_state->__pyx_kp_u_failure_when_setting_reference_f);
  Py_CLEAR(clear_module_state->__pyx_n_s_fastafile);
  Py_CLEAR(clear_module_state->__pyx_n_u_fastafile);
  Py_CLEAR(clear_module_state->__pyx_n_s_fetch);
  Py_CLEAR(clear_module_state->__pyx_kp_u_fetch_called_on_bamfile_without);
  Py_CLEAR(clear_module_state->__pyx_kp_u_fetching_by_region_is_not_availa);
  Py_CLEAR(clear_module_state->__pyx_n_s_field);
  Py_CLEAR(clear_module_state->__pyx_n_s_fields);
  Py_CLEAR(clear_module_state->__pyx_kp_u_file_does_not_contain_alignment);
  Py_CLEAR(clear_module_state->__pyx_kp_u_file_does_not_have_a_valid_heade);
  Py_CLEAR(clear_module_state->__pyx_kp_u_file_has_no_sequences_defined_mo);
  Py_CLEAR(clear_module_state->__pyx_n_s_filename);
  Py_CLEAR(clear_module_state->__pyx_n_u_filename);
  Py_CLEAR(clear_module_state->__pyx_n_u_fileno);
  Py_CLEAR(clear_module_state->__pyx_n_s_filepath_index);
  Py_CLEAR(clear_module_state->__pyx_n_s_filepath_or_object);
  Py_CLEAR(clear_module_state->__pyx_n_s_filter_method);
  Py_CLEAR(clear_module_state->__pyx_n_s_find);
  Py_CLEAR(clear_module_state->__pyx_n_s_find_introns);
  Py_CLEAR(clear_module_state->__pyx_n_s_find_introns_slow);
  Py_CLEAR(clear_module_state->__pyx_n_s_flag);
  Py_CLEAR(clear_module_state->__pyx_n_u_flag_filter);
  Py_CLEAR(clear_module_state->__pyx_n_u_flag_require);
  Py_CLEAR(clear_module_state->__pyx_n_s_format);
  Py_CLEAR(clear_module_state->__pyx_n_s_format_options);
  Py_CLEAR(clear_module_state->__pyx_n_s_from_dict);
  Py_CLEAR(clear_module_state->__pyx_n_s_from_references);
  Py_CLEAR(clear_module_state->__pyx_n_s_from_text);
  Py_CLEAR(clear_module_state->__pyx_n_s_from_text_and_lengths);
  Py_CLEAR(clear_module_state->__pyx_kp_u_gc);
  Py_CLEAR(clear_module_state->__pyx_n_s_genome_loc);
  Py_CLEAR(clear_module_state->__pyx_n_s_genotype);
  Py_CLEAR(clear_module_state->__pyx_n_s_get);
  Py_CLEAR(clear_module_state->__pyx_n_s_get_aligned_pairs);
  Py_CLEAR(clear_module_state->__pyx_n_s_get_index_statistics);
  Py_CLEAR(clear_module_state->__pyx_n_s_get_reference_length);
  Py_CLEAR(clear_module_state->__pyx_n_s_get_reference_name);
  Py_CLEAR(clear_module_state->__pyx_n_s_get_tid);
  Py_CLEAR(clear_module_state->__pyx_n_s_getitem);
  Py_CLEAR(clear_module_state->__pyx_n_s_getrname);
  Py_CLEAR(clear_module_state->__pyx_n_s_getstate);
  Py_CLEAR(clear_module_state->__pyx_n_s_gettid);
  Py_CLEAR(clear_module_state->__pyx_n_u_h);
  Py_CLEAR(clear_module_state->__pyx_n_s_hasReference);
  Py_CLEAR(clear_module_state->__pyx_n_s_has_coord);
  Py_CLEAR(clear_module_state->__pyx_n_s_has_index);
  Py_CLEAR(clear_module_state->__pyx_n_s_has_reference);
  Py_CLEAR(clear_module_state->__pyx_n_s_hdr);
  Py_CLEAR(clear_module_state->__pyx_n_s_head);
  Py_CLEAR(clear_module_state->__pyx_n_s_header);
  Py_CLEAR(clear_module_state->__pyx_n_s_header_dict);
  Py_CLEAR(clear_module_state->__pyx_kp_u_header_line_with_invalid_type);
  Py_CLEAR(clear_module_state->__pyx_kp_u_header_line_without_s);
  Py_CLEAR(clear_module_state->__pyx_kp_u_header_not_available_in_closed_f);
  Py_CLEAR(clear_module_state->__pyx_n_s_idx);
  Py_CLEAR(clear_module_state->__pyx_n_u_ignore_orphans);
  Py_CLEAR(clear_module_state->__pyx_n_u_ignore_overlaps);
  Py_CLEAR(clear_module_state->__pyx_n_s_ignore_truncation);
  Py_CLEAR(clear_module_state->__pyx_n_s_import);
  Py_CLEAR(clear_module_state->__pyx_kp_u_incomplete_sequence_information);
  Py_CLEAR(clear_module_state->__pyx_n_s_index_filename);
  Py_CLEAR(clear_module_state->__pyx_n_s_init);
  Py_CLEAR(clear_module_state->__pyx_n_s_initializing);
  Py_CLEAR(clear_module_state->__pyx_n_s_int_array_template);
  Py_CLEAR(clear_module_state->__pyx_kp_u_interval_of_size_0);
  Py_CLEAR(clear_module_state->__pyx_kp_u_interval_of_size_less_than_0);
  Py_CLEAR(clear_module_state->__pyx_kp_u_invalid_file_opening_mode_s);
  Py_CLEAR(clear_module_state->__pyx_kp_u_invalid_type_for_record_s_s_expe);
  Py_CLEAR(clear_module_state->__pyx_n_s_io);
  Py_CLEAR(clear_module_state->__pyx_n_s_is_bam);
  Py_CLEAR(clear_module_state->__pyx_n_s_is_coroutine);
  Py_CLEAR(clear_module_state->__pyx_n_s_is_cram);
  Py_CLEAR(clear_module_state->__pyx_n_s_is_open);
  Py_CLEAR(clear_module_state->__pyx_n_s_is_valid_tid);
  Py_CLEAR(clear_module_state->__pyx_kp_u_isenabled);
  Py_CLEAR(clear_module_state->__pyx_n_s_islower);
  Py_CLEAR(clear_module_state->__pyx_n_s_isupper);
  Py_CLEAR(clear_module_state->__pyx_n_s_items);
  Py_CLEAR(clear_module_state->__pyx_n_s_iteritems);
  Py_CLEAR(clear_module_state->__pyx_n_s_junc_start);
  Py_CLEAR(clear_module_state->__pyx_n_s_key);
  Py_CLEAR(clear_module_state->__pyx_n_s_keys);
  Py_CLEAR(clear_module_state->__pyx_n_s_kwargs);
  Py_CLEAR(clear_module_state->__pyx_n_s_l_text);
  Py_CLEAR(clear_module_state->__pyx_n_s_last_read_pos);
  Py_CLEAR(clear_module_state->__pyx_n_s_len);
  Py_CLEAR(clear_module_state->__pyx_n_s_length);
  Py_CLEAR(clear_module_state->__pyx_n_s_lengths);
  Py_CLEAR(clear_module_state->__pyx_n_s_line);
  Py_CLEAR(clear_module_state->__pyx_n_s_lines);
  Py_CLEAR(clear_module_state->__pyx_n_s_main);
  Py_CLEAR(clear_module_state->__pyx_n_s_make);
  Py_CLEAR(clear_module_state->__pyx_kp_u_malformatted_header_no_in_field);
  Py_CLEAR(clear_module_state->__pyx_n_s_map);
  Py_CLEAR(clear_module_state->__pyx_n_s_mapped);
  Py_CLEAR(clear_module_state->__pyx_n_u_mapped);
  Py_CLEAR(clear_module_state->__pyx_kp_u_mapping_information_not_recorded);
  Py_CLEAR(clear_module_state->__pyx_n_s_mapping_quality);
  Py_CLEAR(clear_module_state->__pyx_n_s_match_or_deletion);
  Py_CLEAR(clear_module_state->__pyx_n_s_mate);
  Py_CLEAR(clear_module_state->__pyx_kp_u_mate_not_found);
  Py_CLEAR(clear_module_state->__pyx_kp_u_mate_s_is_unmapped);
  Py_CLEAR(clear_module_state->__pyx_n_u_max_depth);
  Py_CLEAR(clear_module_state->__pyx_n_u_min_base_quality);
  Py_CLEAR(clear_module_state->__pyx_n_u_min_mapping_quality);
  Py_CLEAR(clear_module_state->__pyx_n_s_mode);
  Py_CLEAR(clear_module_state->__pyx_n_s_multiple_iterators);
  Py_CLEAR(clear_module_state->__pyx_kp_u_multiple_iterators_not_implement);
  Py_CLEAR(clear_module_state->__pyx_kp_u_multiple_iterators_not_implement_2);
  Py_CLEAR(clear_module_state->__pyx_kp_u_multiple_s_lines_are_not_permitt);
  Py_CLEAR(clear_module_state->__pyx_n_s_n);
  Py_CLEAR(clear_module_state->__pyx_n_s_name);
  Py_CLEAR(clear_module_state->__pyx_n_s_name_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_namedtuple);
  Py_CLEAR(clear_module_state->__pyx_n_s_new);
  Py_CLEAR(clear_module_state->__pyx_n_s_nextiter);
  Py_CLEAR(clear_module_state->__pyx_kp_s_no_default___reduce___due_to_non);
  Py_CLEAR(clear_module_state->__pyx_kp_u_no_index_available_for_fetch);
  Py_CLEAR(clear_module_state->__pyx_kp_u_no_index_available_for_iteration);
  Py_CLEAR(clear_module_state->__pyx_kp_u_no_index_available_for_pileup);
  Py_CLEAR(clear_module_state->__pyx_n_u_nofilter);
  Py_CLEAR(clear_module_state->__pyx_kp_u_not_enough_information_to_constr);
  Py_CLEAR(clear_module_state->__pyx_n_s_nreferences);
  Py_CLEAR(clear_module_state->__pyx_n_s_nt);
  Py_CLEAR(clear_module_state->__pyx_kp_u_number_of_reference_names_and_le);
  Py_CLEAR(clear_module_state->__pyx_n_s_op);
  Py_CLEAR(clear_module_state->__pyx_n_s_open);
  Py_CLEAR(clear_module_state->__pyx_n_s_os);
  Py_CLEAR(clear_module_state->__pyx_n_s_parse_region);
  Py_CLEAR(clear_module_state->__pyx_n_s_pickle);
  Py_CLEAR(clear_module_state->__pyx_n_s_pileup);
  Py_CLEAR(clear_module_state->__pyx_n_s_port);
  Py_CLEAR(clear_module_state->__pyx_n_s_pos);
  Py_CLEAR(clear_module_state->__pyx_n_s_positions);
  Py_CLEAR(clear_module_state->__pyx_n_s_pysam_libcalignmentfile);
  Py_CLEAR(clear_module_state->__pyx_kp_s_pysam_libcalignmentfile_pyx);
  Py_CLEAR(clear_module_state->__pyx_n_s_pyx_PickleError);
  Py_CLEAR(clear_module_state->__pyx_n_s_pyx_checksum);
  Py_CLEAR(clear_module_state->__pyx_n_s_pyx_result);
  Py_CLEAR(clear_module_state->__pyx_n_s_pyx_state);
  Py_CLEAR(clear_module_state->__pyx_n_s_pyx_type);
  Py_CLEAR(clear_module_state->__pyx_n_s_pyx_unpickle_SNPCall);
  Py_CLEAR(clear_module_state->__pyx_n_s_pyx_vtable);
  Py_CLEAR(clear_module_state->__pyx_n_s_qname);
  Py_CLEAR(clear_module_state->__pyx_n_s_qpos);
  Py_CLEAR(clear_module_state->__pyx_n_s_quality);
  Py_CLEAR(clear_module_state->__pyx_n_s_quality_threshold);
  Py_CLEAR(clear_module_state->__pyx_n_s_query_name);
  Py_CLEAR(clear_module_state->__pyx_n_s_query_qualities);
  Py_CLEAR(clear_module_state->__pyx_n_s_r);
  Py_CLEAR(clear_module_state->__pyx_n_u_r);
  Py_CLEAR(clear_module_state->__pyx_n_u_rU);
  Py_CLEAR(clear_module_state->__pyx_n_s_range);
  Py_CLEAR(clear_module_state->__pyx_n_u_rb);
  Py_CLEAR(clear_module_state->__pyx_n_u_rc);
  Py_CLEAR(clear_module_state->__pyx_n_s_re);
  Py_CLEAR(clear_module_state->__pyx_n_s_read);
  Py_CLEAR(clear_module_state->__pyx_n_s_read_callback);
  Py_CLEAR(clear_module_state->__pyx_n_s_read_failure_reason);
  Py_CLEAR(clear_module_state->__pyx_n_s_read_iterator);
  Py_CLEAR(clear_module_state->__pyx_n_s_read_loc);
  Py_CLEAR(clear_module_state->__pyx_kp_u_read_s_is_unpaired);
  Py_CLEAR(clear_module_state->__pyx_kp_u_read_s_not_found);
  Py_CLEAR(clear_module_state->__pyx_n_s_record);
  Py_CLEAR(clear_module_state->__pyx_n_u_redo_baq);
  Py_CLEAR(clear_module_state->__pyx_n_s_reduce);
  Py_CLEAR(clear_module_state->__pyx_n_s_reduce_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_reduce_ex);
  Py_CLEAR(clear_module_state->__pyx_n_s_ref);
  Py_CLEAR(clear_module_state->__pyx_n_s_reference);
  Py_CLEAR(clear_module_state->__pyx_n_s_reference_base);
  Py_CLEAR(clear_module_state->__pyx_n_s_reference_filename);
  Py_CLEAR(clear_module_state->__pyx_kp_u_reference_id_i_out_of_range_0_ti);
  Py_CLEAR(clear_module_state->__pyx_n_s_reference_lengths);
  Py_CLEAR(clear_module_state->__pyx_n_s_reference_names);
  Py_CLEAR(clear_module_state->__pyx_kp_u_reference_sequence_for_tid_not_f);
  Py_CLEAR(clear_module_state->__pyx_n_s_referencelengths);
  Py_CLEAR(clear_module_state->__pyx_n_s_referencenames);
  Py_CLEAR(clear_module_state->__pyx_n_s_references);
  Py_CLEAR(clear_module_state->__pyx_n_s_refpos);
  Py_CLEAR(clear_module_state->__pyx_n_s_region);
  Py_CLEAR(clear_module_state->__pyx_n_s_require_index);
  Py_CLEAR(clear_module_state->__pyx_n_s_res);
  Py_CLEAR(clear_module_state->__pyx_n_s_result);
  Py_CLEAR(clear_module_state->__pyx_n_s_results);
  Py_CLEAR(clear_module_state->__pyx_n_s_ret);
  Py_CLEAR(clear_module_state->__pyx_n_s_rstart);
  Py_CLEAR(clear_module_state->__pyx_n_s_rstop);
  Py_CLEAR(clear_module_state->__pyx_n_s_rtid);
  Py_CLEAR(clear_module_state->__pyx_kp_u_s);
  Py_CLEAR(clear_module_state->__pyx_kp_u_sam_write1_failed_with_error_cod);
  Py_CLEAR(clear_module_state->__pyx_n_s_samfile);
  Py_CLEAR(clear_module_state->__pyx_n_u_samtools);
  Py_CLEAR(clear_module_state->__pyx_n_s_self);
  Py_CLEAR(clear_module_state->__pyx_kp_s_self_b_self_htsfile_self_index_c);
  Py_CLEAR(clear_module_state->__pyx_kp_s_self_b_self_htsfile_self_index_s);
  Py_CLEAR(clear_module_state->__pyx_kp_s_self_htsfile_cannot_be_converted);
  Py_CLEAR(clear_module_state->__pyx_n_s_seq);
  Py_CLEAR(clear_module_state->__pyx_n_s_setstate);
  Py_CLEAR(clear_module_state->__pyx_n_s_setstate_cython);
  Py_CLEAR(clear_module_state->__pyx_n_s_snp_quality);
  Py_CLEAR(clear_module_state->__pyx_n_s_spec);
  Py_CLEAR(clear_module_state->__pyx_n_s_split);
  Py_CLEAR(clear_module_state->__pyx_n_s_splitlines);
  Py_CLEAR(clear_module_state->__pyx_n_s_sq);
  Py_CLEAR(clear_module_state->__pyx_n_s_start);
  Py_CLEAR(clear_module_state->__pyx_n_s_start_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_startswith);
  Py_CLEAR(clear_module_state->__pyx_n_s_state);
  Py_CLEAR(clear_module_state->__pyx_n_u_stepper);
  Py_CLEAR(clear_module_state->__pyx_n_s_stop);
  Py_CLEAR(clear_module_state->__pyx_n_s_stop_2);
  Py_CLEAR(clear_module_state->__pyx_n_s_str);
  Py_CLEAR(clear_module_state->__pyx_kp_s_stringsource);
  Py_CLEAR(clear_module_state->__pyx_n_s_strip);
  Py_CLEAR(clear_module_state->__pyx_n_s_sum);
  Py_CLEAR(clear_module_state->__pyx_n_s_super);
  Py_CLEAR(clear_module_state->__pyx_n_s_t);
  Py_CLEAR(clear_module_state->__pyx_n_s_tell);
  Py_CLEAR(clear_module_state->__pyx_n_s_template);
  Py_CLEAR(clear_module_state->__pyx_n_s_test);
  Py_CLEAR(clear_module_state->__pyx_n_s_text);
  Py_CLEAR(clear_module_state->__pyx_n_s_threads);
  Py_CLEAR(clear_module_state->__pyx_n_s_threshold);
  Py_CLEAR(clear_module_state->__pyx_n_s_tid);
  Py_CLEAR(clear_module_state->__pyx_n_s_to_dict);
  Py_CLEAR(clear_module_state->__pyx_n_u_total);
  Py_CLEAR(clear_module_state->__pyx_n_s_traceback);
  Py_CLEAR(clear_module_state->__pyx_n_s_truncate);
  Py_CLEAR(clear_module_state->__pyx_kp_u_truncated_file);
  Py_CLEAR(clear_module_state->__pyx_kp_u_unable_to_open_index_file);
  Py_CLEAR(clear_module_state->__pyx_kp_u_unable_to_open_index_file_s);
  Py_CLEAR(clear_module_state->__pyx_kp_u_unable_to_read_header_informatio);
  Py_CLEAR(clear_module_state->__pyx_kp_u_unable_to_reopen_htsfile);
  Py_CLEAR(clear_module_state->__pyx_kp_u_unknown_reference);
  Py_CLEAR(clear_module_state->__pyx_kp_u_unknown_stepper_option_s_in_Iter);
  Py_CLEAR(clear_module_state->__pyx_n_s_unmapped);
  Py_CLEAR(clear_module_state->__pyx_n_u_unmapped);
  Py_CLEAR(clear_module_state->__pyx_n_s_until_eof);
  Py_CLEAR(clear_module_state->__pyx_n_s_update);
  Py_CLEAR(clear_module_state->__pyx_n_s_use_setstate);
  Py_CLEAR(clear_module_state->__pyx_n_s_value);
  Py_CLEAR(clear_module_state->__pyx_n_s_values);
  Py_CLEAR(clear_module_state->__pyx_n_u_w);
  Py_CLEAR(clear_module_state->__pyx_n_s_warn);
  Py_CLEAR(clear_module_state->__pyx_n_s_warnings);
  Py_CLEAR(clear_module_state->__pyx_n_u_wb);
  Py_CLEAR(clear_module_state->__pyx_n_u_wb0);
  Py_CLEAR(clear_module_state->__pyx_n_u_wbu);
  Py_CLEAR(clear_module_state->__pyx_n_u_wc);
  Py_CLEAR(clear_module_state->__pyx_n_u_wh);
  Py_CLEAR(clear_module_state->__pyx_n_s_write);
  Py_CLEAR(clear_module_state->__pyx_kp_u_wrong_sequence_information_in_s);
  Py_CLEAR(clear_module_state->__pyx_n_s_x);
  Py_CLEAR(clear_module_state->__pyx_n_s_y);
  Py_CLEAR(clear_module_state->__pyx_n_s_zip);
  Py_CLEAR(clear_module_state->__pyx_int_0);
  Py_CLEAR(clear_module_state->__pyx_int_1);
  Py_CLEAR(clear_module_state->__pyx_int_2);
  Py_CLEAR(clear_module_state->__pyx_int_7);
  Py_CLEAR(clear_module_state->__pyx_int_8);
  Py_CLEAR(clear_module_state->__pyx_int_13);
  Py_CLEAR(clear_module_state->__pyx_int_15);
  Py_CLEAR(clear_module_state->__pyx_int_1796);
  Py_CLEAR(clear_module_state->__pyx_int_8000);
  Py_CLEAR(clear_module_state->__pyx_int_18041500);
  Py_CLEAR(clear_module_state->__pyx_int_84615809);
  Py_CLEAR(clear_module_state->__pyx_int_239452417);
  Py_CLEAR(clear_module_state->__pyx_int_neg_1);
  Py_CLEAR(clear_module_state->__pyx_int_neg_2);
  Py_CLEAR(clear_module_state->__pyx_codeobj_);
  Py_CLEAR(clear_module_state->__pyx_slice__9);
  Py_CLEAR(clear_module_state->__pyx_tuple__4);
  Py_CLEAR(clear_module_state->__pyx_tuple__6);
  Py_CLEAR(clear_module_state->__pyx_tuple__10);
  Py_CLEAR(clear_module_state->__pyx_tuple__14);
  Py_CLEAR(clear_module_state->__pyx_tuple__23);
  Py_CLEAR(clear_module_state->__pyx_tuple__29);
  Py_CLEAR(clear_module_state->__pyx_tuple__30);
  Py_CLEAR(clear_module_state->__pyx_tuple__40);
  Py_CLEAR(clear_module_state->__pyx_tuple__41);
  Py_CLEAR(clear_module_state->__pyx_tuple__42);
  Py_CLEAR(clear_module_state->__pyx_tuple__44);
  Py_CLEAR(clear_module_state->__pyx_tuple__45);
  Py_CLEAR(clear_module_state->__pyx_tuple__47);
  Py_CLEAR(clear_module_state->__pyx_tuple__48);
  Py_CLEAR(clear_module_state->__pyx_tuple__49);
  Py_CLEAR(clear_module_state->__pyx_tuple__50);
  Py_CLEAR(clear_module_state->__pyx_tuple__51);
  Py_CLEAR(clear_module_state->__pyx_tuple__52);
  Py_CLEAR(clear_module_state->__pyx_tuple__54);
  Py_CLEAR(clear_module_state->__pyx_tuple__55);
  Py_CLEAR(clear_module_state->__pyx_tuple__56);
  Py_CLEAR(clear_module_state->__pyx_tuple__59);
  Py_CLEAR(clear_module_state->__pyx_tuple__61);
  Py_CLEAR(clear_module_state->__pyx_tuple__64);
  Py_CLEAR(clear_module_state->__pyx_tuple__65);
  Py_CLEAR(clear_module_state->__pyx_tuple__73);
  Py_CLEAR(clear_module_state->__pyx_tuple__75);
  Py_CLEAR(clear_module_state->__pyx_tuple__83);
  Py_CLEAR(clear_module_state->__pyx_tuple__86);
  Py_CLEAR(clear_module_state->__pyx_tuple__87);
  Py_CLEAR(clear_module_state->__pyx_tuple__94);
  Py_CLEAR(clear_module_state->__pyx_codeobj__5);
  Py_CLEAR(clear_module_state->__pyx_codeobj__7);
  Py_CLEAR(clear_module_state->__pyx_codeobj__8);
  Py_CLEAR(clear_module_state->__pyx_tuple__102);
  Py_CLEAR(clear_module_state->__pyx_tuple__108);
  Py_CLEAR(clear_module_state->__pyx_tuple__117);
  Py_CLEAR(clear_module_state->__pyx_tuple__123);
  Py_CLEAR(clear_module_state->__pyx_tuple__126);
  Py_CLEAR(clear_module_state->__pyx_tuple__127);
  Py_CLEAR(clear_module_state->__pyx_tuple__128);
  Py_CLEAR(clear_module_state->__pyx_tuple__129);
  Py_CLEAR(clear_module_state->__pyx_tuple__130);
  Py_CLEAR(clear_module_state->__pyx_tuple__131);
  Py_CLEAR(clear_module_state->__pyx_tuple__132);
  Py_CLEAR(clear_module_state->__pyx_tuple__133);
  Py_CLEAR(clear_module_state->__pyx_tuple__134);
  Py_CLEAR(clear_module_state->__pyx_tuple__135);
  Py_CLEAR(clear_module_state->__pyx_tuple__136);
  Py_CLEAR(clear_module_state->__pyx_tuple__137);
  Py_CLEAR(clear_module_state->__pyx_tuple__138);
  Py_CLEAR(clear_module_state->__pyx_tuple__139);
  Py_CLEAR(clear_module_state->__pyx_tuple__140);
  Py_CLEAR(clear_module_state->__pyx_tuple__141);
  Py_CLEAR(clear_module_state->__pyx_tuple__142);
  Py_CLEAR(clear_module_state->__pyx_tuple__143);
  Py_CLEAR(clear_module_state->__pyx_tuple__144);
  Py_CLEAR(clear_module_state->__pyx_tuple__145);
  Py_CLEAR(clear_module_state->__pyx_tuple__146);
  Py_CLEAR(clear_module_state->__pyx_tuple__147);
  Py_CLEAR(clear_module_state->__pyx_tuple__148);
  Py_CLEAR(clear_module_state->__pyx_tuple__149);
  Py_CLEAR(clear_module_state->__pyx_tuple__150);
  Py_CLEAR(clear_module_state->__pyx_tuple__151);
  Py_CLEAR(clear_module_state->__pyx_tuple__152);
  Py_CLEAR(clear_module_state->__pyx_tuple__153);
  Py_CLEAR(clear_module_state->__pyx_tuple__154);
  Py_CLEAR(clear_module_state->__pyx_tuple__155);
  Py_CLEAR(clear_module_state->__pyx_tuple__156);
  Py_CLEAR(clear_module_state->__pyx_tuple__157);
  Py_CLEAR(clear_module_state->__pyx_tuple__158);
  Py_CLEAR(clear_module_state->__pyx_tuple__159);
  Py_CLEAR(clear_module_state->__pyx_tuple__160);
  Py_CLEAR(clear_module_state->__pyx_tuple__161);
  Py_CLEAR(clear_module_state->__pyx_tuple__162);
  Py_CLEAR(clear_module_state->__pyx_tuple__163);
  Py_CLEAR(clear_module_state->__pyx_tuple__164);
  Py_CLEAR(clear_module_state->__pyx_tuple__165);
  Py_CLEAR(clear_module_state->__pyx_tuple__166);
  Py_CLEAR(clear_module_state->__pyx_tuple__167);
  Py_CLEAR(clear_module_state->__pyx_tuple__168);
  Py_CLEAR(clear_module_state->__pyx_tuple__169);
  Py_CLEAR(clear_module_state->__pyx_tuple__170);
  Py_CLEAR(clear_module_state->__pyx_tuple__171);
  Py_CLEAR(clear_module_state->__pyx_codeobj__11);
  Py_CLEAR(clear_module_state->__pyx_codeobj__13);
  Py_CLEAR(clear_module_state->__pyx_codeobj__16);
  Py_CLEAR(clear_module_state->__pyx_codeobj__17);
  Py_CLEAR(clear_module_state->__pyx_codeobj__18);
  Py_CLEAR(clear_module_state->__pyx_codeobj__24);
  Py_CLEAR(clear_module_state->__pyx_codeobj__25);
  Py_CLEAR(clear_module_state->__pyx_codeobj__26);
  Py_CLEAR(clear_module_state->__pyx_codeobj__27);
  Py_CLEAR(clear_module_state->__pyx_codeobj__28);
  Py_CLEAR(clear_module_state->__pyx_codeobj__31);
  Py_CLEAR(clear_module_state->__pyx_codeobj__32);
  Py_CLEAR(clear_module_state->__pyx_codeobj__33);
  Py_CLEAR(clear_module_state->__pyx_codeobj__34);
  Py_CLEAR(clear_module_state->__pyx_codeobj__35);
  Py_CLEAR(clear_module_state->__pyx_codeobj__36);
  Py_CLEAR(clear_module_state->__pyx_codeobj__37);
  Py_CLEAR(clear_module_state->__pyx_codeobj__38);
  Py_CLEAR(clear_module_state->__pyx_codeobj__39);
  Py_CLEAR(clear_module_state->__pyx_codeobj__43);
  Py_CLEAR(clear_module_state->__pyx_codeobj__53);
  Py_CLEAR(clear_module_state->__pyx_codeobj__57);
  Py_CLEAR(clear_module_state->__pyx_codeobj__58);
  Py_CLEAR(clear_module_state->__pyx_codeobj__60);
  Py_CLEAR(clear_module_state->__pyx_codeobj__62);
  Py_CLEAR(clear_module_state->__pyx_codeobj__63);
  Py_CLEAR(clear_module_state->__pyx_codeobj__66);
  Py_CLEAR(clear_module_state->__pyx_codeobj__67);
  Py_CLEAR(clear_module_state->__pyx_codeobj__68);
  Py_CLEAR(clear_module_state->__pyx_codeobj__69);
  Py_CLEAR(clear_module_state->__pyx_codeobj__70);
  Py_CLEAR(clear_module_state->__pyx_codeobj__71);
  Py_CLEAR(clear_module_state->__pyx_codeobj__72);
  Py_CLEAR(clear_module_state->__pyx_codeobj__74);
  Py_CLEAR(clear_module_state->__pyx_codeobj__76);
  Py_CLEAR(clear_module_state->__pyx_codeobj__77);
  Py_CLEAR(clear_module_state->__pyx_codeobj__78);
  Py_CLEAR(clear_module_state->__pyx_codeobj__79);
  Py_CLEAR(clear_module_state->__pyx_codeobj__80);
  Py_CLEAR(clear_module_state->__pyx_codeobj__81);
  Py_CLEAR(clear_module_state->__pyx_codeobj__82);
  Py_CLEAR(clear_module_state->__pyx_codeobj__84);
  Py_CLEAR(clear_module_state->__pyx_codeobj__85);
  Py_CLEAR(clear_module_state->__pyx_codeobj__88);
  Py_CLEAR(clear_module_state->__pyx_codeobj__89);
  Py_CLEAR(clear_module_state->__pyx_codeobj__90);
  Py_CLEAR(clear_module_state->__pyx_codeobj__91);
  Py_CLEAR(clear_module_state->__pyx_codeobj__92);
  Py_CLEAR(clear_module_state->__pyx_codeobj__93);
  Py_CLEAR(clear_module_state->__pyx_codeobj__95);
  Py_CLEAR(clear_module_state->__pyx_codeobj__96);
  Py_CLEAR(clear_module_state->__pyx_codeobj__97);
  Py_CLEAR(clear_module_state->__pyx_codeobj__98);
  Py_CLEAR(clear_module_state->__pyx_codeobj__99);
  Py_CLEAR(clear_module_state->__pyx_codeobj__100);
  Py_CLEAR(clear_module_state->__pyx_codeobj__101);
  Py_CLEAR(clear_module_state->__pyx_codeobj__103);
  Py_CLEAR(clear_module_state->__pyx_codeobj__104);
  Py_CLEAR(clear_module_state->__pyx_codeobj__105);
  Py_CLEAR(clear_module_state->__pyx_codeobj__106);
  Py_CLEAR(clear_module_state->__pyx_codeobj__109);
  Py_CLEAR(clear_module_state->__pyx_codeobj__110);
  Py_CLEAR(clear_module_state->__pyx_codeobj__111);
  Py_CLEAR(clear_module_state->__pyx_codeobj__112);
  Py_CLEAR(clear_module_state->__pyx_codeobj__113);
  Py_CLEAR(clear_module_state->__pyx_codeobj__114);
  Py_CLEAR(clear_module_state->__pyx_codeobj__115);
  Py_CLEAR(clear_module_state->__pyx_codeobj__116);
  Py_CLEAR(clear_module_state->__pyx_codeobj__118);
  Py_CLEAR(clear_module_state->__pyx_codeobj__119);
  Py_CLEAR(clear_module_state->__pyx_codeobj__120);
  Py_CLEAR(clear_module_state->__pyx_codeobj__121);
  Py_CLEAR(clear_module_state->__pyx_codeobj__122);
  return 0;
}
#endif
/* #### Code section: module_state_traverse ### */
#if CYTHON_USE_MODULE_STATE
static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) {
  __pyx_mstate *traverse_module_state = __pyx_mstate(m);
  if (!traverse_module_state) return 0;
  Py_VISIT(traverse_module_state->__pyx_d);
  Py_VISIT(traverse_module_state->__pyx_b);
  Py_VISIT(traverse_module_state->__pyx_cython_runtime);
  Py_VISIT(traverse_module_state->__pyx_empty_tuple);
  Py_VISIT(traverse_module_state->__pyx_empty_bytes);
  Py_VISIT(traverse_module_state->__pyx_empty_unicode);
  #ifdef __Pyx_CyFunction_USED
  Py_VISIT(traverse_module_state->__pyx_CyFunctionType);
  #endif
  #ifdef __Pyx_FusedFunction_USED
  Py_VISIT(traverse_module_state->__pyx_FusedFunctionType);
  #endif
  Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_4type_type);
  Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_4bool_bool);
  Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_7complex_complex);
  Py_VISIT(traverse_module_state->__pyx_ptype_7cpython_5array_array);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_10libchtslib_HTSFile);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_9libcfaidx_FastaFile);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_9libcfaidx_FastqProxy);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_9libcfaidx_FastxRecord);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_9libcfaidx_FastxFile);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_9libcfaidx_FastqFile);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_9libcfaidx_Fastafile);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_18libcalignedsegment_PileupRead);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_AlignmentFile);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRow);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumn);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_IndexedReads);
  Py_VISIT(traverse_module_state->__pyx_ptype_5pysam_17libcalignmentfile_SNPCall);
  Py_VISIT(traverse_module_state->__pyx_type_5pysam_17libcalignmentfile_SNPCall);
  Py_VISIT(traverse_module_state->__pyx_n_u_AH);
  Py_VISIT(traverse_module_state->__pyx_n_u_AN);
  Py_VISIT(traverse_module_state->__pyx_n_u_AS);
  Py_VISIT(traverse_module_state->__pyx_kp_u_AlignedSegment_refers_to_referen);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile);
  Py_VISIT(traverse_module_state->__pyx_n_u_AlignmentFile);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile___enter);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile___exit);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile___setstate_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile__open);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_check_index);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_close);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_count);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_count_coverage);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_fetch);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_find_introns);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_find_introns_slow);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_get_index_statisti);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_get_reference_leng);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_get_reference_name);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_get_tid);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_getrname);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_gettid);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_has_index);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_head);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_is_valid_tid);
  Py_VISIT(traverse_module_state->__pyx_kp_u_AlignmentFile_mapped_only_availa);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_mate);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_pileup);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentFile_write);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader);
  Py_VISIT(traverse_module_state->__pyx_n_u_AlignmentHeader);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader___setstate_cytho);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader__build_sequence);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader__from_text_and_l);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_as_dict);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_copy);
  Py_VISIT(traverse_module_state->__pyx_kp_u_AlignmentHeader_does_not_support);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_from_dict);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_from_references);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_from_text);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_get);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_get_reference_le);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_get_reference_na);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_get_tid);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_is_valid_tid);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_items);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_iteritems);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_keys);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_to_dict);
  Py_VISIT(traverse_module_state->__pyx_n_s_AlignmentHeader_values);
  Py_VISIT(traverse_module_state->__pyx_n_s_AssertionError);
  Py_VISIT(traverse_module_state->__pyx_n_s_AttributeError);
  Py_VISIT(traverse_module_state->__pyx_n_s_BAM_CREF_SKIP);
  Py_VISIT(traverse_module_state->__pyx_n_u_BC);
  Py_VISIT(traverse_module_state->__pyx_n_u_CL);
  Py_VISIT(traverse_module_state->__pyx_n_u_CN);
  Py_VISIT(traverse_module_state->__pyx_n_u_CO);
  Py_VISIT(traverse_module_state->__pyx_kp_u_Cannot_add_extra_threads_when_ig);
  Py_VISIT(traverse_module_state->__pyx_n_s_Counter);
  Py_VISIT(traverse_module_state->__pyx_n_u_DS);
  Py_VISIT(traverse_module_state->__pyx_n_u_DT);
  Py_VISIT(traverse_module_state->__pyx_n_u_FO);
  Py_VISIT(traverse_module_state->__pyx_n_u_GO);
  Py_VISIT(traverse_module_state->__pyx_n_u_HD);
  Py_VISIT(traverse_module_state->__pyx_n_u_ID);
  Py_VISIT(traverse_module_state->__pyx_n_s_IOError);
  Py_VISIT(traverse_module_state->__pyx_kp_u_I_O_operation_on_closed_file);
  Py_VISIT(traverse_module_state->__pyx_n_s_ImportError);
  Py_VISIT(traverse_module_state->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0);
  Py_VISIT(traverse_module_state->__pyx_n_s_IndexStats);
  Py_VISIT(traverse_module_state->__pyx_n_u_IndexStats);
  Py_VISIT(traverse_module_state->__pyx_n_s_IndexedReads);
  Py_VISIT(traverse_module_state->__pyx_n_u_IndexedReads);
  Py_VISIT(traverse_module_state->__pyx_n_s_IndexedReads___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IndexedReads___setstate_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IndexedReads_build);
  Py_VISIT(traverse_module_state->__pyx_n_s_IndexedReads_find);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumn);
  Py_VISIT(traverse_module_state->__pyx_n_u_IteratorColumn);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnAll);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnAllRefs);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnAllRefs___reduce_c);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnAllRefs___setstate);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnAll___reduce_cytho);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnAll___setstate_cyt);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnRegion);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnRegion___reduce_cy);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumnRegion___setstate);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumn___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumn___setstate_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumn_addReference);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumn_add_reference);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumn_hasReference);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorColumn_has_reference);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRow);
  Py_VISIT(traverse_module_state->__pyx_n_u_IteratorRow);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowAll);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowAllRefs);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowAllRefs___reduce_cyth);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowAllRefs___setstate_cy);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowAllRefs_nextiter);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowAll___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowAll___setstate_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowHead);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowHead___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowHead___setstate_cytho);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowRegion);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowRegion___reduce_cytho);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowRegion___setstate_cyt);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowSelection);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowSelection___reduce_cy);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRowSelection___setstate);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRow___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_IteratorRow___setstate_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_KNOWN_HEADER_FIELDS);
  Py_VISIT(traverse_module_state->__pyx_n_u_KS);
  Py_VISIT(traverse_module_state->__pyx_n_s_KeyError);
  Py_VISIT(traverse_module_state->__pyx_n_u_L);
  Py_VISIT(traverse_module_state->__pyx_n_u_LB);
  Py_VISIT(traverse_module_state->__pyx_n_u_LN);
  Py_VISIT(traverse_module_state->__pyx_n_u_M5);
  Py_VISIT(traverse_module_state->__pyx_n_s_Mapping);
  Py_VISIT(traverse_module_state->__pyx_n_s_MemoryError);
  Py_VISIT(traverse_module_state->__pyx_n_u_N);
  Py_VISIT(traverse_module_state->__pyx_n_s_NotImplementedError);
  Py_VISIT(traverse_module_state->__pyx_n_s_OSError);
  Py_VISIT(traverse_module_state->__pyx_n_s_OrderedDict);
  Py_VISIT(traverse_module_state->__pyx_n_u_PG);
  Py_VISIT(traverse_module_state->__pyx_n_u_PI);
  Py_VISIT(traverse_module_state->__pyx_n_u_PL);
  Py_VISIT(traverse_module_state->__pyx_n_u_PM);
  Py_VISIT(traverse_module_state->__pyx_n_u_PN);
  Py_VISIT(traverse_module_state->__pyx_n_u_PP);
  Py_VISIT(traverse_module_state->__pyx_n_u_PU);
  Py_VISIT(traverse_module_state->__pyx_n_s_PickleError);
  Py_VISIT(traverse_module_state->__pyx_n_u_RG);
  Py_VISIT(traverse_module_state->__pyx_kp_u_Raw_iterator_set_up_without_regi);
  Py_VISIT(traverse_module_state->__pyx_kp_u_SAM_file_does_not_have_a_valid_h);
  Py_VISIT(traverse_module_state->__pyx_n_u_SM);
  Py_VISIT(traverse_module_state->__pyx_n_u_SN);
  Py_VISIT(traverse_module_state->__pyx_n_s_SNPCall);
  Py_VISIT(traverse_module_state->__pyx_n_s_SNPCall___reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_SNPCall___setstate_cython);
  Py_VISIT(traverse_module_state->__pyx_n_u_SO);
  Py_VISIT(traverse_module_state->__pyx_n_u_SP);
  Py_VISIT(traverse_module_state->__pyx_kp_u_SQ);
  Py_VISIT(traverse_module_state->__pyx_n_u_SQ_2);
  Py_VISIT(traverse_module_state->__pyx_kp_u_SQ_SN_LN);
  Py_VISIT(traverse_module_state->__pyx_n_u_SS);
  Py_VISIT(traverse_module_state->__pyx_n_s_Sequence);
  Py_VISIT(traverse_module_state->__pyx_n_s_StopIteration);
  Py_VISIT(traverse_module_state->__pyx_n_s_StringIO);
  Py_VISIT(traverse_module_state->__pyx_n_u_TP);
  Py_VISIT(traverse_module_state->__pyx_n_s_TypeError);
  Py_VISIT(traverse_module_state->__pyx_n_u_UR);
  Py_VISIT(traverse_module_state->__pyx_n_s_VALID_HEADERS);
  Py_VISIT(traverse_module_state->__pyx_n_s_VALID_HEADER_ORDER);
  Py_VISIT(traverse_module_state->__pyx_n_s_VALID_HEADER_TYPES);
  Py_VISIT(traverse_module_state->__pyx_n_u_VN);
  Py_VISIT(traverse_module_state->__pyx_n_s_ValueError);
  Py_VISIT(traverse_module_state->__pyx_kp_u__12);
  Py_VISIT(traverse_module_state->__pyx_kp_u__124);
  Py_VISIT(traverse_module_state->__pyx_n_s__125);
  Py_VISIT(traverse_module_state->__pyx_kp_u__15);
  Py_VISIT(traverse_module_state->__pyx_n_s__172);
  Py_VISIT(traverse_module_state->__pyx_kp_u__19);
  Py_VISIT(traverse_module_state->__pyx_kp_u__2);
  Py_VISIT(traverse_module_state->__pyx_kp_u__20);
  Py_VISIT(traverse_module_state->__pyx_kp_u__21);
  Py_VISIT(traverse_module_state->__pyx_kp_u__22);
  Py_VISIT(traverse_module_state->__pyx_kp_u__3);
  Py_VISIT(traverse_module_state->__pyx_kp_b__46);
  Py_VISIT(traverse_module_state->__pyx_kp_u_access_from_StringIO_objects_not);
  Py_VISIT(traverse_module_state->__pyx_n_s_addReference);
  Py_VISIT(traverse_module_state->__pyx_n_s_add_hts_options);
  Py_VISIT(traverse_module_state->__pyx_n_s_add_reference);
  Py_VISIT(traverse_module_state->__pyx_n_s_add_sam_header);
  Py_VISIT(traverse_module_state->__pyx_n_s_add_sq_text);
  Py_VISIT(traverse_module_state->__pyx_n_u_adjust_capq_threshold);
  Py_VISIT(traverse_module_state->__pyx_n_u_all);
  Py_VISIT(traverse_module_state->__pyx_n_s_all_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_append);
  Py_VISIT(traverse_module_state->__pyx_n_s_args);
  Py_VISIT(traverse_module_state->__pyx_n_s_array);
  Py_VISIT(traverse_module_state->__pyx_n_s_as_dict);
  Py_VISIT(traverse_module_state->__pyx_n_s_asyncio_coroutines);
  Py_VISIT(traverse_module_state->__pyx_n_s_b);
  Py_VISIT(traverse_module_state->__pyx_n_u_b);
  Py_VISIT(traverse_module_state->__pyx_n_s_base_position);
  Py_VISIT(traverse_module_state->__pyx_n_s_beg);
  Py_VISIT(traverse_module_state->__pyx_n_s_bfile_name);
  Py_VISIT(traverse_module_state->__pyx_n_s_btext);
  Py_VISIT(traverse_module_state->__pyx_n_s_build);
  Py_VISIT(traverse_module_state->__pyx_n_s_build_header_line);
  Py_VISIT(traverse_module_state->__pyx_n_s_build_sequence_section);
  Py_VISIT(traverse_module_state->__pyx_n_s_c);
  Py_VISIT(traverse_module_state->__pyx_n_u_c);
  Py_VISIT(traverse_module_state->__pyx_kp_u_can_not_iterate_over_samfile_wit);
  Py_VISIT(traverse_module_state->__pyx_kp_u_can_only_apply_IndexReads_on_bam);
  Py_VISIT(traverse_module_state->__pyx_kp_u_cannot_create_AlignmentHeader_re);
  Py_VISIT(traverse_module_state->__pyx_n_s_cfilename);
  Py_VISIT(traverse_module_state->__pyx_n_s_check_header);
  Py_VISIT(traverse_module_state->__pyx_n_s_check_index);
  Py_VISIT(traverse_module_state->__pyx_n_s_check_sq);
  Py_VISIT(traverse_module_state->__pyx_n_s_check_truncation);
  Py_VISIT(traverse_module_state->__pyx_n_s_cigar);
  Py_VISIT(traverse_module_state->__pyx_n_s_cigarstring);
  Py_VISIT(traverse_module_state->__pyx_n_s_cigartuples);
  Py_VISIT(traverse_module_state->__pyx_n_s_cindexname);
  Py_VISIT(traverse_module_state->__pyx_n_s_class_getitem);
  Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback);
  Py_VISIT(traverse_module_state->__pyx_n_s_close);
  Py_VISIT(traverse_module_state->__pyx_n_s_closed);
  Py_VISIT(traverse_module_state->__pyx_n_s_cls);
  Py_VISIT(traverse_module_state->__pyx_n_s_cmode);
  Py_VISIT(traverse_module_state->__pyx_n_s_code);
  Py_VISIT(traverse_module_state->__pyx_n_s_collections);
  Py_VISIT(traverse_module_state->__pyx_n_s_collections_abc);
  Py_VISIT(traverse_module_state->__pyx_n_u_compute_baq);
  Py_VISIT(traverse_module_state->__pyx_n_s_consensus_quality);
  Py_VISIT(traverse_module_state->__pyx_n_s_contains);
  Py_VISIT(traverse_module_state->__pyx_n_s_contig);
  Py_VISIT(traverse_module_state->__pyx_n_u_contig);
  Py_VISIT(traverse_module_state->__pyx_n_s_contig_length);
  Py_VISIT(traverse_module_state->__pyx_n_s_copy);
  Py_VISIT(traverse_module_state->__pyx_kp_u_could_not_allocate_bytes);
  Py_VISIT(traverse_module_state->__pyx_kp_u_could_not_allocate_memory_of_siz);
  Py_VISIT(traverse_module_state->__pyx_kp_u_could_not_create_header);
  Py_VISIT(traverse_module_state->__pyx_kp_u_could_not_open_alignment_file);
  Py_VISIT(traverse_module_state->__pyx_kp_u_could_not_open_alignment_file_2);
  Py_VISIT(traverse_module_state->__pyx_kp_u_could_not_parse_header);
  Py_VISIT(traverse_module_state->__pyx_n_s_count);
  Py_VISIT(traverse_module_state->__pyx_n_s_count_a);
  Py_VISIT(traverse_module_state->__pyx_n_s_count_c);
  Py_VISIT(traverse_module_state->__pyx_n_s_count_coverage);
  Py_VISIT(traverse_module_state->__pyx_n_s_count_g);
  Py_VISIT(traverse_module_state->__pyx_n_s_count_t);
  Py_VISIT(traverse_module_state->__pyx_n_s_counter);
  Py_VISIT(traverse_module_state->__pyx_n_s_coverage);
  Py_VISIT(traverse_module_state->__pyx_n_s_creference_filename);
  Py_VISIT(traverse_module_state->__pyx_n_s_ctext);
  Py_VISIT(traverse_module_state->__pyx_n_s_data);
  Py_VISIT(traverse_module_state->__pyx_n_s_defaultdict);
  Py_VISIT(traverse_module_state->__pyx_n_s_dict);
  Py_VISIT(traverse_module_state->__pyx_n_s_dict_2);
  Py_VISIT(traverse_module_state->__pyx_kp_u_disable);
  Py_VISIT(traverse_module_state->__pyx_n_s_duplicate_filehandle);
  Py_VISIT(traverse_module_state->__pyx_kp_u_either_supply_options_template_h);
  Py_VISIT(traverse_module_state->__pyx_kp_u_enable);
  Py_VISIT(traverse_module_state->__pyx_n_s_end);
  Py_VISIT(traverse_module_state->__pyx_n_s_enter);
  Py_VISIT(traverse_module_state->__pyx_n_s_enumerate);
  Py_VISIT(traverse_module_state->__pyx_kp_u_error_during_iteration);
  Py_VISIT(traverse_module_state->__pyx_kp_u_error_while_reading_file);
  Py_VISIT(traverse_module_state->__pyx_kp_u_error_while_reading_file_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_exc_type);
  Py_VISIT(traverse_module_state->__pyx_n_s_exc_value);
  Py_VISIT(traverse_module_state->__pyx_n_s_exit);
  Py_VISIT(traverse_module_state->__pyx_kp_u_failure_when_setting_reference_f);
  Py_VISIT(traverse_module_state->__pyx_n_s_fastafile);
  Py_VISIT(traverse_module_state->__pyx_n_u_fastafile);
  Py_VISIT(traverse_module_state->__pyx_n_s_fetch);
  Py_VISIT(traverse_module_state->__pyx_kp_u_fetch_called_on_bamfile_without);
  Py_VISIT(traverse_module_state->__pyx_kp_u_fetching_by_region_is_not_availa);
  Py_VISIT(traverse_module_state->__pyx_n_s_field);
  Py_VISIT(traverse_module_state->__pyx_n_s_fields);
  Py_VISIT(traverse_module_state->__pyx_kp_u_file_does_not_contain_alignment);
  Py_VISIT(traverse_module_state->__pyx_kp_u_file_does_not_have_a_valid_heade);
  Py_VISIT(traverse_module_state->__pyx_kp_u_file_has_no_sequences_defined_mo);
  Py_VISIT(traverse_module_state->__pyx_n_s_filename);
  Py_VISIT(traverse_module_state->__pyx_n_u_filename);
  Py_VISIT(traverse_module_state->__pyx_n_u_fileno);
  Py_VISIT(traverse_module_state->__pyx_n_s_filepath_index);
  Py_VISIT(traverse_module_state->__pyx_n_s_filepath_or_object);
  Py_VISIT(traverse_module_state->__pyx_n_s_filter_method);
  Py_VISIT(traverse_module_state->__pyx_n_s_find);
  Py_VISIT(traverse_module_state->__pyx_n_s_find_introns);
  Py_VISIT(traverse_module_state->__pyx_n_s_find_introns_slow);
  Py_VISIT(traverse_module_state->__pyx_n_s_flag);
  Py_VISIT(traverse_module_state->__pyx_n_u_flag_filter);
  Py_VISIT(traverse_module_state->__pyx_n_u_flag_require);
  Py_VISIT(traverse_module_state->__pyx_n_s_format);
  Py_VISIT(traverse_module_state->__pyx_n_s_format_options);
  Py_VISIT(traverse_module_state->__pyx_n_s_from_dict);
  Py_VISIT(traverse_module_state->__pyx_n_s_from_references);
  Py_VISIT(traverse_module_state->__pyx_n_s_from_text);
  Py_VISIT(traverse_module_state->__pyx_n_s_from_text_and_lengths);
  Py_VISIT(traverse_module_state->__pyx_kp_u_gc);
  Py_VISIT(traverse_module_state->__pyx_n_s_genome_loc);
  Py_VISIT(traverse_module_state->__pyx_n_s_genotype);
  Py_VISIT(traverse_module_state->__pyx_n_s_get);
  Py_VISIT(traverse_module_state->__pyx_n_s_get_aligned_pairs);
  Py_VISIT(traverse_module_state->__pyx_n_s_get_index_statistics);
  Py_VISIT(traverse_module_state->__pyx_n_s_get_reference_length);
  Py_VISIT(traverse_module_state->__pyx_n_s_get_reference_name);
  Py_VISIT(traverse_module_state->__pyx_n_s_get_tid);
  Py_VISIT(traverse_module_state->__pyx_n_s_getitem);
  Py_VISIT(traverse_module_state->__pyx_n_s_getrname);
  Py_VISIT(traverse_module_state->__pyx_n_s_getstate);
  Py_VISIT(traverse_module_state->__pyx_n_s_gettid);
  Py_VISIT(traverse_module_state->__pyx_n_u_h);
  Py_VISIT(traverse_module_state->__pyx_n_s_hasReference);
  Py_VISIT(traverse_module_state->__pyx_n_s_has_coord);
  Py_VISIT(traverse_module_state->__pyx_n_s_has_index);
  Py_VISIT(traverse_module_state->__pyx_n_s_has_reference);
  Py_VISIT(traverse_module_state->__pyx_n_s_hdr);
  Py_VISIT(traverse_module_state->__pyx_n_s_head);
  Py_VISIT(traverse_module_state->__pyx_n_s_header);
  Py_VISIT(traverse_module_state->__pyx_n_s_header_dict);
  Py_VISIT(traverse_module_state->__pyx_kp_u_header_line_with_invalid_type);
  Py_VISIT(traverse_module_state->__pyx_kp_u_header_line_without_s);
  Py_VISIT(traverse_module_state->__pyx_kp_u_header_not_available_in_closed_f);
  Py_VISIT(traverse_module_state->__pyx_n_s_idx);
  Py_VISIT(traverse_module_state->__pyx_n_u_ignore_orphans);
  Py_VISIT(traverse_module_state->__pyx_n_u_ignore_overlaps);
  Py_VISIT(traverse_module_state->__pyx_n_s_ignore_truncation);
  Py_VISIT(traverse_module_state->__pyx_n_s_import);
  Py_VISIT(traverse_module_state->__pyx_kp_u_incomplete_sequence_information);
  Py_VISIT(traverse_module_state->__pyx_n_s_index_filename);
  Py_VISIT(traverse_module_state->__pyx_n_s_init);
  Py_VISIT(traverse_module_state->__pyx_n_s_initializing);
  Py_VISIT(traverse_module_state->__pyx_n_s_int_array_template);
  Py_VISIT(traverse_module_state->__pyx_kp_u_interval_of_size_0);
  Py_VISIT(traverse_module_state->__pyx_kp_u_interval_of_size_less_than_0);
  Py_VISIT(traverse_module_state->__pyx_kp_u_invalid_file_opening_mode_s);
  Py_VISIT(traverse_module_state->__pyx_kp_u_invalid_type_for_record_s_s_expe);
  Py_VISIT(traverse_module_state->__pyx_n_s_io);
  Py_VISIT(traverse_module_state->__pyx_n_s_is_bam);
  Py_VISIT(traverse_module_state->__pyx_n_s_is_coroutine);
  Py_VISIT(traverse_module_state->__pyx_n_s_is_cram);
  Py_VISIT(traverse_module_state->__pyx_n_s_is_open);
  Py_VISIT(traverse_module_state->__pyx_n_s_is_valid_tid);
  Py_VISIT(traverse_module_state->__pyx_kp_u_isenabled);
  Py_VISIT(traverse_module_state->__pyx_n_s_islower);
  Py_VISIT(traverse_module_state->__pyx_n_s_isupper);
  Py_VISIT(traverse_module_state->__pyx_n_s_items);
  Py_VISIT(traverse_module_state->__pyx_n_s_iteritems);
  Py_VISIT(traverse_module_state->__pyx_n_s_junc_start);
  Py_VISIT(traverse_module_state->__pyx_n_s_key);
  Py_VISIT(traverse_module_state->__pyx_n_s_keys);
  Py_VISIT(traverse_module_state->__pyx_n_s_kwargs);
  Py_VISIT(traverse_module_state->__pyx_n_s_l_text);
  Py_VISIT(traverse_module_state->__pyx_n_s_last_read_pos);
  Py_VISIT(traverse_module_state->__pyx_n_s_len);
  Py_VISIT(traverse_module_state->__pyx_n_s_length);
  Py_VISIT(traverse_module_state->__pyx_n_s_lengths);
  Py_VISIT(traverse_module_state->__pyx_n_s_line);
  Py_VISIT(traverse_module_state->__pyx_n_s_lines);
  Py_VISIT(traverse_module_state->__pyx_n_s_main);
  Py_VISIT(traverse_module_state->__pyx_n_s_make);
  Py_VISIT(traverse_module_state->__pyx_kp_u_malformatted_header_no_in_field);
  Py_VISIT(traverse_module_state->__pyx_n_s_map);
  Py_VISIT(traverse_module_state->__pyx_n_s_mapped);
  Py_VISIT(traverse_module_state->__pyx_n_u_mapped);
  Py_VISIT(traverse_module_state->__pyx_kp_u_mapping_information_not_recorded);
  Py_VISIT(traverse_module_state->__pyx_n_s_mapping_quality);
  Py_VISIT(traverse_module_state->__pyx_n_s_match_or_deletion);
  Py_VISIT(traverse_module_state->__pyx_n_s_mate);
  Py_VISIT(traverse_module_state->__pyx_kp_u_mate_not_found);
  Py_VISIT(traverse_module_state->__pyx_kp_u_mate_s_is_unmapped);
  Py_VISIT(traverse_module_state->__pyx_n_u_max_depth);
  Py_VISIT(traverse_module_state->__pyx_n_u_min_base_quality);
  Py_VISIT(traverse_module_state->__pyx_n_u_min_mapping_quality);
  Py_VISIT(traverse_module_state->__pyx_n_s_mode);
  Py_VISIT(traverse_module_state->__pyx_n_s_multiple_iterators);
  Py_VISIT(traverse_module_state->__pyx_kp_u_multiple_iterators_not_implement);
  Py_VISIT(traverse_module_state->__pyx_kp_u_multiple_iterators_not_implement_2);
  Py_VISIT(traverse_module_state->__pyx_kp_u_multiple_s_lines_are_not_permitt);
  Py_VISIT(traverse_module_state->__pyx_n_s_n);
  Py_VISIT(traverse_module_state->__pyx_n_s_name);
  Py_VISIT(traverse_module_state->__pyx_n_s_name_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_namedtuple);
  Py_VISIT(traverse_module_state->__pyx_n_s_new);
  Py_VISIT(traverse_module_state->__pyx_n_s_nextiter);
  Py_VISIT(traverse_module_state->__pyx_kp_s_no_default___reduce___due_to_non);
  Py_VISIT(traverse_module_state->__pyx_kp_u_no_index_available_for_fetch);
  Py_VISIT(traverse_module_state->__pyx_kp_u_no_index_available_for_iteration);
  Py_VISIT(traverse_module_state->__pyx_kp_u_no_index_available_for_pileup);
  Py_VISIT(traverse_module_state->__pyx_n_u_nofilter);
  Py_VISIT(traverse_module_state->__pyx_kp_u_not_enough_information_to_constr);
  Py_VISIT(traverse_module_state->__pyx_n_s_nreferences);
  Py_VISIT(traverse_module_state->__pyx_n_s_nt);
  Py_VISIT(traverse_module_state->__pyx_kp_u_number_of_reference_names_and_le);
  Py_VISIT(traverse_module_state->__pyx_n_s_op);
  Py_VISIT(traverse_module_state->__pyx_n_s_open);
  Py_VISIT(traverse_module_state->__pyx_n_s_os);
  Py_VISIT(traverse_module_state->__pyx_n_s_parse_region);
  Py_VISIT(traverse_module_state->__pyx_n_s_pickle);
  Py_VISIT(traverse_module_state->__pyx_n_s_pileup);
  Py_VISIT(traverse_module_state->__pyx_n_s_port);
  Py_VISIT(traverse_module_state->__pyx_n_s_pos);
  Py_VISIT(traverse_module_state->__pyx_n_s_positions);
  Py_VISIT(traverse_module_state->__pyx_n_s_pysam_libcalignmentfile);
  Py_VISIT(traverse_module_state->__pyx_kp_s_pysam_libcalignmentfile_pyx);
  Py_VISIT(traverse_module_state->__pyx_n_s_pyx_PickleError);
  Py_VISIT(traverse_module_state->__pyx_n_s_pyx_checksum);
  Py_VISIT(traverse_module_state->__pyx_n_s_pyx_result);
  Py_VISIT(traverse_module_state->__pyx_n_s_pyx_state);
  Py_VISIT(traverse_module_state->__pyx_n_s_pyx_type);
  Py_VISIT(traverse_module_state->__pyx_n_s_pyx_unpickle_SNPCall);
  Py_VISIT(traverse_module_state->__pyx_n_s_pyx_vtable);
  Py_VISIT(traverse_module_state->__pyx_n_s_qname);
  Py_VISIT(traverse_module_state->__pyx_n_s_qpos);
  Py_VISIT(traverse_module_state->__pyx_n_s_quality);
  Py_VISIT(traverse_module_state->__pyx_n_s_quality_threshold);
  Py_VISIT(traverse_module_state->__pyx_n_s_query_name);
  Py_VISIT(traverse_module_state->__pyx_n_s_query_qualities);
  Py_VISIT(traverse_module_state->__pyx_n_s_r);
  Py_VISIT(traverse_module_state->__pyx_n_u_r);
  Py_VISIT(traverse_module_state->__pyx_n_u_rU);
  Py_VISIT(traverse_module_state->__pyx_n_s_range);
  Py_VISIT(traverse_module_state->__pyx_n_u_rb);
  Py_VISIT(traverse_module_state->__pyx_n_u_rc);
  Py_VISIT(traverse_module_state->__pyx_n_s_re);
  Py_VISIT(traverse_module_state->__pyx_n_s_read);
  Py_VISIT(traverse_module_state->__pyx_n_s_read_callback);
  Py_VISIT(traverse_module_state->__pyx_n_s_read_failure_reason);
  Py_VISIT(traverse_module_state->__pyx_n_s_read_iterator);
  Py_VISIT(traverse_module_state->__pyx_n_s_read_loc);
  Py_VISIT(traverse_module_state->__pyx_kp_u_read_s_is_unpaired);
  Py_VISIT(traverse_module_state->__pyx_kp_u_read_s_not_found);
  Py_VISIT(traverse_module_state->__pyx_n_s_record);
  Py_VISIT(traverse_module_state->__pyx_n_u_redo_baq);
  Py_VISIT(traverse_module_state->__pyx_n_s_reduce);
  Py_VISIT(traverse_module_state->__pyx_n_s_reduce_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_reduce_ex);
  Py_VISIT(traverse_module_state->__pyx_n_s_ref);
  Py_VISIT(traverse_module_state->__pyx_n_s_reference);
  Py_VISIT(traverse_module_state->__pyx_n_s_reference_base);
  Py_VISIT(traverse_module_state->__pyx_n_s_reference_filename);
  Py_VISIT(traverse_module_state->__pyx_kp_u_reference_id_i_out_of_range_0_ti);
  Py_VISIT(traverse_module_state->__pyx_n_s_reference_lengths);
  Py_VISIT(traverse_module_state->__pyx_n_s_reference_names);
  Py_VISIT(traverse_module_state->__pyx_kp_u_reference_sequence_for_tid_not_f);
  Py_VISIT(traverse_module_state->__pyx_n_s_referencelengths);
  Py_VISIT(traverse_module_state->__pyx_n_s_referencenames);
  Py_VISIT(traverse_module_state->__pyx_n_s_references);
  Py_VISIT(traverse_module_state->__pyx_n_s_refpos);
  Py_VISIT(traverse_module_state->__pyx_n_s_region);
  Py_VISIT(traverse_module_state->__pyx_n_s_require_index);
  Py_VISIT(traverse_module_state->__pyx_n_s_res);
  Py_VISIT(traverse_module_state->__pyx_n_s_result);
  Py_VISIT(traverse_module_state->__pyx_n_s_results);
  Py_VISIT(traverse_module_state->__pyx_n_s_ret);
  Py_VISIT(traverse_module_state->__pyx_n_s_rstart);
  Py_VISIT(traverse_module_state->__pyx_n_s_rstop);
  Py_VISIT(traverse_module_state->__pyx_n_s_rtid);
  Py_VISIT(traverse_module_state->__pyx_kp_u_s);
  Py_VISIT(traverse_module_state->__pyx_kp_u_sam_write1_failed_with_error_cod);
  Py_VISIT(traverse_module_state->__pyx_n_s_samfile);
  Py_VISIT(traverse_module_state->__pyx_n_u_samtools);
  Py_VISIT(traverse_module_state->__pyx_n_s_self);
  Py_VISIT(traverse_module_state->__pyx_kp_s_self_b_self_htsfile_self_index_c);
  Py_VISIT(traverse_module_state->__pyx_kp_s_self_b_self_htsfile_self_index_s);
  Py_VISIT(traverse_module_state->__pyx_kp_s_self_htsfile_cannot_be_converted);
  Py_VISIT(traverse_module_state->__pyx_n_s_seq);
  Py_VISIT(traverse_module_state->__pyx_n_s_setstate);
  Py_VISIT(traverse_module_state->__pyx_n_s_setstate_cython);
  Py_VISIT(traverse_module_state->__pyx_n_s_snp_quality);
  Py_VISIT(traverse_module_state->__pyx_n_s_spec);
  Py_VISIT(traverse_module_state->__pyx_n_s_split);
  Py_VISIT(traverse_module_state->__pyx_n_s_splitlines);
  Py_VISIT(traverse_module_state->__pyx_n_s_sq);
  Py_VISIT(traverse_module_state->__pyx_n_s_start);
  Py_VISIT(traverse_module_state->__pyx_n_s_start_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_startswith);
  Py_VISIT(traverse_module_state->__pyx_n_s_state);
  Py_VISIT(traverse_module_state->__pyx_n_u_stepper);
  Py_VISIT(traverse_module_state->__pyx_n_s_stop);
  Py_VISIT(traverse_module_state->__pyx_n_s_stop_2);
  Py_VISIT(traverse_module_state->__pyx_n_s_str);
  Py_VISIT(traverse_module_state->__pyx_kp_s_stringsource);
  Py_VISIT(traverse_module_state->__pyx_n_s_strip);
  Py_VISIT(traverse_module_state->__pyx_n_s_sum);
  Py_VISIT(traverse_module_state->__pyx_n_s_super);
  Py_VISIT(traverse_module_state->__pyx_n_s_t);
  Py_VISIT(traverse_module_state->__pyx_n_s_tell);
  Py_VISIT(traverse_module_state->__pyx_n_s_template);
  Py_VISIT(traverse_module_state->__pyx_n_s_test);
  Py_VISIT(traverse_module_state->__pyx_n_s_text);
  Py_VISIT(traverse_module_state->__pyx_n_s_threads);
  Py_VISIT(traverse_module_state->__pyx_n_s_threshold);
  Py_VISIT(traverse_module_state->__pyx_n_s_tid);
  Py_VISIT(traverse_module_state->__pyx_n_s_to_dict);
  Py_VISIT(traverse_module_state->__pyx_n_u_total);
  Py_VISIT(traverse_module_state->__pyx_n_s_traceback);
  Py_VISIT(traverse_module_state->__pyx_n_s_truncate);
  Py_VISIT(traverse_module_state->__pyx_kp_u_truncated_file);
  Py_VISIT(traverse_module_state->__pyx_kp_u_unable_to_open_index_file);
  Py_VISIT(traverse_module_state->__pyx_kp_u_unable_to_open_index_file_s);
  Py_VISIT(traverse_module_state->__pyx_kp_u_unable_to_read_header_informatio);
  Py_VISIT(traverse_module_state->__pyx_kp_u_unable_to_reopen_htsfile);
  Py_VISIT(traverse_module_state->__pyx_kp_u_unknown_reference);
  Py_VISIT(traverse_module_state->__pyx_kp_u_unknown_stepper_option_s_in_Iter);
  Py_VISIT(traverse_module_state->__pyx_n_s_unmapped);
  Py_VISIT(traverse_module_state->__pyx_n_u_unmapped);
  Py_VISIT(traverse_module_state->__pyx_n_s_until_eof);
  Py_VISIT(traverse_module_state->__pyx_n_s_update);
  Py_VISIT(traverse_module_state->__pyx_n_s_use_setstate);
  Py_VISIT(traverse_module_state->__pyx_n_s_value);
  Py_VISIT(traverse_module_state->__pyx_n_s_values);
  Py_VISIT(traverse_module_state->__pyx_n_u_w);
  Py_VISIT(traverse_module_state->__pyx_n_s_warn);
  Py_VISIT(traverse_module_state->__pyx_n_s_warnings);
  Py_VISIT(traverse_module_state->__pyx_n_u_wb);
  Py_VISIT(traverse_module_state->__pyx_n_u_wb0);
  Py_VISIT(traverse_module_state->__pyx_n_u_wbu);
  Py_VISIT(traverse_module_state->__pyx_n_u_wc);
  Py_VISIT(traverse_module_state->__pyx_n_u_wh);
  Py_VISIT(traverse_module_state->__pyx_n_s_write);
  Py_VISIT(traverse_module_state->__pyx_kp_u_wrong_sequence_information_in_s);
  Py_VISIT(traverse_module_state->__pyx_n_s_x);
  Py_VISIT(traverse_module_state->__pyx_n_s_y);
  Py_VISIT(traverse_module_state->__pyx_n_s_zip);
  Py_VISIT(traverse_module_state->__pyx_int_0);
  Py_VISIT(traverse_module_state->__pyx_int_1);
  Py_VISIT(traverse_module_state->__pyx_int_2);
  Py_VISIT(traverse_module_state->__pyx_int_7);
  Py_VISIT(traverse_module_state->__pyx_int_8);
  Py_VISIT(traverse_module_state->__pyx_int_13);
  Py_VISIT(traverse_module_state->__pyx_int_15);
  Py_VISIT(traverse_module_state->__pyx_int_1796);
  Py_VISIT(traverse_module_state->__pyx_int_8000);
  Py_VISIT(traverse_module_state->__pyx_int_18041500);
  Py_VISIT(traverse_module_state->__pyx_int_84615809);
  Py_VISIT(traverse_module_state->__pyx_int_239452417);
  Py_VISIT(traverse_module_state->__pyx_int_neg_1);
  Py_VISIT(traverse_module_state->__pyx_int_neg_2);
  Py_VISIT(traverse_module_state->__pyx_codeobj_);
  Py_VISIT(traverse_module_state->__pyx_slice__9);
  Py_VISIT(traverse_module_state->__pyx_tuple__4);
  Py_VISIT(traverse_module_state->__pyx_tuple__6);
  Py_VISIT(traverse_module_state->__pyx_tuple__10);
  Py_VISIT(traverse_module_state->__pyx_tuple__14);
  Py_VISIT(traverse_module_state->__pyx_tuple__23);
  Py_VISIT(traverse_module_state->__pyx_tuple__29);
  Py_VISIT(traverse_module_state->__pyx_tuple__30);
  Py_VISIT(traverse_module_state->__pyx_tuple__40);
  Py_VISIT(traverse_module_state->__pyx_tuple__41);
  Py_VISIT(traverse_module_state->__pyx_tuple__42);
  Py_VISIT(traverse_module_state->__pyx_tuple__44);
  Py_VISIT(traverse_module_state->__pyx_tuple__45);
  Py_VISIT(traverse_module_state->__pyx_tuple__47);
  Py_VISIT(traverse_module_state->__pyx_tuple__48);
  Py_VISIT(traverse_module_state->__pyx_tuple__49);
  Py_VISIT(traverse_module_state->__pyx_tuple__50);
  Py_VISIT(traverse_module_state->__pyx_tuple__51);
  Py_VISIT(traverse_module_state->__pyx_tuple__52);
  Py_VISIT(traverse_module_state->__pyx_tuple__54);
  Py_VISIT(traverse_module_state->__pyx_tuple__55);
  Py_VISIT(traverse_module_state->__pyx_tuple__56);
  Py_VISIT(traverse_module_state->__pyx_tuple__59);
  Py_VISIT(traverse_module_state->__pyx_tuple__61);
  Py_VISIT(traverse_module_state->__pyx_tuple__64);
  Py_VISIT(traverse_module_state->__pyx_tuple__65);
  Py_VISIT(traverse_module_state->__pyx_tuple__73);
  Py_VISIT(traverse_module_state->__pyx_tuple__75);
  Py_VISIT(traverse_module_state->__pyx_tuple__83);
  Py_VISIT(traverse_module_state->__pyx_tuple__86);
  Py_VISIT(traverse_module_state->__pyx_tuple__87);
  Py_VISIT(traverse_module_state->__pyx_tuple__94);
  Py_VISIT(traverse_module_state->__pyx_codeobj__5);
  Py_VISIT(traverse_module_state->__pyx_codeobj__7);
  Py_VISIT(traverse_module_state->__pyx_codeobj__8);
  Py_VISIT(traverse_module_state->__pyx_tuple__102);
  Py_VISIT(traverse_module_state->__pyx_tuple__108);
  Py_VISIT(traverse_module_state->__pyx_tuple__117);
  Py_VISIT(traverse_module_state->__pyx_tuple__123);
  Py_VISIT(traverse_module_state->__pyx_tuple__126);
  Py_VISIT(traverse_module_state->__pyx_tuple__127);
  Py_VISIT(traverse_module_state->__pyx_tuple__128);
  Py_VISIT(traverse_module_state->__pyx_tuple__129);
  Py_VISIT(traverse_module_state->__pyx_tuple__130);
  Py_VISIT(traverse_module_state->__pyx_tuple__131);
  Py_VISIT(traverse_module_state->__pyx_tuple__132);
  Py_VISIT(traverse_module_state->__pyx_tuple__133);
  Py_VISIT(traverse_module_state->__pyx_tuple__134);
  Py_VISIT(traverse_module_state->__pyx_tuple__135);
  Py_VISIT(traverse_module_state->__pyx_tuple__136);
  Py_VISIT(traverse_module_state->__pyx_tuple__137);
  Py_VISIT(traverse_module_state->__pyx_tuple__138);
  Py_VISIT(traverse_module_state->__pyx_tuple__139);
  Py_VISIT(traverse_module_state->__pyx_tuple__140);
  Py_VISIT(traverse_module_state->__pyx_tuple__141);
  Py_VISIT(traverse_module_state->__pyx_tuple__142);
  Py_VISIT(traverse_module_state->__pyx_tuple__143);
  Py_VISIT(traverse_module_state->__pyx_tuple__144);
  Py_VISIT(traverse_module_state->__pyx_tuple__145);
  Py_VISIT(traverse_module_state->__pyx_tuple__146);
  Py_VISIT(traverse_module_state->__pyx_tuple__147);
  Py_VISIT(traverse_module_state->__pyx_tuple__148);
  Py_VISIT(traverse_module_state->__pyx_tuple__149);
  Py_VISIT(traverse_module_state->__pyx_tuple__150);
  Py_VISIT(traverse_module_state->__pyx_tuple__151);
  Py_VISIT(traverse_module_state->__pyx_tuple__152);
  Py_VISIT(traverse_module_state->__pyx_tuple__153);
  Py_VISIT(traverse_module_state->__pyx_tuple__154);
  Py_VISIT(traverse_module_state->__pyx_tuple__155);
  Py_VISIT(traverse_module_state->__pyx_tuple__156);
  Py_VISIT(traverse_module_state->__pyx_tuple__157);
  Py_VISIT(traverse_module_state->__pyx_tuple__158);
  Py_VISIT(traverse_module_state->__pyx_tuple__159);
  Py_VISIT(traverse_module_state->__pyx_tuple__160);
  Py_VISIT(traverse_module_state->__pyx_tuple__161);
  Py_VISIT(traverse_module_state->__pyx_tuple__162);
  Py_VISIT(traverse_module_state->__pyx_tuple__163);
  Py_VISIT(traverse_module_state->__pyx_tuple__164);
  Py_VISIT(traverse_module_state->__pyx_tuple__165);
  Py_VISIT(traverse_module_state->__pyx_tuple__166);
  Py_VISIT(traverse_module_state->__pyx_tuple__167);
  Py_VISIT(traverse_module_state->__pyx_tuple__168);
  Py_VISIT(traverse_module_state->__pyx_tuple__169);
  Py_VISIT(traverse_module_state->__pyx_tuple__170);
  Py_VISIT(traverse_module_state->__pyx_tuple__171);
  Py_VISIT(traverse_module_state->__pyx_codeobj__11);
  Py_VISIT(traverse_module_state->__pyx_codeobj__13);
  Py_VISIT(traverse_module_state->__pyx_codeobj__16);
  Py_VISIT(traverse_module_state->__pyx_codeobj__17);
  Py_VISIT(traverse_module_state->__pyx_codeobj__18);
  Py_VISIT(traverse_module_state->__pyx_codeobj__24);
  Py_VISIT(traverse_module_state->__pyx_codeobj__25);
  Py_VISIT(traverse_module_state->__pyx_codeobj__26);
  Py_VISIT(traverse_module_state->__pyx_codeobj__27);
  Py_VISIT(traverse_module_state->__pyx_codeobj__28);
  Py_VISIT(traverse_module_state->__pyx_codeobj__31);
  Py_VISIT(traverse_module_state->__pyx_codeobj__32);
  Py_VISIT(traverse_module_state->__pyx_codeobj__33);
  Py_VISIT(traverse_module_state->__pyx_codeobj__34);
  Py_VISIT(traverse_module_state->__pyx_codeobj__35);
  Py_VISIT(traverse_module_state->__pyx_codeobj__36);
  Py_VISIT(traverse_module_state->__pyx_codeobj__37);
  Py_VISIT(traverse_module_state->__pyx_codeobj__38);
  Py_VISIT(traverse_module_state->__pyx_codeobj__39);
  Py_VISIT(traverse_module_state->__pyx_codeobj__43);
  Py_VISIT(traverse_module_state->__pyx_codeobj__53);
  Py_VISIT(traverse_module_state->__pyx_codeobj__57);
  Py_VISIT(traverse_module_state->__pyx_codeobj__58);
  Py_VISIT(traverse_module_state->__pyx_codeobj__60);
  Py_VISIT(traverse_module_state->__pyx_codeobj__62);
  Py_VISIT(traverse_module_state->__pyx_codeobj__63);
  Py_VISIT(traverse_module_state->__pyx_codeobj__66);
  Py_VISIT(traverse_module_state->__pyx_codeobj__67);
  Py_VISIT(traverse_module_state->__pyx_codeobj__68);
  Py_VISIT(traverse_module_state->__pyx_codeobj__69);
  Py_VISIT(traverse_module_state->__pyx_codeobj__70);
  Py_VISIT(traverse_module_state->__pyx_codeobj__71);
  Py_VISIT(traverse_module_state->__pyx_codeobj__72);
  Py_VISIT(traverse_module_state->__pyx_codeobj__74);
  Py_VISIT(traverse_module_state->__pyx_codeobj__76);
  Py_VISIT(traverse_module_state->__pyx_codeobj__77);
  Py_VISIT(traverse_module_state->__pyx_codeobj__78);
  Py_VISIT(traverse_module_state->__pyx_codeobj__79);
  Py_VISIT(traverse_module_state->__pyx_codeobj__80);
  Py_VISIT(traverse_module_state->__pyx_codeobj__81);
  Py_VISIT(traverse_module_state->__pyx_codeobj__82);
  Py_VISIT(traverse_module_state->__pyx_codeobj__84);
  Py_VISIT(traverse_module_state->__pyx_codeobj__85);
  Py_VISIT(traverse_module_state->__pyx_codeobj__88);
  Py_VISIT(traverse_module_state->__pyx_codeobj__89);
  Py_VISIT(traverse_module_state->__pyx_codeobj__90);
  Py_VISIT(traverse_module_state->__pyx_codeobj__91);
  Py_VISIT(traverse_module_state->__pyx_codeobj__92);
  Py_VISIT(traverse_module_state->__pyx_codeobj__93);
  Py_VISIT(traverse_module_state->__pyx_codeobj__95);
  Py_VISIT(traverse_module_state->__pyx_codeobj__96);
  Py_VISIT(traverse_module_state->__pyx_codeobj__97);
  Py_VISIT(traverse_module_state->__pyx_codeobj__98);
  Py_VISIT(traverse_module_state->__pyx_codeobj__99);
  Py_VISIT(traverse_module_state->__pyx_codeobj__100);
  Py_VISIT(traverse_module_state->__pyx_codeobj__101);
  Py_VISIT(traverse_module_state->__pyx_codeobj__103);
  Py_VISIT(traverse_module_state->__pyx_codeobj__104);
  Py_VISIT(traverse_module_state->__pyx_codeobj__105);
  Py_VISIT(traverse_module_state->__pyx_codeobj__106);
  Py_VISIT(traverse_module_state->__pyx_codeobj__109);
  Py_VISIT(traverse_module_state->__pyx_codeobj__110);
  Py_VISIT(traverse_module_state->__pyx_codeobj__111);
  Py_VISIT(traverse_module_state->__pyx_codeobj__112);
  Py_VISIT(traverse_module_state->__pyx_codeobj__113);
  Py_VISIT(traverse_module_state->__pyx_codeobj__114);
  Py_VISIT(traverse_module_state->__pyx_codeobj__115);
  Py_VISIT(traverse_module_state->__pyx_codeobj__116);
  Py_VISIT(traverse_module_state->__pyx_codeobj__118);
  Py_VISIT(traverse_module_state->__pyx_codeobj__119);
  Py_VISIT(traverse_module_state->__pyx_codeobj__120);
  Py_VISIT(traverse_module_state->__pyx_codeobj__121);
  Py_VISIT(traverse_module_state->__pyx_codeobj__122);
  return 0;
}
#endif
/* #### Code section: module_state_defines ### */
#define __pyx_d __pyx_mstate_global->__pyx_d
#define __pyx_b __pyx_mstate_global->__pyx_b
#define __pyx_cython_runtime __pyx_mstate_global->__pyx_cython_runtime
#define __pyx_empty_tuple __pyx_mstate_global->__pyx_empty_tuple
#define __pyx_empty_bytes __pyx_mstate_global->__pyx_empty_bytes
#define __pyx_empty_unicode __pyx_mstate_global->__pyx_empty_unicode
#ifdef __Pyx_CyFunction_USED
#define __pyx_CyFunctionType __pyx_mstate_global->__pyx_CyFunctionType
#endif
#ifdef __Pyx_FusedFunction_USED
#define __pyx_FusedFunctionType __pyx_mstate_global->__pyx_FusedFunctionType
#endif
#ifdef __Pyx_Generator_USED
#define __pyx_GeneratorType __pyx_mstate_global->__pyx_GeneratorType
#endif
#ifdef __Pyx_IterableCoroutine_USED
#define __pyx_IterableCoroutineType __pyx_mstate_global->__pyx_IterableCoroutineType
#endif
#ifdef __Pyx_Coroutine_USED
#define __pyx_CoroutineAwaitType __pyx_mstate_global->__pyx_CoroutineAwaitType
#endif
#ifdef __Pyx_Coroutine_USED
#define __pyx_CoroutineType __pyx_mstate_global->__pyx_CoroutineType
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_7cpython_4type_type __pyx_mstate_global->__pyx_ptype_7cpython_4type_type
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_7cpython_4bool_bool __pyx_mstate_global->__pyx_ptype_7cpython_4bool_bool
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_7cpython_7complex_complex __pyx_mstate_global->__pyx_ptype_7cpython_7complex_complex
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_7cpython_5array_array __pyx_mstate_global->__pyx_ptype_7cpython_5array_array
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_5pysam_10libchtslib_HTSFile __pyx_mstate_global->__pyx_ptype_5pysam_10libchtslib_HTSFile
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_5pysam_9libcfaidx_FastaFile __pyx_mstate_global->__pyx_ptype_5pysam_9libcfaidx_FastaFile
#define __pyx_ptype_5pysam_9libcfaidx_FastqProxy __pyx_mstate_global->__pyx_ptype_5pysam_9libcfaidx_FastqProxy
#define __pyx_ptype_5pysam_9libcfaidx_FastxRecord __pyx_mstate_global->__pyx_ptype_5pysam_9libcfaidx_FastxRecord
#define __pyx_ptype_5pysam_9libcfaidx_FastxFile __pyx_mstate_global->__pyx_ptype_5pysam_9libcfaidx_FastxFile
#define __pyx_ptype_5pysam_9libcfaidx_FastqFile __pyx_mstate_global->__pyx_ptype_5pysam_9libcfaidx_FastqFile
#define __pyx_ptype_5pysam_9libcfaidx_Fastafile __pyx_mstate_global->__pyx_ptype_5pysam_9libcfaidx_Fastafile
#if CYTHON_USE_MODULE_STATE
#endif
#define __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment __pyx_mstate_global->__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment
#define __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn __pyx_mstate_global->__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn
#define __pyx_ptype_5pysam_18libcalignedsegment_PileupRead __pyx_mstate_global->__pyx_ptype_5pysam_18libcalignedsegment_PileupRead
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#endif
#if CYTHON_USE_MODULE_STATE
#define __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader
#define __pyx_type_5pysam_17libcalignmentfile_AlignmentFile __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_AlignmentFile
#define __pyx_type_5pysam_17libcalignmentfile_IteratorRow __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorRow
#define __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion
#define __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead
#define __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll
#define __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs
#define __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection
#define __pyx_type_5pysam_17libcalignmentfile_IteratorColumn __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorColumn
#define __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion
#define __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs
#define __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll
#define __pyx_type_5pysam_17libcalignmentfile_IndexedReads __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_IndexedReads
#define __pyx_type_5pysam_17libcalignmentfile_SNPCall __pyx_mstate_global->__pyx_type_5pysam_17libcalignmentfile_SNPCall
#endif
#define __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader
#define __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs
#define __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll
#define __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads
#define __pyx_ptype_5pysam_17libcalignmentfile_SNPCall __pyx_mstate_global->__pyx_ptype_5pysam_17libcalignmentfile_SNPCall
#define __pyx_n_u_AH __pyx_mstate_global->__pyx_n_u_AH
#define __pyx_n_u_AN __pyx_mstate_global->__pyx_n_u_AN
#define __pyx_n_u_AS __pyx_mstate_global->__pyx_n_u_AS
#define __pyx_kp_u_AlignedSegment_refers_to_referen __pyx_mstate_global->__pyx_kp_u_AlignedSegment_refers_to_referen
#define __pyx_n_s_AlignmentFile __pyx_mstate_global->__pyx_n_s_AlignmentFile
#define __pyx_n_u_AlignmentFile __pyx_mstate_global->__pyx_n_u_AlignmentFile
#define __pyx_n_s_AlignmentFile___enter __pyx_mstate_global->__pyx_n_s_AlignmentFile___enter
#define __pyx_n_s_AlignmentFile___exit __pyx_mstate_global->__pyx_n_s_AlignmentFile___exit
#define __pyx_n_s_AlignmentFile___reduce_cython __pyx_mstate_global->__pyx_n_s_AlignmentFile___reduce_cython
#define __pyx_n_s_AlignmentFile___setstate_cython __pyx_mstate_global->__pyx_n_s_AlignmentFile___setstate_cython
#define __pyx_n_s_AlignmentFile__open __pyx_mstate_global->__pyx_n_s_AlignmentFile__open
#define __pyx_n_s_AlignmentFile_check_index __pyx_mstate_global->__pyx_n_s_AlignmentFile_check_index
#define __pyx_n_s_AlignmentFile_close __pyx_mstate_global->__pyx_n_s_AlignmentFile_close
#define __pyx_n_s_AlignmentFile_count __pyx_mstate_global->__pyx_n_s_AlignmentFile_count
#define __pyx_n_s_AlignmentFile_count_coverage __pyx_mstate_global->__pyx_n_s_AlignmentFile_count_coverage
#define __pyx_n_s_AlignmentFile_fetch __pyx_mstate_global->__pyx_n_s_AlignmentFile_fetch
#define __pyx_n_s_AlignmentFile_find_introns __pyx_mstate_global->__pyx_n_s_AlignmentFile_find_introns
#define __pyx_n_s_AlignmentFile_find_introns_slow __pyx_mstate_global->__pyx_n_s_AlignmentFile_find_introns_slow
#define __pyx_n_s_AlignmentFile_get_index_statisti __pyx_mstate_global->__pyx_n_s_AlignmentFile_get_index_statisti
#define __pyx_n_s_AlignmentFile_get_reference_leng __pyx_mstate_global->__pyx_n_s_AlignmentFile_get_reference_leng
#define __pyx_n_s_AlignmentFile_get_reference_name __pyx_mstate_global->__pyx_n_s_AlignmentFile_get_reference_name
#define __pyx_n_s_AlignmentFile_get_tid __pyx_mstate_global->__pyx_n_s_AlignmentFile_get_tid
#define __pyx_n_s_AlignmentFile_getrname __pyx_mstate_global->__pyx_n_s_AlignmentFile_getrname
#define __pyx_n_s_AlignmentFile_gettid __pyx_mstate_global->__pyx_n_s_AlignmentFile_gettid
#define __pyx_n_s_AlignmentFile_has_index __pyx_mstate_global->__pyx_n_s_AlignmentFile_has_index
#define __pyx_n_s_AlignmentFile_head __pyx_mstate_global->__pyx_n_s_AlignmentFile_head
#define __pyx_n_s_AlignmentFile_is_valid_tid __pyx_mstate_global->__pyx_n_s_AlignmentFile_is_valid_tid
#define __pyx_kp_u_AlignmentFile_mapped_only_availa __pyx_mstate_global->__pyx_kp_u_AlignmentFile_mapped_only_availa
#define __pyx_n_s_AlignmentFile_mate __pyx_mstate_global->__pyx_n_s_AlignmentFile_mate
#define __pyx_n_s_AlignmentFile_pileup __pyx_mstate_global->__pyx_n_s_AlignmentFile_pileup
#define __pyx_n_s_AlignmentFile_write __pyx_mstate_global->__pyx_n_s_AlignmentFile_write
#define __pyx_n_s_AlignmentHeader __pyx_mstate_global->__pyx_n_s_AlignmentHeader
#define __pyx_n_u_AlignmentHeader __pyx_mstate_global->__pyx_n_u_AlignmentHeader
#define __pyx_n_s_AlignmentHeader___reduce_cython __pyx_mstate_global->__pyx_n_s_AlignmentHeader___reduce_cython
#define __pyx_n_s_AlignmentHeader___setstate_cytho __pyx_mstate_global->__pyx_n_s_AlignmentHeader___setstate_cytho
#define __pyx_n_s_AlignmentHeader__build_sequence __pyx_mstate_global->__pyx_n_s_AlignmentHeader__build_sequence
#define __pyx_n_s_AlignmentHeader__from_text_and_l __pyx_mstate_global->__pyx_n_s_AlignmentHeader__from_text_and_l
#define __pyx_n_s_AlignmentHeader_as_dict __pyx_mstate_global->__pyx_n_s_AlignmentHeader_as_dict
#define __pyx_n_s_AlignmentHeader_copy __pyx_mstate_global->__pyx_n_s_AlignmentHeader_copy
#define __pyx_kp_u_AlignmentHeader_does_not_support __pyx_mstate_global->__pyx_kp_u_AlignmentHeader_does_not_support
#define __pyx_n_s_AlignmentHeader_from_dict __pyx_mstate_global->__pyx_n_s_AlignmentHeader_from_dict
#define __pyx_n_s_AlignmentHeader_from_references __pyx_mstate_global->__pyx_n_s_AlignmentHeader_from_references
#define __pyx_n_s_AlignmentHeader_from_text __pyx_mstate_global->__pyx_n_s_AlignmentHeader_from_text
#define __pyx_n_s_AlignmentHeader_get __pyx_mstate_global->__pyx_n_s_AlignmentHeader_get
#define __pyx_n_s_AlignmentHeader_get_reference_le __pyx_mstate_global->__pyx_n_s_AlignmentHeader_get_reference_le
#define __pyx_n_s_AlignmentHeader_get_reference_na __pyx_mstate_global->__pyx_n_s_AlignmentHeader_get_reference_na
#define __pyx_n_s_AlignmentHeader_get_tid __pyx_mstate_global->__pyx_n_s_AlignmentHeader_get_tid
#define __pyx_n_s_AlignmentHeader_is_valid_tid __pyx_mstate_global->__pyx_n_s_AlignmentHeader_is_valid_tid
#define __pyx_n_s_AlignmentHeader_items __pyx_mstate_global->__pyx_n_s_AlignmentHeader_items
#define __pyx_n_s_AlignmentHeader_iteritems __pyx_mstate_global->__pyx_n_s_AlignmentHeader_iteritems
#define __pyx_n_s_AlignmentHeader_keys __pyx_mstate_global->__pyx_n_s_AlignmentHeader_keys
#define __pyx_n_s_AlignmentHeader_to_dict __pyx_mstate_global->__pyx_n_s_AlignmentHeader_to_dict
#define __pyx_n_s_AlignmentHeader_values __pyx_mstate_global->__pyx_n_s_AlignmentHeader_values
#define __pyx_n_s_AssertionError __pyx_mstate_global->__pyx_n_s_AssertionError
#define __pyx_n_s_AttributeError __pyx_mstate_global->__pyx_n_s_AttributeError
#define __pyx_n_s_BAM_CREF_SKIP __pyx_mstate_global->__pyx_n_s_BAM_CREF_SKIP
#define __pyx_n_u_BC __pyx_mstate_global->__pyx_n_u_BC
#define __pyx_n_u_CL __pyx_mstate_global->__pyx_n_u_CL
#define __pyx_n_u_CN __pyx_mstate_global->__pyx_n_u_CN
#define __pyx_n_u_CO __pyx_mstate_global->__pyx_n_u_CO
#define __pyx_kp_u_Cannot_add_extra_threads_when_ig __pyx_mstate_global->__pyx_kp_u_Cannot_add_extra_threads_when_ig
#define __pyx_n_s_Counter __pyx_mstate_global->__pyx_n_s_Counter
#define __pyx_n_u_DS __pyx_mstate_global->__pyx_n_u_DS
#define __pyx_n_u_DT __pyx_mstate_global->__pyx_n_u_DT
#define __pyx_n_u_FO __pyx_mstate_global->__pyx_n_u_FO
#define __pyx_n_u_GO __pyx_mstate_global->__pyx_n_u_GO
#define __pyx_n_u_HD __pyx_mstate_global->__pyx_n_u_HD
#define __pyx_n_u_ID __pyx_mstate_global->__pyx_n_u_ID
#define __pyx_n_s_IOError __pyx_mstate_global->__pyx_n_s_IOError
#define __pyx_kp_u_I_O_operation_on_closed_file __pyx_mstate_global->__pyx_kp_u_I_O_operation_on_closed_file
#define __pyx_n_s_ImportError __pyx_mstate_global->__pyx_n_s_ImportError
#define __pyx_kp_s_Incompatible_checksums_0x_x_vs_0 __pyx_mstate_global->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0
#define __pyx_n_s_IndexStats __pyx_mstate_global->__pyx_n_s_IndexStats
#define __pyx_n_u_IndexStats __pyx_mstate_global->__pyx_n_u_IndexStats
#define __pyx_n_s_IndexedReads __pyx_mstate_global->__pyx_n_s_IndexedReads
#define __pyx_n_u_IndexedReads __pyx_mstate_global->__pyx_n_u_IndexedReads
#define __pyx_n_s_IndexedReads___reduce_cython __pyx_mstate_global->__pyx_n_s_IndexedReads___reduce_cython
#define __pyx_n_s_IndexedReads___setstate_cython __pyx_mstate_global->__pyx_n_s_IndexedReads___setstate_cython
#define __pyx_n_s_IndexedReads_build __pyx_mstate_global->__pyx_n_s_IndexedReads_build
#define __pyx_n_s_IndexedReads_find __pyx_mstate_global->__pyx_n_s_IndexedReads_find
#define __pyx_n_s_IteratorColumn __pyx_mstate_global->__pyx_n_s_IteratorColumn
#define __pyx_n_u_IteratorColumn __pyx_mstate_global->__pyx_n_u_IteratorColumn
#define __pyx_n_s_IteratorColumnAll __pyx_mstate_global->__pyx_n_s_IteratorColumnAll
#define __pyx_n_s_IteratorColumnAllRefs __pyx_mstate_global->__pyx_n_s_IteratorColumnAllRefs
#define __pyx_n_s_IteratorColumnAllRefs___reduce_c __pyx_mstate_global->__pyx_n_s_IteratorColumnAllRefs___reduce_c
#define __pyx_n_s_IteratorColumnAllRefs___setstate __pyx_mstate_global->__pyx_n_s_IteratorColumnAllRefs___setstate
#define __pyx_n_s_IteratorColumnAll___reduce_cytho __pyx_mstate_global->__pyx_n_s_IteratorColumnAll___reduce_cytho
#define __pyx_n_s_IteratorColumnAll___setstate_cyt __pyx_mstate_global->__pyx_n_s_IteratorColumnAll___setstate_cyt
#define __pyx_n_s_IteratorColumnRegion __pyx_mstate_global->__pyx_n_s_IteratorColumnRegion
#define __pyx_n_s_IteratorColumnRegion___reduce_cy __pyx_mstate_global->__pyx_n_s_IteratorColumnRegion___reduce_cy
#define __pyx_n_s_IteratorColumnRegion___setstate __pyx_mstate_global->__pyx_n_s_IteratorColumnRegion___setstate
#define __pyx_n_s_IteratorColumn___reduce_cython __pyx_mstate_global->__pyx_n_s_IteratorColumn___reduce_cython
#define __pyx_n_s_IteratorColumn___setstate_cython __pyx_mstate_global->__pyx_n_s_IteratorColumn___setstate_cython
#define __pyx_n_s_IteratorColumn_addReference __pyx_mstate_global->__pyx_n_s_IteratorColumn_addReference
#define __pyx_n_s_IteratorColumn_add_reference __pyx_mstate_global->__pyx_n_s_IteratorColumn_add_reference
#define __pyx_n_s_IteratorColumn_hasReference __pyx_mstate_global->__pyx_n_s_IteratorColumn_hasReference
#define __pyx_n_s_IteratorColumn_has_reference __pyx_mstate_global->__pyx_n_s_IteratorColumn_has_reference
#define __pyx_n_s_IteratorRow __pyx_mstate_global->__pyx_n_s_IteratorRow
#define __pyx_n_u_IteratorRow __pyx_mstate_global->__pyx_n_u_IteratorRow
#define __pyx_n_s_IteratorRowAll __pyx_mstate_global->__pyx_n_s_IteratorRowAll
#define __pyx_n_s_IteratorRowAllRefs __pyx_mstate_global->__pyx_n_s_IteratorRowAllRefs
#define __pyx_n_s_IteratorRowAllRefs___reduce_cyth __pyx_mstate_global->__pyx_n_s_IteratorRowAllRefs___reduce_cyth
#define __pyx_n_s_IteratorRowAllRefs___setstate_cy __pyx_mstate_global->__pyx_n_s_IteratorRowAllRefs___setstate_cy
#define __pyx_n_s_IteratorRowAllRefs_nextiter __pyx_mstate_global->__pyx_n_s_IteratorRowAllRefs_nextiter
#define __pyx_n_s_IteratorRowAll___reduce_cython __pyx_mstate_global->__pyx_n_s_IteratorRowAll___reduce_cython
#define __pyx_n_s_IteratorRowAll___setstate_cython __pyx_mstate_global->__pyx_n_s_IteratorRowAll___setstate_cython
#define __pyx_n_s_IteratorRowHead __pyx_mstate_global->__pyx_n_s_IteratorRowHead
#define __pyx_n_s_IteratorRowHead___reduce_cython __pyx_mstate_global->__pyx_n_s_IteratorRowHead___reduce_cython
#define __pyx_n_s_IteratorRowHead___setstate_cytho __pyx_mstate_global->__pyx_n_s_IteratorRowHead___setstate_cytho
#define __pyx_n_s_IteratorRowRegion __pyx_mstate_global->__pyx_n_s_IteratorRowRegion
#define __pyx_n_s_IteratorRowRegion___reduce_cytho __pyx_mstate_global->__pyx_n_s_IteratorRowRegion___reduce_cytho
#define __pyx_n_s_IteratorRowRegion___setstate_cyt __pyx_mstate_global->__pyx_n_s_IteratorRowRegion___setstate_cyt
#define __pyx_n_s_IteratorRowSelection __pyx_mstate_global->__pyx_n_s_IteratorRowSelection
#define __pyx_n_s_IteratorRowSelection___reduce_cy __pyx_mstate_global->__pyx_n_s_IteratorRowSelection___reduce_cy
#define __pyx_n_s_IteratorRowSelection___setstate __pyx_mstate_global->__pyx_n_s_IteratorRowSelection___setstate
#define __pyx_n_s_IteratorRow___reduce_cython __pyx_mstate_global->__pyx_n_s_IteratorRow___reduce_cython
#define __pyx_n_s_IteratorRow___setstate_cython __pyx_mstate_global->__pyx_n_s_IteratorRow___setstate_cython
#define __pyx_n_s_KNOWN_HEADER_FIELDS __pyx_mstate_global->__pyx_n_s_KNOWN_HEADER_FIELDS
#define __pyx_n_u_KS __pyx_mstate_global->__pyx_n_u_KS
#define __pyx_n_s_KeyError __pyx_mstate_global->__pyx_n_s_KeyError
#define __pyx_n_u_L __pyx_mstate_global->__pyx_n_u_L
#define __pyx_n_u_LB __pyx_mstate_global->__pyx_n_u_LB
#define __pyx_n_u_LN __pyx_mstate_global->__pyx_n_u_LN
#define __pyx_n_u_M5 __pyx_mstate_global->__pyx_n_u_M5
#define __pyx_n_s_Mapping __pyx_mstate_global->__pyx_n_s_Mapping
#define __pyx_n_s_MemoryError __pyx_mstate_global->__pyx_n_s_MemoryError
#define __pyx_n_u_N __pyx_mstate_global->__pyx_n_u_N
#define __pyx_n_s_NotImplementedError __pyx_mstate_global->__pyx_n_s_NotImplementedError
#define __pyx_n_s_OSError __pyx_mstate_global->__pyx_n_s_OSError
#define __pyx_n_s_OrderedDict __pyx_mstate_global->__pyx_n_s_OrderedDict
#define __pyx_n_u_PG __pyx_mstate_global->__pyx_n_u_PG
#define __pyx_n_u_PI __pyx_mstate_global->__pyx_n_u_PI
#define __pyx_n_u_PL __pyx_mstate_global->__pyx_n_u_PL
#define __pyx_n_u_PM __pyx_mstate_global->__pyx_n_u_PM
#define __pyx_n_u_PN __pyx_mstate_global->__pyx_n_u_PN
#define __pyx_n_u_PP __pyx_mstate_global->__pyx_n_u_PP
#define __pyx_n_u_PU __pyx_mstate_global->__pyx_n_u_PU
#define __pyx_n_s_PickleError __pyx_mstate_global->__pyx_n_s_PickleError
#define __pyx_n_u_RG __pyx_mstate_global->__pyx_n_u_RG
#define __pyx_kp_u_Raw_iterator_set_up_without_regi __pyx_mstate_global->__pyx_kp_u_Raw_iterator_set_up_without_regi
#define __pyx_kp_u_SAM_file_does_not_have_a_valid_h __pyx_mstate_global->__pyx_kp_u_SAM_file_does_not_have_a_valid_h
#define __pyx_n_u_SM __pyx_mstate_global->__pyx_n_u_SM
#define __pyx_n_u_SN __pyx_mstate_global->__pyx_n_u_SN
#define __pyx_n_s_SNPCall __pyx_mstate_global->__pyx_n_s_SNPCall
#define __pyx_n_s_SNPCall___reduce_cython __pyx_mstate_global->__pyx_n_s_SNPCall___reduce_cython
#define __pyx_n_s_SNPCall___setstate_cython __pyx_mstate_global->__pyx_n_s_SNPCall___setstate_cython
#define __pyx_n_u_SO __pyx_mstate_global->__pyx_n_u_SO
#define __pyx_n_u_SP __pyx_mstate_global->__pyx_n_u_SP
#define __pyx_kp_u_SQ __pyx_mstate_global->__pyx_kp_u_SQ
#define __pyx_n_u_SQ_2 __pyx_mstate_global->__pyx_n_u_SQ_2
#define __pyx_kp_u_SQ_SN_LN __pyx_mstate_global->__pyx_kp_u_SQ_SN_LN
#define __pyx_n_u_SS __pyx_mstate_global->__pyx_n_u_SS
#define __pyx_n_s_Sequence __pyx_mstate_global->__pyx_n_s_Sequence
#define __pyx_n_s_StopIteration __pyx_mstate_global->__pyx_n_s_StopIteration
#define __pyx_n_s_StringIO __pyx_mstate_global->__pyx_n_s_StringIO
#define __pyx_n_u_TP __pyx_mstate_global->__pyx_n_u_TP
#define __pyx_n_s_TypeError __pyx_mstate_global->__pyx_n_s_TypeError
#define __pyx_n_u_UR __pyx_mstate_global->__pyx_n_u_UR
#define __pyx_n_s_VALID_HEADERS __pyx_mstate_global->__pyx_n_s_VALID_HEADERS
#define __pyx_n_s_VALID_HEADER_ORDER __pyx_mstate_global->__pyx_n_s_VALID_HEADER_ORDER
#define __pyx_n_s_VALID_HEADER_TYPES __pyx_mstate_global->__pyx_n_s_VALID_HEADER_TYPES
#define __pyx_n_u_VN __pyx_mstate_global->__pyx_n_u_VN
#define __pyx_n_s_ValueError __pyx_mstate_global->__pyx_n_s_ValueError
#define __pyx_kp_u__12 __pyx_mstate_global->__pyx_kp_u__12
#define __pyx_kp_u__124 __pyx_mstate_global->__pyx_kp_u__124
#define __pyx_n_s__125 __pyx_mstate_global->__pyx_n_s__125
#define __pyx_kp_u__15 __pyx_mstate_global->__pyx_kp_u__15
#define __pyx_n_s__172 __pyx_mstate_global->__pyx_n_s__172
#define __pyx_kp_u__19 __pyx_mstate_global->__pyx_kp_u__19
#define __pyx_kp_u__2 __pyx_mstate_global->__pyx_kp_u__2
#define __pyx_kp_u__20 __pyx_mstate_global->__pyx_kp_u__20
#define __pyx_kp_u__21 __pyx_mstate_global->__pyx_kp_u__21
#define __pyx_kp_u__22 __pyx_mstate_global->__pyx_kp_u__22
#define __pyx_kp_u__3 __pyx_mstate_global->__pyx_kp_u__3
#define __pyx_kp_b__46 __pyx_mstate_global->__pyx_kp_b__46
#define __pyx_kp_u_access_from_StringIO_objects_not __pyx_mstate_global->__pyx_kp_u_access_from_StringIO_objects_not
#define __pyx_n_s_addReference __pyx_mstate_global->__pyx_n_s_addReference
#define __pyx_n_s_add_hts_options __pyx_mstate_global->__pyx_n_s_add_hts_options
#define __pyx_n_s_add_reference __pyx_mstate_global->__pyx_n_s_add_reference
#define __pyx_n_s_add_sam_header __pyx_mstate_global->__pyx_n_s_add_sam_header
#define __pyx_n_s_add_sq_text __pyx_mstate_global->__pyx_n_s_add_sq_text
#define __pyx_n_u_adjust_capq_threshold __pyx_mstate_global->__pyx_n_u_adjust_capq_threshold
#define __pyx_n_u_all __pyx_mstate_global->__pyx_n_u_all
#define __pyx_n_s_all_2 __pyx_mstate_global->__pyx_n_s_all_2
#define __pyx_n_s_append __pyx_mstate_global->__pyx_n_s_append
#define __pyx_n_s_args __pyx_mstate_global->__pyx_n_s_args
#define __pyx_n_s_array __pyx_mstate_global->__pyx_n_s_array
#define __pyx_n_s_as_dict __pyx_mstate_global->__pyx_n_s_as_dict
#define __pyx_n_s_asyncio_coroutines __pyx_mstate_global->__pyx_n_s_asyncio_coroutines
#define __pyx_n_s_b __pyx_mstate_global->__pyx_n_s_b
#define __pyx_n_u_b __pyx_mstate_global->__pyx_n_u_b
#define __pyx_n_s_base_position __pyx_mstate_global->__pyx_n_s_base_position
#define __pyx_n_s_beg __pyx_mstate_global->__pyx_n_s_beg
#define __pyx_n_s_bfile_name __pyx_mstate_global->__pyx_n_s_bfile_name
#define __pyx_n_s_btext __pyx_mstate_global->__pyx_n_s_btext
#define __pyx_n_s_build __pyx_mstate_global->__pyx_n_s_build
#define __pyx_n_s_build_header_line __pyx_mstate_global->__pyx_n_s_build_header_line
#define __pyx_n_s_build_sequence_section __pyx_mstate_global->__pyx_n_s_build_sequence_section
#define __pyx_n_s_c __pyx_mstate_global->__pyx_n_s_c
#define __pyx_n_u_c __pyx_mstate_global->__pyx_n_u_c
#define __pyx_kp_u_can_not_iterate_over_samfile_wit __pyx_mstate_global->__pyx_kp_u_can_not_iterate_over_samfile_wit
#define __pyx_kp_u_can_only_apply_IndexReads_on_bam __pyx_mstate_global->__pyx_kp_u_can_only_apply_IndexReads_on_bam
#define __pyx_kp_u_cannot_create_AlignmentHeader_re __pyx_mstate_global->__pyx_kp_u_cannot_create_AlignmentHeader_re
#define __pyx_n_s_cfilename __pyx_mstate_global->__pyx_n_s_cfilename
#define __pyx_n_s_check_header __pyx_mstate_global->__pyx_n_s_check_header
#define __pyx_n_s_check_index __pyx_mstate_global->__pyx_n_s_check_index
#define __pyx_n_s_check_sq __pyx_mstate_global->__pyx_n_s_check_sq
#define __pyx_n_s_check_truncation __pyx_mstate_global->__pyx_n_s_check_truncation
#define __pyx_n_s_cigar __pyx_mstate_global->__pyx_n_s_cigar
#define __pyx_n_s_cigarstring __pyx_mstate_global->__pyx_n_s_cigarstring
#define __pyx_n_s_cigartuples __pyx_mstate_global->__pyx_n_s_cigartuples
#define __pyx_n_s_cindexname __pyx_mstate_global->__pyx_n_s_cindexname
#define __pyx_n_s_class_getitem __pyx_mstate_global->__pyx_n_s_class_getitem
#define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback
#define __pyx_n_s_close __pyx_mstate_global->__pyx_n_s_close
#define __pyx_n_s_closed __pyx_mstate_global->__pyx_n_s_closed
#define __pyx_n_s_cls __pyx_mstate_global->__pyx_n_s_cls
#define __pyx_n_s_cmode __pyx_mstate_global->__pyx_n_s_cmode
#define __pyx_n_s_code __pyx_mstate_global->__pyx_n_s_code
#define __pyx_n_s_collections __pyx_mstate_global->__pyx_n_s_collections
#define __pyx_n_s_collections_abc __pyx_mstate_global->__pyx_n_s_collections_abc
#define __pyx_n_u_compute_baq __pyx_mstate_global->__pyx_n_u_compute_baq
#define __pyx_n_s_consensus_quality __pyx_mstate_global->__pyx_n_s_consensus_quality
#define __pyx_n_s_contains __pyx_mstate_global->__pyx_n_s_contains
#define __pyx_n_s_contig __pyx_mstate_global->__pyx_n_s_contig
#define __pyx_n_u_contig __pyx_mstate_global->__pyx_n_u_contig
#define __pyx_n_s_contig_length __pyx_mstate_global->__pyx_n_s_contig_length
#define __pyx_n_s_copy __pyx_mstate_global->__pyx_n_s_copy
#define __pyx_kp_u_could_not_allocate_bytes __pyx_mstate_global->__pyx_kp_u_could_not_allocate_bytes
#define __pyx_kp_u_could_not_allocate_memory_of_siz __pyx_mstate_global->__pyx_kp_u_could_not_allocate_memory_of_siz
#define __pyx_kp_u_could_not_create_header __pyx_mstate_global->__pyx_kp_u_could_not_create_header
#define __pyx_kp_u_could_not_open_alignment_file __pyx_mstate_global->__pyx_kp_u_could_not_open_alignment_file
#define __pyx_kp_u_could_not_open_alignment_file_2 __pyx_mstate_global->__pyx_kp_u_could_not_open_alignment_file_2
#define __pyx_kp_u_could_not_parse_header __pyx_mstate_global->__pyx_kp_u_could_not_parse_header
#define __pyx_n_s_count __pyx_mstate_global->__pyx_n_s_count
#define __pyx_n_s_count_a __pyx_mstate_global->__pyx_n_s_count_a
#define __pyx_n_s_count_c __pyx_mstate_global->__pyx_n_s_count_c
#define __pyx_n_s_count_coverage __pyx_mstate_global->__pyx_n_s_count_coverage
#define __pyx_n_s_count_g __pyx_mstate_global->__pyx_n_s_count_g
#define __pyx_n_s_count_t __pyx_mstate_global->__pyx_n_s_count_t
#define __pyx_n_s_counter __pyx_mstate_global->__pyx_n_s_counter
#define __pyx_n_s_coverage __pyx_mstate_global->__pyx_n_s_coverage
#define __pyx_n_s_creference_filename __pyx_mstate_global->__pyx_n_s_creference_filename
#define __pyx_n_s_ctext __pyx_mstate_global->__pyx_n_s_ctext
#define __pyx_n_s_data __pyx_mstate_global->__pyx_n_s_data
#define __pyx_n_s_defaultdict __pyx_mstate_global->__pyx_n_s_defaultdict
#define __pyx_n_s_dict __pyx_mstate_global->__pyx_n_s_dict
#define __pyx_n_s_dict_2 __pyx_mstate_global->__pyx_n_s_dict_2
#define __pyx_kp_u_disable __pyx_mstate_global->__pyx_kp_u_disable
#define __pyx_n_s_duplicate_filehandle __pyx_mstate_global->__pyx_n_s_duplicate_filehandle
#define __pyx_kp_u_either_supply_options_template_h __pyx_mstate_global->__pyx_kp_u_either_supply_options_template_h
#define __pyx_kp_u_enable __pyx_mstate_global->__pyx_kp_u_enable
#define __pyx_n_s_end __pyx_mstate_global->__pyx_n_s_end
#define __pyx_n_s_enter __pyx_mstate_global->__pyx_n_s_enter
#define __pyx_n_s_enumerate __pyx_mstate_global->__pyx_n_s_enumerate
#define __pyx_kp_u_error_during_iteration __pyx_mstate_global->__pyx_kp_u_error_during_iteration
#define __pyx_kp_u_error_while_reading_file __pyx_mstate_global->__pyx_kp_u_error_while_reading_file
#define __pyx_kp_u_error_while_reading_file_2 __pyx_mstate_global->__pyx_kp_u_error_while_reading_file_2
#define __pyx_n_s_exc_type __pyx_mstate_global->__pyx_n_s_exc_type
#define __pyx_n_s_exc_value __pyx_mstate_global->__pyx_n_s_exc_value
#define __pyx_n_s_exit __pyx_mstate_global->__pyx_n_s_exit
#define __pyx_kp_u_failure_when_setting_reference_f __pyx_mstate_global->__pyx_kp_u_failure_when_setting_reference_f
#define __pyx_n_s_fastafile __pyx_mstate_global->__pyx_n_s_fastafile
#define __pyx_n_u_fastafile __pyx_mstate_global->__pyx_n_u_fastafile
#define __pyx_n_s_fetch __pyx_mstate_global->__pyx_n_s_fetch
#define __pyx_kp_u_fetch_called_on_bamfile_without __pyx_mstate_global->__pyx_kp_u_fetch_called_on_bamfile_without
#define __pyx_kp_u_fetching_by_region_is_not_availa __pyx_mstate_global->__pyx_kp_u_fetching_by_region_is_not_availa
#define __pyx_n_s_field __pyx_mstate_global->__pyx_n_s_field
#define __pyx_n_s_fields __pyx_mstate_global->__pyx_n_s_fields
#define __pyx_kp_u_file_does_not_contain_alignment __pyx_mstate_global->__pyx_kp_u_file_does_not_contain_alignment
#define __pyx_kp_u_file_does_not_have_a_valid_heade __pyx_mstate_global->__pyx_kp_u_file_does_not_have_a_valid_heade
#define __pyx_kp_u_file_has_no_sequences_defined_mo __pyx_mstate_global->__pyx_kp_u_file_has_no_sequences_defined_mo
#define __pyx_n_s_filename __pyx_mstate_global->__pyx_n_s_filename
#define __pyx_n_u_filename __pyx_mstate_global->__pyx_n_u_filename
#define __pyx_n_u_fileno __pyx_mstate_global->__pyx_n_u_fileno
#define __pyx_n_s_filepath_index __pyx_mstate_global->__pyx_n_s_filepath_index
#define __pyx_n_s_filepath_or_object __pyx_mstate_global->__pyx_n_s_filepath_or_object
#define __pyx_n_s_filter_method __pyx_mstate_global->__pyx_n_s_filter_method
#define __pyx_n_s_find __pyx_mstate_global->__pyx_n_s_find
#define __pyx_n_s_find_introns __pyx_mstate_global->__pyx_n_s_find_introns
#define __pyx_n_s_find_introns_slow __pyx_mstate_global->__pyx_n_s_find_introns_slow
#define __pyx_n_s_flag __pyx_mstate_global->__pyx_n_s_flag
#define __pyx_n_u_flag_filter __pyx_mstate_global->__pyx_n_u_flag_filter
#define __pyx_n_u_flag_require __pyx_mstate_global->__pyx_n_u_flag_require
#define __pyx_n_s_format __pyx_mstate_global->__pyx_n_s_format
#define __pyx_n_s_format_options __pyx_mstate_global->__pyx_n_s_format_options
#define __pyx_n_s_from_dict __pyx_mstate_global->__pyx_n_s_from_dict
#define __pyx_n_s_from_references __pyx_mstate_global->__pyx_n_s_from_references
#define __pyx_n_s_from_text __pyx_mstate_global->__pyx_n_s_from_text
#define __pyx_n_s_from_text_and_lengths __pyx_mstate_global->__pyx_n_s_from_text_and_lengths
#define __pyx_kp_u_gc __pyx_mstate_global->__pyx_kp_u_gc
#define __pyx_n_s_genome_loc __pyx_mstate_global->__pyx_n_s_genome_loc
#define __pyx_n_s_genotype __pyx_mstate_global->__pyx_n_s_genotype
#define __pyx_n_s_get __pyx_mstate_global->__pyx_n_s_get
#define __pyx_n_s_get_aligned_pairs __pyx_mstate_global->__pyx_n_s_get_aligned_pairs
#define __pyx_n_s_get_index_statistics __pyx_mstate_global->__pyx_n_s_get_index_statistics
#define __pyx_n_s_get_reference_length __pyx_mstate_global->__pyx_n_s_get_reference_length
#define __pyx_n_s_get_reference_name __pyx_mstate_global->__pyx_n_s_get_reference_name
#define __pyx_n_s_get_tid __pyx_mstate_global->__pyx_n_s_get_tid
#define __pyx_n_s_getitem __pyx_mstate_global->__pyx_n_s_getitem
#define __pyx_n_s_getrname __pyx_mstate_global->__pyx_n_s_getrname
#define __pyx_n_s_getstate __pyx_mstate_global->__pyx_n_s_getstate
#define __pyx_n_s_gettid __pyx_mstate_global->__pyx_n_s_gettid
#define __pyx_n_u_h __pyx_mstate_global->__pyx_n_u_h
#define __pyx_n_s_hasReference __pyx_mstate_global->__pyx_n_s_hasReference
#define __pyx_n_s_has_coord __pyx_mstate_global->__pyx_n_s_has_coord
#define __pyx_n_s_has_index __pyx_mstate_global->__pyx_n_s_has_index
#define __pyx_n_s_has_reference __pyx_mstate_global->__pyx_n_s_has_reference
#define __pyx_n_s_hdr __pyx_mstate_global->__pyx_n_s_hdr
#define __pyx_n_s_head __pyx_mstate_global->__pyx_n_s_head
#define __pyx_n_s_header __pyx_mstate_global->__pyx_n_s_header
#define __pyx_n_s_header_dict __pyx_mstate_global->__pyx_n_s_header_dict
#define __pyx_kp_u_header_line_with_invalid_type __pyx_mstate_global->__pyx_kp_u_header_line_with_invalid_type
#define __pyx_kp_u_header_line_without_s __pyx_mstate_global->__pyx_kp_u_header_line_without_s
#define __pyx_kp_u_header_not_available_in_closed_f __pyx_mstate_global->__pyx_kp_u_header_not_available_in_closed_f
#define __pyx_n_s_idx __pyx_mstate_global->__pyx_n_s_idx
#define __pyx_n_u_ignore_orphans __pyx_mstate_global->__pyx_n_u_ignore_orphans
#define __pyx_n_u_ignore_overlaps __pyx_mstate_global->__pyx_n_u_ignore_overlaps
#define __pyx_n_s_ignore_truncation __pyx_mstate_global->__pyx_n_s_ignore_truncation
#define __pyx_n_s_import __pyx_mstate_global->__pyx_n_s_import
#define __pyx_kp_u_incomplete_sequence_information __pyx_mstate_global->__pyx_kp_u_incomplete_sequence_information
#define __pyx_n_s_index_filename __pyx_mstate_global->__pyx_n_s_index_filename
#define __pyx_n_s_init __pyx_mstate_global->__pyx_n_s_init
#define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing
#define __pyx_n_s_int_array_template __pyx_mstate_global->__pyx_n_s_int_array_template
#define __pyx_kp_u_interval_of_size_0 __pyx_mstate_global->__pyx_kp_u_interval_of_size_0
#define __pyx_kp_u_interval_of_size_less_than_0 __pyx_mstate_global->__pyx_kp_u_interval_of_size_less_than_0
#define __pyx_kp_u_invalid_file_opening_mode_s __pyx_mstate_global->__pyx_kp_u_invalid_file_opening_mode_s
#define __pyx_kp_u_invalid_type_for_record_s_s_expe __pyx_mstate_global->__pyx_kp_u_invalid_type_for_record_s_s_expe
#define __pyx_n_s_io __pyx_mstate_global->__pyx_n_s_io
#define __pyx_n_s_is_bam __pyx_mstate_global->__pyx_n_s_is_bam
#define __pyx_n_s_is_coroutine __pyx_mstate_global->__pyx_n_s_is_coroutine
#define __pyx_n_s_is_cram __pyx_mstate_global->__pyx_n_s_is_cram
#define __pyx_n_s_is_open __pyx_mstate_global->__pyx_n_s_is_open
#define __pyx_n_s_is_valid_tid __pyx_mstate_global->__pyx_n_s_is_valid_tid
#define __pyx_kp_u_isenabled __pyx_mstate_global->__pyx_kp_u_isenabled
#define __pyx_n_s_islower __pyx_mstate_global->__pyx_n_s_islower
#define __pyx_n_s_isupper __pyx_mstate_global->__pyx_n_s_isupper
#define __pyx_n_s_items __pyx_mstate_global->__pyx_n_s_items
#define __pyx_n_s_iteritems __pyx_mstate_global->__pyx_n_s_iteritems
#define __pyx_n_s_junc_start __pyx_mstate_global->__pyx_n_s_junc_start
#define __pyx_n_s_key __pyx_mstate_global->__pyx_n_s_key
#define __pyx_n_s_keys __pyx_mstate_global->__pyx_n_s_keys
#define __pyx_n_s_kwargs __pyx_mstate_global->__pyx_n_s_kwargs
#define __pyx_n_s_l_text __pyx_mstate_global->__pyx_n_s_l_text
#define __pyx_n_s_last_read_pos __pyx_mstate_global->__pyx_n_s_last_read_pos
#define __pyx_n_s_len __pyx_mstate_global->__pyx_n_s_len
#define __pyx_n_s_length __pyx_mstate_global->__pyx_n_s_length
#define __pyx_n_s_lengths __pyx_mstate_global->__pyx_n_s_lengths
#define __pyx_n_s_line __pyx_mstate_global->__pyx_n_s_line
#define __pyx_n_s_lines __pyx_mstate_global->__pyx_n_s_lines
#define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main
#define __pyx_n_s_make __pyx_mstate_global->__pyx_n_s_make
#define __pyx_kp_u_malformatted_header_no_in_field __pyx_mstate_global->__pyx_kp_u_malformatted_header_no_in_field
#define __pyx_n_s_map __pyx_mstate_global->__pyx_n_s_map
#define __pyx_n_s_mapped __pyx_mstate_global->__pyx_n_s_mapped
#define __pyx_n_u_mapped __pyx_mstate_global->__pyx_n_u_mapped
#define __pyx_kp_u_mapping_information_not_recorded __pyx_mstate_global->__pyx_kp_u_mapping_information_not_recorded
#define __pyx_n_s_mapping_quality __pyx_mstate_global->__pyx_n_s_mapping_quality
#define __pyx_n_s_match_or_deletion __pyx_mstate_global->__pyx_n_s_match_or_deletion
#define __pyx_n_s_mate __pyx_mstate_global->__pyx_n_s_mate
#define __pyx_kp_u_mate_not_found __pyx_mstate_global->__pyx_kp_u_mate_not_found
#define __pyx_kp_u_mate_s_is_unmapped __pyx_mstate_global->__pyx_kp_u_mate_s_is_unmapped
#define __pyx_n_u_max_depth __pyx_mstate_global->__pyx_n_u_max_depth
#define __pyx_n_u_min_base_quality __pyx_mstate_global->__pyx_n_u_min_base_quality
#define __pyx_n_u_min_mapping_quality __pyx_mstate_global->__pyx_n_u_min_mapping_quality
#define __pyx_n_s_mode __pyx_mstate_global->__pyx_n_s_mode
#define __pyx_n_s_multiple_iterators __pyx_mstate_global->__pyx_n_s_multiple_iterators
#define __pyx_kp_u_multiple_iterators_not_implement __pyx_mstate_global->__pyx_kp_u_multiple_iterators_not_implement
#define __pyx_kp_u_multiple_iterators_not_implement_2 __pyx_mstate_global->__pyx_kp_u_multiple_iterators_not_implement_2
#define __pyx_kp_u_multiple_s_lines_are_not_permitt __pyx_mstate_global->__pyx_kp_u_multiple_s_lines_are_not_permitt
#define __pyx_n_s_n __pyx_mstate_global->__pyx_n_s_n
#define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name
#define __pyx_n_s_name_2 __pyx_mstate_global->__pyx_n_s_name_2
#define __pyx_n_s_namedtuple __pyx_mstate_global->__pyx_n_s_namedtuple
#define __pyx_n_s_new __pyx_mstate_global->__pyx_n_s_new
#define __pyx_n_s_nextiter __pyx_mstate_global->__pyx_n_s_nextiter
#define __pyx_kp_s_no_default___reduce___due_to_non __pyx_mstate_global->__pyx_kp_s_no_default___reduce___due_to_non
#define __pyx_kp_u_no_index_available_for_fetch __pyx_mstate_global->__pyx_kp_u_no_index_available_for_fetch
#define __pyx_kp_u_no_index_available_for_iteration __pyx_mstate_global->__pyx_kp_u_no_index_available_for_iteration
#define __pyx_kp_u_no_index_available_for_pileup __pyx_mstate_global->__pyx_kp_u_no_index_available_for_pileup
#define __pyx_n_u_nofilter __pyx_mstate_global->__pyx_n_u_nofilter
#define __pyx_kp_u_not_enough_information_to_constr __pyx_mstate_global->__pyx_kp_u_not_enough_information_to_constr
#define __pyx_n_s_nreferences __pyx_mstate_global->__pyx_n_s_nreferences
#define __pyx_n_s_nt __pyx_mstate_global->__pyx_n_s_nt
#define __pyx_kp_u_number_of_reference_names_and_le __pyx_mstate_global->__pyx_kp_u_number_of_reference_names_and_le
#define __pyx_n_s_op __pyx_mstate_global->__pyx_n_s_op
#define __pyx_n_s_open __pyx_mstate_global->__pyx_n_s_open
#define __pyx_n_s_os __pyx_mstate_global->__pyx_n_s_os
#define __pyx_n_s_parse_region __pyx_mstate_global->__pyx_n_s_parse_region
#define __pyx_n_s_pickle __pyx_mstate_global->__pyx_n_s_pickle
#define __pyx_n_s_pileup __pyx_mstate_global->__pyx_n_s_pileup
#define __pyx_n_s_port __pyx_mstate_global->__pyx_n_s_port
#define __pyx_n_s_pos __pyx_mstate_global->__pyx_n_s_pos
#define __pyx_n_s_positions __pyx_mstate_global->__pyx_n_s_positions
#define __pyx_n_s_pysam_libcalignmentfile __pyx_mstate_global->__pyx_n_s_pysam_libcalignmentfile
#define __pyx_kp_s_pysam_libcalignmentfile_pyx __pyx_mstate_global->__pyx_kp_s_pysam_libcalignmentfile_pyx
#define __pyx_n_s_pyx_PickleError __pyx_mstate_global->__pyx_n_s_pyx_PickleError
#define __pyx_n_s_pyx_checksum __pyx_mstate_global->__pyx_n_s_pyx_checksum
#define __pyx_n_s_pyx_result __pyx_mstate_global->__pyx_n_s_pyx_result
#define __pyx_n_s_pyx_state __pyx_mstate_global->__pyx_n_s_pyx_state
#define __pyx_n_s_pyx_type __pyx_mstate_global->__pyx_n_s_pyx_type
#define __pyx_n_s_pyx_unpickle_SNPCall __pyx_mstate_global->__pyx_n_s_pyx_unpickle_SNPCall
#define __pyx_n_s_pyx_vtable __pyx_mstate_global->__pyx_n_s_pyx_vtable
#define __pyx_n_s_qname __pyx_mstate_global->__pyx_n_s_qname
#define __pyx_n_s_qpos __pyx_mstate_global->__pyx_n_s_qpos
#define __pyx_n_s_quality __pyx_mstate_global->__pyx_n_s_quality
#define __pyx_n_s_quality_threshold __pyx_mstate_global->__pyx_n_s_quality_threshold
#define __pyx_n_s_query_name __pyx_mstate_global->__pyx_n_s_query_name
#define __pyx_n_s_query_qualities __pyx_mstate_global->__pyx_n_s_query_qualities
#define __pyx_n_s_r __pyx_mstate_global->__pyx_n_s_r
#define __pyx_n_u_r __pyx_mstate_global->__pyx_n_u_r
#define __pyx_n_u_rU __pyx_mstate_global->__pyx_n_u_rU
#define __pyx_n_s_range __pyx_mstate_global->__pyx_n_s_range
#define __pyx_n_u_rb __pyx_mstate_global->__pyx_n_u_rb
#define __pyx_n_u_rc __pyx_mstate_global->__pyx_n_u_rc
#define __pyx_n_s_re __pyx_mstate_global->__pyx_n_s_re
#define __pyx_n_s_read __pyx_mstate_global->__pyx_n_s_read
#define __pyx_n_s_read_callback __pyx_mstate_global->__pyx_n_s_read_callback
#define __pyx_n_s_read_failure_reason __pyx_mstate_global->__pyx_n_s_read_failure_reason
#define __pyx_n_s_read_iterator __pyx_mstate_global->__pyx_n_s_read_iterator
#define __pyx_n_s_read_loc __pyx_mstate_global->__pyx_n_s_read_loc
#define __pyx_kp_u_read_s_is_unpaired __pyx_mstate_global->__pyx_kp_u_read_s_is_unpaired
#define __pyx_kp_u_read_s_not_found __pyx_mstate_global->__pyx_kp_u_read_s_not_found
#define __pyx_n_s_record __pyx_mstate_global->__pyx_n_s_record
#define __pyx_n_u_redo_baq __pyx_mstate_global->__pyx_n_u_redo_baq
#define __pyx_n_s_reduce __pyx_mstate_global->__pyx_n_s_reduce
#define __pyx_n_s_reduce_cython __pyx_mstate_global->__pyx_n_s_reduce_cython
#define __pyx_n_s_reduce_ex __pyx_mstate_global->__pyx_n_s_reduce_ex
#define __pyx_n_s_ref __pyx_mstate_global->__pyx_n_s_ref
#define __pyx_n_s_reference __pyx_mstate_global->__pyx_n_s_reference
#define __pyx_n_s_reference_base __pyx_mstate_global->__pyx_n_s_reference_base
#define __pyx_n_s_reference_filename __pyx_mstate_global->__pyx_n_s_reference_filename
#define __pyx_kp_u_reference_id_i_out_of_range_0_ti __pyx_mstate_global->__pyx_kp_u_reference_id_i_out_of_range_0_ti
#define __pyx_n_s_reference_lengths __pyx_mstate_global->__pyx_n_s_reference_lengths
#define __pyx_n_s_reference_names __pyx_mstate_global->__pyx_n_s_reference_names
#define __pyx_kp_u_reference_sequence_for_tid_not_f __pyx_mstate_global->__pyx_kp_u_reference_sequence_for_tid_not_f
#define __pyx_n_s_referencelengths __pyx_mstate_global->__pyx_n_s_referencelengths
#define __pyx_n_s_referencenames __pyx_mstate_global->__pyx_n_s_referencenames
#define __pyx_n_s_references __pyx_mstate_global->__pyx_n_s_references
#define __pyx_n_s_refpos __pyx_mstate_global->__pyx_n_s_refpos
#define __pyx_n_s_region __pyx_mstate_global->__pyx_n_s_region
#define __pyx_n_s_require_index __pyx_mstate_global->__pyx_n_s_require_index
#define __pyx_n_s_res __pyx_mstate_global->__pyx_n_s_res
#define __pyx_n_s_result __pyx_mstate_global->__pyx_n_s_result
#define __pyx_n_s_results __pyx_mstate_global->__pyx_n_s_results
#define __pyx_n_s_ret __pyx_mstate_global->__pyx_n_s_ret
#define __pyx_n_s_rstart __pyx_mstate_global->__pyx_n_s_rstart
#define __pyx_n_s_rstop __pyx_mstate_global->__pyx_n_s_rstop
#define __pyx_n_s_rtid __pyx_mstate_global->__pyx_n_s_rtid
#define __pyx_kp_u_s __pyx_mstate_global->__pyx_kp_u_s
#define __pyx_kp_u_sam_write1_failed_with_error_cod __pyx_mstate_global->__pyx_kp_u_sam_write1_failed_with_error_cod
#define __pyx_n_s_samfile __pyx_mstate_global->__pyx_n_s_samfile
#define __pyx_n_u_samtools __pyx_mstate_global->__pyx_n_u_samtools
#define __pyx_n_s_self __pyx_mstate_global->__pyx_n_s_self
#define __pyx_kp_s_self_b_self_htsfile_self_index_c __pyx_mstate_global->__pyx_kp_s_self_b_self_htsfile_self_index_c
#define __pyx_kp_s_self_b_self_htsfile_self_index_s __pyx_mstate_global->__pyx_kp_s_self_b_self_htsfile_self_index_s
#define __pyx_kp_s_self_htsfile_cannot_be_converted __pyx_mstate_global->__pyx_kp_s_self_htsfile_cannot_be_converted
#define __pyx_n_s_seq __pyx_mstate_global->__pyx_n_s_seq
#define __pyx_n_s_setstate __pyx_mstate_global->__pyx_n_s_setstate
#define __pyx_n_s_setstate_cython __pyx_mstate_global->__pyx_n_s_setstate_cython
#define __pyx_n_s_snp_quality __pyx_mstate_global->__pyx_n_s_snp_quality
#define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec
#define __pyx_n_s_split __pyx_mstate_global->__pyx_n_s_split
#define __pyx_n_s_splitlines __pyx_mstate_global->__pyx_n_s_splitlines
#define __pyx_n_s_sq __pyx_mstate_global->__pyx_n_s_sq
#define __pyx_n_s_start __pyx_mstate_global->__pyx_n_s_start
#define __pyx_n_s_start_2 __pyx_mstate_global->__pyx_n_s_start_2
#define __pyx_n_s_startswith __pyx_mstate_global->__pyx_n_s_startswith
#define __pyx_n_s_state __pyx_mstate_global->__pyx_n_s_state
#define __pyx_n_u_stepper __pyx_mstate_global->__pyx_n_u_stepper
#define __pyx_n_s_stop __pyx_mstate_global->__pyx_n_s_stop
#define __pyx_n_s_stop_2 __pyx_mstate_global->__pyx_n_s_stop_2
#define __pyx_n_s_str __pyx_mstate_global->__pyx_n_s_str
#define __pyx_kp_s_stringsource __pyx_mstate_global->__pyx_kp_s_stringsource
#define __pyx_n_s_strip __pyx_mstate_global->__pyx_n_s_strip
#define __pyx_n_s_sum __pyx_mstate_global->__pyx_n_s_sum
#define __pyx_n_s_super __pyx_mstate_global->__pyx_n_s_super
#define __pyx_n_s_t __pyx_mstate_global->__pyx_n_s_t
#define __pyx_n_s_tell __pyx_mstate_global->__pyx_n_s_tell
#define __pyx_n_s_template __pyx_mstate_global->__pyx_n_s_template
#define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test
#define __pyx_n_s_text __pyx_mstate_global->__pyx_n_s_text
#define __pyx_n_s_threads __pyx_mstate_global->__pyx_n_s_threads
#define __pyx_n_s_threshold __pyx_mstate_global->__pyx_n_s_threshold
#define __pyx_n_s_tid __pyx_mstate_global->__pyx_n_s_tid
#define __pyx_n_s_to_dict __pyx_mstate_global->__pyx_n_s_to_dict
#define __pyx_n_u_total __pyx_mstate_global->__pyx_n_u_total
#define __pyx_n_s_traceback __pyx_mstate_global->__pyx_n_s_traceback
#define __pyx_n_s_truncate __pyx_mstate_global->__pyx_n_s_truncate
#define __pyx_kp_u_truncated_file __pyx_mstate_global->__pyx_kp_u_truncated_file
#define __pyx_kp_u_unable_to_open_index_file __pyx_mstate_global->__pyx_kp_u_unable_to_open_index_file
#define __pyx_kp_u_unable_to_open_index_file_s __pyx_mstate_global->__pyx_kp_u_unable_to_open_index_file_s
#define __pyx_kp_u_unable_to_read_header_informatio __pyx_mstate_global->__pyx_kp_u_unable_to_read_header_informatio
#define __pyx_kp_u_unable_to_reopen_htsfile __pyx_mstate_global->__pyx_kp_u_unable_to_reopen_htsfile
#define __pyx_kp_u_unknown_reference __pyx_mstate_global->__pyx_kp_u_unknown_reference
#define __pyx_kp_u_unknown_stepper_option_s_in_Iter __pyx_mstate_global->__pyx_kp_u_unknown_stepper_option_s_in_Iter
#define __pyx_n_s_unmapped __pyx_mstate_global->__pyx_n_s_unmapped
#define __pyx_n_u_unmapped __pyx_mstate_global->__pyx_n_u_unmapped
#define __pyx_n_s_until_eof __pyx_mstate_global->__pyx_n_s_until_eof
#define __pyx_n_s_update __pyx_mstate_global->__pyx_n_s_update
#define __pyx_n_s_use_setstate __pyx_mstate_global->__pyx_n_s_use_setstate
#define __pyx_n_s_value __pyx_mstate_global->__pyx_n_s_value
#define __pyx_n_s_values __pyx_mstate_global->__pyx_n_s_values
#define __pyx_n_u_w __pyx_mstate_global->__pyx_n_u_w
#define __pyx_n_s_warn __pyx_mstate_global->__pyx_n_s_warn
#define __pyx_n_s_warnings __pyx_mstate_global->__pyx_n_s_warnings
#define __pyx_n_u_wb __pyx_mstate_global->__pyx_n_u_wb
#define __pyx_n_u_wb0 __pyx_mstate_global->__pyx_n_u_wb0
#define __pyx_n_u_wbu __pyx_mstate_global->__pyx_n_u_wbu
#define __pyx_n_u_wc __pyx_mstate_global->__pyx_n_u_wc
#define __pyx_n_u_wh __pyx_mstate_global->__pyx_n_u_wh
#define __pyx_n_s_write __pyx_mstate_global->__pyx_n_s_write
#define __pyx_kp_u_wrong_sequence_information_in_s __pyx_mstate_global->__pyx_kp_u_wrong_sequence_information_in_s
#define __pyx_n_s_x __pyx_mstate_global->__pyx_n_s_x
#define __pyx_n_s_y __pyx_mstate_global->__pyx_n_s_y
#define __pyx_n_s_zip __pyx_mstate_global->__pyx_n_s_zip
#define __pyx_int_0 __pyx_mstate_global->__pyx_int_0
#define __pyx_int_1 __pyx_mstate_global->__pyx_int_1
#define __pyx_int_2 __pyx_mstate_global->__pyx_int_2
#define __pyx_int_7 __pyx_mstate_global->__pyx_int_7
#define __pyx_int_8 __pyx_mstate_global->__pyx_int_8
#define __pyx_int_13 __pyx_mstate_global->__pyx_int_13
#define __pyx_int_15 __pyx_mstate_global->__pyx_int_15
#define __pyx_int_1796 __pyx_mstate_global->__pyx_int_1796
#define __pyx_int_8000 __pyx_mstate_global->__pyx_int_8000
#define __pyx_int_18041500 __pyx_mstate_global->__pyx_int_18041500
#define __pyx_int_84615809 __pyx_mstate_global->__pyx_int_84615809
#define __pyx_int_239452417 __pyx_mstate_global->__pyx_int_239452417
#define __pyx_int_neg_1 __pyx_mstate_global->__pyx_int_neg_1
#define __pyx_int_neg_2 __pyx_mstate_global->__pyx_int_neg_2
#define __pyx_k__107 __pyx_mstate_global->__pyx_k__107
#define __pyx_codeobj_ __pyx_mstate_global->__pyx_codeobj_
#define __pyx_slice__9 __pyx_mstate_global->__pyx_slice__9
#define __pyx_tuple__4 __pyx_mstate_global->__pyx_tuple__4
#define __pyx_tuple__6 __pyx_mstate_global->__pyx_tuple__6
#define __pyx_tuple__10 __pyx_mstate_global->__pyx_tuple__10
#define __pyx_tuple__14 __pyx_mstate_global->__pyx_tuple__14
#define __pyx_tuple__23 __pyx_mstate_global->__pyx_tuple__23
#define __pyx_tuple__29 __pyx_mstate_global->__pyx_tuple__29
#define __pyx_tuple__30 __pyx_mstate_global->__pyx_tuple__30
#define __pyx_tuple__40 __pyx_mstate_global->__pyx_tuple__40
#define __pyx_tuple__41 __pyx_mstate_global->__pyx_tuple__41
#define __pyx_tuple__42 __pyx_mstate_global->__pyx_tuple__42
#define __pyx_tuple__44 __pyx_mstate_global->__pyx_tuple__44
#define __pyx_tuple__45 __pyx_mstate_global->__pyx_tuple__45
#define __pyx_tuple__47 __pyx_mstate_global->__pyx_tuple__47
#define __pyx_tuple__48 __pyx_mstate_global->__pyx_tuple__48
#define __pyx_tuple__49 __pyx_mstate_global->__pyx_tuple__49
#define __pyx_tuple__50 __pyx_mstate_global->__pyx_tuple__50
#define __pyx_tuple__51 __pyx_mstate_global->__pyx_tuple__51
#define __pyx_tuple__52 __pyx_mstate_global->__pyx_tuple__52
#define __pyx_tuple__54 __pyx_mstate_global->__pyx_tuple__54
#define __pyx_tuple__55 __pyx_mstate_global->__pyx_tuple__55
#define __pyx_tuple__56 __pyx_mstate_global->__pyx_tuple__56
#define __pyx_tuple__59 __pyx_mstate_global->__pyx_tuple__59
#define __pyx_tuple__61 __pyx_mstate_global->__pyx_tuple__61
#define __pyx_tuple__64 __pyx_mstate_global->__pyx_tuple__64
#define __pyx_tuple__65 __pyx_mstate_global->__pyx_tuple__65
#define __pyx_tuple__73 __pyx_mstate_global->__pyx_tuple__73
#define __pyx_tuple__75 __pyx_mstate_global->__pyx_tuple__75
#define __pyx_tuple__83 __pyx_mstate_global->__pyx_tuple__83
#define __pyx_tuple__86 __pyx_mstate_global->__pyx_tuple__86
#define __pyx_tuple__87 __pyx_mstate_global->__pyx_tuple__87
#define __pyx_tuple__94 __pyx_mstate_global->__pyx_tuple__94
#define __pyx_codeobj__5 __pyx_mstate_global->__pyx_codeobj__5
#define __pyx_codeobj__7 __pyx_mstate_global->__pyx_codeobj__7
#define __pyx_codeobj__8 __pyx_mstate_global->__pyx_codeobj__8
#define __pyx_tuple__102 __pyx_mstate_global->__pyx_tuple__102
#define __pyx_tuple__108 __pyx_mstate_global->__pyx_tuple__108
#define __pyx_tuple__117 __pyx_mstate_global->__pyx_tuple__117
#define __pyx_tuple__123 __pyx_mstate_global->__pyx_tuple__123
#define __pyx_tuple__126 __pyx_mstate_global->__pyx_tuple__126
#define __pyx_tuple__127 __pyx_mstate_global->__pyx_tuple__127
#define __pyx_tuple__128 __pyx_mstate_global->__pyx_tuple__128
#define __pyx_tuple__129 __pyx_mstate_global->__pyx_tuple__129
#define __pyx_tuple__130 __pyx_mstate_global->__pyx_tuple__130
#define __pyx_tuple__131 __pyx_mstate_global->__pyx_tuple__131
#define __pyx_tuple__132 __pyx_mstate_global->__pyx_tuple__132
#define __pyx_tuple__133 __pyx_mstate_global->__pyx_tuple__133
#define __pyx_tuple__134 __pyx_mstate_global->__pyx_tuple__134
#define __pyx_tuple__135 __pyx_mstate_global->__pyx_tuple__135
#define __pyx_tuple__136 __pyx_mstate_global->__pyx_tuple__136
#define __pyx_tuple__137 __pyx_mstate_global->__pyx_tuple__137
#define __pyx_tuple__138 __pyx_mstate_global->__pyx_tuple__138
#define __pyx_tuple__139 __pyx_mstate_global->__pyx_tuple__139
#define __pyx_tuple__140 __pyx_mstate_global->__pyx_tuple__140
#define __pyx_tuple__141 __pyx_mstate_global->__pyx_tuple__141
#define __pyx_tuple__142 __pyx_mstate_global->__pyx_tuple__142
#define __pyx_tuple__143 __pyx_mstate_global->__pyx_tuple__143
#define __pyx_tuple__144 __pyx_mstate_global->__pyx_tuple__144
#define __pyx_tuple__145 __pyx_mstate_global->__pyx_tuple__145
#define __pyx_tuple__146 __pyx_mstate_global->__pyx_tuple__146
#define __pyx_tuple__147 __pyx_mstate_global->__pyx_tuple__147
#define __pyx_tuple__148 __pyx_mstate_global->__pyx_tuple__148
#define __pyx_tuple__149 __pyx_mstate_global->__pyx_tuple__149
#define __pyx_tuple__150 __pyx_mstate_global->__pyx_tuple__150
#define __pyx_tuple__151 __pyx_mstate_global->__pyx_tuple__151
#define __pyx_tuple__152 __pyx_mstate_global->__pyx_tuple__152
#define __pyx_tuple__153 __pyx_mstate_global->__pyx_tuple__153
#define __pyx_tuple__154 __pyx_mstate_global->__pyx_tuple__154
#define __pyx_tuple__155 __pyx_mstate_global->__pyx_tuple__155
#define __pyx_tuple__156 __pyx_mstate_global->__pyx_tuple__156
#define __pyx_tuple__157 __pyx_mstate_global->__pyx_tuple__157
#define __pyx_tuple__158 __pyx_mstate_global->__pyx_tuple__158
#define __pyx_tuple__159 __pyx_mstate_global->__pyx_tuple__159
#define __pyx_tuple__160 __pyx_mstate_global->__pyx_tuple__160
#define __pyx_tuple__161 __pyx_mstate_global->__pyx_tuple__161
#define __pyx_tuple__162 __pyx_mstate_global->__pyx_tuple__162
#define __pyx_tuple__163 __pyx_mstate_global->__pyx_tuple__163
#define __pyx_tuple__164 __pyx_mstate_global->__pyx_tuple__164
#define __pyx_tuple__165 __pyx_mstate_global->__pyx_tuple__165
#define __pyx_tuple__166 __pyx_mstate_global->__pyx_tuple__166
#define __pyx_tuple__167 __pyx_mstate_global->__pyx_tuple__167
#define __pyx_tuple__168 __pyx_mstate_global->__pyx_tuple__168
#define __pyx_tuple__169 __pyx_mstate_global->__pyx_tuple__169
#define __pyx_tuple__170 __pyx_mstate_global->__pyx_tuple__170
#define __pyx_tuple__171 __pyx_mstate_global->__pyx_tuple__171
#define __pyx_codeobj__11 __pyx_mstate_global->__pyx_codeobj__11
#define __pyx_codeobj__13 __pyx_mstate_global->__pyx_codeobj__13
#define __pyx_codeobj__16 __pyx_mstate_global->__pyx_codeobj__16
#define __pyx_codeobj__17 __pyx_mstate_global->__pyx_codeobj__17
#define __pyx_codeobj__18 __pyx_mstate_global->__pyx_codeobj__18
#define __pyx_codeobj__24 __pyx_mstate_global->__pyx_codeobj__24
#define __pyx_codeobj__25 __pyx_mstate_global->__pyx_codeobj__25
#define __pyx_codeobj__26 __pyx_mstate_global->__pyx_codeobj__26
#define __pyx_codeobj__27 __pyx_mstate_global->__pyx_codeobj__27
#define __pyx_codeobj__28 __pyx_mstate_global->__pyx_codeobj__28
#define __pyx_codeobj__31 __pyx_mstate_global->__pyx_codeobj__31
#define __pyx_codeobj__32 __pyx_mstate_global->__pyx_codeobj__32
#define __pyx_codeobj__33 __pyx_mstate_global->__pyx_codeobj__33
#define __pyx_codeobj__34 __pyx_mstate_global->__pyx_codeobj__34
#define __pyx_codeobj__35 __pyx_mstate_global->__pyx_codeobj__35
#define __pyx_codeobj__36 __pyx_mstate_global->__pyx_codeobj__36
#define __pyx_codeobj__37 __pyx_mstate_global->__pyx_codeobj__37
#define __pyx_codeobj__38 __pyx_mstate_global->__pyx_codeobj__38
#define __pyx_codeobj__39 __pyx_mstate_global->__pyx_codeobj__39
#define __pyx_codeobj__43 __pyx_mstate_global->__pyx_codeobj__43
#define __pyx_codeobj__53 __pyx_mstate_global->__pyx_codeobj__53
#define __pyx_codeobj__57 __pyx_mstate_global->__pyx_codeobj__57
#define __pyx_codeobj__58 __pyx_mstate_global->__pyx_codeobj__58
#define __pyx_codeobj__60 __pyx_mstate_global->__pyx_codeobj__60
#define __pyx_codeobj__62 __pyx_mstate_global->__pyx_codeobj__62
#define __pyx_codeobj__63 __pyx_mstate_global->__pyx_codeobj__63
#define __pyx_codeobj__66 __pyx_mstate_global->__pyx_codeobj__66
#define __pyx_codeobj__67 __pyx_mstate_global->__pyx_codeobj__67
#define __pyx_codeobj__68 __pyx_mstate_global->__pyx_codeobj__68
#define __pyx_codeobj__69 __pyx_mstate_global->__pyx_codeobj__69
#define __pyx_codeobj__70 __pyx_mstate_global->__pyx_codeobj__70
#define __pyx_codeobj__71 __pyx_mstate_global->__pyx_codeobj__71
#define __pyx_codeobj__72 __pyx_mstate_global->__pyx_codeobj__72
#define __pyx_codeobj__74 __pyx_mstate_global->__pyx_codeobj__74
#define __pyx_codeobj__76 __pyx_mstate_global->__pyx_codeobj__76
#define __pyx_codeobj__77 __pyx_mstate_global->__pyx_codeobj__77
#define __pyx_codeobj__78 __pyx_mstate_global->__pyx_codeobj__78
#define __pyx_codeobj__79 __pyx_mstate_global->__pyx_codeobj__79
#define __pyx_codeobj__80 __pyx_mstate_global->__pyx_codeobj__80
#define __pyx_codeobj__81 __pyx_mstate_global->__pyx_codeobj__81
#define __pyx_codeobj__82 __pyx_mstate_global->__pyx_codeobj__82
#define __pyx_codeobj__84 __pyx_mstate_global->__pyx_codeobj__84
#define __pyx_codeobj__85 __pyx_mstate_global->__pyx_codeobj__85
#define __pyx_codeobj__88 __pyx_mstate_global->__pyx_codeobj__88
#define __pyx_codeobj__89 __pyx_mstate_global->__pyx_codeobj__89
#define __pyx_codeobj__90 __pyx_mstate_global->__pyx_codeobj__90
#define __pyx_codeobj__91 __pyx_mstate_global->__pyx_codeobj__91
#define __pyx_codeobj__92 __pyx_mstate_global->__pyx_codeobj__92
#define __pyx_codeobj__93 __pyx_mstate_global->__pyx_codeobj__93
#define __pyx_codeobj__95 __pyx_mstate_global->__pyx_codeobj__95
#define __pyx_codeobj__96 __pyx_mstate_global->__pyx_codeobj__96
#define __pyx_codeobj__97 __pyx_mstate_global->__pyx_codeobj__97
#define __pyx_codeobj__98 __pyx_mstate_global->__pyx_codeobj__98
#define __pyx_codeobj__99 __pyx_mstate_global->__pyx_codeobj__99
#define __pyx_codeobj__100 __pyx_mstate_global->__pyx_codeobj__100
#define __pyx_codeobj__101 __pyx_mstate_global->__pyx_codeobj__101
#define __pyx_codeobj__103 __pyx_mstate_global->__pyx_codeobj__103
#define __pyx_codeobj__104 __pyx_mstate_global->__pyx_codeobj__104
#define __pyx_codeobj__105 __pyx_mstate_global->__pyx_codeobj__105
#define __pyx_codeobj__106 __pyx_mstate_global->__pyx_codeobj__106
#define __pyx_codeobj__109 __pyx_mstate_global->__pyx_codeobj__109
#define __pyx_codeobj__110 __pyx_mstate_global->__pyx_codeobj__110
#define __pyx_codeobj__111 __pyx_mstate_global->__pyx_codeobj__111
#define __pyx_codeobj__112 __pyx_mstate_global->__pyx_codeobj__112
#define __pyx_codeobj__113 __pyx_mstate_global->__pyx_codeobj__113
#define __pyx_codeobj__114 __pyx_mstate_global->__pyx_codeobj__114
#define __pyx_codeobj__115 __pyx_mstate_global->__pyx_codeobj__115
#define __pyx_codeobj__116 __pyx_mstate_global->__pyx_codeobj__116
#define __pyx_codeobj__118 __pyx_mstate_global->__pyx_codeobj__118
#define __pyx_codeobj__119 __pyx_mstate_global->__pyx_codeobj__119
#define __pyx_codeobj__120 __pyx_mstate_global->__pyx_codeobj__120
#define __pyx_codeobj__121 __pyx_mstate_global->__pyx_codeobj__121
#define __pyx_codeobj__122 __pyx_mstate_global->__pyx_codeobj__122
/* #### Code section: module_code ### */

/* "cpython/complex.pxd":19
 * 
 *         @property
 *         cdef inline double real(self) noexcept:             # <<<<<<<<<<<<<<
 *             return self.cval.real
 * 
 */

static CYTHON_INLINE double __pyx_f_7cpython_7complex_7complex_4real_real(PyComplexObject *__pyx_v_self) {
  double __pyx_r;

  /* "cpython/complex.pxd":20
 *         @property
 *         cdef inline double real(self) noexcept:
 *             return self.cval.real             # <<<<<<<<<<<<<<
 * 
 *         @property
 */
  __pyx_r = __pyx_v_self->cval.real;
  goto __pyx_L0;

  /* "cpython/complex.pxd":19
 * 
 *         @property
 *         cdef inline double real(self) noexcept:             # <<<<<<<<<<<<<<
 *             return self.cval.real
 * 
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "cpython/complex.pxd":23
 * 
 *         @property
 *         cdef inline double imag(self) noexcept:             # <<<<<<<<<<<<<<
 *             return self.cval.imag
 * 
 */

static CYTHON_INLINE double __pyx_f_7cpython_7complex_7complex_4imag_imag(PyComplexObject *__pyx_v_self) {
  double __pyx_r;

  /* "cpython/complex.pxd":24
 *         @property
 *         cdef inline double imag(self) noexcept:
 *             return self.cval.imag             # <<<<<<<<<<<<<<
 * 
 *     # PyTypeObject PyComplex_Type
 */
  __pyx_r = __pyx_v_self->cval.imag;
  goto __pyx_L0;

  /* "cpython/complex.pxd":23
 * 
 *         @property
 *         cdef inline double imag(self) noexcept:             # <<<<<<<<<<<<<<
 *             return self.cval.imag
 * 
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "cpython/contextvars.pxd":112
 * 
 * 
 * cdef inline object get_value(var, default_value=None):             # <<<<<<<<<<<<<<
 *     """Return a new reference to the value of the context variable,
 *     or the default value of the context variable,
 */

static CYTHON_INLINE PyObject *__pyx_f_7cpython_11contextvars_get_value(PyObject *__pyx_v_var, struct __pyx_opt_args_7cpython_11contextvars_get_value *__pyx_optional_args) {
  PyObject *__pyx_v_default_value = ((PyObject *)Py_None);
  PyObject *__pyx_v_value;
  PyObject *__pyx_v_pyvalue = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_value", 1);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_default_value = __pyx_optional_args->default_value;
    }
  }

  /* "cpython/contextvars.pxd":117
 *     or None if no such value or default was found.
 *     """
 *     cdef PyObject *value = NULL             # <<<<<<<<<<<<<<
 *     PyContextVar_Get(var, NULL, &value)
 *     if value is NULL:
 */
  __pyx_v_value = NULL;

  /* "cpython/contextvars.pxd":118
 *     """
 *     cdef PyObject *value = NULL
 *     PyContextVar_Get(var, NULL, &value)             # <<<<<<<<<<<<<<
 *     if value is NULL:
 *         # context variable does not have a default
 */
  __pyx_t_1 = PyContextVar_Get(__pyx_v_var, NULL, (&__pyx_v_value)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 118, __pyx_L1_error)

  /* "cpython/contextvars.pxd":119
 *     cdef PyObject *value = NULL
 *     PyContextVar_Get(var, NULL, &value)
 *     if value is NULL:             # <<<<<<<<<<<<<<
 *         # context variable does not have a default
 *         pyvalue = default_value
 */
  __pyx_t_2 = (__pyx_v_value == NULL);
  if (__pyx_t_2) {

    /* "cpython/contextvars.pxd":121
 *     if value is NULL:
 *         # context variable does not have a default
 *         pyvalue = default_value             # <<<<<<<<<<<<<<
 *     else:
 *         # value or default value of context variable
 */
    __Pyx_INCREF(__pyx_v_default_value);
    __pyx_v_pyvalue = __pyx_v_default_value;

    /* "cpython/contextvars.pxd":119
 *     cdef PyObject *value = NULL
 *     PyContextVar_Get(var, NULL, &value)
 *     if value is NULL:             # <<<<<<<<<<<<<<
 *         # context variable does not have a default
 *         pyvalue = default_value
 */
    goto __pyx_L3;
  }

  /* "cpython/contextvars.pxd":124
 *     else:
 *         # value or default value of context variable
 *         pyvalue = <object>value             # <<<<<<<<<<<<<<
 *         Py_XDECREF(value)  # PyContextVar_Get() returned an owned reference as 'PyObject*'
 *     return pyvalue
 */
  /*else*/ {
    __pyx_t_3 = ((PyObject *)__pyx_v_value);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_v_pyvalue = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "cpython/contextvars.pxd":125
 *         # value or default value of context variable
 *         pyvalue = <object>value
 *         Py_XDECREF(value)  # PyContextVar_Get() returned an owned reference as 'PyObject*'             # <<<<<<<<<<<<<<
 *     return pyvalue
 * 
 */
    Py_XDECREF(__pyx_v_value);
  }
  __pyx_L3:;

  /* "cpython/contextvars.pxd":126
 *         pyvalue = <object>value
 *         Py_XDECREF(value)  # PyContextVar_Get() returned an owned reference as 'PyObject*'
 *     return pyvalue             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_pyvalue);
  __pyx_r = __pyx_v_pyvalue;
  goto __pyx_L0;

  /* "cpython/contextvars.pxd":112
 * 
 * 
 * cdef inline object get_value(var, default_value=None):             # <<<<<<<<<<<<<<
 *     """Return a new reference to the value of the context variable,
 *     or the default value of the context variable,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cpython.contextvars.get_value", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pyvalue);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cpython/contextvars.pxd":129
 * 
 * 
 * cdef inline object get_value_no_default(var, default_value=None):             # <<<<<<<<<<<<<<
 *     """Return a new reference to the value of the context variable,
 *     or the provided default value if no such value was found.
 */

static CYTHON_INLINE PyObject *__pyx_f_7cpython_11contextvars_get_value_no_default(PyObject *__pyx_v_var, struct __pyx_opt_args_7cpython_11contextvars_get_value_no_default *__pyx_optional_args) {
  PyObject *__pyx_v_default_value = ((PyObject *)Py_None);
  PyObject *__pyx_v_value;
  PyObject *__pyx_v_pyvalue = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_value_no_default", 1);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_default_value = __pyx_optional_args->default_value;
    }
  }

  /* "cpython/contextvars.pxd":135
 *     Ignores the default value of the context variable, if any.
 *     """
 *     cdef PyObject *value = NULL             # <<<<<<<<<<<<<<
 *     PyContextVar_Get(var, <PyObject*>default_value, &value)
 *     # value of context variable or 'default_value'
 */
  __pyx_v_value = NULL;

  /* "cpython/contextvars.pxd":136
 *     """
 *     cdef PyObject *value = NULL
 *     PyContextVar_Get(var, <PyObject*>default_value, &value)             # <<<<<<<<<<<<<<
 *     # value of context variable or 'default_value'
 *     pyvalue = <object>value
 */
  __pyx_t_1 = PyContextVar_Get(__pyx_v_var, ((PyObject *)__pyx_v_default_value), (&__pyx_v_value)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(1, 136, __pyx_L1_error)

  /* "cpython/contextvars.pxd":138
 *     PyContextVar_Get(var, <PyObject*>default_value, &value)
 *     # value of context variable or 'default_value'
 *     pyvalue = <object>value             # <<<<<<<<<<<<<<
 *     Py_XDECREF(value)  # PyContextVar_Get() returned an owned reference as 'PyObject*'
 *     return pyvalue
 */
  __pyx_t_2 = ((PyObject *)__pyx_v_value);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_v_pyvalue = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cpython/contextvars.pxd":139
 *     # value of context variable or 'default_value'
 *     pyvalue = <object>value
 *     Py_XDECREF(value)  # PyContextVar_Get() returned an owned reference as 'PyObject*'             # <<<<<<<<<<<<<<
 *     return pyvalue
 */
  Py_XDECREF(__pyx_v_value);

  /* "cpython/contextvars.pxd":140
 *     pyvalue = <object>value
 *     Py_XDECREF(value)  # PyContextVar_Get() returned an owned reference as 'PyObject*'
 *     return pyvalue             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_pyvalue);
  __pyx_r = __pyx_v_pyvalue;
  goto __pyx_L0;

  /* "cpython/contextvars.pxd":129
 * 
 * 
 * cdef inline object get_value_no_default(var, default_value=None):             # <<<<<<<<<<<<<<
 *     """Return a new reference to the value of the context variable,
 *     or the provided default value if no such value was found.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("cpython.contextvars.get_value_no_default", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pyvalue);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":104
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

/* Python wrapper */
CYTHON_UNUSED static int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
CYTHON_UNUSED static int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) {
  PyObject *__pyx_v_item_count = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char *__pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  char __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  if (unlikely(__pyx_v_info == NULL)) {
    PyErr_SetString(PyExc_BufferError, "PyObject_GetBuffer: view==NULL argument is obsolete");
    return -1;
  }
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);

  /* "array.pxd":109
 *             # In particular strided access is always provided regardless
 *             # of flags
 *             item_count = Py_SIZE(self)             # <<<<<<<<<<<<<<
 * 
 *             info.suboffsets = NULL
 */
  __pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 109, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_item_count = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "array.pxd":111
 *             item_count = Py_SIZE(self)
 * 
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 */
  __pyx_v_info->suboffsets = NULL;

  /* "array.pxd":112
 * 
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars             # <<<<<<<<<<<<<<
 *             info.readonly = 0
 *             info.ndim = 1
 */
  __pyx_t_2 = __pyx_v_self->data.as_chars;
  __pyx_v_info->buf = __pyx_t_2;

  /* "array.pxd":113
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars
 *             info.readonly = 0             # <<<<<<<<<<<<<<
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 */
  __pyx_v_info->readonly = 0;

  /* "array.pxd":114
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 *             info.ndim = 1             # <<<<<<<<<<<<<<
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count
 */
  __pyx_v_info->ndim = 1;

  /* "array.pxd":115
 *             info.readonly = 0
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)             # <<<<<<<<<<<<<<
 *             info.len = info.itemsize * item_count
 * 
 */
  __pyx_t_3 = __pyx_v_self->ob_descr->itemsize;
  __pyx_v_info->itemsize = __pyx_t_3;

  /* "array.pxd":116
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count             # <<<<<<<<<<<<<<
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 */
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 116, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_info->len = __pyx_t_5;

  /* "array.pxd":118
 *             info.len = info.itemsize * item_count
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)             # <<<<<<<<<<<<<<
 *             if not info.shape:
 *                 raise MemoryError()
 */
  __pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2)));

  /* "array.pxd":119
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
  __pyx_t_6 = (!(__pyx_v_info->shape != 0));
  if (unlikely(__pyx_t_6)) {

    /* "array.pxd":120
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:
 *                 raise MemoryError()             # <<<<<<<<<<<<<<
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize
 */
    PyErr_NoMemory(); __PYX_ERR(2, 120, __pyx_L1_error)

    /* "array.pxd":119
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
  }

  /* "array.pxd":121
 *             if not info.shape:
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing             # <<<<<<<<<<<<<<
 *             info.strides = &info.itemsize
 * 
 */
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 121, __pyx_L1_error)
  (__pyx_v_info->shape[0]) = __pyx_t_5;

  /* "array.pxd":122
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize             # <<<<<<<<<<<<<<
 * 
 *             info.format = <char*> (info.shape + 1)
 */
  __pyx_v_info->strides = (&__pyx_v_info->itemsize);

  /* "array.pxd":124
 *             info.strides = &info.itemsize
 * 
 *             info.format = <char*> (info.shape + 1)             # <<<<<<<<<<<<<<
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 */
  __pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1));

  /* "array.pxd":125
 * 
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode             # <<<<<<<<<<<<<<
 *             info.format[1] = 0
 *             info.obj = self
 */
  __pyx_t_7 = __pyx_v_self->ob_descr->typecode;
  (__pyx_v_info->format[0]) = __pyx_t_7;

  /* "array.pxd":126
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0             # <<<<<<<<<<<<<<
 *             info.obj = self
 * 
 */
  (__pyx_v_info->format[1]) = 0;

  /* "array.pxd":127
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 *             info.obj = self             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 */
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self);
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj);
  __pyx_v_info->obj = ((PyObject *)__pyx_v_self);

  /* "array.pxd":104
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fulfill the PEP.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = 0;
  }
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_item_count);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":129
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

/* Python wrapper */
CYTHON_UNUSED static void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
CYTHON_UNUSED static void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) {

  /* "array.pxd":130
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 *             PyObject_Free(info.shape)             # <<<<<<<<<<<<<<
 * 
 *     array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr)
 */
  PyObject_Free(__pyx_v_info->shape);

  /* "array.pxd":129
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

  /* function exit code */
}

/* "array.pxd":141
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) {
  arrayobject *__pyx_v_op = 0;
  arrayobject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clone", 1);

  /* "array.pxd":145
 *     type will be same as template.
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)             # <<<<<<<<<<<<<<
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 */
  __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 145, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":146
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
  if (__pyx_v_zero) {
  } else {
    __pyx_t_2 = __pyx_v_zero;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "array.pxd":147
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
    (void)(memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize)));

    /* "array.pxd":146
 *     if zero is true, new array will be initialized with zeroes."""
 *     cdef array op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
  }

  /* "array.pxd":148
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline array copy(array self):
 */
  __Pyx_XDECREF((PyObject *)__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_op);
  __pyx_r = __pyx_v_op;
  goto __pyx_L0;

  /* "array.pxd":141
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_op);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":150
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) {
  arrayobject *__pyx_v_op = 0;
  arrayobject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("copy", 1);

  /* "array.pxd":152
 * cdef inline array copy(array self):
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)             # <<<<<<<<<<<<<<
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op
 */
  __pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 152, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":153
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
  (void)(memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize)));

  /* "array.pxd":154
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:
 */
  __Pyx_XDECREF((PyObject *)__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_op);
  __pyx_r = __pyx_v_op;
  goto __pyx_L0;

  /* "array.pxd":150
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     cdef array op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_op);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":156
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficient appending of new stuff of same type
 *     (e.g. of same array type)
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) {
  Py_ssize_t __pyx_v_itemsize;
  Py_ssize_t __pyx_v_origsize;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* "array.pxd":160
 *     (e.g. of same array type)
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 */
  __pyx_t_1 = __pyx_v_self->ob_descr->itemsize;
  __pyx_v_itemsize = __pyx_t_1;

  /* "array.pxd":161
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)             # <<<<<<<<<<<<<<
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 */
  __pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self));

  /* "array.pxd":162
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)             # <<<<<<<<<<<<<<
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0
 */
  __pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(2, 162, __pyx_L1_error)

  /* "array.pxd":163
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
  (void)(memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize)));

  /* "array.pxd":164
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend(array self, array other) except -1:
 */
  __pyx_r = 0;
  goto __pyx_L0;

  /* "array.pxd":156
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficient appending of new stuff of same type
 *     (e.g. of same array type)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}

/* "array.pxd":166
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) {
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* "array.pxd":168
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
  __pyx_t_1 = (__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode);
  if (__pyx_t_1) {

    /* "array.pxd":169
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()             # <<<<<<<<<<<<<<
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 */
    __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == ((int)0))) __PYX_ERR(2, 169, __pyx_L1_error)

    /* "array.pxd":168
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
  }

  /* "array.pxd":170
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))             # <<<<<<<<<<<<<<
 * 
 * cdef inline void zero(array self) noexcept:
 */
  __pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(2, 170, __pyx_L1_error)
  __pyx_r = __pyx_t_2;
  goto __pyx_L0;

  /* "array.pxd":166
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}

/* "array.pxd":172
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self) noexcept:             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) {

  /* "array.pxd":174
 * cdef inline void zero(array self) noexcept:
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 */
  (void)(memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize)));

  /* "array.pxd":172
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self) noexcept:             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

  /* function exit code */
}

/* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(fields, record):             # <<<<<<<<<<<<<<
 *     '''build a header line from `fields` dictionary for `record`'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_1build_header_line(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_build_header_line, "build_header_line(fields, record)\nbuild a header line from `fields` dictionary for `record`");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_1build_header_line = {"build_header_line", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_1build_header_line, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_build_header_line};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_1build_header_line(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_record = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[2] = {0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("build_header_line (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fields,&__pyx_n_s_record,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_fields)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 142, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_record)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 142, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("build_header_line", 1, 2, 2, 1); __PYX_ERR(0, 142, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "build_header_line") < 0)) __PYX_ERR(0, 142, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 2)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
    }
    __pyx_v_fields = values[0];
    __pyx_v_record = values[1];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("build_header_line", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 142, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.build_header_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_build_header_line(__pyx_self, __pyx_v_fields, __pyx_v_record);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_build_header_line(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record) {
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  unsigned int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  Py_UCS4 __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj_)
  __Pyx_RefNannySetupContext("build_header_line", 1);
  __Pyx_TraceCall("build_header_line", __pyx_f[0], 142, 0, __PYX_ERR(0, 142, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":146
 * 
 *     # TODO: add checking for field and sort order
 *     line = ["@%s" % record]             # <<<<<<<<<<<<<<
 *         # comment
 *     if record == "CO":
 */
  __pyx_t_1 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_s, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1)) __PYX_ERR(0, 146, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_v_line = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":148
 *     line = ["@%s" % record]
 *         # comment
 *     if record == "CO":             # <<<<<<<<<<<<<<
 *         line.append(fields)
 *     # user tags
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_record, __pyx_n_u_CO, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 148, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":149
 *         # comment
 *     if record == "CO":
 *         line.append(fields)             # <<<<<<<<<<<<<<
 *     # user tags
 *     elif record.islower():
 */
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 149, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":148
 *     line = ["@%s" % record]
 *         # comment
 *     if record == "CO":             # <<<<<<<<<<<<<<
 *         line.append(fields)
 *     # user tags
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":151
 *         line.append(fields)
 *     # user tags
 *     elif record.islower():             # <<<<<<<<<<<<<<
 *         for key in sorted(fields):
 *             line.append("%s:%s" % (key, str(fields[key])))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_record, __pyx_n_s_islower); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_6 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 151, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 151, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":152
 *     # user tags
 *     elif record.islower():
 *         for key in sorted(fields):             # <<<<<<<<<<<<<<
 *             line.append("%s:%s" % (key, str(fields[key])))
 *     # defined tags
 */
    __pyx_t_1 = PySequence_List(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_4 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 152, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1);
    __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      {
        Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
        #if !CYTHON_ASSUME_SAFE_MACROS
        if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 152, __pyx_L1_error)
        #endif
        if (__pyx_t_7 >= __pyx_temp) break;
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 152, __pyx_L1_error)
      #else
      __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":153
 *     elif record.islower():
 *         for key in sorted(fields):
 *             line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *     # defined tags
 *     else:
 */
      __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = 0;
      __pyx_t_9 = 127;
      __pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_key), __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_9;
      __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
      __pyx_t_5 = 0;
      __Pyx_INCREF(__pyx_kp_u__2);
      __pyx_t_8 += 1;
      __Pyx_GIVEREF(__pyx_kp_u__2);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u__2);
      __pyx_t_5 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyObject_Unicode(__pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_9;
      __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_10); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 153, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "pysam/libcalignmentfile.pyx":152
 *     # user tags
 *     elif record.islower():
 *         for key in sorted(fields):             # <<<<<<<<<<<<<<
 *             line.append("%s:%s" % (key, str(fields[key])))
 *     # defined tags
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":151
 *         line.append(fields)
 *     # user tags
 *     elif record.islower():             # <<<<<<<<<<<<<<
 *         for key in sorted(fields):
 *             line.append("%s:%s" % (key, str(fields[key])))
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":157
 *     else:
 *         # write fields of the specification
 *         for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
 *             if key in fields:
 *                 line.append("%s:%s" % (key, str(fields[key])))
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 157, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) {
      __pyx_t_1 = __pyx_t_10; __Pyx_INCREF(__pyx_t_1);
      __pyx_t_7 = 0;
      __pyx_t_11 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 157, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    for (;;) {
      if (likely(!__pyx_t_11)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 157, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_10 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_10); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 157, __pyx_L1_error)
          #else
          __pyx_t_10 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 157, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          #endif
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 157, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_10); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 157, __pyx_L1_error)
          #else
          __pyx_t_10 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 157, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          #endif
        }
      } else {
        __pyx_t_10 = __pyx_t_11(__pyx_t_1);
        if (unlikely(!__pyx_t_10)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 157, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_10);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_10);
      __pyx_t_10 = 0;

      /* "pysam/libcalignmentfile.pyx":158
 *         # write fields of the specification
 *         for key in VALID_HEADER_ORDER[record]:
 *             if key in fields:             # <<<<<<<<<<<<<<
 *                 line.append("%s:%s" % (key, str(fields[key])))
 *         # write user fields
 */
      __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 158, __pyx_L1_error)
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":159
 *         for key in VALID_HEADER_ORDER[record]:
 *             if key in fields:
 *                 line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *         # write user fields
 *         for key in fields:
 */
        __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_8 = 0;
        __pyx_t_9 = 127;
        __pyx_t_2 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_key), __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_9;
        __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_INCREF(__pyx_kp_u__2);
        __pyx_t_8 += 1;
        __Pyx_GIVEREF(__pyx_kp_u__2);
        PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_kp_u__2);
        __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_5 = __Pyx_PyObject_Unicode(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_9;
        __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_5);
        __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_10, 3, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_5); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 159, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "pysam/libcalignmentfile.pyx":158
 *         # write fields of the specification
 *         for key in VALID_HEADER_ORDER[record]:
 *             if key in fields:             # <<<<<<<<<<<<<<
 *                 line.append("%s:%s" % (key, str(fields[key])))
 *         # write user fields
 */
      }

      /* "pysam/libcalignmentfile.pyx":157
 *     else:
 *         # write fields of the specification
 *         for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
 *             if key in fields:
 *                 line.append("%s:%s" % (key, str(fields[key])))
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":161
 *                 line.append("%s:%s" % (key, str(fields[key])))
 *         # write user fields
 *         for key in fields:             # <<<<<<<<<<<<<<
 *             if not key.isupper():
 *                 line.append("%s:%s" % (key, str(fields[key])))
 */
    if (likely(PyList_CheckExact(__pyx_v_fields)) || PyTuple_CheckExact(__pyx_v_fields)) {
      __pyx_t_1 = __pyx_v_fields; __Pyx_INCREF(__pyx_t_1);
      __pyx_t_7 = 0;
      __pyx_t_11 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 161, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_11)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 161, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_5); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 161, __pyx_L1_error)
          #else
          __pyx_t_5 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 161, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 161, __pyx_L1_error)
            #endif
            if (__pyx_t_7 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_5); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 161, __pyx_L1_error)
          #else
          __pyx_t_5 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 161, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        }
      } else {
        __pyx_t_5 = __pyx_t_11(__pyx_t_1);
        if (unlikely(!__pyx_t_5)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 161, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":162
 *         # write user fields
 *         for key in fields:
 *             if not key.isupper():             # <<<<<<<<<<<<<<
 *                 line.append("%s:%s" % (key, str(fields[key])))
 * 
 */
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_isupper); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 162, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_2 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 162, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_12 = (!__pyx_t_3);
      if (__pyx_t_12) {

        /* "pysam/libcalignmentfile.pyx":163
 *         for key in fields:
 *             if not key.isupper():
 *                 line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 * 
 *     return "\t".join(line)
 */
        __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_8 = 0;
        __pyx_t_9 = 127;
        __pyx_t_10 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_key), __pyx_empty_unicode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_9;
        __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_10);
        __pyx_t_10 = 0;
        __Pyx_INCREF(__pyx_kp_u__2);
        __pyx_t_8 += 1;
        __Pyx_GIVEREF(__pyx_kp_u__2);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_kp_u__2);
        __pyx_t_10 = __Pyx_PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_2 = __Pyx_PyObject_Unicode(__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_9;
        __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_5, 3, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_t_2); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":162
 *         # write user fields
 *         for key in fields:
 *             if not key.isupper():             # <<<<<<<<<<<<<<
 *                 line.append("%s:%s" % (key, str(fields[key])))
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":161
 *                 line.append("%s:%s" % (key, str(fields[key])))
 *         # write user fields
 *         for key in fields:             # <<<<<<<<<<<<<<
 *             if not key.isupper():
 *                 line.append("%s:%s" % (key, str(fields[key])))
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":165
 *                 line.append("%s:%s" % (key, str(fields[key])))
 * 
 *     return "\t".join(line)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyUnicode_Join(__pyx_kp_u__3, __pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 165, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(fields, record):             # <<<<<<<<<<<<<<
 *     '''build a header line from `fields` dictionary for `record`'''
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.libcalignmentfile.build_header_line", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":168
 * 
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):             # <<<<<<<<<<<<<<
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 */

static struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_t *__pyx_v_hdr) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_header = 0;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("makeAlignmentHeader", 1);
  __Pyx_TraceCall("makeAlignmentHeader", __pyx_f[0], 168, 0, __PYX_ERR(0, 168, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":169
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:             # <<<<<<<<<<<<<<
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 * 
 */
  __pyx_t_1 = (!(__pyx_v_hdr != 0));
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":170
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')             # <<<<<<<<<<<<<<
 * 
 *     # check: is AlignmetHeader.__cinit__ called?
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 170, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 170, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":169
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:             # <<<<<<<<<<<<<<
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":173
 * 
 *     # check: is AlignmetHeader.__cinit__ called?
 *     cdef AlignmentHeader header = AlignmentHeader.__new__(AlignmentHeader)             # <<<<<<<<<<<<<<
 *     header.ptr = hdr
 * 
 */
  __pyx_t_2 = ((PyObject *)__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(((PyTypeObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_empty_tuple, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __pyx_L1_error)
  __Pyx_GOTREF((PyObject *)__pyx_t_2);
  __pyx_v_header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":174
 *     # check: is AlignmetHeader.__cinit__ called?
 *     cdef AlignmentHeader header = AlignmentHeader.__new__(AlignmentHeader)
 *     header.ptr = hdr             # <<<<<<<<<<<<<<
 * 
 *     return header
 */
  __pyx_v_header->ptr = __pyx_v_hdr;

  /* "pysam/libcalignmentfile.pyx":176
 *     header.ptr = hdr
 * 
 *     return header             # <<<<<<<<<<<<<<
 * 
 * def read_failure_reason(code):
 */
  __Pyx_XDECREF((PyObject *)__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_header);
  __pyx_r = __pyx_v_header;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":168
 * 
 * 
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):             # <<<<<<<<<<<<<<
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.makeAlignmentHeader", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_header);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_3read_failure_reason(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_2read_failure_reason, "read_failure_reason(code)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_3read_failure_reason = {"read_failure_reason", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_3read_failure_reason, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_2read_failure_reason};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_3read_failure_reason(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_code = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("read_failure_reason (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_code,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_code)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 178, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "read_failure_reason") < 0)) __PYX_ERR(0, 178, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_code = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("read_failure_reason", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 178, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.read_failure_reason", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_2read_failure_reason(__pyx_self, __pyx_v_code);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_2read_failure_reason(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_code) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__5)
  __Pyx_RefNannySetupContext("read_failure_reason", 1);
  __Pyx_TraceCall("read_failure_reason", __pyx_f[0], 178, 0, __PYX_ERR(0, 178, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":179
 * 
 * def read_failure_reason(code):
 *     if code == -2:             # <<<<<<<<<<<<<<
 *         return 'truncated file'
 *     else:
 */
  __pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_code, __pyx_int_neg_2, -2L, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 179, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":180
 * def read_failure_reason(code):
 *     if code == -2:
 *         return 'truncated file'             # <<<<<<<<<<<<<<
 *     else:
 *         return "error {} while reading file".format(code)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_kp_u_truncated_file);
    __pyx_r = __pyx_kp_u_truncated_file;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":179
 * 
 * def read_failure_reason(code):
 *     if code == -2:             # <<<<<<<<<<<<<<
 *         return 'truncated file'
 *     else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":182
 *         return 'truncated file'
 *     else:
 *         return "error {} while reading file".format(code)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_error_while_reading_file, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 182, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    __pyx_t_5 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_5 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_code};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 182, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.read_failure_reason", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":187
 * # the following should be class-method for VariantHeader, but cdef @classmethods
 * # are not implemented in cython.
 * cdef int fill_AlignmentHeader_from_list(bam_hdr_t *dest,             # <<<<<<<<<<<<<<
 *                                         reference_names,
 *                                         reference_lengths,
 */

static int __pyx_f_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list(CYTHON_UNUSED bam_hdr_t *__pyx_v_dest, CYTHON_UNUSED PyObject *__pyx_v_reference_names, CYTHON_UNUSED PyObject *__pyx_v_reference_lengths, struct __pyx_opt_args_5pysam_17libcalignmentfile_fill_AlignmentHeader_from_list *__pyx_optional_args) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("fill_AlignmentHeader_from_list", __pyx_f[0], 187, 0, __PYX_ERR(0, 187, __pyx_L1_error));
  if (__pyx_optional_args) {
  }

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.fill_AlignmentHeader_from_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":228
 * 
 *     # See makeVariantHeader for C constructor
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = NULL
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, __pyx_nargs); return -1;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_VARARGS(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 228, 0, __PYX_ERR(0, 228, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":229
 *     # See makeVariantHeader for C constructor
 *     def __cinit__(self):
 *         self.ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     # Python constructor
 */
  __pyx_v_self->ptr = NULL;

  /* "pysam/libcalignmentfile.pyx":228
 * 
 *     # See makeVariantHeader for C constructor
 *     def __cinit__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = NULL
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":232
 * 
 *     # Python constructor
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, __pyx_nargs); return -1;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_VARARGS(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_2__init__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 232, 0, __PYX_ERR(0, 232, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":233
 *     # Python constructor
 *     def __init__(self):
 *         self.ptr = bam_hdr_init()             # <<<<<<<<<<<<<<
 *         if self.ptr is NULL:
 *             raise MemoryError("could not create header")
 */
  __pyx_v_self->ptr = bam_hdr_init();

  /* "pysam/libcalignmentfile.pyx":234
 *     def __init__(self):
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not create header")
 * 
 */
  __pyx_t_1 = (__pyx_v_self->ptr == NULL);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":235
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 *             raise MemoryError("could not create header")             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 235, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":234
 *     def __init__(self):
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not create header")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":232
 * 
 *     # Python constructor
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":237
 *             raise MemoryError("could not create header")
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths, "AlignmentHeader._from_text_and_lengths(cls, text, reference_names, reference_lengths)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths = {"_from_text_and_lengths", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_text = 0;
  PyObject *__pyx_v_reference_names = 0;
  PyObject *__pyx_v_reference_lengths = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[3] = {0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_from_text_and_lengths (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_text,&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_text)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 237, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference_names)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 237, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, 1); __PYX_ERR(0, 237, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference_lengths)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[2]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 237, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, 2); __PYX_ERR(0, 237, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_from_text_and_lengths") < 0)) __PYX_ERR(0, 237, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 3)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
      values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
    }
    __pyx_v_text = values[0];
    __pyx_v_reference_names = values[1];
    __pyx_v_reference_lengths = values[2];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_from_text_and_lengths", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 237, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._from_text_and_lengths", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(((PyTypeObject*)__pyx_v_cls), __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self = 0;
  char *__pyx_v_ctext;
  int __pyx_v_l_text;
  int __pyx_v_n;
  int __pyx_v_x;
  PyObject *__pyx_v_btext = NULL;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_7genexpr__pyx_v_ref = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  char *__pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  unsigned int __pyx_t_8;
  int __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  int32_t __pyx_t_13;
  uint32_t __pyx_t_14;
  char const *__pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__7)
  __Pyx_RefNannySetupContext("_from_text_and_lengths", 0);
  __Pyx_TraceCall("_from_text_and_lengths", __pyx_f[0], 237, 0, __PYX_ERR(0, 237, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_reference_names);

  /* "pysam/libcalignmentfile.pyx":240
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):
 * 
 *         cdef AlignmentHeader self = AlignmentHeader()             # <<<<<<<<<<<<<<
 *         cdef char *ctext
 *         cdef int l_text
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_self = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":244
 *         cdef int l_text
 *         cdef int n, x
 *         if text is not None:             # <<<<<<<<<<<<<<
 *             btext = force_bytes(text)
 *             ctext = btext
 */
  __pyx_t_2 = (__pyx_v_text != Py_None);
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":245
 *         cdef int n, x
 *         if text is not None:
 *             btext = force_bytes(text)             # <<<<<<<<<<<<<<
 *             ctext = btext
 *             l_text = len(btext)
 */
    __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_text, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_btext = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":246
 *         if text is not None:
 *             btext = force_bytes(text)
 *             ctext = btext             # <<<<<<<<<<<<<<
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 */
    if (unlikely(__pyx_v_btext == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
      __PYX_ERR(0, 246, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyBytes_AsWritableString(__pyx_v_btext); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 246, __pyx_L1_error)
    __pyx_v_ctext = __pyx_t_3;

    /* "pysam/libcalignmentfile.pyx":247
 *             btext = force_bytes(text)
 *             ctext = btext
 *             l_text = len(btext)             # <<<<<<<<<<<<<<
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:
 */
    if (unlikely(__pyx_v_btext == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 247, __pyx_L1_error)
    }
    __pyx_t_4 = __Pyx_PyBytes_GET_SIZE(__pyx_v_btext); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 247, __pyx_L1_error)
    __pyx_v_l_text = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":248
 *             ctext = btext
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))             # <<<<<<<<<<<<<<
 *             if self.ptr.text == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 */
    __pyx_v_self->ptr->text = ((char *)calloc((__pyx_v_l_text + 1), (sizeof(char))));

    /* "pysam/libcalignmentfile.pyx":249
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text
 */
    __pyx_t_2 = (__pyx_v_self->ptr->text == NULL);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":250
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))             # <<<<<<<<<<<<<<
 *             self.ptr.l_text = l_text
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyInt_From_long((__pyx_v_l_text + 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = NULL;
      __pyx_t_8 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_8 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_6};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 250, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __pyx_t_5 = __Pyx_PyInt_FromSize_t((sizeof(char))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_1);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1)) __PYX_ERR(0, 250, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_5);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error);
      __pyx_t_1 = 0;
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 250, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 250, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":249
 *             l_text = len(btext)
 *             self.ptr.text = <char*>calloc(l_text + 1, sizeof(char))
 *             if self.ptr.text == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text
 */
    }

    /* "pysam/libcalignmentfile.pyx":251
 *             if self.ptr.text == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text             # <<<<<<<<<<<<<<
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 * 
 */
    __pyx_v_self->ptr->l_text = __pyx_v_l_text;

    /* "pysam/libcalignmentfile.pyx":252
 *                 raise MemoryError("could not allocate {} bytes".format(l_text + 1), sizeof(char))
 *             self.ptr.l_text = l_text
 *             memcpy(self.ptr.text, ctext, l_text + 1)             # <<<<<<<<<<<<<<
 * 
 *         if reference_names and reference_lengths:
 */
    (void)(memcpy(__pyx_v_self->ptr->text, __pyx_v_ctext, (__pyx_v_l_text + 1)));

    /* "pysam/libcalignmentfile.pyx":244
 *         cdef int l_text
 *         cdef int n, x
 *         if text is not None:             # <<<<<<<<<<<<<<
 *             btext = force_bytes(text)
 *             ctext = btext
 */
  }

  /* "pysam/libcalignmentfile.pyx":254
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 * 
 *         if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *             reference_names = [force_bytes(ref) for ref in reference_names]
 * 
 */
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 254, __pyx_L1_error)
  if (__pyx_t_9) {
  } else {
    __pyx_t_2 = __pyx_t_9;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 254, __pyx_L1_error)
  __pyx_t_2 = __pyx_t_9;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":255
 * 
 *         if reference_names and reference_lengths:
 *             reference_names = [force_bytes(ref) for ref in reference_names]             # <<<<<<<<<<<<<<
 * 
 *             self.ptr.n_targets = len(reference_names)
 */
    { /* enter inner scope */
      __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 255, __pyx_L10_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (likely(PyList_CheckExact(__pyx_v_reference_names)) || PyTuple_CheckExact(__pyx_v_reference_names)) {
        __pyx_t_6 = __pyx_v_reference_names; __Pyx_INCREF(__pyx_t_6);
        __pyx_t_4 = 0;
        __pyx_t_10 = NULL;
      } else {
        __pyx_t_4 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_v_reference_names); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 255, __pyx_L10_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_10 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_6); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 255, __pyx_L10_error)
      }
      for (;;) {
        if (likely(!__pyx_t_10)) {
          if (likely(PyList_CheckExact(__pyx_t_6))) {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_6);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 255, __pyx_L10_error)
              #endif
              if (__pyx_t_4 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_1 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely((0 < 0))) __PYX_ERR(0, 255, __pyx_L10_error)
            #else
            __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_6, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          } else {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_6);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 255, __pyx_L10_error)
              #endif
              if (__pyx_t_4 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely((0 < 0))) __PYX_ERR(0, 255, __pyx_L10_error)
            #else
            __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_6, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L10_error)
            __Pyx_GOTREF(__pyx_t_1);
            #endif
          }
        } else {
          __pyx_t_1 = __pyx_t_10(__pyx_t_6);
          if (unlikely(!__pyx_t_1)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 255, __pyx_L10_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_1);
        }
        __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_ref, __pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_7genexpr__pyx_v_ref, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 255, __pyx_L10_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 255, __pyx_L10_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_7genexpr__pyx_v_ref); __pyx_7genexpr__pyx_v_ref = 0;
      goto __pyx_L14_exit_scope;
      __pyx_L10_error:;
      __Pyx_XDECREF(__pyx_7genexpr__pyx_v_ref); __pyx_7genexpr__pyx_v_ref = 0;
      goto __pyx_L1_error;
      __pyx_L14_exit_scope:;
    } /* exit inner scope */
    __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":257
 *             reference_names = [force_bytes(ref) for ref in reference_names]
 * 
 *             self.ptr.n_targets = len(reference_names)             # <<<<<<<<<<<<<<
 * 
 *             n = sum([len(reference_names) + 1])
 */
    __pyx_t_4 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 257, __pyx_L1_error)
    __pyx_v_self->ptr->n_targets = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":259
 *             self.ptr.n_targets = len(reference_names)
 * 
 *             n = sum([len(reference_names) + 1])             # <<<<<<<<<<<<<<
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:
 */
    __pyx_t_4 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 259, __pyx_L1_error)
    __pyx_t_5 = PyInt_FromSsize_t((__pyx_t_4 + 1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyList_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_5);
    if (__Pyx_PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_n = __pyx_t_11;

    /* "pysam/libcalignmentfile.pyx":260
 * 
 *             n = sum([len(reference_names) + 1])
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))             # <<<<<<<<<<<<<<
 *             if self.ptr.target_name == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 */
    __pyx_v_self->ptr->target_name = ((char **)calloc(__pyx_v_n, (sizeof(char *))));

    /* "pysam/libcalignmentfile.pyx":261
 *             n = sum([len(reference_names) + 1])
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 * 
 */
    __pyx_t_2 = (__pyx_v_self->ptr->target_name == NULL);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":262
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))             # <<<<<<<<<<<<<<
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyInt_FromSize_t((sizeof(char *))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_12 = NULL;
      __pyx_t_8 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_8 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_12, __pyx_t_1, __pyx_t_7};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 2+__pyx_t_8);
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 262, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(0, 262, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":261
 *             n = sum([len(reference_names) + 1])
 *             self.ptr.target_name = <char**>calloc(n, sizeof(char*))
 *             if self.ptr.target_name == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":264
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(char *)))
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))             # <<<<<<<<<<<<<<
 *             if self.ptr.target_len == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 */
    __pyx_v_self->ptr->target_len = ((uint32_t *)calloc(__pyx_v_n, (sizeof(uint32_t))));

    /* "pysam/libcalignmentfile.pyx":265
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *             if self.ptr.target_len == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 * 
 */
    __pyx_t_2 = (__pyx_v_self->ptr->target_len == NULL);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":266
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *             if self.ptr.target_len == NULL:
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))             # <<<<<<<<<<<<<<
 * 
 *             for x from 0 <= x < self.ptr.n_targets:
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyInt_FromSize_t((sizeof(uint32_t))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_12 = NULL;
      __pyx_t_8 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_8 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_12, __pyx_t_7, __pyx_t_1};
        __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_8, 2+__pyx_t_8);
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 266, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 266, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 266, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":265
 * 
 *             self.ptr.target_len = <uint32_t*>calloc(n, sizeof(uint32_t))
 *             if self.ptr.target_len == NULL:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":268
 *                 raise MemoryError("could not allocate {} bytes".format(n, sizeof(uint32_t)))
 * 
 *             for x from 0 <= x < self.ptr.n_targets:             # <<<<<<<<<<<<<<
 *                 self.ptr.target_len[x] = reference_lengths[x]
 *                 name = reference_names[x]
 */
    __pyx_t_13 = __pyx_v_self->ptr->n_targets;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_13; __pyx_v_x++) {

      /* "pysam/libcalignmentfile.pyx":269
 * 
 *             for x from 0 <= x < self.ptr.n_targets:
 *                 self.ptr.target_len[x] = reference_lengths[x]             # <<<<<<<<<<<<<<
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 */
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_reference_lengths, __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_14 = __Pyx_PyInt_As_uint32_t(__pyx_t_5); if (unlikely((__pyx_t_14 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      (__pyx_v_self->ptr->target_len[__pyx_v_x]) = __pyx_t_14;

      /* "pysam/libcalignmentfile.pyx":270
 *             for x from 0 <= x < self.ptr.n_targets:
 *                 self.ptr.target_len[x] = reference_lengths[x]
 *                 name = reference_names[x]             # <<<<<<<<<<<<<<
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:
 */
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_reference_names, __pyx_v_x, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":271
 *                 self.ptr.target_len[x] = reference_lengths[x]
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))             # <<<<<<<<<<<<<<
 *                 if self.ptr.target_name[x] == NULL:
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 */
      __pyx_t_4 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 271, __pyx_L1_error)
      (__pyx_v_self->ptr->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_4 + 1), (sizeof(char))));

      /* "pysam/libcalignmentfile.pyx":272
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:             # <<<<<<<<<<<<<<
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 */
      __pyx_t_2 = ((__pyx_v_self->ptr->target_name[__pyx_v_x]) == NULL);
      if (unlikely(__pyx_t_2)) {

        /* "pysam/libcalignmentfile.pyx":273
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))             # <<<<<<<<<<<<<<
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 * 
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 273, __pyx_L1_error)
        __pyx_t_1 = PyInt_FromSsize_t((__pyx_t_4 + 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = __Pyx_PyInt_FromSize_t((sizeof(char))); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_12 = NULL;
        __pyx_t_8 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_12)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_12);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_8 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[3] = {__pyx_t_12, __pyx_t_1, __pyx_t_7};
          __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 2+__pyx_t_8);
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 273, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 273, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_Raise(__pyx_t_6, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __PYX_ERR(0, 273, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":272
 *                 name = reference_names[x]
 *                 self.ptr.target_name[x] = <char*>calloc(len(name) + 1, sizeof(char))
 *                 if self.ptr.target_name[x] == NULL:             # <<<<<<<<<<<<<<
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 */
      }

      /* "pysam/libcalignmentfile.pyx":274
 *                 if self.ptr.target_name[x] == NULL:
 *                     raise MemoryError("could not allocate {} bytes".format(len(name) + 1, sizeof(char)))
 *                 strncpy(self.ptr.target_name[x], name, len(name))             # <<<<<<<<<<<<<<
 * 
 *         return self
 */
      __pyx_t_15 = __Pyx_PyObject_AsString(__pyx_v_name); if (unlikely((!__pyx_t_15) && PyErr_Occurred())) __PYX_ERR(0, 274, __pyx_L1_error)
      __pyx_t_4 = PyObject_Length(__pyx_v_name); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 274, __pyx_L1_error)
      (void)(strncpy((__pyx_v_self->ptr->target_name[__pyx_v_x]), __pyx_t_15, __pyx_t_4));
    }

    /* "pysam/libcalignmentfile.pyx":254
 *             memcpy(self.ptr.text, ctext, l_text + 1)
 * 
 *         if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *             reference_names = [force_bytes(ref) for ref in reference_names]
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":276
 *                 strncpy(self.ptr.target_name[x], name, len(name))
 * 
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":237
 *             raise MemoryError("could not create header")
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._from_text_and_lengths", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_self);
  __Pyx_XDECREF(__pyx_v_btext);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_ref);
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":278
 *         return self
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_text(cls, text):
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text, "AlignmentHeader.from_text(cls, text)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text = {"from_text", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_text = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_text (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_text,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_text)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 278, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "from_text") < 0)) __PYX_ERR(0, 278, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_text = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_text", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 278, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(((PyTypeObject*)__pyx_v_cls), __pyx_v_text);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_text) {
  PyObject *__pyx_v_reference_names = NULL;
  PyObject *__pyx_v_reference_lengths = NULL;
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_8genexpr1__pyx_v_x = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  Py_ssize_t __pyx_t_10;
  PyObject *(*__pyx_t_11)(PyObject *);
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  int __pyx_t_15;
  int __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__8)
  __Pyx_RefNannySetupContext("from_text", 1);
  __Pyx_TraceCall("from_text", __pyx_f[0], 278, 0, __PYX_ERR(0, 278, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":281
 *     def from_text(cls, text):
 * 
 *         reference_names, reference_lengths = [], []             # <<<<<<<<<<<<<<
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 281, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_reference_names = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_reference_lengths = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":282
 * 
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():             # <<<<<<<<<<<<<<
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_text, __pyx_n_s_splitlines); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 282, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 282, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 282, __pyx_L1_error)
        #else
        __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 282, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 282, __pyx_L1_error)
        #else
        __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 282, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":283
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):             # <<<<<<<<<<<<<<
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 283, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_u_SQ};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 283, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_8) {

      /* "pysam/libcalignmentfile.pyx":284
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
      { /* enter inner scope */
        __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_split); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 284, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_9 = NULL;
        __pyx_t_4 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
            __pyx_t_4 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_kp_u__3};
          __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_t_3, 1, 0, NULL, NULL, &__pyx_slice__9, 1, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 284, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
          __pyx_t_3 = __pyx_t_7; __Pyx_INCREF(__pyx_t_3);
          __pyx_t_10 = 0;
          __pyx_t_11 = NULL;
        } else {
          __pyx_t_10 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 284, __pyx_L8_error)
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        for (;;) {
          if (likely(!__pyx_t_11)) {
            if (likely(PyList_CheckExact(__pyx_t_3))) {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_3);
                #if !CYTHON_ASSUME_SAFE_MACROS
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 284, __pyx_L8_error)
                #endif
                if (__pyx_t_10 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_7); __pyx_t_10++; if (unlikely((0 < 0))) __PYX_ERR(0, 284, __pyx_L8_error)
              #else
              __pyx_t_7 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 284, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_7);
              #endif
            } else {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_3);
                #if !CYTHON_ASSUME_SAFE_MACROS
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 284, __pyx_L8_error)
                #endif
                if (__pyx_t_10 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_7); __pyx_t_10++; if (unlikely((0 < 0))) __PYX_ERR(0, 284, __pyx_L8_error)
              #else
              __pyx_t_7 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 284, __pyx_L8_error)
              __Pyx_GOTREF(__pyx_t_7);
              #endif
            }
          } else {
            __pyx_t_7 = __pyx_t_11(__pyx_t_3);
            if (unlikely(!__pyx_t_7)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 284, __pyx_L8_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_7);
          }
          __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_x, __pyx_t_7);
          __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_8genexpr1__pyx_v_x, __pyx_n_s_split); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 284, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 284, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 284, __pyx_L8_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_x); __pyx_8genexpr1__pyx_v_x = 0;
        goto __pyx_L12_exit_scope;
        __pyx_L8_error:;
        __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_x); __pyx_8genexpr1__pyx_v_x = 0;
        goto __pyx_L1_error;
        __pyx_L12_exit_scope:;
      } /* exit inner scope */
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyDict_Type)), __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "pysam/libcalignmentfile.pyx":285
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_13, &__pyx_t_14);
        __Pyx_XGOTREF(__pyx_t_12);
        __Pyx_XGOTREF(__pyx_t_13);
        __Pyx_XGOTREF(__pyx_t_14);
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":286
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:
 *                     reference_names.append(fields["SN"])             # <<<<<<<<<<<<<<
 *                     reference_lengths.append(int(fields["LN"]))
 *                 except KeyError:
 */
          __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_fields, __pyx_n_u_SN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 286, __pyx_L13_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_15 = __Pyx_PyList_Append(__pyx_v_reference_names, __pyx_t_3); if (unlikely(__pyx_t_15 == ((int)-1))) __PYX_ERR(0, 286, __pyx_L13_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pysam/libcalignmentfile.pyx":287
 *                 try:
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 */
          __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_fields, __pyx_n_u_LN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __pyx_L13_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L13_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_15 = __Pyx_PyList_Append(__pyx_v_reference_lengths, __pyx_t_2); if (unlikely(__pyx_t_15 == ((int)-1))) __PYX_ERR(0, 287, __pyx_L13_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "pysam/libcalignmentfile.pyx":285
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 */
        }
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L20_try_end;
        __pyx_L13_error:;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "pysam/libcalignmentfile.pyx":288
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 *                 except ValueError:
 */
        __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_16) {
          __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_9) < 0) __PYX_ERR(0, 288, __pyx_L15_except_error)
          __Pyx_XGOTREF(__pyx_t_2);
          __Pyx_XGOTREF(__pyx_t_3);
          __Pyx_XGOTREF(__pyx_t_9);

          /* "pysam/libcalignmentfile.pyx":289
 *                     reference_lengths.append(int(fields["LN"]))
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 *                 except ValueError:
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))
 */
          __pyx_t_7 = __Pyx_PyObject_Unicode(__pyx_v_fields); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 289, __pyx_L15_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_17 = PyUnicode_Format(__pyx_kp_u_incomplete_sequence_information, __pyx_t_7); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 289, __pyx_L15_except_error)
          __Pyx_GOTREF(__pyx_t_17);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_17); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 289, __pyx_L15_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
          __Pyx_Raise(__pyx_t_7, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __PYX_ERR(0, 289, __pyx_L15_except_error)
        }

        /* "pysam/libcalignmentfile.pyx":290
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 *                 except ValueError:             # <<<<<<<<<<<<<<
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))
 * 
 */
        __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError);
        if (__pyx_t_16) {
          __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_9, &__pyx_t_3, &__pyx_t_2) < 0) __PYX_ERR(0, 290, __pyx_L15_except_error)
          __Pyx_XGOTREF(__pyx_t_9);
          __Pyx_XGOTREF(__pyx_t_3);
          __Pyx_XGOTREF(__pyx_t_2);

          /* "pysam/libcalignmentfile.pyx":291
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 *                 except ValueError:
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 */
          __pyx_t_7 = __Pyx_PyObject_Unicode(__pyx_v_fields); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 291, __pyx_L15_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_17 = PyUnicode_Format(__pyx_kp_u_wrong_sequence_information_in_s, __pyx_t_7); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 291, __pyx_L15_except_error)
          __Pyx_GOTREF(__pyx_t_17);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_17); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 291, __pyx_L15_except_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
          __Pyx_Raise(__pyx_t_7, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __PYX_ERR(0, 291, __pyx_L15_except_error)
        }
        goto __pyx_L15_except_error;

        /* "pysam/libcalignmentfile.pyx":285
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(int(fields["LN"]))
 */
        __pyx_L15_except_error:;
        __Pyx_XGIVEREF(__pyx_t_12);
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_13, __pyx_t_14);
        goto __pyx_L1_error;
        __pyx_L20_try_end:;
      }

      /* "pysam/libcalignmentfile.pyx":283
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):             # <<<<<<<<<<<<<<
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 *                 try:
 */
    }

    /* "pysam/libcalignmentfile.pyx":282
 * 
 *         reference_names, reference_lengths = [], []
 *         for line in text.splitlines():             # <<<<<<<<<<<<<<
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":293
 *                     raise ValueError("wrong sequence information in '%s'" % str(fields))
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[4] = {__pyx_t_3, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 3+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":278
 *         return self
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_text(cls, text):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_text", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XDECREF(__pyx_v_reference_lengths);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_8genexpr1__pyx_v_x);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":295
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_dict(cls, header_dict):
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict, "AlignmentHeader.from_dict(cls, header_dict)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict = {"from_dict", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_header_dict = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_dict (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_header_dict,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_header_dict)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 295, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "from_dict") < 0)) __PYX_ERR(0, 295, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_header_dict = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_dict", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 295, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(((PyTypeObject*)__pyx_v_cls), __pyx_v_header_dict);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_header_dict) {
  PyObject *__pyx_v_lines = 0;
  PyObject *__pyx_v_record = NULL;
  PyObject *__pyx_v_data = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_v_reference_names = NULL;
  PyObject *__pyx_v_reference_lengths = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  unsigned int __pyx_t_10;
  int __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_t_18;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__11)
  __Pyx_RefNannySetupContext("from_dict", 1);
  __Pyx_TraceCall("from_dict", __pyx_f[0], 295, 0, __PYX_ERR(0, 295, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":298
 *     def from_dict(cls, header_dict):
 * 
 *         cdef list lines = []             # <<<<<<<<<<<<<<
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 298, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_lines = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":300
 *         cdef list lines = []
 *         # first: defined tags
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in header_dict:
 *                 data = header_dict[record]
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 300, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 300, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 300, __pyx_L1_error)
          #endif
          if (__pyx_t_3 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely((0 < 0))) __PYX_ERR(0, 300, __pyx_L1_error)
        #else
        __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 300, __pyx_L1_error)
          #endif
          if (__pyx_t_3 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely((0 < 0))) __PYX_ERR(0, 300, __pyx_L1_error)
        #else
        __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 300, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 300, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":301
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 *             if record in header_dict:             # <<<<<<<<<<<<<<
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 */
    __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_header_dict, Py_EQ)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 301, __pyx_L1_error)
    if (__pyx_t_5) {

      /* "pysam/libcalignmentfile.pyx":302
 *         for record in VALID_HEADERS:
 *             if record in header_dict:
 *                 data = header_dict[record]             # <<<<<<<<<<<<<<
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 *                     raise ValueError(
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 302, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":303
 *             if record in header_dict:
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_5 = PyObject_IsInstance(__pyx_v_data, __pyx_t_6); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 303, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = (!__pyx_t_5);
      if (unlikely(__pyx_t_7)) {

        /* "pysam/libcalignmentfile.pyx":305
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(             # <<<<<<<<<<<<<<
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_invalid_type_for_record_s_s_expe, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 305, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);

        /* "pysam/libcalignmentfile.pyx":306
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))             # <<<<<<<<<<<<<<
 *                 if isinstance(data, Mapping):
 *                     lines.append(build_header_line(data, record))
 */
        __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 306, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = __Pyx_PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 306, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = NULL;
        __pyx_t_10 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
            __pyx_t_10 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[4] = {__pyx_t_8, __pyx_v_record, ((PyObject *)Py_TYPE(__pyx_v_data)), __pyx_t_9};
          __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_10, 3+__pyx_t_10);
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 305, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        }

        /* "pysam/libcalignmentfile.pyx":304
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 */
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 304, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __PYX_ERR(0, 304, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":303
 *             if record in header_dict:
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s".format(
 */
      }

      /* "pysam/libcalignmentfile.pyx":307
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(data, record))
 *                 else:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyObject_IsInstance(__pyx_v_data, __pyx_t_1); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 307, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_7) {

        /* "pysam/libcalignmentfile.pyx":308
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):
 *                     lines.append(build_header_line(data, record))             # <<<<<<<<<<<<<<
 *                 else:
 *                     for fields in header_dict[record]:
 */
        __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_9 = NULL;
        __pyx_t_10 = 0;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_10 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[3] = {__pyx_t_9, __pyx_v_data, __pyx_v_record};
          __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_10, 2+__pyx_t_10);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pysam/libcalignmentfile.pyx":307
 *                         "invalid type for record %s: %s, expected %s".format(
 *                             record, type(data), VALID_HEADER_TYPES[record]))
 *                 if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(data, record))
 *                 else:
 */
        goto __pyx_L7;
      }

      /* "pysam/libcalignmentfile.pyx":310
 *                     lines.append(build_header_line(data, record))
 *                 else:
 *                     for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                         lines.append(build_header_line(fields, record))
 * 
 */
      /*else*/ {
        __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
          __pyx_t_6 = __pyx_t_1; __Pyx_INCREF(__pyx_t_6);
          __pyx_t_12 = 0;
          __pyx_t_13 = NULL;
        } else {
          __pyx_t_12 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 310, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_13 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_6); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 310, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        for (;;) {
          if (likely(!__pyx_t_13)) {
            if (likely(PyList_CheckExact(__pyx_t_6))) {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_6);
                #if !CYTHON_ASSUME_SAFE_MACROS
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 310, __pyx_L1_error)
                #endif
                if (__pyx_t_12 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 310, __pyx_L1_error)
              #else
              __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_6, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            } else {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_6);
                #if !CYTHON_ASSUME_SAFE_MACROS
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 310, __pyx_L1_error)
                #endif
                if (__pyx_t_12 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_12); __Pyx_INCREF(__pyx_t_1); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 310, __pyx_L1_error)
              #else
              __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_6, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              #endif
            }
          } else {
            __pyx_t_1 = __pyx_t_13(__pyx_t_6);
            if (unlikely(!__pyx_t_1)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 310, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":311
 *                 else:
 *                     for fields in header_dict[record]:
 *                         lines.append(build_header_line(fields, record))             # <<<<<<<<<<<<<<
 * 
 *         # then: user tags (lower case), sorted alphabetically
 */
          __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 311, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_8 = NULL;
          __pyx_t_10 = 0;
          #if CYTHON_UNPACK_METHODS
          if (unlikely(PyMethod_Check(__pyx_t_9))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_9, function);
              __pyx_t_10 = 1;
            }
          }
          #endif
          {
            PyObject *__pyx_callargs[3] = {__pyx_t_8, __pyx_v_fields, __pyx_v_record};
            __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_10, 2+__pyx_t_10);
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          }
          __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 311, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":310
 *                     lines.append(build_header_line(data, record))
 *                 else:
 *                     for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                         lines.append(build_header_line(fields, record))
 * 
 */
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __pyx_L7:;

      /* "pysam/libcalignmentfile.pyx":301
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 *             if record in header_dict:             # <<<<<<<<<<<<<<
 *                 data = header_dict[record]
 *                 if not isinstance(data, VALID_HEADER_TYPES[record]):
 */
    }

    /* "pysam/libcalignmentfile.pyx":300
 *         cdef list lines = []
 *         # first: defined tags
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in header_dict:
 *                 data = header_dict[record]
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":314
 * 
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):             # <<<<<<<<<<<<<<
 *             if record in VALID_HEADERS:
 *                 continue
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_header_dict, __pyx_n_s_items); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL};
    __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_10, 0+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_t_1 = PySequence_List(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_2 = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_11 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 314, __pyx_L1_error)
  __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1);
  __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    {
      Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
      #if !CYTHON_ASSUME_SAFE_MACROS
      if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 314, __pyx_L1_error)
      #endif
      if (__pyx_t_3 >= __pyx_temp) break;
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely((0 < 0))) __PYX_ERR(0, 314, __pyx_L1_error)
    #else
    __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 314, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 314, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 314, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_8 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 314, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_14 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_8);
      index = 0; __pyx_t_6 = __pyx_t_14(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      index = 1; __pyx_t_9 = __pyx_t_14(__pyx_t_8); if (unlikely(!__pyx_t_9)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_8), 2) < 0) __PYX_ERR(0, 314, __pyx_L1_error)
      __pyx_t_14 = NULL;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L15_unpacking_done;
      __pyx_L14_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_14 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 314, __pyx_L1_error)
      __pyx_L15_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pysam/libcalignmentfile.pyx":315
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):
 *             if record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *                 continue
 *             if isinstance(data, Mapping):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 315, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_2, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 315, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_7) {

      /* "pysam/libcalignmentfile.pyx":316
 *         for record, data in sorted(header_dict.items()):
 *             if record in VALID_HEADERS:
 *                 continue             # <<<<<<<<<<<<<<
 *             if isinstance(data, Mapping):
 *                 lines.append(build_header_line(data, record))
 */
      goto __pyx_L12_continue;

      /* "pysam/libcalignmentfile.pyx":315
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):
 *             if record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *                 continue
 *             if isinstance(data, Mapping):
 */
    }

    /* "pysam/libcalignmentfile.pyx":317
 *             if record in VALID_HEADERS:
 *                 continue
 *             if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                 lines.append(build_header_line(data, record))
 *             else:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = PyObject_IsInstance(__pyx_v_data, __pyx_t_2); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_7) {

      /* "pysam/libcalignmentfile.pyx":318
 *                 continue
 *             if isinstance(data, Mapping):
 *                 lines.append(build_header_line(data, record))             # <<<<<<<<<<<<<<
 *             else:
 *                 for fields in header_dict[record]:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_6 = NULL;
      __pyx_t_10 = 0;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
          __pyx_t_10 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_6, __pyx_v_data, __pyx_v_record};
        __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_10, 2+__pyx_t_10);
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 318, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":317
 *             if record in VALID_HEADERS:
 *                 continue
 *             if isinstance(data, Mapping):             # <<<<<<<<<<<<<<
 *                 lines.append(build_header_line(data, record))
 *             else:
 */
      goto __pyx_L17;
    }

    /* "pysam/libcalignmentfile.pyx":320
 *                 lines.append(build_header_line(data, record))
 *             else:
 *                 for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(fields, record))
 * 
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_header_dict, __pyx_v_record); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
        __pyx_t_9 = __pyx_t_2; __Pyx_INCREF(__pyx_t_9);
        __pyx_t_12 = 0;
        __pyx_t_4 = NULL;
      } else {
        __pyx_t_12 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 320, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_4 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 320, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      for (;;) {
        if (likely(!__pyx_t_4)) {
          if (likely(PyList_CheckExact(__pyx_t_9))) {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_9);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 320, __pyx_L1_error)
              #endif
              if (__pyx_t_12 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 320, __pyx_L1_error)
            #else
            __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_9, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          } else {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_9);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 320, __pyx_L1_error)
              #endif
              if (__pyx_t_12 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely((0 < 0))) __PYX_ERR(0, 320, __pyx_L1_error)
            #else
            __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_9, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 320, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_4(__pyx_t_9);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 320, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":321
 *             else:
 *                 for fields in header_dict[record]:
 *                     lines.append(build_header_line(fields, record))             # <<<<<<<<<<<<<<
 * 
 *         text = "\n".join(lines) + "\n"
 */
        __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_build_header_line); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 321, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = NULL;
        __pyx_t_10 = 0;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_10 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[3] = {__pyx_t_8, __pyx_v_fields, __pyx_v_record};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_10, 2+__pyx_t_10);
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 321, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":320
 *                 lines.append(build_header_line(data, record))
 *             else:
 *                 for fields in header_dict[record]:             # <<<<<<<<<<<<<<
 *                     lines.append(build_header_line(fields, record))
 * 
 */
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __pyx_L17:;

    /* "pysam/libcalignmentfile.pyx":314
 * 
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(header_dict.items()):             # <<<<<<<<<<<<<<
 *             if record in VALID_HEADERS:
 *                 continue
 */
    __pyx_L12_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":323
 *                     lines.append(build_header_line(fields, record))
 * 
 *         text = "\n".join(lines) + "\n"             # <<<<<<<<<<<<<<
 * 
 *         reference_names, reference_lengths = [], []
 */
  __pyx_t_1 = PyUnicode_Join(__pyx_kp_u__12, __pyx_v_lines); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 323, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_1, __pyx_kp_u__12); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 323, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_text = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;

  /* "pysam/libcalignmentfile.pyx":325
 *         text = "\n".join(lines) + "\n"
 * 
 *         reference_names, reference_lengths = [], []             # <<<<<<<<<<<<<<
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 */
  __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 325, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_reference_names = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_v_reference_lengths = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":326
 * 
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:             # <<<<<<<<<<<<<<
 *             for fields in header_dict["SQ"]:
 *                 try:
 */
  __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_n_u_SQ_2, __pyx_v_header_dict, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 326, __pyx_L1_error)
  if (__pyx_t_7) {

    /* "pysam/libcalignmentfile.pyx":327
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
    __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_header_dict, __pyx_n_u_SQ_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9);
      __pyx_t_3 = 0;
      __pyx_t_4 = NULL;
    } else {
      __pyx_t_3 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 327, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 327, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_4)) {
        if (likely(PyList_CheckExact(__pyx_t_9))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_9);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 327, __pyx_L1_error)
            #endif
            if (__pyx_t_3 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely((0 < 0))) __PYX_ERR(0, 327, __pyx_L1_error)
          #else
          __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_9, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_9);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 327, __pyx_L1_error)
            #endif
            if (__pyx_t_3 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely((0 < 0))) __PYX_ERR(0, 327, __pyx_L1_error)
          #else
          __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_9, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 327, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_4(__pyx_t_9);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 327, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":328
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_15, &__pyx_t_16, &__pyx_t_17);
        __Pyx_XGOTREF(__pyx_t_15);
        __Pyx_XGOTREF(__pyx_t_16);
        __Pyx_XGOTREF(__pyx_t_17);
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":329
 *             for fields in header_dict["SQ"]:
 *                 try:
 *                     reference_names.append(fields["SN"])             # <<<<<<<<<<<<<<
 *                     reference_lengths.append(fields["LN"])
 *                 except KeyError:
 */
          __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_u_SN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 329, __pyx_L25_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_reference_names, __pyx_t_1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 329, __pyx_L25_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":330
 *                 try:
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 */
          __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_v_fields, __pyx_n_u_LN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 330, __pyx_L25_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_reference_lengths, __pyx_t_1); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 330, __pyx_L25_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pysam/libcalignmentfile.pyx":328
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 */
        }
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        goto __pyx_L32_try_end;
        __pyx_L25_error:;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pysam/libcalignmentfile.pyx":331
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 * 
 */
        __pyx_t_18 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_18) {
          __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_2, &__pyx_t_6) < 0) __PYX_ERR(0, 331, __pyx_L27_except_error)
          __Pyx_XGOTREF(__pyx_t_1);
          __Pyx_XGOTREF(__pyx_t_2);
          __Pyx_XGOTREF(__pyx_t_6);

          /* "pysam/libcalignmentfile.pyx":332
 *                     reference_lengths.append(fields["LN"])
 *                 except KeyError:
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 */
          __pyx_t_8 = __Pyx_PyObject_Unicode(__pyx_v_fields); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 332, __pyx_L27_except_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_19 = PyUnicode_Format(__pyx_kp_u_incomplete_sequence_information, __pyx_t_8); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 332, __pyx_L27_except_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_19); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 332, __pyx_L27_except_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __PYX_ERR(0, 332, __pyx_L27_except_error)
        }
        goto __pyx_L27_except_error;

        /* "pysam/libcalignmentfile.pyx":328
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     reference_names.append(fields["SN"])
 *                     reference_lengths.append(fields["LN"])
 */
        __pyx_L27_except_error:;
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_XGIVEREF(__pyx_t_16);
        __Pyx_XGIVEREF(__pyx_t_17);
        __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_16, __pyx_t_17);
        goto __pyx_L1_error;
        __pyx_L32_try_end:;
      }

      /* "pysam/libcalignmentfile.pyx":327
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:
 *             for fields in header_dict["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "pysam/libcalignmentfile.pyx":326
 * 
 *         reference_names, reference_lengths = [], []
 *         if "SQ" in header_dict:             # <<<<<<<<<<<<<<
 *             for fields in header_dict["SQ"]:
 *                 try:
 */
  }

  /* "pysam/libcalignmentfile.pyx":334
 *                     raise KeyError("incomplete sequence information in '%s'" % str(fields))
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = NULL;
  __pyx_t_10 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
      __pyx_t_10 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[4] = {__pyx_t_2, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_10, 3+__pyx_t_10);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __pyx_r = __pyx_t_9;
  __pyx_t_9 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":295
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_dict(cls, header_dict):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_lines);
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XDECREF(__pyx_v_reference_lengths);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":336
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references, "AlignmentHeader.from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references = {"from_references", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references(PyObject *__pyx_v_cls, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_reference_names = 0;
  PyObject *__pyx_v_reference_lengths = 0;
  PyObject *__pyx_v_text = 0;
  PyObject *__pyx_v_add_sq_text = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[4] = {0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("from_references (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,&__pyx_n_s_text,&__pyx_n_s_add_sq_text,0};

    /* "pysam/libcalignmentfile.pyx":337
 * 
 *     @classmethod
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):             # <<<<<<<<<<<<<<
 * 
 *         if len(reference_names) != len(reference_lengths):
 */
    values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
    values[3] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_True));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference_names)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 336, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference_lengths)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 336, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("from_references", 0, 2, 4, 1); __PYX_ERR(0, 336, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_text);
          if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 336, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_add_sq_text);
          if (value) { values[3] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 336, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "from_references") < 0)) __PYX_ERR(0, 336, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_reference_names = values[0];
    __pyx_v_reference_lengths = values[1];
    __pyx_v_text = values[2];
    __pyx_v_add_sq_text = values[3];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("from_references", 0, 2, 4, __pyx_nargs); __PYX_ERR(0, 336, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_references", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(((PyTypeObject*)__pyx_v_cls), __pyx_v_reference_names, __pyx_v_reference_lengths, __pyx_v_text, __pyx_v_add_sq_text);

  /* "pysam/libcalignmentfile.pyx":336
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 */

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_text, PyObject *__pyx_v_add_sq_text) {
  PyObject *__pyx_8genexpr2__pyx_v_x = NULL;
  PyObject *__pyx_8genexpr2__pyx_v_y = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  unsigned int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__13)
  __Pyx_RefNannySetupContext("from_references", 0);
  __Pyx_TraceCall("from_references", __pyx_f[0], 336, 0, __PYX_ERR(0, 336, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_text);

  /* "pysam/libcalignmentfile.pyx":339
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 *         if len(reference_names) != len(reference_lengths):             # <<<<<<<<<<<<<<
 *             raise ValueError("number of reference names and lengths do not match")
 * 
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 339, __pyx_L1_error)
  __pyx_t_2 = PyObject_Length(__pyx_v_reference_lengths); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 339, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_1 != __pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":340
 * 
 *         if len(reference_names) != len(reference_lengths):
 *             raise ValueError("number of reference names and lengths do not match")             # <<<<<<<<<<<<<<
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 340, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 340, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":339
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 *         if len(reference_names) != len(reference_lengths):             # <<<<<<<<<<<<<<
 *             raise ValueError("number of reference names and lengths do not match")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":343
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:             # <<<<<<<<<<<<<<
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(
 *                 reference_names, reference_lengths)])
 */
  __pyx_t_5 = (__pyx_v_text == Py_None);
  if (__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_add_sq_text); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 343, __pyx_L1_error)
  __pyx_t_3 = __pyx_t_5;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":344
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(             # <<<<<<<<<<<<<<
 *                 reference_names, reference_lengths)])
 * 
 */
    { /* enter inner scope */
      __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 344, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_4);

      /* "pysam/libcalignmentfile.pyx":345
 *         if text is None and add_sq_text:
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(
 *                 reference_names, reference_lengths)])             # <<<<<<<<<<<<<<
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 */
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 344, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_v_reference_names);
      __Pyx_GIVEREF(__pyx_v_reference_names);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_reference_names)) __PYX_ERR(0, 344, __pyx_L9_error);
      __Pyx_INCREF(__pyx_v_reference_lengths);
      __Pyx_GIVEREF(__pyx_v_reference_lengths);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_reference_lengths)) __PYX_ERR(0, 344, __pyx_L9_error);

      /* "pysam/libcalignmentfile.pyx":344
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(             # <<<<<<<<<<<<<<
 *                 reference_names, reference_lengths)])
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 344, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
        __pyx_t_6 = __pyx_t_7; __Pyx_INCREF(__pyx_t_6);
        __pyx_t_2 = 0;
        __pyx_t_8 = NULL;
      } else {
        __pyx_t_2 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 344, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 344, __pyx_L9_error)
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      for (;;) {
        if (likely(!__pyx_t_8)) {
          if (likely(PyList_CheckExact(__pyx_t_6))) {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_6);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 344, __pyx_L9_error)
              #endif
              if (__pyx_t_2 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_7); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 344, __pyx_L9_error)
            #else
            __pyx_t_7 = __Pyx_PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 344, __pyx_L9_error)
            __Pyx_GOTREF(__pyx_t_7);
            #endif
          } else {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_6);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 344, __pyx_L9_error)
              #endif
              if (__pyx_t_2 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_2); __Pyx_INCREF(__pyx_t_7); __pyx_t_2++; if (unlikely((0 < 0))) __PYX_ERR(0, 344, __pyx_L9_error)
            #else
            __pyx_t_7 = __Pyx_PySequence_ITEM(__pyx_t_6, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 344, __pyx_L9_error)
            __Pyx_GOTREF(__pyx_t_7);
            #endif
          }
        } else {
          __pyx_t_7 = __pyx_t_8(__pyx_t_6);
          if (unlikely(!__pyx_t_7)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 344, __pyx_L9_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_7);
        }
        if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
          PyObject* sequence = __pyx_t_7;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 344, __pyx_L9_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_10);
          #else
          __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 344, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 344, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_10);
          #endif
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_11 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 344, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_12 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_11);
          index = 0; __pyx_t_9 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_9)) goto __pyx_L12_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_9);
          index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L12_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_10);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) __PYX_ERR(0, 344, __pyx_L9_error)
          __pyx_t_12 = NULL;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          goto __pyx_L13_unpacking_done;
          __pyx_L12_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_12 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 344, __pyx_L9_error)
          __pyx_L13_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_x, __pyx_t_9);
        __pyx_t_9 = 0;
        __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_y, __pyx_t_10);
        __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_SQ_SN_LN, __pyx_n_s_format); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 344, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = NULL;
        __pyx_t_13 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_10))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_10, function);
            __pyx_t_13 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[3] = {__pyx_t_9, __pyx_8genexpr2__pyx_v_x, __pyx_8genexpr2__pyx_v_y};
          __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_13, 2+__pyx_t_13);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 344, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 344, __pyx_L9_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); __pyx_8genexpr2__pyx_v_x = 0;
      __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_y); __pyx_8genexpr2__pyx_v_y = 0;
      goto __pyx_L15_exit_scope;
      __pyx_L9_error:;
      __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x); __pyx_8genexpr2__pyx_v_x = 0;
      __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_y); __pyx_8genexpr2__pyx_v_y = 0;
      goto __pyx_L1_error;
      __pyx_L15_exit_scope:;
    } /* exit inner scope */
    __pyx_t_6 = PyUnicode_Join(__pyx_kp_u__15, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "pysam/libcalignmentfile.pyx":343
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 *         if text is None and add_sq_text:             # <<<<<<<<<<<<<<
 *             text = "".join(["@SQ\tSN:{}\tLN:{}\n".format(x, y) for x, y in zip(
 *                 reference_names, reference_lengths)])
 */
  }

  /* "pysam/libcalignmentfile.pyx":347
 *                 reference_names, reference_lengths)])
 * 
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = NULL;
  __pyx_t_13 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_13 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[4] = {__pyx_t_7, __pyx_v_text, __pyx_v_reference_names, __pyx_v_reference_lengths};
    __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_13, 3+__pyx_t_13);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":336
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.from_references", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_x);
  __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_y);
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":349
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_hdr_destroy(self.ptr)
 *         self.ptr = NULL
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_12__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 349, 0, __PYX_ERR(0, 349, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":350
 * 
 *     def __dealloc__(self):
 *         bam_hdr_destroy(self.ptr)             # <<<<<<<<<<<<<<
 *         self.ptr = NULL
 * 
 */
  bam_hdr_destroy(__pyx_v_self->ptr);

  /* "pysam/libcalignmentfile.pyx":351
 *     def __dealloc__(self):
 *         bam_hdr_destroy(self.ptr)
 *         self.ptr = NULL             # <<<<<<<<<<<<<<
 * 
 *     def __bool__(self):
 */
  __pyx_v_self->ptr = NULL;

  /* "pysam/libcalignmentfile.pyx":349
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_hdr_destroy(self.ptr)
 *         self.ptr = NULL
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentHeader.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
}

/* "pysam/libcalignmentfile.pyx":353
 *         self.ptr = NULL
 * 
 *     def __bool__(self):             # <<<<<<<<<<<<<<
 *         return self.ptr != NULL
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_14__bool__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__bool__", __pyx_f[0], 353, 0, __PYX_ERR(0, 353, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":354
 * 
 *     def __bool__(self):
 *         return self.ptr != NULL             # <<<<<<<<<<<<<<
 * 
 *     def copy(self):
 */
  __pyx_r = (__pyx_v_self->ptr != NULL);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":353
 *         self.ptr = NULL
 * 
 *     def __bool__(self):             # <<<<<<<<<<<<<<
 *         return self.ptr != NULL
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":356
 *         return self.ptr != NULL
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_16copy, "AlignmentHeader.copy(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_17copy = {"copy", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_16copy};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("copy (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("copy", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "copy", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_16copy(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__16)
  __Pyx_RefNannySetupContext("copy", 1);
  __Pyx_TraceCall("copy", __pyx_f[0], 356, 0, __PYX_ERR(0, 356, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":357
 * 
 *     def copy(self):
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))             # <<<<<<<<<<<<<<
 * 
 *     property nreferences:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(bam_hdr_dup(__pyx_v_self->ptr))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":356
 *         return self.ptr != NULL
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":363
 * 
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.ptr.n_targets
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 363, 0, __PYX_ERR(0, 363, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":364
 *         This is a read-only attribute."""
 *         def __get__(self):
 *             return self.ptr.n_targets             # <<<<<<<<<<<<<<
 * 
 *     property references:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":363
 * 
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.ptr.n_targets
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":369
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  int __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int32_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 369, 0, __PYX_ERR(0, 369, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":370
 *         read-only attribute"""
 *         def __get__(self):
 *             t = []             # <<<<<<<<<<<<<<
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_t = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":372
 *             t = []
 *             cdef int x
 *             for x in range(self.ptr.n_targets):             # <<<<<<<<<<<<<<
 *                 t.append(charptr_to_str(self.ptr.target_name[x]))
 *             return tuple(t)
 */
  __pyx_t_2 = __pyx_v_self->ptr->n_targets;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_x = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":373
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 *                 t.append(charptr_to_str(self.ptr.target_name[x]))             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    __pyx_t_1 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->ptr->target_name[__pyx_v_x]), NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 373, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":374
 *             for x in range(self.ptr.n_targets):
 *                 t.append(charptr_to_str(self.ptr.target_name[x]))
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     property lengths:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":369
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.references.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":381
 *         :attr:`pysam.AlignmentFile.references`
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  int __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int32_t __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 381, 0, __PYX_ERR(0, 381, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":382
 *         """
 *         def __get__(self):
 *             t = []             # <<<<<<<<<<<<<<
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 382, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_t = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":384
 *             t = []
 *             cdef int x
 *             for x in range(self.ptr.n_targets):             # <<<<<<<<<<<<<<
 *                 t.append(self.ptr.target_len[x])
 *             return tuple(t)
 */
  __pyx_t_2 = __pyx_v_self->ptr->n_targets;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_x = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":385
 *             cdef int x
 *             for x in range(self.ptr.n_targets):
 *                 t.append(self.ptr.target_len[x])             # <<<<<<<<<<<<<<
 *             return tuple(t)
 * 
 */
    __pyx_t_1 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 385, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_t, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 385, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":386
 *             for x in range(self.ptr.n_targets):
 *                 t.append(self.ptr.target_len[x])
 *             return tuple(t)             # <<<<<<<<<<<<<<
 * 
 *     def _build_sequence_section(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_AsTuple(__pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 386, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":381
 *         :attr:`pysam.AlignmentFile.references`
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             t = []
 *             cdef int x
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":388
 *             return tuple(t)
 * 
 *     def _build_sequence_section(self):             # <<<<<<<<<<<<<<
 *         """return sequence section of header.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section, "AlignmentHeader._build_sequence_section(self)\nreturn sequence section of header.\n\n        The sequence section is built from the list of reference names and\n        lengths stored in the BAM-file and not from any @SQ entries that\n        are part of the header's text section.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section = {"_build_sequence_section", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_build_sequence_section (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("_build_sequence_section", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "_build_sequence_section", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  int __pyx_v_x;
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int32_t __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  unsigned int __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__17)
  __Pyx_RefNannySetupContext("_build_sequence_section", 1);
  __Pyx_TraceCall("_build_sequence_section", __pyx_f[0], 388, 0, __PYX_ERR(0, 388, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":397
 * 
 *         cdef int x
 *         text = []             # <<<<<<<<<<<<<<
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_text = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":398
 *         cdef int x
 *         text = []
 *         for x in range(self.ptr.n_targets):             # <<<<<<<<<<<<<<
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 *                 force_str(self.ptr.target_name[x]),
 */
  __pyx_t_2 = __pyx_v_self->ptr->n_targets;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_x = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":399
 *         text = []
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(             # <<<<<<<<<<<<<<
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_SQ_SN_LN, __pyx_n_s_format); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 399, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "pysam/libcalignmentfile.pyx":400
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 *                 force_str(self.ptr.target_name[x]),             # <<<<<<<<<<<<<<
 *                 self.ptr.target_len[x]))
 *         return "".join(text)
 */
    __pyx_t_6 = __Pyx_PyBytes_FromString((__pyx_v_self->ptr->target_name[__pyx_v_x])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 400, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 400, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/libcalignmentfile.pyx":401
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))             # <<<<<<<<<<<<<<
 *         return "".join(text)
 * 
 */
    __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_x])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 401, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    __pyx_t_9 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_9 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[3] = {__pyx_t_8, __pyx_t_7, __pyx_t_6};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }

    /* "pysam/libcalignmentfile.pyx":399
 *         text = []
 *         for x in range(self.ptr.n_targets):
 *             text.append("@SQ\tSN:{}\tLN:{}\n".format(             # <<<<<<<<<<<<<<
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))
 */
    __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_text, __pyx_t_1); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 399, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":402
 *                 force_str(self.ptr.target_name[x]),
 *                 self.ptr.target_len[x]))
 *         return "".join(text)             # <<<<<<<<<<<<<<
 * 
 *     def to_dict(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyUnicode_Join(__pyx_kp_u__15, __pyx_v_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":388
 *             return tuple(t)
 * 
 *     def _build_sequence_section(self):             # <<<<<<<<<<<<<<
 *         """return sequence section of header.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader._build_sequence_section", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":404
 *         return "".join(text)
 * 
 *     def to_dict(self):             # <<<<<<<<<<<<<<
 *         """return two-level dictionary with header information from the file.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict, "AlignmentHeader.to_dict(self)\nreturn two-level dictionary with header information from the file.\n\n        The first level contains the record (``HD``, ``SQ``, etc) and\n        the second level contains the fields (``VN``, ``LN``, etc).\n\n        The parser is validating and will raise an AssertionError if\n        if encounters any record or field tags that are not part of\n        the SAM specification. Use the\n        :attr:`pysam.AlignmentFile.text` attribute to get the unparsed\n        header.\n\n        The parsing follows the SAM format specification with the\n        exception of the ``CL`` field. This option will consume the\n        rest of a header line irrespective of any additional fields.\n        This behaviour has been added to accommodate command line\n        options that contain characters that are not valid field\n        separators.\n\n        If no @SQ entries are within the text section of the header,\n        this will be automatically added from the reference names and\n        lengths stored in the binary part of the header.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict = {"to_dict", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("to_dict (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("to_dict", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "to_dict", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_record = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_idx = NULL;
  PyObject *__pyx_v_field = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_sq = NULL;
  PyObject *__pyx_v_ref = NULL;
  PyObject *__pyx_v_length = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  Py_ssize_t __pyx_t_10;
  Py_UCS4 __pyx_t_11;
  int __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *(*__pyx_t_17)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__18)
  __Pyx_RefNannySetupContext("to_dict", 1);
  __Pyx_TraceCall("to_dict", __pyx_f[0], 404, 0, __PYX_ERR(0, 404, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":427
 *         lengths stored in the binary part of the header.
 *         """
 *         result = collections.OrderedDict()             # <<<<<<<<<<<<<<
 * 
 *         # convert to python string
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_OrderedDict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 427, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_v_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":430
 * 
 *         # convert to python string
 *         t = self.__str__()             # <<<<<<<<<<<<<<
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 430, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 430, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_v_t = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":431
 *         # convert to python string
 *         t = self.__str__()
 *         for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *             line = line.strip(' \0')
 *             if not line:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_split); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_u__12};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3);
    __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 431, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 431, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_3);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 431, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 431, __pyx_L1_error)
        #else
        __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_3);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 431, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 431, __pyx_L1_error)
        #else
        __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 431, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_3);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 431, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":432
 *         t = self.__str__()
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')             # <<<<<<<<<<<<<<
 *             if not line:
 *                 continue
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_strip); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 432, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_u__19};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 432, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF_SET(__pyx_v_line, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":433
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')
 *             if not line:             # <<<<<<<<<<<<<<
 *                 continue
 *             assert line.startswith("@"), \
 */
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_line); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 433, __pyx_L1_error)
    __pyx_t_9 = (!__pyx_t_8);
    if (__pyx_t_9) {

      /* "pysam/libcalignmentfile.pyx":434
 *             line = line.strip(' \0')
 *             if not line:
 *                 continue             # <<<<<<<<<<<<<<
 *             assert line.startswith("@"), \
 *                 "header line without '@': '%s'" % line
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":433
 *         for line in t.split("\n"):
 *             line = line.strip(' \0')
 *             if not line:             # <<<<<<<<<<<<<<
 *                 continue
 *             assert line.startswith("@"), \
 */
    }

    /* "pysam/libcalignmentfile.pyx":435
 *             if not line:
 *                 continue
 *             assert line.startswith("@"), \             # <<<<<<<<<<<<<<
 *                 "header line without '@': '%s'" % line
 *             fields = line[1:].split("\t")
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(__pyx_assertions_enabled())) {
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_startswith); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_7 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_kp_u__20};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 435, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_9)) {

        /* "pysam/libcalignmentfile.pyx":436
 *                 continue
 *             assert line.startswith("@"), \
 *                 "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
 *             fields = line[1:].split("\t")
 *             record = fields[0]
 */
        __pyx_t_1 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_header_line_without_s, __pyx_v_line); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_1, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __PYX_ERR(0, 435, __pyx_L1_error)
      }
    }
    #else
    if ((1)); else __PYX_ERR(0, 435, __pyx_L1_error)
    #endif

    /* "pysam/libcalignmentfile.pyx":437
 *             assert line.startswith("@"), \
 *                 "header line without '@': '%s'" % line
 *             fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
 *             record = fields[0]
 *             assert record in VALID_HEADER_TYPES, \
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_line, 1, 0, NULL, NULL, &__pyx_slice__9, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 437, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_split); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 437, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_kp_u__3};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":438
 *                 "header line without '@': '%s'" % line
 *             fields = line[1:].split("\t")
 *             record = fields[0]             # <<<<<<<<<<<<<<
 *             assert record in VALID_HEADER_TYPES, \
 *                 "header line with invalid type '%s': '%s'" % (record, line)
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_fields, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 438, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":439
 *             fields = line[1:].split("\t")
 *             record = fields[0]
 *             assert record in VALID_HEADER_TYPES, \             # <<<<<<<<<<<<<<
 *                 "header line with invalid type '%s': '%s'" % (record, line)
 * 
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(__pyx_assertions_enabled())) {
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_9 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_t_1, Py_EQ)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 439, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_9)) {

        /* "pysam/libcalignmentfile.pyx":440
 *             record = fields[0]
 *             assert record in VALID_HEADER_TYPES, \
 *                 "header line with invalid type '%s': '%s'" % (record, line)             # <<<<<<<<<<<<<<
 * 
 *             # treat comments
 */
        __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 440, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_10 = 0;
        __pyx_t_11 = 127;
        __Pyx_INCREF(__pyx_kp_u_header_line_with_invalid_type);
        __pyx_t_10 += 31;
        __Pyx_GIVEREF(__pyx_kp_u_header_line_with_invalid_type);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_header_line_with_invalid_type);
        __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_record), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 440, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_11;
        __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
        __pyx_t_7 = 0;
        __Pyx_INCREF(__pyx_kp_u__21);
        __pyx_t_10 += 4;
        __Pyx_GIVEREF(__pyx_kp_u__21);
        PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u__21);
        __pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_line), __pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 440, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) : __pyx_t_11;
        __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_7);
        __pyx_t_7 = 0;
        __Pyx_INCREF(__pyx_kp_u__22);
        __pyx_t_10 += 1;
        __Pyx_GIVEREF(__pyx_kp_u__22);
        PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__22);
        __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 440, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_7, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __PYX_ERR(0, 439, __pyx_L1_error)
      }
    }
    #else
    if ((1)); else __PYX_ERR(0, 439, __pyx_L1_error)
    #endif

    /* "pysam/libcalignmentfile.pyx":443
 * 
 *             # treat comments
 *             if record == "CO":             # <<<<<<<<<<<<<<
 *                 if record not in result:
 *                     result[record] = []
 */
    __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_record, __pyx_n_u_CO, Py_EQ)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 443, __pyx_L1_error)
    if (__pyx_t_9) {

      /* "pysam/libcalignmentfile.pyx":444
 *             # treat comments
 *             if record == "CO":
 *                 if record not in result:             # <<<<<<<<<<<<<<
 *                     result[record] = []
 *                 result[record].append("\t".join( fields[1:]))
 */
      __pyx_t_9 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 444, __pyx_L1_error)
      if (__pyx_t_9) {

        /* "pysam/libcalignmentfile.pyx":445
 *             if record == "CO":
 *                 if record not in result:
 *                     result[record] = []             # <<<<<<<<<<<<<<
 *                 result[record].append("\t".join( fields[1:]))
 *                 continue
 */
        __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 445, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        if (unlikely((PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_7) < 0))) __PYX_ERR(0, 445, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "pysam/libcalignmentfile.pyx":444
 *             # treat comments
 *             if record == "CO":
 *                 if record not in result:             # <<<<<<<<<<<<<<
 *                     result[record] = []
 *                 result[record].append("\t".join( fields[1:]))
 */
      }

      /* "pysam/libcalignmentfile.pyx":446
 *                 if record not in result:
 *                     result[record] = []
 *                 result[record].append("\t".join( fields[1:]))             # <<<<<<<<<<<<<<
 *                 continue
 *             # the following is clumsy as generators do not work?
 */
      __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__9, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_2); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":447
 *                     result[record] = []
 *                 result[record].append("\t".join( fields[1:]))
 *                 continue             # <<<<<<<<<<<<<<
 *             # the following is clumsy as generators do not work?
 *             x = {}
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":443
 * 
 *             # treat comments
 *             if record == "CO":             # <<<<<<<<<<<<<<
 *                 if record not in result:
 *                     result[record] = []
 */
    }

    /* "pysam/libcalignmentfile.pyx":449
 *                 continue
 *             # the following is clumsy as generators do not work?
 *             x = {}             # <<<<<<<<<<<<<<
 * 
 *             for idx, field in enumerate(fields[1:]):
 */
    __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_x, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":451
 *             x = {}
 * 
 *             for idx, field in enumerate(fields[1:]):             # <<<<<<<<<<<<<<
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )
 */
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_2 = __pyx_int_0;
    __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__9, 1, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 451, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
      __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1);
      __pyx_t_10 = 0;
      __pyx_t_13 = NULL;
    } else {
      __pyx_t_10 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_13 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 451, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    for (;;) {
      if (likely(!__pyx_t_13)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 451, __pyx_L1_error)
            #endif
            if (__pyx_t_10 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_7); __pyx_t_10++; if (unlikely((0 < 0))) __PYX_ERR(0, 451, __pyx_L1_error)
          #else
          __pyx_t_7 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 451, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 451, __pyx_L1_error)
            #endif
            if (__pyx_t_10 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_10); __Pyx_INCREF(__pyx_t_7); __pyx_t_10++; if (unlikely((0 < 0))) __PYX_ERR(0, 451, __pyx_L1_error)
          #else
          __pyx_t_7 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 451, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
        }
      } else {
        __pyx_t_7 = __pyx_t_13(__pyx_t_1);
        if (unlikely(!__pyx_t_7)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 451, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_7);
      }
      __Pyx_XDECREF_SET(__pyx_v_field, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_2);
      __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 451, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_2);
      __pyx_t_2 = __pyx_t_7;
      __pyx_t_7 = 0;

      /* "pysam/libcalignmentfile.pyx":452
 * 
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:             # <<<<<<<<<<<<<<
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 */
      __pyx_t_9 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__2, __pyx_v_field, Py_NE)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 452, __pyx_L1_error)
      if (unlikely(__pyx_t_9)) {

        /* "pysam/libcalignmentfile.pyx":453
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):
 */
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 453, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_Raise(__pyx_t_7, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __PYX_ERR(0, 453, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":452
 * 
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:             # <<<<<<<<<<<<<<
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 */
      }

      /* "pysam/libcalignmentfile.pyx":454
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)             # <<<<<<<<<<<<<<
 *                 if key in ("CL",):
 *                     # special treatment for command line
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_field, __pyx_n_s_split); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 454, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 454, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) {
        PyObject* sequence = __pyx_t_14;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 454, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_15);
        #else
        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        #endif
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_16 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_17 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_16);
        index = 0; __pyx_t_7 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_7)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        index = 1; __pyx_t_15 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_15);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 2) < 0) __PYX_ERR(0, 454, __pyx_L1_error)
        __pyx_t_17 = NULL;
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        goto __pyx_L12_unpacking_done;
        __pyx_L11_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_17 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 454, __pyx_L1_error)
        __pyx_L12_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_15);
      __pyx_t_15 = 0;

      /* "pysam/libcalignmentfile.pyx":455
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):             # <<<<<<<<<<<<<<
 *                     # special treatment for command line
 *                     # statements (CL). These might contain
 */
      __Pyx_INCREF(__pyx_v_key);
      __pyx_t_14 = __pyx_v_key;
      __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_t_14, __pyx_n_u_CL, Py_EQ)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 455, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_8 = __pyx_t_9;
      if (__pyx_t_8) {

        /* "pysam/libcalignmentfile.pyx":462
 *                     # header. Thus, in contravention to the
 *                     # SAM API, consume the rest of the line.
 *                     key, value = "\t".join(fields[idx+1:]).split(":", 1)             # <<<<<<<<<<<<<<
 *                     x[key] = KNOWN_HEADER_FIELDS[record][key](value)
 *                     break
 */
        __pyx_t_14 = __Pyx_PyInt_AddObjC(__pyx_v_idx, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_15 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 0, 0, &__pyx_t_14, NULL, NULL, 0, 0, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_t_15 = PyUnicode_Split(((PyObject*)__pyx_t_14), __Pyx_NoneAsNull(__pyx_kp_u__2), 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 462, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        if (1) {
          PyObject* sequence = __pyx_t_15;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 462, __pyx_L1_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_14 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(__pyx_t_7);
          #else
          __pyx_t_14 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 462, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 462, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        }
        __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_14);
        __pyx_t_14 = 0;
        __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "pysam/libcalignmentfile.pyx":463
 *                     # SAM API, consume the rest of the line.
 *                     key, value = "\t".join(fields[idx+1:]).split(":", 1)
 *                     x[key] = KNOWN_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
 *                     break
 * 
 */
        __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_14 = __Pyx_PyObject_GetItem(__pyx_t_7, __pyx_v_record); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_GetItem(__pyx_t_14, __pyx_v_key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = NULL;
        __pyx_t_4 = 0;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
            __pyx_t_4 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_v_value};
          __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 463, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        if (unlikely((PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_15) < 0))) __PYX_ERR(0, 463, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

        /* "pysam/libcalignmentfile.pyx":464
 *                     key, value = "\t".join(fields[idx+1:]).split(":", 1)
 *                     x[key] = KNOWN_HEADER_FIELDS[record][key](value)
 *                     break             # <<<<<<<<<<<<<<
 * 
 *                 # interpret type of known header record tags, default to str
 */
        goto __pyx_L9_break;

        /* "pysam/libcalignmentfile.pyx":455
 *                     raise ValueError("malformatted header: no ':' in field" )
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):             # <<<<<<<<<<<<<<
 *                     # special treatment for command line
 *                     # statements (CL). These might contain
 */
      }

      /* "pysam/libcalignmentfile.pyx":467
 * 
 *                 # interpret type of known header record tags, default to str
 *                 x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value)             # <<<<<<<<<<<<<<
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:
 */
      __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_KNOWN_HEADER_FIELDS); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_16 = __Pyx_PyObject_GetItem(__pyx_t_14, __pyx_v_record); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_get); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_16 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_14))) {
        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_14);
        if (likely(__pyx_t_16)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
          __Pyx_INCREF(__pyx_t_16);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_14, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[3] = {__pyx_t_16, __pyx_v_key, ((PyObject *)(&PyUnicode_Type))};
        __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_14, __pyx_callargs+1-__pyx_t_4, 2+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 467, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      }
      __pyx_t_14 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_14)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_v_value};
        __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 467, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      if (unlikely((PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_15) < 0))) __PYX_ERR(0, 467, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

      /* "pysam/libcalignmentfile.pyx":451
 *             x = {}
 * 
 *             for idx, field in enumerate(fields[1:]):             # <<<<<<<<<<<<<<
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L14_for_end;
    __pyx_L9_break:;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L14_for_end;
    __pyx_L14_for_end:;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":469
 *                 x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value)
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:             # <<<<<<<<<<<<<<
 *                 if record in result:
 *                     raise ValueError(
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_15 = PyObject_RichCompare(__pyx_t_1, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_15); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_15); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    if (__pyx_t_8) {

      /* "pysam/libcalignmentfile.pyx":470
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:
 *                 if record in result:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "multiple '%s' lines are not permitted" % record)
 */
      __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_EQ)); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 470, __pyx_L1_error)
      if (unlikely(__pyx_t_8)) {

        /* "pysam/libcalignmentfile.pyx":472
 *                 if record in result:
 *                     raise ValueError(
 *                         "multiple '%s' lines are not permitted" % record)             # <<<<<<<<<<<<<<
 * 
 *                 result[record] = x
 */
        __pyx_t_15 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_multiple_s_lines_are_not_permitt, __pyx_v_record); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 472, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);

        /* "pysam/libcalignmentfile.pyx":471
 *             if VALID_HEADER_TYPES[record] == Mapping:
 *                 if record in result:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "multiple '%s' lines are not permitted" % record)
 * 
 */
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 471, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 471, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":470
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:
 *                 if record in result:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "multiple '%s' lines are not permitted" % record)
 */
      }

      /* "pysam/libcalignmentfile.pyx":474
 *                         "multiple '%s' lines are not permitted" % record)
 * 
 *                 result[record] = x             # <<<<<<<<<<<<<<
 *             elif VALID_HEADER_TYPES[record] == Sequence:
 *                 if record not in result: result[record] = []
 */
      if (unlikely((PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_v_x) < 0))) __PYX_ERR(0, 474, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":469
 *                 x[key] = KNOWN_HEADER_FIELDS[record].get(key, str)(value)
 * 
 *             if VALID_HEADER_TYPES[record] == Mapping:             # <<<<<<<<<<<<<<
 *                 if record in result:
 *                     raise ValueError(
 */
      goto __pyx_L15;
    }

    /* "pysam/libcalignmentfile.pyx":475
 * 
 *                 result[record] = x
 *             elif VALID_HEADER_TYPES[record] == Sequence:             # <<<<<<<<<<<<<<
 *                 if record not in result: result[record] = []
 *                 result[record].append(x)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_15 = __Pyx_PyObject_GetItem(__pyx_t_2, __pyx_v_record); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_15, __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 475, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_8) {

      /* "pysam/libcalignmentfile.pyx":476
 *                 result[record] = x
 *             elif VALID_HEADER_TYPES[record] == Sequence:
 *                 if record not in result: result[record] = []             # <<<<<<<<<<<<<<
 *                 result[record].append(x)
 * 
 */
      __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 476, __pyx_L1_error)
      if (__pyx_t_8) {
        __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 476, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely((PyObject_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_1) < 0))) __PYX_ERR(0, 476, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }

      /* "pysam/libcalignmentfile.pyx":477
 *             elif VALID_HEADER_TYPES[record] == Sequence:
 *                 if record not in result: result[record] = []
 *                 result[record].append(x)             # <<<<<<<<<<<<<<
 * 
 *         # if there are no SQ lines in the header, add the
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 477, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_12 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_v_x); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 477, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":475
 * 
 *                 result[record] = x
 *             elif VALID_HEADER_TYPES[record] == Sequence:             # <<<<<<<<<<<<<<
 *                 if record not in result: result[record] = []
 *                 result[record].append(x)
 */
    }
    __pyx_L15:;

    /* "pysam/libcalignmentfile.pyx":431
 *         # convert to python string
 *         t = self.__str__()
 *         for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *             line = line.strip(' \0')
 *             if not line:
 */
    __pyx_L3_continue:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/libcalignmentfile.pyx":488
 *         # the SQ information is not part of the textual header
 *         # and thus are missing from the output. See issue 84.
 *         if "SQ" not in result:             # <<<<<<<<<<<<<<
 *             sq = []
 *             for ref, length in zip(self.references, self.lengths):
 */
  __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_n_u_SQ_2, __pyx_v_result, Py_NE)); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 488, __pyx_L1_error)
  if (__pyx_t_8) {

    /* "pysam/libcalignmentfile.pyx":489
 *         # and thus are missing from the output. See issue 84.
 *         if "SQ" not in result:
 *             sq = []             # <<<<<<<<<<<<<<
 *             for ref, length in zip(self.references, self.lengths):
 *                 sq.append({'LN': length, 'SN': ref })
 */
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 489, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_sq = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":490
 *         if "SQ" not in result:
 *             sq = []
 *             for ref, length in zip(self.references, self.lengths):             # <<<<<<<<<<<<<<
 *                 sq.append({'LN': length, 'SN': ref })
 *             result["SQ"] = sq
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_lengths); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_1);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error);
    __pyx_t_3 = 0;
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2);
      __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 490, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 490, __pyx_L1_error)
            #endif
            if (__pyx_t_5 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 490, __pyx_L1_error)
          #else
          __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 490, __pyx_L1_error)
            #endif
            if (__pyx_t_5 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 490, __pyx_L1_error)
          #else
          __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 490, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_6(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 490, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 490, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_15);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 490, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 490, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 490, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_17 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_7);
        index = 0; __pyx_t_3 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L22_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_15 = __pyx_t_17(__pyx_t_7); if (unlikely(!__pyx_t_15)) goto __pyx_L22_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_15);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_7), 2) < 0) __PYX_ERR(0, 490, __pyx_L1_error)
        __pyx_t_17 = NULL;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L23_unpacking_done;
        __pyx_L22_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_17 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 490, __pyx_L1_error)
        __pyx_L23_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_15);
      __pyx_t_15 = 0;

      /* "pysam/libcalignmentfile.pyx":491
 *             sq = []
 *             for ref, length in zip(self.references, self.lengths):
 *                 sq.append({'LN': length, 'SN': ref })             # <<<<<<<<<<<<<<
 *             result["SQ"] = sq
 * 
 */
      __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 491, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_LN, __pyx_v_length) < 0) __PYX_ERR(0, 491, __pyx_L1_error)
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_u_SN, __pyx_v_ref) < 0) __PYX_ERR(0, 491, __pyx_L1_error)
      __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_sq, __pyx_t_1); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 491, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":490
 *         if "SQ" not in result:
 *             sq = []
 *             for ref, length in zip(self.references, self.lengths):             # <<<<<<<<<<<<<<
 *                 sq.append({'LN': length, 'SN': ref })
 *             result["SQ"] = sq
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":492
 *             for ref, length in zip(self.references, self.lengths):
 *                 sq.append({'LN': length, 'SN': ref })
 *             result["SQ"] = sq             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
    if (unlikely((PyObject_SetItem(__pyx_v_result, __pyx_n_u_SQ_2, __pyx_v_sq) < 0))) __PYX_ERR(0, 492, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":488
 *         # the SQ information is not part of the textual header
 *         # and thus are missing from the output. See issue 84.
 *         if "SQ" not in result:             # <<<<<<<<<<<<<<
 *             sq = []
 *             for ref, length in zip(self.references, self.lengths):
 */
  }

  /* "pysam/libcalignmentfile.pyx":494
 *             result["SQ"] = sq
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def as_dict(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":404
 *         return "".join(text)
 * 
 *     def to_dict(self):             # <<<<<<<<<<<<<<
 *         """return two-level dictionary with header information from the file.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.to_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_idx);
  __Pyx_XDECREF(__pyx_v_field);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_sq);
  __Pyx_XDECREF(__pyx_v_ref);
  __Pyx_XDECREF(__pyx_v_length);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":496
 *         return result
 * 
 *     def as_dict(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict, "AlignmentHeader.as_dict(self)\ndeprecated, use :meth:`to_dict()` instead");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict = {"as_dict", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("as_dict (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("as_dict", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "as_dict", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__24)
  __Pyx_RefNannySetupContext("as_dict", 1);
  __Pyx_TraceCall("as_dict", __pyx_f[0], 496, 0, __PYX_ERR(0, 496, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":498
 *     def as_dict(self):
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_name(self, tid):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 498, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 498, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":496
 *         return result
 * 
 *     def as_dict(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.as_dict", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":500
 *         return self.to_dict()
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         if tid == -1:
 *             return None
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name, "AlignmentHeader.get_reference_name(self, tid)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name = {"get_reference_name", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_tid = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tid,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 500, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_reference_name") < 0)) __PYX_ERR(0, 500, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_tid = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_reference_name", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 500, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v_tid);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__25)
  __Pyx_RefNannySetupContext("get_reference_name", 1);
  __Pyx_TraceCall("get_reference_name", __pyx_f[0], 500, 0, __PYX_ERR(0, 500, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":501
 * 
 *     def get_reference_name(self, tid):
 *         if tid == -1:             # <<<<<<<<<<<<<<
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:
 */
  __pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_tid, __pyx_int_neg_1, -1L, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 501, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":502
 *     def get_reference_name(self, tid):
 *         if tid == -1:
 *             return None             # <<<<<<<<<<<<<<
 *         if not 0 <= tid < self.ptr.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":501
 * 
 *     def get_reference_name(self, tid):
 *         if tid == -1:             # <<<<<<<<<<<<<<
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:
 */
  }

  /* "pysam/libcalignmentfile.pyx":503
 *         if tid == -1:
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:             # <<<<<<<<<<<<<<
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_int_0, __pyx_v_tid, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 503, __pyx_L1_error)
  if (__Pyx_PyObject_IsTrue(__pyx_t_2)) {
    __Pyx_DECREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyObject_RichCompare(__pyx_v_tid, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = (!__pyx_t_1);
  if (unlikely(__pyx_t_4)) {

    /* "pysam/libcalignmentfile.pyx":505
 *         if not 0 <= tid < self.ptr.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))             # <<<<<<<<<<<<<<
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_self->ptr->n_targets); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 505, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 505, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_tid);
    __Pyx_GIVEREF(__pyx_v_tid);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_tid)) __PYX_ERR(0, 505, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_2);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2)) __PYX_ERR(0, 505, __pyx_L1_error);
    __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":504
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %             # <<<<<<<<<<<<<<
 *                              (tid, self.ptr.n_targets))
 *         return charptr_to_str(self.ptr.target_name[tid])
 */
    __pyx_t_2 = PyUnicode_Format(__pyx_kp_u_reference_id_i_out_of_range_0_ti, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 504, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 504, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 504, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":503
 *         if tid == -1:
 *             return None
 *         if not 0 <= tid < self.ptr.n_targets:             # <<<<<<<<<<<<<<
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))
 */
  }

  /* "pysam/libcalignmentfile.pyx":506
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.ptr.n_targets))
 *         return charptr_to_str(self.ptr.target_name[tid])             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_length(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_tid); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 506, __pyx_L1_error)
  __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str((__pyx_v_self->ptr->target_name[__pyx_t_5]), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":500
 *         return self.to_dict()
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         if tid == -1:
 *             return None
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":508
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length, "AlignmentHeader.get_reference_length(self, reference)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length = {"get_reference_length", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_reference = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_length (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 508, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_reference_length") < 0)) __PYX_ERR(0, 508, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_reference = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_reference_length", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 508, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v_reference);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference) {
  int __pyx_v_tid;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__26)
  __Pyx_RefNannySetupContext("get_reference_length", 1);
  __Pyx_TraceCall("get_reference_length", __pyx_f[0], 508, 0, __PYX_ERR(0, 508, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":509
 * 
 *     def get_reference_length(self, reference):
 *         cdef int tid = self.get_tid(reference)             # <<<<<<<<<<<<<<
 *         if tid < 0:
 *             raise KeyError("unknown reference {}".format(reference))
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_reference};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 509, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 509, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_tid = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":510
 *     def get_reference_length(self, reference):
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:             # <<<<<<<<<<<<<<
 *             raise KeyError("unknown reference {}".format(reference))
 *         else:
 */
  __pyx_t_6 = (__pyx_v_tid < 0);
  if (unlikely(__pyx_t_6)) {

    /* "pysam/libcalignmentfile.pyx":511
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:
 *             raise KeyError("unknown reference {}".format(reference))             # <<<<<<<<<<<<<<
 *         else:
 *             return self.ptr.target_len[tid]
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_unknown_reference, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_reference};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 511, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 511, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 511, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":510
 *     def get_reference_length(self, reference):
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:             # <<<<<<<<<<<<<<
 *             raise KeyError("unknown reference {}".format(reference))
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":513
 *             raise KeyError("unknown reference {}".format(reference))
 *         else:
 *             return self.ptr.target_len[tid]             # <<<<<<<<<<<<<<
 * 
 *     def is_valid_tid(self, int tid):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->ptr->target_len[__pyx_v_tid])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 513, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/libcalignmentfile.pyx":508
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":515
 *             return self.ptr.target_len[tid]
 * 
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid, "AlignmentHeader.is_valid_tid(self, int tid)\n\n        return True if the numerical :term:`tid` is valid; False otherwise.\n\n        Note that the unmapped tid code (-1) counts as an invalid.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid = {"is_valid_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_tid;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tid,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 515, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "is_valid_tid") < 0)) __PYX_ERR(0, 515, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_tid = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 515, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("is_valid_tid", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 515, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v_tid);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, int __pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__27)
  __Pyx_RefNannySetupContext("is_valid_tid", 1);
  __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 515, 0, __PYX_ERR(0, 515, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":521
 *         Note that the unmapped tid code (-1) counts as an invalid.
 *         """
 *         return 0 <= tid < self.ptr.n_targets             # <<<<<<<<<<<<<<
 * 
 *     def get_tid(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = (0 <= __pyx_v_tid);
  if (__pyx_t_1) {
    __pyx_t_1 = (__pyx_v_tid < __pyx_v_self->ptr->n_targets);
  }
  __pyx_t_2 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 521, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":515
 *             return self.ptr.target_len[tid]
 * 
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":523
 *         return 0 <= tid < self.ptr.n_targets
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid, "AlignmentHeader.get_tid(self, reference)\n\n        return the numerical :term:`tid` corresponding to\n        :term:`reference`\n\n        returns -1 if reference is not known.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid = {"get_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_reference = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tid (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 523, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_tid") < 0)) __PYX_ERR(0, 523, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_reference = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_tid", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 523, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v_reference);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_reference) {
  int __pyx_v_tid;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  char const *__pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__28)
  __Pyx_RefNannySetupContext("get_tid", 0);
  __Pyx_TraceCall("get_tid", __pyx_f[0], 523, 0, __PYX_ERR(0, 523, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_reference);

  /* "pysam/libcalignmentfile.pyx":530
 *         returns -1 if reference is not known.
 *         """
 *         reference = force_bytes(reference)             # <<<<<<<<<<<<<<
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:
 */
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_reference, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_reference, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":531
 *         """
 *         reference = force_bytes(reference)
 *         tid = bam_name2id(self.ptr, reference)             # <<<<<<<<<<<<<<
 *         if tid < -1:
 *             raise ValueError('could not parse header')
 */
  __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_reference); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 531, __pyx_L1_error)
  __pyx_v_tid = bam_name2id(__pyx_v_self->ptr, __pyx_t_2);

  /* "pysam/libcalignmentfile.pyx":532
 *         reference = force_bytes(reference)
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:             # <<<<<<<<<<<<<<
 *             raise ValueError('could not parse header')
 *         return tid
 */
  __pyx_t_3 = (__pyx_v_tid < -1L);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":533
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:
 *             raise ValueError('could not parse header')             # <<<<<<<<<<<<<<
 *         return tid
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 533, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 533, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":532
 *         reference = force_bytes(reference)
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:             # <<<<<<<<<<<<<<
 *             raise ValueError('could not parse header')
 *         return tid
 */
  }

  /* "pysam/libcalignmentfile.pyx":534
 *         if tid < -1:
 *             raise ValueError('could not parse header')
 *         return tid             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 534, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":523
 *         return 0 <= tid < self.ptr.n_targets
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_reference);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":536
 *         return tid
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         '''string with the full contents of the :term:`sam file` header as a
 *         string.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__(PyObject *__pyx_v_self); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__, "string with the full contents of the :term:`sam file` header as a\n        string.\n\n        If no @SQ entries are within the text section of the header,\n        this will be automatically added from the reference names and\n        lengths stored in the binary part of the header.\n\n        See :attr:`pysam.AlignmentFile.header.to_dict()` to get a parsed\n        representation of the header.\n        ");
#if CYTHON_UPDATE_DESCRIPTOR_DOC
struct wrapperbase __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__;
#endif
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 1);
  __Pyx_TraceCall("__str__", __pyx_f[0], 536, 0, __PYX_ERR(0, 536, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":547
 *         representation of the header.
 *         '''
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)             # <<<<<<<<<<<<<<
 *         if "@SQ" not in text:
 *             text += "\n" + self._build_sequence_section()
 */
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size(__pyx_v_self->ptr->text, __pyx_v_self->ptr->l_text); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 547, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_text = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":548
 *         '''
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)
 *         if "@SQ" not in text:             # <<<<<<<<<<<<<<
 *             text += "\n" + self._build_sequence_section()
 *         return text
 */
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u_SQ, __pyx_v_text, Py_NE)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 548, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":549
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)
 *         if "@SQ" not in text:
 *             text += "\n" + self._build_sequence_section()             # <<<<<<<<<<<<<<
 *         return text
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_build_sequence_section); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    __pyx_t_5 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_5 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 549, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_3 = PyNumber_Add(__pyx_kp_u__12, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_text, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":548
 *         '''
 *         text = from_string_and_size(self.ptr.text, self.ptr.l_text)
 *         if "@SQ" not in text:             # <<<<<<<<<<<<<<
 *             text += "\n" + self._build_sequence_section()
 *         return text
 */
  }

  /* "pysam/libcalignmentfile.pyx":550
 *         if "@SQ" not in text:
 *             text += "\n" + self._build_sequence_section()
 *         return text             # <<<<<<<<<<<<<<
 * 
 *     # dictionary access methods, for backwards compatibility.
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_text);
  __pyx_r = __pyx_v_text;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":536
 *         return tid
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         '''string with the full contents of the :term:`sam file` header as a
 *         string.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":553
 * 
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):             # <<<<<<<<<<<<<<
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_value) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key), ((PyObject *)__pyx_v_value));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_34__setitem__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_key, CYTHON_UNUSED PyObject *__pyx_v_value) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__setitem__", 1);
  __Pyx_TraceCall("__setitem__", __pyx_f[0], 553, 0, __PYX_ERR(0, 553, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":554
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, key):
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 554, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":553
 * 
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):             # <<<<<<<<<<<<<<
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":556
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 *     def __getitem__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__getitem__(key)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_36__getitem__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getitem__", 1);
  __Pyx_TraceCall("__getitem__", __pyx_f[0], 556, 0, __PYX_ERR(0, 556, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":557
 * 
 *     def __getitem__(self, key):
 *         return self.to_dict().__getitem__(key)             # <<<<<<<<<<<<<<
 * 
 *     def items(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 557, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_getitem); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 557, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_key};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 557, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":556
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")
 * 
 *     def __getitem__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__getitem__(key)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":559
 *         return self.to_dict().__getitem__(key)
 * 
 *     def items(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_38items, "AlignmentHeader.items(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_39items = {"items", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_38items};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("items (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("items", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "items", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_38items(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__31)
  __Pyx_RefNannySetupContext("items", 1);
  __Pyx_TraceCall("items", __pyx_f[0], 559, 0, __PYX_ERR(0, 559, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":560
 * 
 *     def items(self):
 *         return self.to_dict().items()             # <<<<<<<<<<<<<<
 * 
 *     # PY2 compatibility
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":559
 *         return self.to_dict().__getitem__(key)
 * 
 *     def items(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.items", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":563
 * 
 *     # PY2 compatibility
 *     def iteritems(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems, "AlignmentHeader.iteritems(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems = {"iteritems", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("iteritems (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("iteritems", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "iteritems", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__32)
  __Pyx_RefNannySetupContext("iteritems", 1);
  __Pyx_TraceCall("iteritems", __pyx_f[0], 563, 0, __PYX_ERR(0, 563, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":564
 *     # PY2 compatibility
 *     def iteritems(self):
 *         return self.to_dict().items()             # <<<<<<<<<<<<<<
 * 
 *     def keys(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_items); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 564, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":563
 * 
 *     # PY2 compatibility
 *     def iteritems(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.iteritems", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":566
 *         return self.to_dict().items()
 * 
 *     def keys(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().keys()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_42keys, "AlignmentHeader.keys(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_43keys = {"keys", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_42keys};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("keys (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("keys", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "keys", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_42keys(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__33)
  __Pyx_RefNannySetupContext("keys", 1);
  __Pyx_TraceCall("keys", __pyx_f[0], 566, 0, __PYX_ERR(0, 566, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":567
 * 
 *     def keys(self):
 *         return self.to_dict().keys()             # <<<<<<<<<<<<<<
 * 
 *     def values(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_keys); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 567, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":566
 *         return self.to_dict().items()
 * 
 *     def keys(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().keys()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.keys", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":569
 *         return self.to_dict().keys()
 * 
 *     def values(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().values()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_44values, "AlignmentHeader.values(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_45values = {"values", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_44values};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("values (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("values", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "values", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_44values(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__34)
  __Pyx_RefNannySetupContext("values", 1);
  __Pyx_TraceCall("values", __pyx_f[0], 569, 0, __PYX_ERR(0, 569, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":570
 * 
 *     def values(self):
 *         return self.to_dict().values()             # <<<<<<<<<<<<<<
 * 
 *     def get(self, *args):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 570, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_values); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 570, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 570, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":569
 *         return self.to_dict().keys()
 * 
 *     def values(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().values()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.values", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":572
 *         return self.to_dict().values()
 * 
 *     def get(self, *args):             # <<<<<<<<<<<<<<
 *         return self.to_dict().get(*args)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_46get, "AlignmentHeader.get(self, *args)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_47get = {"get", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_46get};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_VARARGS(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "get", 0))) return NULL;
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v_args);

  /* function exit code */
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_46get(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_args) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__35)
  __Pyx_RefNannySetupContext("get", 1);
  __Pyx_TraceCall("get", __pyx_f[0], 572, 0, __PYX_ERR(0, 572, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":573
 * 
 *     def get(self, *args):
 *         return self.to_dict().get(*args)             # <<<<<<<<<<<<<<
 * 
 *     def __len__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_get); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_v_args, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":572
 *         return self.to_dict().values()
 * 
 *     def get(self, *args):             # <<<<<<<<<<<<<<
 *         return self.to_dict().get(*args)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.get", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":575
 *         return self.to_dict().get(*args)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__len__()
 * 
 */

/* Python wrapper */
static Py_ssize_t __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static Py_ssize_t __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_48__len__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__len__", 1);
  __Pyx_TraceCall("__len__", __pyx_f[0], 575, 0, __PYX_ERR(0, 575, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":576
 * 
 *     def __len__(self):
 *         return self.to_dict().__len__()             # <<<<<<<<<<<<<<
 * 
 *     def __contains__(self, key):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 576, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_6;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":575
 *         return self.to_dict().get(*args)
 * 
 *     def __len__(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__len__()
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__len__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":578
 *         return self.to_dict().__len__()
 * 
 *     def __contains__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__contains__(key)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), ((PyObject *)__pyx_v_key));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_50__contains__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, PyObject *__pyx_v_key) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__contains__", 1);
  __Pyx_TraceCall("__contains__", __pyx_f[0], 578, 0, __PYX_ERR(0, 578, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":579
 * 
 *     def __contains__(self, key):
 *         return self.to_dict().__contains__(key)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_to_dict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_contains); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_key};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_6;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":578
 *         return self.to_dict().__len__()
 * 
 *     def __contains__(self, key):             # <<<<<<<<<<<<<<
 *         return self.to_dict().__contains__(key)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__, "AlignmentHeader.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__36)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__, "AlignmentHeader.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__37)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentHeader.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":738
 *     """
 * 
 *     def __cinit__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         self.htsfile = NULL
 *         self.filename = None
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 1))) return -1;
  if (unlikely(__pyx_kwds)) {
    __pyx_v_kwargs = __Pyx_KwargsAsDict_VARARGS(__pyx_kwds, __pyx_kwvalues);
    if (unlikely(!__pyx_v_kwargs)) return -1;
    __Pyx_GOTREF(__pyx_v_kwargs);
  } else {
    __pyx_v_kwargs = PyDict_New();
    if (unlikely(!__pyx_v_kwargs)) return -1;
    __Pyx_GOTREF(__pyx_v_kwargs);
  }
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);

  /* function exit code */
  __Pyx_DECREF(__pyx_v_args);
  __Pyx_DECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  unsigned int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 738, 0, __PYX_ERR(0, 738, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_args);

  /* "pysam/libcalignmentfile.pyx":739
 * 
 *     def __cinit__(self, *args, **kwargs):
 *         self.htsfile = NULL             # <<<<<<<<<<<<<<
 *         self.filename = None
 *         self.mode = None
 */
  __pyx_v_self->__pyx_base.htsfile = NULL;

  /* "pysam/libcalignmentfile.pyx":740
 *     def __cinit__(self, *args, **kwargs):
 *         self.htsfile = NULL
 *         self.filename = None             # <<<<<<<<<<<<<<
 *         self.mode = None
 *         self.threads = 1
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
  __pyx_v_self->__pyx_base.filename = Py_None;

  /* "pysam/libcalignmentfile.pyx":741
 *         self.htsfile = NULL
 *         self.filename = None
 *         self.mode = None             # <<<<<<<<<<<<<<
 *         self.threads = 1
 *         self.is_stream = False
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.mode);
  __pyx_v_self->__pyx_base.mode = Py_None;

  /* "pysam/libcalignmentfile.pyx":742
 *         self.filename = None
 *         self.mode = None
 *         self.threads = 1             # <<<<<<<<<<<<<<
 *         self.is_stream = False
 *         self.is_remote = False
 */
  __Pyx_INCREF(__pyx_int_1);
  __Pyx_GIVEREF(__pyx_int_1);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.threads);
  __pyx_v_self->__pyx_base.threads = __pyx_int_1;

  /* "pysam/libcalignmentfile.pyx":743
 *         self.mode = None
 *         self.threads = 1
 *         self.is_stream = False             # <<<<<<<<<<<<<<
 *         self.is_remote = False
 *         self.index = NULL
 */
  __pyx_v_self->__pyx_base.is_stream = 0;

  /* "pysam/libcalignmentfile.pyx":744
 *         self.threads = 1
 *         self.is_stream = False
 *         self.is_remote = False             # <<<<<<<<<<<<<<
 *         self.index = NULL
 * 
 */
  __pyx_v_self->__pyx_base.is_remote = 0;

  /* "pysam/libcalignmentfile.pyx":745
 *         self.is_stream = False
 *         self.is_remote = False
 *         self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *         if "filename" in kwargs:
 */
  __pyx_v_self->index = NULL;

  /* "pysam/libcalignmentfile.pyx":747
 *         self.index = NULL
 * 
 *         if "filename" in kwargs:             # <<<<<<<<<<<<<<
 *             args = [kwargs["filename"]]
 *             del kwargs["filename"]
 */
  __pyx_t_1 = (__Pyx_PyDict_ContainsTF(__pyx_n_u_filename, __pyx_v_kwargs, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 747, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":748
 * 
 *         if "filename" in kwargs:
 *             args = [kwargs["filename"]]             # <<<<<<<<<<<<<<
 *             del kwargs["filename"]
 * 
 */
    __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_kwargs, __pyx_n_u_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 748, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_2)) __PYX_ERR(0, 748, __pyx_L1_error);
    __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":749
 *         if "filename" in kwargs:
 *             args = [kwargs["filename"]]
 *             del kwargs["filename"]             # <<<<<<<<<<<<<<
 * 
 *         self._open(*args, **kwargs)
 */
    if (unlikely((PyDict_DelItem(__pyx_v_kwargs, __pyx_n_u_filename) < 0))) __PYX_ERR(0, 749, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":747
 *         self.index = NULL
 * 
 *         if "filename" in kwargs:             # <<<<<<<<<<<<<<
 *             args = [kwargs["filename"]]
 *             del kwargs["filename"]
 */
  }

  /* "pysam/libcalignmentfile.pyx":751
 *             del kwargs["filename"]
 * 
 *         self._open(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *         # allocate memory for iterator
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":754
 * 
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
 *         if self.b == NULL:
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 */
  __pyx_v_self->b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/libcalignmentfile.pyx":755
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 *         if self.b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 */
  __pyx_t_1 = (__pyx_v_self->b == NULL);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":756
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 *         if self.b == NULL:
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))             # <<<<<<<<<<<<<<
 * 
 *     def has_index(self):
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_allocate_memory_of_siz, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyInt_FromSize_t((sizeof(bam1_t))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    __pyx_t_6 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_6 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_2};
      __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 756, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 756, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":755
 *         # allocate memory for iterator
 *         self.b = <bam1_t*>calloc(1, sizeof(bam1_t))
 *         if self.b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":738
 *     """
 * 
 *     def __cinit__(self, *args, **kwargs):             # <<<<<<<<<<<<<<
 *         self.htsfile = NULL
 *         self.filename = None
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":758
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 *     def has_index(self):             # <<<<<<<<<<<<<<
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index, "AlignmentFile.has_index(self)\nreturn true if htsfile has an existing (and opened) index.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_3has_index = {"has_index", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("has_index (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("has_index", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "has_index", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_2has_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__38)
  __Pyx_RefNannySetupContext("has_index", 1);
  __Pyx_TraceCall("has_index", __pyx_f[0], 758, 0, __PYX_ERR(0, 758, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":761
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 *         return self.index != NULL             # <<<<<<<<<<<<<<
 * 
 *     def check_index(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_self->index != NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":758
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 *     def has_index(self):             # <<<<<<<<<<<<<<
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.has_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":763
 *         return self.index != NULL
 * 
 *     def check_index(self):             # <<<<<<<<<<<<<<
 *         """return True if index is present.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index, "AlignmentFile.check_index(self)\nreturn True if index is present.\n\n        Raises\n        ------\n\n        AttributeError\n            if htsfile is :term:`SAM` formatted and thus has no index.\n\n        ValueError\n            if htsfile is closed or index could not be opened.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_5check_index = {"check_index", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("check_index (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("check_index", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "check_index", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4check_index(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__39)
  __Pyx_RefNannySetupContext("check_index", 1);
  __Pyx_TraceCall("check_index", __pyx_f[0], 763, 0, __PYX_ERR(0, 763, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":776
 *         """
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":777
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 777, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":776
 *         """
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 */
  }

  /* "pysam/libcalignmentfile.pyx":778
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:             # <<<<<<<<<<<<<<
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = (!__pyx_t_2);
  if (__pyx_t_4) {
  } else {
    __pyx_t_3 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 778, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_2 = (!__pyx_t_4);
  __pyx_t_3 = __pyx_t_2;
  __pyx_L5_bool_binop_done:;
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":779
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(             # <<<<<<<<<<<<<<
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_AttributeError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 779, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 779, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":778
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:             # <<<<<<<<<<<<<<
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 */
  }

  /* "pysam/libcalignmentfile.pyx":781
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "mapping information not recorded in index "
 */
  __pyx_t_3 = (__pyx_v_self->index == NULL);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":782
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "mapping information not recorded in index "
 *                 "or index not available")
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 782, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":781
 *             raise AttributeError(
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "mapping information not recorded in index "
 */
  }

  /* "pysam/libcalignmentfile.pyx":785
 *                 "mapping information not recorded in index "
 *                 "or index not available")
 *         return True             # <<<<<<<<<<<<<<
 * 
 *     def _open(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_True);
  __pyx_r = Py_True;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":763
 *         return self.index != NULL
 * 
 *     def check_index(self):             # <<<<<<<<<<<<<<
 *         """return True if index is present.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.check_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               mode=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open, "AlignmentFile._open(self, filepath_or_object, mode=None, AlignmentFile template=None, reference_names=None, reference_lengths=None, reference_filename=None, text=None, header=None, port=None, add_sq_text=True, add_sam_header=True, check_header=True, check_sq=True, index_filename=None, filepath_index=None, require_index=False, referencenames=None, referencelengths=None, duplicate_filehandle=True, ignore_truncation=False, format_options=None, threads=1)\nopen a sam, bam or cram formatted file.\n\n        If _open is called on an existing file, the current file\n        will be closed and a new file will be opened.\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_7_open = {"_open", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_filepath_or_object = 0;
  PyObject *__pyx_v_mode = 0;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template = 0;
  PyObject *__pyx_v_reference_names = 0;
  PyObject *__pyx_v_reference_lengths = 0;
  PyObject *__pyx_v_reference_filename = 0;
  PyObject *__pyx_v_text = 0;
  PyObject *__pyx_v_header = 0;
  CYTHON_UNUSED PyObject *__pyx_v_port = 0;
  PyObject *__pyx_v_add_sq_text = 0;
  PyObject *__pyx_v_add_sam_header = 0;
  CYTHON_UNUSED PyObject *__pyx_v_check_header = 0;
  PyObject *__pyx_v_check_sq = 0;
  PyObject *__pyx_v_index_filename = 0;
  PyObject *__pyx_v_filepath_index = 0;
  PyObject *__pyx_v_require_index = 0;
  PyObject *__pyx_v_referencenames = 0;
  PyObject *__pyx_v_referencelengths = 0;
  PyObject *__pyx_v_duplicate_filehandle = 0;
  PyObject *__pyx_v_ignore_truncation = 0;
  PyObject *__pyx_v_format_options = 0;
  PyObject *__pyx_v_threads = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_open (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filepath_or_object,&__pyx_n_s_mode,&__pyx_n_s_template,&__pyx_n_s_reference_names,&__pyx_n_s_reference_lengths,&__pyx_n_s_reference_filename,&__pyx_n_s_text,&__pyx_n_s_header,&__pyx_n_s_port,&__pyx_n_s_add_sq_text,&__pyx_n_s_add_sam_header,&__pyx_n_s_check_header,&__pyx_n_s_check_sq,&__pyx_n_s_index_filename,&__pyx_n_s_filepath_index,&__pyx_n_s_require_index,&__pyx_n_s_referencenames,&__pyx_n_s_referencelengths,&__pyx_n_s_duplicate_filehandle,&__pyx_n_s_ignore_truncation,&__pyx_n_s_format_options,&__pyx_n_s_threads,0};

    /* "pysam/libcalignmentfile.pyx":789
 *     def _open(self,
 *               filepath_or_object,
 *               mode=None,             # <<<<<<<<<<<<<<
 *               AlignmentFile template=None,
 *               reference_names=None,
 */
    values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":790
 *               filepath_or_object,
 *               mode=None,
 *               AlignmentFile template=None,             # <<<<<<<<<<<<<<
 *               reference_names=None,
 *               reference_lengths=None,
 */
    values[2] = __Pyx_Arg_NewRef_FASTCALL((PyObject *)((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None));

    /* "pysam/libcalignmentfile.pyx":791
 *               mode=None,
 *               AlignmentFile template=None,
 *               reference_names=None,             # <<<<<<<<<<<<<<
 *               reference_lengths=None,
 *               reference_filename=None,
 */
    values[3] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":792
 *               AlignmentFile template=None,
 *               reference_names=None,
 *               reference_lengths=None,             # <<<<<<<<<<<<<<
 *               reference_filename=None,
 *               text=None,
 */
    values[4] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":793
 *               reference_names=None,
 *               reference_lengths=None,
 *               reference_filename=None,             # <<<<<<<<<<<<<<
 *               text=None,
 *               header=None,
 */
    values[5] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":794
 *               reference_lengths=None,
 *               reference_filename=None,
 *               text=None,             # <<<<<<<<<<<<<<
 *               header=None,
 *               port=None,
 */
    values[6] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":795
 *               reference_filename=None,
 *               text=None,
 *               header=None,             # <<<<<<<<<<<<<<
 *               port=None,
 *               add_sq_text=True,
 */
    values[7] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":796
 *               text=None,
 *               header=None,
 *               port=None,             # <<<<<<<<<<<<<<
 *               add_sq_text=True,
 *               add_sam_header=True,
 */
    values[8] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":797
 *               header=None,
 *               port=None,
 *               add_sq_text=True,             # <<<<<<<<<<<<<<
 *               add_sam_header=True,
 *               check_header=True,
 */
    values[9] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_True));

    /* "pysam/libcalignmentfile.pyx":798
 *               port=None,
 *               add_sq_text=True,
 *               add_sam_header=True,             # <<<<<<<<<<<<<<
 *               check_header=True,
 *               check_sq=True,
 */
    values[10] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_True));

    /* "pysam/libcalignmentfile.pyx":799
 *               add_sq_text=True,
 *               add_sam_header=True,
 *               check_header=True,             # <<<<<<<<<<<<<<
 *               check_sq=True,
 *               index_filename=None,
 */
    values[11] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_True));

    /* "pysam/libcalignmentfile.pyx":800
 *               add_sam_header=True,
 *               check_header=True,
 *               check_sq=True,             # <<<<<<<<<<<<<<
 *               index_filename=None,
 *               filepath_index=None,
 */
    values[12] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_True));

    /* "pysam/libcalignmentfile.pyx":801
 *               check_header=True,
 *               check_sq=True,
 *               index_filename=None,             # <<<<<<<<<<<<<<
 *               filepath_index=None,
 *               require_index=False,
 */
    values[13] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":802
 *               check_sq=True,
 *               index_filename=None,
 *               filepath_index=None,             # <<<<<<<<<<<<<<
 *               require_index=False,
 *               referencenames=None,
 */
    values[14] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":803
 *               index_filename=None,
 *               filepath_index=None,
 *               require_index=False,             # <<<<<<<<<<<<<<
 *               referencenames=None,
 *               referencelengths=None,
 */
    values[15] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_False));

    /* "pysam/libcalignmentfile.pyx":804
 *               filepath_index=None,
 *               require_index=False,
 *               referencenames=None,             # <<<<<<<<<<<<<<
 *               referencelengths=None,
 *               duplicate_filehandle=True,
 */
    values[16] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":805
 *               require_index=False,
 *               referencenames=None,
 *               referencelengths=None,             # <<<<<<<<<<<<<<
 *               duplicate_filehandle=True,
 *               ignore_truncation=False,
 */
    values[17] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":806
 *               referencenames=None,
 *               referencelengths=None,
 *               duplicate_filehandle=True,             # <<<<<<<<<<<<<<
 *               ignore_truncation=False,
 *               format_options=None,
 */
    values[18] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_True));

    /* "pysam/libcalignmentfile.pyx":807
 *               referencelengths=None,
 *               duplicate_filehandle=True,
 *               ignore_truncation=False,             # <<<<<<<<<<<<<<
 *               format_options=None,
 *               threads=1):
 */
    values[19] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_False));

    /* "pysam/libcalignmentfile.pyx":808
 *               duplicate_filehandle=True,
 *               ignore_truncation=False,
 *               format_options=None,             # <<<<<<<<<<<<<<
 *               threads=1):
 *         '''open a sam, bam or cram formatted file.
 */
    values[20] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
    values[21] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)__pyx_int_1));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case 22: values[21] = __Pyx_Arg_FASTCALL(__pyx_args, 21);
        CYTHON_FALLTHROUGH;
        case 21: values[20] = __Pyx_Arg_FASTCALL(__pyx_args, 20);
        CYTHON_FALLTHROUGH;
        case 20: values[19] = __Pyx_Arg_FASTCALL(__pyx_args, 19);
        CYTHON_FALLTHROUGH;
        case 19: values[18] = __Pyx_Arg_FASTCALL(__pyx_args, 18);
        CYTHON_FALLTHROUGH;
        case 18: values[17] = __Pyx_Arg_FASTCALL(__pyx_args, 17);
        CYTHON_FALLTHROUGH;
        case 17: values[16] = __Pyx_Arg_FASTCALL(__pyx_args, 16);
        CYTHON_FALLTHROUGH;
        case 16: values[15] = __Pyx_Arg_FASTCALL(__pyx_args, 15);
        CYTHON_FALLTHROUGH;
        case 15: values[14] = __Pyx_Arg_FASTCALL(__pyx_args, 14);
        CYTHON_FALLTHROUGH;
        case 14: values[13] = __Pyx_Arg_FASTCALL(__pyx_args, 13);
        CYTHON_FALLTHROUGH;
        case 13: values[12] = __Pyx_Arg_FASTCALL(__pyx_args, 12);
        CYTHON_FALLTHROUGH;
        case 12: values[11] = __Pyx_Arg_FASTCALL(__pyx_args, 11);
        CYTHON_FALLTHROUGH;
        case 11: values[10] = __Pyx_Arg_FASTCALL(__pyx_args, 10);
        CYTHON_FALLTHROUGH;
        case 10: values[9] = __Pyx_Arg_FASTCALL(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = __Pyx_Arg_FASTCALL(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_filepath_or_object)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_mode);
          if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_template);
          if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference_names);
          if (value) { values[3] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference_lengths);
          if (value) { values[4] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference_filename);
          if (value) { values[5] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_text);
          if (value) { values[6] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_header);
          if (value) { values[7] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_port);
          if (value) { values[8] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  9:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_add_sq_text);
          if (value) { values[9] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 10:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_add_sam_header);
          if (value) { values[10] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 11:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_check_header);
          if (value) { values[11] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 12:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_check_sq);
          if (value) { values[12] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 13:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_index_filename);
          if (value) { values[13] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 14:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_filepath_index);
          if (value) { values[14] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 15:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_require_index);
          if (value) { values[15] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 16:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_referencenames);
          if (value) { values[16] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 17:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_referencelengths);
          if (value) { values[17] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 18:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_duplicate_filehandle);
          if (value) { values[18] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 19:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_ignore_truncation);
          if (value) { values[19] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 20:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_format_options);
          if (value) { values[20] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 21:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_threads);
          if (value) { values[21] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 787, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_open") < 0)) __PYX_ERR(0, 787, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case 22: values[21] = __Pyx_Arg_FASTCALL(__pyx_args, 21);
        CYTHON_FALLTHROUGH;
        case 21: values[20] = __Pyx_Arg_FASTCALL(__pyx_args, 20);
        CYTHON_FALLTHROUGH;
        case 20: values[19] = __Pyx_Arg_FASTCALL(__pyx_args, 19);
        CYTHON_FALLTHROUGH;
        case 19: values[18] = __Pyx_Arg_FASTCALL(__pyx_args, 18);
        CYTHON_FALLTHROUGH;
        case 18: values[17] = __Pyx_Arg_FASTCALL(__pyx_args, 17);
        CYTHON_FALLTHROUGH;
        case 17: values[16] = __Pyx_Arg_FASTCALL(__pyx_args, 16);
        CYTHON_FALLTHROUGH;
        case 16: values[15] = __Pyx_Arg_FASTCALL(__pyx_args, 15);
        CYTHON_FALLTHROUGH;
        case 15: values[14] = __Pyx_Arg_FASTCALL(__pyx_args, 14);
        CYTHON_FALLTHROUGH;
        case 14: values[13] = __Pyx_Arg_FASTCALL(__pyx_args, 13);
        CYTHON_FALLTHROUGH;
        case 13: values[12] = __Pyx_Arg_FASTCALL(__pyx_args, 12);
        CYTHON_FALLTHROUGH;
        case 12: values[11] = __Pyx_Arg_FASTCALL(__pyx_args, 11);
        CYTHON_FALLTHROUGH;
        case 11: values[10] = __Pyx_Arg_FASTCALL(__pyx_args, 10);
        CYTHON_FALLTHROUGH;
        case 10: values[9] = __Pyx_Arg_FASTCALL(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = __Pyx_Arg_FASTCALL(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_filepath_or_object = values[0];
    __pyx_v_mode = values[1];
    __pyx_v_template = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[2]);
    __pyx_v_reference_names = values[3];
    __pyx_v_reference_lengths = values[4];
    __pyx_v_reference_filename = values[5];
    __pyx_v_text = values[6];
    __pyx_v_header = values[7];
    __pyx_v_port = values[8];
    __pyx_v_add_sq_text = values[9];
    __pyx_v_add_sam_header = values[10];
    __pyx_v_check_header = values[11];
    __pyx_v_check_sq = values[12];
    __pyx_v_index_filename = values[13];
    __pyx_v_filepath_index = values[14];
    __pyx_v_require_index = values[15];
    __pyx_v_referencenames = values[16];
    __pyx_v_referencelengths = values[17];
    __pyx_v_duplicate_filehandle = values[18];
    __pyx_v_ignore_truncation = values[19];
    __pyx_v_format_options = values[20];
    __pyx_v_threads = values[21];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 22, __pyx_nargs); __PYX_ERR(0, 787, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_template), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "template", 0))) __PYX_ERR(0, 790, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_filepath_or_object, __pyx_v_mode, __pyx_v_template, __pyx_v_reference_names, __pyx_v_reference_lengths, __pyx_v_reference_filename, __pyx_v_text, __pyx_v_header, __pyx_v_port, __pyx_v_add_sq_text, __pyx_v_add_sam_header, __pyx_v_check_header, __pyx_v_check_sq, __pyx_v_index_filename, __pyx_v_filepath_index, __pyx_v_require_index, __pyx_v_referencenames, __pyx_v_referencelengths, __pyx_v_duplicate_filehandle, __pyx_v_ignore_truncation, __pyx_v_format_options, __pyx_v_threads);

  /* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               mode=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filepath_or_object, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_template, PyObject *__pyx_v_reference_names, PyObject *__pyx_v_reference_lengths, PyObject *__pyx_v_reference_filename, PyObject *__pyx_v_text, PyObject *__pyx_v_header, CYTHON_UNUSED PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_add_sam_header, CYTHON_UNUSED PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_index_filename, PyObject *__pyx_v_filepath_index, PyObject *__pyx_v_require_index, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths, PyObject *__pyx_v_duplicate_filehandle, PyObject *__pyx_v_ignore_truncation, PyObject *__pyx_v_format_options, PyObject *__pyx_v_threads) {
  char *__pyx_v_cfilename;
  char *__pyx_v_creference_filename;
  char *__pyx_v_cindexname;
  CYTHON_UNUSED char *__pyx_v_cmode;
  bam_hdr_t *__pyx_v_hdr;
  PyObject *__pyx_v_filename = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_bfile_name = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  unsigned int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  char *__pyx_t_10;
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  htsFile *__pyx_t_13;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  Py_ssize_t __pyx_t_16;
  char const *__pyx_t_17;
  bam_hdr_t *__pyx_t_18;
  int64_t __pyx_t_19;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__43)
  __Pyx_RefNannySetupContext("_open", 0);
  __Pyx_TraceCall("_open", __pyx_f[0], 787, 0, __PYX_ERR(0, 787, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_mode);
  __Pyx_INCREF(__pyx_v_reference_names);
  __Pyx_INCREF(__pyx_v_reference_lengths);
  __Pyx_INCREF(__pyx_v_reference_filename);

  /* "pysam/libcalignmentfile.pyx":816
 * 
 *         '''
 *         cdef char *cfilename = NULL             # <<<<<<<<<<<<<<
 *         cdef char *creference_filename = NULL
 *         cdef char *cindexname = NULL
 */
  __pyx_v_cfilename = NULL;

  /* "pysam/libcalignmentfile.pyx":817
 *         '''
 *         cdef char *cfilename = NULL
 *         cdef char *creference_filename = NULL             # <<<<<<<<<<<<<<
 *         cdef char *cindexname = NULL
 *         cdef char *cmode = NULL
 */
  __pyx_v_creference_filename = NULL;

  /* "pysam/libcalignmentfile.pyx":818
 *         cdef char *cfilename = NULL
 *         cdef char *creference_filename = NULL
 *         cdef char *cindexname = NULL             # <<<<<<<<<<<<<<
 *         cdef char *cmode = NULL
 *         cdef bam_hdr_t * hdr = NULL
 */
  __pyx_v_cindexname = NULL;

  /* "pysam/libcalignmentfile.pyx":819
 *         cdef char *creference_filename = NULL
 *         cdef char *cindexname = NULL
 *         cdef char *cmode = NULL             # <<<<<<<<<<<<<<
 *         cdef bam_hdr_t * hdr = NULL
 * 
 */
  __pyx_v_cmode = NULL;

  /* "pysam/libcalignmentfile.pyx":820
 *         cdef char *cindexname = NULL
 *         cdef char *cmode = NULL
 *         cdef bam_hdr_t * hdr = NULL             # <<<<<<<<<<<<<<
 * 
 *         if threads > 1 and ignore_truncation:
 */
  __pyx_v_hdr = NULL;

  /* "pysam/libcalignmentfile.pyx":822
 *         cdef bam_hdr_t * hdr = NULL
 * 
 *         if threads > 1 and ignore_truncation:             # <<<<<<<<<<<<<<
 *            # This won't raise errors if reaching a truncated alignment,
 *            # because bgzf_mt_reader in htslib does not deal with
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_threads, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 822, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 822, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_ignore_truncation); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 822, __pyx_L1_error)
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":828
 *            # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888)
 *            # Better to avoid this (for now) than to produce seemingly correct results.
 *            raise ValueError('Cannot add extra threads when "ignore_truncation" is True')             # <<<<<<<<<<<<<<
 *         self.threads = threads
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 828, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 828, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":822
 *         cdef bam_hdr_t * hdr = NULL
 * 
 *         if threads > 1 and ignore_truncation:             # <<<<<<<<<<<<<<
 *            # This won't raise errors if reaching a truncated alignment,
 *            # because bgzf_mt_reader in htslib does not deal with
 */
  }

  /* "pysam/libcalignmentfile.pyx":829
 *            # Better to avoid this (for now) than to produce seemingly correct results.
 *            raise ValueError('Cannot add extra threads when "ignore_truncation" is True')
 *         self.threads = threads             # <<<<<<<<<<<<<<
 * 
 *         # for backwards compatibility:
 */
  __Pyx_INCREF(__pyx_v_threads);
  __Pyx_GIVEREF(__pyx_v_threads);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.threads);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.threads);
  __pyx_v_self->__pyx_base.threads = __pyx_v_threads;

  /* "pysam/libcalignmentfile.pyx":832
 * 
 *         # for backwards compatibility:
 *         if referencenames is not None:             # <<<<<<<<<<<<<<
 *             reference_names = referencenames
 *         if referencelengths is not None:
 */
  __pyx_t_1 = (__pyx_v_referencenames != Py_None);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":833
 *         # for backwards compatibility:
 *         if referencenames is not None:
 *             reference_names = referencenames             # <<<<<<<<<<<<<<
 *         if referencelengths is not None:
 *             reference_lengths = referencelengths
 */
    __Pyx_INCREF(__pyx_v_referencenames);
    __Pyx_DECREF_SET(__pyx_v_reference_names, __pyx_v_referencenames);

    /* "pysam/libcalignmentfile.pyx":832
 * 
 *         # for backwards compatibility:
 *         if referencenames is not None:             # <<<<<<<<<<<<<<
 *             reference_names = referencenames
 *         if referencelengths is not None:
 */
  }

  /* "pysam/libcalignmentfile.pyx":834
 *         if referencenames is not None:
 *             reference_names = referencenames
 *         if referencelengths is not None:             # <<<<<<<<<<<<<<
 *             reference_lengths = referencelengths
 * 
 */
  __pyx_t_1 = (__pyx_v_referencelengths != Py_None);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":835
 *             reference_names = referencenames
 *         if referencelengths is not None:
 *             reference_lengths = referencelengths             # <<<<<<<<<<<<<<
 * 
 *         # close a previously opened file
 */
    __Pyx_INCREF(__pyx_v_referencelengths);
    __Pyx_DECREF_SET(__pyx_v_reference_lengths, __pyx_v_referencelengths);

    /* "pysam/libcalignmentfile.pyx":834
 *         if referencenames is not None:
 *             reference_names = referencenames
 *         if referencelengths is not None:             # <<<<<<<<<<<<<<
 *             reference_lengths = referencelengths
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":838
 * 
 *         # close a previously opened file
 *         if self.is_open:             # <<<<<<<<<<<<<<
 *             self.close()
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 838, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 838, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":839
 *         # close a previously opened file
 *         if self.is_open:
 *             self.close()             # <<<<<<<<<<<<<<
 * 
 *         # autodetection for read
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 839, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    __pyx_t_6 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_6 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 839, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":838
 * 
 *         # close a previously opened file
 *         if self.is_open:             # <<<<<<<<<<<<<<
 *             self.close()
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":842
 * 
 *         # autodetection for read
 *         if mode is None:             # <<<<<<<<<<<<<<
 *             mode = "r"
 * 
 */
  __pyx_t_1 = (__pyx_v_mode == Py_None);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":843
 *         # autodetection for read
 *         if mode is None:
 *             mode = "r"             # <<<<<<<<<<<<<<
 * 
 *         if add_sam_header and mode == "w":
 */
    __Pyx_INCREF(__pyx_n_u_r);
    __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_u_r);

    /* "pysam/libcalignmentfile.pyx":842
 * 
 *         # autodetection for read
 *         if mode is None:             # <<<<<<<<<<<<<<
 *             mode = "r"
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":845
 *             mode = "r"
 * 
 *         if add_sam_header and mode == "w":             # <<<<<<<<<<<<<<
 *             mode = "wh"
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_add_sam_header); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 845, __pyx_L1_error)
  if (__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_w, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 845, __pyx_L1_error)
  __pyx_t_1 = __pyx_t_3;
  __pyx_L11_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":846
 * 
 *         if add_sam_header and mode == "w":
 *             mode = "wh"             # <<<<<<<<<<<<<<
 * 
 *         assert mode in ("r", "w", "rb", "wb", "wh",
 */
    __Pyx_INCREF(__pyx_n_u_wh);
    __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_u_wh);

    /* "pysam/libcalignmentfile.pyx":845
 *             mode = "r"
 * 
 *         if add_sam_header and mode == "w":             # <<<<<<<<<<<<<<
 *             mode = "wh"
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":848
 *             mode = "wh"
 * 
 *         assert mode in ("r", "w", "rb", "wb", "wh",             # <<<<<<<<<<<<<<
 *                         "wbu", "rU", "wb0",
 *                         "rc", "wc"), \
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(__pyx_assertions_enabled())) {
    __Pyx_INCREF(__pyx_v_mode);
    __pyx_t_2 = __pyx_v_mode;
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_r, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_w, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_rb, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_wb, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_wh, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_wbu, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_rU, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_wb0, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_rc, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_n_u_wc, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 848, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_3;
    __pyx_L13_bool_binop_done:;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = __pyx_t_1;
    if (unlikely(!__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":851
 *                         "wbu", "rU", "wb0",
 *                         "rc", "wc"), \
 *             "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
 * 
 *         self.duplicate_filehandle = duplicate_filehandle
 */
      __pyx_t_2 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 851, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_t_2, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_ERR(0, 848, __pyx_L1_error)
    }
  }
  #else
  if ((1)); else __PYX_ERR(0, 848, __pyx_L1_error)
  #endif

  /* "pysam/libcalignmentfile.pyx":853
 *             "invalid file opening mode `%s`" % mode
 * 
 *         self.duplicate_filehandle = duplicate_filehandle             # <<<<<<<<<<<<<<
 * 
 *         # StringIO not supported
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_duplicate_filehandle); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 853, __pyx_L1_error)
  __pyx_v_self->__pyx_base.duplicate_filehandle = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":856
 * 
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "access from StringIO objects not supported")
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_IsInstance(__pyx_v_filepath_or_object, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 856, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":857
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__45, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 857, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 857, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":856
 * 
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "access from StringIO objects not supported")
 */
  }

  /* "pysam/libcalignmentfile.pyx":860
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 *         elif isinstance(filepath_or_object, int):             # <<<<<<<<<<<<<<
 *             self.filename = filepath_or_object
 *             filename = None
 */
  __pyx_t_3 = PyInt_Check(__pyx_v_filepath_or_object); 
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":861
 *         # reading from a file descriptor
 *         elif isinstance(filepath_or_object, int):
 *             self.filename = filepath_or_object             # <<<<<<<<<<<<<<
 *             filename = None
 *             self.is_remote = False
 */
    __Pyx_INCREF(__pyx_v_filepath_or_object);
    __Pyx_GIVEREF(__pyx_v_filepath_or_object);
    __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
    __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
    __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object;

    /* "pysam/libcalignmentfile.pyx":862
 *         elif isinstance(filepath_or_object, int):
 *             self.filename = filepath_or_object
 *             filename = None             # <<<<<<<<<<<<<<
 *             self.is_remote = False
 *             self.is_stream = True
 */
    __Pyx_INCREF(Py_None);
    __pyx_v_filename = ((PyObject*)Py_None);

    /* "pysam/libcalignmentfile.pyx":863
 *             self.filename = filepath_or_object
 *             filename = None
 *             self.is_remote = False             # <<<<<<<<<<<<<<
 *             self.is_stream = True
 *         # reading from a File object or other object with fileno
 */
    __pyx_v_self->__pyx_base.is_remote = 0;

    /* "pysam/libcalignmentfile.pyx":864
 *             filename = None
 *             self.is_remote = False
 *             self.is_stream = True             # <<<<<<<<<<<<<<
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):
 */
    __pyx_v_self->__pyx_base.is_stream = 1;

    /* "pysam/libcalignmentfile.pyx":860
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 *         elif isinstance(filepath_or_object, int):             # <<<<<<<<<<<<<<
 *             self.filename = filepath_or_object
 *             filename = None
 */
    goto __pyx_L23;
  }

  /* "pysam/libcalignmentfile.pyx":866
 *             self.is_stream = True
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):             # <<<<<<<<<<<<<<
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')
 */
  __pyx_t_3 = __Pyx_HasAttr(__pyx_v_filepath_or_object, __pyx_n_u_fileno); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 866, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":867
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):
 *             if filepath_or_object.closed:             # <<<<<<<<<<<<<<
 *                 raise ValueError('I/O operation on closed file')
 *             self.filename = filepath_or_object
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_closed); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 867, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 867, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":868
 *         elif hasattr(filepath_or_object, "fileno"):
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')             # <<<<<<<<<<<<<<
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 868, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_ERR(0, 868, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":867
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):
 *             if filepath_or_object.closed:             # <<<<<<<<<<<<<<
 *                 raise ValueError('I/O operation on closed file')
 *             self.filename = filepath_or_object
 */
    }

    /* "pysam/libcalignmentfile.pyx":869
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')
 *             self.filename = filepath_or_object             # <<<<<<<<<<<<<<
 *             # .name can be TextIOWrapper
 *             try:
 */
    __Pyx_INCREF(__pyx_v_filepath_or_object);
    __Pyx_GIVEREF(__pyx_v_filepath_or_object);
    __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
    __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
    __pyx_v_self->__pyx_base.filename = __pyx_v_filepath_or_object;

    /* "pysam/libcalignmentfile.pyx":871
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 *             try:             # <<<<<<<<<<<<<<
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      __Pyx_XGOTREF(__pyx_t_7);
      __Pyx_XGOTREF(__pyx_t_8);
      __Pyx_XGOTREF(__pyx_t_9);
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":872
 *             # .name can be TextIOWrapper
 *             try:
 *                 filename = encode_filename(str(filepath_or_object.name))             # <<<<<<<<<<<<<<
 *                 cfilename = filename
 *             except AttributeError:
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_filepath_or_object, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 872, __pyx_L25_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = __Pyx_PyObject_Unicode(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 872, __pyx_L25_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 872, __pyx_L25_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_v_filename = ((PyObject*)__pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysam/libcalignmentfile.pyx":873
 *             try:
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename             # <<<<<<<<<<<<<<
 *             except AttributeError:
 *                 filename = None
 */
        if (unlikely(__pyx_v_filename == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
          __PYX_ERR(0, 873, __pyx_L25_error)
        }
        __pyx_t_10 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 873, __pyx_L25_error)
        __pyx_v_cfilename = __pyx_t_10;

        /* "pysam/libcalignmentfile.pyx":871
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 *             try:             # <<<<<<<<<<<<<<
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 */
      }
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L30_try_end;
      __pyx_L25_error:;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":874
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 *             except AttributeError:             # <<<<<<<<<<<<<<
 *                 filename = None
 *             self.is_remote = False
 */
      __pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
      if (__pyx_t_11) {
        __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 874, __pyx_L27_except_error)
        __Pyx_XGOTREF(__pyx_t_2);
        __Pyx_XGOTREF(__pyx_t_4);
        __Pyx_XGOTREF(__pyx_t_5);

        /* "pysam/libcalignmentfile.pyx":875
 *                 cfilename = filename
 *             except AttributeError:
 *                 filename = None             # <<<<<<<<<<<<<<
 *             self.is_remote = False
 *             self.is_stream = True
 */
        __Pyx_INCREF(Py_None);
        __Pyx_XDECREF_SET(__pyx_v_filename, ((PyObject*)Py_None));
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        goto __pyx_L26_exception_handled;
      }
      goto __pyx_L27_except_error;

      /* "pysam/libcalignmentfile.pyx":871
 *             self.filename = filepath_or_object
 *             # .name can be TextIOWrapper
 *             try:             # <<<<<<<<<<<<<<
 *                 filename = encode_filename(str(filepath_or_object.name))
 *                 cfilename = filename
 */
      __pyx_L27_except_error:;
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      goto __pyx_L1_error;
      __pyx_L26_exception_handled:;
      __Pyx_XGIVEREF(__pyx_t_7);
      __Pyx_XGIVEREF(__pyx_t_8);
      __Pyx_XGIVEREF(__pyx_t_9);
      __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      __pyx_L30_try_end:;
    }

    /* "pysam/libcalignmentfile.pyx":876
 *             except AttributeError:
 *                 filename = None
 *             self.is_remote = False             # <<<<<<<<<<<<<<
 *             self.is_stream = True
 *         # what remains is a filename
 */
    __pyx_v_self->__pyx_base.is_remote = 0;

    /* "pysam/libcalignmentfile.pyx":877
 *                 filename = None
 *             self.is_remote = False
 *             self.is_stream = True             # <<<<<<<<<<<<<<
 *         # what remains is a filename
 *         else:
 */
    __pyx_v_self->__pyx_base.is_stream = 1;

    /* "pysam/libcalignmentfile.pyx":866
 *             self.is_stream = True
 *         # reading from a File object or other object with fileno
 *         elif hasattr(filepath_or_object, "fileno"):             # <<<<<<<<<<<<<<
 *             if filepath_or_object.closed:
 *                 raise ValueError('I/O operation on closed file')
 */
    goto __pyx_L23;
  }

  /* "pysam/libcalignmentfile.pyx":880
 *         # what remains is a filename
 *         else:
 *             self.filename = filename = encode_filename(filepath_or_object)             # <<<<<<<<<<<<<<
 *             cfilename = filename
 *             self.is_remote = hisremote(cfilename)
 */
  /*else*/ {
    __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_filepath_or_object); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 880, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF(__pyx_v_self->__pyx_base.filename);
    __Pyx_DECREF(__pyx_v_self->__pyx_base.filename);
    __pyx_v_self->__pyx_base.filename = __pyx_t_5;
    __Pyx_INCREF(__pyx_t_5);
    __pyx_v_filename = ((PyObject*)__pyx_t_5);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":881
 *         else:
 *             self.filename = filename = encode_filename(filepath_or_object)
 *             cfilename = filename             # <<<<<<<<<<<<<<
 *             self.is_remote = hisremote(cfilename)
 *             self.is_stream = self.filename == b'-'
 */
    if (unlikely(__pyx_v_filename == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
      __PYX_ERR(0, 881, __pyx_L1_error)
    }
    __pyx_t_10 = __Pyx_PyBytes_AsWritableString(__pyx_v_filename); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 881, __pyx_L1_error)
    __pyx_v_cfilename = __pyx_t_10;

    /* "pysam/libcalignmentfile.pyx":882
 *             self.filename = filename = encode_filename(filepath_or_object)
 *             cfilename = filename
 *             self.is_remote = hisremote(cfilename)             # <<<<<<<<<<<<<<
 *             self.is_stream = self.filename == b'-'
 * 
 */
    __pyx_v_self->__pyx_base.is_remote = hisremote(__pyx_v_cfilename);

    /* "pysam/libcalignmentfile.pyx":883
 *             cfilename = filename
 *             self.is_remote = hisremote(cfilename)
 *             self.is_stream = self.filename == b'-'             # <<<<<<<<<<<<<<
 * 
 *         # for htslib, wbu seems to not work
 */
    __pyx_t_5 = PyObject_RichCompare(__pyx_v_self->__pyx_base.filename, __pyx_kp_b__46, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 883, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 883, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_self->__pyx_base.is_stream = __pyx_t_3;
  }
  __pyx_L23:;

  /* "pysam/libcalignmentfile.pyx":886
 * 
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":             # <<<<<<<<<<<<<<
 *             mode = "wb0"
 * 
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_wbu, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 886, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":887
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":
 *             mode = "wb0"             # <<<<<<<<<<<<<<
 * 
 *         self.mode = force_bytes(mode)
 */
    __Pyx_INCREF(__pyx_n_u_wb0);
    __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_u_wb0);

    /* "pysam/libcalignmentfile.pyx":886
 * 
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":             # <<<<<<<<<<<<<<
 *             mode = "wb0"
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":889
 *             mode = "wb0"
 * 
 *         self.mode = force_bytes(mode)             # <<<<<<<<<<<<<<
 *         self.reference_filename = reference_filename = encode_filename(
 *             reference_filename)
 */
  __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_bytes(__pyx_v_mode, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 889, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->__pyx_base.mode);
  __Pyx_DECREF(__pyx_v_self->__pyx_base.mode);
  __pyx_v_self->__pyx_base.mode = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":890
 * 
 *         self.mode = force_bytes(mode)
 *         self.reference_filename = reference_filename = encode_filename(             # <<<<<<<<<<<<<<
 *             reference_filename)
 * 
 */
  __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_v_reference_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 890, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->reference_filename);
  __Pyx_DECREF(__pyx_v_self->reference_filename);
  __pyx_v_self->reference_filename = __pyx_t_5;
  __Pyx_INCREF(__pyx_t_5);
  __Pyx_DECREF_SET(__pyx_v_reference_filename, __pyx_t_5);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":893
 *             reference_filename)
 * 
 *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
 *             # open file for writing
 * 
 */
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 893, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_5, __pyx_n_u_w, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 893, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":896
 *             # open file for writing
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 896, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_header); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 896, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_text); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 896, __pyx_L1_error)
    if (!__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 896, __pyx_L1_error)
    if (__pyx_t_1) {
    } else {
      __pyx_t_3 = __pyx_t_1;
      goto __pyx_L36_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 896, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_1;
    __pyx_L36_bool_binop_done:;
    __pyx_t_1 = (!__pyx_t_3);
    if (unlikely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":897
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 *                     "and `reference_lengths` for writing")
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 897, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 897, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":896
 *             # open file for writing
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 */
    }

    /* "pysam/libcalignmentfile.pyx":901
 *                     "and `reference_lengths` for writing")
 * 
 *             if template:             # <<<<<<<<<<<<<<
 *                 # header is copied, though at the moment not strictly
 *                 # necessary as AlignmentHeader is immutable.
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_template)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 901, __pyx_L1_error)
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":904
 *                 # header is copied, though at the moment not strictly
 *                 # necessary as AlignmentHeader is immutable.
 *                 self.header = template.header.copy()             # <<<<<<<<<<<<<<
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_template->header), __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 904, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 904, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 904, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
      __Pyx_DECREF((PyObject *)__pyx_v_self->header);
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":901
 *                     "and `reference_lengths` for writing")
 * 
 *             if template:             # <<<<<<<<<<<<<<
 *                 # header is copied, though at the moment not strictly
 *                 # necessary as AlignmentHeader is immutable.
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":905
 *                 # necessary as AlignmentHeader is immutable.
 *                 self.header = template.header.copy()
 *             elif isinstance(header, AlignmentHeader):             # <<<<<<<<<<<<<<
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):
 */
    __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_header, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader); 
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":906
 *                 self.header = template.header.copy()
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()             # <<<<<<<<<<<<<<
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_header, __pyx_n_s_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
      __Pyx_DECREF((PyObject *)__pyx_v_self->header);
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":905
 *                 # necessary as AlignmentHeader is immutable.
 *                 self.header = template.header.copy()
 *             elif isinstance(header, AlignmentHeader):             # <<<<<<<<<<<<<<
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":907
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 907, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyObject_IsInstance(__pyx_v_header, __pyx_t_5); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 907, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":908
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)             # <<<<<<<<<<<<<<
 *             elif reference_names and reference_lengths:
 *                 self.header = AlignmentHeader.from_references(
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_dict); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 908, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_header};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 908, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 908, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_5);
      __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
      __Pyx_DECREF((PyObject *)__pyx_v_self->header);
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
      __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":907
 *             elif isinstance(header, AlignmentHeader):
 *                 self.header = header.copy()
 *             elif isinstance(header, Mapping):             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":909
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_references(
 *                     reference_names,
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 909, __pyx_L1_error)
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L42_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 909, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_3;
    __pyx_L42_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":910
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 *                 self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                     reference_names,
 *                     reference_lengths,
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_references); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);

      /* "pysam/libcalignmentfile.pyx":912
 *                 self.header = AlignmentHeader.from_references(
 *                     reference_names,
 *                     reference_lengths,             # <<<<<<<<<<<<<<
 *                     add_sq_text=add_sq_text,
 *                     text=text)
 */
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_v_reference_names);
      __Pyx_GIVEREF(__pyx_v_reference_names);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_reference_names)) __PYX_ERR(0, 910, __pyx_L1_error);
      __Pyx_INCREF(__pyx_v_reference_lengths);
      __Pyx_GIVEREF(__pyx_v_reference_lengths);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_reference_lengths)) __PYX_ERR(0, 910, __pyx_L1_error);

      /* "pysam/libcalignmentfile.pyx":913
 *                     reference_names,
 *                     reference_lengths,
 *                     add_sq_text=add_sq_text,             # <<<<<<<<<<<<<<
 *                     text=text)
 *             elif text:
 */
      __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_add_sq_text, __pyx_v_add_sq_text) < 0) __PYX_ERR(0, 913, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":914
 *                     reference_lengths,
 *                     add_sq_text=add_sq_text,
 *                     text=text)             # <<<<<<<<<<<<<<
 *             elif text:
 *                 self.header = AlignmentHeader.from_text(text)
 */
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_text, __pyx_v_text) < 0) __PYX_ERR(0, 913, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":910
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:
 *                 self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                     reference_names,
 *                     reference_lengths,
 */
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 910, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_12);
      __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
      __Pyx_DECREF((PyObject *)__pyx_v_self->header);
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_12);
      __pyx_t_12 = 0;

      /* "pysam/libcalignmentfile.pyx":909
 *             elif isinstance(header, Mapping):
 *                 self.header = AlignmentHeader.from_dict(header)
 *             elif reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_references(
 *                     reference_names,
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":915
 *                     add_sq_text=add_sq_text,
 *                     text=text)
 *             elif text:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 */
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_text); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 915, __pyx_L1_error)
    if (likely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":916
 *                     text=text)
 *             elif text:
 *                 self.header = AlignmentHeader.from_text(text)             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("not enough information to construct header. Please provide template, "
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_text); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 916, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_text};
        __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 916, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 916, __pyx_L1_error)
      __Pyx_GIVEREF(__pyx_t_12);
      __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
      __Pyx_DECREF((PyObject *)__pyx_v_self->header);
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_12);
      __pyx_t_12 = 0;

      /* "pysam/libcalignmentfile.pyx":915
 *                     add_sq_text=add_sq_text,
 *                     text=text)
 *             elif text:             # <<<<<<<<<<<<<<
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 */
      goto __pyx_L41;
    }

    /* "pysam/libcalignmentfile.pyx":918
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 *                 raise ValueError("not enough information to construct header. Please provide template, "             # <<<<<<<<<<<<<<
 *                                  "header, text or reference_names/reference_lengths")
 *             self.htsfile = self._open_htsfile()
 */
    /*else*/ {
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__48, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 918, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_Raise(__pyx_t_12, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __PYX_ERR(0, 918, __pyx_L1_error)
    }
    __pyx_L41:;

    /* "pysam/libcalignmentfile.pyx":920
 *                 raise ValueError("not enough information to construct header. Please provide template, "
 *                                  "header, text or reference_names/reference_lengths")
 *             self.htsfile = self._open_htsfile()             # <<<<<<<<<<<<<<
 * 
 *             if self.htsfile == NULL:
 */
    __pyx_t_13 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_13 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 920, __pyx_L1_error)
    __pyx_v_self->__pyx_base.htsfile = __pyx_t_13;

    /* "pysam/libcalignmentfile.pyx":922
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 */
    __pyx_t_1 = (__pyx_v_self->__pyx_base.htsfile == NULL);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":923
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),
 */
      __pyx_t_1 = (errno != 0);
      if (unlikely(__pyx_t_1)) {

        /* "pysam/libcalignmentfile.pyx":924
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(             # <<<<<<<<<<<<<<
 *                         force_str(filename),
 *                         force_str(strerror(errno))))
 */
        __pyx_t_12 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_open_alignment_file, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);

        /* "pysam/libcalignmentfile.pyx":925
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),             # <<<<<<<<<<<<<<
 *                         force_str(strerror(errno))))
 *                 else:
 */
        __pyx_t_5 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 925, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);

        /* "pysam/libcalignmentfile.pyx":926
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),
 *                         force_str(strerror(errno))))             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 */
        __pyx_t_14 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 926, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_15 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_14, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 926, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_14 = NULL;
        __pyx_t_6 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
            __pyx_t_6 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[3] = {__pyx_t_14, __pyx_t_5, __pyx_t_15};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 2+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        }

        /* "pysam/libcalignmentfile.pyx":924
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(             # <<<<<<<<<<<<<<
 *                         force_str(filename),
 *                         force_str(strerror(errno))))
 */
        __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_12);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_12)) __PYX_ERR(0, 924, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_2);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error);
        __pyx_t_12 = 0;
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 924, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":923
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 *                         force_str(filename),
 */
      }

      /* "pysam/libcalignmentfile.pyx":928
 *                         force_str(strerror(errno))))
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))             # <<<<<<<<<<<<<<
 *             if format_options and len(format_options):
 *                 self.add_hts_options(format_options)
 */
      /*else*/ {
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_open_alignment_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 928, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_12 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 928, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_15 = NULL;
        __pyx_t_6 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_4))) {
          __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4);
          if (likely(__pyx_t_15)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
            __Pyx_INCREF(__pyx_t_15);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_4, function);
            __pyx_t_6 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_t_12};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        }
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 928, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __PYX_ERR(0, 928, __pyx_L1_error)
      }

      /* "pysam/libcalignmentfile.pyx":922
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(
 */
    }

    /* "pysam/libcalignmentfile.pyx":929
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 *             # set filename with reference sequences. If no filename
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_format_options); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 929, __pyx_L1_error)
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L47_bool_binop_done;
    }
    __pyx_t_16 = PyObject_Length(__pyx_v_format_options); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 929, __pyx_L1_error)
    __pyx_t_3 = (__pyx_t_16 != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L47_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":930
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 *             if format_options and len(format_options):
 *                 self.add_hts_options(format_options)             # <<<<<<<<<<<<<<
 *             # set filename with reference sequences. If no filename
 *             # is given, the CRAM reference arrays will be built from
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_hts_options); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 930, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_12 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_12, __pyx_v_format_options};
        __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 930, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "pysam/libcalignmentfile.pyx":929
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 *             # set filename with reference sequences. If no filename
 */
    }

    /* "pysam/libcalignmentfile.pyx":934
 *             # is given, the CRAM reference arrays will be built from
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:             # <<<<<<<<<<<<<<
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")
 */
    __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_u_c, __pyx_v_mode, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 934, __pyx_L1_error)
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L50_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 934, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_3;
    __pyx_L50_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":935
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):             # <<<<<<<<<<<<<<
 *                     raise ValueError("failure when setting reference filename")
 * 
 */
      __pyx_t_17 = __Pyx_PyObject_AsString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) __PYX_ERR(0, 935, __pyx_L1_error)
      __pyx_t_1 = (hts_set_fai_filename(__pyx_v_self->__pyx_base.htsfile, __pyx_t_17) != 0);
      if (unlikely(__pyx_t_1)) {

        /* "pysam/libcalignmentfile.pyx":936
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")             # <<<<<<<<<<<<<<
 * 
 *             # write header to htsfile
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__49, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 936, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __PYX_ERR(0, 936, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":935
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):             # <<<<<<<<<<<<<<
 *                     raise ValueError("failure when setting reference filename")
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":934
 *             # is given, the CRAM reference arrays will be built from
 *             # the @SQ header in the header
 *             if "c" in mode and reference_filename:             # <<<<<<<<<<<<<<
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")
 */
    }

    /* "pysam/libcalignmentfile.pyx":939
 * 
 *             # write header to htsfile
 *             if "b" in mode or "c" in mode or "h" in mode:             # <<<<<<<<<<<<<<
 *                 hdr = self.header.ptr
 *                 with nogil:
 */
    __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_u_b, __pyx_v_mode, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 939, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L54_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_u_c, __pyx_v_mode, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 939, __pyx_L1_error)
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L54_bool_binop_done;
    }
    __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_u_h, __pyx_v_mode, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 939, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_3;
    __pyx_L54_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":940
 *             # write header to htsfile
 *             if "b" in mode or "c" in mode or "h" in mode:
 *                 hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     sam_hdr_write(self.htsfile, hdr)
 */
      __pyx_t_18 = __pyx_v_self->header->ptr;
      __pyx_v_hdr = __pyx_t_18;

      /* "pysam/libcalignmentfile.pyx":941
 *             if "b" in mode or "c" in mode or "h" in mode:
 *                 hdr = self.header.ptr
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          _save = NULL;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":942
 *                 hdr = self.header.ptr
 *                 with nogil:
 *                     sam_hdr_write(self.htsfile, hdr)             # <<<<<<<<<<<<<<
 * 
 *         elif mode[0] == "r":
 */
            (void)(sam_hdr_write(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr));
          }

          /* "pysam/libcalignmentfile.pyx":941
 *             if "b" in mode or "c" in mode or "h" in mode:
 *                 hdr = self.header.ptr
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L59;
            }
            __pyx_L59:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":939
 * 
 *             # write header to htsfile
 *             if "b" in mode or "c" in mode or "h" in mode:             # <<<<<<<<<<<<<<
 *                 hdr = self.header.ptr
 *                 with nogil:
 */
    }

    /* "pysam/libcalignmentfile.pyx":893
 *             reference_filename)
 * 
 *         if mode[0] == 'w':             # <<<<<<<<<<<<<<
 *             # open file for writing
 * 
 */
    goto __pyx_L34;
  }

  /* "pysam/libcalignmentfile.pyx":944
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
 *             # open file for reading
 *             self.htsfile = self._open_htsfile()
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 944, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_t_4, __pyx_n_u_r, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 944, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":946
 *         elif mode[0] == "r":
 *             # open file for reading
 *             self.htsfile = self._open_htsfile()             # <<<<<<<<<<<<<<
 * 
 *             if self.htsfile == NULL:
 */
    __pyx_t_13 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._open_htsfile(((struct __pyx_obj_5pysam_10libchtslib_HTSFile *)__pyx_v_self)); if (unlikely(__pyx_t_13 == ((htsFile *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 946, __pyx_L1_error)
    __pyx_v_self->__pyx_base.htsfile = __pyx_t_13;

    /* "pysam/libcalignmentfile.pyx":948
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 */
    __pyx_t_1 = (__pyx_v_self->__pyx_base.htsfile == NULL);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":949
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 *                                   force_str(strerror(errno))))
 */
      __pyx_t_1 = (errno != 0);
      if (unlikely(__pyx_t_1)) {

        /* "pysam/libcalignmentfile.pyx":950
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),             # <<<<<<<<<<<<<<
 *                                   force_str(strerror(errno))))
 *                 else:
 */
        __pyx_t_4 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_open_alignment_file, __pyx_n_s_format); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_15 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);

        /* "pysam/libcalignmentfile.pyx":951
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 *                                   force_str(strerror(errno))))             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 */
        __pyx_t_5 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 951, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_14 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_5, NULL); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 951, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = NULL;
        __pyx_t_6 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_12))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_12);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_12, function);
            __pyx_t_6 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_t_15, __pyx_t_14};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+1-__pyx_t_6, 2+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 950, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        }

        /* "pysam/libcalignmentfile.pyx":950
 *             if self.htsfile == NULL:
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),             # <<<<<<<<<<<<<<
 *                                   force_str(strerror(errno))))
 *                 else:
 */
        __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_GIVEREF(__pyx_t_4);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_4)) __PYX_ERR(0, 950, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_2);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_2)) __PYX_ERR(0, 950, __pyx_L1_error);
        __pyx_t_4 = 0;
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 950, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 950, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":949
 * 
 *             if self.htsfile == NULL:
 *                 if errno:             # <<<<<<<<<<<<<<
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 *                                   force_str(strerror(errno))))
 */
      }

      /* "pysam/libcalignmentfile.pyx":953
 *                                   force_str(strerror(errno))))
 *                 else:
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))             # <<<<<<<<<<<<<<
 * 
 *             if self.htsfile.format.category != sequence_data:
 */
      /*else*/ {
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_open_alignment_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_v_filename, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_14 = NULL;
        __pyx_t_6 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_12))) {
          __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12);
          if (likely(__pyx_t_14)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
            __Pyx_INCREF(__pyx_t_14);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_12, function);
            __pyx_t_6 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_t_4};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_12, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 953, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        }
        __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 953, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_Raise(__pyx_t_12, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __PYX_ERR(0, 953, __pyx_L1_error)
      }

      /* "pysam/libcalignmentfile.pyx":948
 *             self.htsfile = self._open_htsfile()
 * 
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 if errno:
 *                     raise IOError(errno, "could not open alignment file `{}`: {}".format(force_str(filename),
 */
    }

    /* "pysam/libcalignmentfile.pyx":955
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 * 
 *             if self.htsfile.format.category != sequence_data:             # <<<<<<<<<<<<<<
 *                 raise ValueError("file does not contain alignment data")
 * 
 */
    __pyx_t_1 = (__pyx_v_self->__pyx_base.htsfile->format.category != sequence_data);
    if (unlikely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":956
 * 
 *             if self.htsfile.format.category != sequence_data:
 *                 raise ValueError("file does not contain alignment data")             # <<<<<<<<<<<<<<
 * 
 *             if format_options and len(format_options):
 */
      __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__50, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 956, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_Raise(__pyx_t_12, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __PYX_ERR(0, 956, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":955
 *                     raise ValueError("could not open alignment file `{}`".format(force_str(filename)))
 * 
 *             if self.htsfile.format.category != sequence_data:             # <<<<<<<<<<<<<<
 *                 raise ValueError("file does not contain alignment data")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":958
 *                 raise ValueError("file does not contain alignment data")
 * 
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_format_options); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 958, __pyx_L1_error)
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L64_bool_binop_done;
    }
    __pyx_t_16 = PyObject_Length(__pyx_v_format_options); if (unlikely(__pyx_t_16 == ((Py_ssize_t)-1))) __PYX_ERR(0, 958, __pyx_L1_error)
    __pyx_t_3 = (__pyx_t_16 != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L64_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":959
 * 
 *             if format_options and len(format_options):
 *                 self.add_hts_options(format_options)             # <<<<<<<<<<<<<<
 * 
 *             self.check_truncation(ignore_truncation)
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_hts_options); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 959, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_format_options};
        __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 959, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

      /* "pysam/libcalignmentfile.pyx":958
 *                 raise ValueError("file does not contain alignment data")
 * 
 *             if format_options and len(format_options):             # <<<<<<<<<<<<<<
 *                 self.add_hts_options(format_options)
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":961
 *                 self.add_hts_options(format_options)
 * 
 *             self.check_truncation(ignore_truncation)             # <<<<<<<<<<<<<<
 * 
 *             # bam/cram files require a valid header
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_truncation); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = NULL;
    __pyx_t_6 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_6 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_ignore_truncation};
      __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 961, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

    /* "pysam/libcalignmentfile.pyx":964
 * 
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 */
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L67_bool_binop_done;
    }
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 964, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_1 = __pyx_t_3;
    __pyx_L67_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":965
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          _save = NULL;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":966
 *             if self.is_bam or self.is_cram:
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                 if hdr == NULL:
 *                     raise ValueError(
 */
            __pyx_v_hdr = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile);
          }

          /* "pysam/libcalignmentfile.pyx":965
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L71;
            }
            __pyx_L71:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":967
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "file does not have a valid header (mode='%s') "
 */
      __pyx_t_1 = (__pyx_v_hdr == NULL);
      if (unlikely(__pyx_t_1)) {

        /* "pysam/libcalignmentfile.pyx":970
 *                     raise ValueError(
 *                         "file does not have a valid header (mode='%s') "
 *                         "- is it BAM/CRAM format?" % mode)             # <<<<<<<<<<<<<<
 *                 self.header = makeAlignmentHeader(hdr)
 *             else:
 */
        __pyx_t_12 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_file_does_not_have_a_valid_heade, __pyx_v_mode); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 970, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);

        /* "pysam/libcalignmentfile.pyx":968
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "file does not have a valid header (mode='%s') "
 *                         "- is it BAM/CRAM format?" % mode)
 */
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 968, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_Raise(__pyx_t_2, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_ERR(0, 968, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":967
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 *                 if hdr == NULL:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "file does not have a valid header (mode='%s') "
 */
      }

      /* "pysam/libcalignmentfile.pyx":971
 *                         "file does not have a valid header (mode='%s') "
 *                         "- is it BAM/CRAM format?" % mode)
 *                 self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 *             else:
 *                 # in sam files a header is optional. If not given,
 */
      __pyx_t_2 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 971, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
      __Pyx_DECREF((PyObject *)__pyx_v_self->header);
      __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":964
 * 
 *             # bam/cram files require a valid header
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hdr = sam_hdr_read(self.htsfile)
 */
      goto __pyx_L66;
    }

    /* "pysam/libcalignmentfile.pyx":976
 *                 # user may provide reference names and lengths to built
 *                 # an on-the-fly header.
 *                 if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(
 */
    /*else*/ {
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_names); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 976, __pyx_L1_error)
      if (__pyx_t_3) {
      } else {
        __pyx_t_1 = __pyx_t_3;
        goto __pyx_L74_bool_binop_done;
      }
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_lengths); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 976, __pyx_L1_error)
      __pyx_t_1 = __pyx_t_3;
      __pyx_L74_bool_binop_done:;
      if (__pyx_t_1) {

        /* "pysam/libcalignmentfile.pyx":978
 *                 if reference_names and reference_lengths:
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader), __pyx_n_s_from_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 978, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);

        /* "pysam/libcalignmentfile.pyx":979
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(
 *                         reference_names=reference_names,             # <<<<<<<<<<<<<<
 *                         reference_lengths=reference_lengths,
 *                         add_sq_text=add_sq_text,
 */
        __pyx_t_12 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 979, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_reference_names, __pyx_v_reference_names) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":980
 *                     self.header = AlignmentHeader.from_references(
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,             # <<<<<<<<<<<<<<
 *                         add_sq_text=add_sq_text,
 *                         text=text)
 */
        if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_reference_lengths, __pyx_v_reference_lengths) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":981
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,
 *                         add_sq_text=add_sq_text,             # <<<<<<<<<<<<<<
 *                         text=text)
 *                 else:
 */
        if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_add_sq_text, __pyx_v_add_sq_text) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":982
 *                         reference_lengths=reference_lengths,
 *                         add_sq_text=add_sq_text,
 *                         text=text)             # <<<<<<<<<<<<<<
 *                 else:
 *                     with nogil:
 */
        if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_text, __pyx_v_text) < 0) __PYX_ERR(0, 979, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":978
 *                 if reference_names and reference_lengths:
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(             # <<<<<<<<<<<<<<
 *                         reference_names=reference_names,
 *                         reference_lengths=reference_lengths,
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 978, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader))))) __PYX_ERR(0, 978, __pyx_L1_error)
        __Pyx_GIVEREF(__pyx_t_4);
        __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
        __Pyx_DECREF((PyObject *)__pyx_v_self->header);
        __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_4);
        __pyx_t_4 = 0;

        /* "pysam/libcalignmentfile.pyx":976
 *                 # user may provide reference names and lengths to built
 *                 # an on-the-fly header.
 *                 if reference_names and reference_lengths:             # <<<<<<<<<<<<<<
 *                     # build header from a target names and lengths
 *                     self.header = AlignmentHeader.from_references(
 */
        goto __pyx_L73;
      }

      /* "pysam/libcalignmentfile.pyx":984
 *                         text=text)
 *                 else:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 */
      /*else*/ {
        {
            #ifdef WITH_THREAD
            PyThreadState *_save;
            _save = NULL;
            Py_UNBLOCK_THREADS
            __Pyx_FastGIL_Remember();
            #endif
            /*try:*/ {

              /* "pysam/libcalignmentfile.pyx":985
 *                 else:
 *                     with nogil:
 *                         hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                     if hdr == NULL:
 *                         raise ValueError(
 */
              __pyx_v_hdr = sam_hdr_read(__pyx_v_self->__pyx_base.htsfile);
            }

            /* "pysam/libcalignmentfile.pyx":984
 *                         text=text)
 *                 else:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 */
            /*finally:*/ {
              /*normal exit:*/{
                #ifdef WITH_THREAD
                __Pyx_FastGIL_Forget();
                Py_BLOCK_THREADS
                #endif
                goto __pyx_L78;
              }
              __pyx_L78:;
            }
        }

        /* "pysam/libcalignmentfile.pyx":986
 *                     with nogil:
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:             # <<<<<<<<<<<<<<
 *                         raise ValueError(
 *                             "SAM? file does not have a valid header (mode='%s'), "
 */
        __pyx_t_1 = (__pyx_v_hdr == NULL);
        if (unlikely(__pyx_t_1)) {

          /* "pysam/libcalignmentfile.pyx":987
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 *                         raise ValueError(             # <<<<<<<<<<<<<<
 *                             "SAM? file does not have a valid header (mode='%s'), "
 *                             "please provide reference_names and reference_lengths")
 */
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__51, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 987, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_Raise(__pyx_t_4, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __PYX_ERR(0, 987, __pyx_L1_error)

          /* "pysam/libcalignmentfile.pyx":986
 *                     with nogil:
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:             # <<<<<<<<<<<<<<
 *                         raise ValueError(
 *                             "SAM? file does not have a valid header (mode='%s'), "
 */
        }

        /* "pysam/libcalignmentfile.pyx":990
 *                             "SAM? file does not have a valid header (mode='%s'), "
 *                             "please provide reference_names and reference_lengths")
 *                     self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 * 
 *             # set filename with reference sequences
 */
        __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 990, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
        __Pyx_DECREF((PyObject *)__pyx_v_self->header);
        __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_4);
        __pyx_t_4 = 0;
      }
      __pyx_L73:;
    }
    __pyx_L66:;

    /* "pysam/libcalignmentfile.pyx":993
 * 
 *             # set filename with reference sequences
 *             if self.is_cram and reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = self.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 993, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 993, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L81_bool_binop_done;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 993, __pyx_L1_error)
    __pyx_t_1 = __pyx_t_3;
    __pyx_L81_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":994
 *             # set filename with reference sequences
 *             if self.is_cram and reference_filename:
 *                 creference_filename = self.reference_filename             # <<<<<<<<<<<<<<
 *                 hts_set_opt(self.htsfile,
 *                             CRAM_OPT_REFERENCE,
 */
      __pyx_t_10 = __Pyx_PyObject_AsWritableString(__pyx_v_self->reference_filename); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 994, __pyx_L1_error)
      __pyx_v_creference_filename = __pyx_t_10;

      /* "pysam/libcalignmentfile.pyx":995
 *             if self.is_cram and reference_filename:
 *                 creference_filename = self.reference_filename
 *                 hts_set_opt(self.htsfile,             # <<<<<<<<<<<<<<
 *                             CRAM_OPT_REFERENCE,
 *                             creference_filename)
 */
      (void)(hts_set_opt(__pyx_v_self->__pyx_base.htsfile, CRAM_OPT_REFERENCE, __pyx_v_creference_filename));

      /* "pysam/libcalignmentfile.pyx":993
 * 
 *             # set filename with reference sequences
 *             if self.is_cram and reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = self.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    }

    /* "pysam/libcalignmentfile.pyx":999
 *                             creference_filename)
 * 
 *             if check_sq and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     ("file has no sequences defined (mode='%s') - "
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_check_sq); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 999, __pyx_L1_error)
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L84_bool_binop_done;
    }
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_4, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 999, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_1 = __pyx_t_3;
    __pyx_L84_bool_binop_done:;
    if (unlikely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":1003
 *                     ("file has no sequences defined (mode='%s') - "
 *                      "is it SAM/BAM format? Consider opening with "
 *                      "check_sq=False") % mode)             # <<<<<<<<<<<<<<
 * 
 *             if self.is_bam or self.is_cram:
 */
      __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_file_has_no_sequences_defined_mo, __pyx_v_mode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1003, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);

      /* "pysam/libcalignmentfile.pyx":1000
 * 
 *             if check_sq and self.header.nreferences == 0:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     ("file has no sequences defined (mode='%s') - "
 *                      "is it SAM/BAM format? Consider opening with "
 */
      __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1000, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_12, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __PYX_ERR(0, 1000, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":999
 *                             creference_filename)
 * 
 *             if check_sq and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     ("file has no sequences defined (mode='%s') - "
 */
    }

    /* "pysam/libcalignmentfile.pyx":1005
 *                      "check_sq=False") % mode)
 * 
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:
 */
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L87_bool_binop_done;
    }
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_12); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1005, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_1 = __pyx_t_3;
    __pyx_L87_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":1006
 * 
 *             if self.is_bam or self.is_cram:
 *                 self.index_filename = index_filename or filepath_index             # <<<<<<<<<<<<<<
 *                 if self.index_filename:
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 */
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_index_filename); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1006, __pyx_L1_error)
      if (!__pyx_t_1) {
      } else {
        __Pyx_INCREF(__pyx_v_index_filename);
        __pyx_t_12 = __pyx_v_index_filename;
        goto __pyx_L89_bool_binop_done;
      }
      __Pyx_INCREF(__pyx_v_filepath_index);
      __pyx_t_12 = __pyx_v_filepath_index;
      __pyx_L89_bool_binop_done:;
      __Pyx_GIVEREF(__pyx_t_12);
      __Pyx_GOTREF(__pyx_v_self->__pyx_base.index_filename);
      __Pyx_DECREF(__pyx_v_self->__pyx_base.index_filename);
      __pyx_v_self->__pyx_base.index_filename = __pyx_t_12;
      __pyx_t_12 = 0;

      /* "pysam/libcalignmentfile.pyx":1007
 *             if self.is_bam or self.is_cram:
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 */
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->__pyx_base.index_filename); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1007, __pyx_L1_error)
      if (__pyx_t_1) {

        /* "pysam/libcalignmentfile.pyx":1008
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:
 *                     cindexname = bfile_name = encode_filename(self.index_filename)             # <<<<<<<<<<<<<<
 * 
 *                 if cfilename or cindexname:
 */
        __pyx_t_12 = __pyx_v_self->__pyx_base.index_filename;
        __Pyx_INCREF(__pyx_t_12);
        __pyx_t_4 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1008, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        if (unlikely(__pyx_t_4 == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
          __PYX_ERR(0, 1008, __pyx_L1_error)
        }
        __pyx_t_10 = __Pyx_PyBytes_AsWritableString(__pyx_t_4); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 1008, __pyx_L1_error)
        __pyx_v_cindexname = __pyx_t_10;
        __Pyx_INCREF(__pyx_t_4);
        __pyx_v_bfile_name = ((PyObject*)__pyx_t_4);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "pysam/libcalignmentfile.pyx":1007
 *             if self.is_bam or self.is_cram:
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":1010
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 *                 if cfilename or cindexname:             # <<<<<<<<<<<<<<
 *                     with nogil:
 *                         self.index = sam_index_load3(self.htsfile, cfilename, cindexname,
 */
      __pyx_t_3 = (__pyx_v_cfilename != 0);
      if (!__pyx_t_3) {
      } else {
        __pyx_t_1 = __pyx_t_3;
        goto __pyx_L93_bool_binop_done;
      }
      __pyx_t_3 = (__pyx_v_cindexname != 0);
      __pyx_t_1 = __pyx_t_3;
      __pyx_L93_bool_binop_done:;
      if (__pyx_t_1) {

        /* "pysam/libcalignmentfile.pyx":1011
 * 
 *                 if cfilename or cindexname:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         self.index = sam_index_load3(self.htsfile, cfilename, cindexname,
 *                                                      HTS_IDX_SAVE_REMOTE|HTS_IDX_SILENT_FAIL)
 */
        {
            #ifdef WITH_THREAD
            PyThreadState *_save;
            _save = NULL;
            Py_UNBLOCK_THREADS
            __Pyx_FastGIL_Remember();
            #endif
            /*try:*/ {

              /* "pysam/libcalignmentfile.pyx":1012
 *                 if cfilename or cindexname:
 *                     with nogil:
 *                         self.index = sam_index_load3(self.htsfile, cfilename, cindexname,             # <<<<<<<<<<<<<<
 *                                                      HTS_IDX_SAVE_REMOTE|HTS_IDX_SILENT_FAIL)
 * 
 */
              __pyx_v_self->index = sam_index_load3(__pyx_v_self->__pyx_base.htsfile, __pyx_v_cfilename, __pyx_v_cindexname, (HTS_IDX_SAVE_REMOTE | HTS_IDX_SILENT_FAIL));
            }

            /* "pysam/libcalignmentfile.pyx":1011
 * 
 *                 if cfilename or cindexname:
 *                     with nogil:             # <<<<<<<<<<<<<<
 *                         self.index = sam_index_load3(self.htsfile, cfilename, cindexname,
 *                                                      HTS_IDX_SAVE_REMOTE|HTS_IDX_SILENT_FAIL)
 */
            /*finally:*/ {
              /*normal exit:*/{
                #ifdef WITH_THREAD
                __Pyx_FastGIL_Forget();
                Py_BLOCK_THREADS
                #endif
                goto __pyx_L97;
              }
              __pyx_L97:;
            }
        }

        /* "pysam/libcalignmentfile.pyx":1015
 *                                                      HTS_IDX_SAVE_REMOTE|HTS_IDX_SILENT_FAIL)
 * 
 *                     if not self.index and (cindexname or require_index):             # <<<<<<<<<<<<<<
 *                         if errno:
 *                             raise IOError(errno, force_str(strerror(errno)))
 */
        __pyx_t_3 = (!(__pyx_v_self->index != 0));
        if (__pyx_t_3) {
        } else {
          __pyx_t_1 = __pyx_t_3;
          goto __pyx_L99_bool_binop_done;
        }
        __pyx_t_3 = (__pyx_v_cindexname != 0);
        if (!__pyx_t_3) {
        } else {
          __pyx_t_1 = __pyx_t_3;
          goto __pyx_L99_bool_binop_done;
        }
        __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_require_index); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1015, __pyx_L1_error)
        __pyx_t_1 = __pyx_t_3;
        __pyx_L99_bool_binop_done:;
        if (__pyx_t_1) {

          /* "pysam/libcalignmentfile.pyx":1016
 * 
 *                     if not self.index and (cindexname or require_index):
 *                         if errno:             # <<<<<<<<<<<<<<
 *                             raise IOError(errno, force_str(strerror(errno)))
 *                         else:
 */
          __pyx_t_1 = (errno != 0);
          if (unlikely(__pyx_t_1)) {

            /* "pysam/libcalignmentfile.pyx":1017
 *                     if not self.index and (cindexname or require_index):
 *                         if errno:
 *                             raise IOError(errno, force_str(strerror(errno)))             # <<<<<<<<<<<<<<
 *                         else:
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)
 */
            __pyx_t_4 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1017, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_12 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1017, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_12);
            __pyx_t_2 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1017, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1017, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_12);
            __Pyx_GIVEREF(__pyx_t_4);
            if (__Pyx_PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_4)) __PYX_ERR(0, 1017, __pyx_L1_error);
            __Pyx_GIVEREF(__pyx_t_2);
            if (__Pyx_PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_2)) __PYX_ERR(0, 1017, __pyx_L1_error);
            __pyx_t_4 = 0;
            __pyx_t_2 = 0;
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1017, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            __Pyx_Raise(__pyx_t_2, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __PYX_ERR(0, 1017, __pyx_L1_error)

            /* "pysam/libcalignmentfile.pyx":1016
 * 
 *                     if not self.index and (cindexname or require_index):
 *                         if errno:             # <<<<<<<<<<<<<<
 *                             raise IOError(errno, force_str(strerror(errno)))
 *                         else:
 */
          }

          /* "pysam/libcalignmentfile.pyx":1019
 *                             raise IOError(errno, force_str(strerror(errno)))
 *                         else:
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)             # <<<<<<<<<<<<<<
 * 
 *                 elif require_index:
 */
          /*else*/ {
            __pyx_t_2 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_unable_to_open_index_file_s, __pyx_v_self->__pyx_base.index_filename); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1019, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1019, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_12);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_Raise(__pyx_t_12, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
            __PYX_ERR(0, 1019, __pyx_L1_error)
          }

          /* "pysam/libcalignmentfile.pyx":1015
 *                                                      HTS_IDX_SAVE_REMOTE|HTS_IDX_SILENT_FAIL)
 * 
 *                     if not self.index and (cindexname or require_index):             # <<<<<<<<<<<<<<
 *                         if errno:
 *                             raise IOError(errno, force_str(strerror(errno)))
 */
        }

        /* "pysam/libcalignmentfile.pyx":1010
 *                     cindexname = bfile_name = encode_filename(self.index_filename)
 * 
 *                 if cfilename or cindexname:             # <<<<<<<<<<<<<<
 *                     with nogil:
 *                         self.index = sam_index_load3(self.htsfile, cfilename, cindexname,
 */
        goto __pyx_L92;
      }

      /* "pysam/libcalignmentfile.pyx":1021
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)
 * 
 *                 elif require_index:             # <<<<<<<<<<<<<<
 *                     raise IOError('unable to open index file')
 * 
 */
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_require_index); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1021, __pyx_L1_error)
      if (unlikely(__pyx_t_1)) {

        /* "pysam/libcalignmentfile.pyx":1022
 * 
 *                 elif require_index:
 *                     raise IOError('unable to open index file')             # <<<<<<<<<<<<<<
 * 
 *                 # save start of data section
 */
        __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1022, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_Raise(__pyx_t_12, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __PYX_ERR(0, 1022, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1021
 *                             raise IOError('unable to open index file `%s`' % self.index_filename)
 * 
 *                 elif require_index:             # <<<<<<<<<<<<<<
 *                     raise IOError('unable to open index file')
 * 
 */
      }
      __pyx_L92:;

      /* "pysam/libcalignmentfile.pyx":1025
 * 
 *                 # save start of data section
 *                 if not self.is_stream:             # <<<<<<<<<<<<<<
 *                     self.start_offset = self.tell()
 * 
 */
      __pyx_t_1 = (!__pyx_v_self->__pyx_base.is_stream);
      if (__pyx_t_1) {

        /* "pysam/libcalignmentfile.pyx":1026
 *                 # save start of data section
 *                 if not self.is_stream:
 *                     self.start_offset = self.tell()             # <<<<<<<<<<<<<<
 * 
 *     def fetch(self,
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1026, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = NULL;
        __pyx_t_6 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
            __pyx_t_6 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
          __pyx_t_12 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1026, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        }
        __pyx_t_19 = __Pyx_PyInt_As_int64_t(__pyx_t_12); if (unlikely((__pyx_t_19 == ((int64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1026, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_v_self->__pyx_base.start_offset = __pyx_t_19;

        /* "pysam/libcalignmentfile.pyx":1025
 * 
 *                 # save start of data section
 *                 if not self.is_stream:             # <<<<<<<<<<<<<<
 *                     self.start_offset = self.tell()
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":1005
 *                      "check_sq=False") % mode)
 * 
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 self.index_filename = index_filename or filepath_index
 *                 if self.index_filename:
 */
    }

    /* "pysam/libcalignmentfile.pyx":944
 *                     sam_hdr_write(self.htsfile, hdr)
 * 
 *         elif mode[0] == "r":             # <<<<<<<<<<<<<<
 *             # open file for reading
 *             self.htsfile = self._open_htsfile()
 */
  }
  __pyx_L34:;

  /* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               mode=None,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile._open", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_filename);
  __Pyx_XDECREF(__pyx_v_bfile_name);
  __Pyx_XDECREF(__pyx_v_mode);
  __Pyx_XDECREF(__pyx_v_reference_names);
  __Pyx_XDECREF(__pyx_v_reference_lengths);
  __Pyx_XDECREF(__pyx_v_reference_filename);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1028
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8fetch, "AlignmentFile.fetch(self, contig=None, start=None, stop=None, region=None, tid=None, until_eof=False, multiple_iterators=False, reference=None, end=None)\nfetch reads aligned in a :term:`region`.\n\n        See :meth:`~pysam.HTSFile.parse_region` for more information\n        on how genomic regions can be specified. :term:`reference` and\n        `end` are also accepted for backward compatibility as synonyms\n        for :term:`contig` and `stop`, respectively.\n\n        Without a `contig` or `region` all mapped reads in the file\n        will be fetched. The reads will be returned ordered by reference\n        sequence, which will not necessarily be the order within the\n        file. This mode of iteration still requires an index. If there is\n        no index, use `until_eof=True`.\n\n        If only `contig` is set, all reads aligned to `contig`\n        will be fetched.\n\n        A :term:`SAM` file does not allow random access. If `region`\n        or `contig` are given, an exception is raised.\n\n        Parameters\n        ----------\n\n        until_eof : bool\n\n           If `until_eof` is True, all reads from the current file\n           position will be returned in order as they are within the\n           file. Using this option will also fetch unmapped reads.\n\n        multiple_iterators : bool\n\n           If `multiple_iterators` is True, multiple\n           iterators on the same file can be used at the same time. The\n           iterator returned will receive its own copy of a filehandle to\n           the file effectively re-opening the file. Re-opening a file\n           creates some overhead, so beware.\n\n        Returns\n        -------\n\n\t\tAn iterator over a collection of reads. : IteratorRow\n\n        Raises\n        ------\n\n        ValueError\n            if the genomic coordinates are out of range or invalid or the\n            file does not permit random access to genomic coordinates.\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_9fetch = {"fetch", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8fetch};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_tid = 0;
  PyObject *__pyx_v_until_eof = 0;
  PyObject *__pyx_v_multiple_iterators = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fetch (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_tid,&__pyx_n_s_until_eof,&__pyx_n_s_multiple_iterators,&__pyx_n_s_reference,&__pyx_n_s_end,0};

    /* "pysam/libcalignmentfile.pyx":1029
 * 
 *     def fetch(self,
 *               contig=None,             # <<<<<<<<<<<<<<
 *               start=None,
 *               stop=None,
 */
    values[0] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1030
 *     def fetch(self,
 *               contig=None,
 *               start=None,             # <<<<<<<<<<<<<<
 *               stop=None,
 *               region=None,
 */
    values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1031
 *               contig=None,
 *               start=None,
 *               stop=None,             # <<<<<<<<<<<<<<
 *               region=None,
 *               tid=None,
 */
    values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1032
 *               start=None,
 *               stop=None,
 *               region=None,             # <<<<<<<<<<<<<<
 *               tid=None,
 *               until_eof=False,
 */
    values[3] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1033
 *               stop=None,
 *               region=None,
 *               tid=None,             # <<<<<<<<<<<<<<
 *               until_eof=False,
 *               multiple_iterators=False,
 */
    values[4] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1034
 *               region=None,
 *               tid=None,
 *               until_eof=False,             # <<<<<<<<<<<<<<
 *               multiple_iterators=False,
 *               reference=None,
 */
    values[5] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_False));

    /* "pysam/libcalignmentfile.pyx":1035
 *               tid=None,
 *               until_eof=False,
 *               multiple_iterators=False,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               end=None):
 */
    values[6] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_False));

    /* "pysam/libcalignmentfile.pyx":1036
 *               until_eof=False,
 *               multiple_iterators=False,
 *               reference=None,             # <<<<<<<<<<<<<<
 *               end=None):
 *         """fetch reads aligned in a :term:`region`.
 */
    values[7] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1037
 *               multiple_iterators=False,
 *               reference=None,
 *               end=None):             # <<<<<<<<<<<<<<
 *         """fetch reads aligned in a :term:`region`.
 * 
 */
    values[8] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  9: values[8] = __Pyx_Arg_FASTCALL(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_contig);
          if (value) { values[0] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_start);
          if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_stop);
          if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_region);
          if (value) { values[3] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid);
          if (value) { values[4] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_until_eof);
          if (value) { values[5] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[6] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference);
          if (value) { values[7] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_end);
          if (value) { values[8] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1028, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "fetch") < 0)) __PYX_ERR(0, 1028, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  9: values[8] = __Pyx_Arg_FASTCALL(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_tid = values[4];
    __pyx_v_until_eof = values[5];
    __pyx_v_multiple_iterators = values[6];
    __pyx_v_reference = values[7];
    __pyx_v_end = values[8];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 9, __pyx_nargs); __PYX_ERR(0, 1028, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_tid, __pyx_v_until_eof, __pyx_v_multiple_iterators, __pyx_v_reference, __pyx_v_end);

  /* "pysam/libcalignmentfile.pyx":1028
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8fetch(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) {
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rstop;
  int __pyx_v_has_coord;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  unsigned int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__53)
  __Pyx_RefNannySetupContext("fetch", 0);
  __Pyx_TraceCall("fetch", __pyx_f[0], 1028, 0, __PYX_ERR(0, 1028, __pyx_L1_error));
  __Pyx_INCREF(__pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":1089
 *         cdef int rtid, rstart, rstop, has_coord
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1090
 * 
 *         if not self.is_open:
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1090, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1089
 *         cdef int rtid, rstart, rstop, has_coord
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1092
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, tid,
 *             end=end, reference=reference)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":1093
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 *             contig, start, stop, region, tid,             # <<<<<<<<<<<<<<
 *             end=end, reference=reference)
 * 
 */
  __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_contig);
  __Pyx_GIVEREF(__pyx_v_contig);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_contig)) __PYX_ERR(0, 1092, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_start)) __PYX_ERR(0, 1092, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_stop);
  __Pyx_GIVEREF(__pyx_v_stop);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_stop)) __PYX_ERR(0, 1092, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_region)) __PYX_ERR(0, 1092, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_v_tid)) __PYX_ERR(0, 1092, __pyx_L1_error);

  /* "pysam/libcalignmentfile.pyx":1094
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 *             contig, start, stop, region, tid,
 *             end=end, reference=reference)             # <<<<<<<<<<<<<<
 * 
 *        # Turn of re-opening if htsfile is a stream
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1094, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1094, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1094, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1092
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, tid,
 *             end=end, reference=reference)
 */
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
    PyObject* sequence = __pyx_t_6;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1092, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_7);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1092, __pyx_L1_error)
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
    __pyx_t_8 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1092, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_8);
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_9(__pyx_t_8); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) __PYX_ERR(0, 1092, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1092, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1092, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_has_coord = __pyx_t_10;
  __pyx_v_rtid = __pyx_t_11;
  __pyx_v_rstart = __pyx_t_12;
  __pyx_v_rstop = __pyx_t_13;

  /* "pysam/libcalignmentfile.pyx":1097
 * 
 *        # Turn of re-opening if htsfile is a stream
 *         if self.is_stream:             # <<<<<<<<<<<<<<
 *             multiple_iterators = False
 * 
 */
  if (__pyx_v_self->__pyx_base.is_stream) {

    /* "pysam/libcalignmentfile.pyx":1098
 *        # Turn of re-opening if htsfile is a stream
 *         if self.is_stream:
 *             multiple_iterators = False             # <<<<<<<<<<<<<<
 * 
 *         if self.is_bam or self.is_cram:
 */
    __Pyx_INCREF(Py_False);
    __Pyx_DECREF_SET(__pyx_v_multiple_iterators, Py_False);

    /* "pysam/libcalignmentfile.pyx":1097
 * 
 *        # Turn of re-opening if htsfile is a stream
 *         if self.is_stream:             # <<<<<<<<<<<<<<
 *             multiple_iterators = False
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1100
 *             multiple_iterators = False
 * 
 *         if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1100, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_2) {
  } else {
    __pyx_t_3 = __pyx_t_2;
    goto __pyx_L8_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1100, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1100, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_3 = __pyx_t_2;
  __pyx_L8_bool_binop_done:;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1101
 * 
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:             # <<<<<<<<<<<<<<
 *                 if not self.has_index():
 *                     raise ValueError(
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1101, __pyx_L1_error)
    __pyx_t_14 = (!__pyx_t_2);
    if (__pyx_t_14) {
    } else {
      __pyx_t_3 = __pyx_t_14;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_14 = (!__pyx_v_self->__pyx_base.is_remote);
    __pyx_t_3 = __pyx_t_14;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":1102
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "fetch called on bamfile without index")
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = NULL;
      __pyx_t_15 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_15 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL};
        __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_15, 0+__pyx_t_15);
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1102, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1102, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_14 = (!__pyx_t_3);
      if (unlikely(__pyx_t_14)) {

        /* "pysam/libcalignmentfile.pyx":1103
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "fetch called on bamfile without index")
 * 
 */
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1103, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_Raise(__pyx_t_6, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __PYX_ERR(0, 1103, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1102
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "fetch called on bamfile without index")
 */
      }

      /* "pysam/libcalignmentfile.pyx":1101
 * 
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:             # <<<<<<<<<<<<<<
 *                 if not self.has_index():
 *                     raise ValueError(
 */
    }

    /* "pysam/libcalignmentfile.pyx":1106
 *                         "fetch called on bamfile without index")
 * 
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,
 */
    __pyx_t_14 = (__pyx_v_has_coord != 0);
    if (__pyx_t_14) {

      /* "pysam/libcalignmentfile.pyx":1107
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)
 */
      __Pyx_XDECREF(__pyx_r);

      /* "pysam/libcalignmentfile.pyx":1108
 *             if has_coord:
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,             # <<<<<<<<<<<<<<
 *                     multiple_iterators=multiple_iterators)
 *             else:
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rstop); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);

      /* "pysam/libcalignmentfile.pyx":1107
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)
 */
      __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF((PyObject *)__pyx_v_self);
      __Pyx_GIVEREF((PyObject *)__pyx_v_self);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1107, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_6);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6)) __PYX_ERR(0, 1107, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_7);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_7)) __PYX_ERR(0, 1107, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_1);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_1)) __PYX_ERR(0, 1107, __pyx_L1_error);
      __pyx_t_6 = 0;
      __pyx_t_7 = 0;
      __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":1109
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *             else:
 *                 if until_eof:
 */
      __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1109, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1109, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1107
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rstop,
 *                     multiple_iterators=multiple_iterators)
 */
      __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1107, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_r = __pyx_t_7;
      __pyx_t_7 = 0;
      goto __pyx_L0;

      /* "pysam/libcalignmentfile.pyx":1106
 *                         "fetch called on bamfile without index")
 * 
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rstop,
 */
    }

    /* "pysam/libcalignmentfile.pyx":1111
 *                     multiple_iterators=multiple_iterators)
 *             else:
 *                 if until_eof:             # <<<<<<<<<<<<<<
 *                     return IteratorRowAll(
 *                         self,
 */
    /*else*/ {
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 1111, __pyx_L1_error)
      if (__pyx_t_14) {

        /* "pysam/libcalignmentfile.pyx":1112
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __Pyx_XDECREF(__pyx_r);

        /* "pysam/libcalignmentfile.pyx":1113
 *                 if until_eof:
 *                     return IteratorRowAll(
 *                         self,             # <<<<<<<<<<<<<<
 *                         multiple_iterators=multiple_iterators)
 *                 else:
 */
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1112, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF((PyObject *)__pyx_v_self);
        __Pyx_GIVEREF((PyObject *)__pyx_v_self);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1112, __pyx_L1_error);

        /* "pysam/libcalignmentfile.pyx":1114
 *                     return IteratorRowAll(
 *                         self,
 *                         multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *                 else:
 *                     # AH: check - reason why no multiple_iterators for
 */
        __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1114, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1114, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1112
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1112, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_4;
        __pyx_t_4 = 0;
        goto __pyx_L0;

        /* "pysam/libcalignmentfile.pyx":1111
 *                     multiple_iterators=multiple_iterators)
 *             else:
 *                 if until_eof:             # <<<<<<<<<<<<<<
 *                     return IteratorRowAll(
 *                         self,
 */
      }

      /* "pysam/libcalignmentfile.pyx":1118
 *                     # AH: check - reason why no multiple_iterators for
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
      /*else*/ {
        __Pyx_XDECREF(__pyx_r);

        /* "pysam/libcalignmentfile.pyx":1119
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(
 *                         self,             # <<<<<<<<<<<<<<
 *                         multiple_iterators=multiple_iterators)
 *         else:
 */
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1118, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF((PyObject *)__pyx_v_self);
        __Pyx_GIVEREF((PyObject *)__pyx_v_self);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1118, __pyx_L1_error);

        /* "pysam/libcalignmentfile.pyx":1120
 *                     return IteratorRowAllRefs(
 *                         self,
 *                         multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *         else:
 *             if has_coord:
 */
        __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1120, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1120, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":1118
 *                     # AH: check - reason why no multiple_iterators for
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs), __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1118, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_r = __pyx_t_7;
        __pyx_t_7 = 0;
        goto __pyx_L0;
      }
    }

    /* "pysam/libcalignmentfile.pyx":1100
 *             multiple_iterators = False
 * 
 *         if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 */
  }

  /* "pysam/libcalignmentfile.pyx":1122
 *                         multiple_iterators=multiple_iterators)
 *         else:
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "fetching by region is not available for SAM files")
 */
  /*else*/ {
    __pyx_t_14 = (__pyx_v_has_coord != 0);
    if (unlikely(__pyx_t_14)) {

      /* "pysam/libcalignmentfile.pyx":1123
 *         else:
 *             if has_coord:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "fetching by region is not available for SAM files")
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1123, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 1123, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1122
 *                         multiple_iterators=multiple_iterators)
 *         else:
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "fetching by region is not available for SAM files")
 */
    }

    /* "pysam/libcalignmentfile.pyx":1126
 *                     "fetching by region is not available for SAM files")
 * 
 *             if multiple_iterators == True:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "multiple iterators not implemented for SAM files")
 */
    __pyx_t_7 = PyObject_RichCompare(__pyx_v_multiple_iterators, Py_True, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1126, __pyx_L1_error)
    __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 1126, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__pyx_t_14)) {

      /* "pysam/libcalignmentfile.pyx":1127
 * 
 *             if multiple_iterators == True:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "multiple iterators not implemented for SAM files")
 * 
 */
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1127, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __PYX_ERR(0, 1127, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1126
 *                     "fetching by region is not available for SAM files")
 * 
 *             if multiple_iterators == True:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "multiple iterators not implemented for SAM files")
 */
    }

    /* "pysam/libcalignmentfile.pyx":1130
 *                     "multiple iterators not implemented for SAM files")
 * 
 *             return IteratorRowAll(self,             # <<<<<<<<<<<<<<
 *                                   multiple_iterators=multiple_iterators)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF((PyObject *)__pyx_v_self);
    __Pyx_GIVEREF((PyObject *)__pyx_v_self);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1130, __pyx_L1_error);

    /* "pysam/libcalignmentfile.pyx":1131
 * 
 *             return IteratorRowAll(self,
 *                                   multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def head(self, n, multiple_iterators=True):
 */
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1131, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1131, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1130
 *                     "multiple iterators not implemented for SAM files")
 * 
 *             return IteratorRowAll(self,             # <<<<<<<<<<<<<<
 *                                   multiple_iterators=multiple_iterators)
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll), __pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "pysam/libcalignmentfile.pyx":1028
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_multiple_iterators);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1133
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return an iterator over the first n alignments.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10head, "AlignmentFile.head(self, n, multiple_iterators=True)\nreturn an iterator over the first n alignments.\n\n        This iterator is is useful for inspecting the bam-file.\n\n        Parameters\n        ----------\n\n        multiple_iterators : bool\n\n            is set to True by default in order to\n            avoid changing the current file position.\n\n        Returns\n        -------\n\n\t\tan iterator over a collection of reads : IteratorRowHead\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_11head = {"head", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10head};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_n = 0;
  PyObject *__pyx_v_multiple_iterators = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[2] = {0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("head (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,&__pyx_n_s_multiple_iterators,0};
    values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_True));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_n)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1133, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1133, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "head") < 0)) __PYX_ERR(0, 1133, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_n = values[0];
    __pyx_v_multiple_iterators = values[1];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("head", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 1133, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_n, __pyx_v_multiple_iterators);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10head(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__57)
  __Pyx_RefNannySetupContext("head", 1);
  __Pyx_TraceCall("head", __pyx_f[0], 1133, 0, __PYX_ERR(0, 1133, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1152
 * 
 *         '''
 *         return IteratorRowHead(self, n,             # <<<<<<<<<<<<<<
 *                                multiple_iterators=multiple_iterators)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1152, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1152, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_n);
  __Pyx_GIVEREF(__pyx_v_n);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_n)) __PYX_ERR(0, 1152, __pyx_L1_error);

  /* "pysam/libcalignmentfile.pyx":1153
 *         '''
 *         return IteratorRowHead(self, n,
 *                                multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def mate(self, AlignedSegment read):
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1153, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 1153, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1152
 * 
 *         '''
 *         return IteratorRowHead(self, n,             # <<<<<<<<<<<<<<
 *                                multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1152, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1133
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return an iterator over the first n alignments.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1155
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self, AlignedSegment read):             # <<<<<<<<<<<<<<
 *         '''return the mate of :class:`pysam.AlignedSegment` `read`.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12mate, "AlignmentFile.mate(self, AlignedSegment read)\nreturn the mate of :class:`pysam.AlignedSegment` `read`.\n\n        .. note::\n\n            Calling this method will change the file position.\n            This might interfere with any iterators that have\n            not re-opened the file.\n\n        .. note::\n\n           This method is too slow for high-throughput processing.\n           If a read needs to be processed with its mate, work\n           from a read name sorted file or, better, cache reads.\n\n        Returns\n        -------\n\n        the mate : AlignedSegment\n\n        Raises\n        ------\n\n        ValueError\n            if the read is unpaired or the mate is unmapped\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_13mate = {"mate", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12mate};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mate (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_read,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_read)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1155, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "mate") < 0)) __PYX_ERR(0, 1155, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_read = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)values[0]);
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("mate", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1155, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.mate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 1155, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_read);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12mate(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) {
  uint32_t __pyx_v_flag;
  int __pyx_v_x;
  PyObject *__pyx_v_mate = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__58)
  __Pyx_RefNannySetupContext("mate", 1);
  __Pyx_TraceCall("mate", __pyx_f[0], 1155, 0, __PYX_ERR(0, 1155, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1182
 * 
 *         '''
 *         cdef uint32_t flag = read._delegate.core.flag             # <<<<<<<<<<<<<<
 * 
 *         if flag & BAM_FPAIRED == 0:
 */
  __pyx_t_1 = __pyx_v_read->_delegate->core.flag;
  __pyx_v_flag = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":1184
 *         cdef uint32_t flag = read._delegate.core.flag
 * 
 *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 */
  __pyx_t_2 = ((__pyx_v_flag & BAM_FPAIRED) == 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1186
 *         if flag & BAM_FPAIRED == 0:
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))             # <<<<<<<<<<<<<<
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1186, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/libcalignmentfile.pyx":1185
 * 
 *         if flag & BAM_FPAIRED == 0:
 *             raise ValueError("read %s: is unpaired" %             # <<<<<<<<<<<<<<
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:
 */
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_read_s_is_unpaired, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1185, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1185, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1184
 *         cdef uint32_t flag = read._delegate.core.flag
 * 
 *         if flag & BAM_FPAIRED == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 */
  }

  /* "pysam/libcalignmentfile.pyx":1187
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("mate %s: is unmapped" %
 *                              (read.query_name))
 */
  __pyx_t_2 = ((__pyx_v_flag & BAM_FMUNMAP) != 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1189
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %
 *                              (read.query_name))             # <<<<<<<<<<<<<<
 * 
 *         # xor flags to get the other mate
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1189, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/libcalignmentfile.pyx":1188
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %             # <<<<<<<<<<<<<<
 *                              (read.query_name))
 * 
 */
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_mate_s_is_unmapped, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1188, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1188, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1188, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1187
 *             raise ValueError("read %s: is unpaired" %
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("mate %s: is unmapped" %
 *                              (read.query_name))
 */
  }

  /* "pysam/libcalignmentfile.pyx":1192
 * 
 *         # xor flags to get the other mate
 *         cdef int x = BAM_FREAD1 + BAM_FREAD2             # <<<<<<<<<<<<<<
 *         flag = (flag ^ x) & x
 * 
 */
  __pyx_v_x = (BAM_FREAD1 + BAM_FREAD2);

  /* "pysam/libcalignmentfile.pyx":1193
 *         # xor flags to get the other mate
 *         cdef int x = BAM_FREAD1 + BAM_FREAD2
 *         flag = (flag ^ x) & x             # <<<<<<<<<<<<<<
 * 
 *         # Make sure to use a separate file to jump around
 */
  __pyx_v_flag = ((__pyx_v_flag ^ __pyx_v_x) & __pyx_v_x);

  /* "pysam/libcalignmentfile.pyx":1201
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/libcalignmentfile.pyx":1202
 *         # by using tell and seek.
 *         for mate in self.fetch(
 *                 read._delegate.core.mpos,             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid,
 */
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mpos); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1202, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/libcalignmentfile.pyx":1203
 *         for mate in self.fetch(
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,             # <<<<<<<<<<<<<<
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 */
  __pyx_t_5 = __Pyx_PyInt_From_long((__pyx_v_read->_delegate->core.mpos + 1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1203, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/libcalignmentfile.pyx":1201
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4)) __PYX_ERR(0, 1201, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_5);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5)) __PYX_ERR(0, 1201, __pyx_L1_error);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":1204
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid,             # <<<<<<<<<<<<<<
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \
 */
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1204, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1204, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_4) < 0) __PYX_ERR(0, 1204, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":1205
 *                 read._delegate.core.mpos + 1,
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):             # <<<<<<<<<<<<<<
 *             if mate.flag & flag != 0 and \
 *                mate.query_name == read.query_name:
 */
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_multiple_iterators, Py_True) < 0) __PYX_ERR(0, 1204, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1201
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5);
    __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1201, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1201, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_8)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_5);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1201, __pyx_L1_error)
          #endif
          if (__pyx_t_7 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 1201, __pyx_L1_error)
        #else
        __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1201, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_5);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1201, __pyx_L1_error)
          #endif
          if (__pyx_t_7 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely((0 < 0))) __PYX_ERR(0, 1201, __pyx_L1_error)
        #else
        __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1201, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_8(__pyx_t_5);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1201, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_mate, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pysam/libcalignmentfile.pyx":1206
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \             # <<<<<<<<<<<<<<
 *                mate.query_name == read.query_name:
 *                 break
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_flag); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_flag); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyNumber_And(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = (__Pyx_PyInt_BoolNeObjC(__pyx_t_3, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 1206, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_9) {
    } else {
      __pyx_t_2 = __pyx_t_9;
      goto __pyx_L8_bool_binop_done;
    }

    /* "pysam/libcalignmentfile.pyx":1207
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \
 *                mate.query_name == read.query_name:             # <<<<<<<<<<<<<<
 *                 break
 *         else:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_mate, __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1207, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1207, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_t_6, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1207, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 1207, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __pyx_t_9;
    __pyx_L8_bool_binop_done:;

    /* "pysam/libcalignmentfile.pyx":1206
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \             # <<<<<<<<<<<<<<
 *                mate.query_name == read.query_name:
 *                 break
 */
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":1208
 *             if mate.flag & flag != 0 and \
 *                mate.query_name == read.query_name:
 *                 break             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("mate not found")
 */
      goto __pyx_L6_break;

      /* "pysam/libcalignmentfile.pyx":1206
 *                 tid=read._delegate.core.mtid,
 *                 multiple_iterators=True):
 *             if mate.flag & flag != 0 and \             # <<<<<<<<<<<<<<
 *                mate.query_name == read.query_name:
 *                 break
 */
    }

    /* "pysam/libcalignmentfile.pyx":1201
 *         # could thus be made much quicker, for example
 *         # by using tell and seek.
 *         for mate in self.fetch(             # <<<<<<<<<<<<<<
 *                 read._delegate.core.mpos,
 *                 read._delegate.core.mpos + 1,
 */
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  goto __pyx_L10_for_else;
  __pyx_L6_break:;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  goto __pyx_L11_for_end;
  /*else*/ {
    __pyx_L10_for_else:;

    /* "pysam/libcalignmentfile.pyx":1210
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__59, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1210, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 1210, __pyx_L1_error)
  }
  __pyx_L11_for_end:;

  /* "pysam/libcalignmentfile.pyx":1212
 *             raise ValueError("mate not found")
 * 
 *         return mate             # <<<<<<<<<<<<<<
 * 
 *     def pileup(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_mate);
  __pyx_r = __pyx_v_mate;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1155
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self, AlignedSegment read):             # <<<<<<<<<<<<<<
 *         '''return the mate of :class:`pysam.AlignedSegment` `read`.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.mate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mate);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1214
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14pileup, "AlignmentFile.pileup(self, contig=None, start=None, stop=None, region=None, reference=None, end=None, **kwargs)\nperform a :term:`pileup` within a :term:`region`. The region is\n        specified by :term:`contig`, `start` and `stop` (using\n        0-based indexing).  :term:`reference` and `end` are also accepted for\n        backward compatibility as synonyms for :term:`contig` and `stop`,\n        respectively.  Alternatively, a samtools 'region' string\n        can be supplied.\n\n        Without 'contig' or 'region' all reads will be used for the\n        pileup. The reads will be returned ordered by\n        :term:`contig` sequence, which will not necessarily be the\n        order within the file.\n\n        Note that :term:`SAM` formatted files do not allow random\n        access.  In these files, if a 'region' or 'contig' are\n        given an exception is raised.\n\n        .. note::\n\n            'all' reads which overlap the region are returned. The\n            first base returned will be the first base of the first\n            read 'not' necessarily the first base of the region used\n            in the query.\n\n        Parameters\n        ----------\n\n        truncate : bool\n\n           By default, the samtools pileup engine outputs all reads\n           overlapping a region. If truncate is True and a region is\n           given, only columns in the exact region specified are\n           returned.\n\n        max_depth : int\n           Maximum read depth permitted. The default limit is '8000'.\n\n        stepper : string\n           The stepper controls how the iterator advances.\n           Possible options for the stepper are\n\n           ``all``\n              skip reads in which any of the following flags are set:\n              BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL, BAM_FDUP\n\n           ``nofilter``\n              uses every single read turning off any filtering.\n\n           ``samtools``\n              same filter and read processing a""s in samtools\n              pileup. For full compatibility, this requires a\n              'fastafile' to be given. The following options all pertain\n              to filtering of the ``samtools`` stepper.\n\n        fastafile : :class:`~pysam.FastaFile` object.\n\n           This is required for some of the steppers.\n\n        ignore_overlaps: bool\n\n           If set to True, detect if read pairs overlap and only take\n           the higher quality base. This is the default.\n\n        flag_filter : int\n\n           ignore reads where any of the bits in the flag are set. The default is\n           BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP.\n\n        flag_require : int\n\n           only use reads where certain flags are set. The default is 0.\n\n        ignore_orphans: bool\n\n            ignore orphans (paired reads that are not in a proper pair).\n            The default is to ignore orphans.\n\n        min_base_quality: int\n\n           Minimum base quality. Bases below the minimum quality will\n           not be output. The default is 13.\n\n        adjust_capq_threshold: int\n\n           adjust mapping quality. The default is 0 for no\n           adjustment. The recommended value for adjustment is 50.\n\n        min_mapping_quality : int\n\n           only use reads above a minimum mapping quality. The default is 0.\n\n        compute_baq: bool\n\n           re-alignment computing per-Base Alignment Qualities (BAQ). The\n           default is to do re-alignment. Realignment requires a reference\n           sequence. If none is present, no realignment will be performed.\n\n        redo_baq: bool\n\n           recompute per-Base Alignment Quality on the fly ignoring\n           existing base qualities. The default is False (use existing\n           base qualities).\n\n        Returns\n        -------\n\n        an iterator over genomic positions. : IteratorColumn\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_15pileup = {"pileup", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14pileup};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_kwargs = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[6] = {0,0,0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("pileup (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_reference,&__pyx_n_s_end,0};

    /* "pysam/libcalignmentfile.pyx":1215
 * 
 *     def pileup(self,
 *                contig=None,             # <<<<<<<<<<<<<<
 *                start=None,
 *                stop=None,
 */
    values[0] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1216
 *     def pileup(self,
 *                contig=None,
 *                start=None,             # <<<<<<<<<<<<<<
 *                stop=None,
 *                region=None,
 */
    values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1217
 *                contig=None,
 *                start=None,
 *                stop=None,             # <<<<<<<<<<<<<<
 *                region=None,
 *                reference=None,
 */
    values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1218
 *                start=None,
 *                stop=None,
 *                region=None,             # <<<<<<<<<<<<<<
 *                reference=None,
 *                end=None,
 */
    values[3] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1219
 *                stop=None,
 *                region=None,
 *                reference=None,             # <<<<<<<<<<<<<<
 *                end=None,
 *                **kwargs):
 */
    values[4] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1220
 *                region=None,
 *                reference=None,
 *                end=None,             # <<<<<<<<<<<<<<
 *                **kwargs):
 *         """perform a :term:`pileup` within a :term:`region`. The region is
 */
    values[5] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_contig);
          if (value) { values[0] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1214, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_start);
          if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1214, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_stop);
          if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1214, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_region);
          if (value) { values[3] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1214, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference);
          if (value) { values[4] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1214, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_end);
          if (value) { values[5] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1214, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "pileup") < 0)) __PYX_ERR(0, 1214, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_reference = values[4];
    __pyx_v_end = values[5];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 6, __pyx_nargs); __PYX_ERR(0, 1214, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_reference, __pyx_v_end, __pyx_v_kwargs);

  /* "pysam/libcalignmentfile.pyx":1214
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */

  /* function exit code */
  __Pyx_DECREF(__pyx_v_kwargs);
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_14pileup(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_reference, PyObject *__pyx_v_end, PyObject *__pyx_v_kwargs) {
  int __pyx_v_rtid;
  int __pyx_v_has_coord;
  int32_t __pyx_v_rstart;
  int32_t __pyx_v_rstop;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_t_11;
  int32_t __pyx_t_12;
  int32_t __pyx_t_13;
  unsigned int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__60)
  __Pyx_RefNannySetupContext("pileup", 1);
  __Pyx_TraceCall("pileup", __pyx_f[0], 1214, 0, __PYX_ERR(0, 1214, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1333
 *         cdef int32_t rstart, rstop
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1333, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1333, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1334
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1334, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1334, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1333
 *         cdef int32_t rstart, rstop
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1336
 *             raise ValueError("I/O operation on closed file")
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_parse_region); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":1337
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(
 *             contig, start, stop, region, reference=reference, end=end)             # <<<<<<<<<<<<<<
 * 
 *         if has_coord:
 */
  __pyx_t_4 = PyTuple_New(4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_contig);
  __Pyx_GIVEREF(__pyx_v_contig);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_contig)) __PYX_ERR(0, 1336, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_start)) __PYX_ERR(0, 1336, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_stop);
  __Pyx_GIVEREF(__pyx_v_stop);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_v_stop)) __PYX_ERR(0, 1336, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_v_region)) __PYX_ERR(0, 1336, __pyx_L1_error);
  __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1337, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1337, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1337, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1336
 *             raise ValueError("I/O operation on closed file")
 * 
 *         has_coord, rtid, rstart, rstop = self.parse_region(             # <<<<<<<<<<<<<<
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
    PyObject* sequence = __pyx_t_6;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1336, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_7);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 1336, __pyx_L1_error)
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_5,&__pyx_t_4,&__pyx_t_1,&__pyx_t_7};
    __pyx_t_8 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1336, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_9 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_8);
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_9(__pyx_t_8); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 4) < 0) __PYX_ERR(0, 1336, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1336, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int32_t(__pyx_t_1); if (unlikely((__pyx_t_12 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int32_t(__pyx_t_7); if (unlikely((__pyx_t_13 == ((int32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1336, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_has_coord = __pyx_t_10;
  __pyx_v_rtid = __pyx_t_11;
  __pyx_v_rstart = __pyx_t_12;
  __pyx_v_rstop = __pyx_t_13;

  /* "pysam/libcalignmentfile.pyx":1339
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 *         if has_coord:             # <<<<<<<<<<<<<<
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")
 */
  __pyx_t_3 = (__pyx_v_has_coord != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1340
 * 
 *         if has_coord:
 *             if not self.has_index():             # <<<<<<<<<<<<<<
 *                 raise ValueError("no index available for pileup")
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1340, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_1 = NULL;
    __pyx_t_14 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
        __pyx_t_14 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL};
      __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_14, 0+__pyx_t_14);
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1340, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1340, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_2 = (!__pyx_t_3);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":1341
 *         if has_coord:
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorColumnRegion(self,
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1341, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(0, 1341, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":1340
 * 
 *         if has_coord:
 *             if not self.has_index():             # <<<<<<<<<<<<<<
 *                 raise ValueError("no index available for pileup")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":1343
 *                 raise ValueError("no index available for pileup")
 * 
 *             return IteratorColumnRegion(self,             # <<<<<<<<<<<<<<
 *                                         tid=rtid,
 *                                         start=rstart,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1343, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF((PyObject *)__pyx_v_self);
    __Pyx_GIVEREF((PyObject *)__pyx_v_self);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1343, __pyx_L1_error);

    /* "pysam/libcalignmentfile.pyx":1344
 * 
 *             return IteratorColumnRegion(self,
 *                                         tid=rtid,             # <<<<<<<<<<<<<<
 *                                         start=rstart,
 *                                         stop=rstop,
 */
    __pyx_t_1 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1344, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_tid, __pyx_t_4) < 0) __PYX_ERR(0, 1344, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/libcalignmentfile.pyx":1345
 *             return IteratorColumnRegion(self,
 *                                         tid=rtid,
 *                                         start=rstart,             # <<<<<<<<<<<<<<
 *                                         stop=rstop,
 *                                         **kwargs)
 */
    __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_rstart); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1345, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_t_4) < 0) __PYX_ERR(0, 1344, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/libcalignmentfile.pyx":1346
 *                                         tid=rtid,
 *                                         start=rstart,
 *                                         stop=rstop,             # <<<<<<<<<<<<<<
 *                                         **kwargs)
 *         else:
 */
    __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_rstop); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1346, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_stop, __pyx_t_4) < 0) __PYX_ERR(0, 1344, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":1347
 *                                         start=rstart,
 *                                         stop=rstop,
 *                                         **kwargs)             # <<<<<<<<<<<<<<
 *         else:
 *             if self.has_index():
 */
    if (__Pyx_MergeKeywords(__pyx_t_7, __pyx_v_kwargs) < 0) __PYX_ERR(0, 1347, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1343
 *                 raise ValueError("no index available for pileup")
 * 
 *             return IteratorColumnRegion(self,             # <<<<<<<<<<<<<<
 *                                         tid=rtid,
 *                                         start=rstart,
 */
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion), __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1343, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1339
 *             contig, start, stop, region, reference=reference, end=end)
 * 
 *         if has_coord:             # <<<<<<<<<<<<<<
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")
 */
  }

  /* "pysam/libcalignmentfile.pyx":1349
 *                                         **kwargs)
 *         else:
 *             if self.has_index():             # <<<<<<<<<<<<<<
 *                 return IteratorColumnAllRefs(self, **kwargs)
 *             else:
 */
  /*else*/ {
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_index); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1349, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = NULL;
    __pyx_t_14 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
        __pyx_t_14 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_14, 0+__pyx_t_14);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1349, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1349, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":1350
 *         else:
 *             if self.has_index():
 *                 return IteratorColumnAllRefs(self, **kwargs)             # <<<<<<<<<<<<<<
 *             else:
 *                 return IteratorColumnAll(self, **kwargs)
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF((PyObject *)__pyx_v_self);
      __Pyx_GIVEREF((PyObject *)__pyx_v_self);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1350, __pyx_L1_error);
      __pyx_t_7 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs), __pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_r = __pyx_t_6;
      __pyx_t_6 = 0;
      goto __pyx_L0;

      /* "pysam/libcalignmentfile.pyx":1349
 *                                         **kwargs)
 *         else:
 *             if self.has_index():             # <<<<<<<<<<<<<<
 *                 return IteratorColumnAllRefs(self, **kwargs)
 *             else:
 */
    }

    /* "pysam/libcalignmentfile.pyx":1352
 *                 return IteratorColumnAllRefs(self, **kwargs)
 *             else:
 *                 return IteratorColumnAll(self, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *     def count(self,
 */
    /*else*/ {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_INCREF((PyObject *)__pyx_v_self);
      __Pyx_GIVEREF((PyObject *)__pyx_v_self);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 1352, __pyx_L1_error);
      __pyx_t_7 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll), __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1352, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
    }
  }

  /* "pysam/libcalignmentfile.pyx":1214
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1354
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16count, "AlignmentFile.count(self, contig=None, start=None, stop=None, region=None, until_eof=False, read_callback=u'nofilter', reference=None, end=None)\ncount the number of reads in :term:`region`\n\n        The region is specified by :term:`contig`, `start` and `stop`.\n        :term:`reference` and `end` are also accepted for backward\n        compatibility as synonyms for :term:`contig` and `stop`,\n        respectively.  Alternatively, a `samtools`_ :term:`region`\n        string can be supplied.\n\n        A :term:`SAM` file does not allow random access and if\n        `region` or `contig` are given, an exception is raised.\n\n        Parameters\n        ----------\n\n        contig : string\n            reference_name of the genomic region (chromosome)\n\n        start : int\n            start of the genomic region (0-based inclusive)\n\n        stop : int\n            end of the genomic region (0-based exclusive)\n\n        region : string\n            a region string in samtools format.\n\n        until_eof : bool\n            count until the end of the file, possibly including\n            unmapped reads as well.\n\n        read_callback: string or function\n\n            select a call-back to ignore reads when counting. It can\n            be either a string with the following values:\n\n            ``all``\n                skip reads in which any of the following\n                flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n                BAM_FDUP\n\n            ``nofilter``\n                uses every single read\n\n            Alternatively, `read_callback` can be a function\n            ``check_read(read)`` that should return True only for\n            those reads that shall be included in the counting.\n\n        reference : string\n            backward compatible synonym for `contig`\n\n        end : int\n            backward compatible synonym for `stop`\n\n        Raises\n        ------\n\n        ValueError\n            if the genomic coordi""nates are out of range or invalid.\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_17count = {"count", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16count};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_until_eof = 0;
  PyObject *__pyx_v_read_callback = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[8] = {0,0,0,0,0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("count (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_until_eof,&__pyx_n_s_read_callback,&__pyx_n_s_reference,&__pyx_n_s_end,0};

    /* "pysam/libcalignmentfile.pyx":1355
 * 
 *     def count(self,
 *               contig=None,             # <<<<<<<<<<<<<<
 *               start=None,
 *               stop=None,
 */
    values[0] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1356
 *     def count(self,
 *               contig=None,
 *               start=None,             # <<<<<<<<<<<<<<
 *               stop=None,
 *               region=None,
 */
    values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1357
 *               contig=None,
 *               start=None,
 *               stop=None,             # <<<<<<<<<<<<<<
 *               region=None,
 *               until_eof=False,
 */
    values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1358
 *               start=None,
 *               stop=None,
 *               region=None,             # <<<<<<<<<<<<<<
 *               until_eof=False,
 *               read_callback="nofilter",
 */
    values[3] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1359
 *               stop=None,
 *               region=None,
 *               until_eof=False,             # <<<<<<<<<<<<<<
 *               read_callback="nofilter",
 *               reference=None,
 */
    values[4] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_False));
    values[5] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)__pyx_n_u_nofilter));

    /* "pysam/libcalignmentfile.pyx":1361
 *               until_eof=False,
 *               read_callback="nofilter",
 *               reference=None,             # <<<<<<<<<<<<<<
 *               end=None):
 *         '''count the number of reads in :term:`region`
 */
    values[6] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1362
 *               read_callback="nofilter",
 *               reference=None,
 *               end=None):             # <<<<<<<<<<<<<<
 *         '''count the number of reads in :term:`region`
 * 
 */
    values[7] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_contig);
          if (value) { values[0] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_start);
          if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_stop);
          if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_region);
          if (value) { values[3] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_until_eof);
          if (value) { values[4] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_read_callback);
          if (value) { values[5] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference);
          if (value) { values[6] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_end);
          if (value) { values[7] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1354, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "count") < 0)) __PYX_ERR(0, 1354, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_until_eof = values[4];
    __pyx_v_read_callback = values[5];
    __pyx_v_reference = values[6];
    __pyx_v_end = values[7];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count", 0, 0, 8, __pyx_nargs); __PYX_ERR(0, 1354, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_until_eof, __pyx_v_read_callback, __pyx_v_reference, __pyx_v_end);

  /* "pysam/libcalignmentfile.pyx":1354
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_16count(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) {
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0;
  long __pyx_v_counter;
  int __pyx_v_filter_method;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  unsigned int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__62)
  __Pyx_RefNannySetupContext("count", 1);
  __Pyx_TraceCall("count", __pyx_f[0], 1354, 0, __PYX_ERR(0, 1354, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1424
 *         '''
 *         cdef AlignedSegment read
 *         cdef long counter = 0             # <<<<<<<<<<<<<<
 * 
 *         if not self.is_open:
 */
  __pyx_v_counter = 0;

  /* "pysam/libcalignmentfile.pyx":1426
 *         cdef long counter = 0
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1426, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1426, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1427
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         cdef int filter_method = 0
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1427, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1427, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1426
 *         cdef long counter = 0
 * 
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1429
 *             raise ValueError("I/O operation on closed file")
 * 
 *         cdef int filter_method = 0             # <<<<<<<<<<<<<<
 *         if read_callback == "all":
 *             filter_method = 1
 */
  __pyx_v_filter_method = 0;

  /* "pysam/libcalignmentfile.pyx":1430
 * 
 *         cdef int filter_method = 0
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_read_callback, __pyx_n_u_all, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1430, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1431
 *         cdef int filter_method = 0
 *         if read_callback == "all":
 *             filter_method = 1             # <<<<<<<<<<<<<<
 *         elif read_callback == "nofilter":
 *             filter_method = 2
 */
    __pyx_v_filter_method = 1;

    /* "pysam/libcalignmentfile.pyx":1430
 * 
 *         cdef int filter_method = 0
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":1432
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_read_callback, __pyx_n_u_nofilter, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1432, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":1433
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 *             filter_method = 2             # <<<<<<<<<<<<<<
 * 
 *         for read in self.fetch(contig=contig,
 */
    __pyx_v_filter_method = 2;

    /* "pysam/libcalignmentfile.pyx":1432
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":1435
 *             filter_method = 2
 * 
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyDict_NewPresized(7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_contig, __pyx_v_contig) < 0) __PYX_ERR(0, 1435, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1436
 * 
 *         for read in self.fetch(contig=contig,
 *                                start=start,             # <<<<<<<<<<<<<<
 *                                stop=stop,
 *                                reference=reference,
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1435, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1437
 *         for read in self.fetch(contig=contig,
 *                                start=start,
 *                                stop=stop,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                end=end,
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_stop, __pyx_v_stop) < 0) __PYX_ERR(0, 1435, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1438
 *                                start=start,
 *                                stop=stop,
 *                                reference=reference,             # <<<<<<<<<<<<<<
 *                                end=end,
 *                                region=region,
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1435, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1439
 *                                stop=stop,
 *                                reference=reference,
 *                                end=end,             # <<<<<<<<<<<<<<
 *                                region=region,
 *                                until_eof=until_eof):
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1435, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1440
 *                                reference=reference,
 *                                end=end,
 *                                region=region,             # <<<<<<<<<<<<<<
 *                                until_eof=until_eof):
 *             # apply filter
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1435, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1441
 *                                end=end,
 *                                region=region,
 *                                until_eof=until_eof):             # <<<<<<<<<<<<<<
 *             # apply filter
 *             if filter_method == 1:
 */
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_until_eof, __pyx_v_until_eof) < 0) __PYX_ERR(0, 1435, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1435
 *             filter_method = 2
 * 
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1435, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
    __pyx_t_4 = __pyx_t_5; __Pyx_INCREF(__pyx_t_4);
    __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1435, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1435, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_4);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1435, __pyx_L1_error)
          #endif
          if (__pyx_t_6 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely((0 < 0))) __PYX_ERR(0, 1435, __pyx_L1_error)
        #else
        __pyx_t_5 = __Pyx_PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1435, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_4);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1435, __pyx_L1_error)
          #endif
          if (__pyx_t_6 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely((0 < 0))) __PYX_ERR(0, 1435, __pyx_L1_error)
        #else
        __pyx_t_5 = __Pyx_PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1435, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_7(__pyx_t_4);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1435, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1435, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":1443
 *                                until_eof=until_eof):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
    switch (__pyx_v_filter_method) {
      case 1:

      /* "pysam/libcalignmentfile.pyx":1445
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1445, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_t_5, __pyx_int_1796, 0x704, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1445, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1445, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":1446
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue             # <<<<<<<<<<<<<<
 *             elif filter_method == 2:
 *                 # filter = "nofilter"
 */
        goto __pyx_L5_continue;

        /* "pysam/libcalignmentfile.pyx":1445
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      }

      /* "pysam/libcalignmentfile.pyx":1443
 *                                until_eof=until_eof):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
      break;
      case 2:

      /* "pysam/libcalignmentfile.pyx":1447
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue
 *             elif filter_method == 2:             # <<<<<<<<<<<<<<
 *                 # filter = "nofilter"
 *                 pass
 */
      break;
      default:

      /* "pysam/libcalignmentfile.pyx":1451
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 *             counter += 1
 */
      __Pyx_INCREF(__pyx_v_read_callback);
      __pyx_t_5 = __pyx_v_read_callback; __pyx_t_8 = NULL;
      __pyx_t_9 = 0;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_9 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, ((PyObject *)__pyx_v_read)};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9);
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1451, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1451, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_2 = (!__pyx_t_3);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":1452
 *             else:
 *                 if not read_callback(read):
 *                     continue             # <<<<<<<<<<<<<<
 *             counter += 1
 * 
 */
        goto __pyx_L5_continue;

        /* "pysam/libcalignmentfile.pyx":1451
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 *             counter += 1
 */
      }
      break;
    }

    /* "pysam/libcalignmentfile.pyx":1453
 *                 if not read_callback(read):
 *                     continue
 *             counter += 1             # <<<<<<<<<<<<<<
 * 
 *         return counter
 */
    __pyx_v_counter = (__pyx_v_counter + 1);

    /* "pysam/libcalignmentfile.pyx":1435
 *             filter_method = 2
 * 
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
    __pyx_L5_continue:;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":1455
 *             counter += 1
 * 
 *         return counter             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_counter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1455, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1354
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_read);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1457
 *         return counter
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking             # <<<<<<<<<<<<<<
 *     def count_coverage(self,
 *                        contig,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage, "AlignmentFile.count_coverage(self, contig, start=None, stop=None, region=None, quality_threshold=15, read_callback=u'all', reference=None, end=None)\ncount the coverage of genomic positions by reads in :term:`region`.\n\n        The region is specified by :term:`contig`, `start` and `stop`.\n        :term:`reference` and `end` are also accepted for backward\n        compatibility as synonyms for :term:`contig` and `stop`,\n        respectively.  Alternatively, a `samtools`_ :term:`region`\n        string can be supplied.  The coverage is computed per-base [ACGT].\n\n        Parameters\n        ----------\n\n        contig : string\n            reference_name of the genomic region (chromosome)\n\n        start : int\n            start of the genomic region (0-based inclusive). If not\n            given, count from the start of the chromosome.\n\n        stop : int\n            end of the genomic region (0-based exclusive). If not given,\n            count to the end of the chromosome.\n\n        region : string\n            a region string.\n\n        quality_threshold : int\n            quality_threshold is the minimum quality score (in phred) a\n            base has to reach to be counted.\n\n        read_callback: string or function\n\n            select a call-back to ignore reads when counting. It can\n            be either a string with the following values:\n\n            ``all``\n                skip reads in which any of the following\n                flags are set: BAM_FUNMAP, BAM_FSECONDARY, BAM_FQCFAIL,\n                BAM_FDUP\n\n            ``nofilter``\n                uses every single read\n\n            Alternatively, `read_callback` can be a function\n            ``check_read(read)`` that should return True only for\n            those reads that shall be included in the counting.\n\n        reference : string\n            backward compatible synonym for `contig`\n\n        end : int\n            backward compatible synonym for `stop`\n\n        Ra""ises\n        ------\n\n        ValueError\n            if the genomic coordinates are out of range or invalid.\n\n        Returns\n        -------\n\n        four array.arrays of the same length in order A C G T : tuple\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage = {"count_coverage", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_contig = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_quality_threshold = 0;
  PyObject *__pyx_v_read_callback = 0;
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_end = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[8] = {0,0,0,0,0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("count_coverage (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_contig,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_region,&__pyx_n_s_quality_threshold,&__pyx_n_s_read_callback,&__pyx_n_s_reference,&__pyx_n_s_end,0};

    /* "pysam/libcalignmentfile.pyx":1460
 *     def count_coverage(self,
 *                        contig,
 *                        start=None,             # <<<<<<<<<<<<<<
 *                        stop=None,
 *                        region=None,
 */
    values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1461
 *                        contig,
 *                        start=None,
 *                        stop=None,             # <<<<<<<<<<<<<<
 *                        region=None,
 *                        quality_threshold=15,
 */
    values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1462
 *                        start=None,
 *                        stop=None,
 *                        region=None,             # <<<<<<<<<<<<<<
 *                        quality_threshold=15,
 *                        read_callback='all',
 */
    values[3] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
    values[4] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)__pyx_int_15));
    values[5] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)__pyx_n_u_all));

    /* "pysam/libcalignmentfile.pyx":1465
 *                        quality_threshold=15,
 *                        read_callback='all',
 *                        reference=None,             # <<<<<<<<<<<<<<
 *                        end=None):
 *         """count the coverage of genomic positions by reads in :term:`region`.
 */
    values[6] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));

    /* "pysam/libcalignmentfile.pyx":1466
 *                        read_callback='all',
 *                        reference=None,
 *                        end=None):             # <<<<<<<<<<<<<<
 *         """count the coverage of genomic positions by reads in :term:`region`.
 * 
 */
    values[7] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_contig)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_start);
          if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_stop);
          if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_region);
          if (value) { values[3] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_quality_threshold);
          if (value) { values[4] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_read_callback);
          if (value) { values[5] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference);
          if (value) { values[6] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_end);
          if (value) { values[7] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1457, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "count_coverage") < 0)) __PYX_ERR(0, 1457, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  8: values[7] = __Pyx_Arg_FASTCALL(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = __Pyx_Arg_FASTCALL(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_contig = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_region = values[3];
    __pyx_v_quality_threshold = values[4];
    __pyx_v_read_callback = values[5];
    __pyx_v_reference = values[6];
    __pyx_v_end = values[7];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count_coverage", 0, 1, 8, __pyx_nargs); __PYX_ERR(0, 1457, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_contig, __pyx_v_start, __pyx_v_stop, __pyx_v_region, __pyx_v_quality_threshold, __pyx_v_read_callback, __pyx_v_reference, __pyx_v_end);

  /* "pysam/libcalignmentfile.pyx":1457
 *         return counter
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking             # <<<<<<<<<<<<<<
 *     def count_coverage(self,
 *                        contig,
 */

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_contig, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_region, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback, PyObject *__pyx_v_reference, PyObject *__pyx_v_end) {
  uint32_t __pyx_v_contig_length;
  int __pyx_v__start;
  int __pyx_v__stop;
  int __pyx_v_length;
  arrayobject *__pyx_v_int_array_template = 0;
  arrayobject *__pyx_v_count_a = 0;
  arrayobject *__pyx_v_count_c = 0;
  arrayobject *__pyx_v_count_g = 0;
  arrayobject *__pyx_v_count_t = 0;
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0;
  PyObject *__pyx_v_seq = 0;
  arrayobject *__pyx_v_quality = 0;
  int __pyx_v_qpos;
  int __pyx_v_refpos;
  CYTHON_UNUSED int __pyx_v_c;
  int __pyx_v_filter_method;
  int __pyx_v__threshold;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  uint32_t __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *(*__pyx_t_17)(PyObject *);
  Py_UCS4 __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__63)
  __Pyx_RefNannySetupContext("count_coverage", 1);
  __Pyx_TraceCall("count_coverage", __pyx_f[0], 1457, 0, __PYX_ERR(0, 1457, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1532
 *         """
 * 
 *         cdef uint32_t contig_length = self.get_reference_length(contig)             # <<<<<<<<<<<<<<
 *         cdef int _start = start if start is not None else 0
 *         cdef int _stop = stop if stop is not None else contig_length
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_length); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1532, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_contig};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_5 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1532, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_contig_length = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":1533
 * 
 *         cdef uint32_t contig_length = self.get_reference_length(contig)
 *         cdef int _start = start if start is not None else 0             # <<<<<<<<<<<<<<
 *         cdef int _stop = stop if stop is not None else contig_length
 *         _stop = _stop if _stop < contig_length else contig_length
 */
  __pyx_t_7 = (__pyx_v_start != Py_None);
  if (__pyx_t_7) {
    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1533, __pyx_L1_error)
    __pyx_t_6 = __pyx_t_8;
  } else {
    __pyx_t_6 = 0;
  }
  __pyx_v__start = __pyx_t_6;

  /* "pysam/libcalignmentfile.pyx":1534
 *         cdef uint32_t contig_length = self.get_reference_length(contig)
 *         cdef int _start = start if start is not None else 0
 *         cdef int _stop = stop if stop is not None else contig_length             # <<<<<<<<<<<<<<
 *         _stop = _stop if _stop < contig_length else contig_length
 * 
 */
  __pyx_t_7 = (__pyx_v_stop != Py_None);
  if (__pyx_t_7) {
    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1534, __pyx_L1_error)
    __pyx_t_6 = __pyx_t_8;
  } else {
    __pyx_t_6 = __pyx_v_contig_length;
  }
  __pyx_v__stop = __pyx_t_6;

  /* "pysam/libcalignmentfile.pyx":1535
 *         cdef int _start = start if start is not None else 0
 *         cdef int _stop = stop if stop is not None else contig_length
 *         _stop = _stop if _stop < contig_length else contig_length             # <<<<<<<<<<<<<<
 * 
 *         if _stop == _start:
 */
  __pyx_t_7 = (__pyx_v__stop < __pyx_v_contig_length);
  if (__pyx_t_7) {
    __pyx_t_5 = __pyx_v__stop;
  } else {
    __pyx_t_5 = __pyx_v_contig_length;
  }
  __pyx_v__stop = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":1537
 *         _stop = _stop if _stop < contig_length else contig_length
 * 
 *         if _stop == _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 */
  __pyx_t_7 = (__pyx_v__stop == __pyx_v__start);
  if (unlikely(__pyx_t_7)) {

    /* "pysam/libcalignmentfile.pyx":1538
 * 
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")             # <<<<<<<<<<<<<<
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1538, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1537
 *         _stop = _stop if _stop < contig_length else contig_length
 * 
 *         if _stop == _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1539
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size less than 0")
 * 
 */
  __pyx_t_7 = (__pyx_v__stop < __pyx_v__start);
  if (unlikely(__pyx_t_7)) {

    /* "pysam/libcalignmentfile.pyx":1540
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")             # <<<<<<<<<<<<<<
 * 
 *         cdef int length = _stop - _start
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1540, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1540, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1539
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:             # <<<<<<<<<<<<<<
 *             raise ValueError("interval of size less than 0")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1542
 *             raise ValueError("interval of size less than 0")
 * 
 *         cdef int length = _stop - _start             # <<<<<<<<<<<<<<
 *         cdef c_array.array int_array_template = array.array('L', [])
 *         cdef c_array.array count_a
 */
  __pyx_v_length = (__pyx_v__stop - __pyx_v__start);

  /* "pysam/libcalignmentfile.pyx":1543
 * 
 *         cdef int length = _stop - _start
 *         cdef c_array.array int_array_template = array.array('L', [])             # <<<<<<<<<<<<<<
 *         cdef c_array.array count_a
 *         cdef c_array.array count_c
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_L);
  __Pyx_GIVEREF(__pyx_n_u_L);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_L)) __PYX_ERR(0, 1543, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1)) __PYX_ERR(0, 1543, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1543, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_int_array_template = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1548
 *         cdef c_array.array count_g
 *         cdef c_array.array count_t
 *         count_a = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_c = c_array.clone(int_array_template, length, zero=True)
 *         count_g = c_array.clone(int_array_template, length, zero=True)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1548, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_a = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1549
 *         cdef c_array.array count_t
 *         count_a = c_array.clone(int_array_template, length, zero=True)
 *         count_c = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_g = c_array.clone(int_array_template, length, zero=True)
 *         count_t = c_array.clone(int_array_template, length, zero=True)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1549, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_c = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1550
 *         count_a = c_array.clone(int_array_template, length, zero=True)
 *         count_c = c_array.clone(int_array_template, length, zero=True)
 *         count_g = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_t = c_array.clone(int_array_template, length, zero=True)
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1550, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_g = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1551
 *         count_c = c_array.clone(int_array_template, length, zero=True)
 *         count_g = c_array.clone(int_array_template, length, zero=True)
 *         count_t = c_array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 * 
 *         cdef AlignedSegment read
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1551, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_count_t = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1558
 *         cdef int qpos
 *         cdef int refpos
 *         cdef int c = 0             # <<<<<<<<<<<<<<
 *         cdef int filter_method = 0
 * 
 */
  __pyx_v_c = 0;

  /* "pysam/libcalignmentfile.pyx":1559
 *         cdef int refpos
 *         cdef int c = 0
 *         cdef int filter_method = 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_filter_method = 0;

  /* "pysam/libcalignmentfile.pyx":1562
 * 
 * 
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
  __pyx_t_7 = (__Pyx_PyUnicode_Equals(__pyx_v_read_callback, __pyx_n_u_all, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1562, __pyx_L1_error)
  if (__pyx_t_7) {

    /* "pysam/libcalignmentfile.pyx":1563
 * 
 *         if read_callback == "all":
 *             filter_method = 1             # <<<<<<<<<<<<<<
 *         elif read_callback == "nofilter":
 *             filter_method = 2
 */
    __pyx_v_filter_method = 1;

    /* "pysam/libcalignmentfile.pyx":1562
 * 
 * 
 *         if read_callback == "all":             # <<<<<<<<<<<<<<
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 */
    goto __pyx_L5;
  }

  /* "pysam/libcalignmentfile.pyx":1564
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  __pyx_t_7 = (__Pyx_PyUnicode_Equals(__pyx_v_read_callback, __pyx_n_u_nofilter, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1564, __pyx_L1_error)
  if (__pyx_t_7) {

    /* "pysam/libcalignmentfile.pyx":1565
 *             filter_method = 1
 *         elif read_callback == "nofilter":
 *             filter_method = 2             # <<<<<<<<<<<<<<
 * 
 *         cdef int _threshold = quality_threshold or 0
 */
    __pyx_v_filter_method = 2;

    /* "pysam/libcalignmentfile.pyx":1564
 *         if read_callback == "all":
 *             filter_method = 1
 *         elif read_callback == "nofilter":             # <<<<<<<<<<<<<<
 *             filter_method = 2
 * 
 */
  }
  __pyx_L5:;

  /* "pysam/libcalignmentfile.pyx":1567
 *             filter_method = 2
 * 
 *         cdef int _threshold = quality_threshold or 0             # <<<<<<<<<<<<<<
 *         for read in self.fetch(contig=contig,
 *                                reference=reference,
 */
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_quality_threshold); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1567, __pyx_L1_error)
  if (!__pyx_t_7) {
  } else {
    __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_quality_threshold); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1567, __pyx_L1_error)
    __pyx_t_6 = __pyx_t_8;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_6 = 0;
  __pyx_L6_bool_binop_done:;
  __pyx_v__threshold = __pyx_t_6;

  /* "pysam/libcalignmentfile.pyx":1568
 * 
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                start=start,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1568, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1568, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_contig, __pyx_v_contig) < 0) __PYX_ERR(0, 1568, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1569
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,
 *                                reference=reference,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                stop=stop,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reference, __pyx_v_reference) < 0) __PYX_ERR(0, 1568, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1570
 *         for read in self.fetch(contig=contig,
 *                                reference=reference,
 *                                start=start,             # <<<<<<<<<<<<<<
 *                                stop=stop,
 *                                end=end,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_start, __pyx_v_start) < 0) __PYX_ERR(0, 1568, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1571
 *                                reference=reference,
 *                                start=start,
 *                                stop=stop,             # <<<<<<<<<<<<<<
 *                                end=end,
 *                                region=region):
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_stop, __pyx_v_stop) < 0) __PYX_ERR(0, 1568, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1572
 *                                start=start,
 *                                stop=stop,
 *                                end=end,             # <<<<<<<<<<<<<<
 *                                region=region):
 *             # apply filter
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_end, __pyx_v_end) < 0) __PYX_ERR(0, 1568, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1573
 *                                stop=stop,
 *                                end=end,
 *                                region=region):             # <<<<<<<<<<<<<<
 *             # apply filter
 *             if filter_method == 1:
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_region, __pyx_v_region) < 0) __PYX_ERR(0, 1568, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1568
 * 
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                start=start,
 */
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1568, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2);
    __pyx_t_9 = 0;
    __pyx_t_10 = NULL;
  } else {
    __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1568, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1568, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_10)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1568, __pyx_L1_error)
          #endif
          if (__pyx_t_9 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely((0 < 0))) __PYX_ERR(0, 1568, __pyx_L1_error)
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1568, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1568, __pyx_L1_error)
          #endif
          if (__pyx_t_9 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely((0 < 0))) __PYX_ERR(0, 1568, __pyx_L1_error)
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1568, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_10(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1568, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1568, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_read, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1575
 *                                region=region):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
    switch (__pyx_v_filter_method) {
      case 1:

      /* "pysam/libcalignmentfile.pyx":1577
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1577, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyInt_AndObjC(__pyx_t_3, __pyx_int_1796, 0x704, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1577, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1577, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_7) {

        /* "pysam/libcalignmentfile.pyx":1578
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue             # <<<<<<<<<<<<<<
 *             elif filter_method == 2:
 *                 # filter = "nofilter"
 */
        goto __pyx_L8_continue;

        /* "pysam/libcalignmentfile.pyx":1577
 *             if filter_method == 1:
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif filter_method == 2:
 */
      }

      /* "pysam/libcalignmentfile.pyx":1575
 *                                region=region):
 *             # apply filter
 *             if filter_method == 1:             # <<<<<<<<<<<<<<
 *                 # filter = "all"
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
      break;
      case 2:

      /* "pysam/libcalignmentfile.pyx":1579
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue
 *             elif filter_method == 2:             # <<<<<<<<<<<<<<
 *                 # filter = "nofilter"
 *                 pass
 */
      break;
      default:

      /* "pysam/libcalignmentfile.pyx":1583
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
      __Pyx_INCREF(__pyx_v_read_callback);
      __pyx_t_3 = __pyx_v_read_callback; __pyx_t_11 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_11, ((PyObject *)__pyx_v_read)};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1583, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1583, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_12 = (!__pyx_t_7);
      if (__pyx_t_12) {

        /* "pysam/libcalignmentfile.pyx":1584
 *             else:
 *                 if not read_callback(read):
 *                     continue             # <<<<<<<<<<<<<<
 * 
 *             # count
 */
        goto __pyx_L8_continue;

        /* "pysam/libcalignmentfile.pyx":1583
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 * 
 */
      }
      break;
    }

    /* "pysam/libcalignmentfile.pyx":1587
 * 
 *             # count
 *             seq = read.seq             # <<<<<<<<<<<<<<
 *             if seq is None:
 *                 continue
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_seq); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1587, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(0, 1587, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_seq, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":1588
 *             # count
 *             seq = read.seq
 *             if seq is None:             # <<<<<<<<<<<<<<
 *                 continue
 *             quality = read.query_qualities
 */
    __pyx_t_12 = (__pyx_v_seq == ((PyObject*)Py_None));
    if (__pyx_t_12) {

      /* "pysam/libcalignmentfile.pyx":1589
 *             seq = read.seq
 *             if seq is None:
 *                 continue             # <<<<<<<<<<<<<<
 *             quality = read.query_qualities
 * 
 */
      goto __pyx_L8_continue;

      /* "pysam/libcalignmentfile.pyx":1588
 *             # count
 *             seq = read.seq
 *             if seq is None:             # <<<<<<<<<<<<<<
 *                 continue
 *             quality = read.query_qualities
 */
    }

    /* "pysam/libcalignmentfile.pyx":1590
 *             if seq is None:
 *                 continue
 *             quality = read.query_qualities             # <<<<<<<<<<<<<<
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1590, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) __PYX_ERR(0, 1590, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_quality, ((arrayobject *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":1592
 *             quality = read.query_qualities
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):             # <<<<<<<<<<<<<<
 *                 if qpos is not None and refpos is not None and \
 *                    _start <= refpos < _stop:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1592, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_11, Py_True};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3);
      __pyx_t_13 = 0;
      __pyx_t_14 = NULL;
    } else {
      __pyx_t_13 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1592, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_14 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_3); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1592, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_14)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_3);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1592, __pyx_L1_error)
            #endif
            if (__pyx_t_13 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely((0 < 0))) __PYX_ERR(0, 1592, __pyx_L1_error)
          #else
          __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_3);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1592, __pyx_L1_error)
            #endif
            if (__pyx_t_13 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_1); __pyx_t_13++; if (unlikely((0 < 0))) __PYX_ERR(0, 1592, __pyx_L1_error)
          #else
          __pyx_t_1 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_14(__pyx_t_3);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1592, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 1592, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_15 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_15);
        #else
        __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1592, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1592, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_16 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1592, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_17 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_16);
        index = 0; __pyx_t_11 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_11)) goto __pyx_L15_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_11);
        index = 1; __pyx_t_15 = __pyx_t_17(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L15_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_15);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_16), 2) < 0) __PYX_ERR(0, 1592, __pyx_L1_error)
        __pyx_t_17 = NULL;
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        goto __pyx_L16_unpacking_done;
        __pyx_L15_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_17 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 1592, __pyx_L1_error)
        __pyx_L16_unpacking_done:;
      }
      __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1592, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_t_15); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1592, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __pyx_v_qpos = __pyx_t_6;
      __pyx_v_refpos = __pyx_t_8;

      /* "pysam/libcalignmentfile.pyx":1593
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \             # <<<<<<<<<<<<<<
 *                    _start <= refpos < _stop:
 * 
 */
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_qpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1593, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = (__pyx_t_1 != Py_None);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_7) {
      } else {
        __pyx_t_12 = __pyx_t_7;
        goto __pyx_L18_bool_binop_done;
      }
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_refpos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1593, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = (__pyx_t_1 != Py_None);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_7) {
      } else {
        __pyx_t_12 = __pyx_t_7;
        goto __pyx_L18_bool_binop_done;
      }

      /* "pysam/libcalignmentfile.pyx":1594
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \
 *                    _start <= refpos < _stop:             # <<<<<<<<<<<<<<
 * 
 *                     # only check base quality if _threshold > 0
 */
      __pyx_t_7 = (__pyx_v__start <= __pyx_v_refpos);
      if (__pyx_t_7) {
        __pyx_t_7 = (__pyx_v_refpos < __pyx_v__stop);
      }
      __pyx_t_12 = __pyx_t_7;
      __pyx_L18_bool_binop_done:;

      /* "pysam/libcalignmentfile.pyx":1593
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \             # <<<<<<<<<<<<<<
 *                    _start <= refpos < _stop:
 * 
 */
      if (__pyx_t_12) {

        /* "pysam/libcalignmentfile.pyx":1597
 * 
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 */
        __pyx_t_7 = (__pyx_v__threshold != 0);
        if (!__pyx_t_7) {
          goto __pyx_L23_next_or;
        } else {
        }
        __pyx_t_7 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_quality)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1597, __pyx_L1_error)
        if (!__pyx_t_7) {
          goto __pyx_L23_next_or;
        } else {
        }
        __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quality), __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1597, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_15 = __Pyx_PyInt_From_int(__pyx_v__threshold); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1597, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_15);
        __pyx_t_11 = PyObject_RichCompare(__pyx_t_1, __pyx_t_15, Py_GE); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1597, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1597, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (!__pyx_t_7) {
        } else {
          __pyx_t_12 = __pyx_t_7;
          goto __pyx_L22_bool_binop_done;
        }
        __pyx_L23_next_or:;
        __pyx_t_7 = (!(__pyx_v__threshold != 0));
        __pyx_t_12 = __pyx_t_7;
        __pyx_L22_bool_binop_done:;
        if (__pyx_t_12) {

          /* "pysam/libcalignmentfile.pyx":1598
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:
 *                         if seq[qpos] == 'A':             # <<<<<<<<<<<<<<
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':
 */
          __pyx_t_18 = __Pyx_GetItemInt_Unicode(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(__pyx_t_18 == (Py_UCS4)-1)) __PYX_ERR(0, 1598, __pyx_L1_error)
          __pyx_t_12 = (__pyx_t_18 == 65);
          if (__pyx_t_12) {

            /* "pysam/libcalignmentfile.pyx":1599
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 */
            __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_a->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_a->data.as_ulongs[__pyx_t_8]) + 1);

            /* "pysam/libcalignmentfile.pyx":1598
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:
 *                         if seq[qpos] == 'A':             # <<<<<<<<<<<<<<
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':
 */
          }

          /* "pysam/libcalignmentfile.pyx":1600
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':             # <<<<<<<<<<<<<<
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':
 */
          __pyx_t_18 = __Pyx_GetItemInt_Unicode(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(__pyx_t_18 == (Py_UCS4)-1)) __PYX_ERR(0, 1600, __pyx_L1_error)
          __pyx_t_12 = (__pyx_t_18 == 67);
          if (__pyx_t_12) {

            /* "pysam/libcalignmentfile.pyx":1601
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 */
            __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_c->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_c->data.as_ulongs[__pyx_t_8]) + 1);

            /* "pysam/libcalignmentfile.pyx":1600
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':             # <<<<<<<<<<<<<<
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':
 */
          }

          /* "pysam/libcalignmentfile.pyx":1602
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':             # <<<<<<<<<<<<<<
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':
 */
          __pyx_t_18 = __Pyx_GetItemInt_Unicode(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(__pyx_t_18 == (Py_UCS4)-1)) __PYX_ERR(0, 1602, __pyx_L1_error)
          __pyx_t_12 = (__pyx_t_18 == 71);
          if (__pyx_t_12) {

            /* "pysam/libcalignmentfile.pyx":1603
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'T':
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 */
            __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_g->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_g->data.as_ulongs[__pyx_t_8]) + 1);

            /* "pysam/libcalignmentfile.pyx":1602
 *                         if seq[qpos] == 'C':
 *                             count_c.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'G':             # <<<<<<<<<<<<<<
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':
 */
          }

          /* "pysam/libcalignmentfile.pyx":1604
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':             # <<<<<<<<<<<<<<
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 * 
 */
          __pyx_t_18 = __Pyx_GetItemInt_Unicode(__pyx_v_seq, __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(__pyx_t_18 == (Py_UCS4)-1)) __PYX_ERR(0, 1604, __pyx_L1_error)
          __pyx_t_12 = (__pyx_t_18 == 84);
          if (__pyx_t_12) {

            /* "pysam/libcalignmentfile.pyx":1605
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':
 *                             count_t.data.as_ulongs[refpos - _start] += 1             # <<<<<<<<<<<<<<
 * 
 *         return count_a, count_c, count_g, count_t
 */
            __pyx_t_8 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_t->data.as_ulongs[__pyx_t_8]) = ((__pyx_v_count_t->data.as_ulongs[__pyx_t_8]) + 1);

            /* "pysam/libcalignmentfile.pyx":1604
 *                         if seq[qpos] == 'G':
 *                             count_g.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'T':             # <<<<<<<<<<<<<<
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 * 
 */
          }

          /* "pysam/libcalignmentfile.pyx":1597
 * 
 *                     # only check base quality if _threshold > 0
 *                     if (_threshold and quality and quality[qpos] >= _threshold) or not _threshold:             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 */
        }

        /* "pysam/libcalignmentfile.pyx":1593
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and \             # <<<<<<<<<<<<<<
 *                    _start <= refpos < _stop:
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":1592
 *             quality = read.query_qualities
 * 
 *             for qpos, refpos in read.get_aligned_pairs(True):             # <<<<<<<<<<<<<<
 *                 if qpos is not None and refpos is not None and \
 *                    _start <= refpos < _stop:
 */
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1568
 * 
 *         cdef int _threshold = quality_threshold or 0
 *         for read in self.fetch(contig=contig,             # <<<<<<<<<<<<<<
 *                                reference=reference,
 *                                start=start,
 */
    __pyx_L8_continue:;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":1607
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 * 
 *         return count_a, count_c, count_g, count_t             # <<<<<<<<<<<<<<
 * 
 *     def find_introns_slow(self, read_iterator):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1607, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF((PyObject *)__pyx_v_count_a);
  __Pyx_GIVEREF((PyObject *)__pyx_v_count_a);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_count_a))) __PYX_ERR(0, 1607, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_count_c);
  __Pyx_GIVEREF((PyObject *)__pyx_v_count_c);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_count_c))) __PYX_ERR(0, 1607, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_count_g);
  __Pyx_GIVEREF((PyObject *)__pyx_v_count_g);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 2, ((PyObject *)__pyx_v_count_g))) __PYX_ERR(0, 1607, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_count_t);
  __Pyx_GIVEREF((PyObject *)__pyx_v_count_t);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 3, ((PyObject *)__pyx_v_count_t))) __PYX_ERR(0, 1607, __pyx_L1_error);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1457
 *         return counter
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking             # <<<<<<<<<<<<<<
 *     def count_coverage(self,
 *                        contig,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_int_array_template);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_a);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_c);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_g);
  __Pyx_XDECREF((PyObject *)__pyx_v_count_t);
  __Pyx_XDECREF((PyObject *)__pyx_v_read);
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_XDECREF((PyObject *)__pyx_v_quality);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1609
 *         return count_a, count_c, count_g, count_t
 * 
 *     def find_introns_slow(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow, "AlignmentFile.find_introns_slow(self, read_iterator)\nReturn a dictionary {(start, stop): count}\n        Listing the intronic sites in the reads (identified by 'N' in the cigar strings),\n        and their support ( = number of reads ).\n\n        read_iterator can be the result of a .fetch(...) call.\n        Or it can be a generator filtering such reads. Example\n        samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow = {"find_introns_slow", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_read_iterator = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_introns_slow (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_read_iterator,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_read_iterator)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1609, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "find_introns_slow") < 0)) __PYX_ERR(0, 1609, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_read_iterator = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_introns_slow", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1609, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns_slow", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_read_iterator);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator) {
  PyObject *__pyx_v_res = NULL;
  PyObject *__pyx_v_r = NULL;
  PyObject *__pyx_v_last_read_pos = NULL;
  PyObject *__pyx_v_read_loc = NULL;
  PyObject *__pyx_v_genome_loc = NULL;
  PyObject *__pyx_v_start = NULL;
  PyObject *__pyx_v_stop = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__66)
  __Pyx_RefNannySetupContext("find_introns_slow", 1);
  __Pyx_TraceCall("find_introns_slow", __pyx_f[0], 1609, 0, __PYX_ERR(0, 1609, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1618
 *         samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)
 *         """
 *         res = collections.Counter()             # <<<<<<<<<<<<<<
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Counter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1618, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1618, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_v_res = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1619
 *         """
 *         res = collections.Counter()
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 */
  if (likely(PyList_CheckExact(__pyx_v_read_iterator)) || PyTuple_CheckExact(__pyx_v_read_iterator)) {
    __pyx_t_1 = __pyx_v_read_iterator; __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_read_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1619, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1619, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1619, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 1619, __pyx_L1_error)
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1619, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1619, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 1619, __pyx_L1_error)
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1619, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1619, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1620
 *         res = collections.Counter()
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:             # <<<<<<<<<<<<<<
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1620, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_n_u_N, __pyx_t_3, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1620, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_7) {

      /* "pysam/libcalignmentfile.pyx":1621
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False             # <<<<<<<<<<<<<<
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:
 */
      __Pyx_INCREF(Py_False);
      __Pyx_XDECREF_SET(__pyx_v_last_read_pos, Py_False);

      /* "pysam/libcalignmentfile.pyx":1622
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():             # <<<<<<<<<<<<<<
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_r, __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1622, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL};
        __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1622, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2);
        __pyx_t_9 = 0;
        __pyx_t_10 = NULL;
      } else {
        __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1622, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_10 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1622, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_10)) {
          if (likely(PyList_CheckExact(__pyx_t_2))) {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_2);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1622, __pyx_L1_error)
              #endif
              if (__pyx_t_9 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely((0 < 0))) __PYX_ERR(0, 1622, __pyx_L1_error)
            #else
            __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1622, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            {
              Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_2);
              #if !CYTHON_ASSUME_SAFE_MACROS
              if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1622, __pyx_L1_error)
              #endif
              if (__pyx_t_9 >= __pyx_temp) break;
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_3); __pyx_t_9++; if (unlikely((0 < 0))) __PYX_ERR(0, 1622, __pyx_L1_error)
            #else
            __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1622, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_10(__pyx_t_2);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 1622, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
          PyObject* sequence = __pyx_t_3;
          Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            __PYX_ERR(0, 1622, __pyx_L1_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_11 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_11);
          #else
          __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1622, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1622, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          #endif
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_12 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1622, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_13 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_12);
          index = 0; __pyx_t_8 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_8);
          index = 1; __pyx_t_11 = __pyx_t_13(__pyx_t_12); if (unlikely(!__pyx_t_11)) goto __pyx_L8_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_11);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_12), 2) < 0) __PYX_ERR(0, 1622, __pyx_L1_error)
          __pyx_t_13 = NULL;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          goto __pyx_L9_unpacking_done;
          __pyx_L8_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_13 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 1622, __pyx_L1_error)
          __pyx_L9_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_read_loc, __pyx_t_8);
        __pyx_t_8 = 0;
        __Pyx_XDECREF_SET(__pyx_v_genome_loc, __pyx_t_11);
        __pyx_t_11 = 0;

        /* "pysam/libcalignmentfile.pyx":1623
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:             # <<<<<<<<<<<<<<
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:
 */
        __pyx_t_14 = (__pyx_v_read_loc == Py_None);
        if (__pyx_t_14) {
        } else {
          __pyx_t_7 = __pyx_t_14;
          goto __pyx_L11_bool_binop_done;
        }
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_last_read_pos); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 1623, __pyx_L1_error)
        __pyx_t_7 = __pyx_t_14;
        __pyx_L11_bool_binop_done:;
        if (__pyx_t_7) {

          /* "pysam/libcalignmentfile.pyx":1624
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc             # <<<<<<<<<<<<<<
 *                     elif read_loc and last_read_pos is None:
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 */
          __Pyx_INCREF(__pyx_v_genome_loc);
          __Pyx_XDECREF_SET(__pyx_v_start, __pyx_v_genome_loc);

          /* "pysam/libcalignmentfile.pyx":1623
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 *                     if read_loc is None and last_read_pos:             # <<<<<<<<<<<<<<
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:
 */
          goto __pyx_L10;
        }

        /* "pysam/libcalignmentfile.pyx":1625
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:             # <<<<<<<<<<<<<<
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1
 */
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_read_loc); if (unlikely((__pyx_t_14 < 0))) __PYX_ERR(0, 1625, __pyx_L1_error)
        if (__pyx_t_14) {
        } else {
          __pyx_t_7 = __pyx_t_14;
          goto __pyx_L13_bool_binop_done;
        }
        __pyx_t_14 = (__pyx_v_last_read_pos == Py_None);
        __pyx_t_7 = __pyx_t_14;
        __pyx_L13_bool_binop_done:;
        if (__pyx_t_7) {

          /* "pysam/libcalignmentfile.pyx":1626
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:
 *                         stop = genome_loc  # we are right exclusive ,so this is correct             # <<<<<<<<<<<<<<
 *                         res[(start, stop)] += 1
 *                         del start
 */
          __Pyx_INCREF(__pyx_v_genome_loc);
          __pyx_v_stop = __pyx_v_genome_loc;

          /* "pysam/libcalignmentfile.pyx":1627
 *                     elif read_loc and last_read_pos is None:
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1             # <<<<<<<<<<<<<<
 *                         del start
 *                         del stop
 */
          if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1627, __pyx_L1_error) }
          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1627, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_INCREF(__pyx_v_start);
          __Pyx_GIVEREF(__pyx_v_start);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_start)) __PYX_ERR(0, 1627, __pyx_L1_error);
          __Pyx_INCREF(__pyx_v_stop);
          __Pyx_GIVEREF(__pyx_v_stop);
          if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_stop)) __PYX_ERR(0, 1627, __pyx_L1_error);
          __pyx_t_11 = __Pyx_PyObject_GetItem(__pyx_v_res, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1627, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_11, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1627, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (unlikely((PyObject_SetItem(__pyx_v_res, __pyx_t_3, __pyx_t_8) < 0))) __PYX_ERR(0, 1627, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pysam/libcalignmentfile.pyx":1628
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1
 *                         del start             # <<<<<<<<<<<<<<
 *                         del stop
 *                     last_read_pos = read_loc
 */
          if (unlikely(!__pyx_v_start)) { __Pyx_RaiseUnboundLocalError("start"); __PYX_ERR(0, 1628, __pyx_L1_error) }
          __Pyx_DECREF(__pyx_v_start); __pyx_v_start = 0;

          /* "pysam/libcalignmentfile.pyx":1629
 *                         res[(start, stop)] += 1
 *                         del start
 *                         del stop             # <<<<<<<<<<<<<<
 *                     last_read_pos = read_loc
 *         return res
 */
          __Pyx_DECREF(__pyx_v_stop); __pyx_v_stop = 0;

          /* "pysam/libcalignmentfile.pyx":1625
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 *                     elif read_loc and last_read_pos is None:             # <<<<<<<<<<<<<<
 *                         stop = genome_loc  # we are right exclusive ,so this is correct
 *                         res[(start, stop)] += 1
 */
        }
        __pyx_L10:;

        /* "pysam/libcalignmentfile.pyx":1630
 *                         del start
 *                         del stop
 *                     last_read_pos = read_loc             # <<<<<<<<<<<<<<
 *         return res
 * 
 */
        __Pyx_INCREF(__pyx_v_read_loc);
        __Pyx_DECREF_SET(__pyx_v_last_read_pos, __pyx_v_read_loc);

        /* "pysam/libcalignmentfile.pyx":1622
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():             # <<<<<<<<<<<<<<
 *                     if read_loc is None and last_read_pos:
 *                         start = genome_loc
 */
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysam/libcalignmentfile.pyx":1620
 *         res = collections.Counter()
 *         for r in read_iterator:
 *             if 'N' in r.cigarstring:             # <<<<<<<<<<<<<<
 *                 last_read_pos = False
 *                 for read_loc, genome_loc in r.get_aligned_pairs():
 */
    }

    /* "pysam/libcalignmentfile.pyx":1619
 *         """
 *         res = collections.Counter()
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             if 'N' in r.cigarstring:
 *                 last_read_pos = False
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1631
 *                         del stop
 *                     last_read_pos = read_loc
 *         return res             # <<<<<<<<<<<<<<
 * 
 *     def find_introns(self, read_iterator):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_res);
  __pyx_r = __pyx_v_res;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1609
 *         return count_a, count_c, count_g, count_t
 * 
 *     def find_introns_slow(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns_slow", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_res);
  __Pyx_XDECREF(__pyx_v_r);
  __Pyx_XDECREF(__pyx_v_last_read_pos);
  __Pyx_XDECREF(__pyx_v_read_loc);
  __Pyx_XDECREF(__pyx_v_genome_loc);
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_stop);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1633
 *         return res
 * 
 *     def find_introns(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns, "AlignmentFile.find_introns(self, read_iterator)\nReturn a dictionary {(start, stop): count}\n        Listing the intronic sites in the reads (identified by 'N' in the cigar strings),\n        and their support ( = number of reads ).\n\n        read_iterator can be the result of a .fetch(...) call.\n        Or it can be a generator filtering such reads. Example\n        samfile.find_introns((read for read in samfile.fetch(...) if read.is_reverse)\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns = {"find_introns", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_read_iterator = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find_introns (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_read_iterator,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_read_iterator)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1633, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "find_introns") < 0)) __PYX_ERR(0, 1633, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_read_iterator = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find_introns", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1633, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_read_iterator);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_read_iterator) {
  uint32_t __pyx_v_base_position;
  uint32_t __pyx_v_junc_start;
  uint32_t __pyx_v_nt;
  int __pyx_v_op;
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_r = 0;
  int __pyx_v_BAM_CREF_SKIP;
  PyObject *__pyx_v_res = NULL;
  PyObject *__pyx_v_match_or_deletion = NULL;
  PyObject *__pyx_v_cigar = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  uint32_t __pyx_t_7;
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *(*__pyx_t_14)(PyObject *);
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__67)
  __Pyx_RefNannySetupContext("find_introns", 1);
  __Pyx_TraceCall("find_introns", __pyx_f[0], 1633, 0, __PYX_ERR(0, 1633, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1646
 *             int op
 *             AlignedSegment r
 *             int BAM_CREF_SKIP = 3 #BAM_CREF_SKIP             # <<<<<<<<<<<<<<
 * 
 *         res = collections.Counter()
 */
  __pyx_v_BAM_CREF_SKIP = 3;

  /* "pysam/libcalignmentfile.pyx":1648
 *             int BAM_CREF_SKIP = 3 #BAM_CREF_SKIP
 * 
 *         res = collections.Counter()             # <<<<<<<<<<<<<<
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_Counter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1648, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1648, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_v_res = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1650
 *         res = collections.Counter()
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position             # <<<<<<<<<<<<<<
 *         for r in read_iterator:
 *             base_position = r.pos
 */
  __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1650, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PySet_Add(__pyx_t_1, __pyx_int_0) < 0) __PYX_ERR(0, 1650, __pyx_L1_error)
  if (PySet_Add(__pyx_t_1, __pyx_int_2) < 0) __PYX_ERR(0, 1650, __pyx_L1_error)
  if (PySet_Add(__pyx_t_1, __pyx_int_7) < 0) __PYX_ERR(0, 1650, __pyx_L1_error)
  if (PySet_Add(__pyx_t_1, __pyx_int_8) < 0) __PYX_ERR(0, 1650, __pyx_L1_error)
  __pyx_v_match_or_deletion = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1651
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             base_position = r.pos
 *             cigar = r.cigartuples
 */
  if (likely(PyList_CheckExact(__pyx_v_read_iterator)) || PyTuple_CheckExact(__pyx_v_read_iterator)) {
    __pyx_t_1 = __pyx_v_read_iterator; __Pyx_INCREF(__pyx_t_1);
    __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_read_iterator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1651, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1651, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 1651, __pyx_L1_error)
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1651, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        {
          Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_1);
          #if !CYTHON_ASSUME_SAFE_MACROS
          if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1651, __pyx_L1_error)
          #endif
          if (__pyx_t_5 >= __pyx_temp) break;
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely((0 < 0))) __PYX_ERR(0, 1651, __pyx_L1_error)
        #else
        __pyx_t_3 = __Pyx_PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1651, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_6(__pyx_t_1);
      if (unlikely(!__pyx_t_3)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 1651, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment))))) __PYX_ERR(0, 1651, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_r, ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1652
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 *         for r in read_iterator:
 *             base_position = r.pos             # <<<<<<<<<<<<<<
 *             cigar = r.cigartuples
 *             if cigar is None:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_r), __pyx_n_s_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1652, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1652, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_base_position = __pyx_t_7;

    /* "pysam/libcalignmentfile.pyx":1653
 *         for r in read_iterator:
 *             base_position = r.pos
 *             cigar = r.cigartuples             # <<<<<<<<<<<<<<
 *             if cigar is None:
 *                 continue
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_r), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1653, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_cigar, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1654
 *             base_position = r.pos
 *             cigar = r.cigartuples
 *             if cigar is None:             # <<<<<<<<<<<<<<
 *                 continue
 * 
 */
    __pyx_t_8 = (__pyx_v_cigar == Py_None);
    if (__pyx_t_8) {

      /* "pysam/libcalignmentfile.pyx":1655
 *             cigar = r.cigartuples
 *             if cigar is None:
 *                 continue             # <<<<<<<<<<<<<<
 * 
 *             for op, nt in cigar:
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":1654
 *             base_position = r.pos
 *             cigar = r.cigartuples
 *             if cigar is None:             # <<<<<<<<<<<<<<
 *                 continue
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":1657
 *                 continue
 * 
 *             for op, nt in cigar:             # <<<<<<<<<<<<<<
 *                 if op in match_or_deletion:
 *                     base_position += nt
 */
    if (likely(PyList_CheckExact(__pyx_v_cigar)) || PyTuple_CheckExact(__pyx_v_cigar)) {
      __pyx_t_3 = __pyx_v_cigar; __Pyx_INCREF(__pyx_t_3);
      __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
    } else {
      __pyx_t_9 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_cigar); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1657, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_10 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 1657, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_10)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_3);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1657, __pyx_L1_error)
            #endif
            if (__pyx_t_9 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely((0 < 0))) __PYX_ERR(0, 1657, __pyx_L1_error)
          #else
          __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1657, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          {
            Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_3);
            #if !CYTHON_ASSUME_SAFE_MACROS
            if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 1657, __pyx_L1_error)
            #endif
            if (__pyx_t_9 >= __pyx_temp) break;
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely((0 < 0))) __PYX_ERR(0, 1657, __pyx_L1_error)
          #else
          __pyx_t_2 = __Pyx_PySequence_ITEM(__pyx_t_3, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1657, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_10(__pyx_t_3);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 1657, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
        PyObject* sequence = __pyx_t_2;
        Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          __PYX_ERR(0, 1657, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_12);
        #else
        __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1657, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1657, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        #endif
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_13 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1657, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_14 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_13);
        index = 0; __pyx_t_11 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_11)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_11);
        index = 1; __pyx_t_12 = __pyx_t_14(__pyx_t_13); if (unlikely(!__pyx_t_12)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_12);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_13), 2) < 0) __PYX_ERR(0, 1657, __pyx_L1_error)
        __pyx_t_14 = NULL;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        goto __pyx_L9_unpacking_done;
        __pyx_L8_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_14 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 1657, __pyx_L1_error)
        __pyx_L9_unpacking_done:;
      }
      __pyx_t_15 = __Pyx_PyInt_As_int(__pyx_t_11); if (unlikely((__pyx_t_15 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1657, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_12); if (unlikely((__pyx_t_7 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 1657, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_v_op = __pyx_t_15;
      __pyx_v_nt = __pyx_t_7;

      /* "pysam/libcalignmentfile.pyx":1658
 * 
 *             for op, nt in cigar:
 *                 if op in match_or_deletion:             # <<<<<<<<<<<<<<
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:
 */
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_op); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1658, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = (__Pyx_PySet_ContainsTF(__pyx_t_2, __pyx_v_match_or_deletion, Py_EQ)); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 1658, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_8) {

        /* "pysam/libcalignmentfile.pyx":1659
 *             for op, nt in cigar:
 *                 if op in match_or_deletion:
 *                     base_position += nt             # <<<<<<<<<<<<<<
 *                 elif op == BAM_CREF_SKIP:
 *                     junc_start = base_position
 */
        __pyx_v_base_position = (__pyx_v_base_position + __pyx_v_nt);

        /* "pysam/libcalignmentfile.pyx":1658
 * 
 *             for op, nt in cigar:
 *                 if op in match_or_deletion:             # <<<<<<<<<<<<<<
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:
 */
        goto __pyx_L10;
      }

      /* "pysam/libcalignmentfile.pyx":1660
 *                 if op in match_or_deletion:
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     junc_start = base_position
 *                     base_position += nt
 */
      __pyx_t_8 = (__pyx_v_op == __pyx_v_BAM_CREF_SKIP);
      if (__pyx_t_8) {

        /* "pysam/libcalignmentfile.pyx":1661
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:
 *                     junc_start = base_position             # <<<<<<<<<<<<<<
 *                     base_position += nt
 *                     res[(junc_start, base_position)] += 1
 */
        __pyx_v_junc_start = __pyx_v_base_position;

        /* "pysam/libcalignmentfile.pyx":1662
 *                 elif op == BAM_CREF_SKIP:
 *                     junc_start = base_position
 *                     base_position += nt             # <<<<<<<<<<<<<<
 *                     res[(junc_start, base_position)] += 1
 *         return res
 */
        __pyx_v_base_position = (__pyx_v_base_position + __pyx_v_nt);

        /* "pysam/libcalignmentfile.pyx":1663
 *                     junc_start = base_position
 *                     base_position += nt
 *                     res[(junc_start, base_position)] += 1             # <<<<<<<<<<<<<<
 *         return res
 * 
 */
        __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_junc_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1663, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_12 = __Pyx_PyInt_From_uint32_t(__pyx_v_base_position); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1663, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1663, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_2);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2)) __PYX_ERR(0, 1663, __pyx_L1_error);
        __Pyx_GIVEREF(__pyx_t_12);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_12)) __PYX_ERR(0, 1663, __pyx_L1_error);
        __pyx_t_2 = 0;
        __pyx_t_12 = 0;
        __pyx_t_12 = __Pyx_PyObject_GetItem(__pyx_v_res, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 1663, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_12, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1663, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        if (unlikely((PyObject_SetItem(__pyx_v_res, __pyx_t_11, __pyx_t_2) < 0))) __PYX_ERR(0, 1663, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "pysam/libcalignmentfile.pyx":1660
 *                 if op in match_or_deletion:
 *                     base_position += nt
 *                 elif op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                     junc_start = base_position
 *                     base_position += nt
 */
      }
      __pyx_L10:;

      /* "pysam/libcalignmentfile.pyx":1657
 *                 continue
 * 
 *             for op, nt in cigar:             # <<<<<<<<<<<<<<
 *                 if op in match_or_deletion:
 *                     base_position += nt
 */
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":1651
 * 
 *         match_or_deletion = {0, 2, 7, 8} # only M/=/X (0/7/8) and D (2) are related to genome position
 *         for r in read_iterator:             # <<<<<<<<<<<<<<
 *             base_position = r.pos
 *             cigar = r.cigartuples
 */
    __pyx_L3_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1664
 *                     base_position += nt
 *                     res[(junc_start, base_position)] += 1
 *         return res             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_res);
  __pyx_r = __pyx_v_res;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1633
 *         return res
 * 
 *     def find_introns(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.find_introns", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_r);
  __Pyx_XDECREF(__pyx_v_res);
  __Pyx_XDECREF(__pyx_v_match_or_deletion);
  __Pyx_XDECREF(__pyx_v_cigar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1667
 * 
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24close, "AlignmentFile.close(self)\ncloses the :class:`pysam.AlignmentFile`.");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_25close = {"close", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24close};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("close", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "close", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_24close(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__68)
  __Pyx_RefNannySetupContext("close", 1);
  __Pyx_TraceCall("close", __pyx_f[0], 1667, 0, __PYX_ERR(0, 1667, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1670
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 *         if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_1 = (__pyx_v_self->__pyx_base.htsfile == NULL);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1671
 * 
 *         if self.htsfile == NULL:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         if self.index != NULL:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1670
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 *         if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1673
 *             return
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  __pyx_t_1 = (__pyx_v_self->index != NULL);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1674
 * 
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)             # <<<<<<<<<<<<<<
 *             self.index = NULL
 * 
 */
    hts_idx_destroy(__pyx_v_self->index);

    /* "pysam/libcalignmentfile.pyx":1675
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)
 *             self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret = hts_close(self.htsfile)
 */
    __pyx_v_self->index = NULL;

    /* "pysam/libcalignmentfile.pyx":1673
 *             return
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1677
 *             self.index = NULL
 * 
 *         cdef int ret = hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *         self.htsfile = NULL
 * 
 */
  __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile);

  /* "pysam/libcalignmentfile.pyx":1678
 * 
 *         cdef int ret = hts_close(self.htsfile)
 *         self.htsfile = NULL             # <<<<<<<<<<<<<<
 * 
 *         self.header = None
 */
  __pyx_v_self->__pyx_base.htsfile = NULL;

  /* "pysam/libcalignmentfile.pyx":1680
 *         self.htsfile = NULL
 * 
 *         self.header = None             # <<<<<<<<<<<<<<
 * 
 *         if ret < 0:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
  __Pyx_DECREF((PyObject *)__pyx_v_self->header);
  __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None);

  /* "pysam/libcalignmentfile.pyx":1682
 *         self.header = None
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  __pyx_t_1 = (__pyx_v_ret < 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1684
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
    __pyx_t_1 = (errno == EPIPE);
    if (likely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":1685
 *             global errno
 *             if errno == EPIPE:
 *                 errno = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))
 */
      errno = 0;

      /* "pysam/libcalignmentfile.pyx":1684
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
      goto __pyx_L6;
    }

    /* "pysam/libcalignmentfile.pyx":1687
 *                 errno = 0
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_2);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2)) __PYX_ERR(0, 1687, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_4);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4)) __PYX_ERR(0, 1687, __pyx_L1_error);
      __pyx_t_2 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1687, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 1687, __pyx_L1_error)
    }
    __pyx_L6:;

    /* "pysam/libcalignmentfile.pyx":1682
 *         self.header = None
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1667
 * 
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1689
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = 0
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_26__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 1);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1689, 0, __PYX_ERR(0, 1689, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1690
 * 
 *     def __dealloc__(self):
 *         cdef int ret = 0             # <<<<<<<<<<<<<<
 * 
 *         if self.index != NULL:
 */
  __pyx_v_ret = 0;

  /* "pysam/libcalignmentfile.pyx":1692
 *         cdef int ret = 0
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  __pyx_t_1 = (__pyx_v_self->index != NULL);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1693
 * 
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)             # <<<<<<<<<<<<<<
 *             self.index = NULL
 * 
 */
    hts_idx_destroy(__pyx_v_self->index);

    /* "pysam/libcalignmentfile.pyx":1694
 *         if self.index != NULL:
 *             hts_idx_destroy(self.index)
 *             self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.htsfile != NULL:
 */
    __pyx_v_self->index = NULL;

    /* "pysam/libcalignmentfile.pyx":1692
 *         cdef int ret = 0
 * 
 *         if self.index != NULL:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             self.index = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1696
 *             self.index = NULL
 * 
 *         if self.htsfile != NULL:             # <<<<<<<<<<<<<<
 *             ret = hts_close(self.htsfile)
 *             self.htsfile = NULL
 */
  __pyx_t_1 = (__pyx_v_self->__pyx_base.htsfile != NULL);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1697
 * 
 *         if self.htsfile != NULL:
 *             ret = hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *             self.htsfile = NULL
 * 
 */
    __pyx_v_ret = hts_close(__pyx_v_self->__pyx_base.htsfile);

    /* "pysam/libcalignmentfile.pyx":1698
 *         if self.htsfile != NULL:
 *             ret = hts_close(self.htsfile)
 *             self.htsfile = NULL             # <<<<<<<<<<<<<<
 * 
 *         self.header = None
 */
    __pyx_v_self->__pyx_base.htsfile = NULL;

    /* "pysam/libcalignmentfile.pyx":1696
 *             self.index = NULL
 * 
 *         if self.htsfile != NULL:             # <<<<<<<<<<<<<<
 *             ret = hts_close(self.htsfile)
 *             self.htsfile = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1700
 *             self.htsfile = NULL
 * 
 *         self.header = None             # <<<<<<<<<<<<<<
 * 
 *         if self.b:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
  __Pyx_DECREF((PyObject *)__pyx_v_self->header);
  __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None);

  /* "pysam/libcalignmentfile.pyx":1702
 *         self.header = None
 * 
 *         if self.b:             # <<<<<<<<<<<<<<
 *             bam_destroy1(self.b)
 *             self.b = NULL
 */
  __pyx_t_1 = (__pyx_v_self->b != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1703
 * 
 *         if self.b:
 *             bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *             self.b = NULL
 * 
 */
    bam_destroy1(__pyx_v_self->b);

    /* "pysam/libcalignmentfile.pyx":1704
 *         if self.b:
 *             bam_destroy1(self.b)
 *             self.b = NULL             # <<<<<<<<<<<<<<
 * 
 *         if ret < 0:
 */
    __pyx_v_self->b = NULL;

    /* "pysam/libcalignmentfile.pyx":1702
 *         self.header = None
 * 
 *         if self.b:             # <<<<<<<<<<<<<<
 *             bam_destroy1(self.b)
 *             self.b = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":1706
 *             self.b = NULL
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  __pyx_t_1 = (__pyx_v_ret < 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":1708
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
    __pyx_t_1 = (errno == EPIPE);
    if (likely(__pyx_t_1)) {

      /* "pysam/libcalignmentfile.pyx":1709
 *             global errno
 *             if errno == EPIPE:
 *                 errno = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))
 */
      errno = 0;

      /* "pysam/libcalignmentfile.pyx":1708
 *         if ret < 0:
 *             global errno
 *             if errno == EPIPE:             # <<<<<<<<<<<<<<
 *                 errno = 0
 *             else:
 */
      goto __pyx_L7;
    }

    /* "pysam/libcalignmentfile.pyx":1711
 *                 errno = 0
 *             else:
 *                 raise IOError(errno, force_str(strerror(errno)))             # <<<<<<<<<<<<<<
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyInt_From_int(errno); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyBytes_FromString(strerror(errno)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __pyx_f_5pysam_9libcutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_2);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2)) __PYX_ERR(0, 1711, __pyx_L1_error);
      __Pyx_GIVEREF(__pyx_t_4);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4)) __PYX_ERR(0, 1711, __pyx_L1_error);
      __pyx_t_2 = 0;
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 1711, __pyx_L1_error)
    }
    __pyx_L7:;

    /* "pysam/libcalignmentfile.pyx":1706
 *             self.b = NULL
 * 
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             global errno
 *             if errno == EPIPE:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1689
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = 0
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.AlignmentFile.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/libcalignmentfile.pyx":1713
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedSegment` to disk.
 */

static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read, int __pyx_skip_dispatch) {
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__69)
  __Pyx_RefNannySetupContext("write", 1);
  __Pyx_TraceCall("write", __pyx_f[0], 1713, 0, __PYX_ERR(0, 1713, __pyx_L1_error));
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || __Pyx_PyType_HasFeature(Py_TYPE(((PyObject *)__pyx_v_self)), (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {
    #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
    if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) {
      PY_UINT64_T __pyx_typedict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      #endif
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1713, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!__Pyx_IsSameCFunction(__pyx_t_1, (void*) __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write)) {
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
        __pyx_t_5 = 0;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_5 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_4, ((PyObject *)__pyx_v_read)};
          __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1713, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
        __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1713, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_r = __pyx_t_6;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L0;
      }
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
      __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self));
      __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self));
      if (unlikely(__pyx_typedict_guard != __pyx_tp_dict_version)) {
        __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT;
      }
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
    }
    #endif
  }

  /* "pysam/libcalignmentfile.pyx":1726
 *                 this will be 0.
 *         '''
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1726, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = (!__pyx_t_7);
  if (__pyx_t_8) {

    /* "pysam/libcalignmentfile.pyx":1727
 *         '''
 *         if not self.is_open:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1726
 *                 this will be 0.
 *         '''
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1729
 *             return 0
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "AlignedSegment refers to reference number {} that "
 */
  __pyx_t_8 = (__pyx_v_self->header->ptr->n_targets <= __pyx_v_read->_delegate->core.tid);
  if (unlikely(__pyx_t_8)) {

    /* "pysam/libcalignmentfile.pyx":1732
 *             raise ValueError(
 *                 "AlignedSegment refers to reference number {} that "
 *                 "is larger than the number of references ({}) in the header".format(             # <<<<<<<<<<<<<<
 *                     read._delegate.core.tid, self.header.ptr.n_targets))
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_AlignedSegment_refers_to_referen, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1732, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "pysam/libcalignmentfile.pyx":1733
 *                 "AlignedSegment refers to reference number {} that "
 *                 "is larger than the number of references ({}) in the header".format(
 *                     read._delegate.core.tid, self.header.ptr.n_targets))             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret
 */
    __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1733, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_self->header->ptr->n_targets); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1733, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_9 = NULL;
    __pyx_t_5 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_5 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[3] = {__pyx_t_9, __pyx_t_3, __pyx_t_4};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_5, 2+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }

    /* "pysam/libcalignmentfile.pyx":1730
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "AlignedSegment refers to reference number {} that "
 *                 "is larger than the number of references ({}) in the header".format(
 */
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1730, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1729
 *             return 0
 * 
 *         if self.header.ptr.n_targets <= read._delegate.core.tid:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "AlignedSegment refers to reference number {} that "
 */
  }

  /* "pysam/libcalignmentfile.pyx":1736
 * 
 *         cdef int ret
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_write1(self.htsfile,
 *                              self.header.ptr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":1737
 *         cdef int ret
 *         with nogil:
 *             ret = sam_write1(self.htsfile,             # <<<<<<<<<<<<<<
 *                              self.header.ptr,
 *                              read._delegate)
 */
        __pyx_v_ret = sam_write1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->header->ptr, __pyx_v_read->_delegate);
      }

      /* "pysam/libcalignmentfile.pyx":1736
 * 
 *         cdef int ret
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_write1(self.htsfile,
 *                              self.header.ptr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L7;
        }
        __pyx_L7:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":1744
 *         #      when ret == -1 we get a "SystemError: error return without
 *         #      exception set".
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             raise IOError(
 *             "sam_write1 failed with error code {}".format(ret))
 */
  __pyx_t_8 = (__pyx_v_ret < 0);
  if (unlikely(__pyx_t_8)) {

    /* "pysam/libcalignmentfile.pyx":1746
 *         if ret < 0:
 *             raise IOError(
 *             "sam_write1 failed with error code {}".format(ret))             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_sam_write1_failed_with_error_cod, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1746, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = NULL;
    __pyx_t_5 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_5 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_4};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1746, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }

    /* "pysam/libcalignmentfile.pyx":1745
 *         #      exception set".
 *         if ret < 0:
 *             raise IOError(             # <<<<<<<<<<<<<<
 *             "sam_write1 failed with error code {}".format(ret))
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1745, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1744
 *         #      when ret == -1 we get a "SystemError: error return without
 *         #      exception set".
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             raise IOError(
 *             "sam_write1 failed with error code {}".format(ret))
 */
  }

  /* "pysam/libcalignmentfile.pyx":1748
 *             "sam_write1 failed with error code {}".format(ret))
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     # context manager interface
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1713
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedSegment` to disk.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28write, "AlignmentFile.write(self, AlignedSegment read) -> int\n\n        write a single :class:`pysam.AlignedSegment` to disk.\n\n        Raises:\n            ValueError\n                if the writing failed\n\n        Returns:\n            int :\n                the number of bytes written. If the file is closed,\n                this will be 0.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_29write = {"write", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_28write};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_29write(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_read,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_read)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1713, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "write") < 0)) __PYX_ERR(0, 1713, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_read = ((struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *)values[0]);
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("write", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1713, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment, 1, "read", 0))) __PYX_ERR(0, 1713, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_read);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_28write(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *__pyx_v_read) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__69)
  __Pyx_RefNannySetupContext("write", 1);
  __Pyx_TraceCall("write (wrapper)", __pyx_f[0], 1713, 0, __PYX_ERR(0, 1713, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write(__pyx_v_self, __pyx_v_read, 1); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1713, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1713, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1751
 * 
 *     # context manager interface
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__, "AlignmentFile.__enter__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__ = {"__enter__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__enter__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__enter__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__70)
  __Pyx_RefNannySetupContext("__enter__", 1);
  __Pyx_TraceCall("__enter__", __pyx_f[0], 1751, 0, __PYX_ERR(0, 1751, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1752
 *     # context manager interface
 *     def __enter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1751
 * 
 *     # context manager interface
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1754
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 *         return False
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__, "AlignmentFile.__exit__(self, exc_type, exc_value, traceback)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__ = {"__exit__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0;
  CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0;
  CYTHON_UNUSED PyObject *__pyx_v_traceback = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[3] = {0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exc_type,&__pyx_n_s_exc_value,&__pyx_n_s_traceback,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_exc_type)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1754, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_exc_value)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1754, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 1754, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_traceback)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[2]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1754, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 1754, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__exit__") < 0)) __PYX_ERR(0, 1754, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 3)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
      values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
    }
    __pyx_v_exc_type = values[0];
    __pyx_v_exc_value = values[1];
    __pyx_v_traceback = values[2];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 1754, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_exc_type, __pyx_v_exc_value, __pyx_v_traceback);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_exc_type, CYTHON_UNUSED PyObject *__pyx_v_exc_value, CYTHON_UNUSED PyObject *__pyx_v_traceback) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__71)
  __Pyx_RefNannySetupContext("__exit__", 1);
  __Pyx_TraceCall("__exit__", __pyx_f[0], 1754, 0, __PYX_ERR(0, 1754, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1755
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()             # <<<<<<<<<<<<<<
 *         return False
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1756
 *     def __exit__(self, exc_type, exc_value, traceback):
 *         self.close()
 *         return False             # <<<<<<<<<<<<<<
 * 
 *     ###############################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_False);
  __pyx_r = Py_False;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1754
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 *         return False
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1770
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_tid;
  uint64_t __pyx_v_total;
  uint64_t __pyx_v_mapped;
  uint64_t __pyx_v_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1770, 0, __PYX_ERR(0, 1770, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1771
 *         """
 *         def __get__(self):
 *             self.check_index()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = 0
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1771, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1773
 *             self.check_index()
 *             cdef int tid
 *             cdef uint64_t total = 0             # <<<<<<<<<<<<<<
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 */
  __pyx_v_total = 0;

  /* "pysam/libcalignmentfile.pyx":1775
 *             cdef uint64_t total = 0
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1775, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1775, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {

    /* "pysam/libcalignmentfile.pyx":1776
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":1777
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *                 total += mapped
 *             return total
 */
          (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped)));
        }

        /* "pysam/libcalignmentfile.pyx":1776
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":1778
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped             # <<<<<<<<<<<<<<
 *             return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + __pyx_v_mapped);
  }

  /* "pysam/libcalignmentfile.pyx":1779
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += mapped
 *             return total             # <<<<<<<<<<<<<<
 * 
 *     property unmapped:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1770
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.mapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1788
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_tid;
  uint64_t __pyx_v_total;
  uint64_t __pyx_v_mapped;
  uint64_t __pyx_v_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1788, 0, __PYX_ERR(0, 1788, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1789
 *         """
 *         def __get__(self):
 *             self.check_index()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = hts_idx_get_n_no_coor(self.index)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1789, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1789, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1791
 *             self.check_index()
 *             cdef int tid
 *             cdef uint64_t total = hts_idx_get_n_no_coor(self.index)             # <<<<<<<<<<<<<<
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 */
  __pyx_v_total = hts_idx_get_n_no_coor(__pyx_v_self->index);

  /* "pysam/libcalignmentfile.pyx":1793
 *             cdef uint64_t total = hts_idx_get_n_no_coor(self.index)
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1793, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1793, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {

    /* "pysam/libcalignmentfile.pyx":1794
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":1795
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *                 total += unmapped
 *             return total
 */
          (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped)));
        }

        /* "pysam/libcalignmentfile.pyx":1794
 *             cdef uint64_t mapped, unmapped
 *             for tid from 0 <= tid < self.header.nreferences:
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":1796
 *                 with nogil:
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped             # <<<<<<<<<<<<<<
 *             return total
 * 
 */
    __pyx_v_total = (__pyx_v_total + __pyx_v_unmapped);
  }

  /* "pysam/libcalignmentfile.pyx":1797
 *                     hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *                 total += unmapped
 *             return total             # <<<<<<<<<<<<<<
 * 
 *     property nocoordinate:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_total); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1797, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1788
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef int tid
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.unmapped.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1806
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef uint64_t n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  uint64_t __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1806, 0, __PYX_ERR(0, 1806, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1807
 *         """
 *         def __get__(self):
 *             self.check_index()             # <<<<<<<<<<<<<<
 *             cdef uint64_t n
 *             with nogil:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1807, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1807, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1809
 *             self.check_index()
 *             cdef uint64_t n
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 n = hts_idx_get_n_no_coor(self.index)
 *             return n
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":1810
 *             cdef uint64_t n
 *             with nogil:
 *                 n = hts_idx_get_n_no_coor(self.index)             # <<<<<<<<<<<<<<
 *             return n
 * 
 */
        __pyx_v_n = hts_idx_get_n_no_coor(__pyx_v_self->index);
      }

      /* "pysam/libcalignmentfile.pyx":1809
 *             self.check_index()
 *             cdef uint64_t n
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 n = hts_idx_get_n_no_coor(self.index)
 *             return n
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":1811
 *             with nogil:
 *                 n = hts_idx_get_n_no_coor(self.index)
 *             return n             # <<<<<<<<<<<<<<
 * 
 *     def get_index_statistics(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1811, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1806
 *         index format does not record these statistics.)
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self.check_index()
 *             cdef uint64_t n
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.nocoordinate.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1813
 *             return n
 * 
 *     def get_index_statistics(self):             # <<<<<<<<<<<<<<
 *         """return statistics about mapped/unmapped reads per chromosome as
 *         they are stored in the index, similarly to the statistics printed
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics, "AlignmentFile.get_index_statistics(self)\nreturn statistics about mapped/unmapped reads per chromosome as\n        they are stored in the index, similarly to the statistics printed\n        by the ``samtools idxstats`` command.\n\n        CRAI indexes do not record these statistics, so for a CRAM file\n        with a .crai index the returned statistics will all be 0.\n\n        Returns:\n            list :\n                a list of records for each chromosome. Each record has the\n                attributes 'contig', 'mapped', 'unmapped' and 'total'.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics = {"get_index_statistics", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_index_statistics (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("get_index_statistics", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "get_index_statistics", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_tid;
  uint64_t __pyx_v_mapped;
  uint64_t __pyx_v_unmapped;
  PyObject *__pyx_v_results = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__72)
  __Pyx_RefNannySetupContext("get_index_statistics", 1);
  __Pyx_TraceCall("get_index_statistics", __pyx_f[0], 1813, 0, __PYX_ERR(0, 1813, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1827
 *         """
 * 
 *         self.check_index()             # <<<<<<<<<<<<<<
 *         cdef int tid
 *         cdef uint64_t mapped, unmapped
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_check_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1827, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1827, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1830
 *         cdef int tid
 *         cdef uint64_t mapped, unmapped
 *         results = []             # <<<<<<<<<<<<<<
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_results = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":1832
 *         results = []
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1832, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1832, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (__pyx_v_tid = 0; __pyx_v_tid < __pyx_t_5; __pyx_v_tid++) {

    /* "pysam/libcalignmentfile.pyx":1833
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":1834
 *         for tid from 0 <= tid < self.nreferences:
 *             with nogil:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)             # <<<<<<<<<<<<<<
 *             results.append(
 *                 IndexStats._make((
 */
          (void)(hts_idx_get_stat(__pyx_v_self->index, __pyx_v_tid, (&__pyx_v_mapped), (&__pyx_v_unmapped)));
        }

        /* "pysam/libcalignmentfile.pyx":1833
 *         # TODO: use header
 *         for tid from 0 <= tid < self.nreferences:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":1836
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(
 *                 IndexStats._make((             # <<<<<<<<<<<<<<
 *                     self.get_reference_name(tid),
 *                     mapped,
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_IndexStats); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1836, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_make); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1836, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":1837
 *             results.append(
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),             # <<<<<<<<<<<<<<
 *                     mapped,
 *                     unmapped,
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_7};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1837, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }

    /* "pysam/libcalignmentfile.pyx":1838
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),
 *                     mapped,             # <<<<<<<<<<<<<<
 *                     unmapped,
 *                     mapped + unmapped)))
 */
    __pyx_t_6 = __Pyx_PyInt_From_uint64_t(__pyx_v_mapped); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1838, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "pysam/libcalignmentfile.pyx":1839
 *                     self.get_reference_name(tid),
 *                     mapped,
 *                     unmapped,             # <<<<<<<<<<<<<<
 *                     mapped + unmapped)))
 * 
 */
    __pyx_t_7 = __Pyx_PyInt_From_uint64_t(__pyx_v_unmapped); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1839, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);

    /* "pysam/libcalignmentfile.pyx":1840
 *                     mapped,
 *                     unmapped,
 *                     mapped + unmapped)))             # <<<<<<<<<<<<<<
 * 
 *         return results
 */
    __pyx_t_8 = __Pyx_PyInt_From_uint64_t((__pyx_v_mapped + __pyx_v_unmapped)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1840, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);

    /* "pysam/libcalignmentfile.pyx":1837
 *             results.append(
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),             # <<<<<<<<<<<<<<
 *                     mapped,
 *                     unmapped,
 */
    __pyx_t_9 = PyTuple_New(4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1837, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_2);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_2)) __PYX_ERR(0, 1837, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_6);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_6)) __PYX_ERR(0, 1837, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_7);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_7)) __PYX_ERR(0, 1837, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_8);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_8)) __PYX_ERR(0, 1837, __pyx_L1_error);
    __pyx_t_2 = 0;
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;
    __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_9};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1836, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }

    /* "pysam/libcalignmentfile.pyx":1835
 *             with nogil:
 *                 hts_idx_get_stat(self.index, tid, &mapped, &unmapped)
 *             results.append(             # <<<<<<<<<<<<<<
 *                 IndexStats._make((
 *                     self.get_reference_name(tid),
 */
    __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_results, __pyx_t_1); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 1835, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/libcalignmentfile.pyx":1842
 *                     mapped + unmapped)))
 * 
 *         return results             # <<<<<<<<<<<<<<
 * 
 *     ###############################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_results);
  __pyx_r = __pyx_v_results;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1813
 *             return n
 * 
 *     def get_index_statistics(self):             # <<<<<<<<<<<<<<
 *         """return statistics about mapped/unmapped reads per chromosome as
 *         they are stored in the index, similarly to the statistics printed
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_index_statistics", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1849
 *     ## and multiple_iterators)
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_36__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 1);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1849, 0, __PYX_ERR(0, 1849, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1850
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1851
 *     def __iter__(self):
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         if not self.is_bam and self.header.nreferences == 0:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1851, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1851, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1850
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):
 *         if not self.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":1853
 *             raise ValueError("I/O operation on closed file")
 * 
 *         if not self.is_bam and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1853, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1853, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = (!__pyx_t_2);
  if (__pyx_t_4) {
  } else {
    __pyx_t_3 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1853, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_1, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 1853, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __pyx_t_4;
  __pyx_L5_bool_binop_done:;
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":1854
 * 
 *         if not self.is_bam and self.header.nreferences == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1854, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 1854, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1853
 *             raise ValueError("I/O operation on closed file")
 * 
 *         if not self.is_bam and self.header.nreferences == 0:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 */
  }

  /* "pysam/libcalignmentfile.pyx":1856
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1849
 *     ## and multiple_iterators)
 *     ## Possible solutions: deprecate or open new file handle
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1858
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1858, 0, __PYX_ERR(0, 1858, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1859
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1858
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1861
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`.
 */

static int __pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  bam_hdr_t *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("cnext", __pyx_f[0], 1861, 0, __PYX_ERR(0, 1861, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1866
 *         '''
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_1 = __pyx_v_self->header->ptr;
  __pyx_v_hdr = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":1867
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":1868
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->b);
      }

      /* "pysam/libcalignmentfile.pyx":1867
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":1871
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1861
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1873
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_38__next__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  unsigned int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1873, 0, __PYX_ERR(0, 1873, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1874
 * 
 *     def __next__(self):
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self->__pyx_base.__pyx_vtab)->cnext(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1874, __pyx_L1_error)
  __pyx_v_ret = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":1875
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  __pyx_t_2 = (__pyx_v_ret >= 0);
  if (likely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1876
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((PyObject *)__pyx_v_self->header);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_3))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1876, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1875
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1877
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_2 = (__pyx_v_ret == -1L);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":1878
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __pyx_error_without_exception = 1;
    goto __pyx_L1_error;;

    /* "pysam/libcalignmentfile.pyx":1877
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1880
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 *     ###########################################
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1880, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1880, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_7 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_5};
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1880, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1880, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 1880, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1873
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1884
 *     ###########################################
 *     # methods/properties referencing the header
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid, "AlignmentFile.is_valid_tid(self, int tid)\n\n        return True if the numerical :term:`tid` is valid; False otherwise.\n\n        Note that the unmapped tid code (-1) counts as an invalid.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid = {"is_valid_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_tid;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("is_valid_tid (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tid,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1884, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "is_valid_tid") < 0)) __PYX_ERR(0, 1884, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_tid = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1884, __pyx_L3_error)
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("is_valid_tid", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1884, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_tid);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, int __pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  unsigned int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__74)
  __Pyx_RefNannySetupContext("is_valid_tid", 1);
  __Pyx_TraceCall("is_valid_tid", __pyx_f[0], 1884, 0, __PYX_ERR(0, 1884, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1890
 *         Note that the unmapped tid code (-1) counts as an invalid.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.is_valid_tid(tid)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1891
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.is_valid_tid(tid)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1891, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1891, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1890
 *         Note that the unmapped tid code (-1) counts as an invalid.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.is_valid_tid(tid)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1892
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.is_valid_tid(tid)             # <<<<<<<<<<<<<<
 * 
 *     def get_tid(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_is_valid_tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1892, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_6 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_4};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1892, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1884
 *     ###########################################
 *     # methods/properties referencing the header
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.is_valid_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1894
 *         return self.header.is_valid_tid(tid)
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid, "AlignmentFile.get_tid(self, reference)\n\n        return the numerical :term:`tid` corresponding to\n        :term:`reference`\n\n        returns -1 if reference is not known.\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid = {"get_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_reference = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tid (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1894, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_tid") < 0)) __PYX_ERR(0, 1894, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_reference = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_tid", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1894, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__76)
  __Pyx_RefNannySetupContext("get_tid", 1);
  __Pyx_TraceCall("get_tid", __pyx_f[0], 1894, 0, __PYX_ERR(0, 1894, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1901
 *         returns -1 if reference is not known.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_tid(reference)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1902
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.get_tid(reference)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1902, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1902, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1901
 *         returns -1 if reference is not known.
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_tid(reference)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1903
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_tid(reference)             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_name(self, tid):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1903, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_reference};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1903, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1894
 *         return self.header.is_valid_tid(tid)
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_tid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1905
 *         return self.header.get_tid(reference)
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name, "AlignmentFile.get_reference_name(self, tid)\n\n        return :term:`reference` name corresponding to numerical :term:`tid`\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name = {"get_reference_name", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_tid = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_name (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tid,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1905, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_reference_name") < 0)) __PYX_ERR(0, 1905, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_tid = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_reference_name", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1905, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_tid);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__77)
  __Pyx_RefNannySetupContext("get_reference_name", 1);
  __Pyx_TraceCall("get_reference_name", __pyx_f[0], 1905, 0, __PYX_ERR(0, 1905, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1909
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_name(tid)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1910
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.get_reference_name(tid)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1910, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1910, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1909
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_name(tid)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1911
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_name(tid)             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_length(self, reference):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1911, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_tid};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1911, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1905
 *         return self.header.get_tid(reference)
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_reference_name", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1913
 *         return self.header.get_reference_name(tid)
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length, "AlignmentFile.get_reference_length(self, reference)\n\n        return :term:`reference` length corresponding to numerical :term:`tid`\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length = {"get_reference_length", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_reference = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_length (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1913, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "get_reference_length") < 0)) __PYX_ERR(0, 1913, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_reference = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_reference_length", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1913, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__78)
  __Pyx_RefNannySetupContext("get_reference_length", 1);
  __Pyx_TraceCall("get_reference_length", __pyx_f[0], 1913, 0, __PYX_ERR(0, 1913, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1917
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_length(reference)
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->header) == Py_None);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1918
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.get_reference_length(reference)
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1918, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1918, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":1917
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 *         """
 *         if self.header is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_length(reference)
 */
  }

  /* "pysam/libcalignmentfile.pyx":1919
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")
 *         return self.header.get_reference_length(reference)             # <<<<<<<<<<<<<<
 * 
 *     property nreferences:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_get_reference_length); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_reference};
    __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1919, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1913
 *         return self.header.get_reference_name(tid)
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.get_reference_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1924
 *         """int with the number of :term:`reference` sequences in the file.
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.nreferences
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1924, 0, __PYX_ERR(0, 1924, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1925
 *         This is a read-only attribute."""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.nreferences
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1925, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1926
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.nreferences             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1926, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1925
 *         This is a read-only attribute."""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.nreferences
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1928
 *                 return self.header.nreferences
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     property references:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1928, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1924
 *         """int with the number of :term:`reference` sequences in the file.
 *         This is a read-only attribute."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.nreferences
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.nreferences.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1933
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.references
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1933, 0, __PYX_ERR(0, 1933, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1934
 *         read-only attribute"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.references
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1934, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1935
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.references             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_references); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1935, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1934
 *         read-only attribute"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.references
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1937
 *                 return self.header.references
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     property lengths:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1937, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1937, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1933
 *         """tuple with the names of :term:`reference` sequences. This is a
 *         read-only attribute"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.references
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.references.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1945
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.lengths
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1945, 0, __PYX_ERR(0, 1945, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1946
 *         """
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.lengths
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1946, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1947
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.lengths             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_lengths); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1947, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1946
 *         """
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.lengths
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1949
 *                 return self.header.lengths
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     # Compatibility functions for pysam < 0.14
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1949, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1949, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1945
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.lengths
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.lengths.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1954
 *     property text:
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.__str__()
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1954, 0, __PYX_ERR(0, 1954, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1955
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.__str__()
 *             else:
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(((PyObject *)__pyx_v_self->header)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1955, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":1956
 *         def __get__(self):
 *             if self.header:
 *                 return self.header.__str__()             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError("header not available in closed files")
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->header), __pyx_n_s_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1956, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    __pyx_t_5 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_5 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1956, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":1955
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):
 *             if self.header:             # <<<<<<<<<<<<<<
 *                 return self.header.__str__()
 *             else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":1958
 *                 return self.header.__str__()
 *             else:
 *                 raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 * 
 *     # Compatibility functions for pysam < 0.8.3
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1958, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 1958, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":1954
 *     property text:
 *         """deprecated, use :attr:`references` and :attr:`lengths` instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.header:
 *                 return self.header.__str__()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.text.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1961
 * 
 *     # Compatibility functions for pysam < 0.8.3
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48gettid, "AlignmentFile.gettid(self, reference)\ndeprecated, use :meth:`get_tid` instead");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_49gettid = {"gettid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48gettid};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_reference = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gettid (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_reference)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1961, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "gettid") < 0)) __PYX_ERR(0, 1961, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_reference = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("gettid", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1961, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.gettid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_48gettid(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__79)
  __Pyx_RefNannySetupContext("gettid", 1);
  __Pyx_TraceCall("gettid", __pyx_f[0], 1961, 0, __PYX_ERR(0, 1961, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1963
 *     def gettid(self, reference):
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)             # <<<<<<<<<<<<<<
 * 
 *     def getrname(self, tid):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tid); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_reference};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1963, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1961
 * 
 *     # Compatibility functions for pysam < 0.8.3
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.gettid", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1965
 *         return self.get_tid(reference)
 * 
 *     def getrname(self, tid):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_50getrname, "AlignmentFile.getrname(self, tid)\ndeprecated, use :meth:`get_reference_name` instead");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_51getrname = {"getrname", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_50getrname};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_tid = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getrname (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tid,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1965, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "getrname") < 0)) __PYX_ERR(0, 1965, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_tid = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getrname", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1965, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.getrname", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_tid);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_50getrname(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__80)
  __Pyx_RefNannySetupContext("getrname", 1);
  __Pyx_TraceCall("getrname", __pyx_f[0], 1965, 0, __PYX_ERR(0, 1965, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1967
 *     def getrname(self, tid):
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_tid};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1967, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":1965
 *         return self.get_tid(reference)
 * 
 *     def getrname(self, tid):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.getrname", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pxd":46
 * 
 * cdef class AlignmentFile(HTSFile):
 *     cdef readonly object reference_filename             # <<<<<<<<<<<<<<
 *     cdef readonly AlignmentHeader header
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[4], 46, 0, __PYX_ERR(4, 46, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->reference_filename);
  __pyx_r = __pyx_v_self->reference_filename;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.reference_filename.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pxd":47
 * cdef class AlignmentFile(HTSFile):
 *     cdef readonly object reference_filename
 *     cdef readonly AlignmentHeader header             # <<<<<<<<<<<<<<
 * 
 *     # pointer to index
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[4], 47, 0, __PYX_ERR(4, 47, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self->header);
  __pyx_r = ((PyObject *)__pyx_v_self->header);
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__, "AlignmentFile.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__81)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__, "AlignmentFile.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__82)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.AlignmentFile.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":1995
 *     '''
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 *         cdef char *creference_filename
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_multiple_iterators;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[2] = {0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_multiple_iterators,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1995, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[1] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1995, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 1995, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1995, __pyx_L3_error)
    } else {
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 1995, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 1995, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  char *__pyx_v_cfilename;
  char *__pyx_v_creference_filename;
  char *__pyx_v_cindexname;
  CYTHON_UNUSED PyObject *__pyx_v_bindex_filename = NULL;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  char *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  unsigned int __pyx_t_7;
  htsFile *__pyx_t_8;
  hts_idx_t *__pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1995, 0, __PYX_ERR(0, 1995, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":1998
 *         cdef char *cfilename
 *         cdef char *creference_filename
 *         cdef char *cindexname = NULL             # <<<<<<<<<<<<<<
 * 
 *         if not samfile.is_open:
 */
  __pyx_v_cindexname = NULL;

  /* "pysam/libcalignmentfile.pyx":2000
 *         cdef char *cindexname = NULL
 * 
 *         if not samfile.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_open); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2000, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":2001
 * 
 *         if not samfile.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as the
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2001, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2001, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2000
 *         cdef char *cindexname = NULL
 * 
 *         if not samfile.is_open:             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2005
 *         # makes sure that samfile stays alive as long as the
 *         # iterator is alive
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 * 
 *         # reopen the file - note that this makes the iterator
 */
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->samfile);
  __Pyx_DECREF((PyObject *)__pyx_v_self->samfile);
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/libcalignmentfile.pyx":2009
 *         # reopen the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 * 
 *             cfilename = samfile.filename
 */
  __pyx_t_3 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":2011
 *         if multiple_iterators:
 * 
 *             cfilename = samfile.filename             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 */
    __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2011, __pyx_L1_error)
    __pyx_v_cfilename = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":2012
 * 
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             assert self.htsfile != NULL
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2013
 *             cfilename = samfile.filename
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')             # <<<<<<<<<<<<<<
 *             assert self.htsfile != NULL
 * 
 */
          __pyx_v_self->htsfile = hts_open(__pyx_v_cfilename, ((char const *)"r"));
        }

        /* "pysam/libcalignmentfile.pyx":2012
 * 
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             assert self.htsfile != NULL
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L7;
          }
          __pyx_L7:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2014
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             assert self.htsfile != NULL             # <<<<<<<<<<<<<<
 * 
 *             if samfile.has_index():
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(__pyx_assertions_enabled())) {
      __pyx_t_3 = (__pyx_v_self->htsfile != NULL);
      if (unlikely(!__pyx_t_3)) {
        __Pyx_Raise(__pyx_builtin_AssertionError, 0, 0, 0);
        __PYX_ERR(0, 2014, __pyx_L1_error)
      }
    }
    #else
    if ((1)); else __PYX_ERR(0, 2014, __pyx_L1_error)
    #endif

    /* "pysam/libcalignmentfile.pyx":2016
 *             assert self.htsfile != NULL
 * 
 *             if samfile.has_index():             # <<<<<<<<<<<<<<
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2016, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_7 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2016, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 2016, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":2017
 * 
 *             if samfile.has_index():
 *                 if samfile.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:
 */
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_samfile->__pyx_base.index_filename); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 2017, __pyx_L1_error)
      if (__pyx_t_3) {

        /* "pysam/libcalignmentfile.pyx":2018
 *             if samfile.has_index():
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)             # <<<<<<<<<<<<<<
 *                 with nogil:
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 */
        __pyx_t_1 = __pyx_v_samfile->__pyx_base.index_filename;
        __Pyx_INCREF(__pyx_t_1);
        __pyx_t_5 = __pyx_f_5pysam_9libcutils_encode_filename(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2018, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(__pyx_t_5 == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
          __PYX_ERR(0, 2018, __pyx_L1_error)
        }
        __pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_t_5); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2018, __pyx_L1_error)
        __pyx_v_cindexname = __pyx_t_4;
        __Pyx_INCREF(__pyx_t_5);
        __pyx_v_bindex_filename = ((PyObject*)__pyx_t_5);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "pysam/libcalignmentfile.pyx":2017
 * 
 *             if samfile.has_index():
 *                 if samfile.index_filename:             # <<<<<<<<<<<<<<
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:
 */
      }

      /* "pysam/libcalignmentfile.pyx":2019
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 *             else:
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          _save = NULL;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":2020
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)             # <<<<<<<<<<<<<<
 *             else:
 *                 self.index = NULL
 */
            __pyx_v_self->index = sam_index_load2(__pyx_v_self->htsfile, __pyx_v_cfilename, __pyx_v_cindexname);
          }

          /* "pysam/libcalignmentfile.pyx":2019
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 *                 with nogil:             # <<<<<<<<<<<<<<
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 *             else:
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L12;
            }
            __pyx_L12:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":2016
 *             assert self.htsfile != NULL
 * 
 *             if samfile.has_index():             # <<<<<<<<<<<<<<
 *                 if samfile.index_filename:
 *                     cindexname = bindex_filename = encode_filename(samfile.index_filename)
 */
      goto __pyx_L8;
    }

    /* "pysam/libcalignmentfile.pyx":2022
 *                     self.index = sam_index_load2(self.htsfile, cfilename, cindexname)
 *             else:
 *                 self.index = NULL             # <<<<<<<<<<<<<<
 * 
 *             # need to advance in newly opened file to position after header
 */
    /*else*/ {
      __pyx_v_self->index = NULL;
    }
    __pyx_L8:;

    /* "pysam/libcalignmentfile.pyx":2026
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2027
 *             # better: use seek/tell?
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")
 */
          __pyx_v_hdr = sam_hdr_read(__pyx_v_self->htsfile);
        }

        /* "pysam/libcalignmentfile.pyx":2026
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L15;
          }
          __pyx_L15:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2028
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:             # <<<<<<<<<<<<<<
 *                 raise IOError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    __pyx_t_3 = (__pyx_v_hdr == NULL);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":2029
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")             # <<<<<<<<<<<<<<
 *             self.header = makeAlignmentHeader(hdr)
 * 
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2029, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __PYX_ERR(0, 2029, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2028
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:             # <<<<<<<<<<<<<<
 *                 raise IOError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    }

    /* "pysam/libcalignmentfile.pyx":2030
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 * 
 *             self.owns_samfile = True
 */
    __pyx_t_5 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2030, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
    __Pyx_DECREF((PyObject *)__pyx_v_self->header);
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":2032
 *             self.header = makeAlignmentHeader(hdr)
 * 
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 * 
 *             # options specific to CRAM files
 */
    __pyx_v_self->owns_samfile = 1;

    /* "pysam/libcalignmentfile.pyx":2035
 * 
 *             # options specific to CRAM files
 *             if samfile.is_cram and samfile.reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = samfile.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2035, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2035, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_2) {
    } else {
      __pyx_t_3 = __pyx_t_2;
      goto __pyx_L18_bool_binop_done;
    }
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_samfile->reference_filename); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2035, __pyx_L1_error)
    __pyx_t_3 = __pyx_t_2;
    __pyx_L18_bool_binop_done:;
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":2036
 *             # options specific to CRAM files
 *             if samfile.is_cram and samfile.reference_filename:
 *                 creference_filename = samfile.reference_filename             # <<<<<<<<<<<<<<
 *                 hts_set_opt(self.htsfile,
 *                             CRAM_OPT_REFERENCE,
 */
      __pyx_t_4 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->reference_filename); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 2036, __pyx_L1_error)
      __pyx_v_creference_filename = __pyx_t_4;

      /* "pysam/libcalignmentfile.pyx":2037
 *             if samfile.is_cram and samfile.reference_filename:
 *                 creference_filename = samfile.reference_filename
 *                 hts_set_opt(self.htsfile,             # <<<<<<<<<<<<<<
 *                             CRAM_OPT_REFERENCE,
 *                             creference_filename)
 */
      (void)(hts_set_opt(__pyx_v_self->htsfile, CRAM_OPT_REFERENCE, __pyx_v_creference_filename));

      /* "pysam/libcalignmentfile.pyx":2035
 * 
 *             # options specific to CRAM files
 *             if samfile.is_cram and samfile.reference_filename:             # <<<<<<<<<<<<<<
 *                 creference_filename = samfile.reference_filename
 *                 hts_set_opt(self.htsfile,
 */
    }

    /* "pysam/libcalignmentfile.pyx":2009
 *         # reopen the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 * 
 *             cfilename = samfile.filename
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2042
 * 
 *         else:
 *             self.htsfile = samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.index = samfile.index
 *             self.owns_samfile = False
 */
  /*else*/ {
    __pyx_t_8 = __pyx_v_samfile->__pyx_base.htsfile;
    __pyx_v_self->htsfile = __pyx_t_8;

    /* "pysam/libcalignmentfile.pyx":2043
 *         else:
 *             self.htsfile = samfile.htsfile
 *             self.index = samfile.index             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 *             self.header = samfile.header
 */
    __pyx_t_9 = __pyx_v_samfile->index;
    __pyx_v_self->index = __pyx_t_9;

    /* "pysam/libcalignmentfile.pyx":2044
 *             self.htsfile = samfile.htsfile
 *             self.index = samfile.index
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 *             self.header = samfile.header
 * 
 */
    __pyx_v_self->owns_samfile = 0;

    /* "pysam/libcalignmentfile.pyx":2045
 *             self.index = samfile.index
 *             self.owns_samfile = False
 *             self.header = samfile.header             # <<<<<<<<<<<<<<
 * 
 *         self.retval = 0
 */
    __pyx_t_5 = ((PyObject *)__pyx_v_samfile->header);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
    __Pyx_DECREF((PyObject *)__pyx_v_self->header);
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5);
    __pyx_t_5 = 0;
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":2047
 *             self.header = samfile.header
 * 
 *         self.retval = 0             # <<<<<<<<<<<<<<
 * 
 *         self.b = bam_init1()
 */
  __pyx_v_self->retval = 0;

  /* "pysam/libcalignmentfile.pyx":2049
 *         self.retval = 0
 * 
 *         self.b = bam_init1()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->b = bam_init1();

  /* "pysam/libcalignmentfile.pyx":1995
 *     '''
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 *         cdef char *creference_filename
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_bindex_filename);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2051
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self) {
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2051, 0, __PYX_ERR(0, 2051, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2052
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_idx_destroy(self.index)
 */
  bam_destroy1(__pyx_v_self->b);

  /* "pysam/libcalignmentfile.pyx":2053
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             hts_close(self.htsfile)
 */
  __pyx_t_1 = (__pyx_v_self->owns_samfile != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2054
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 *             hts_idx_destroy(self.index)             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 * 
 */
    hts_idx_destroy(__pyx_v_self->index);

    /* "pysam/libcalignmentfile.pyx":2055
 *         if self.owns_samfile:
 *             hts_idx_destroy(self.index)
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    (void)(hts_close(__pyx_v_self->htsfile));

    /* "pysam/libcalignmentfile.pyx":2053
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_idx_destroy(self.index)
 *             hts_close(self.htsfile)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2051
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRow.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__, "IteratorRow.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__84)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__, "IteratorRow.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__85)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRow.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2072
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_beg;
  int __pyx_v_stop;
  int __pyx_v_multiple_iterators;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[5] = {0,0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_beg,&__pyx_n_s_stop,&__pyx_n_s_multiple_iterators,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  5: values[4] = __Pyx_Arg_VARARGS(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2072, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2072, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); __PYX_ERR(0, 2072, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_beg)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[2]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2072, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); __PYX_ERR(0, 2072, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_stop)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[3]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2072, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); __PYX_ERR(0, 2072, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[4] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2072, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 2072, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  5: values[4] = __Pyx_Arg_VARARGS(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3);
        values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2073, __pyx_L3_error)
    __pyx_v_beg = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2073, __pyx_L3_error)
    __pyx_v_stop = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_stop == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2073, __pyx_L3_error)
    if (values[4]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2074, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2074
 *     def __init__(self, AlignmentFile samfile,
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile.has_index():
 */
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, __pyx_nargs); __PYX_ERR(0, 2072, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2072, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_stop, __pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":2072
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_stop, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2072, 0, __PYX_ERR(0, 2072, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2076
 *                  int multiple_iterators=False):
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for iteration")
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2076, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2076, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 2076, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = (!__pyx_t_5);
  if (unlikely(__pyx_t_6)) {

    /* "pysam/libcalignmentfile.pyx":2077
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for iteration")             # <<<<<<<<<<<<<<
 * 
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__86, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2077, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 2077, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2076
 *                  int multiple_iterators=False):
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for iteration")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2079
 *             raise ValueError("no index available for iteration")
 * 
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *         with nogil:
 *             self.iter = sam_itr_queryi(
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion);
  __Pyx_GIVEREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion))) __PYX_ERR(0, 2079, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 2079, __pyx_L1_error);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_samfile))) __PYX_ERR(0, 2079, __pyx_L1_error);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_7) < 0) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":2080
 * 
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.iter = sam_itr_queryi(
 *                 self.index,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2081
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 *         with nogil:
 *             self.iter = sam_itr_queryi(             # <<<<<<<<<<<<<<
 *                 self.index,
 *                 tid,
 */
        __pyx_v_self->iter = sam_itr_queryi(__pyx_v_self->__pyx_base.index, __pyx_v_tid, __pyx_v_beg, __pyx_v_stop);
      }

      /* "pysam/libcalignmentfile.pyx":2080
 * 
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.iter = sam_itr_queryi(
 *                 self.index,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L6:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2072
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int stop,
 *                  int multiple_iterators=False):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2087
 *                 stop)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 1);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2087, 0, __PYX_ERR(0, 2087, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2088
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2087
 *                 stop)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2090
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2090, 0, __PYX_ERR(0, 2090, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2091
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2090
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2093
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:
 */

static int __pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("cnext", __pyx_f[0], 2093, 0, __PYX_ERR(0, 2093, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2095
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),
 *                                        self.iter,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2096
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:
 *             self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),             # <<<<<<<<<<<<<<
 *                                        self.iter,
 *                                        self.b,
 */
        __pyx_v_self->__pyx_base.retval = hts_itr_next(hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile), __pyx_v_self->iter, __pyx_v_self->__pyx_base.b, __pyx_v_self->__pyx_base.htsfile);
      }

      /* "pysam/libcalignmentfile.pyx":2095
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:             # <<<<<<<<<<<<<<
 *             self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),
 *                                        self.iter,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2093
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         with nogil:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2101
 *                                        self.htsfile)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         self.cnext()
 *         if self.retval >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  unsigned int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2101, 0, __PYX_ERR(0, 2101, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2102
 * 
 *     def __next__(self):
 *         self.cnext()             # <<<<<<<<<<<<<<
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2102, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2103
 *     def __next__(self):
 *         self.cnext()
 *         if self.retval >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:
 */
  __pyx_t_1 = (__pyx_v_self->__pyx_base.retval >= 0);
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2104
 *         self.cnext()
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif self.retval == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_3 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2104, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2103
 *     def __next__(self):
 *         self.cnext()
 *         if self.retval >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2105
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         elif self.retval == -2:
 */
  __pyx_t_1 = (__pyx_v_self->__pyx_base.retval == -1L);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2106
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         elif self.retval == -2:
 *             # Note: it is currently not the case that hts_iter_next
 */
    __pyx_error_without_exception = 1;
    goto __pyx_L1_error;;

    /* "pysam/libcalignmentfile.pyx":2105
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif self.retval == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         elif self.retval == -2:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2107
 *         elif self.retval == -1:
 *             raise StopIteration
 *         elif self.retval == -2:             # <<<<<<<<<<<<<<
 *             # Note: it is currently not the case that hts_iter_next
 *             # returns -2 for a truncated file.
 */
  __pyx_t_1 = (__pyx_v_self->__pyx_base.retval == -2L);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2111
 *             # returns -2 for a truncated file.
 *             # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__87, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2111, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2111, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2107
 *         elif self.retval == -1:
 *             raise StopIteration
 *         elif self.retval == -2:             # <<<<<<<<<<<<<<
 *             # Note: it is currently not the case that hts_iter_next
 *             # returns -2 for a truncated file.
 */
  }

  /* "pysam/libcalignmentfile.pyx":2113
 *             raise IOError('truncated file')
 *         else:
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_error_while_reading_file_2, __pyx_n_s_format); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2113, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.retval); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2113, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    __pyx_t_6 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_6 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_v_self->__pyx_base.samfile->__pyx_base.filename, __pyx_t_4};
      __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 2+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2113, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2113, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2113, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2101
 *                                        self.htsfile)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         self.cnext()
 *         if self.retval >= 0:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2115
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2115, 0, __PYX_ERR(0, 2115, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2116
 * 
 *     def __dealloc__(self):
 *         hts_itr_destroy(self.iter)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  hts_itr_destroy(__pyx_v_self->iter);

  /* "pysam/libcalignmentfile.pyx":2115
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorRowRegion.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__, "IteratorRowRegion.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__88)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_s, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__, "IteratorRowRegion.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__89)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_s, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowRegion.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2131
 *     """
 * 
 *     def __init__(self,             # <<<<<<<<<<<<<<
 *                  AlignmentFile samfile,
 *                  int n,
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_n;
  int __pyx_v_multiple_iterators;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[3] = {0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_n,&__pyx_n_s_multiple_iterators,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2131, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_n)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2131, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 2131, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[2] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2131, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 2131, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_n = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2133, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2134, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2134
 *                  AlignmentFile samfile,
 *                  int n,
 *                  int multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 */
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, __pyx_nargs); __PYX_ERR(0, 2131, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2132, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self), __pyx_v_samfile, __pyx_v_n, __pyx_v_multiple_iterators);

  /* "pysam/libcalignmentfile.pyx":2131
 *     """
 * 
 *     def __init__(self,             # <<<<<<<<<<<<<<
 *                  AlignmentFile samfile,
 *                  int n,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2131, 0, __PYX_ERR(0, 2131, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2135
 *                  int n,
 *                  int multiple_iterators=False):
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         self.max_rows = n
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead);
  __Pyx_GIVEREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead))) __PYX_ERR(0, 2135, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 2135, __pyx_L1_error);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_samfile))) __PYX_ERR(0, 2135, __pyx_L1_error);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2137
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 *         self.max_rows = n             # <<<<<<<<<<<<<<
 *         self.current_row = 0
 * 
 */
  __pyx_v_self->max_rows = __pyx_v_n;

  /* "pysam/libcalignmentfile.pyx":2138
 * 
 *         self.max_rows = n
 *         self.current_row = 0             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->current_row = 0;

  /* "pysam/libcalignmentfile.pyx":2131
 *     """
 * 
 *     def __init__(self,             # <<<<<<<<<<<<<<
 *                  AlignmentFile samfile,
 *                  int n,
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2140
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 1);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2140, 0, __PYX_ERR(0, 2140, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2141
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2140
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2143
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2143, 0, __PYX_ERR(0, 2143, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2144
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2143
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2146
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

static int __pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  bam_hdr_t *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("cnext", __pyx_f[0], 2146, 0, __PYX_ERR(0, 2146, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2149
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_1 = __pyx_v_self->__pyx_base.header->ptr;
  __pyx_v_hdr = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2150
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2151
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b);
      }

      /* "pysam/libcalignmentfile.pyx":2150
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2154
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2146
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2156
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  unsigned int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2156, 0, __PYX_ERR(0, 2156, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2157
 * 
 *     def __next__(self):
 *         if self.current_row >= self.max_rows:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = (__pyx_v_self->current_row >= __pyx_v_self->max_rows);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2158
 *     def __next__(self):
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret = self.cnext()
 */
    __pyx_error_without_exception = 1;
    goto __pyx_L1_error;;

    /* "pysam/libcalignmentfile.pyx":2157
 * 
 *     def __next__(self):
 *         if self.current_row >= self.max_rows:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2160
 *             raise StopIteration
 * 
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             self.current_row += 1
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2160, __pyx_L1_error)
  __pyx_v_ret = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2161
 * 
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_t_1 = (__pyx_v_ret >= 0);
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2162
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             self.current_row += 1             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
    __pyx_v_self->current_row = (__pyx_v_self->current_row + 1);

    /* "pysam/libcalignmentfile.pyx":2163
 *         if ret >= 0:
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_3))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2163, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2161
 * 
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2164
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_1 = (__pyx_v_ret == -1L);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2165
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __pyx_error_without_exception = 1;
    goto __pyx_L1_error;;

    /* "pysam/libcalignmentfile.pyx":2164
 *             self.current_row += 1
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2167
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2167, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2167, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_7 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_5};
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2167, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2167, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2167, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2156
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__, "IteratorRowHead.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__90)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__, "IteratorRowHead.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__91)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowHead.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2183
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_multiple_iterators;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[2] = {0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_multiple_iterators,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2183, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[1] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2183, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 2183, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2183, __pyx_L3_error)
    } else {
      __pyx_v_multiple_iterators = ((int)0);
    }
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 2183, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2183, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2183, 0, __PYX_ERR(0, 2183, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2184
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll);
  __Pyx_GIVEREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll))) __PYX_ERR(0, 2184, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 2184, __pyx_L1_error);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_samfile))) __PYX_ERR(0, 2184, __pyx_L1_error);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2184, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2183
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2186
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 1);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2186, 0, __PYX_ERR(0, 2186, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2187
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2186
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2189
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2189, 0, __PYX_ERR(0, 2189, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2190
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2189
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2192
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

static int __pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  bam_hdr_t *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("cnext", __pyx_f[0], 2192, 0, __PYX_ERR(0, 2192, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2195
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_1 = __pyx_v_self->__pyx_base.header->ptr;
  __pyx_v_hdr = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2196
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2197
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b);
      }

      /* "pysam/libcalignmentfile.pyx":2196
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2200
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2192
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         cdef int ret
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2202
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  unsigned int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2202, 0, __PYX_ERR(0, 2202, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2203
 * 
 *     def __next__(self):
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2203, __pyx_L1_error)
  __pyx_v_ret = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2204
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  __pyx_t_2 = (__pyx_v_ret >= 0);
  if (likely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2205
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_3))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2204
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2206
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_2 = (__pyx_v_ret == -1L);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2207
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __pyx_error_without_exception = 1;
    goto __pyx_L1_error;;

    /* "pysam/libcalignmentfile.pyx":2206
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2209
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2209, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2209, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_7 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_5};
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2209, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2209, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2209, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2202
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__, "IteratorRowAll.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__92)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__, "IteratorRowAll.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__93)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAll.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2223
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_multiple_iterators = 0;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[2] = {0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_multiple_iterators,0};
    values[1] = __Pyx_Arg_NewRef_VARARGS(((PyObject *)Py_False));
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2223, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[1] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2223, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 2223, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_multiple_iterators = values[1];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 2223, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2223, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2223, 0, __PYX_ERR(0, 2223, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2224
 * 
 *     def __init__(self, AlignmentFile samfile, multiple_iterators=False):
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         if not samfile.has_index():
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs);
  __Pyx_GIVEREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs))) __PYX_ERR(0, 2224, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 2224, __pyx_L1_error);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_samfile))) __PYX_ERR(0, 2224, __pyx_L1_error);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) __PYX_ERR(0, 2224, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2224, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2226
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for fetch")
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_has_index); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2226, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL};
    __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 2226, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_7 = (!__pyx_t_6);
  if (unlikely(__pyx_t_7)) {

    /* "pysam/libcalignmentfile.pyx":2227
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__94, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __PYX_ERR(0, 2227, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2226
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 *         if not samfile.has_index():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for fetch")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2229
 *             raise ValueError("no index available for fetch")
 * 
 *         self.tid = -1             # <<<<<<<<<<<<<<
 * 
 *     def nextiter(self):
 */
  __pyx_v_self->tid = -1;

  /* "pysam/libcalignmentfile.pyx":2223
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2231
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter, "IteratorRowAllRefs.nextiter(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter = {"nextiter", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("nextiter (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("nextiter", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "nextiter", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  htsFile *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__95)
  __Pyx_RefNannySetupContext("nextiter", 1);
  __Pyx_TraceCall("nextiter", __pyx_f[0], 2231, 0, __PYX_ERR(0, 2231, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2235
 *         # will not be re-opened.
 *         self.rowiter = IteratorRowRegion(self.samfile,
 *                                          self.tid,             # <<<<<<<<<<<<<<
 *                                          0,
 *                                          MAX_POS)
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":2237
 *                                          self.tid,
 *                                          0,
 *                                          MAX_POS)             # <<<<<<<<<<<<<<
 *         # set htsfile and header of the rowiter
 *         # to the values in this iterator to reflect multiple_iterators
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_5pysam_17libcalignmentfile_MAX_POS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/libcalignmentfile.pyx":2234
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 *         self.rowiter = IteratorRowRegion(self.samfile,             # <<<<<<<<<<<<<<
 *                                          self.tid,
 *                                          0,
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF((PyObject *)__pyx_v_self->__pyx_base.samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self->__pyx_base.samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->__pyx_base.samfile))) __PYX_ERR(0, 2234, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1)) __PYX_ERR(0, 2234, __pyx_L1_error);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_int_0)) __PYX_ERR(0, 2234, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2)) __PYX_ERR(0, 2234, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2234, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->rowiter);
  __Pyx_DECREF((PyObject *)__pyx_v_self->rowiter);
  __pyx_v_self->rowiter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":2240
 *         # set htsfile and header of the rowiter
 *         # to the values in this iterator to reflect multiple_iterators
 *         self.rowiter.htsfile = self.htsfile             # <<<<<<<<<<<<<<
 *         self.rowiter.header = self.header
 * 
 */
  __pyx_t_4 = __pyx_v_self->__pyx_base.htsfile;
  __pyx_v_self->rowiter->__pyx_base.htsfile = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":2241
 *         # to the values in this iterator to reflect multiple_iterators
 *         self.rowiter.htsfile = self.htsfile
 *         self.rowiter.header = self.header             # <<<<<<<<<<<<<<
 * 
 *         # make sure the iterator understand that IteratorRowAllRefs
 */
  __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->rowiter->__pyx_base.header);
  __Pyx_DECREF((PyObject *)__pyx_v_self->rowiter->__pyx_base.header);
  __pyx_v_self->rowiter->__pyx_base.header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":2245
 *         # make sure the iterator understand that IteratorRowAllRefs
 *         # has ownership
 *         self.rowiter.owns_samfile = False             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->rowiter->__pyx_base.owns_samfile = 0;

  /* "pysam/libcalignmentfile.pyx":2231
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.nextiter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2247
 *         self.rowiter.owns_samfile = False
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 1);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2247, 0, __PYX_ERR(0, 2247, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2248
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2247
 *         self.rowiter.owns_samfile = False
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2250
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         # Create an initial iterator
 *         if self.tid == -1:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  unsigned int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2250, 0, __PYX_ERR(0, 2250, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2252
 *     def __next__(self):
 *         # Create an initial iterator
 *         if self.tid == -1:             # <<<<<<<<<<<<<<
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 */
  __pyx_t_1 = (__pyx_v_self->tid == -1L);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2253
 *         # Create an initial iterator
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 *             self.tid = 0
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2253, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 2253, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = (!__pyx_t_1);
    if (unlikely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":2254
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 *             self.tid = 0
 *             self.nextiter()
 */
      __pyx_error_without_exception = 1;
      goto __pyx_L1_error;;

      /* "pysam/libcalignmentfile.pyx":2253
 *         # Create an initial iterator
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 *             self.tid = 0
 */
    }

    /* "pysam/libcalignmentfile.pyx":2255
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 *             self.tid = 0             # <<<<<<<<<<<<<<
 *             self.nextiter()
 * 
 */
    __pyx_v_self->tid = 0;

    /* "pysam/libcalignmentfile.pyx":2256
 *                 raise StopIteration
 *             self.tid = 0
 *             self.nextiter()             # <<<<<<<<<<<<<<
 * 
 *         while 1:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2256, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    __pyx_t_6 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_6 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL};
      __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2256, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":2252
 *     def __next__(self):
 *         # Create an initial iterator
 *         if self.tid == -1:             # <<<<<<<<<<<<<<
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 */
  }

  /* "pysam/libcalignmentfile.pyx":2258
 *             self.nextiter()
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.rowiter.cnext()
 * 
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2259
 * 
 *         while 1:
 *             self.rowiter.cnext()             # <<<<<<<<<<<<<<
 * 
 *             # If current iterator is not exhausted, return aligned read
 */
    ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_v_self->rowiter->__pyx_vtab)->cnext(__pyx_v_self->rowiter); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2259, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2262
 * 
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:             # <<<<<<<<<<<<<<
 *                 return makeAlignedSegment(self.rowiter.b, self.header)
 * 
 */
    __pyx_t_3 = (__pyx_v_self->rowiter->__pyx_base.retval > 0);
    if (__pyx_t_3) {

      /* "pysam/libcalignmentfile.pyx":2263
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:
 *                 return makeAlignedSegment(self.rowiter.b, self.header)             # <<<<<<<<<<<<<<
 * 
 *             self.tid += 1
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = ((PyObject *)__pyx_v_self->__pyx_base.header);
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->rowiter->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_2))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2263, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;

      /* "pysam/libcalignmentfile.pyx":2262
 * 
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:             # <<<<<<<<<<<<<<
 *                 return makeAlignedSegment(self.rowiter.b, self.header)
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2265
 *                 return makeAlignedSegment(self.rowiter.b, self.header)
 * 
 *             self.tid += 1             # <<<<<<<<<<<<<<
 * 
 *             # Otherwise, proceed to next reference or stop
 */
    __pyx_v_self->tid = (__pyx_v_self->tid + 1);

    /* "pysam/libcalignmentfile.pyx":2268
 * 
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 self.nextiter()
 *             else:
 */
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2268, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 2268, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (likely(__pyx_t_3)) {

      /* "pysam/libcalignmentfile.pyx":2269
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:
 *                 self.nextiter()             # <<<<<<<<<<<<<<
 *             else:
 *                 raise StopIteration
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2269, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = NULL;
      __pyx_t_6 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_6 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2269, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":2268
 * 
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 self.nextiter()
 *             else:
 */
      goto __pyx_L8;
    }

    /* "pysam/libcalignmentfile.pyx":2271
 *                 self.nextiter()
 *             else:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    /*else*/ {
      __pyx_error_without_exception = 1;
      goto __pyx_L1_error;;
    }
    __pyx_L8:;
  }

  /* "pysam/libcalignmentfile.pyx":2250
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         # Create an initial iterator
 *         if self.tid == -1:
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__, "IteratorRowAllRefs.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__96)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__, "IteratorRowAllRefs.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__97)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowAllRefs.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2284
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_positions = 0;
  int __pyx_v_multiple_iterators;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[3] = {0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_positions,&__pyx_n_s_multiple_iterators,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2284, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_positions)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2284, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); __PYX_ERR(0, 2284, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[2] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2284, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 2284, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    __pyx_v_positions = values[1];
    if (values[2]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2284, __pyx_L3_error)
    } else {
      __pyx_v_multiple_iterators = ((int)1);
    }
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, __pyx_nargs); __PYX_ERR(0, 2284, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2284, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self), __pyx_v_samfile, __pyx_v_positions, __pyx_v_multiple_iterators);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2284, 0, __PYX_ERR(0, 2284, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2285
 * 
 *     def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True):
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         self.positions = positions
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection);
  __Pyx_GIVEREF((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection))) __PYX_ERR(0, 2285, __pyx_L1_error);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_self))) __PYX_ERR(0, 2285, __pyx_L1_error);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_samfile))) __PYX_ERR(0, 2285, __pyx_L1_error);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2285, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2287
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 *         self.positions = positions             # <<<<<<<<<<<<<<
 *         self.current_pos = 0
 * 
 */
  __Pyx_INCREF(__pyx_v_positions);
  __Pyx_GIVEREF(__pyx_v_positions);
  __Pyx_GOTREF(__pyx_v_self->positions);
  __Pyx_DECREF(__pyx_v_self->positions);
  __pyx_v_self->positions = __pyx_v_positions;

  /* "pysam/libcalignmentfile.pyx":2288
 * 
 *         self.positions = positions
 *         self.current_pos = 0             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->current_pos = 0;

  /* "pysam/libcalignmentfile.pyx":2284
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, positions, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2290
 *         self.current_pos = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 1);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2290, 0, __PYX_ERR(0, 2290, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2291
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef bam1_t * getCurrent(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2290
 *         self.current_pos = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2293
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 2293, 0, __PYX_ERR(0, 2293, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2294
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2293
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.getCurrent", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2296
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 *         # end iteration if out of positions
 */

static int __pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  uint64_t __pyx_v_pos;
  int __pyx_v_ret;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  uint64_t __pyx_t_4;
  bam_hdr_t *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnext", 1);
  __Pyx_TraceCall("cnext", __pyx_f[0], 2296, 0, __PYX_ERR(0, 2296, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2299
 *         '''cversion of iterator'''
 *         # end iteration if out of positions
 *         if self.current_pos >= len(self.positions): return -1             # <<<<<<<<<<<<<<
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]
 */
  __pyx_t_1 = __pyx_v_self->positions;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 2299, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_v_self->current_pos >= __pyx_t_2);
  if (__pyx_t_3) {
    __pyx_r = -1;
    goto __pyx_L0;
  }

  /* "pysam/libcalignmentfile.pyx":2301
 *         if self.current_pos >= len(self.positions): return -1
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]             # <<<<<<<<<<<<<<
 *         with nogil:
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->positions, __pyx_v_self->current_pos, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2301, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_uint64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2301, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":2302
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),
 *                       pos,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2303
 *         cdef uint64_t pos = self.positions[self.current_pos]
 *         with nogil:
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),             # <<<<<<<<<<<<<<
 *                       pos,
 *                       0)
 */
        (void)(bgzf_seek(hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile), __pyx_v_pos, 0));
      }

      /* "pysam/libcalignmentfile.pyx":2302
 * 
 *         cdef uint64_t pos = self.positions[self.current_pos]
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bgzf_seek(hts_get_bgzfp(self.htsfile),
 *                       pos,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L6;
        }
        __pyx_L6:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2306
 *                       pos,
 *                       0)
 *         self.current_pos += 1             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret
 */
  __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1);

  /* "pysam/libcalignmentfile.pyx":2309
 * 
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(self.htsfile,
 */
  __pyx_t_5 = __pyx_v_self->__pyx_base.header->ptr;
  __pyx_v_hdr = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":2310
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2311
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             hdr,
 *                             self.b)
 */
        __pyx_v_ret = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_hdr, __pyx_v_self->__pyx_base.b);
      }

      /* "pysam/libcalignmentfile.pyx":2310
 *         cdef int ret
 *         cdef bam_hdr_t * hdr = self.header.ptr
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             hdr,
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L9;
        }
        __pyx_L9:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2314
 *                             hdr,
 *                             self.b)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2296
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 *         # end iteration if out of positions
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2316
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  unsigned int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2316, 0, __PYX_ERR(0, 2316, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2317
 * 
 *     def __next__(self):
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2317, __pyx_L1_error)
  __pyx_v_ret = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2318
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  __pyx_t_2 = (__pyx_v_ret >= 0);
  if (likely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2319
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)             # <<<<<<<<<<<<<<
 *         elif ret == -1:
 *             raise StopIteration
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = ((PyObject *)__pyx_v_self->__pyx_base.header);
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment(__pyx_v_self->__pyx_base.b, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_3))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2319, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2318
 *     def __next__(self):
 *         cdef int ret = self.cnext()
 *         if ret >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2320
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  __pyx_t_2 = (__pyx_v_ret == -1L);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2321
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError(read_failure_reason(ret))
 */
    __pyx_error_without_exception = 1;
    goto __pyx_L1_error;;

    /* "pysam/libcalignmentfile.pyx":2320
 *         if ret >= 0:
 *             return makeAlignedSegment(self.b, self.header)
 *         elif ret == -1:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 *         else:
 */
  }

  /* "pysam/libcalignmentfile.pyx":2323
 *             raise StopIteration
 *         else:
 *             raise IOError(read_failure_reason(ret))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_read_failure_reason); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2323, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_ret); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2323, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    __pyx_t_7 = 0;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_7 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_5};
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2323, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2323, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2323, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2316
 *         return ret
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         cdef int ret = self.cnext()
 *         if ret >= 0:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__, "IteratorRowSelection.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__98)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__, "IteratorRowSelection.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__99)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_b_self_htsfile_self_index_c, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorRowSelection.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2326
 * 
 * 
 * cdef int __advance_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_nofilter(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__advance_nofilter", __pyx_f[0], 2326, 0, __PYX_ERR(0, 2326, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2329
 *     '''advance without any read filtering.
 *     '''
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     with nogil:
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2331
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 *     return ret
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2332
 *     cdef int ret
 *     with nogil:
 *         ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
        __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
      }

      /* "pysam/libcalignmentfile.pyx":2331
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 *     return ret
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2333
 *     with nogil:
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2326
 * 
 * 
 * cdef int __advance_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.__advance_nofilter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2336
 * 
 * 
 * cdef int __advance_raw_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance (without iterator) without any read filtering.
 *     '''
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_nofilter(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__advance_raw_nofilter", __pyx_f[0], 2336, 0, __PYX_ERR(0, 2336, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2339
 *     '''advance (without iterator) without any read filtering.
 *     '''
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     with nogil:
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2341
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_read1(d.htsfile, d.header, b)
 *     return ret
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2342
 *     cdef int ret
 *     with nogil:
 *         ret = sam_read1(d.htsfile, d.header, b)             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
        __pyx_v_ret = sam_read1(__pyx_v_d->htsfile, __pyx_v_d->header, __pyx_v_b);
      }

      /* "pysam/libcalignmentfile.pyx":2341
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     with nogil:             # <<<<<<<<<<<<<<
 *         ret = sam_read1(d.htsfile, d.header, b)
 *     return ret
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2343
 *     with nogil:
 *         ret = sam_read1(d.htsfile, d.header, b)
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2336
 * 
 * 
 * cdef int __advance_raw_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance (without iterator) without any read filtering.
 *     '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.__advance_raw_nofilter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2346
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  CYTHON_UNUSED PyObject *__pyx_v_mask = 0;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__advance_all", 1);
  __Pyx_TraceCall("__advance_all", __pyx_f[0], 2346, 0, __PYX_ERR(0, 2346, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2352
 *     '''
 * 
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP
 *     cdef int ret
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2353
 * 
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     while 1:
 */
  __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2353, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_mask = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2355
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP
 *     cdef int ret
 *     while 1:             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2356
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2357
 *     while 1:
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 *         if ret < 0:
 *             break
 */
          __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
        }

        /* "pysam/libcalignmentfile.pyx":2356
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2358
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    __pyx_t_2 = (__pyx_v_ret < 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2359
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:
 *             break             # <<<<<<<<<<<<<<
 *         if b.core.flag & d.flag_filter:
 *             continue
 */
      goto __pyx_L4_break;

      /* "pysam/libcalignmentfile.pyx":2358
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2360
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    __pyx_t_2 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2361
 *             break
 *         if b.core.flag & d.flag_filter:
 *             continue             # <<<<<<<<<<<<<<
 *         break
 *     return ret
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2360
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    }

    /* "pysam/libcalignmentfile.pyx":2362
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         break             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
    goto __pyx_L4_break;
    __pyx_L3_continue:;
  }
  __pyx_L4_break:;

  /* "pysam/libcalignmentfile.pyx":2363
 *             continue
 *         break
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2346
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.__advance_all", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mask);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2366
 * 
 * 
 * cdef int __advance_raw_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_raw_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__advance_raw_all", __pyx_f[0], 2366, 0, __PYX_ERR(0, 2366, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2372
 *     '''
 * 
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     while 1:
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2374
 *     cdef __iterdata * d = <__iterdata*>data
 *     cdef int ret
 *     while 1:             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2375
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2376
 *     while 1:
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)             # <<<<<<<<<<<<<<
 *         if ret < 0:
 *             break
 */
          __pyx_v_ret = sam_read1(__pyx_v_d->htsfile, __pyx_v_d->header, __pyx_v_b);
        }

        /* "pysam/libcalignmentfile.pyx":2375
 *     cdef int ret
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2377
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    __pyx_t_1 = (__pyx_v_ret < 0);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":2378
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 *             break             # <<<<<<<<<<<<<<
 *         if b.core.flag & d.flag_filter:
 *             continue
 */
      goto __pyx_L4_break;

      /* "pysam/libcalignmentfile.pyx":2377
 *         with nogil:
 *             ret = sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2379
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    __pyx_t_1 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":2380
 *             break
 *         if b.core.flag & d.flag_filter:
 *             continue             # <<<<<<<<<<<<<<
 *         break
 *     return ret
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2379
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         break
 */
    }

    /* "pysam/libcalignmentfile.pyx":2381
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         break             # <<<<<<<<<<<<<<
 *     return ret
 * 
 */
    goto __pyx_L4_break;
    __pyx_L3_continue:;
  }
  __pyx_L4_break:;

  /* "pysam/libcalignmentfile.pyx":2382
 *             continue
 *         break
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2366
 * 
 * 
 * cdef int __advance_raw_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic filters such as
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.__advance_raw_all", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2385
 * 
 * 
 * cdef int __advance_samtools(void * data, bam1_t * b):             # <<<<<<<<<<<<<<
 *     '''advance using same filter and read processing as in
 *     the samtools pileup.
 */

static int __pyx_f_5pysam_17libcalignmentfile___advance_samtools(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_17libcalignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_v_q;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int32_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  unsigned int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__advance_samtools", 1);
  __Pyx_TraceCall("__advance_samtools", __pyx_f[0], 2385, 0, __PYX_ERR(0, 2385, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2389
 *     the samtools pileup.
 *     '''
 *     cdef __iterdata * d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret
 *     cdef int q
 */
  __pyx_v_d = ((__pyx_t_5pysam_17libcalignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/libcalignmentfile.pyx":2393
 *     cdef int q
 * 
 *     while 1:             # <<<<<<<<<<<<<<
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2394
 * 
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2395
 *     while 1:
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)             # <<<<<<<<<<<<<<
 *         if ret < 0:
 *             break
 */
          __pyx_t_2 = (__pyx_v_d->iter != 0);
          if (__pyx_t_2) {
            __pyx_t_1 = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
          } else {
            __pyx_t_1 = sam_read1(__pyx_v_d->htsfile, __pyx_v_d->header, __pyx_v_b);
          }
          __pyx_v_ret = __pyx_t_1;
        }

        /* "pysam/libcalignmentfile.pyx":2394
 * 
 *     while 1:
 *         with nogil:             # <<<<<<<<<<<<<<
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2396
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    __pyx_t_2 = (__pyx_v_ret < 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2397
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:
 *             break             # <<<<<<<<<<<<<<
 *         if b.core.flag & d.flag_filter:
 *             continue
 */
      goto __pyx_L4_break;

      /* "pysam/libcalignmentfile.pyx":2396
 *         with nogil:
 *             ret = sam_itr_next(d.htsfile, d.iter, b) if d.iter else sam_read1(d.htsfile, d.header, b)
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             break
 *         if b.core.flag & d.flag_filter:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2398
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 */
    __pyx_t_2 = ((__pyx_v_b->core.flag & __pyx_v_d->flag_filter) != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2399
 *             break
 *         if b.core.flag & d.flag_filter:
 *             continue             # <<<<<<<<<<<<<<
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 *             continue
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2398
 *         if ret < 0:
 *             break
 *         if b.core.flag & d.flag_filter:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 */
    }

    /* "pysam/libcalignmentfile.pyx":2400
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    __pyx_t_3 = (__pyx_v_d->flag_require != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L13_bool_binop_done;
    }
    __pyx_t_3 = (!((__pyx_v_b->core.flag & __pyx_v_d->flag_require) != 0));
    __pyx_t_2 = __pyx_t_3;
    __pyx_L13_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2401
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):
 *             continue             # <<<<<<<<<<<<<<
 * 
 *         # reload sequence
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2400
 *         if b.core.flag & d.flag_filter:
 *             continue
 *         if d.flag_require and not (b.core.flag & d.flag_require):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2404
 * 
 *         # reload sequence
 *         if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
 *             if d.seq != NULL:
 *                 free(d.seq)
 */
    __pyx_t_3 = (__pyx_v_d->fastafile != NULL);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_3 = (__pyx_v_b->core.tid != __pyx_v_d->tid);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L16_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2405
 *         # reload sequence
 *         if d.fastafile != NULL and b.core.tid != d.tid:
 *             if d.seq != NULL:             # <<<<<<<<<<<<<<
 *                 free(d.seq)
 *             d.tid = b.core.tid
 */
      __pyx_t_2 = (__pyx_v_d->seq != NULL);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2406
 *         if d.fastafile != NULL and b.core.tid != d.tid:
 *             if d.seq != NULL:
 *                 free(d.seq)             # <<<<<<<<<<<<<<
 *             d.tid = b.core.tid
 *             with nogil:
 */
        free(__pyx_v_d->seq);

        /* "pysam/libcalignmentfile.pyx":2405
 *         # reload sequence
 *         if d.fastafile != NULL and b.core.tid != d.tid:
 *             if d.seq != NULL:             # <<<<<<<<<<<<<<
 *                 free(d.seq)
 *             d.tid = b.core.tid
 */
      }

      /* "pysam/libcalignmentfile.pyx":2407
 *             if d.seq != NULL:
 *                 free(d.seq)
 *             d.tid = b.core.tid             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 d.seq = faidx_fetch_seq(
 */
      __pyx_t_4 = __pyx_v_b->core.tid;
      __pyx_v_d->tid = __pyx_t_4;

      /* "pysam/libcalignmentfile.pyx":2408
 *                 free(d.seq)
 *             d.tid = b.core.tid
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 d.seq = faidx_fetch_seq(
 *                     d.fastafile,
 */
      {
          #ifdef WITH_THREAD
          PyThreadState *_save;
          _save = NULL;
          Py_UNBLOCK_THREADS
          __Pyx_FastGIL_Remember();
          #endif
          /*try:*/ {

            /* "pysam/libcalignmentfile.pyx":2409
 *             d.tid = b.core.tid
 *             with nogil:
 *                 d.seq = faidx_fetch_seq(             # <<<<<<<<<<<<<<
 *                     d.fastafile,
 *                     d.header.target_name[d.tid],
 */
            __pyx_v_d->seq = faidx_fetch_seq(__pyx_v_d->fastafile, (__pyx_v_d->header->target_name[__pyx_v_d->tid]), 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, (&__pyx_v_d->seq_len));
          }

          /* "pysam/libcalignmentfile.pyx":2408
 *                 free(d.seq)
 *             d.tid = b.core.tid
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 d.seq = faidx_fetch_seq(
 *                     d.fastafile,
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              __Pyx_FastGIL_Forget();
              Py_BLOCK_THREADS
              #endif
              goto __pyx_L23;
            }
            __pyx_L23:;
          }
      }

      /* "pysam/libcalignmentfile.pyx":2415
 *                     &d.seq_len)
 * 
 *             if d.seq == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(
 */
      __pyx_t_2 = (__pyx_v_d->seq == NULL);
      if (unlikely(__pyx_t_2)) {

        /* "pysam/libcalignmentfile.pyx":2417
 *             if d.seq == NULL:
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(             # <<<<<<<<<<<<<<
 *                         d.header.target_name[d.tid], d.tid))
 * 
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_reference_sequence_for_tid_not_f, __pyx_n_s_format); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2417, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);

        /* "pysam/libcalignmentfile.pyx":2418
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(
 *                         d.header.target_name[d.tid], d.tid))             # <<<<<<<<<<<<<<
 * 
 *         # realign read - changes base qualities
 */
        __pyx_t_7 = __Pyx_PyBytes_FromString((__pyx_v_d->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2418, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_d->tid); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2418, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = NULL;
        __pyx_t_10 = 0;
        #if CYTHON_UNPACK_METHODS
        if (likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_10 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[3] = {__pyx_t_9, __pyx_t_7, __pyx_t_8};
          __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_10, 2+__pyx_t_10);
          __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2417, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }

        /* "pysam/libcalignmentfile.pyx":2416
 * 
 *             if d.seq == NULL:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "reference sequence for '{}' (tid={}) not found".format(
 *                         d.header.target_name[d.tid], d.tid))
 */
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2416, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_Raise(__pyx_t_6, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __PYX_ERR(0, 2416, __pyx_L1_error)

        /* "pysam/libcalignmentfile.pyx":2415
 *                     &d.seq_len)
 * 
 *             if d.seq == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "reference sequence for '{}' (tid={}) not found".format(
 */
      }

      /* "pysam/libcalignmentfile.pyx":2404
 * 
 *         # reload sequence
 *         if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
 *             if d.seq != NULL:
 *                 free(d.seq)
 */
    }

    /* "pysam/libcalignmentfile.pyx":2421
 * 
 *         # realign read - changes base qualities
 *         if d.seq != NULL and d.compute_baq:             # <<<<<<<<<<<<<<
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 */
    __pyx_t_3 = (__pyx_v_d->seq != NULL);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L26_bool_binop_done;
    }
    __pyx_t_2 = __pyx_v_d->compute_baq;
    __pyx_L26_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2424
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 *             if d.redo_baq:             # <<<<<<<<<<<<<<
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)
 *             else:
 */
      if (__pyx_v_d->redo_baq) {

        /* "pysam/libcalignmentfile.pyx":2425
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 *             if d.redo_baq:
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)             # <<<<<<<<<<<<<<
 *             else:
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)
 */
        (void)(sam_prob_realn(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, 7));

        /* "pysam/libcalignmentfile.pyx":2424
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 *             if d.redo_baq:             # <<<<<<<<<<<<<<
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)
 *             else:
 */
        goto __pyx_L28;
      }

      /* "pysam/libcalignmentfile.pyx":2427
 *                 sam_prob_realn(b, d.seq, d.seq_len, 7)
 *             else:
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)             # <<<<<<<<<<<<<<
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 */
      /*else*/ {
        (void)(sam_prob_realn(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, 3));
      }
      __pyx_L28:;

      /* "pysam/libcalignmentfile.pyx":2421
 * 
 *         # realign read - changes base qualities
 *         if d.seq != NULL and d.compute_baq:             # <<<<<<<<<<<<<<
 *             # 4th option to realign is flag:
 *             # apply_baq = flag&1, extend_baq = flag&2, redo_baq = flag&4
 */
    }

    /* "pysam/libcalignmentfile.pyx":2429
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:             # <<<<<<<<<<<<<<
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:
 */
    __pyx_t_3 = (__pyx_v_d->seq != NULL);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L30_bool_binop_done;
    }
    __pyx_t_3 = (__pyx_v_d->adjust_capq_threshold > 10);
    __pyx_t_2 = __pyx_t_3;
    __pyx_L30_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2430
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)             # <<<<<<<<<<<<<<
 *             if q < 0:
 *                 continue
 */
      __pyx_v_q = sam_cap_mapq(__pyx_v_b, __pyx_v_d->seq, __pyx_v_d->seq_len, __pyx_v_d->adjust_capq_threshold);

      /* "pysam/libcalignmentfile.pyx":2431
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:             # <<<<<<<<<<<<<<
 *                 continue
 *             elif b.core.qual > q:
 */
      __pyx_t_2 = (__pyx_v_q < 0);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2432
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:
 *                 continue             # <<<<<<<<<<<<<<
 *             elif b.core.qual > q:
 *                 b.core.qual = q
 */
        goto __pyx_L3_continue;

        /* "pysam/libcalignmentfile.pyx":2431
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:             # <<<<<<<<<<<<<<
 *                 continue
 *             elif b.core.qual > q:
 */
      }

      /* "pysam/libcalignmentfile.pyx":2433
 *             if q < 0:
 *                 continue
 *             elif b.core.qual > q:             # <<<<<<<<<<<<<<
 *                 b.core.qual = q
 * 
 */
      __pyx_t_2 = (__pyx_v_b->core.qual > __pyx_v_q);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2434
 *                 continue
 *             elif b.core.qual > q:
 *                 b.core.qual = q             # <<<<<<<<<<<<<<
 * 
 *         if b.core.qual < d.min_mapping_quality:
 */
        __pyx_v_b->core.qual = __pyx_v_q;

        /* "pysam/libcalignmentfile.pyx":2433
 *             if q < 0:
 *                 continue
 *             elif b.core.qual > q:             # <<<<<<<<<<<<<<
 *                 b.core.qual = q
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":2429
 *                 sam_prob_realn(b, d.seq, d.seq_len, 3)
 * 
 *         if d.seq != NULL and d.adjust_capq_threshold > 10:             # <<<<<<<<<<<<<<
 *             q = sam_cap_mapq(b, d.seq, d.seq_len, d.adjust_capq_threshold)
 *             if q < 0:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2436
 *                 b.core.qual = q
 * 
 *         if b.core.qual < d.min_mapping_quality:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 */
    __pyx_t_2 = (__pyx_v_b->core.qual < __pyx_v_d->min_mapping_quality);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2437
 * 
 *         if b.core.qual < d.min_mapping_quality:
 *             continue             # <<<<<<<<<<<<<<
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 *             continue
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2436
 *                 b.core.qual = q
 * 
 *         if b.core.qual < d.min_mapping_quality:             # <<<<<<<<<<<<<<
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 */
    }

    /* "pysam/libcalignmentfile.pyx":2438
 *         if b.core.qual < d.min_mapping_quality:
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    if (__pyx_v_d->ignore_orphans) {
    } else {
      __pyx_t_2 = __pyx_v_d->ignore_orphans;
      goto __pyx_L35_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_b->core.flag & BAM_FPAIRED) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L35_bool_binop_done;
    }
    __pyx_t_3 = (!((__pyx_v_b->core.flag & BAM_FPROPER_PAIR) != 0));
    __pyx_t_2 = __pyx_t_3;
    __pyx_L35_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2439
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):
 *             continue             # <<<<<<<<<<<<<<
 * 
 *         break
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2438
 *         if b.core.qual < d.min_mapping_quality:
 *             continue
 *         if d.ignore_orphans and b.core.flag & BAM_FPAIRED and not (b.core.flag & BAM_FPROPER_PAIR):             # <<<<<<<<<<<<<<
 *             continue
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2441
 *             continue
 * 
 *         break             # <<<<<<<<<<<<<<
 * 
 *     return ret
 */
    goto __pyx_L4_break;
    __pyx_L3_continue:;
  }
  __pyx_L4_break:;

  /* "pysam/libcalignmentfile.pyx":2443
 *         break
 * 
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2385
 * 
 * 
 * cdef int __advance_samtools(void * data, bam1_t * b):             # <<<<<<<<<<<<<<
 *     '''advance using same filter and read processing as in
 *     the samtools pileup.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.__advance_samtools", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2478
 *     '''
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_kwargs = 0;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2478, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2478, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 2478, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2478, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_kwargs);
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  uint32_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 1);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2478, 0, __PYX_ERR(0, 2478, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2479
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", "samtools")
 */
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->samfile);
  __Pyx_DECREF((PyObject *)__pyx_v_self->samfile);
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/libcalignmentfile.pyx":2480
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)             # <<<<<<<<<<<<<<
 *         self.stepper = kwargs.get("stepper", "samtools")
 *         self.max_depth = kwargs.get("max_depth", 8000)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_fastafile, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2480, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_9libcfaidx_FastaFile))))) __PYX_ERR(0, 2480, __pyx_L1_error)
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->fastafile);
  __Pyx_DECREF((PyObject *)__pyx_v_self->fastafile);
  __pyx_v_self->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2481
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", "samtools")             # <<<<<<<<<<<<<<
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_stepper, __pyx_n_u_samtools); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->stepper);
  __Pyx_DECREF(__pyx_v_self->stepper);
  __pyx_v_self->stepper = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2482
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", "samtools")
 *         self.max_depth = kwargs.get("max_depth", 8000)             # <<<<<<<<<<<<<<
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_max_depth, __pyx_int_8000); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2482, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2482, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->max_depth = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2483
 *         self.stepper = kwargs.get("stepper", "samtools")
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)             # <<<<<<<<<<<<<<
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 *         self.iterdata.seq = NULL
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_ignore_overlaps, Py_True); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2483, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2483, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->ignore_overlaps = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2484
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_min_base_quality, __pyx_int_13); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2484, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_uint32_t(__pyx_t_1); if (unlikely((__pyx_t_4 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 2484, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->min_base_quality = __pyx_t_4;

  /* "pysam/libcalignmentfile.pyx":2485
 *         self.ignore_overlaps = kwargs.get("ignore_overlaps", True)
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/libcalignmentfile.pyx":2486
 *         self.min_base_quality = kwargs.get("min_base_quality", 13)
 *         self.iterdata.seq = NULL
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)             # <<<<<<<<<<<<<<
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_min_mapping_quality, __pyx_int_0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2486, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2486, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->iterdata.min_mapping_quality = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2487
 *         self.iterdata.seq = NULL
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)             # <<<<<<<<<<<<<<
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_flag_require, __pyx_int_0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2487, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->iterdata.flag_require = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2488
 *         self.iterdata.min_mapping_quality = kwargs.get("min_mapping_quality", 0)
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)             # <<<<<<<<<<<<<<
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 */
  __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_flag_filter, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2488, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.flag_filter = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2489
 *         self.iterdata.flag_require = kwargs.get("flag_require", 0)
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)             # <<<<<<<<<<<<<<
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_adjust_capq_threshold, __pyx_int_0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2489, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2489, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.adjust_capq_threshold = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2490
 *         self.iterdata.flag_filter = kwargs.get("flag_filter", BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP)
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)             # <<<<<<<<<<<<<<
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_compute_baq, Py_True); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2490, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.compute_baq = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2491
 *         self.iterdata.adjust_capq_threshold = kwargs.get("adjust_capq_threshold", 0)
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)             # <<<<<<<<<<<<<<
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)
 * 
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_redo_baq, Py_False); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2491, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2491, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.redo_baq = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2492
 *         self.iterdata.compute_baq = kwargs.get("compute_baq", True)
 *         self.iterdata.redo_baq = kwargs.get("redo_baq", False)
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)             # <<<<<<<<<<<<<<
 * 
 *         self.tid = 0
 */
  __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_u_ignore_orphans, Py_True); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2492, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_self->iterdata.ignore_orphans = __pyx_t_3;

  /* "pysam/libcalignmentfile.pyx":2494
 *         self.iterdata.ignore_orphans = kwargs.get("ignore_orphans", True)
 * 
 *         self.tid = 0             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         self.n_plp = 0
 */
  __pyx_v_self->tid = 0;

  /* "pysam/libcalignmentfile.pyx":2495
 * 
 *         self.tid = 0
 *         self.pos = 0             # <<<<<<<<<<<<<<
 *         self.n_plp = 0
 *         self.plp = NULL
 */
  __pyx_v_self->pos = 0;

  /* "pysam/libcalignmentfile.pyx":2496
 *         self.tid = 0
 *         self.pos = 0
 *         self.n_plp = 0             # <<<<<<<<<<<<<<
 *         self.plp = NULL
 *         self.pileup_iter = <bam_mplp_t>NULL
 */
  __pyx_v_self->n_plp = 0;

  /* "pysam/libcalignmentfile.pyx":2497
 *         self.pos = 0
 *         self.n_plp = 0
 *         self.plp = NULL             # <<<<<<<<<<<<<<
 *         self.pileup_iter = <bam_mplp_t>NULL
 * 
 */
  __pyx_v_self->plp = NULL;

  /* "pysam/libcalignmentfile.pyx":2498
 *         self.n_plp = 0
 *         self.plp = NULL
 *         self.pileup_iter = <bam_mplp_t>NULL             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->pileup_iter = ((bam_mplp_t)NULL);

  /* "pysam/libcalignmentfile.pyx":2478
 *     '''
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         self.fastafile = kwargs.get("fastafile", None)
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2500
 *         self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__iter__", 1);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 2500, 0, __PYX_ERR(0, 2500, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2501
 * 
 *     def __iter__(self):
 *         return self             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self);
  __pyx_r = ((PyObject *)__pyx_v_self);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2500
 *         self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2503
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

static int __pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("cnext", __pyx_f[0], 2503, 0, __PYX_ERR(0, 2503, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2507
 *         '''
 *         # do not release gil here because of call-backs
 *         cdef int ret = bam_mplp_auto(self.pileup_iter,             # <<<<<<<<<<<<<<
 *                                      &self.tid,
 *                                      &self.pos,
 */
  __pyx_v_ret = bam_mplp_auto(__pyx_v_self->pileup_iter, (&__pyx_v_self->tid), (&__pyx_v_self->pos), (&__pyx_v_self->n_plp), (&__pyx_v_self->plp));

  /* "pysam/libcalignmentfile.pyx":2512
 *                                      &self.n_plp,
 *                                      &self.plp)
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     cdef char * get_sequence(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2503
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2514
 *         return ret
 * 
 *     cdef char * get_sequence(self):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  char *__pyx_r;
  __Pyx_TraceDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("get_sequence", __pyx_f[0], 2514, 0, __PYX_ERR(0, 2514, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2517
 *         '''return current reference sequence underlying the iterator.
 *         '''
 *         return self.iterdata.seq             # <<<<<<<<<<<<<<
 * 
 *     property seq_len:
 */
  __pyx_r = __pyx_v_self->iterdata.seq;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2514
 *         return ret
 * 
 *     cdef char * get_sequence(self):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.get_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2521
 *     property seq_len:
 *         '''current sequence length.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.iterdata.seq_len
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2521, 0, __PYX_ERR(0, 2521, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2522
 *         '''current sequence length.'''
 *         def __get__(self):
 *             return self.iterdata.seq_len             # <<<<<<<<<<<<<<
 * 
 *     def add_reference(self, FastaFile fastafile):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2521
 *     property seq_len:
 *         '''current sequence length.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.iterdata.seq_len
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.seq_len.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2524
 *             return self.iterdata.seq_len
 * 
 *     def add_reference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference, "IteratorColumn.add_reference(self, FastaFile fastafile)\n\n       add reference sequences in `fastafile` to iterator.");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference = {"add_reference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add_reference (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fastafile,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_fastafile)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2524, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "add_reference") < 0)) __PYX_ERR(0, 2524, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)values[0]);
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add_reference", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 2524, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.add_reference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9libcfaidx_FastaFile, 1, "fastafile", 0))) __PYX_ERR(0, 2524, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_fastafile);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  faidx_t *__pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__100)
  __Pyx_RefNannySetupContext("add_reference", 1);
  __Pyx_TraceCall("add_reference", __pyx_f[0], 2524, 0, __PYX_ERR(0, 2524, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2527
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 *        self.fastafile = fastafile             # <<<<<<<<<<<<<<
 *        if self.iterdata.seq != NULL:
 *            free(self.iterdata.seq)
 */
  __Pyx_INCREF((PyObject *)__pyx_v_fastafile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_fastafile);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->fastafile);
  __Pyx_DECREF((PyObject *)__pyx_v_self->fastafile);
  __pyx_v_self->fastafile = __pyx_v_fastafile;

  /* "pysam/libcalignmentfile.pyx":2528
 *        add reference sequences in `fastafile` to iterator.'''
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *            free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 */
  __pyx_t_1 = (__pyx_v_self->iterdata.seq != NULL);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2529
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL:
 *            free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile
 */
    free(__pyx_v_self->iterdata.seq);

    /* "pysam/libcalignmentfile.pyx":2528
 *        add reference sequences in `fastafile` to iterator.'''
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *            free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 */
  }

  /* "pysam/libcalignmentfile.pyx":2530
 *        if self.iterdata.seq != NULL:
 *            free(self.iterdata.seq)
 *        self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/libcalignmentfile.pyx":2531
 *            free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 * 
 *     def has_reference(self):
 */
  __pyx_t_2 = __pyx_v_self->fastafile->fastafile;
  __pyx_v_self->iterdata.fastafile = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2524
 *             return self.iterdata.seq_len
 * 
 *     def add_reference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.add_reference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2533
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def has_reference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference, "IteratorColumn.has_reference(self)\n\n        return true if iterator is associated with a reference");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference = {"has_reference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("has_reference (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("has_reference", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "has_reference", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__101)
  __Pyx_RefNannySetupContext("has_reference", 1);
  __Pyx_TraceCall("has_reference", __pyx_f[0], 2533, 0, __PYX_ERR(0, 2533, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2536
 *         '''
 *         return true if iterator is associated with a reference'''
 *         return self.fastafile             # <<<<<<<<<<<<<<
 * 
 *     cdef _setup_iterator(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF((PyObject *)__pyx_v_self->fastafile);
  __pyx_r = ((PyObject *)__pyx_v_self->fastafile);
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2533
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def has_reference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.has_reference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2538
 *         return self.fastafile
 * 
 *     cdef _setup_iterator(self,             # <<<<<<<<<<<<<<
 *                          int tid,
 *                          int start,
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args) {
  int __pyx_v_multiple_iterators = ((int)0);
  void *__pyx_v_data[1];
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  htsFile *__pyx_t_6;
  hts_itr_t *__pyx_t_7;
  bam_hdr_t *__pyx_t_8;
  int __pyx_t_9;
  faidx_t *__pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_setup_iterator", 1);
  __Pyx_TraceCall("_setup_iterator", __pyx_f[0], 2538, 0, __PYX_ERR(0, 2538, __pyx_L1_error));
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_multiple_iterators = __pyx_optional_args->multiple_iterators;
    }
  }

  /* "pysam/libcalignmentfile.pyx":2545
 *         '''setup the iterator structure'''
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators)             # <<<<<<<<<<<<<<
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.iter = self.iter.iter
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_stop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF((PyObject *)__pyx_v_self->samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self->samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self->samfile))) __PYX_ERR(0, 2545, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1)) __PYX_ERR(0, 2545, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2)) __PYX_ERR(0, 2545, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_3);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_3)) __PYX_ERR(0, 2545, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4)) __PYX_ERR(0, 2545, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2545, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->iter);
  __Pyx_DECREF((PyObject *)__pyx_v_self->iter);
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2546
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators)
 *         self.iterdata.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL
 */
  __pyx_t_6 = __pyx_v_self->samfile->__pyx_base.htsfile;
  __pyx_v_self->iterdata.htsfile = __pyx_t_6;

  /* "pysam/libcalignmentfile.pyx":2547
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators)
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 */
  __pyx_t_7 = __pyx_v_self->iter->iter;
  __pyx_v_self->iterdata.iter = __pyx_t_7;

  /* "pysam/libcalignmentfile.pyx":2548
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header.ptr
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/libcalignmentfile.pyx":2549
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/libcalignmentfile.pyx":2550
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header.ptr             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile is not None:
 */
  __pyx_t_8 = __pyx_v_self->samfile->header->ptr;
  __pyx_v_self->iterdata.header = __pyx_t_8;

  /* "pysam/libcalignmentfile.pyx":2552
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
  __pyx_t_9 = (((PyObject *)__pyx_v_self->fastafile) != Py_None);
  if (__pyx_t_9) {

    /* "pysam/libcalignmentfile.pyx":2553
 * 
 *         if self.fastafile is not None:
 *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 *         else:
 *             self.iterdata.fastafile = NULL
 */
    __pyx_t_10 = __pyx_v_self->fastafile->fastafile;
    __pyx_v_self->iterdata.fastafile = __pyx_t_10;

    /* "pysam/libcalignmentfile.pyx":2552
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":2555
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *         # Free any previously allocated memory before reassigning
 */
  /*else*/ {
    __pyx_v_self->iterdata.fastafile = NULL;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":2559
 *         # Free any previously allocated memory before reassigning
 *         # pileup_iter
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 * 
 *         cdef void * data[1]
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2559, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2562
 * 
 *         cdef void * data[1]
 *         data[0] = <void*>&self.iterdata             # <<<<<<<<<<<<<<
 * 
 *         if self.stepper is None or self.stepper == "all":
 */
  (__pyx_v_data[0]) = ((void *)(&__pyx_v_self->iterdata));

  /* "pysam/libcalignmentfile.pyx":2564
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_11 = (__pyx_v_self->stepper == Py_None);
  if (!__pyx_t_11) {
  } else {
    __pyx_t_9 = __pyx_t_11;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_11 = (__Pyx_PyUnicode_Equals(__pyx_v_self->stepper, __pyx_n_u_all, Py_EQ)); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 2564, __pyx_L1_error)
  __pyx_t_9 = __pyx_t_11;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_9) {

    /* "pysam/libcalignmentfile.pyx":2565
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_all,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2566
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_all,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_all)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2565
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_all,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2564
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2569
 *                                                  <bam_plp_auto_f>&__advance_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_self->stepper, __pyx_n_u_nofilter, Py_EQ)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 2569, __pyx_L1_error)
  if (__pyx_t_9) {

    /* "pysam/libcalignmentfile.pyx":2570
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2571
 *         elif self.stepper == "nofilter":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_nofilter)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2570
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L12;
          }
          __pyx_L12:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2569
 *                                                  <bam_plp_auto_f>&__advance_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2574
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_self->stepper, __pyx_n_u_samtools, Py_EQ)); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 2574, __pyx_L1_error)
  if (likely(__pyx_t_9)) {

    /* "pysam/libcalignmentfile.pyx":2575
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2576
 *         elif self.stepper == "samtools":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_samtools)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2575
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L15;
          }
          __pyx_L15:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2574
 *                                                  <bam_plp_auto_f>&__advance_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2580
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
  /*else*/ {

    /* "pysam/libcalignmentfile.pyx":2581
 *         else:
 *             raise ValueError(
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
 * 
 *         if self.max_depth:
 */
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2581, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/libcalignmentfile.pyx":2580
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2580, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __PYX_ERR(0, 2580, __pyx_L1_error)
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":2583
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  __pyx_t_9 = (__pyx_v_self->max_depth != 0);
  if (__pyx_t_9) {

    /* "pysam/libcalignmentfile.pyx":2584
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2585
 *         if self.max_depth:
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)             # <<<<<<<<<<<<<<
 * 
 *         if self.ignore_overlaps:
 */
          bam_mplp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
        }

        /* "pysam/libcalignmentfile.pyx":2584
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L19;
          }
          __pyx_L19:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2583
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2587
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  if (__pyx_v_self->ignore_overlaps) {

    /* "pysam/libcalignmentfile.pyx":2588
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2589
 *         if self.ignore_overlaps:
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     cdef _setup_raw_rest_iterator(self):
 */
          bam_mplp_init_overlaps(__pyx_v_self->pileup_iter);
        }

        /* "pysam/libcalignmentfile.pyx":2588
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L23;
          }
          __pyx_L23:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2587
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2538
 *         return self.fastafile
 * 
 *     cdef _setup_iterator(self,             # <<<<<<<<<<<<<<
 *                          int tid,
 *                          int start,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn._setup_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2591
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef _setup_raw_rest_iterator(self):             # <<<<<<<<<<<<<<
 *         '''set up an "iterator" that just uses sam_read1(), similar to HTS_IDX_REST'''
 * 
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_raw_rest_iterator(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  void *__pyx_v_data[1];
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  htsFile *__pyx_t_1;
  bam_hdr_t *__pyx_t_2;
  int __pyx_t_3;
  faidx_t *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_setup_raw_rest_iterator", 1);
  __Pyx_TraceCall("_setup_raw_rest_iterator", __pyx_f[0], 2591, 0, __PYX_ERR(0, 2591, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2594
 *         '''set up an "iterator" that just uses sam_read1(), similar to HTS_IDX_REST'''
 * 
 *         self.iter = None             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = NULL
 *         self.iterdata.htsfile = self.samfile.htsfile
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->iter);
  __Pyx_DECREF((PyObject *)__pyx_v_self->iter);
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None);

  /* "pysam/libcalignmentfile.pyx":2595
 * 
 *         self.iter = None
 *         self.iterdata.iter = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.seq = NULL
 */
  __pyx_v_self->iterdata.iter = NULL;

  /* "pysam/libcalignmentfile.pyx":2596
 *         self.iter = None
 *         self.iterdata.iter = NULL
 *         self.iterdata.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 */
  __pyx_t_1 = __pyx_v_self->samfile->__pyx_base.htsfile;
  __pyx_v_self->iterdata.htsfile = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2597
 *         self.iterdata.iter = NULL
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header.ptr
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/libcalignmentfile.pyx":2598
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/libcalignmentfile.pyx":2599
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header.ptr             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile is not None:
 */
  __pyx_t_2 = __pyx_v_self->samfile->header->ptr;
  __pyx_v_self->iterdata.header = __pyx_t_2;

  /* "pysam/libcalignmentfile.pyx":2601
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
  __pyx_t_3 = (((PyObject *)__pyx_v_self->fastafile) != Py_None);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":2602
 * 
 *         if self.fastafile is not None:
 *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 *         else:
 *             self.iterdata.fastafile = NULL
 */
    __pyx_t_4 = __pyx_v_self->fastafile->fastafile;
    __pyx_v_self->iterdata.fastafile = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":2601
 *         self.iterdata.header = self.samfile.header.ptr
 * 
 *         if self.fastafile is not None:             # <<<<<<<<<<<<<<
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":2604
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *         # Free any previously allocated memory before reassigning
 */
  /*else*/ {
    __pyx_v_self->iterdata.fastafile = NULL;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":2608
 *         # Free any previously allocated memory before reassigning
 *         # pileup_iter
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 * 
 *         cdef void * data[1]
 */
  __pyx_t_5 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2608, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysam/libcalignmentfile.pyx":2611
 * 
 *         cdef void * data[1]
 *         data[0] = <void*>&self.iterdata             # <<<<<<<<<<<<<<
 * 
 *         if self.stepper is None or self.stepper == "all":
 */
  (__pyx_v_data[0]) = ((void *)(&__pyx_v_self->iterdata));

  /* "pysam/libcalignmentfile.pyx":2613
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_6 = (__pyx_v_self->stepper == Py_None);
  if (!__pyx_t_6) {
  } else {
    __pyx_t_3 = __pyx_t_6;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_self->stepper, __pyx_n_u_all, Py_EQ)); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 2613, __pyx_L1_error)
  __pyx_t_3 = __pyx_t_6;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":2614
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2615
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_raw_all)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2614
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L9;
          }
          __pyx_L9:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2613
 *         data[0] = <void*>&self.iterdata
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2618
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_self->stepper, __pyx_n_u_nofilter, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 2618, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":2619
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2620
 *         elif self.stepper == "nofilter":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_raw_nofilter)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2619
 *                                                  data)
 *         elif self.stepper == "nofilter":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L12;
          }
          __pyx_L12:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2618
 *                                                  <bam_plp_auto_f>&__advance_raw_all,
 *                                                  data)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2623
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_self->stepper, __pyx_n_u_samtools, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 2623, __pyx_L1_error)
  if (likely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":2624
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2625
 *         elif self.stepper == "samtools":
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,             # <<<<<<<<<<<<<<
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 *                                                  data)
 */
          __pyx_v_self->pileup_iter = bam_mplp_init(1, ((bam_plp_auto_f)(&__pyx_f_5pysam_17libcalignmentfile___advance_samtools)), __pyx_v_data);
        }

        /* "pysam/libcalignmentfile.pyx":2624
 *                                                  data)
 *         elif self.stepper == "samtools":
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = bam_mplp_init(1,
 *                                                  <bam_plp_auto_f>&__advance_samtools,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L15;
          }
          __pyx_L15:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2623
 *                                                  <bam_plp_auto_f>&__advance_raw_nofilter,
 *                                                  data)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.pileup_iter = bam_mplp_init(1,
 */
    goto __pyx_L4;
  }

  /* "pysam/libcalignmentfile.pyx":2629
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
  /*else*/ {

    /* "pysam/libcalignmentfile.pyx":2630
 *         else:
 *             raise ValueError(
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
 * 
 *         if self.max_depth:
 */
    __pyx_t_5 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2630, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "pysam/libcalignmentfile.pyx":2629
 *                                                  data)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_7, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __PYX_ERR(0, 2629, __pyx_L1_error)
  }
  __pyx_L4:;

  /* "pysam/libcalignmentfile.pyx":2632
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  __pyx_t_3 = (__pyx_v_self->max_depth != 0);
  if (__pyx_t_3) {

    /* "pysam/libcalignmentfile.pyx":2633
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2634
 *         if self.max_depth:
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)             # <<<<<<<<<<<<<<
 * 
 *         if self.ignore_overlaps:
 */
          bam_mplp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
        }

        /* "pysam/libcalignmentfile.pyx":2633
 * 
 *         if self.max_depth:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L19;
          }
          __pyx_L19:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2632
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2636
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  if (__pyx_v_self->ignore_overlaps) {

    /* "pysam/libcalignmentfile.pyx":2637
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2638
 *         if self.ignore_overlaps:
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     cdef reset(self, tid, start, stop):
 */
          bam_mplp_init_overlaps(__pyx_v_self->pileup_iter);
        }

        /* "pysam/libcalignmentfile.pyx":2637
 * 
 *         if self.ignore_overlaps:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L23;
          }
          __pyx_L23:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2636
 *                 bam_mplp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 *         if self.ignore_overlaps:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2591
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef _setup_raw_rest_iterator(self):             # <<<<<<<<<<<<<<
 *         '''set up an "iterator" that just uses sam_read1(), similar to HTS_IDX_REST'''
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn._setup_raw_rest_iterator", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2640
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef reset(self, tid, start, stop):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_stop) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  hts_itr_t *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("reset", 1);
  __Pyx_TraceCall("reset", __pyx_f[0], 2640, 0, __PYX_ERR(0, 2640, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2646
 *         having to incur the full set-up costs.
 *         '''
 *         if self.iter is None:             # <<<<<<<<<<<<<<
 *             raise TypeError("Raw iterator set up without region cannot be reset")
 * 
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->iter) == Py_None);
  if (unlikely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2647
 *         '''
 *         if self.iter is None:
 *             raise TypeError("Raw iterator set up without region cannot be reset")             # <<<<<<<<<<<<<<
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__102, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2647, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2647, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2646
 *         having to incur the full set-up costs.
 *         '''
 *         if self.iter is None:             # <<<<<<<<<<<<<<
 *             raise TypeError("Raw iterator set up without region cannot be reset")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2649
 *             raise TypeError("Raw iterator set up without region cannot be reset")
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 * 
 */
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF((PyObject *)__pyx_v_self->samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_self->samfile);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->samfile))) __PYX_ERR(0, 2649, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_tid)) __PYX_ERR(0, 2649, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_start)) __PYX_ERR(0, 2649, __pyx_L1_error);
  __Pyx_INCREF(__pyx_v_stop);
  __Pyx_GIVEREF(__pyx_v_stop);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_stop)) __PYX_ERR(0, 2649, __pyx_L1_error);
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_int_0) < 0) __PYX_ERR(0, 2649, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion), __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2649, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->iter);
  __Pyx_DECREF((PyObject *)__pyx_v_self->iter);
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pysam/libcalignmentfile.pyx":2650
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)
 *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
 * 
 *         # invalidate sequence if different tid
 */
  __pyx_t_5 = __pyx_v_self->iter->iter;
  __pyx_v_self->iterdata.iter = __pyx_t_5;

  /* "pysam/libcalignmentfile.pyx":2653
 * 
 *         # invalidate sequence if different tid
 *         if self.tid != tid:             # <<<<<<<<<<<<<<
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 2653, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2654
 *         # invalidate sequence if different tid
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
    __pyx_t_1 = (__pyx_v_self->iterdata.seq != NULL);
    if (__pyx_t_1) {

      /* "pysam/libcalignmentfile.pyx":2655
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1
 */
      free(__pyx_v_self->iterdata.seq);

      /* "pysam/libcalignmentfile.pyx":2654
 *         # invalidate sequence if different tid
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
    }

    /* "pysam/libcalignmentfile.pyx":2656
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *             self.iterdata.tid = -1
 * 
 */
    __pyx_v_self->iterdata.seq = NULL;

    /* "pysam/libcalignmentfile.pyx":2657
 *                 free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 * 
 *         # self.pileup_iter = bam_mplp_init(1
 */
    __pyx_v_self->iterdata.tid = -1;

    /* "pysam/libcalignmentfile.pyx":2653
 * 
 *         # invalidate sequence if different tid
 *         if self.tid != tid:             # <<<<<<<<<<<<<<
 *             if self.iterdata.seq != NULL:
 *                 free(self.iterdata.seq)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2662
 *         #                                  &__advancepileup,
 *         #                                  &self.iterdata)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bam_mplp_reset(self.pileup_iter)
 * 
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      _save = NULL;
      Py_UNBLOCK_THREADS
      __Pyx_FastGIL_Remember();
      #endif
      /*try:*/ {

        /* "pysam/libcalignmentfile.pyx":2663
 *         #                                  &self.iterdata)
 *         with nogil:
 *             bam_mplp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     cdef _free_pileup_iter(self):
 */
        bam_mplp_reset(__pyx_v_self->pileup_iter);
      }

      /* "pysam/libcalignmentfile.pyx":2662
 *         #                                  &__advancepileup,
 *         #                                  &self.iterdata)
 *         with nogil:             # <<<<<<<<<<<<<<
 *             bam_mplp_reset(self.pileup_iter)
 * 
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          __Pyx_FastGIL_Forget();
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L8;
        }
        __pyx_L8:;
      }
  }

  /* "pysam/libcalignmentfile.pyx":2640
 *                 bam_mplp_init_overlaps(self.pileup_iter)
 * 
 *     cdef reset(self, tid, start, stop):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2665
 *             bam_mplp_reset(self.pileup_iter)
 * 
 *     cdef _free_pileup_iter(self):             # <<<<<<<<<<<<<<
 *         '''free the memory alloc'd by bam_plp_init.
 * 
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_free_pileup_iter", 1);
  __Pyx_TraceCall("_free_pileup_iter", __pyx_f[0], 2665, 0, __PYX_ERR(0, 2665, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2670
 *         This is needed before setup_iterator allocates another
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)
 */
  __pyx_t_1 = (__pyx_v_self->pileup_iter != ((bam_mplp_t)NULL));
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2671
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2672
 *         if self.pileup_iter != <bam_mplp_t>NULL:
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 *                 bam_mplp_destroy(self.pileup_iter)
 *                 self.pileup_iter = <bam_mplp_t>NULL
 */
          bam_mplp_reset(__pyx_v_self->pileup_iter);

          /* "pysam/libcalignmentfile.pyx":2673
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
 *                 self.pileup_iter = <bam_mplp_t>NULL
 * 
 */
          bam_mplp_destroy(__pyx_v_self->pileup_iter);

          /* "pysam/libcalignmentfile.pyx":2674
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)
 *                 self.pileup_iter = <bam_mplp_t>NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
          __pyx_v_self->pileup_iter = ((bam_mplp_t)NULL);
        }

        /* "pysam/libcalignmentfile.pyx":2671
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 bam_mplp_reset(self.pileup_iter)
 *                 bam_mplp_destroy(self.pileup_iter)
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L6;
          }
          __pyx_L6:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2670
 *         This is needed before setup_iterator allocates another
 *         pileup_iter, or else memory will be lost.  '''
 *         if self.pileup_iter != <bam_mplp_t>NULL:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 bam_mplp_reset(self.pileup_iter)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2665
 *             bam_mplp_reset(self.pileup_iter)
 * 
 *     cdef _free_pileup_iter(self):             # <<<<<<<<<<<<<<
 *         '''free the memory alloc'd by bam_plp_init.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn._free_pileup_iter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2676
 *                 self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 1);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2676, 0, __PYX_ERR(0, 2676, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2679
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 *         self.plp = <const bam_pileup1_t*>NULL
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2679, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2680
 *         # that have not been fully consumed
 *         self._free_pileup_iter()
 *         self.plp = <const bam_pileup1_t*>NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.iterdata.seq != NULL:
 */
  __pyx_v_self->plp = ((bam_pileup1_t const *)NULL);

  /* "pysam/libcalignmentfile.pyx":2682
 *         self.plp = <const bam_pileup1_t*>NULL
 * 
 *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
  __pyx_t_2 = (__pyx_v_self->iterdata.seq != NULL);
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":2683
 * 
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 * 
 */
    free(__pyx_v_self->iterdata.seq);

    /* "pysam/libcalignmentfile.pyx":2684
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 * 
 *     # backwards compatibility
 */
    __pyx_v_self->iterdata.seq = NULL;

    /* "pysam/libcalignmentfile.pyx":2682
 *         self.plp = <const bam_pileup1_t*>NULL
 * 
 *         if self.iterdata.seq != NULL:             # <<<<<<<<<<<<<<
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL
 */
  }

  /* "pysam/libcalignmentfile.pyx":2676
 *                 self.pileup_iter = <bam_mplp_t>NULL
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IteratorColumn.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/libcalignmentfile.pyx":2688
 *     # backwards compatibility
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference, "IteratorColumn.hasReference(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference = {"hasReference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("hasReference (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("hasReference", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "hasReference", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__103)
  __Pyx_RefNannySetupContext("hasReference", 1);
  __Pyx_TraceCall("hasReference", __pyx_f[0], 2688, 0, __PYX_ERR(0, 2688, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2689
 * 
 *     def hasReference(self):
 *         return self.has_reference()             # <<<<<<<<<<<<<<
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_reference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2689, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2688
 *     # backwards compatibility
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.hasReference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2690
 *     def hasReference(self):
 *         return self.has_reference()
 *     cdef char * getSequence(self):             # <<<<<<<<<<<<<<
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):
 */

static char *__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  char *__pyx_r;
  __Pyx_TraceDeclarations
  char *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("getSequence", __pyx_f[0], 2690, 0, __PYX_ERR(0, 2690, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2691
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 *         return self.get_sequence()             # <<<<<<<<<<<<<<
 *     def addReference(self, FastaFile fastafile):
 *         return self.add_reference(fastafile)
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->get_sequence(__pyx_v_self); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2691, __pyx_L1_error)
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2690
 *     def hasReference(self):
 *         return self.has_reference()
 *     cdef char * getSequence(self):             # <<<<<<<<<<<<<<
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.getSequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2692
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *         return self.add_reference(fastafile)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12addReference, "IteratorColumn.addReference(self, FastaFile fastafile)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_13addReference = {"addReference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12addReference};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("addReference (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fastafile,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_fastafile)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2692, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "addReference") < 0)) __PYX_ERR(0, 2692, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)values[0]);
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("addReference", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 2692, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.addReference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_9libcfaidx_FastaFile, 1, "fastafile", 0))) __PYX_ERR(0, 2692, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_fastafile);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_12addReference(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_9libcfaidx_FastaFile *__pyx_v_fastafile) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__104)
  __Pyx_RefNannySetupContext("addReference", 1);
  __Pyx_TraceCall("addReference", __pyx_f[0], 2692, 0, __PYX_ERR(0, 2692, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2693
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):
 *         return self.add_reference(fastafile)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_reference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2693, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_3, ((PyObject *)__pyx_v_fastafile)};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2693, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2692
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *         return self.add_reference(fastafile)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.addReference", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__, "IteratorColumn.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__105)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__, "IteratorColumn.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__106)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumn.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2699
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   int tid = 0,
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_start;
  int __pyx_v_stop;
  int __pyx_v_truncate;
  int __pyx_v_multiple_iterators;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[6] = {0,0,0,0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_truncate,&__pyx_n_s_multiple_iterators,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  6: values[5] = __Pyx_Arg_VARARGS(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_VARARGS(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2699, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tid);
          if (value) { values[1] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2699, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_start);
          if (value) { values[2] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2699, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_stop);
          if (value) { values[3] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2699, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_truncate);
          if (value) { values[4] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2699, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[5] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2699, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2699, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  6: values[5] = __Pyx_Arg_VARARGS(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_VARARGS(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2701, __pyx_L3_error)
    } else {
      __pyx_v_tid = ((int)0);
    }
    if (values[2]) {
      __pyx_v_start = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2702, __pyx_L3_error)
    } else {
      __pyx_v_start = ((int)0);
    }
    if (values[3]) {
      __pyx_v_stop = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_stop == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2703, __pyx_L3_error)
    } else {
      __pyx_v_stop = __pyx_k__107;
    }
    if (values[4]) {
      __pyx_v_truncate = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2704, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2704
 *                   int start = 0,
 *                   int stop = MAX_POS,
 *                   int truncate = False,             # <<<<<<<<<<<<<<
 *                   int multiple_iterators = True,
 *                   **kwargs ):
 */
      __pyx_v_truncate = ((int)0);
    }
    if (values[5]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2705, __pyx_L3_error)
    } else {

      /* "pysam/libcalignmentfile.pyx":2705
 *                   int stop = MAX_POS,
 *                   int truncate = False,
 *                   int multiple_iterators = True,             # <<<<<<<<<<<<<<
 *                   **kwargs ):
 * 
 */
      __pyx_v_multiple_iterators = ((int)1);
    }
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 6, __pyx_nargs); __PYX_ERR(0, 2699, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2700, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_stop, __pyx_v_truncate, __pyx_v_multiple_iterators, __pyx_v_kwargs);

  /* "pysam/libcalignmentfile.pyx":2699
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   int tid = 0,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_kwargs);
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_stop, int __pyx_v_truncate, int __pyx_v_multiple_iterators, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  unsigned int __pyx_t_6;
  struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 1);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2699, 0, __PYX_ERR(0, 2699, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2710
 *         # initialize iterator. Multiple iterators not available
 *         # for CRAM.
 *         if multiple_iterators and samfile.is_cram:             # <<<<<<<<<<<<<<
 *             warnings.warn("multiple_iterators not implemented for CRAM")
 *             multiple_iterators = False
 */
  __pyx_t_2 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_cram); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2710, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2710, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2711
 *         # for CRAM.
 *         if multiple_iterators and samfile.is_cram:
 *             warnings.warn("multiple_iterators not implemented for CRAM")             # <<<<<<<<<<<<<<
 *             multiple_iterators = False
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_warnings); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_warn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    __pyx_t_6 = 0;
    #if CYTHON_UNPACK_METHODS
    if (unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_6 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_kp_u_multiple_iterators_not_implement_2};
      __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/libcalignmentfile.pyx":2712
 *         if multiple_iterators and samfile.is_cram:
 *             warnings.warn("multiple_iterators not implemented for CRAM")
 *             multiple_iterators = False             # <<<<<<<<<<<<<<
 * 
 *         self._setup_iterator(tid, start, stop, multiple_iterators)
 */
    __pyx_v_multiple_iterators = 0;

    /* "pysam/libcalignmentfile.pyx":2710
 *         # initialize iterator. Multiple iterators not available
 *         # for CRAM.
 *         if multiple_iterators and samfile.is_cram:             # <<<<<<<<<<<<<<
 *             warnings.warn("multiple_iterators not implemented for CRAM")
 *             multiple_iterators = False
 */
  }

  /* "pysam/libcalignmentfile.pyx":2714
 *             multiple_iterators = False
 * 
 *         self._setup_iterator(tid, start, stop, multiple_iterators)             # <<<<<<<<<<<<<<
 *         self.start = start
 *         self.stop = stop
 */
  __pyx_t_7.__pyx_n = 1;
  __pyx_t_7.multiple_iterators = __pyx_v_multiple_iterators;
  __pyx_t_3 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_stop, &__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2714, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/libcalignmentfile.pyx":2715
 * 
 *         self._setup_iterator(tid, start, stop, multiple_iterators)
 *         self.start = start             # <<<<<<<<<<<<<<
 *         self.stop = stop
 *         self.truncate = truncate
 */
  __pyx_v_self->start = __pyx_v_start;

  /* "pysam/libcalignmentfile.pyx":2716
 *         self._setup_iterator(tid, start, stop, multiple_iterators)
 *         self.start = start
 *         self.stop = stop             # <<<<<<<<<<<<<<
 *         self.truncate = truncate
 * 
 */
  __pyx_v_self->stop = __pyx_v_stop;

  /* "pysam/libcalignmentfile.pyx":2717
 *         self.start = start
 *         self.stop = stop
 *         self.truncate = truncate             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_v_self->truncate = __pyx_v_truncate;

  /* "pysam/libcalignmentfile.pyx":2699
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   int tid = 0,
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2719
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self) {
  int __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2719, 0, __PYX_ERR(0, 2719, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2723
 *         cdef int n
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             n = self.cnext()
 *             if n < 0:
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2724
 * 
 *         while 1:
 *             n = self.cnext()             # <<<<<<<<<<<<<<
 *             if n < 0:
 *                 raise ValueError("error during iteration" )
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2724, __pyx_L1_error)
    __pyx_v_n = __pyx_t_1;

    /* "pysam/libcalignmentfile.pyx":2725
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    __pyx_t_2 = (__pyx_v_n < 0);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":2726
 *             n = self.cnext()
 *             if n < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if n == 0:
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__108, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2726, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 2726, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2725
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2728
 *                 raise ValueError("error during iteration" )
 * 
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 * 
 */
    __pyx_t_2 = (__pyx_v_n == 0);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":2729
 * 
 *             if n == 0:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             if self.truncate:
 */
      __pyx_error_without_exception = 1;
      goto __pyx_L1_error;;

      /* "pysam/libcalignmentfile.pyx":2728
 *                 raise ValueError("error during iteration" )
 * 
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2731
 *                 raise StopIteration
 * 
 *             if self.truncate:             # <<<<<<<<<<<<<<
 *                 if self.start > self.pos:
 *                     continue
 */
    __pyx_t_2 = (__pyx_v_self->truncate != 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2732
 * 
 *             if self.truncate:
 *                 if self.start > self.pos:             # <<<<<<<<<<<<<<
 *                     continue
 *                 if self.pos >= self.stop:
 */
      __pyx_t_2 = (__pyx_v_self->start > __pyx_v_self->__pyx_base.pos);
      if (__pyx_t_2) {

        /* "pysam/libcalignmentfile.pyx":2733
 *             if self.truncate:
 *                 if self.start > self.pos:
 *                     continue             # <<<<<<<<<<<<<<
 *                 if self.pos >= self.stop:
 *                     raise StopIteration
 */
        goto __pyx_L3_continue;

        /* "pysam/libcalignmentfile.pyx":2732
 * 
 *             if self.truncate:
 *                 if self.start > self.pos:             # <<<<<<<<<<<<<<
 *                     continue
 *                 if self.pos >= self.stop:
 */
      }

      /* "pysam/libcalignmentfile.pyx":2734
 *                 if self.start > self.pos:
 *                     continue
 *                 if self.pos >= self.stop:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 * 
 */
      __pyx_t_2 = (__pyx_v_self->__pyx_base.pos >= __pyx_v_self->stop);
      if (unlikely(__pyx_t_2)) {

        /* "pysam/libcalignmentfile.pyx":2735
 *                     continue
 *                 if self.pos >= self.stop:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             return makePileupColumn(&self.plp,
 */
        __pyx_error_without_exception = 1;
        goto __pyx_L1_error;;

        /* "pysam/libcalignmentfile.pyx":2734
 *                 if self.start > self.pos:
 *                     continue
 *                 if self.pos >= self.stop:             # <<<<<<<<<<<<<<
 *                     raise StopIteration
 * 
 */
      }

      /* "pysam/libcalignmentfile.pyx":2731
 *                 raise StopIteration
 * 
 *             if self.truncate:             # <<<<<<<<<<<<<<
 *                 if self.start > self.pos:
 *                     continue
 */
    }

    /* "pysam/libcalignmentfile.pyx":2737
 *                     raise StopIteration
 * 
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/libcalignmentfile.pyx":2743
 *                                     self.min_base_quality,
 *                                     self.iterdata.seq,
 *                                     self.samfile.header)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_3 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header);
    __Pyx_INCREF(__pyx_t_3);

    /* "pysam/libcalignmentfile.pyx":2737
 *                     raise StopIteration
 * 
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_3))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2737, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
    __pyx_L3_continue:;
  }

  /* "pysam/libcalignmentfile.pyx":2719
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__, "IteratorColumnRegion.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__109)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__, "IteratorColumnRegion.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__110)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnRegion.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2750
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2750, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2750, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 2750, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2751, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_kwargs);
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 1);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2750, 0, __PYX_ERR(0, 2750, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2755
 * 
 *         # no iteration over empty files
 *         if not samfile.nreferences:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2755, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (!__pyx_t_2);
  if (unlikely(__pyx_t_3)) {

    /* "pysam/libcalignmentfile.pyx":2756
 *         # no iteration over empty files
 *         if not samfile.nreferences:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         # initialize iterator
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    __PYX_ERR(0, 2756, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2755
 * 
 *         # no iteration over empty files
 *         if not samfile.nreferences:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2759
 * 
 *         # initialize iterator
 *         self._setup_iterator(self.tid, 0, MAX_POS, 1)             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_t_4.__pyx_n = 1;
  __pyx_t_4.multiple_iterators = 1;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2750
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2761
 *         self._setup_iterator(self.tid, 0, MAX_POS, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self) {
  int __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2761, 0, __PYX_ERR(0, 2761, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2764
 * 
 *         cdef int n
 *         while 1:             # <<<<<<<<<<<<<<
 *             n = self.cnext()
 *             if n < 0:
 */
  while (1) {

    /* "pysam/libcalignmentfile.pyx":2765
 *         cdef int n
 *         while 1:
 *             n = self.cnext()             # <<<<<<<<<<<<<<
 *             if n < 0:
 *                 raise ValueError("error during iteration")
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2765, __pyx_L1_error)
    __pyx_v_n = __pyx_t_1;

    /* "pysam/libcalignmentfile.pyx":2766
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration")
 * 
 */
    __pyx_t_2 = (__pyx_v_n < 0);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":2767
 *             n = self.cnext()
 *             if n < 0:
 *                 raise ValueError("error during iteration")             # <<<<<<<<<<<<<<
 * 
 *             # proceed to next reference or stop
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__108, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2767, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 2767, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2766
 *         while 1:
 *             n = self.cnext()
 *             if n < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2770
 * 
 *             # proceed to next reference or stop
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:
 */
    __pyx_t_2 = (__pyx_v_n == 0);
    if (__pyx_t_2) {

      /* "pysam/libcalignmentfile.pyx":2771
 *             # proceed to next reference or stop
 *             if n == 0:
 *                 self.tid += 1             # <<<<<<<<<<<<<<
 *                 if self.tid < self.samfile.nreferences:
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)
 */
      __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1);

      /* "pysam/libcalignmentfile.pyx":2772
 *             if n == 0:
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)
 *                 else:
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2772, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2772, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_4, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2772, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2772, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (likely(__pyx_t_2)) {

        /* "pysam/libcalignmentfile.pyx":2773
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise StopIteration
 */
        __pyx_t_6.__pyx_n = 1;
        __pyx_t_6.multiple_iterators = 0;
        __pyx_t_5 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_17libcalignmentfile_MAX_POS, &__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2773, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "pysam/libcalignmentfile.pyx":2772
 *             if n == 0:
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)
 *                 else:
 */
        goto __pyx_L7;
      }

      /* "pysam/libcalignmentfile.pyx":2775
 *                     self._setup_iterator(self.tid, 0, MAX_POS, 0)
 *                 else:
 *                     raise StopIteration             # <<<<<<<<<<<<<<
 *                 continue
 * 
 */
      /*else*/ {
        __pyx_error_without_exception = 1;
        goto __pyx_L1_error;;
      }
      __pyx_L7:;

      /* "pysam/libcalignmentfile.pyx":2776
 *                 else:
 *                     raise StopIteration
 *                 continue             # <<<<<<<<<<<<<<
 * 
 *             # return result, if within same reference
 */
      goto __pyx_L3_continue;

      /* "pysam/libcalignmentfile.pyx":2770
 * 
 *             # proceed to next reference or stop
 *             if n == 0:             # <<<<<<<<<<<<<<
 *                 self.tid += 1
 *                 if self.tid < self.samfile.nreferences:
 */
    }

    /* "pysam/libcalignmentfile.pyx":2779
 * 
 *             # return result, if within same reference
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/libcalignmentfile.pyx":2785
 *                                     self.min_base_quality,
 *                                     self.iterdata.seq,
 *                                     self.samfile.header)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_5 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header);
    __Pyx_INCREF(__pyx_t_5);

    /* "pysam/libcalignmentfile.pyx":2779
 * 
 *             # return result, if within same reference
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                     self.tid,
 *                                     self.pos,
 */
    __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_5))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2779, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
    __pyx_L3_continue:;
  }

  /* "pysam/libcalignmentfile.pyx":2761
 *         self._setup_iterator(self.tid, 0, MAX_POS, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__, "IteratorColumnAllRefs.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__111)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__, "IteratorColumnAllRefs.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__112)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAllRefs.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2792
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2792, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 2792, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 2792, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2793, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll___cinit__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_kwargs);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_DECREF(__pyx_v_kwargs);
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll___cinit__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__cinit__", 1);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2792, 0, __PYX_ERR(0, 2792, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2796
 *                   **kwargs):
 * 
 *         self._setup_raw_rest_iterator()             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base._setup_raw_rest_iterator(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2792
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2798
 *         self._setup_raw_rest_iterator()
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_2__next__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_2__next__(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self) {
  int __pyx_v_n;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_error_without_exception = 0; /* StopIteration */
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__next__", 1);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2798, 0, __PYX_ERR(0, 2798, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2801
 * 
 *         cdef int n
 *         n = self.cnext()             # <<<<<<<<<<<<<<
 *         if n < 0:
 *             raise ValueError("error during iteration")
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)__pyx_v_self)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2801, __pyx_L1_error)
  __pyx_v_n = __pyx_t_1;

  /* "pysam/libcalignmentfile.pyx":2802
 *         cdef int n
 *         n = self.cnext()
 *         if n < 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("error during iteration")
 * 
 */
  __pyx_t_2 = (__pyx_v_n < 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2803
 *         n = self.cnext()
 *         if n < 0:
 *             raise ValueError("error during iteration")             # <<<<<<<<<<<<<<
 * 
 *         if n == 0:
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__108, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2803, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2803, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2802
 *         cdef int n
 *         n = self.cnext()
 *         if n < 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("error during iteration")
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2805
 *             raise ValueError("error during iteration")
 * 
 *         if n == 0:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_2 = (__pyx_v_n == 0);
  if (unlikely(__pyx_t_2)) {

    /* "pysam/libcalignmentfile.pyx":2806
 * 
 *         if n == 0:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         return makePileupColumn(&self.plp,
 */
    __pyx_error_without_exception = 1;
    goto __pyx_L1_error;;

    /* "pysam/libcalignmentfile.pyx":2805
 *             raise ValueError("error during iteration")
 * 
 *         if n == 0:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2808
 *             raise StopIteration
 * 
 *         return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                 self.tid,
 *                                 self.pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/libcalignmentfile.pyx":2814
 *                                 self.min_base_quality,
 *                                 self.iterdata.seq,
 *                                 self.samfile.header)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = ((PyObject *)__pyx_v_self->__pyx_base.samfile->header);
  __Pyx_INCREF(__pyx_t_3);

  /* "pysam/libcalignmentfile.pyx":2808
 *             raise StopIteration
 * 
 *         return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                 self.tid,
 *                                 self.pos,
 */
  __pyx_t_4 = ((PyObject *)__pyx_f_5pysam_18libcalignedsegment_makePileupColumn((&__pyx_v_self->__pyx_base.plp), __pyx_v_self->__pyx_base.tid, __pyx_v_self->__pyx_base.pos, __pyx_v_self->__pyx_base.n_plp, __pyx_v_self->__pyx_base.min_base_quality, __pyx_v_self->__pyx_base.iterdata.seq, ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_3))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2798
 *         self._setup_raw_rest_iterator()
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 * 
 *         cdef int n
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  if (!__pyx_error_without_exception) {
    __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  }
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__, "IteratorColumnAll.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__113)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__, "IteratorColumnAll.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__114)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IteratorColumnAll.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2830
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2830, 0, __PYX_ERR(0, 2830, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2831
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):
 *             return self._tid             # <<<<<<<<<<<<<<
 * 
 *     property pos:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2831, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2830
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._tid
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2835
 *     property pos:
 *        '''nucleotide position of SNP.'''
 *        def __get__(self): return self._pos             # <<<<<<<<<<<<<<
 * 
 *     property reference_base:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2835, 0, __PYX_ERR(0, 2835, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2835, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2839
 *     property reference_base:
 *        '''reference base at pos. ``N`` if no reference sequence supplied.'''
 *        def __get__(self): return from_string_and_size( &self._reference_base, 1 )             # <<<<<<<<<<<<<<
 * 
 *     property genotype:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_14reference_base___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2839, 0, __PYX_ERR(0, 2839, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2839, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.reference_base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2843
 *     property genotype:
 *        '''the genotype called.'''
 *        def __get__(self): return from_string_and_size( &self._genotype, 1 )             # <<<<<<<<<<<<<<
 * 
 *     property consensus_quality:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2843, 0, __PYX_ERR(0, 2843, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_9libcutils_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2843, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.genotype.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2847
 *     property consensus_quality:
 *        '''the genotype quality (Phred-scaled).'''
 *        def __get__(self): return self._consensus_quality             # <<<<<<<<<<<<<<
 * 
 *     property snp_quality:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2847, 0, __PYX_ERR(0, 2847, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2847, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.consensus_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2852
 *        '''the snp quality (Phred scaled) - probability of consensus being
 *        identical to reference sequence.'''
 *        def __get__(self): return self._snp_quality             # <<<<<<<<<<<<<<
 * 
 *     property mapping_quality:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_11snp_quality___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2852, 0, __PYX_ERR(0, 2852, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2852, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.snp_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2857
 *        '''the root mean square (rms) of the mapping quality of all reads
 *        involved in the call.'''
 *        def __get__(self): return self._rms_mapping_quality             # <<<<<<<<<<<<<<
 * 
 *     property coverage:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2857, 0, __PYX_ERR(0, 2857, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.mapping_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2861
 *     property coverage:
 *        '''coverage or read depth - the number of reads involved in the call.'''
 *        def __get__(self): return self._coverage             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 1);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2861, 0, __PYX_ERR(0, 2861, __pyx_L1_error));
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.coverage.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2863
 *        def __get__(self): return self._coverage
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join( map(str, (
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_1__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_1__str__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall___str__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 1);
  __Pyx_TraceCall("__str__", __pyx_f[0], 2863, 0, __PYX_ERR(0, 2863, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2865
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/libcalignmentfile.pyx":2866
 * 
 *         return "\t".join( map(str, (
 *                     self.tid,             # <<<<<<<<<<<<<<
 *                     self.pos,
 *                     self.reference_base,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tid); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/libcalignmentfile.pyx":2867
 *         return "\t".join( map(str, (
 *                     self.tid,
 *                     self.pos,             # <<<<<<<<<<<<<<
 *                     self.reference_base,
 *                     self.genotype,
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/libcalignmentfile.pyx":2868
 *                     self.tid,
 *                     self.pos,
 *                     self.reference_base,             # <<<<<<<<<<<<<<
 *                     self.genotype,
 *                     self.consensus_quality,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_base); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2868, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/libcalignmentfile.pyx":2869
 *                     self.pos,
 *                     self.reference_base,
 *                     self.genotype,             # <<<<<<<<<<<<<<
 *                     self.consensus_quality,
 *                     self.snp_quality,
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_genotype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2869, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/libcalignmentfile.pyx":2870
 *                     self.reference_base,
 *                     self.genotype,
 *                     self.consensus_quality,             # <<<<<<<<<<<<<<
 *                     self.snp_quality,
 *                     self.mapping_quality,
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_consensus_quality); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 2870, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/libcalignmentfile.pyx":2871
 *                     self.genotype,
 *                     self.consensus_quality,
 *                     self.snp_quality,             # <<<<<<<<<<<<<<
 *                     self.mapping_quality,
 *                     self.coverage ) ) )
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_snp_quality); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2871, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/libcalignmentfile.pyx":2872
 *                     self.consensus_quality,
 *                     self.snp_quality,
 *                     self.mapping_quality,             # <<<<<<<<<<<<<<
 *                     self.coverage ) ) )
 * 
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 2872, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/libcalignmentfile.pyx":2873
 *                     self.snp_quality,
 *                     self.mapping_quality,
 *                     self.coverage ) ) )             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_coverage); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/libcalignmentfile.pyx":2866
 * 
 *         return "\t".join( map(str, (
 *                     self.tid,             # <<<<<<<<<<<<<<
 *                     self.pos,
 *                     self.reference_base,
 */
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_3);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_5);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_6);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_7);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_8);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8)) __PYX_ERR(0, 2866, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;

  /* "pysam/libcalignmentfile.pyx":2865
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2865, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF((PyObject *)(&PyUnicode_Type));
  __Pyx_GIVEREF((PyObject *)(&PyUnicode_Type));
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)(&PyUnicode_Type)))) __PYX_ERR(0, 2865, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_9);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9)) __PYX_ERR(0, 2865, __pyx_L1_error);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2865, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyUnicode_Join(__pyx_kp_u__3, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2865, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "pysam/libcalignmentfile.pyx":2863
 *        def __get__(self): return self._coverage
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join( map(str, (
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__, "SNPCall.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_v_state = 0;
  PyObject *__pyx_v__dict = 0;
  int __pyx_v_use_setstate;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__115)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":5
 *     cdef object _dict
 *     cdef bint use_setstate
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)             # <<<<<<<<<<<<<<
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_char(__pyx_v_self->_genotype); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_4)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyInt_From_char(__pyx_v_self->_reference_base); if (unlikely(!__pyx_t_5)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_6)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_self->_tid); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1)) __PYX_ERR(3, 5, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_2);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2)) __PYX_ERR(3, 5, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_3);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3)) __PYX_ERR(3, 5, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4)) __PYX_ERR(3, 5, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_5);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5)) __PYX_ERR(3, 5, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_6);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6)) __PYX_ERR(3, 5, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_7);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7)) __PYX_ERR(3, 5, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_8);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8)) __PYX_ERR(3, 5, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;
  __pyx_v_state = ((PyObject*)__pyx_t_9);
  __pyx_t_9 = 0;

  /* "(tree fragment)":6
 *     cdef bint use_setstate
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)
 *     _dict = getattr(self, '__dict__', None)             # <<<<<<<<<<<<<<
 *     if _dict is not None:
 *         state += (_dict,)
 */
  __pyx_t_9 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_v__dict = __pyx_t_9;
  __pyx_t_9 = 0;

  /* "(tree fragment)":7
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
  __pyx_t_10 = (__pyx_v__dict != Py_None);
  if (__pyx_t_10) {

    /* "(tree fragment)":8
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:
 *         state += (_dict,)             # <<<<<<<<<<<<<<
 *         use_setstate = True
 *     else:
 */
    __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v__dict);
    __Pyx_GIVEREF(__pyx_v__dict);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v__dict)) __PYX_ERR(3, 8, __pyx_L1_error);
    __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 8, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_8));
    __pyx_t_8 = 0;

    /* "(tree fragment)":9
 *     if _dict is not None:
 *         state += (_dict,)
 *         use_setstate = True             # <<<<<<<<<<<<<<
 *     else:
 *         use_setstate = False
 */
    __pyx_v_use_setstate = 1;

    /* "(tree fragment)":7
 *     state = (self._consensus_quality, self._coverage, self._genotype, self._pos, self._reference_base, self._rms_mapping_quality, self._snp_quality, self._tid)
 *     _dict = getattr(self, '__dict__', None)
 *     if _dict is not None:             # <<<<<<<<<<<<<<
 *         state += (_dict,)
 *         use_setstate = True
 */
    goto __pyx_L3;
  }

  /* "(tree fragment)":11
 *         use_setstate = True
 *     else:
 *         use_setstate = False             # <<<<<<<<<<<<<<
 *     if use_setstate:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, None), state
 */
  /*else*/ {
    __pyx_v_use_setstate = 0;
  }
  __pyx_L3:;

  /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, None), state
 *     else:
 */
  if (__pyx_v_use_setstate) {

    /* "(tree fragment)":13
 *         use_setstate = False
 *     if use_setstate:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, None), state             # <<<<<<<<<<<<<<
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, state)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_pyx_unpickle_SNPCall); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))))) __PYX_ERR(3, 13, __pyx_L1_error);
    __Pyx_INCREF(__pyx_int_239452417);
    __Pyx_GIVEREF(__pyx_int_239452417);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_239452417)) __PYX_ERR(3, 13, __pyx_L1_error);
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, Py_None)) __PYX_ERR(3, 13, __pyx_L1_error);
    __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 13, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_8);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8)) __PYX_ERR(3, 13, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_9);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_9)) __PYX_ERR(3, 13, __pyx_L1_error);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_v_state)) __PYX_ERR(3, 13, __pyx_L1_error);
    __pyx_t_8 = 0;
    __pyx_t_9 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "(tree fragment)":12
 *     else:
 *         use_setstate = False
 *     if use_setstate:             # <<<<<<<<<<<<<<
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, None), state
 *     else:
 */
  }

  /* "(tree fragment)":15
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, None), state
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, state)             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_pyx_unpickle_SNPCall); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(3, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))));
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))))) __PYX_ERR(3, 15, __pyx_L1_error);
    __Pyx_INCREF(__pyx_int_239452417);
    __Pyx_GIVEREF(__pyx_int_239452417);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_int_239452417)) __PYX_ERR(3, 15, __pyx_L1_error);
    __Pyx_INCREF(__pyx_v_state);
    __Pyx_GIVEREF(__pyx_v_state);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_v_state)) __PYX_ERR(3, 15, __pyx_L1_error);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 15, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_7);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7)) __PYX_ERR(3, 15, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_9);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9)) __PYX_ERR(3, 15, __pyx_L1_error);
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;
    __pyx_r = __pyx_t_8;
    __pyx_t_8 = 0;
    goto __pyx_L0;
  }

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_state);
  __Pyx_XDECREF(__pyx_v__dict);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__, "SNPCall.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 16, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 16, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 16, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__116)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 16, 0, __PYX_ERR(3, 16, __pyx_L1_error));

  /* "(tree fragment)":17
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, state)
 * def __setstate_cython__(self, __pyx_state):
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)             # <<<<<<<<<<<<<<
 */
  if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_v___pyx_state))) __PYX_ERR(3, 17, __pyx_L1_error)
  __pyx_t_1 = __pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.SNPCall.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2898
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_multiple_iterators;
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[2] = {0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
  #endif
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_multiple_iterators,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_samfile)) != 0)) {
          (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2898, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_multiple_iterators);
          if (value) { values[1] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2898, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 2898, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)values[0]);
    if (values[1]) {
      __pyx_v_multiple_iterators = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_multiple_iterators == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2898, __pyx_L3_error)
    } else {
      __pyx_v_multiple_iterators = ((int)1);
    }
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 2898, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, 1, "samfile", 0))) __PYX_ERR(0, 2898, __pyx_L1_error)
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads___init__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  char *__pyx_v_cfilename;
  bam_hdr_t *__pyx_v_hdr;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  char *__pyx_t_3;
  htsFile *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 1);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2898, 0, __PYX_ERR(0, 2898, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2903
 *         # makes sure that samfile stays alive as long as this
 *         # object is alive.
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 *         cdef bam_hdr_t * hdr = NULL
 *         assert samfile.is_bam, "can only apply IndexReads on bam files"
 */
  __Pyx_INCREF((PyObject *)__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_v_samfile);
  __Pyx_GOTREF((PyObject *)__pyx_v_self->samfile);
  __Pyx_DECREF((PyObject *)__pyx_v_self->samfile);
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/libcalignmentfile.pyx":2904
 *         # object is alive.
 *         self.samfile = samfile
 *         cdef bam_hdr_t * hdr = NULL             # <<<<<<<<<<<<<<
 *         assert samfile.is_bam, "can only apply IndexReads on bam files"
 * 
 */
  __pyx_v_hdr = NULL;

  /* "pysam/libcalignmentfile.pyx":2905
 *         self.samfile = samfile
 *         cdef bam_hdr_t * hdr = NULL
 *         assert samfile.is_bam, "can only apply IndexReads on bam files"             # <<<<<<<<<<<<<<
 * 
 *         # multiple_iterators the file - note that this makes the iterator
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(__pyx_assertions_enabled())) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_is_bam); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2905, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2905, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(!__pyx_t_2)) {
      __Pyx_Raise(__pyx_builtin_AssertionError, __pyx_kp_u_can_only_apply_IndexReads_on_bam, 0, 0);
      __PYX_ERR(0, 2905, __pyx_L1_error)
    }
  }
  #else
  if ((1)); else __PYX_ERR(0, 2905, __pyx_L1_error)
  #endif

  /* "pysam/libcalignmentfile.pyx":2909
 *         # multiple_iterators the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 *             cfilename = samfile.filename
 *             with nogil:
 */
  __pyx_t_2 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_2) {

    /* "pysam/libcalignmentfile.pyx":2910
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:
 *             cfilename = samfile.filename             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 */
    __pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_samfile->__pyx_base.filename); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(0, 2910, __pyx_L1_error)
    __pyx_v_cfilename = __pyx_t_3;

    /* "pysam/libcalignmentfile.pyx":2911
 *         if multiple_iterators:
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2912
 *             cfilename = samfile.filename
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')             # <<<<<<<<<<<<<<
 *             if self.htsfile == NULL:
 *                 raise OSError("unable to reopen htsfile")
 */
          __pyx_v_self->htsfile = hts_open(__pyx_v_cfilename, ((char const *)"r"));
        }

        /* "pysam/libcalignmentfile.pyx":2911
 *         if multiple_iterators:
 *             cfilename = samfile.filename
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L6;
          }
          __pyx_L6:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2913
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to reopen htsfile")
 * 
 */
    __pyx_t_2 = (__pyx_v_self->htsfile == NULL);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":2914
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 *                 raise OSError("unable to reopen htsfile")             # <<<<<<<<<<<<<<
 * 
 *             # need to advance in newly opened file to position after header
 */
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__117, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2914, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 2914, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2913
 *             with nogil:
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to reopen htsfile")
 * 
 */
    }

    /* "pysam/libcalignmentfile.pyx":2918
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2919
 *             # better: use seek/tell?
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             if hdr == NULL:
 *                 raise OSError("unable to read header information")
 */
          __pyx_v_hdr = sam_hdr_read(__pyx_v_self->htsfile);
        }

        /* "pysam/libcalignmentfile.pyx":2918
 *             # need to advance in newly opened file to position after header
 *             # better: use seek/tell?
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L10;
          }
          __pyx_L10:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2920
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    __pyx_t_2 = (__pyx_v_hdr == NULL);
    if (unlikely(__pyx_t_2)) {

      /* "pysam/libcalignmentfile.pyx":2921
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:
 *                 raise OSError("unable to read header information")             # <<<<<<<<<<<<<<
 *             self.header = makeAlignmentHeader(hdr)
 *             self.owns_samfile = True
 */
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2921, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __PYX_ERR(0, 2921, __pyx_L1_error)

      /* "pysam/libcalignmentfile.pyx":2920
 *             with nogil:
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr == NULL:             # <<<<<<<<<<<<<<
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 */
    }

    /* "pysam/libcalignmentfile.pyx":2922
 *             if hdr == NULL:
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)             # <<<<<<<<<<<<<<
 *             self.owns_samfile = True
 *         else:
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_17libcalignmentfile_makeAlignmentHeader(__pyx_v_hdr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2922, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
    __Pyx_DECREF((PyObject *)__pyx_v_self->header);
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":2923
 *                 raise OSError("unable to read header information")
 *             self.header = makeAlignmentHeader(hdr)
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 *         else:
 *             self.htsfile = self.samfile.htsfile
 */
    __pyx_v_self->owns_samfile = 1;

    /* "pysam/libcalignmentfile.pyx":2909
 *         # multiple_iterators the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 *             cfilename = samfile.filename
 *             with nogil:
 */
    goto __pyx_L3;
  }

  /* "pysam/libcalignmentfile.pyx":2925
 *             self.owns_samfile = True
 *         else:
 *             self.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.header = samfile.header
 *             self.owns_samfile = False
 */
  /*else*/ {
    __pyx_t_4 = __pyx_v_self->samfile->__pyx_base.htsfile;
    __pyx_v_self->htsfile = __pyx_t_4;

    /* "pysam/libcalignmentfile.pyx":2926
 *         else:
 *             self.htsfile = self.samfile.htsfile
 *             self.header = samfile.header             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 * 
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_samfile->header);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_GOTREF((PyObject *)__pyx_v_self->header);
    __Pyx_DECREF((PyObject *)__pyx_v_self->header);
    __pyx_v_self->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/libcalignmentfile.pyx":2927
 *             self.htsfile = self.samfile.htsfile
 *             self.header = samfile.header
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 * 
 *     def build(self):
 */
    __pyx_v_self->owns_samfile = 0;
  }
  __pyx_L3:;

  /* "pysam/libcalignmentfile.pyx":2898
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         cdef char *cfilename
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2929
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build the index.'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_3build(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_2build, "IndexedReads.build(self)\nbuild the index.");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_3build = {"build", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_3build, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_2build};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_3build(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("build (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("build", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "build", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_2build(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self) {
  int __pyx_v_ret;
  bam1_t *__pyx_v_b;
  uint64_t __pyx_v_pos;
  bam_hdr_t *__pyx_v_hdr;
  PyObject *__pyx_v_qname = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  unsigned int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  bam_hdr_t *__pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__118)
  __Pyx_RefNannySetupContext("build", 1);
  __Pyx_TraceCall("build", __pyx_f[0], 2929, 0, __PYX_ERR(0, 2929, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2932
 *         '''build the index.'''
 * 
 *         self.index = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 * 
 *         # this method will start indexing from the current file position
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2932, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2932, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, ((PyObject *)(&PyList_Type))};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2932, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->index);
  __Pyx_DECREF(__pyx_v_self->index);
  __pyx_v_self->index = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/libcalignmentfile.pyx":2935
 * 
 *         # this method will start indexing from the current file position
 *         cdef int ret = 1             # <<<<<<<<<<<<<<
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:
 */
  __pyx_v_ret = 1;

  /* "pysam/libcalignmentfile.pyx":2936
 *         # this method will start indexing from the current file position
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))             # <<<<<<<<<<<<<<
 *         if b == NULL:
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))
 */
  __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/libcalignmentfile.pyx":2937
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))
 * 
 */
  __pyx_t_5 = (__pyx_v_b == NULL);
  if (unlikely(__pyx_t_5)) {

    /* "pysam/libcalignmentfile.pyx":2938
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))             # <<<<<<<<<<<<<<
 * 
 *         cdef uint64_t pos
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_could_not_allocate_bytes, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2938, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyInt_FromSize_t((sizeof(bam1_t))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2938, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = NULL;
    __pyx_t_4 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_4 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_2};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2938, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_MemoryError, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2938, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 2938, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2937
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 *         if b == NULL:             # <<<<<<<<<<<<<<
 *             raise MemoryError("could not allocate {} bytes".format(sizeof(bam1_t)))
 * 
 */
  }

  /* "pysam/libcalignmentfile.pyx":2941
 * 
 *         cdef uint64_t pos
 *         cdef bam_hdr_t * hdr = self.header.ptr             # <<<<<<<<<<<<<<
 * 
 *         while ret > 0:
 */
  __pyx_t_7 = __pyx_v_self->header->ptr;
  __pyx_v_hdr = __pyx_t_7;

  /* "pysam/libcalignmentfile.pyx":2943
 *         cdef bam_hdr_t * hdr = self.header.ptr
 * 
 *         while ret > 0:             # <<<<<<<<<<<<<<
 *             with nogil:
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 */
  while (1) {
    __pyx_t_5 = (__pyx_v_ret > 0);
    if (!__pyx_t_5) break;

    /* "pysam/libcalignmentfile.pyx":2944
 * 
 *         while ret > 0:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *                 ret = sam_read1(self.htsfile,
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        _save = NULL;
        Py_UNBLOCK_THREADS
        __Pyx_FastGIL_Remember();
        #endif
        /*try:*/ {

          /* "pysam/libcalignmentfile.pyx":2945
 *         while ret > 0:
 *             with nogil:
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))             # <<<<<<<<<<<<<<
 *                 ret = sam_read1(self.htsfile,
 *                                 hdr,
 */
          __pyx_v_pos = bgzf_tell(hts_get_bgzfp(__pyx_v_self->htsfile));

          /* "pysam/libcalignmentfile.pyx":2946
 *             with nogil:
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *                 ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                                 hdr,
 *                                 b)
 */
          __pyx_v_ret = sam_read1(__pyx_v_self->htsfile, __pyx_v_hdr, __pyx_v_b);
        }

        /* "pysam/libcalignmentfile.pyx":2944
 * 
 *         while ret > 0:
 *             with nogil:             # <<<<<<<<<<<<<<
 *                 pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *                 ret = sam_read1(self.htsfile,
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            __Pyx_FastGIL_Forget();
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L10;
          }
          __pyx_L10:;
        }
    }

    /* "pysam/libcalignmentfile.pyx":2950
 *                                 b)
 * 
 *             if ret > 0:             # <<<<<<<<<<<<<<
 *                 qname = charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)
 */
    __pyx_t_5 = (__pyx_v_ret > 0);
    if (__pyx_t_5) {

      /* "pysam/libcalignmentfile.pyx":2951
 * 
 *             if ret > 0:
 *                 qname = charptr_to_str(pysam_bam_get_qname(b))             # <<<<<<<<<<<<<<
 *                 self.index[qname].append(pos)
 * 
 */
      __pyx_t_3 = __pyx_f_5pysam_9libcutils_charptr_to_str(pysam_bam_get_qname(__pyx_v_b), NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2951, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_qname, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/libcalignmentfile.pyx":2952
 *             if ret > 0:
 *                 qname = charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)             # <<<<<<<<<<<<<<
 * 
 *         bam_destroy1(b)
 */
      __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2952, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = __Pyx_PyInt_From_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2952, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_t_1); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 2952, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/libcalignmentfile.pyx":2950
 *                                 b)
 * 
 *             if ret > 0:             # <<<<<<<<<<<<<<
 *                 qname = charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)
 */
    }
  }

  /* "pysam/libcalignmentfile.pyx":2954
 *                 self.index[qname].append(pos)
 * 
 *         bam_destroy1(b)             # <<<<<<<<<<<<<<
 * 
 *     def find(self, query_name):
 */
  bam_destroy1(__pyx_v_b);

  /* "pysam/libcalignmentfile.pyx":2929
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build the index.'''
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.build", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qname);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2956
 *         bam_destroy1(b)
 * 
 *     def find(self, query_name):             # <<<<<<<<<<<<<<
 *         '''find `query_name` in index.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_4find, "IndexedReads.find(self, query_name)\nfind `query_name` in index.\n\n        Returns\n        -------\n\n        IteratorRowSelection\n            Returns an iterator over all reads with query_name.\n\n        Raises\n        ------\n\n        KeyError\n            if the `query_name` is not in the index.\n\n        ");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_5find = {"find", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_4find};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v_query_name = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("find (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_query_name,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_query_name)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2956, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "find") < 0)) __PYX_ERR(0, 2956, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v_query_name = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("find", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 2956, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self), __pyx_v_query_name);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_4find(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_query_name) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__119)
  __Pyx_RefNannySetupContext("find", 1);
  __Pyx_TraceCall("find", __pyx_f[0], 2956, 0, __PYX_ERR(0, 2956, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2972
 * 
 *         '''
 *         if query_name in self.index:             # <<<<<<<<<<<<<<
 *             return IteratorRowSelection(
 *                 self.samfile,
 */
  __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_query_name, __pyx_v_self->index, Py_EQ)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 2972, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "pysam/libcalignmentfile.pyx":2973
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/libcalignmentfile.pyx":2975
 *             return IteratorRowSelection(
 *                 self.samfile,
 *                 self.index[query_name],             # <<<<<<<<<<<<<<
 *                 multiple_iterators = False)
 *         else:
 */
    __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_self->index, __pyx_v_query_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2975, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "pysam/libcalignmentfile.pyx":2973
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2973, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF((PyObject *)__pyx_v_self->samfile);
    __Pyx_GIVEREF((PyObject *)__pyx_v_self->samfile);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self->samfile))) __PYX_ERR(0, 2973, __pyx_L1_error);
    __Pyx_GIVEREF(__pyx_t_2);
    if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2)) __PYX_ERR(0, 2973, __pyx_L1_error);
    __pyx_t_2 = 0;

    /* "pysam/libcalignmentfile.pyx":2976
 *                 self.samfile,
 *                 self.index[query_name],
 *                 multiple_iterators = False)             # <<<<<<<<<<<<<<
 *         else:
 *             raise KeyError("read %s not found" % query_name)
 */
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2976, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, Py_False) < 0) __PYX_ERR(0, 2976, __pyx_L1_error)

    /* "pysam/libcalignmentfile.pyx":2973
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection), __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2973, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "pysam/libcalignmentfile.pyx":2972
 * 
 *         '''
 *         if query_name in self.index:             # <<<<<<<<<<<<<<
 *             return IteratorRowSelection(
 *                 self.samfile,
 */
  }

  /* "pysam/libcalignmentfile.pyx":2978
 *                 multiple_iterators = False)
 *         else:
 *             raise KeyError("read %s not found" % query_name)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  /*else*/ {
    __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_read_s_not_found, __pyx_v_query_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2978, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2978, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 2978, __pyx_L1_error)
  }

  /* "pysam/libcalignmentfile.pyx":2956
 *         bam_destroy1(b)
 * 
 *     def find(self, query_name):             # <<<<<<<<<<<<<<
 *         '''find `query_name` in index.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/libcalignmentfile.pyx":2980
 *             raise KeyError("read %s not found" % query_name)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */

/* Python wrapper */
static void __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self) {
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
  __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self) {
  __Pyx_TraceDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2980, 0, __PYX_ERR(0, 2980, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":2981
 * 
 *     def __dealloc__(self):
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 */
  __pyx_t_1 = (__pyx_v_self->owns_samfile != 0);
  if (__pyx_t_1) {

    /* "pysam/libcalignmentfile.pyx":2982
 *     def __dealloc__(self):
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 */
    (void)(hts_close(__pyx_v_self->htsfile));

    /* "pysam/libcalignmentfile.pyx":2981
 * 
 *     def __dealloc__(self):
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 */
  }

  /* "pysam/libcalignmentfile.pyx":2980
 *             raise KeyError("read %s not found" % query_name)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.libcalignmentfile.IndexedReads.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
}

/* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__, "IndexedReads.__reduce_cython__(self)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  if (unlikely(__pyx_nargs > 0)) {
    __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;}
  if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__120)
  __Pyx_RefNannySetupContext("__reduce_cython__", 1);
  __Pyx_TraceCall("__reduce_cython__", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":2
 * def __reduce_cython__(self):
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_htsfile_cannot_be_converted, 0, 0);
  __PYX_ERR(3, 2, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__, "IndexedReads.__setstate_cython__(self, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__(PyObject *__pyx_v_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[1] = {0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 3, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(3, 3, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 1)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
    }
    __pyx_v___pyx_state = values[0];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(3, 3, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__(((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)__pyx_v_self), __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__121)
  __Pyx_RefNannySetupContext("__setstate_cython__", 1);
  __Pyx_TraceCall("__setstate_cython__", __pyx_f[3], 3, 0, __PYX_ERR(3, 3, __pyx_L1_error));

  /* "(tree fragment)":4
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"             # <<<<<<<<<<<<<<
 */
  __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_self_htsfile_cannot_be_converted, 0, 0);
  __PYX_ERR(3, 4, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.libcalignmentfile.IndexedReads.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall, "__pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state)");
static PyMethodDef __pyx_mdef_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall = {"__pyx_unpickle_SNPCall", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall};
static PyObject *__pyx_pw_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  PyObject *__pyx_v___pyx_type = 0;
  long __pyx_v___pyx_checksum;
  PyObject *__pyx_v___pyx_state = 0;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyObject* values[3] = {0,0,0};
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__pyx_unpickle_SNPCall (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_type)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 1, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_checksum)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 1, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SNPCall", 1, 3, 3, 1); __PYX_ERR(3, 1, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[2]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(3, 1, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SNPCall", 1, 3, 3, 2); __PYX_ERR(3, 1, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__pyx_unpickle_SNPCall") < 0)) __PYX_ERR(3, 1, __pyx_L3_error)
      }
    } else if (unlikely(__pyx_nargs != 3)) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
      values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
      values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
    }
    __pyx_v___pyx_type = values[0];
    __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(3, 1, __pyx_L3_error)
    __pyx_v___pyx_state = values[2];
  }
  goto __pyx_L6_skip;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_SNPCall", 1, 3, 3, __pyx_nargs); __PYX_ERR(3, 1, __pyx_L3_error)
  __pyx_L6_skip:;
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("pysam.libcalignmentfile.__pyx_unpickle_SNPCall", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state);

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_17libcalignmentfile_4__pyx_unpickle_SNPCall(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_v___pyx_PickleError = 0;
  PyObject *__pyx_v___pyx_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  unsigned int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceFrameInit(__pyx_codeobj__122)
  __Pyx_RefNannySetupContext("__pyx_unpickle_SNPCall", 1);
  __Pyx_TraceCall("__pyx_unpickle_SNPCall", __pyx_f[3], 1, 0, __PYX_ERR(3, 1, __pyx_L1_error));

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xe45c101, 0x1134a9c, 0x50b2281):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum
 */
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_tuple__123, Py_NE)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(3, 4, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "(tree fragment)":5
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xe45c101, 0x1134a9c, 0x50b2281):
 *         from pickle import PickleError as __pyx_PickleError             # <<<<<<<<<<<<<<
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 */
    __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_n_s_PickleError);
    __Pyx_GIVEREF(__pyx_n_s_PickleError);
    if (__Pyx_PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_PickleError)) __PYX_ERR(3, 5, __pyx_L1_error);
    __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 5, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_1);
    __pyx_v___pyx_PickleError = __pyx_t_1;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "(tree fragment)":6
 *     if __pyx_checksum not in (0xe45c101, 0x1134a9c, 0x50b2281):
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum             # <<<<<<<<<<<<<<
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:
 */
    __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 6, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_v___pyx_PickleError, __pyx_t_1, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(3, 6, __pyx_L1_error)

    /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xe45c101, 0x1134a9c, 0x50b2281):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum
 */
  }

  /* "(tree fragment)":7
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum
 *     __pyx_result = SNPCall.__new__(__pyx_type)             # <<<<<<<<<<<<<<
 *     if __pyx_state is not None:
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_SNPCall), __pyx_n_s_new); if (unlikely(!__pyx_t_3)) __PYX_ERR(3, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  #if CYTHON_UNPACK_METHODS
  if (likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_5 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v___pyx_type};
    __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 7, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_v___pyx_result = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "(tree fragment)":8
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  __pyx_t_2 = (__pyx_v___pyx_state != Py_None);
  if (__pyx_t_2) {

    /* "(tree fragment)":9
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)             # <<<<<<<<<<<<<<
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 */
    if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_v___pyx_state))) __PYX_ERR(3, 9, __pyx_L1_error)
    __pyx_t_1 = __pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(((struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 9, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "(tree fragment)":8
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum
 *     __pyx_result = SNPCall.__new__(__pyx_type)
 *     if __pyx_state is not None:             # <<<<<<<<<<<<<<
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 */
  }

  /* "(tree fragment)":10
 *     if __pyx_state is not None:
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result             # <<<<<<<<<<<<<<
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v___pyx_result);
  __pyx_r = __pyx_v___pyx_result;
  goto __pyx_L0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.libcalignmentfile.__pyx_unpickle_SNPCall", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v___pyx_PickleError);
  __Pyx_XDECREF(__pyx_v___pyx_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "(tree fragment)":11
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 */

static PyObject *__pyx_f_5pysam_17libcalignmentfile___pyx_unpickle_SNPCall__set_state(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  char __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  unsigned int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_unpickle_SNPCall__set_state", 1);
  __Pyx_TraceCall("__pyx_unpickle_SNPCall__set_state", __pyx_f[3], 11, 0, __PYX_ERR(3, 11, __pyx_L1_error));

  /* "(tree fragment)":12
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]             # <<<<<<<<<<<<<<
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[8])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_consensus_quality = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_coverage = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_As_char(__pyx_t_1); if (unlikely((__pyx_t_3 == (char)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_genotype = __pyx_t_3;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_pos = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_As_char(__pyx_t_1); if (unlikely((__pyx_t_3 == (char)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_reference_base = __pyx_t_3;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_rms_mapping_quality = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_snp_quality = __pyx_t_2;
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(3, 12, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 7, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(3, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v___pyx_result->_tid = __pyx_t_2;

  /* "(tree fragment)":13
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[8])
 */
  if (unlikely(__pyx_v___pyx_state == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(3, 13, __pyx_L1_error)
  }
  __pyx_t_5 = __Pyx_PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(3, 13, __pyx_L1_error)
  __pyx_t_6 = (__pyx_t_5 > 8);
  if (__pyx_t_6) {
  } else {
    __pyx_t_4 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_6 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(3, 13, __pyx_L1_error)
  __pyx_t_4 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_4) {

    /* "(tree fragment)":14
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 *         __pyx_result.__dict__.update(__pyx_state[8])             # <<<<<<<<<<<<<<
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_update); if (unlikely(!__pyx_t_8)) __PYX_ERR(3, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (unlikely(__pyx_v___pyx_state == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(3, 14, __pyx_L1_error)
    }
    __pyx_t_7 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 8, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(3, 14, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = NULL;
    __pyx_t_10 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_10 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_7};
      __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_10, 1+__pyx_t_10);
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 14, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "(tree fragment)":13
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):             # <<<<<<<<<<<<<<
 *         __pyx_result.__dict__.update(__pyx_state[8])
 */
  }

  /* "(tree fragment)":11
 *         __pyx_unpickle_SNPCall__set_state(<SNPCall> __pyx_result, __pyx_state)
 *     return __pyx_result
 * cdef __pyx_unpickle_SNPCall__set_state(SNPCall __pyx_result, tuple __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_result._consensus_quality = __pyx_state[0]; __pyx_result._coverage = __pyx_state[1]; __pyx_result._genotype = __pyx_state[2]; __pyx_result._pos = __pyx_state[3]; __pyx_result._reference_base = __pyx_state[4]; __pyx_result._rms_mapping_quality = __pyx_state[5]; __pyx_result._snp_quality = __pyx_state[6]; __pyx_result._tid = __pyx_state[7]
 *     if len(__pyx_state) > 8 and hasattr(__pyx_result, '__dict__'):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.libcalignmentfile.__pyx_unpickle_SNPCall__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  #if CYTHON_COMPILING_IN_LIMITED_API
  allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc);
  o = alloc_func(t, 0);
  #else
  if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  #endif
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_1__cinit__(o, __pyx_empty_tuple, NULL) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && (!PyType_IS_GC(Py_TYPE(o)) || !__Pyx_PyObject_GC_IsFinalized(o))) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_13__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
  (*Py_TYPE(o)->tp_free)(o);
  #else
  {
    freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free);
    if (tp_free) tp_free(o);
  }
  #endif
}
static PyObject *__pyx_sq_item_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static int __pyx_mp_ass_subscript_5pysam_17libcalignmentfile_AlignmentHeader(PyObject *o, PyObject *i, PyObject *v) {
  if (v) {
    return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_35__setitem__(o, i, v);
  }
  else {
    __Pyx_TypeName o_type_name;
    o_type_name = __Pyx_PyType_GetName(Py_TYPE(o));
    PyErr_Format(PyExc_NotImplementedError,
      "Subscript deletion not supported by " __Pyx_FMT_TYPENAME, o_type_name);
    __Pyx_DECREF_TypeName(o_type_name);
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11nreferences_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_references(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_10references_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7lengths_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_AlignmentHeader[] = {
  {"_from_text_and_lengths", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_4_from_text_and_lengths},
  {"from_text", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_6from_text},
  {"from_dict", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_8from_dict},
  {"from_references", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_10from_references},
  {"copy", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_17copy, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_16copy},
  {"_build_sequence_section", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_18_build_sequence_section},
  {"to_dict", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_20to_dict},
  {"as_dict", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_22as_dict},
  {"get_reference_name", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_24get_reference_name},
  {"get_reference_length", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_26get_reference_length},
  {"is_valid_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_28is_valid_tid},
  {"get_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_30get_tid},
  {"items", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_39items, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_38items},
  {"iteritems", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_40iteritems},
  {"keys", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_43keys, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_42keys},
  {"values", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_45values, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_44values},
  {"get", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_47get, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_46get},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_52__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_54__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_AlignmentHeader[] = {
  {(char *)"nreferences", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_nreferences, 0, (char *)PyDoc_STR("int with the number of :term:`reference` sequences in the file.\n\n        This is a read-only attribute."), 0},
  {(char *)"references", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_references, 0, (char *)PyDoc_STR("tuple with the names of :term:`reference` sequences. This is a\n        read-only attribute"), 0},
  {(char *)"lengths", __pyx_getprop_5pysam_17libcalignmentfile_15AlignmentHeader_lengths, 0, (char *)PyDoc_STR("tuple of the lengths of the :term:`reference` sequences. This is a\n        read-only attribute. The lengths are in the same order as\n        :attr:`pysam.AlignmentFile.references`\n        "), 0},
  {0, 0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader},
  {Py_nb_bool, (void *)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__},
  {Py_sq_length, (void *)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__},
  {Py_sq_item, (void *)__pyx_sq_item_5pysam_17libcalignmentfile_AlignmentHeader},
  {Py_sq_contains, (void *)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__},
  {Py_mp_length, (void *)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__},
  {Py_mp_subscript, (void *)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__},
  {Py_mp_ass_subscript, (void *)__pyx_mp_ass_subscript_5pysam_17libcalignmentfile_AlignmentHeader},
  {Py_tp_str, (void *)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__},
  {Py_tp_doc, (void *)PyDoc_STR("AlignmentHeader()\nheader information for a :class:`AlignmentFile` object\n\n    Parameters\n    ----------\n    header_dict : dict\n        build header from a multi-level dictionary. The\n        first level are the four types ('HD', 'SQ', ...). The second\n        level are a list of lines, with each line being a list of\n        tag-value pairs. The header is constructed first from all the\n        defined fields, followed by user tags in alphabetical\n        order. Alternatively, an :class:`~pysam.AlignmentHeader`\n        object can be passed directly.\n\n    text : string\n        use the string provided as the header\n\n    reference_names : list\n        see reference_lengths\n\n    reference_lengths : list\n        build header from list of chromosome names and lengths.  By\n        default, 'SQ' and 'LN' tags will be added to the header\n        text. This option can be changed by unsetting the flag\n        `add_sq_text`.\n\n    add_sq_text : bool\n        do not add 'SQ' and 'LN' tags to header. This option permits\n        construction :term:`SAM` formatted files without a header.\n\n    ")},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_AlignmentHeader},
  {Py_tp_getset, (void *)__pyx_getsets_5pysam_17libcalignmentfile_AlignmentHeader},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader_spec = {
  "pysam.libcalignmentfile.AlignmentHeader",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE,
  __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader_slots,
};
#else

static PyNumberMethods __pyx_tp_as_number_AlignmentHeader = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_15__bool__, /*nb_bool*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000)
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  0, /*nb_index*/
  #if PY_VERSION_HEX >= 0x03050000
  0, /*nb_matrix_multiply*/
  #endif
  #if PY_VERSION_HEX >= 0x03050000
  0, /*nb_inplace_matrix_multiply*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_AlignmentHeader = {
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_5pysam_17libcalignmentfile_AlignmentHeader, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_51__contains__, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_AlignmentHeader = {
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_49__len__, /*mp_length*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_37__getitem__, /*mp_subscript*/
  __pyx_mp_ass_subscript_5pysam_17libcalignmentfile_AlignmentHeader, /*mp_ass_subscript*/
};

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_AlignmentHeader = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""AlignmentHeader", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number_AlignmentHeader, /*tp_as_number*/
  &__pyx_tp_as_sequence_AlignmentHeader, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_AlignmentHeader, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_33__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  PyDoc_STR("AlignmentHeader()\nheader information for a :class:`AlignmentFile` object\n\n    Parameters\n    ----------\n    header_dict : dict\n        build header from a multi-level dictionary. The\n        first level are the four types ('HD', 'SQ', ...). The second\n        level are a list of lines, with each line being a list of\n        tag-value pairs. The header is constructed first from all the\n        defined fields, followed by user tags in alphabetical\n        order. Alternatively, an :class:`~pysam.AlignmentHeader`\n        object can be passed directly.\n\n    text : string\n        use the string provided as the header\n\n    reference_names : list\n        see reference_lengths\n\n    reference_lengths : list\n        build header from list of chromosome names and lengths.  By\n        default, 'SQ' and 'LN' tags will be added to the header\n        text. This option can be changed by unsetting the flag\n        `add_sq_text`.\n\n    add_sq_text : bool\n        do not add 'SQ' and 'LN' tags to header. This option permits\n        construction :term:`SAM` formatted files without a header.\n\n    "), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_15AlignmentHeader_3__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_AlignmentHeader, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_AlignmentFile __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p;
  PyObject *o = __Pyx_PyType_GetSlot(__pyx_ptype_5pysam_10libchtslib_HTSFile, tp_new, newfunc)(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile;
  p->reference_filename = Py_None; Py_INCREF(Py_None);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_27__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->reference_filename);
  Py_CLEAR(p->header);
  #if PY_MAJOR_VERSION < 3
  if (!(__pyx_ptype_5pysam_10libchtslib_HTSFile) || PyType_IS_GC(__pyx_ptype_5pysam_10libchtslib_HTSFile)) PyObject_GC_Track(o);
  #else
  if (PyType_IS_GC(__pyx_ptype_5pysam_10libchtslib_HTSFile)) PyObject_GC_Track(o);
  #endif
  if (likely(__pyx_ptype_5pysam_10libchtslib_HTSFile)) __Pyx_PyType_GetSlot(__pyx_ptype_5pysam_10libchtslib_HTSFile, tp_dealloc, destructor)(o); else __Pyx_call_next_tp_dealloc(o, __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o;
  e = ((likely(__pyx_ptype_5pysam_10libchtslib_HTSFile)) ? ((__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_traverse) ? __pyx_ptype_5pysam_10libchtslib_HTSFile->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile)); if (e) return e;
  if (p->reference_filename) {
    e = (*v)(p->reference_filename, a); if (e) return e;
  }
  if (p->header) {
    e = (*v)(((PyObject *)p->header), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)o;
  if (likely(__pyx_ptype_5pysam_10libchtslib_HTSFile)) { if (__pyx_ptype_5pysam_10libchtslib_HTSFile->tp_clear) __pyx_ptype_5pysam_10libchtslib_HTSFile->tp_clear(o); } else __Pyx_call_next_tp_clear(o, __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile);
  tmp = ((PyObject*)p->reference_filename);
  p->reference_filename = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->header);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_mapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6mapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_8unmapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nocoordinate(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_12nocoordinate_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11nreferences_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_10references_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7lengths_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_4text_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_reference_filename(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_18reference_filename_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_6header_1__get__(o);
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_AlignmentFile[] = {
  {"has_index", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_3has_index, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_2has_index},
  {"check_index", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_5check_index, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_4check_index},
  {"_open", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_7_open, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_6_open},
  {"fetch", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_9fetch, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_8fetch},
  {"head", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_11head, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_10head},
  {"mate", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_13mate, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_12mate},
  {"pileup", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_15pileup, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_14pileup},
  {"count", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_17count, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_16count},
  {"count_coverage", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_18count_coverage},
  {"find_introns_slow", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_20find_introns_slow},
  {"find_introns", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_22find_introns},
  {"close", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_25close, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_24close},
  {"__enter__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_30__enter__},
  {"__exit__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_32__exit__},
  {"get_index_statistics", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_34get_index_statistics},
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__, METH_NOARGS|METH_COEXIST, 0},
  {"is_valid_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_40is_valid_tid},
  {"get_tid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_42get_tid},
  {"get_reference_name", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_44get_reference_name},
  {"get_reference_length", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_46get_reference_length},
  {"gettid", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_49gettid, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_48gettid},
  {"getrname", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_51getrname, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_50getrname},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_52__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_13AlignmentFile_54__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_AlignmentFile[] = {
  {(char *)"mapped", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_mapped, 0, (char *)PyDoc_STR("int with total number of mapped alignments according to the\n        statistics recorded in the index. This is a read-only\n        attribute.\n        (This will be 0 for a CRAM file indexed by a .crai index, as that\n        index format does not record these statistics.)\n        "), 0},
  {(char *)"unmapped", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_unmapped, 0, (char *)PyDoc_STR("int with total number of unmapped reads according to the statistics\n        recorded in the index. This number of reads includes the number of reads\n        without coordinates. This is a read-only attribute.\n        (This will be 0 for a CRAM file indexed by a .crai index, as that\n        index format does not record these statistics.)\n        "), 0},
  {(char *)"nocoordinate", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nocoordinate, 0, (char *)PyDoc_STR("int with total number of reads without coordinates according to the\n        statistics recorded in the index, i.e., the statistic printed for \"*\"\n        by the ``samtools idxstats`` command. This is a read-only attribute.\n        (This will be 0 for a CRAM file indexed by a .crai index, as that\n        index format does not record these statistics.)\n        "), 0},
  {(char *)"nreferences", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_nreferences, 0, (char *)PyDoc_STR("int with the number of :term:`reference` sequences in the file.\n        This is a read-only attribute."), 0},
  {(char *)"references", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_references, 0, (char *)PyDoc_STR("tuple with the names of :term:`reference` sequences. This is a\n        read-only attribute"), 0},
  {(char *)"lengths", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_lengths, 0, (char *)PyDoc_STR("tuple of the lengths of the :term:`reference` sequences. This is a\n        read-only attribute. The lengths are in the same order as\n        :attr:`pysam.AlignmentFile.references`\n\n        "), 0},
  {(char *)"text", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_text, 0, (char *)PyDoc_STR("deprecated, use :attr:`references` and :attr:`lengths` instead"), 0},
  {(char *)"reference_filename", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_reference_filename, 0, (char *)0, 0},
  {(char *)"header", __pyx_getprop_5pysam_17libcalignmentfile_13AlignmentFile_header, 0, (char *)0, 0},
  {0, 0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_AlignmentFile_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile},
  {Py_tp_doc, (void *)PyDoc_STR("AlignmentFile(filepath_or_object, mode=None, template=None,\n    reference_names=None, reference_lengths=None, text=NULL,\n    header=None, add_sq_text=False, check_header=True, check_sq=True,\n    reference_filename=None, filename=None, index_filename=None,\n    filepath_index=None, require_index=False, duplicate_filehandle=True,\n    ignore_truncation=False, threads=1)\n\n    A :term:`SAM`/:term:`BAM`/:term:`CRAM` formatted file.\n\n    If `filepath_or_object` is a string, the file is automatically\n    opened. If `filepath_or_object` is a python File object, the\n    already opened file will be used.\n\n    If the file is opened for reading and an index exists (if file is BAM, a\n    .bai file or if CRAM a .crai file), it will be opened automatically.\n    `index_filename` may be specified explicitly. If the index is not named\n    in the standard manner, not located in the same directory as the\n    BAM/CRAM file, or is remote.  Without an index, random access via\n    :meth:`~pysam.AlignmentFile.fetch` and :meth:`~pysam.AlignmentFile.pileup`\n    is disabled.\n\n    For writing, the header of a :term:`SAM` file/:term:`BAM` file can\n    be constituted from several sources (see also the samtools format\n    specification):\n\n        1. If `template` is given, the header is copied from another\n           `AlignmentFile` (`template` must be a\n           :class:`~pysam.AlignmentFile`).\n\n        2. If `header` is given, the header is built from a\n           multi-level dictionary.\n\n        3. If `text` is given, new header text is copied from raw\n           text.\n\n        4. The names (`reference_names`) and lengths\n           (`reference_lengths`) are supplied directly as lists.\n\n    When reading or writing a CRAM file, the filename of a FASTA-formatted\n    reference can be specified with `reference_filename`.\n\n    By default, if a file is opened in mode 'r', it is checked\n    for a valid header (`check_header` = True) and a definition of\n    chr""omosome names (`check_sq` = True).\n\n    Parameters\n    ----------\n    mode : string\n        `mode` should be ``r`` for reading or ``w`` for writing. The\n        default is text mode (:term:`SAM`). For binary (:term:`BAM`)\n        I/O you should append ``b`` for compressed or ``u`` for\n        uncompressed :term:`BAM` output.  Use ``h`` to output header\n        information in text (:term:`TAM`) mode. Use ``c`` for\n        :term:`CRAM` formatted files.\n\n        If ``b`` is present, it must immediately follow ``r`` or\n        ``w``.  Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``,\n        ``wbu``, ``wb0``, ``rc`` and ``wc``. For instance, to open a\n        :term:`BAM` formatted file for reading, type::\n\n           f = pysam.AlignmentFile('ex1.bam','rb')\n\n        If mode is not specified, the method will try to auto-detect\n        in the order 'rb', 'r', thus both the following should work::\n\n            f1 = pysam.AlignmentFile('ex1.bam')\n            f2 = pysam.AlignmentFile('ex1.sam')\n\n    template : AlignmentFile\n        when writing, copy header from file `template`.\n\n    header :  dict or AlignmentHeader\n        when writing, build header from a multi-level dictionary. The\n        first level are the four types ('HD', 'SQ', ...). The second\n        level are a list of lines, with each line being a list of\n        tag-value pairs. The header is constructed first from all the\n        defined fields, followed by user tags in alphabetical\n        order. Alternatively, an :class:`~pysam.AlignmentHeader`\n        object can be passed directly.\n\n    text : string\n        when writing, use the string provided as the header\n\n    reference_names : list\n        see reference_lengths\n\n    reference_lengths : list\n        when writing or opening a SAM file without header build header\n        from list of chromosome names and lengths.  By default, 'SQ'\n        and 'LN' tags will be added to the header text. This option\n        ""can be changed by unsetting the flag `add_sq_text`.\n\n    add_sq_text : bool\n        do not add 'SQ' and 'LN' tags to header. This option permits\n        construction :term:`SAM` formatted files without a header.\n\n    add_sam_header : bool\n        when outputting SAM the default is to output a header. This is\n        equivalent to opening the file in 'wh' mode. If this option is\n        set to False, no header will be output. To read such a file,\n        set `check_header=False`.\n\n    check_header : bool\n        obsolete: when reading a SAM file, check if header is present\n        (default=True)\n\n    check_sq : bool\n        when reading, check if SQ entries are present in header\n        (default=True)\n\n    reference_filename : string\n        Path to a FASTA-formatted reference file. Valid only for CRAM files.\n        When reading a CRAM file, this overrides both ``$REF_PATH`` and the URL\n        specified in the header (``UR`` tag), which are normally used to find\n        the reference.\n\n    index_filename : string\n        Explicit path to the index file.  Only needed if the index is not\n        named in the standard manner, not located in the same directory as\n        the BAM/CRAM file, or is remote.  An IOError is raised if the index\n        cannot be found or is invalid.\n\n    filepath_index : string\n        Alias for `index_filename`.\n\n    require_index : bool\n        When reading, require that an index file is present and is valid or\n        raise an IOError.  (default=False)\n\n    filename : string\n        Alternative to filepath_or_object. Filename of the file\n        to be opened.\n\n    duplicate_filehandle: bool\n        By default, file handles passed either directly or through\n        File-like objects will be duplicated before passing them to\n        htslib. The duplication prevents issues where the same stream\n        will be closed by htslib and through destruction of the\n        high-level python object. Set ""to False to turn off\n        duplication.\n\n    ignore_truncation: bool\n        Issue a warning, instead of raising an error if the current file\n        appears to be truncated due to a missing EOF marker.  Only applies\n        to bgzipped formats. (Default=False)\n\n    format_options: list\n        A list of key=value strings, as accepted by --input-fmt-option and\n        --output-fmt-option in samtools.\n    threads: integer\n        Number of threads to use for compressing/decompressing BAM/CRAM files.\n        Setting threads to > 1 cannot be combined with `ignore_truncation`.\n        (Default=1)\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile},
  {Py_tp_iter, (void *)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_AlignmentFile},
  {Py_tp_getset, (void *)__pyx_getsets_5pysam_17libcalignmentfile_AlignmentFile},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_AlignmentFile_spec = {
  "pysam.libcalignmentfile.AlignmentFile",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE,
  __pyx_type_5pysam_17libcalignmentfile_AlignmentFile_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_AlignmentFile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""AlignmentFile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_AlignmentFile, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/
  PyDoc_STR("AlignmentFile(filepath_or_object, mode=None, template=None,\n    reference_names=None, reference_lengths=None, text=NULL,\n    header=None, add_sq_text=False, check_header=True, check_sq=True,\n    reference_filename=None, filename=None, index_filename=None,\n    filepath_index=None, require_index=False, duplicate_filehandle=True,\n    ignore_truncation=False, threads=1)\n\n    A :term:`SAM`/:term:`BAM`/:term:`CRAM` formatted file.\n\n    If `filepath_or_object` is a string, the file is automatically\n    opened. If `filepath_or_object` is a python File object, the\n    already opened file will be used.\n\n    If the file is opened for reading and an index exists (if file is BAM, a\n    .bai file or if CRAM a .crai file), it will be opened automatically.\n    `index_filename` may be specified explicitly. If the index is not named\n    in the standard manner, not located in the same directory as the\n    BAM/CRAM file, or is remote.  Without an index, random access via\n    :meth:`~pysam.AlignmentFile.fetch` and :meth:`~pysam.AlignmentFile.pileup`\n    is disabled.\n\n    For writing, the header of a :term:`SAM` file/:term:`BAM` file can\n    be constituted from several sources (see also the samtools format\n    specification):\n\n        1. If `template` is given, the header is copied from another\n           `AlignmentFile` (`template` must be a\n           :class:`~pysam.AlignmentFile`).\n\n        2. If `header` is given, the header is built from a\n           multi-level dictionary.\n\n        3. If `text` is given, new header text is copied from raw\n           text.\n\n        4. The names (`reference_names`) and lengths\n           (`reference_lengths`) are supplied directly as lists.\n\n    When reading or writing a CRAM file, the filename of a FASTA-formatted\n    reference can be specified with `reference_filename`.\n\n    By default, if a file is opened in mode 'r', it is checked\n    for a valid header (`check_header` = True) and a definition of\n    chr""omosome names (`check_sq` = True).\n\n    Parameters\n    ----------\n    mode : string\n        `mode` should be ``r`` for reading or ``w`` for writing. The\n        default is text mode (:term:`SAM`). For binary (:term:`BAM`)\n        I/O you should append ``b`` for compressed or ``u`` for\n        uncompressed :term:`BAM` output.  Use ``h`` to output header\n        information in text (:term:`TAM`) mode. Use ``c`` for\n        :term:`CRAM` formatted files.\n\n        If ``b`` is present, it must immediately follow ``r`` or\n        ``w``.  Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``,\n        ``wbu``, ``wb0``, ``rc`` and ``wc``. For instance, to open a\n        :term:`BAM` formatted file for reading, type::\n\n           f = pysam.AlignmentFile('ex1.bam','rb')\n\n        If mode is not specified, the method will try to auto-detect\n        in the order 'rb', 'r', thus both the following should work::\n\n            f1 = pysam.AlignmentFile('ex1.bam')\n            f2 = pysam.AlignmentFile('ex1.sam')\n\n    template : AlignmentFile\n        when writing, copy header from file `template`.\n\n    header :  dict or AlignmentHeader\n        when writing, build header from a multi-level dictionary. The\n        first level are the four types ('HD', 'SQ', ...). The second\n        level are a list of lines, with each line being a list of\n        tag-value pairs. The header is constructed first from all the\n        defined fields, followed by user tags in alphabetical\n        order. Alternatively, an :class:`~pysam.AlignmentHeader`\n        object can be passed directly.\n\n    text : string\n        when writing, use the string provided as the header\n\n    reference_names : list\n        see reference_lengths\n\n    reference_lengths : list\n        when writing or opening a SAM file without header build header\n        from list of chromosome names and lengths.  By default, 'SQ'\n        and 'LN' tags will be added to the header text. This option\n        ""can be changed by unsetting the flag `add_sq_text`.\n\n    add_sq_text : bool\n        do not add 'SQ' and 'LN' tags to header. This option permits\n        construction :term:`SAM` formatted files without a header.\n\n    add_sam_header : bool\n        when outputting SAM the default is to output a header. This is\n        equivalent to opening the file in 'wh' mode. If this option is\n        set to False, no header will be output. To read such a file,\n        set `check_header=False`.\n\n    check_header : bool\n        obsolete: when reading a SAM file, check if header is present\n        (default=True)\n\n    check_sq : bool\n        when reading, check if SQ entries are present in header\n        (default=True)\n\n    reference_filename : string\n        Path to a FASTA-formatted reference file. Valid only for CRAM files.\n        When reading a CRAM file, this overrides both ``$REF_PATH`` and the URL\n        specified in the header (``UR`` tag), which are normally used to find\n        the reference.\n\n    index_filename : string\n        Explicit path to the index file.  Only needed if the index is not\n        named in the standard manner, not located in the same directory as\n        the BAM/CRAM file, or is remote.  An IOError is raised if the index\n        cannot be found or is invalid.\n\n    filepath_index : string\n        Alias for `index_filename`.\n\n    require_index : bool\n        When reading, require that an index file is present and is valid or\n        raise an IOError.  (default=False)\n\n    filename : string\n        Alternative to filepath_or_object. Filename of the file\n        to be opened.\n\n    duplicate_filehandle: bool\n        By default, file handles passed either directly or through\n        File-like objects will be duplicated before passing them to\n        htslib. The duplication prevents issues where the same stream\n        will be closed by htslib and through destruction of the\n        high-level python object. Set ""to False to turn off\n        duplication.\n\n    ignore_truncation: bool\n        Issue a warning, instead of raising an error if the current file\n        appears to be truncated due to a missing EOF marker.  Only applies\n        to bgzipped formats. (Default=False)\n\n    format_options: list\n        A list of key=value strings, as accepted by --input-fmt-option and\n        --output-fmt-option in samtools.\n    threads: integer\n        Number of threads to use for compressing/decompressing BAM/CRAM files.\n        Setting threads to > 1 cannot be combined with `ignore_truncation`.\n        (Default=1)\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_AlignmentFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_AlignmentFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_37__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_13AlignmentFile_39__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_AlignmentFile, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_AlignmentFile, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_AlignmentFile, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *p;
  PyObject *o;
  #if CYTHON_COMPILING_IN_LIMITED_API
  allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc);
  o = alloc_func(t, 0);
  #else
  if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  #endif
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_3__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->header);
  #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
  (*Py_TYPE(o)->tp_free)(o);
  #else
  {
    freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free);
    if (tp_free) tp_free(o);
  }
  #endif
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o;
  if (p->samfile) {
    e = (*v)(((PyObject *)p->samfile), a); if (e) return e;
  }
  if (p->header) {
    e = (*v)(((PyObject *)p->header), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->header);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRow[] = {
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_11IteratorRow_6__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorRow_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_doc, (void *)PyDoc_STR("IteratorRow(AlignmentFile samfile, int multiple_iterators=False)\nabstract base class for iterators over mapped reads.\n\n    Various iterators implement different behaviours for wrapping around\n    contig boundaries. Examples include:\n\n    :class:`pysam.IteratorRowRegion`\n        iterate within a single contig and a defined region.\n\n    :class:`pysam.IteratorRowAll`\n        iterate until EOF. This iterator will also include unmapped reads.\n\n    :class:`pysam.IteratorRowAllRefs`\n        iterate over all reads in all reference sequences.\n\n    The method :meth:`AlignmentFile.fetch` returns an IteratorRow.\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorRow_spec = {
  "pysam.libcalignmentfile.IteratorRow",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorRow_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRow = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorRow", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRow), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("IteratorRow(AlignmentFile samfile, int multiple_iterators=False)\nabstract base class for iterators over mapped reads.\n\n    Various iterators implement different behaviours for wrapping around\n    contig boundaries. Examples include:\n\n    :class:`pysam.IteratorRowRegion`\n        iterate within a single contig and a defined region.\n\n    :class:`pysam.IteratorRowAll`\n        iterate until EOF. This iterator will also include unmapped reads.\n\n    :class:`pysam.IteratorRowAllRefs`\n        iterate over all reads in all reference sequences.\n\n    The method :meth:`AlignmentFile.fetch` returns an IteratorRow.\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorRow, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_11IteratorRow_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowRegion __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion;
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowRegion(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowRegion) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_7__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow(o);
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowRegion[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_8__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorRowRegion_10__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowRegion},
  {Py_tp_doc, (void *)PyDoc_STR("IteratorRowRegion(AlignmentFile samfile, int tid, int beg, int stop, int multiple_iterators=False)\n*(AlignmentFile samfile, int tid, int beg, int stop,\n    int multiple_iterators=False)*\n\n    iterate over mapped reads in a region.\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_iter, (void *)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_3__iter__},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorRowRegion},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowRegion},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion_spec = {
  "pysam.libcalignmentfile.IteratorRowRegion",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorRowRegion", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowRegion, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("IteratorRowRegion(AlignmentFile samfile, int tid, int beg, int stop, int multiple_iterators=False)\n*(AlignmentFile samfile, int tid, int beg, int stop,\n    int multiple_iterators=False)*\n\n    iterate over mapped reads in a region.\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorRowRegion, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_17IteratorRowRegion_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowRegion, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowHead __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead;
  return o;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowHead[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_6__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_15IteratorRowHead_8__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead_slots[] = {
  {Py_tp_doc, (void *)PyDoc_STR("IteratorRowHead(AlignmentFile samfile, int n, int multiple_iterators=False)\n*(AlignmentFile samfile, n, int multiple_iterators=False)*\n\n    iterate over first n reads in `samfile`\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.head`.\n\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_iter, (void *)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_3__iter__},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorRowHead},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowHead},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead_spec = {
  "pysam.libcalignmentfile.IteratorRowHead",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowHead = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorRowHead", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("IteratorRowHead(AlignmentFile samfile, int n, int multiple_iterators=False)\n*(AlignmentFile samfile, n, int multiple_iterators=False)*\n\n    iterate over first n reads in `samfile`\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.head`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorRowHead, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_15IteratorRowHead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowHead, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowAll __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll;
  return o;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowAll[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_6__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorRowAll_8__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll_slots[] = {
  {Py_tp_doc, (void *)PyDoc_STR("IteratorRowAll(AlignmentFile samfile, int multiple_iterators=False)\n*(AlignmentFile samfile, int multiple_iterators=False)*\n\n    iterate over all reads in `samfile`\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow},
  {Py_tp_iter, (void *)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_3__iter__},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorRowAll},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAll},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll_spec = {
  "pysam.libcalignmentfile.IteratorRowAll",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowAll = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorRowAll", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("IteratorRowAll(AlignmentFile samfile, int multiple_iterators=False)\n*(AlignmentFile samfile, int multiple_iterators=False)*\n\n    iterate over all reads in `samfile`\n\n    .. note::\n\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorRowAll, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorRowAll_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAll, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o);
  p->rowiter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowAllRefs) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->rowiter);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o;
  e = __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow(o, v, a); if (e) return e;
  if (p->rowiter) {
    e = (*v)(((PyObject *)p->rowiter), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowAllRefs(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs *)o;
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow(o);
  tmp = ((PyObject*)p->rowiter);
  p->rowiter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowAllRefs[] = {
  {"nextiter", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_2nextiter},
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_8__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_18IteratorRowAllRefs_10__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowAllRefs},
  {Py_tp_doc, (void *)PyDoc_STR("IteratorRowAllRefs(AlignmentFile samfile, multiple_iterators=False)\niterates over all mapped reads by chaining iterators over each\n    reference\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowAllRefs},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowAllRefs},
  {Py_tp_iter, (void *)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_5__iter__},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorRowAllRefs},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAllRefs},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs_spec = {
  "pysam.libcalignmentfile.IteratorRowAllRefs",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorRowAllRefs", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("IteratorRowAllRefs(AlignmentFile samfile, multiple_iterators=False)\niterates over all mapped reads by chaining iterators over each\n    reference\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_5__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_7__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_18IteratorRowAllRefs_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowAllRefs, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorRowSelection __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection;
  p->positions = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowSelection(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowSelection) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->positions);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowSelection(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o;
  e = __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRow(o, v, a); if (e) return e;
  if (p->positions) {
    e = (*v)(p->positions, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowSelection(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *)o;
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRow(o);
  tmp = ((PyObject*)p->positions);
  p->positions = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorRowSelection[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_6__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorRowSelection_8__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowSelection},
  {Py_tp_doc, (void *)PyDoc_STR("IteratorRowSelection(AlignmentFile samfile, positions, int multiple_iterators=True)\n*(AlignmentFile samfile)*\n\n    iterate over reads in `samfile` at a given list of file positions.\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a :meth:`AlignmentFile.fetch`.\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowSelection},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowSelection},
  {Py_tp_iter, (void *)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_3__iter__},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorRowSelection},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowSelection},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection_spec = {
  "pysam.libcalignmentfile.IteratorRowSelection",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorRowSelection", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("IteratorRowSelection(AlignmentFile samfile, positions, int multiple_iterators=True)\n*(AlignmentFile samfile)*\n\n    iterate over reads in `samfile` at a given list of file positions.\n\n    .. note::\n        It is usually not necessary to create an object of this class\n        explicitly. It is returned as a result of call to a :meth:`AlignmentFile.fetch`.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_20IteratorRowSelection_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorRowSelection, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *p;
  PyObject *o;
  #if CYTHON_COMPILING_IN_LIMITED_API
  allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc);
  o = alloc_func(t, 0);
  #else
  if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  #endif
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  p->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)Py_None); Py_INCREF(Py_None);
  p->stepper = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_9__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->iter);
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->fastafile);
  Py_CLEAR(p->stepper);
  #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
  (*Py_TYPE(o)->tp_free)(o);
  #else
  {
    freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free);
    if (tp_free) tp_free(o);
  }
  #endif
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)o;
  if (p->iter) {
    e = (*v)(((PyObject *)p->iter), a); if (e) return e;
  }
  if (p->samfile) {
    e = (*v)(((PyObject *)p->samfile), a); if (e) return e;
  }
  if (p->fastafile) {
    e = (*v)(((PyObject *)p->fastafile), a); if (e) return e;
  }
  if (p->stepper) {
    e = (*v)(p->stepper, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *)o;
  tmp = ((PyObject*)p->iter);
  p->iter = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->fastafile);
  p->fastafile = ((struct __pyx_obj_5pysam_9libcfaidx_FastaFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->stepper);
  p->stepper = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_14IteratorColumn_seq_len(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7seq_len_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumn[] = {
  {"add_reference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_4add_reference},
  {"has_reference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_6has_reference},
  {"hasReference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_10hasReference},
  {"addReference", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_13addReference, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_12addReference},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_14__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_14IteratorColumn_16__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_IteratorColumn[] = {
  {(char *)"seq_len", __pyx_getprop_5pysam_17libcalignmentfile_14IteratorColumn_seq_len, 0, (char *)PyDoc_STR("current sequence length."), 0},
  {0, 0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorColumn_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_doc, (void *)PyDoc_STR("abstract base class for iterators over columns.\n\n    IteratorColumn objects wrap the pileup functionality of samtools.\n\n    For reasons of efficiency, the iterator points to the current\n    pileup buffer. The pileup buffer is updated at every iteration.\n    This might cause some unexpected behaviour. For example,\n    consider the conversion to a list::\n\n       f = AlignmentFile(\"file.bam\", \"rb\")\n       result = list(f.pileup())\n\n    Here, ``result`` will contain ``n`` objects of type\n    :class:`~pysam.PileupColumn` for ``n`` columns, but each object in\n    ``result`` will contain the same information.\n\n    The desired behaviour can be achieved by list comprehension::\n\n       result = [x.pileups() for x in f.pileup()]\n\n    ``result`` will be a list of ``n`` lists of objects of type\n    :class:`~pysam.PileupRead`.\n\n    If the iterator is associated with a :class:`~pysam.Fastafile`\n    using the :meth:`add_reference` method, then the iterator will\n    export the current sequence via the methods :meth:`get_sequence`\n    and :meth:`seq_len`.\n\n    See :class:`~AlignmentFile.pileup` for kwargs to the iterator.\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_iter, (void *)__pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_getset, (void *)__pyx_getsets_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorColumn_spec = {
  "pysam.libcalignmentfile.IteratorColumn",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumn_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumn = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorColumn", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("abstract base class for iterators over columns.\n\n    IteratorColumn objects wrap the pileup functionality of samtools.\n\n    For reasons of efficiency, the iterator points to the current\n    pileup buffer. The pileup buffer is updated at every iteration.\n    This might cause some unexpected behaviour. For example,\n    consider the conversion to a list::\n\n       f = AlignmentFile(\"file.bam\", \"rb\")\n       result = list(f.pileup())\n\n    Here, ``result`` will contain ``n`` objects of type\n    :class:`~pysam.PileupColumn` for ``n`` columns, but each object in\n    ``result`` will contain the same information.\n\n    The desired behaviour can be achieved by list comprehension::\n\n       result = [x.pileups() for x in f.pileup()]\n\n    ``result`` will be a list of ``n`` lists of objects of type\n    :class:`~pysam.PileupRead`.\n\n    If the iterator is associated with a :class:`~pysam.Fastafile`\n    using the :meth:`add_reference` method, then the iterator will\n    export the current sequence via the methods :meth:`get_sequence`\n    and :meth:`seq_len`.\n\n    See :class:`~AlignmentFile.pileup` for kwargs to the iterator.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorColumn, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_IteratorColumn, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnRegion __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion;
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnRegion[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_20IteratorColumnRegion_6__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion_slots[] = {
  {Py_tp_doc, (void *)PyDoc_STR("iterates over a region only.\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorColumnRegion},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnRegion},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion_spec = {
  "pysam.libcalignmentfile.IteratorColumnRegion",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorColumnRegion", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("iterates over a region only.\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY || 0
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_20IteratorColumnRegion_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnRegion, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnRegion, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAllRefs __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAllRefs[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_6__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs_slots[] = {
  {Py_tp_doc, (void *)PyDoc_STR("iterates over all columns by chaining iterators over each reference\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAllRefs},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAllRefs},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs_spec = {
  "pysam.libcalignmentfile.IteratorColumnAllRefs",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorColumnAllRefs", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("iterates over all columns by chaining iterators over each reference\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY || 0
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAllRefs, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAllRefs, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif
static struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumnAll __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAll;

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAll(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *p;
  PyObject *o = __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_17libcalignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll;
  if (unlikely(__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_1__cinit__(o, a, k) < 0)) goto bad;
  return o;
  bad:
  Py_DECREF(o); o = 0;
  return NULL;
}

static PyObject *__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(PyObject *self, CYTHON_UNUSED PyObject *arg) {
  PyObject *res = __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__(self);
  if (!res && !PyErr_Occurred()) { PyErr_SetNone(PyExc_StopIteration); }
  return res;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAll[] = {
  {"__next__", (PyCFunction)__pyx_specialmethod___pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__, METH_NOARGS|METH_COEXIST, 0},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_4__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_17IteratorColumnAll_6__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll_slots[] = {
  {Py_tp_doc, (void *)PyDoc_STR("iterates over all columns, without using an index\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn},
  {Py_tp_iternext, (void *)__pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAll},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAll},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll_spec = {
  "pysam.libcalignmentfile.IteratorColumnAll",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IteratorColumnAll", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumnAll), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IteratorColumn, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("iterates over all columns, without using an index\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY || 0
  __pyx_pw_5pysam_17libcalignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_17IteratorColumnAll_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IteratorColumnAll, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IteratorColumnAll, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_IndexedReads(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *p;
  PyObject *o;
  #if CYTHON_COMPILING_IN_LIMITED_API
  allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc);
  o = alloc_func(t, 0);
  #else
  if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  #endif
  p = ((struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)o);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->index = Py_None; Py_INCREF(Py_None);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_IndexedReads(PyObject *o) {
  struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)o;
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_IndexedReads) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1);
    __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_7__dealloc__(o);
    __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->index);
  Py_CLEAR(p->header);
  #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
  (*Py_TYPE(o)->tp_free)(o);
  #else
  {
    freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free);
    if (tp_free) tp_free(o);
  }
  #endif
}

static int __pyx_tp_traverse_5pysam_17libcalignmentfile_IndexedReads(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)o;
  if (p->samfile) {
    e = (*v)(((PyObject *)p->samfile), a); if (e) return e;
  }
  if (p->index) {
    e = (*v)(p->index, a); if (e) return e;
  }
  if (p->header) {
    e = (*v)(((PyObject *)p->header), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_17libcalignmentfile_IndexedReads(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->index);
  p->index = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->header);
  p->header = ((struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_IndexedReads[] = {
  {"build", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_3build, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_2build},
  {"find", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_5find, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_4find},
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_8__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_12IndexedReads_10__setstate_cython__},
  {0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_IndexedReads_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_IndexedReads},
  {Py_tp_doc, (void *)PyDoc_STR("IndexedReads(AlignmentFile samfile, int multiple_iterators=True)\nIndex a Sam/BAM-file by query name while keeping the\n    original sort order intact.\n\n    The index is kept in memory and can be substantial.\n\n    By default, the file is re-opened to avoid conflicts if multiple\n    operators work on the same file. Set `multiple_iterators` = False\n    to not re-open `samfile`.\n\n    Parameters\n    ----------\n\n    samfile : AlignmentFile\n        File to be indexed.\n\n    multiple_iterators : bool\n        Flag indicating whether the file should be reopened. Reopening prevents\n        existing iterators being affected by the indexing.\n\n    ")},
  {Py_tp_traverse, (void *)__pyx_tp_traverse_5pysam_17libcalignmentfile_IndexedReads},
  {Py_tp_clear, (void *)__pyx_tp_clear_5pysam_17libcalignmentfile_IndexedReads},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_IndexedReads},
  {Py_tp_init, (void *)__pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_IndexedReads},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_IndexedReads_spec = {
  "pysam.libcalignmentfile.IndexedReads",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
  __pyx_type_5pysam_17libcalignmentfile_IndexedReads_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_IndexedReads = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""IndexedReads", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_IndexedReads), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_IndexedReads, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  PyDoc_STR("IndexedReads(AlignmentFile samfile, int multiple_iterators=True)\nIndex a Sam/BAM-file by query name while keeping the\n    original sort order intact.\n\n    The index is kept in memory and can be substantial.\n\n    By default, the file is re-opened to avoid conflicts if multiple\n    operators work on the same file. Set `multiple_iterators` = False\n    to not re-open `samfile`.\n\n    Parameters\n    ----------\n\n    samfile : AlignmentFile\n        File to be indexed.\n\n    multiple_iterators : bool\n        Flag indicating whether the file should be reopened. Reopening prevents\n        existing iterators being affected by the indexing.\n\n    "), /*tp_doc*/
  __pyx_tp_traverse_5pysam_17libcalignmentfile_IndexedReads, /*tp_traverse*/
  __pyx_tp_clear_5pysam_17libcalignmentfile_IndexedReads, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_IndexedReads, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  __pyx_pw_5pysam_17libcalignmentfile_12IndexedReads_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_IndexedReads, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif

static PyObject *__pyx_tp_new_5pysam_17libcalignmentfile_SNPCall(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  #if CYTHON_COMPILING_IN_LIMITED_API
  allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc);
  o = alloc_func(t, 0);
  #else
  if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  #endif
  return o;
}

static void __pyx_tp_dealloc_5pysam_17libcalignmentfile_SNPCall(PyObject *o) {
  #if CYTHON_USE_TP_FINALIZE
  if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && (!PyType_IS_GC(Py_TYPE(o)) || !__Pyx_PyObject_GC_IsFinalized(o))) {
    if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_5pysam_17libcalignmentfile_SNPCall) {
      if (PyObject_CallFinalizerFromDealloc(o)) return;
    }
  }
  #endif
  #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
  (*Py_TYPE(o)->tp_free)(o);
  #else
  {
    freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free);
    if (tp_free) tp_free(o);
  }
  #endif
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3tid_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3pos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_reference_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_14reference_base_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_genotype(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8genotype_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_consensus_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_17consensus_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_snp_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_11snp_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_15mapping_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_coverage(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_8coverage_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_17libcalignmentfile_SNPCall[] = {
  {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_2__reduce_cython__},
  {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_5pysam_17libcalignmentfile_7SNPCall_4__setstate_cython__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_17libcalignmentfile_SNPCall[] = {
  {(char *)"tid", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_tid, 0, (char *)PyDoc_STR("the chromosome ID as is defined in the header"), 0},
  {(char *)"pos", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_pos, 0, (char *)PyDoc_STR("nucleotide position of SNP."), 0},
  {(char *)"reference_base", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_reference_base, 0, (char *)PyDoc_STR("reference base at pos. ``N`` if no reference sequence supplied."), 0},
  {(char *)"genotype", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_genotype, 0, (char *)PyDoc_STR("the genotype called."), 0},
  {(char *)"consensus_quality", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_consensus_quality, 0, (char *)PyDoc_STR("the genotype quality (Phred-scaled)."), 0},
  {(char *)"snp_quality", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_snp_quality, 0, (char *)PyDoc_STR("the snp quality (Phred scaled) - probability of consensus being\n       identical to reference sequence."), 0},
  {(char *)"mapping_quality", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_mapping_quality, 0, (char *)PyDoc_STR("the root mean square (rms) of the mapping quality of all reads\n       involved in the call."), 0},
  {(char *)"coverage", __pyx_getprop_5pysam_17libcalignmentfile_7SNPCall_coverage, 0, (char *)PyDoc_STR("coverage or read depth - the number of reads involved in the call."), 0},
  {0, 0, 0, 0, 0}
};
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_type_5pysam_17libcalignmentfile_SNPCall_slots[] = {
  {Py_tp_dealloc, (void *)__pyx_tp_dealloc_5pysam_17libcalignmentfile_SNPCall},
  {Py_tp_str, (void *)__pyx_pw_5pysam_17libcalignmentfile_7SNPCall_1__str__},
  {Py_tp_doc, (void *)PyDoc_STR("the results of a SNP call.")},
  {Py_tp_methods, (void *)__pyx_methods_5pysam_17libcalignmentfile_SNPCall},
  {Py_tp_getset, (void *)__pyx_getsets_5pysam_17libcalignmentfile_SNPCall},
  {Py_tp_new, (void *)__pyx_tp_new_5pysam_17libcalignmentfile_SNPCall},
  {0, 0},
};
static PyType_Spec __pyx_type_5pysam_17libcalignmentfile_SNPCall_spec = {
  "pysam.libcalignmentfile.SNPCall",
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall),
  0,
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE,
  __pyx_type_5pysam_17libcalignmentfile_SNPCall_slots,
};
#else

static PyTypeObject __pyx_type_5pysam_17libcalignmentfile_SNPCall = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.libcalignmentfile.""SNPCall", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_17libcalignmentfile_SNPCall), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_17libcalignmentfile_SNPCall, /*tp_dealloc*/
  #if PY_VERSION_HEX < 0x030800b4
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030800b4
  0, /*tp_vectorcall_offset*/
  #endif
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #endif
  #if PY_MAJOR_VERSION >= 3
  0, /*tp_as_async*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_17libcalignmentfile_7SNPCall_1__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  PyDoc_STR("the results of a SNP call."), /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_17libcalignmentfile_SNPCall, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_17libcalignmentfile_SNPCall, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  #if !CYTHON_USE_TYPE_SPECS
  0, /*tp_dictoffset*/
  #endif
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_17libcalignmentfile_SNPCall, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  #if CYTHON_USE_TP_FINALIZE
  0, /*tp_finalize*/
  #else
  NULL, /*tp_finalize*/
  #endif
  #endif
  #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
  0, /*tp_vectorcall*/
  #endif
  #if __PYX_NEED_TP_PRINT_SLOT == 1
  0, /*tp_print*/
  #endif
  #if PY_VERSION_HEX >= 0x030C0000
  0, /*tp_watched*/
  #endif
  #if PY_VERSION_HEX >= 0x030d00A4
  0, /*tp_versions_used*/
  #endif
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
  0, /*tp_pypy_flags*/
  #endif
};
#endif

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif
/* #### Code section: pystring_table ### */

static int __Pyx_CreateStringTabAndInitStrings(void) {
  __Pyx_StringTabEntry __pyx_string_tab[] = {
    {&__pyx_n_u_AH, __pyx_k_AH, sizeof(__pyx_k_AH), 0, 1, 0, 1},
    {&__pyx_n_u_AN, __pyx_k_AN, sizeof(__pyx_k_AN), 0, 1, 0, 1},
    {&__pyx_n_u_AS, __pyx_k_AS, sizeof(__pyx_k_AS), 0, 1, 0, 1},
    {&__pyx_kp_u_AlignedSegment_refers_to_referen, __pyx_k_AlignedSegment_refers_to_referen, sizeof(__pyx_k_AlignedSegment_refers_to_referen), 0, 1, 0, 0},
    {&__pyx_n_s_AlignmentFile, __pyx_k_AlignmentFile, sizeof(__pyx_k_AlignmentFile), 0, 0, 1, 1},
    {&__pyx_n_u_AlignmentFile, __pyx_k_AlignmentFile, sizeof(__pyx_k_AlignmentFile), 0, 1, 0, 1},
    {&__pyx_n_s_AlignmentFile___enter, __pyx_k_AlignmentFile___enter, sizeof(__pyx_k_AlignmentFile___enter), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile___exit, __pyx_k_AlignmentFile___exit, sizeof(__pyx_k_AlignmentFile___exit), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile___reduce_cython, __pyx_k_AlignmentFile___reduce_cython, sizeof(__pyx_k_AlignmentFile___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile___setstate_cython, __pyx_k_AlignmentFile___setstate_cython, sizeof(__pyx_k_AlignmentFile___setstate_cython), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile__open, __pyx_k_AlignmentFile__open, sizeof(__pyx_k_AlignmentFile__open), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_check_index, __pyx_k_AlignmentFile_check_index, sizeof(__pyx_k_AlignmentFile_check_index), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_close, __pyx_k_AlignmentFile_close, sizeof(__pyx_k_AlignmentFile_close), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_count, __pyx_k_AlignmentFile_count, sizeof(__pyx_k_AlignmentFile_count), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_count_coverage, __pyx_k_AlignmentFile_count_coverage, sizeof(__pyx_k_AlignmentFile_count_coverage), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_fetch, __pyx_k_AlignmentFile_fetch, sizeof(__pyx_k_AlignmentFile_fetch), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_find_introns, __pyx_k_AlignmentFile_find_introns, sizeof(__pyx_k_AlignmentFile_find_introns), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_find_introns_slow, __pyx_k_AlignmentFile_find_introns_slow, sizeof(__pyx_k_AlignmentFile_find_introns_slow), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_get_index_statisti, __pyx_k_AlignmentFile_get_index_statisti, sizeof(__pyx_k_AlignmentFile_get_index_statisti), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_get_reference_leng, __pyx_k_AlignmentFile_get_reference_leng, sizeof(__pyx_k_AlignmentFile_get_reference_leng), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_get_reference_name, __pyx_k_AlignmentFile_get_reference_name, sizeof(__pyx_k_AlignmentFile_get_reference_name), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_get_tid, __pyx_k_AlignmentFile_get_tid, sizeof(__pyx_k_AlignmentFile_get_tid), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_getrname, __pyx_k_AlignmentFile_getrname, sizeof(__pyx_k_AlignmentFile_getrname), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_gettid, __pyx_k_AlignmentFile_gettid, sizeof(__pyx_k_AlignmentFile_gettid), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_has_index, __pyx_k_AlignmentFile_has_index, sizeof(__pyx_k_AlignmentFile_has_index), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_head, __pyx_k_AlignmentFile_head, sizeof(__pyx_k_AlignmentFile_head), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_is_valid_tid, __pyx_k_AlignmentFile_is_valid_tid, sizeof(__pyx_k_AlignmentFile_is_valid_tid), 0, 0, 1, 1},
    {&__pyx_kp_u_AlignmentFile_mapped_only_availa, __pyx_k_AlignmentFile_mapped_only_availa, sizeof(__pyx_k_AlignmentFile_mapped_only_availa), 0, 1, 0, 0},
    {&__pyx_n_s_AlignmentFile_mate, __pyx_k_AlignmentFile_mate, sizeof(__pyx_k_AlignmentFile_mate), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_pileup, __pyx_k_AlignmentFile_pileup, sizeof(__pyx_k_AlignmentFile_pileup), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentFile_write, __pyx_k_AlignmentFile_write, sizeof(__pyx_k_AlignmentFile_write), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader, __pyx_k_AlignmentHeader, sizeof(__pyx_k_AlignmentHeader), 0, 0, 1, 1},
    {&__pyx_n_u_AlignmentHeader, __pyx_k_AlignmentHeader, sizeof(__pyx_k_AlignmentHeader), 0, 1, 0, 1},
    {&__pyx_n_s_AlignmentHeader___reduce_cython, __pyx_k_AlignmentHeader___reduce_cython, sizeof(__pyx_k_AlignmentHeader___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader___setstate_cytho, __pyx_k_AlignmentHeader___setstate_cytho, sizeof(__pyx_k_AlignmentHeader___setstate_cytho), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader__build_sequence, __pyx_k_AlignmentHeader__build_sequence, sizeof(__pyx_k_AlignmentHeader__build_sequence), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader__from_text_and_l, __pyx_k_AlignmentHeader__from_text_and_l, sizeof(__pyx_k_AlignmentHeader__from_text_and_l), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_as_dict, __pyx_k_AlignmentHeader_as_dict, sizeof(__pyx_k_AlignmentHeader_as_dict), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_copy, __pyx_k_AlignmentHeader_copy, sizeof(__pyx_k_AlignmentHeader_copy), 0, 0, 1, 1},
    {&__pyx_kp_u_AlignmentHeader_does_not_support, __pyx_k_AlignmentHeader_does_not_support, sizeof(__pyx_k_AlignmentHeader_does_not_support), 0, 1, 0, 0},
    {&__pyx_n_s_AlignmentHeader_from_dict, __pyx_k_AlignmentHeader_from_dict, sizeof(__pyx_k_AlignmentHeader_from_dict), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_from_references, __pyx_k_AlignmentHeader_from_references, sizeof(__pyx_k_AlignmentHeader_from_references), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_from_text, __pyx_k_AlignmentHeader_from_text, sizeof(__pyx_k_AlignmentHeader_from_text), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_get, __pyx_k_AlignmentHeader_get, sizeof(__pyx_k_AlignmentHeader_get), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_get_reference_le, __pyx_k_AlignmentHeader_get_reference_le, sizeof(__pyx_k_AlignmentHeader_get_reference_le), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_get_reference_na, __pyx_k_AlignmentHeader_get_reference_na, sizeof(__pyx_k_AlignmentHeader_get_reference_na), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_get_tid, __pyx_k_AlignmentHeader_get_tid, sizeof(__pyx_k_AlignmentHeader_get_tid), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_is_valid_tid, __pyx_k_AlignmentHeader_is_valid_tid, sizeof(__pyx_k_AlignmentHeader_is_valid_tid), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_items, __pyx_k_AlignmentHeader_items, sizeof(__pyx_k_AlignmentHeader_items), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_iteritems, __pyx_k_AlignmentHeader_iteritems, sizeof(__pyx_k_AlignmentHeader_iteritems), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_keys, __pyx_k_AlignmentHeader_keys, sizeof(__pyx_k_AlignmentHeader_keys), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_to_dict, __pyx_k_AlignmentHeader_to_dict, sizeof(__pyx_k_AlignmentHeader_to_dict), 0, 0, 1, 1},
    {&__pyx_n_s_AlignmentHeader_values, __pyx_k_AlignmentHeader_values, sizeof(__pyx_k_AlignmentHeader_values), 0, 0, 1, 1},
    {&__pyx_n_s_AssertionError, __pyx_k_AssertionError, sizeof(__pyx_k_AssertionError), 0, 0, 1, 1},
    {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
    {&__pyx_n_s_BAM_CREF_SKIP, __pyx_k_BAM_CREF_SKIP, sizeof(__pyx_k_BAM_CREF_SKIP), 0, 0, 1, 1},
    {&__pyx_n_u_BC, __pyx_k_BC, sizeof(__pyx_k_BC), 0, 1, 0, 1},
    {&__pyx_n_u_CL, __pyx_k_CL, sizeof(__pyx_k_CL), 0, 1, 0, 1},
    {&__pyx_n_u_CN, __pyx_k_CN, sizeof(__pyx_k_CN), 0, 1, 0, 1},
    {&__pyx_n_u_CO, __pyx_k_CO, sizeof(__pyx_k_CO), 0, 1, 0, 1},
    {&__pyx_kp_u_Cannot_add_extra_threads_when_ig, __pyx_k_Cannot_add_extra_threads_when_ig, sizeof(__pyx_k_Cannot_add_extra_threads_when_ig), 0, 1, 0, 0},
    {&__pyx_n_s_Counter, __pyx_k_Counter, sizeof(__pyx_k_Counter), 0, 0, 1, 1},
    {&__pyx_n_u_DS, __pyx_k_DS, sizeof(__pyx_k_DS), 0, 1, 0, 1},
    {&__pyx_n_u_DT, __pyx_k_DT, sizeof(__pyx_k_DT), 0, 1, 0, 1},
    {&__pyx_n_u_FO, __pyx_k_FO, sizeof(__pyx_k_FO), 0, 1, 0, 1},
    {&__pyx_n_u_GO, __pyx_k_GO, sizeof(__pyx_k_GO), 0, 1, 0, 1},
    {&__pyx_n_u_HD, __pyx_k_HD, sizeof(__pyx_k_HD), 0, 1, 0, 1},
    {&__pyx_n_u_ID, __pyx_k_ID, sizeof(__pyx_k_ID), 0, 1, 0, 1},
    {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1},
    {&__pyx_kp_u_I_O_operation_on_closed_file, __pyx_k_I_O_operation_on_closed_file, sizeof(__pyx_k_I_O_operation_on_closed_file), 0, 1, 0, 0},
    {&__pyx_n_s_ImportError, __pyx_k_ImportError, sizeof(__pyx_k_ImportError), 0, 0, 1, 1},
    {&__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_k_Incompatible_checksums_0x_x_vs_0, sizeof(__pyx_k_Incompatible_checksums_0x_x_vs_0), 0, 0, 1, 0},
    {&__pyx_n_s_IndexStats, __pyx_k_IndexStats, sizeof(__pyx_k_IndexStats), 0, 0, 1, 1},
    {&__pyx_n_u_IndexStats, __pyx_k_IndexStats, sizeof(__pyx_k_IndexStats), 0, 1, 0, 1},
    {&__pyx_n_s_IndexedReads, __pyx_k_IndexedReads, sizeof(__pyx_k_IndexedReads), 0, 0, 1, 1},
    {&__pyx_n_u_IndexedReads, __pyx_k_IndexedReads, sizeof(__pyx_k_IndexedReads), 0, 1, 0, 1},
    {&__pyx_n_s_IndexedReads___reduce_cython, __pyx_k_IndexedReads___reduce_cython, sizeof(__pyx_k_IndexedReads___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IndexedReads___setstate_cython, __pyx_k_IndexedReads___setstate_cython, sizeof(__pyx_k_IndexedReads___setstate_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IndexedReads_build, __pyx_k_IndexedReads_build, sizeof(__pyx_k_IndexedReads_build), 0, 0, 1, 1},
    {&__pyx_n_s_IndexedReads_find, __pyx_k_IndexedReads_find, sizeof(__pyx_k_IndexedReads_find), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumn, __pyx_k_IteratorColumn, sizeof(__pyx_k_IteratorColumn), 0, 0, 1, 1},
    {&__pyx_n_u_IteratorColumn, __pyx_k_IteratorColumn, sizeof(__pyx_k_IteratorColumn), 0, 1, 0, 1},
    {&__pyx_n_s_IteratorColumnAll, __pyx_k_IteratorColumnAll, sizeof(__pyx_k_IteratorColumnAll), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnAllRefs, __pyx_k_IteratorColumnAllRefs, sizeof(__pyx_k_IteratorColumnAllRefs), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnAllRefs___reduce_c, __pyx_k_IteratorColumnAllRefs___reduce_c, sizeof(__pyx_k_IteratorColumnAllRefs___reduce_c), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnAllRefs___setstate, __pyx_k_IteratorColumnAllRefs___setstate, sizeof(__pyx_k_IteratorColumnAllRefs___setstate), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnAll___reduce_cytho, __pyx_k_IteratorColumnAll___reduce_cytho, sizeof(__pyx_k_IteratorColumnAll___reduce_cytho), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnAll___setstate_cyt, __pyx_k_IteratorColumnAll___setstate_cyt, sizeof(__pyx_k_IteratorColumnAll___setstate_cyt), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnRegion, __pyx_k_IteratorColumnRegion, sizeof(__pyx_k_IteratorColumnRegion), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnRegion___reduce_cy, __pyx_k_IteratorColumnRegion___reduce_cy, sizeof(__pyx_k_IteratorColumnRegion___reduce_cy), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumnRegion___setstate, __pyx_k_IteratorColumnRegion___setstate, sizeof(__pyx_k_IteratorColumnRegion___setstate), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumn___reduce_cython, __pyx_k_IteratorColumn___reduce_cython, sizeof(__pyx_k_IteratorColumn___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumn___setstate_cython, __pyx_k_IteratorColumn___setstate_cython, sizeof(__pyx_k_IteratorColumn___setstate_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumn_addReference, __pyx_k_IteratorColumn_addReference, sizeof(__pyx_k_IteratorColumn_addReference), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumn_add_reference, __pyx_k_IteratorColumn_add_reference, sizeof(__pyx_k_IteratorColumn_add_reference), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumn_hasReference, __pyx_k_IteratorColumn_hasReference, sizeof(__pyx_k_IteratorColumn_hasReference), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorColumn_has_reference, __pyx_k_IteratorColumn_has_reference, sizeof(__pyx_k_IteratorColumn_has_reference), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRow, __pyx_k_IteratorRow, sizeof(__pyx_k_IteratorRow), 0, 0, 1, 1},
    {&__pyx_n_u_IteratorRow, __pyx_k_IteratorRow, sizeof(__pyx_k_IteratorRow), 0, 1, 0, 1},
    {&__pyx_n_s_IteratorRowAll, __pyx_k_IteratorRowAll, sizeof(__pyx_k_IteratorRowAll), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowAllRefs, __pyx_k_IteratorRowAllRefs, sizeof(__pyx_k_IteratorRowAllRefs), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowAllRefs___reduce_cyth, __pyx_k_IteratorRowAllRefs___reduce_cyth, sizeof(__pyx_k_IteratorRowAllRefs___reduce_cyth), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowAllRefs___setstate_cy, __pyx_k_IteratorRowAllRefs___setstate_cy, sizeof(__pyx_k_IteratorRowAllRefs___setstate_cy), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowAllRefs_nextiter, __pyx_k_IteratorRowAllRefs_nextiter, sizeof(__pyx_k_IteratorRowAllRefs_nextiter), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowAll___reduce_cython, __pyx_k_IteratorRowAll___reduce_cython, sizeof(__pyx_k_IteratorRowAll___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowAll___setstate_cython, __pyx_k_IteratorRowAll___setstate_cython, sizeof(__pyx_k_IteratorRowAll___setstate_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowHead, __pyx_k_IteratorRowHead, sizeof(__pyx_k_IteratorRowHead), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowHead___reduce_cython, __pyx_k_IteratorRowHead___reduce_cython, sizeof(__pyx_k_IteratorRowHead___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowHead___setstate_cytho, __pyx_k_IteratorRowHead___setstate_cytho, sizeof(__pyx_k_IteratorRowHead___setstate_cytho), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowRegion, __pyx_k_IteratorRowRegion, sizeof(__pyx_k_IteratorRowRegion), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowRegion___reduce_cytho, __pyx_k_IteratorRowRegion___reduce_cytho, sizeof(__pyx_k_IteratorRowRegion___reduce_cytho), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowRegion___setstate_cyt, __pyx_k_IteratorRowRegion___setstate_cyt, sizeof(__pyx_k_IteratorRowRegion___setstate_cyt), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowSelection, __pyx_k_IteratorRowSelection, sizeof(__pyx_k_IteratorRowSelection), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowSelection___reduce_cy, __pyx_k_IteratorRowSelection___reduce_cy, sizeof(__pyx_k_IteratorRowSelection___reduce_cy), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRowSelection___setstate, __pyx_k_IteratorRowSelection___setstate, sizeof(__pyx_k_IteratorRowSelection___setstate), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRow___reduce_cython, __pyx_k_IteratorRow___reduce_cython, sizeof(__pyx_k_IteratorRow___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_IteratorRow___setstate_cython, __pyx_k_IteratorRow___setstate_cython, sizeof(__pyx_k_IteratorRow___setstate_cython), 0, 0, 1, 1},
    {&__pyx_n_s_KNOWN_HEADER_FIELDS, __pyx_k_KNOWN_HEADER_FIELDS, sizeof(__pyx_k_KNOWN_HEADER_FIELDS), 0, 0, 1, 1},
    {&__pyx_n_u_KS, __pyx_k_KS, sizeof(__pyx_k_KS), 0, 1, 0, 1},
    {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
    {&__pyx_n_u_L, __pyx_k_L, sizeof(__pyx_k_L), 0, 1, 0, 1},
    {&__pyx_n_u_LB, __pyx_k_LB, sizeof(__pyx_k_LB), 0, 1, 0, 1},
    {&__pyx_n_u_LN, __pyx_k_LN, sizeof(__pyx_k_LN), 0, 1, 0, 1},
    {&__pyx_n_u_M5, __pyx_k_M5, sizeof(__pyx_k_M5), 0, 1, 0, 1},
    {&__pyx_n_s_Mapping, __pyx_k_Mapping, sizeof(__pyx_k_Mapping), 0, 0, 1, 1},
    {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
    {&__pyx_n_u_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 1, 0, 1},
    {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
    {&__pyx_n_s_OSError, __pyx_k_OSError, sizeof(__pyx_k_OSError), 0, 0, 1, 1},
    {&__pyx_n_s_OrderedDict, __pyx_k_OrderedDict, sizeof(__pyx_k_OrderedDict), 0, 0, 1, 1},
    {&__pyx_n_u_PG, __pyx_k_PG, sizeof(__pyx_k_PG), 0, 1, 0, 1},
    {&__pyx_n_u_PI, __pyx_k_PI, sizeof(__pyx_k_PI), 0, 1, 0, 1},
    {&__pyx_n_u_PL, __pyx_k_PL, sizeof(__pyx_k_PL), 0, 1, 0, 1},
    {&__pyx_n_u_PM, __pyx_k_PM, sizeof(__pyx_k_PM), 0, 1, 0, 1},
    {&__pyx_n_u_PN, __pyx_k_PN, sizeof(__pyx_k_PN), 0, 1, 0, 1},
    {&__pyx_n_u_PP, __pyx_k_PP, sizeof(__pyx_k_PP), 0, 1, 0, 1},
    {&__pyx_n_u_PU, __pyx_k_PU, sizeof(__pyx_k_PU), 0, 1, 0, 1},
    {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1},
    {&__pyx_n_u_RG, __pyx_k_RG, sizeof(__pyx_k_RG), 0, 1, 0, 1},
    {&__pyx_kp_u_Raw_iterator_set_up_without_regi, __pyx_k_Raw_iterator_set_up_without_regi, sizeof(__pyx_k_Raw_iterator_set_up_without_regi), 0, 1, 0, 0},
    {&__pyx_kp_u_SAM_file_does_not_have_a_valid_h, __pyx_k_SAM_file_does_not_have_a_valid_h, sizeof(__pyx_k_SAM_file_does_not_have_a_valid_h), 0, 1, 0, 0},
    {&__pyx_n_u_SM, __pyx_k_SM, sizeof(__pyx_k_SM), 0, 1, 0, 1},
    {&__pyx_n_u_SN, __pyx_k_SN, sizeof(__pyx_k_SN), 0, 1, 0, 1},
    {&__pyx_n_s_SNPCall, __pyx_k_SNPCall, sizeof(__pyx_k_SNPCall), 0, 0, 1, 1},
    {&__pyx_n_s_SNPCall___reduce_cython, __pyx_k_SNPCall___reduce_cython, sizeof(__pyx_k_SNPCall___reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_SNPCall___setstate_cython, __pyx_k_SNPCall___setstate_cython, sizeof(__pyx_k_SNPCall___setstate_cython), 0, 0, 1, 1},
    {&__pyx_n_u_SO, __pyx_k_SO, sizeof(__pyx_k_SO), 0, 1, 0, 1},
    {&__pyx_n_u_SP, __pyx_k_SP, sizeof(__pyx_k_SP), 0, 1, 0, 1},
    {&__pyx_kp_u_SQ, __pyx_k_SQ, sizeof(__pyx_k_SQ), 0, 1, 0, 0},
    {&__pyx_n_u_SQ_2, __pyx_k_SQ_2, sizeof(__pyx_k_SQ_2), 0, 1, 0, 1},
    {&__pyx_kp_u_SQ_SN_LN, __pyx_k_SQ_SN_LN, sizeof(__pyx_k_SQ_SN_LN), 0, 1, 0, 0},
    {&__pyx_n_u_SS, __pyx_k_SS, sizeof(__pyx_k_SS), 0, 1, 0, 1},
    {&__pyx_n_s_Sequence, __pyx_k_Sequence, sizeof(__pyx_k_Sequence), 0, 0, 1, 1},
    {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 0, 0, 1, 1},
    {&__pyx_n_s_StringIO, __pyx_k_StringIO, sizeof(__pyx_k_StringIO), 0, 0, 1, 1},
    {&__pyx_n_u_TP, __pyx_k_TP, sizeof(__pyx_k_TP), 0, 1, 0, 1},
    {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
    {&__pyx_n_u_UR, __pyx_k_UR, sizeof(__pyx_k_UR), 0, 1, 0, 1},
    {&__pyx_n_s_VALID_HEADERS, __pyx_k_VALID_HEADERS, sizeof(__pyx_k_VALID_HEADERS), 0, 0, 1, 1},
    {&__pyx_n_s_VALID_HEADER_ORDER, __pyx_k_VALID_HEADER_ORDER, sizeof(__pyx_k_VALID_HEADER_ORDER), 0, 0, 1, 1},
    {&__pyx_n_s_VALID_HEADER_TYPES, __pyx_k_VALID_HEADER_TYPES, sizeof(__pyx_k_VALID_HEADER_TYPES), 0, 0, 1, 1},
    {&__pyx_n_u_VN, __pyx_k_VN, sizeof(__pyx_k_VN), 0, 1, 0, 1},
    {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
    {&__pyx_kp_u__12, __pyx_k__12, sizeof(__pyx_k__12), 0, 1, 0, 0},
    {&__pyx_kp_u__124, __pyx_k__124, sizeof(__pyx_k__124), 0, 1, 0, 0},
    {&__pyx_n_s__125, __pyx_k__125, sizeof(__pyx_k__125), 0, 0, 1, 1},
    {&__pyx_kp_u__15, __pyx_k__15, sizeof(__pyx_k__15), 0, 1, 0, 0},
    {&__pyx_n_s__172, __pyx_k__172, sizeof(__pyx_k__172), 0, 0, 1, 1},
    {&__pyx_kp_u__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 1, 0, 0},
    {&__pyx_kp_u__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0, 0},
    {&__pyx_kp_u__20, __pyx_k__20, sizeof(__pyx_k__20), 0, 1, 0, 0},
    {&__pyx_kp_u__21, __pyx_k__21, sizeof(__pyx_k__21), 0, 1, 0, 0},
    {&__pyx_kp_u__22, __pyx_k__22, sizeof(__pyx_k__22), 0, 1, 0, 0},
    {&__pyx_kp_u__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 1, 0, 0},
    {&__pyx_kp_b__46, __pyx_k__46, sizeof(__pyx_k__46), 0, 0, 0, 0},
    {&__pyx_kp_u_access_from_StringIO_objects_not, __pyx_k_access_from_StringIO_objects_not, sizeof(__pyx_k_access_from_StringIO_objects_not), 0, 1, 0, 0},
    {&__pyx_n_s_addReference, __pyx_k_addReference, sizeof(__pyx_k_addReference), 0, 0, 1, 1},
    {&__pyx_n_s_add_hts_options, __pyx_k_add_hts_options, sizeof(__pyx_k_add_hts_options), 0, 0, 1, 1},
    {&__pyx_n_s_add_reference, __pyx_k_add_reference, sizeof(__pyx_k_add_reference), 0, 0, 1, 1},
    {&__pyx_n_s_add_sam_header, __pyx_k_add_sam_header, sizeof(__pyx_k_add_sam_header), 0, 0, 1, 1},
    {&__pyx_n_s_add_sq_text, __pyx_k_add_sq_text, sizeof(__pyx_k_add_sq_text), 0, 0, 1, 1},
    {&__pyx_n_u_adjust_capq_threshold, __pyx_k_adjust_capq_threshold, sizeof(__pyx_k_adjust_capq_threshold), 0, 1, 0, 1},
    {&__pyx_n_u_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 1, 0, 1},
    {&__pyx_n_s_all_2, __pyx_k_all_2, sizeof(__pyx_k_all_2), 0, 0, 1, 1},
    {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
    {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
    {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
    {&__pyx_n_s_as_dict, __pyx_k_as_dict, sizeof(__pyx_k_as_dict), 0, 0, 1, 1},
    {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1},
    {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
    {&__pyx_n_u_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 1, 0, 1},
    {&__pyx_n_s_base_position, __pyx_k_base_position, sizeof(__pyx_k_base_position), 0, 0, 1, 1},
    {&__pyx_n_s_beg, __pyx_k_beg, sizeof(__pyx_k_beg), 0, 0, 1, 1},
    {&__pyx_n_s_bfile_name, __pyx_k_bfile_name, sizeof(__pyx_k_bfile_name), 0, 0, 1, 1},
    {&__pyx_n_s_btext, __pyx_k_btext, sizeof(__pyx_k_btext), 0, 0, 1, 1},
    {&__pyx_n_s_build, __pyx_k_build, sizeof(__pyx_k_build), 0, 0, 1, 1},
    {&__pyx_n_s_build_header_line, __pyx_k_build_header_line, sizeof(__pyx_k_build_header_line), 0, 0, 1, 1},
    {&__pyx_n_s_build_sequence_section, __pyx_k_build_sequence_section, sizeof(__pyx_k_build_sequence_section), 0, 0, 1, 1},
    {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
    {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1},
    {&__pyx_kp_u_can_not_iterate_over_samfile_wit, __pyx_k_can_not_iterate_over_samfile_wit, sizeof(__pyx_k_can_not_iterate_over_samfile_wit), 0, 1, 0, 0},
    {&__pyx_kp_u_can_only_apply_IndexReads_on_bam, __pyx_k_can_only_apply_IndexReads_on_bam, sizeof(__pyx_k_can_only_apply_IndexReads_on_bam), 0, 1, 0, 0},
    {&__pyx_kp_u_cannot_create_AlignmentHeader_re, __pyx_k_cannot_create_AlignmentHeader_re, sizeof(__pyx_k_cannot_create_AlignmentHeader_re), 0, 1, 0, 0},
    {&__pyx_n_s_cfilename, __pyx_k_cfilename, sizeof(__pyx_k_cfilename), 0, 0, 1, 1},
    {&__pyx_n_s_check_header, __pyx_k_check_header, sizeof(__pyx_k_check_header), 0, 0, 1, 1},
    {&__pyx_n_s_check_index, __pyx_k_check_index, sizeof(__pyx_k_check_index), 0, 0, 1, 1},
    {&__pyx_n_s_check_sq, __pyx_k_check_sq, sizeof(__pyx_k_check_sq), 0, 0, 1, 1},
    {&__pyx_n_s_check_truncation, __pyx_k_check_truncation, sizeof(__pyx_k_check_truncation), 0, 0, 1, 1},
    {&__pyx_n_s_cigar, __pyx_k_cigar, sizeof(__pyx_k_cigar), 0, 0, 1, 1},
    {&__pyx_n_s_cigarstring, __pyx_k_cigarstring, sizeof(__pyx_k_cigarstring), 0, 0, 1, 1},
    {&__pyx_n_s_cigartuples, __pyx_k_cigartuples, sizeof(__pyx_k_cigartuples), 0, 0, 1, 1},
    {&__pyx_n_s_cindexname, __pyx_k_cindexname, sizeof(__pyx_k_cindexname), 0, 0, 1, 1},
    {&__pyx_n_s_class_getitem, __pyx_k_class_getitem, sizeof(__pyx_k_class_getitem), 0, 0, 1, 1},
    {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
    {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
    {&__pyx_n_s_closed, __pyx_k_closed, sizeof(__pyx_k_closed), 0, 0, 1, 1},
    {&__pyx_n_s_cls, __pyx_k_cls, sizeof(__pyx_k_cls), 0, 0, 1, 1},
    {&__pyx_n_s_cmode, __pyx_k_cmode, sizeof(__pyx_k_cmode), 0, 0, 1, 1},
    {&__pyx_n_s_code, __pyx_k_code, sizeof(__pyx_k_code), 0, 0, 1, 1},
    {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
    {&__pyx_n_s_collections_abc, __pyx_k_collections_abc, sizeof(__pyx_k_collections_abc), 0, 0, 1, 1},
    {&__pyx_n_u_compute_baq, __pyx_k_compute_baq, sizeof(__pyx_k_compute_baq), 0, 1, 0, 1},
    {&__pyx_n_s_consensus_quality, __pyx_k_consensus_quality, sizeof(__pyx_k_consensus_quality), 0, 0, 1, 1},
    {&__pyx_n_s_contains, __pyx_k_contains, sizeof(__pyx_k_contains), 0, 0, 1, 1},
    {&__pyx_n_s_contig, __pyx_k_contig, sizeof(__pyx_k_contig), 0, 0, 1, 1},
    {&__pyx_n_u_contig, __pyx_k_contig, sizeof(__pyx_k_contig), 0, 1, 0, 1},
    {&__pyx_n_s_contig_length, __pyx_k_contig_length, sizeof(__pyx_k_contig_length), 0, 0, 1, 1},
    {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
    {&__pyx_kp_u_could_not_allocate_bytes, __pyx_k_could_not_allocate_bytes, sizeof(__pyx_k_could_not_allocate_bytes), 0, 1, 0, 0},
    {&__pyx_kp_u_could_not_allocate_memory_of_siz, __pyx_k_could_not_allocate_memory_of_siz, sizeof(__pyx_k_could_not_allocate_memory_of_siz), 0, 1, 0, 0},
    {&__pyx_kp_u_could_not_create_header, __pyx_k_could_not_create_header, sizeof(__pyx_k_could_not_create_header), 0, 1, 0, 0},
    {&__pyx_kp_u_could_not_open_alignment_file, __pyx_k_could_not_open_alignment_file, sizeof(__pyx_k_could_not_open_alignment_file), 0, 1, 0, 0},
    {&__pyx_kp_u_could_not_open_alignment_file_2, __pyx_k_could_not_open_alignment_file_2, sizeof(__pyx_k_could_not_open_alignment_file_2), 0, 1, 0, 0},
    {&__pyx_kp_u_could_not_parse_header, __pyx_k_could_not_parse_header, sizeof(__pyx_k_could_not_parse_header), 0, 1, 0, 0},
    {&__pyx_n_s_count, __pyx_k_count, sizeof(__pyx_k_count), 0, 0, 1, 1},
    {&__pyx_n_s_count_a, __pyx_k_count_a, sizeof(__pyx_k_count_a), 0, 0, 1, 1},
    {&__pyx_n_s_count_c, __pyx_k_count_c, sizeof(__pyx_k_count_c), 0, 0, 1, 1},
    {&__pyx_n_s_count_coverage, __pyx_k_count_coverage, sizeof(__pyx_k_count_coverage), 0, 0, 1, 1},
    {&__pyx_n_s_count_g, __pyx_k_count_g, sizeof(__pyx_k_count_g), 0, 0, 1, 1},
    {&__pyx_n_s_count_t, __pyx_k_count_t, sizeof(__pyx_k_count_t), 0, 0, 1, 1},
    {&__pyx_n_s_counter, __pyx_k_counter, sizeof(__pyx_k_counter), 0, 0, 1, 1},
    {&__pyx_n_s_coverage, __pyx_k_coverage, sizeof(__pyx_k_coverage), 0, 0, 1, 1},
    {&__pyx_n_s_creference_filename, __pyx_k_creference_filename, sizeof(__pyx_k_creference_filename), 0, 0, 1, 1},
    {&__pyx_n_s_ctext, __pyx_k_ctext, sizeof(__pyx_k_ctext), 0, 0, 1, 1},
    {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1},
    {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1},
    {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1},
    {&__pyx_n_s_dict_2, __pyx_k_dict_2, sizeof(__pyx_k_dict_2), 0, 0, 1, 1},
    {&__pyx_kp_u_disable, __pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0, 0},
    {&__pyx_n_s_duplicate_filehandle, __pyx_k_duplicate_filehandle, sizeof(__pyx_k_duplicate_filehandle), 0, 0, 1, 1},
    {&__pyx_kp_u_either_supply_options_template_h, __pyx_k_either_supply_options_template_h, sizeof(__pyx_k_either_supply_options_template_h), 0, 1, 0, 0},
    {&__pyx_kp_u_enable, __pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0, 0},
    {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
    {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1},
    {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
    {&__pyx_kp_u_error_during_iteration, __pyx_k_error_during_iteration, sizeof(__pyx_k_error_during_iteration), 0, 1, 0, 0},
    {&__pyx_kp_u_error_while_reading_file, __pyx_k_error_while_reading_file, sizeof(__pyx_k_error_while_reading_file), 0, 1, 0, 0},
    {&__pyx_kp_u_error_while_reading_file_2, __pyx_k_error_while_reading_file_2, sizeof(__pyx_k_error_while_reading_file_2), 0, 1, 0, 0},
    {&__pyx_n_s_exc_type, __pyx_k_exc_type, sizeof(__pyx_k_exc_type), 0, 0, 1, 1},
    {&__pyx_n_s_exc_value, __pyx_k_exc_value, sizeof(__pyx_k_exc_value), 0, 0, 1, 1},
    {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1},
    {&__pyx_kp_u_failure_when_setting_reference_f, __pyx_k_failure_when_setting_reference_f, sizeof(__pyx_k_failure_when_setting_reference_f), 0, 1, 0, 0},
    {&__pyx_n_s_fastafile, __pyx_k_fastafile, sizeof(__pyx_k_fastafile), 0, 0, 1, 1},
    {&__pyx_n_u_fastafile, __pyx_k_fastafile, sizeof(__pyx_k_fastafile), 0, 1, 0, 1},
    {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1},
    {&__pyx_kp_u_fetch_called_on_bamfile_without, __pyx_k_fetch_called_on_bamfile_without, sizeof(__pyx_k_fetch_called_on_bamfile_without), 0, 1, 0, 0},
    {&__pyx_kp_u_fetching_by_region_is_not_availa, __pyx_k_fetching_by_region_is_not_availa, sizeof(__pyx_k_fetching_by_region_is_not_availa), 0, 1, 0, 0},
    {&__pyx_n_s_field, __pyx_k_field, sizeof(__pyx_k_field), 0, 0, 1, 1},
    {&__pyx_n_s_fields, __pyx_k_fields, sizeof(__pyx_k_fields), 0, 0, 1, 1},
    {&__pyx_kp_u_file_does_not_contain_alignment, __pyx_k_file_does_not_contain_alignment, sizeof(__pyx_k_file_does_not_contain_alignment), 0, 1, 0, 0},
    {&__pyx_kp_u_file_does_not_have_a_valid_heade, __pyx_k_file_does_not_have_a_valid_heade, sizeof(__pyx_k_file_does_not_have_a_valid_heade), 0, 1, 0, 0},
    {&__pyx_kp_u_file_has_no_sequences_defined_mo, __pyx_k_file_has_no_sequences_defined_mo, sizeof(__pyx_k_file_has_no_sequences_defined_mo), 0, 1, 0, 0},
    {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1},
    {&__pyx_n_u_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 1, 0, 1},
    {&__pyx_n_u_fileno, __pyx_k_fileno, sizeof(__pyx_k_fileno), 0, 1, 0, 1},
    {&__pyx_n_s_filepath_index, __pyx_k_filepath_index, sizeof(__pyx_k_filepath_index), 0, 0, 1, 1},
    {&__pyx_n_s_filepath_or_object, __pyx_k_filepath_or_object, sizeof(__pyx_k_filepath_or_object), 0, 0, 1, 1},
    {&__pyx_n_s_filter_method, __pyx_k_filter_method, sizeof(__pyx_k_filter_method), 0, 0, 1, 1},
    {&__pyx_n_s_find, __pyx_k_find, sizeof(__pyx_k_find), 0, 0, 1, 1},
    {&__pyx_n_s_find_introns, __pyx_k_find_introns, sizeof(__pyx_k_find_introns), 0, 0, 1, 1},
    {&__pyx_n_s_find_introns_slow, __pyx_k_find_introns_slow, sizeof(__pyx_k_find_introns_slow), 0, 0, 1, 1},
    {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1},
    {&__pyx_n_u_flag_filter, __pyx_k_flag_filter, sizeof(__pyx_k_flag_filter), 0, 1, 0, 1},
    {&__pyx_n_u_flag_require, __pyx_k_flag_require, sizeof(__pyx_k_flag_require), 0, 1, 0, 1},
    {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
    {&__pyx_n_s_format_options, __pyx_k_format_options, sizeof(__pyx_k_format_options), 0, 0, 1, 1},
    {&__pyx_n_s_from_dict, __pyx_k_from_dict, sizeof(__pyx_k_from_dict), 0, 0, 1, 1},
    {&__pyx_n_s_from_references, __pyx_k_from_references, sizeof(__pyx_k_from_references), 0, 0, 1, 1},
    {&__pyx_n_s_from_text, __pyx_k_from_text, sizeof(__pyx_k_from_text), 0, 0, 1, 1},
    {&__pyx_n_s_from_text_and_lengths, __pyx_k_from_text_and_lengths, sizeof(__pyx_k_from_text_and_lengths), 0, 0, 1, 1},
    {&__pyx_kp_u_gc, __pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0, 0},
    {&__pyx_n_s_genome_loc, __pyx_k_genome_loc, sizeof(__pyx_k_genome_loc), 0, 0, 1, 1},
    {&__pyx_n_s_genotype, __pyx_k_genotype, sizeof(__pyx_k_genotype), 0, 0, 1, 1},
    {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
    {&__pyx_n_s_get_aligned_pairs, __pyx_k_get_aligned_pairs, sizeof(__pyx_k_get_aligned_pairs), 0, 0, 1, 1},
    {&__pyx_n_s_get_index_statistics, __pyx_k_get_index_statistics, sizeof(__pyx_k_get_index_statistics), 0, 0, 1, 1},
    {&__pyx_n_s_get_reference_length, __pyx_k_get_reference_length, sizeof(__pyx_k_get_reference_length), 0, 0, 1, 1},
    {&__pyx_n_s_get_reference_name, __pyx_k_get_reference_name, sizeof(__pyx_k_get_reference_name), 0, 0, 1, 1},
    {&__pyx_n_s_get_tid, __pyx_k_get_tid, sizeof(__pyx_k_get_tid), 0, 0, 1, 1},
    {&__pyx_n_s_getitem, __pyx_k_getitem, sizeof(__pyx_k_getitem), 0, 0, 1, 1},
    {&__pyx_n_s_getrname, __pyx_k_getrname, sizeof(__pyx_k_getrname), 0, 0, 1, 1},
    {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1},
    {&__pyx_n_s_gettid, __pyx_k_gettid, sizeof(__pyx_k_gettid), 0, 0, 1, 1},
    {&__pyx_n_u_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 1, 0, 1},
    {&__pyx_n_s_hasReference, __pyx_k_hasReference, sizeof(__pyx_k_hasReference), 0, 0, 1, 1},
    {&__pyx_n_s_has_coord, __pyx_k_has_coord, sizeof(__pyx_k_has_coord), 0, 0, 1, 1},
    {&__pyx_n_s_has_index, __pyx_k_has_index, sizeof(__pyx_k_has_index), 0, 0, 1, 1},
    {&__pyx_n_s_has_reference, __pyx_k_has_reference, sizeof(__pyx_k_has_reference), 0, 0, 1, 1},
    {&__pyx_n_s_hdr, __pyx_k_hdr, sizeof(__pyx_k_hdr), 0, 0, 1, 1},
    {&__pyx_n_s_head, __pyx_k_head, sizeof(__pyx_k_head), 0, 0, 1, 1},
    {&__pyx_n_s_header, __pyx_k_header, sizeof(__pyx_k_header), 0, 0, 1, 1},
    {&__pyx_n_s_header_dict, __pyx_k_header_dict, sizeof(__pyx_k_header_dict), 0, 0, 1, 1},
    {&__pyx_kp_u_header_line_with_invalid_type, __pyx_k_header_line_with_invalid_type, sizeof(__pyx_k_header_line_with_invalid_type), 0, 1, 0, 0},
    {&__pyx_kp_u_header_line_without_s, __pyx_k_header_line_without_s, sizeof(__pyx_k_header_line_without_s), 0, 1, 0, 0},
    {&__pyx_kp_u_header_not_available_in_closed_f, __pyx_k_header_not_available_in_closed_f, sizeof(__pyx_k_header_not_available_in_closed_f), 0, 1, 0, 0},
    {&__pyx_n_s_idx, __pyx_k_idx, sizeof(__pyx_k_idx), 0, 0, 1, 1},
    {&__pyx_n_u_ignore_orphans, __pyx_k_ignore_orphans, sizeof(__pyx_k_ignore_orphans), 0, 1, 0, 1},
    {&__pyx_n_u_ignore_overlaps, __pyx_k_ignore_overlaps, sizeof(__pyx_k_ignore_overlaps), 0, 1, 0, 1},
    {&__pyx_n_s_ignore_truncation, __pyx_k_ignore_truncation, sizeof(__pyx_k_ignore_truncation), 0, 0, 1, 1},
    {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
    {&__pyx_kp_u_incomplete_sequence_information, __pyx_k_incomplete_sequence_information, sizeof(__pyx_k_incomplete_sequence_information), 0, 1, 0, 0},
    {&__pyx_n_s_index_filename, __pyx_k_index_filename, sizeof(__pyx_k_index_filename), 0, 0, 1, 1},
    {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
    {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1},
    {&__pyx_n_s_int_array_template, __pyx_k_int_array_template, sizeof(__pyx_k_int_array_template), 0, 0, 1, 1},
    {&__pyx_kp_u_interval_of_size_0, __pyx_k_interval_of_size_0, sizeof(__pyx_k_interval_of_size_0), 0, 1, 0, 0},
    {&__pyx_kp_u_interval_of_size_less_than_0, __pyx_k_interval_of_size_less_than_0, sizeof(__pyx_k_interval_of_size_less_than_0), 0, 1, 0, 0},
    {&__pyx_kp_u_invalid_file_opening_mode_s, __pyx_k_invalid_file_opening_mode_s, sizeof(__pyx_k_invalid_file_opening_mode_s), 0, 1, 0, 0},
    {&__pyx_kp_u_invalid_type_for_record_s_s_expe, __pyx_k_invalid_type_for_record_s_s_expe, sizeof(__pyx_k_invalid_type_for_record_s_s_expe), 0, 1, 0, 0},
    {&__pyx_n_s_io, __pyx_k_io, sizeof(__pyx_k_io), 0, 0, 1, 1},
    {&__pyx_n_s_is_bam, __pyx_k_is_bam, sizeof(__pyx_k_is_bam), 0, 0, 1, 1},
    {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1},
    {&__pyx_n_s_is_cram, __pyx_k_is_cram, sizeof(__pyx_k_is_cram), 0, 0, 1, 1},
    {&__pyx_n_s_is_open, __pyx_k_is_open, sizeof(__pyx_k_is_open), 0, 0, 1, 1},
    {&__pyx_n_s_is_valid_tid, __pyx_k_is_valid_tid, sizeof(__pyx_k_is_valid_tid), 0, 0, 1, 1},
    {&__pyx_kp_u_isenabled, __pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0, 0},
    {&__pyx_n_s_islower, __pyx_k_islower, sizeof(__pyx_k_islower), 0, 0, 1, 1},
    {&__pyx_n_s_isupper, __pyx_k_isupper, sizeof(__pyx_k_isupper), 0, 0, 1, 1},
    {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
    {&__pyx_n_s_iteritems, __pyx_k_iteritems, sizeof(__pyx_k_iteritems), 0, 0, 1, 1},
    {&__pyx_n_s_junc_start, __pyx_k_junc_start, sizeof(__pyx_k_junc_start), 0, 0, 1, 1},
    {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
    {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
    {&__pyx_n_s_kwargs, __pyx_k_kwargs, sizeof(__pyx_k_kwargs), 0, 0, 1, 1},
    {&__pyx_n_s_l_text, __pyx_k_l_text, sizeof(__pyx_k_l_text), 0, 0, 1, 1},
    {&__pyx_n_s_last_read_pos, __pyx_k_last_read_pos, sizeof(__pyx_k_last_read_pos), 0, 0, 1, 1},
    {&__pyx_n_s_len, __pyx_k_len, sizeof(__pyx_k_len), 0, 0, 1, 1},
    {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1},
    {&__pyx_n_s_lengths, __pyx_k_lengths, sizeof(__pyx_k_lengths), 0, 0, 1, 1},
    {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1},
    {&__pyx_n_s_lines, __pyx_k_lines, sizeof(__pyx_k_lines), 0, 0, 1, 1},
    {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
    {&__pyx_n_s_make, __pyx_k_make, sizeof(__pyx_k_make), 0, 0, 1, 1},
    {&__pyx_kp_u_malformatted_header_no_in_field, __pyx_k_malformatted_header_no_in_field, sizeof(__pyx_k_malformatted_header_no_in_field), 0, 1, 0, 0},
    {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1},
    {&__pyx_n_s_mapped, __pyx_k_mapped, sizeof(__pyx_k_mapped), 0, 0, 1, 1},
    {&__pyx_n_u_mapped, __pyx_k_mapped, sizeof(__pyx_k_mapped), 0, 1, 0, 1},
    {&__pyx_kp_u_mapping_information_not_recorded, __pyx_k_mapping_information_not_recorded, sizeof(__pyx_k_mapping_information_not_recorded), 0, 1, 0, 0},
    {&__pyx_n_s_mapping_quality, __pyx_k_mapping_quality, sizeof(__pyx_k_mapping_quality), 0, 0, 1, 1},
    {&__pyx_n_s_match_or_deletion, __pyx_k_match_or_deletion, sizeof(__pyx_k_match_or_deletion), 0, 0, 1, 1},
    {&__pyx_n_s_mate, __pyx_k_mate, sizeof(__pyx_k_mate), 0, 0, 1, 1},
    {&__pyx_kp_u_mate_not_found, __pyx_k_mate_not_found, sizeof(__pyx_k_mate_not_found), 0, 1, 0, 0},
    {&__pyx_kp_u_mate_s_is_unmapped, __pyx_k_mate_s_is_unmapped, sizeof(__pyx_k_mate_s_is_unmapped), 0, 1, 0, 0},
    {&__pyx_n_u_max_depth, __pyx_k_max_depth, sizeof(__pyx_k_max_depth), 0, 1, 0, 1},
    {&__pyx_n_u_min_base_quality, __pyx_k_min_base_quality, sizeof(__pyx_k_min_base_quality), 0, 1, 0, 1},
    {&__pyx_n_u_min_mapping_quality, __pyx_k_min_mapping_quality, sizeof(__pyx_k_min_mapping_quality), 0, 1, 0, 1},
    {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
    {&__pyx_n_s_multiple_iterators, __pyx_k_multiple_iterators, sizeof(__pyx_k_multiple_iterators), 0, 0, 1, 1},
    {&__pyx_kp_u_multiple_iterators_not_implement, __pyx_k_multiple_iterators_not_implement, sizeof(__pyx_k_multiple_iterators_not_implement), 0, 1, 0, 0},
    {&__pyx_kp_u_multiple_iterators_not_implement_2, __pyx_k_multiple_iterators_not_implement_2, sizeof(__pyx_k_multiple_iterators_not_implement_2), 0, 1, 0, 0},
    {&__pyx_kp_u_multiple_s_lines_are_not_permitt, __pyx_k_multiple_s_lines_are_not_permitt, sizeof(__pyx_k_multiple_s_lines_are_not_permitt), 0, 1, 0, 0},
    {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
    {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
    {&__pyx_n_s_name_2, __pyx_k_name_2, sizeof(__pyx_k_name_2), 0, 0, 1, 1},
    {&__pyx_n_s_namedtuple, __pyx_k_namedtuple, sizeof(__pyx_k_namedtuple), 0, 0, 1, 1},
    {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1},
    {&__pyx_n_s_nextiter, __pyx_k_nextiter, sizeof(__pyx_k_nextiter), 0, 0, 1, 1},
    {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0},
    {&__pyx_kp_u_no_index_available_for_fetch, __pyx_k_no_index_available_for_fetch, sizeof(__pyx_k_no_index_available_for_fetch), 0, 1, 0, 0},
    {&__pyx_kp_u_no_index_available_for_iteration, __pyx_k_no_index_available_for_iteration, sizeof(__pyx_k_no_index_available_for_iteration), 0, 1, 0, 0},
    {&__pyx_kp_u_no_index_available_for_pileup, __pyx_k_no_index_available_for_pileup, sizeof(__pyx_k_no_index_available_for_pileup), 0, 1, 0, 0},
    {&__pyx_n_u_nofilter, __pyx_k_nofilter, sizeof(__pyx_k_nofilter), 0, 1, 0, 1},
    {&__pyx_kp_u_not_enough_information_to_constr, __pyx_k_not_enough_information_to_constr, sizeof(__pyx_k_not_enough_information_to_constr), 0, 1, 0, 0},
    {&__pyx_n_s_nreferences, __pyx_k_nreferences, sizeof(__pyx_k_nreferences), 0, 0, 1, 1},
    {&__pyx_n_s_nt, __pyx_k_nt, sizeof(__pyx_k_nt), 0, 0, 1, 1},
    {&__pyx_kp_u_number_of_reference_names_and_le, __pyx_k_number_of_reference_names_and_le, sizeof(__pyx_k_number_of_reference_names_and_le), 0, 1, 0, 0},
    {&__pyx_n_s_op, __pyx_k_op, sizeof(__pyx_k_op), 0, 0, 1, 1},
    {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1},
    {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
    {&__pyx_n_s_parse_region, __pyx_k_parse_region, sizeof(__pyx_k_parse_region), 0, 0, 1, 1},
    {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1},
    {&__pyx_n_s_pileup, __pyx_k_pileup, sizeof(__pyx_k_pileup), 0, 0, 1, 1},
    {&__pyx_n_s_port, __pyx_k_port, sizeof(__pyx_k_port), 0, 0, 1, 1},
    {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1},
    {&__pyx_n_s_positions, __pyx_k_positions, sizeof(__pyx_k_positions), 0, 0, 1, 1},
    {&__pyx_n_s_pysam_libcalignmentfile, __pyx_k_pysam_libcalignmentfile, sizeof(__pyx_k_pysam_libcalignmentfile), 0, 0, 1, 1},
    {&__pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_k_pysam_libcalignmentfile_pyx, sizeof(__pyx_k_pysam_libcalignmentfile_pyx), 0, 0, 1, 0},
    {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1},
    {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1},
    {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1},
    {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1},
    {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1},
    {&__pyx_n_s_pyx_unpickle_SNPCall, __pyx_k_pyx_unpickle_SNPCall, sizeof(__pyx_k_pyx_unpickle_SNPCall), 0, 0, 1, 1},
    {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
    {&__pyx_n_s_qname, __pyx_k_qname, sizeof(__pyx_k_qname), 0, 0, 1, 1},
    {&__pyx_n_s_qpos, __pyx_k_qpos, sizeof(__pyx_k_qpos), 0, 0, 1, 1},
    {&__pyx_n_s_quality, __pyx_k_quality, sizeof(__pyx_k_quality), 0, 0, 1, 1},
    {&__pyx_n_s_quality_threshold, __pyx_k_quality_threshold, sizeof(__pyx_k_quality_threshold), 0, 0, 1, 1},
    {&__pyx_n_s_query_name, __pyx_k_query_name, sizeof(__pyx_k_query_name), 0, 0, 1, 1},
    {&__pyx_n_s_query_qualities, __pyx_k_query_qualities, sizeof(__pyx_k_query_qualities), 0, 0, 1, 1},
    {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
    {&__pyx_n_u_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 1, 0, 1},
    {&__pyx_n_u_rU, __pyx_k_rU, sizeof(__pyx_k_rU), 0, 1, 0, 1},
    {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
    {&__pyx_n_u_rb, __pyx_k_rb, sizeof(__pyx_k_rb), 0, 1, 0, 1},
    {&__pyx_n_u_rc, __pyx_k_rc, sizeof(__pyx_k_rc), 0, 1, 0, 1},
    {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1},
    {&__pyx_n_s_read, __pyx_k_read, sizeof(__pyx_k_read), 0, 0, 1, 1},
    {&__pyx_n_s_read_callback, __pyx_k_read_callback, sizeof(__pyx_k_read_callback), 0, 0, 1, 1},
    {&__pyx_n_s_read_failure_reason, __pyx_k_read_failure_reason, sizeof(__pyx_k_read_failure_reason), 0, 0, 1, 1},
    {&__pyx_n_s_read_iterator, __pyx_k_read_iterator, sizeof(__pyx_k_read_iterator), 0, 0, 1, 1},
    {&__pyx_n_s_read_loc, __pyx_k_read_loc, sizeof(__pyx_k_read_loc), 0, 0, 1, 1},
    {&__pyx_kp_u_read_s_is_unpaired, __pyx_k_read_s_is_unpaired, sizeof(__pyx_k_read_s_is_unpaired), 0, 1, 0, 0},
    {&__pyx_kp_u_read_s_not_found, __pyx_k_read_s_not_found, sizeof(__pyx_k_read_s_not_found), 0, 1, 0, 0},
    {&__pyx_n_s_record, __pyx_k_record, sizeof(__pyx_k_record), 0, 0, 1, 1},
    {&__pyx_n_u_redo_baq, __pyx_k_redo_baq, sizeof(__pyx_k_redo_baq), 0, 1, 0, 1},
    {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1},
    {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1},
    {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1},
    {&__pyx_n_s_ref, __pyx_k_ref, sizeof(__pyx_k_ref), 0, 0, 1, 1},
    {&__pyx_n_s_reference, __pyx_k_reference, sizeof(__pyx_k_reference), 0, 0, 1, 1},
    {&__pyx_n_s_reference_base, __pyx_k_reference_base, sizeof(__pyx_k_reference_base), 0, 0, 1, 1},
    {&__pyx_n_s_reference_filename, __pyx_k_reference_filename, sizeof(__pyx_k_reference_filename), 0, 0, 1, 1},
    {&__pyx_kp_u_reference_id_i_out_of_range_0_ti, __pyx_k_reference_id_i_out_of_range_0_ti, sizeof(__pyx_k_reference_id_i_out_of_range_0_ti), 0, 1, 0, 0},
    {&__pyx_n_s_reference_lengths, __pyx_k_reference_lengths, sizeof(__pyx_k_reference_lengths), 0, 0, 1, 1},
    {&__pyx_n_s_reference_names, __pyx_k_reference_names, sizeof(__pyx_k_reference_names), 0, 0, 1, 1},
    {&__pyx_kp_u_reference_sequence_for_tid_not_f, __pyx_k_reference_sequence_for_tid_not_f, sizeof(__pyx_k_reference_sequence_for_tid_not_f), 0, 1, 0, 0},
    {&__pyx_n_s_referencelengths, __pyx_k_referencelengths, sizeof(__pyx_k_referencelengths), 0, 0, 1, 1},
    {&__pyx_n_s_referencenames, __pyx_k_referencenames, sizeof(__pyx_k_referencenames), 0, 0, 1, 1},
    {&__pyx_n_s_references, __pyx_k_references, sizeof(__pyx_k_references), 0, 0, 1, 1},
    {&__pyx_n_s_refpos, __pyx_k_refpos, sizeof(__pyx_k_refpos), 0, 0, 1, 1},
    {&__pyx_n_s_region, __pyx_k_region, sizeof(__pyx_k_region), 0, 0, 1, 1},
    {&__pyx_n_s_require_index, __pyx_k_require_index, sizeof(__pyx_k_require_index), 0, 0, 1, 1},
    {&__pyx_n_s_res, __pyx_k_res, sizeof(__pyx_k_res), 0, 0, 1, 1},
    {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1},
    {&__pyx_n_s_results, __pyx_k_results, sizeof(__pyx_k_results), 0, 0, 1, 1},
    {&__pyx_n_s_ret, __pyx_k_ret, sizeof(__pyx_k_ret), 0, 0, 1, 1},
    {&__pyx_n_s_rstart, __pyx_k_rstart, sizeof(__pyx_k_rstart), 0, 0, 1, 1},
    {&__pyx_n_s_rstop, __pyx_k_rstop, sizeof(__pyx_k_rstop), 0, 0, 1, 1},
    {&__pyx_n_s_rtid, __pyx_k_rtid, sizeof(__pyx_k_rtid), 0, 0, 1, 1},
    {&__pyx_kp_u_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 1, 0, 0},
    {&__pyx_kp_u_sam_write1_failed_with_error_cod, __pyx_k_sam_write1_failed_with_error_cod, sizeof(__pyx_k_sam_write1_failed_with_error_cod), 0, 1, 0, 0},
    {&__pyx_n_s_samfile, __pyx_k_samfile, sizeof(__pyx_k_samfile), 0, 0, 1, 1},
    {&__pyx_n_u_samtools, __pyx_k_samtools, sizeof(__pyx_k_samtools), 0, 1, 0, 1},
    {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
    {&__pyx_kp_s_self_b_self_htsfile_self_index_c, __pyx_k_self_b_self_htsfile_self_index_c, sizeof(__pyx_k_self_b_self_htsfile_self_index_c), 0, 0, 1, 0},
    {&__pyx_kp_s_self_b_self_htsfile_self_index_s, __pyx_k_self_b_self_htsfile_self_index_s, sizeof(__pyx_k_self_b_self_htsfile_self_index_s), 0, 0, 1, 0},
    {&__pyx_kp_s_self_htsfile_cannot_be_converted, __pyx_k_self_htsfile_cannot_be_converted, sizeof(__pyx_k_self_htsfile_cannot_be_converted), 0, 0, 1, 0},
    {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1},
    {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1},
    {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1},
    {&__pyx_n_s_snp_quality, __pyx_k_snp_quality, sizeof(__pyx_k_snp_quality), 0, 0, 1, 1},
    {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1},
    {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
    {&__pyx_n_s_splitlines, __pyx_k_splitlines, sizeof(__pyx_k_splitlines), 0, 0, 1, 1},
    {&__pyx_n_s_sq, __pyx_k_sq, sizeof(__pyx_k_sq), 0, 0, 1, 1},
    {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
    {&__pyx_n_s_start_2, __pyx_k_start_2, sizeof(__pyx_k_start_2), 0, 0, 1, 1},
    {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
    {&__pyx_n_s_state, __pyx_k_state, sizeof(__pyx_k_state), 0, 0, 1, 1},
    {&__pyx_n_u_stepper, __pyx_k_stepper, sizeof(__pyx_k_stepper), 0, 1, 0, 1},
    {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1},
    {&__pyx_n_s_stop_2, __pyx_k_stop_2, sizeof(__pyx_k_stop_2), 0, 0, 1, 1},
    {&__pyx_n_s_str, __pyx_k_str, sizeof(__pyx_k_str), 0, 0, 1, 1},
    {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0},
    {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1},
    {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
    {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1},
    {&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
    {&__pyx_n_s_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 0, 0, 1, 1},
    {&__pyx_n_s_template, __pyx_k_template, sizeof(__pyx_k_template), 0, 0, 1, 1},
    {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
    {&__pyx_n_s_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 0, 1, 1},
    {&__pyx_n_s_threads, __pyx_k_threads, sizeof(__pyx_k_threads), 0, 0, 1, 1},
    {&__pyx_n_s_threshold, __pyx_k_threshold, sizeof(__pyx_k_threshold), 0, 0, 1, 1},
    {&__pyx_n_s_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 0, 1, 1},
    {&__pyx_n_s_to_dict, __pyx_k_to_dict, sizeof(__pyx_k_to_dict), 0, 0, 1, 1},
    {&__pyx_n_u_total, __pyx_k_total, sizeof(__pyx_k_total), 0, 1, 0, 1},
    {&__pyx_n_s_traceback, __pyx_k_traceback, sizeof(__pyx_k_traceback), 0, 0, 1, 1},
    {&__pyx_n_s_truncate, __pyx_k_truncate, sizeof(__pyx_k_truncate), 0, 0, 1, 1},
    {&__pyx_kp_u_truncated_file, __pyx_k_truncated_file, sizeof(__pyx_k_truncated_file), 0, 1, 0, 0},
    {&__pyx_kp_u_unable_to_open_index_file, __pyx_k_unable_to_open_index_file, sizeof(__pyx_k_unable_to_open_index_file), 0, 1, 0, 0},
    {&__pyx_kp_u_unable_to_open_index_file_s, __pyx_k_unable_to_open_index_file_s, sizeof(__pyx_k_unable_to_open_index_file_s), 0, 1, 0, 0},
    {&__pyx_kp_u_unable_to_read_header_informatio, __pyx_k_unable_to_read_header_informatio, sizeof(__pyx_k_unable_to_read_header_informatio), 0, 1, 0, 0},
    {&__pyx_kp_u_unable_to_reopen_htsfile, __pyx_k_unable_to_reopen_htsfile, sizeof(__pyx_k_unable_to_reopen_htsfile), 0, 1, 0, 0},
    {&__pyx_kp_u_unknown_reference, __pyx_k_unknown_reference, sizeof(__pyx_k_unknown_reference), 0, 1, 0, 0},
    {&__pyx_kp_u_unknown_stepper_option_s_in_Iter, __pyx_k_unknown_stepper_option_s_in_Iter, sizeof(__pyx_k_unknown_stepper_option_s_in_Iter), 0, 1, 0, 0},
    {&__pyx_n_s_unmapped, __pyx_k_unmapped, sizeof(__pyx_k_unmapped), 0, 0, 1, 1},
    {&__pyx_n_u_unmapped, __pyx_k_unmapped, sizeof(__pyx_k_unmapped), 0, 1, 0, 1},
    {&__pyx_n_s_until_eof, __pyx_k_until_eof, sizeof(__pyx_k_until_eof), 0, 0, 1, 1},
    {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1},
    {&__pyx_n_s_use_setstate, __pyx_k_use_setstate, sizeof(__pyx_k_use_setstate), 0, 0, 1, 1},
    {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
    {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
    {&__pyx_n_u_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 1, 0, 1},
    {&__pyx_n_s_warn, __pyx_k_warn, sizeof(__pyx_k_warn), 0, 0, 1, 1},
    {&__pyx_n_s_warnings, __pyx_k_warnings, sizeof(__pyx_k_warnings), 0, 0, 1, 1},
    {&__pyx_n_u_wb, __pyx_k_wb, sizeof(__pyx_k_wb), 0, 1, 0, 1},
    {&__pyx_n_u_wb0, __pyx_k_wb0, sizeof(__pyx_k_wb0), 0, 1, 0, 1},
    {&__pyx_n_u_wbu, __pyx_k_wbu, sizeof(__pyx_k_wbu), 0, 1, 0, 1},
    {&__pyx_n_u_wc, __pyx_k_wc, sizeof(__pyx_k_wc), 0, 1, 0, 1},
    {&__pyx_n_u_wh, __pyx_k_wh, sizeof(__pyx_k_wh), 0, 1, 0, 1},
    {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
    {&__pyx_kp_u_wrong_sequence_information_in_s, __pyx_k_wrong_sequence_information_in_s, sizeof(__pyx_k_wrong_sequence_information_in_s), 0, 1, 0, 0},
    {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
    {&__pyx_n_s_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 0, 1, 1},
    {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
    {0, 0, 0, 0, 0, 0, 0}
  };
  return __Pyx_InitStrings(__pyx_string_tab);
}
/* #### Code section: cached_builtins ### */
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) __PYX_ERR(0, 62, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 170, __pyx_L1_error)
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 235, __pyx_L1_error)
  __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) __PYX_ERR(0, 259, __pyx_L1_error)
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 288, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 344, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 372, __pyx_L1_error)
  __pyx_builtin_AssertionError = __Pyx_GetBuiltinName(__pyx_n_s_AssertionError); if (!__pyx_builtin_AssertionError) __PYX_ERR(0, 435, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 451, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 554, __pyx_L1_error)
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 779, __pyx_L1_error)
  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 857, __pyx_L1_error)
  __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 924, __pyx_L1_error)
  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) __PYX_ERR(0, 1878, __pyx_L1_error)
  __pyx_builtin_super = __Pyx_GetBuiltinName(__pyx_n_s_super); if (!__pyx_builtin_super) __PYX_ERR(0, 2079, __pyx_L1_error)
  __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) __PYX_ERR(0, 2865, __pyx_L1_error)
  __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) __PYX_ERR(0, 2914, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### Code section: cached_constants ### */

static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pysam/libcalignmentfile.pyx":170
 * cdef AlignmentHeader makeAlignmentHeader(bam_hdr_t *hdr):
 *     if not hdr:
 *         raise ValueError('cannot create AlignmentHeader, received NULL pointer')             # <<<<<<<<<<<<<<
 * 
 *     # check: is AlignmetHeader.__cinit__ called?
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_u_cannot_create_AlignmentHeader_re); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "pysam/libcalignmentfile.pyx":235
 *         self.ptr = bam_hdr_init()
 *         if self.ptr is NULL:
 *             raise MemoryError("could not create header")             # <<<<<<<<<<<<<<
 * 
 *     @classmethod
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_u_could_not_create_header); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 235, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "pysam/libcalignmentfile.pyx":284
 *         for line in text.splitlines():
 *             if line.startswith("@SQ"):
 *                 fields = dict([x.split(":", 1) for x in line.split("\t")[1:]])             # <<<<<<<<<<<<<<
 *                 try:
 *                     reference_names.append(fields["SN"])
 */
  __pyx_slice__9 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__9)) __PYX_ERR(0, 284, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__9);
  __Pyx_GIVEREF(__pyx_slice__9);
  __pyx_tuple__10 = PyTuple_Pack(2, __pyx_kp_u__2, __pyx_int_1); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 284, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pysam/libcalignmentfile.pyx":340
 * 
 *         if len(reference_names) != len(reference_lengths):
 *             raise ValueError("number of reference names and lengths do not match")             # <<<<<<<<<<<<<<
 * 
 *         # optionally, if there is no text, add a SAM compatible header to output file.
 */
  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_u_number_of_reference_names_and_le); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 340, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "pysam/libcalignmentfile.pyx":453
 *             for idx, field in enumerate(fields[1:]):
 *                 if ":" not in field:
 *                     raise ValueError("malformatted header: no ':' in field" )             # <<<<<<<<<<<<<<
 *                 key, value = field.split(":", 1)
 *                 if key in ("CL",):
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u_malformatted_header_no_in_field); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 453, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "pysam/libcalignmentfile.pyx":533
 *         tid = bam_name2id(self.ptr, reference)
 *         if tid < -1:
 *             raise ValueError('could not parse header')             # <<<<<<<<<<<<<<
 *         return tid
 * 
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_u_could_not_parse_header); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "pysam/libcalignmentfile.pyx":554
 *     # dictionary access methods, for backwards compatibility.
 *     def __setitem__(self, key, value):
 *         raise TypeError("AlignmentHeader does not support item assignment (use header.to_dict()")             # <<<<<<<<<<<<<<
 * 
 *     def __getitem__(self, key):
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_u_AlignmentHeader_does_not_support); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "pysam/libcalignmentfile.pyx":777
 * 
 *         if not self.is_open:
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(
 */
  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_u_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 777, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "pysam/libcalignmentfile.pyx":779
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(             # <<<<<<<<<<<<<<
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 */
  __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_u_AlignmentFile_mapped_only_availa); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 779, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "pysam/libcalignmentfile.pyx":782
 *                 "AlignmentFile.mapped only available in bam files")
 *         if self.index == NULL:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "mapping information not recorded in index "
 *                 "or index not available")
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_u_mapping_information_not_recorded); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 782, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "pysam/libcalignmentfile.pyx":828
 *            # to bgzf_read (https://github.com/samtools/htslib/blob/1.7/bgzf.c#L888)
 *            # Better to avoid this (for now) than to produce seemingly correct results.
 *            raise ValueError('Cannot add extra threads when "ignore_truncation" is True')             # <<<<<<<<<<<<<<
 *         self.threads = threads
 * 
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_u_Cannot_add_extra_threads_when_ig); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 828, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "pysam/libcalignmentfile.pyx":857
 *         # StringIO not supported
 *         if isinstance(filepath_or_object, StringIO):
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "access from StringIO objects not supported")
 *         # reading from a file descriptor
 */
  __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_u_access_from_StringIO_objects_not); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);

  /* "pysam/libcalignmentfile.pyx":897
 * 
 *             if not (template or header or text or (reference_names and reference_lengths)):
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "either supply options `template`, `header`, `text` or  both `reference_names` "
 *                     "and `reference_lengths` for writing")
 */
  __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_u_either_supply_options_template_h); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 897, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "pysam/libcalignmentfile.pyx":918
 *                 self.header = AlignmentHeader.from_text(text)
 *             else:
 *                 raise ValueError("not enough information to construct header. Please provide template, "             # <<<<<<<<<<<<<<
 *                                  "header, text or reference_names/reference_lengths")
 *             self.htsfile = self._open_htsfile()
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_u_not_enough_information_to_constr); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 918, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "pysam/libcalignmentfile.pyx":936
 *             if "c" in mode and reference_filename:
 *                 if (hts_set_fai_filename(self.htsfile, self.reference_filename) != 0):
 *                     raise ValueError("failure when setting reference filename")             # <<<<<<<<<<<<<<
 * 
 *             # write header to htsfile
 */
  __pyx_tuple__49 = PyTuple_Pack(1, __pyx_kp_u_failure_when_setting_reference_f); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 936, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "pysam/libcalignmentfile.pyx":956
 * 
 *             if self.htsfile.format.category != sequence_data:
 *                 raise ValueError("file does not contain alignment data")             # <<<<<<<<<<<<<<
 * 
 *             if format_options and len(format_options):
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_u_file_does_not_contain_alignment); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "pysam/libcalignmentfile.pyx":987
 *                         hdr = sam_hdr_read(self.htsfile)
 *                     if hdr == NULL:
 *                         raise ValueError(             # <<<<<<<<<<<<<<
 *                             "SAM? file does not have a valid header (mode='%s'), "
 *                             "please provide reference_names and reference_lengths")
 */
  __pyx_tuple__51 = PyTuple_Pack(1, __pyx_kp_u_SAM_file_does_not_have_a_valid_h); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 987, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "pysam/libcalignmentfile.pyx":1022
 * 
 *                 elif require_index:
 *                     raise IOError('unable to open index file')             # <<<<<<<<<<<<<<
 * 
 *                 # save start of data section
 */
  __pyx_tuple__52 = PyTuple_Pack(1, __pyx_kp_u_unable_to_open_index_file); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 1022, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "pysam/libcalignmentfile.pyx":1103
 *             if not until_eof and not self.is_remote:
 *                 if not self.has_index():
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "fetch called on bamfile without index")
 * 
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_kp_u_fetch_called_on_bamfile_without); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 1103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "pysam/libcalignmentfile.pyx":1123
 *         else:
 *             if has_coord:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "fetching by region is not available for SAM files")
 * 
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_kp_u_fetching_by_region_is_not_availa); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 1123, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);

  /* "pysam/libcalignmentfile.pyx":1127
 * 
 *             if multiple_iterators == True:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "multiple iterators not implemented for SAM files")
 * 
 */
  __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_u_multiple_iterators_not_implement); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 1127, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "pysam/libcalignmentfile.pyx":1210
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
  __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_u_mate_not_found); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 1210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);

  /* "pysam/libcalignmentfile.pyx":1341
 *         if has_coord:
 *             if not self.has_index():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorColumnRegion(self,
 */
  __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_u_no_index_available_for_pileup); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 1341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);

  /* "pysam/libcalignmentfile.pyx":1538
 * 
 *         if _stop == _start:
 *             raise ValueError("interval of size 0")             # <<<<<<<<<<<<<<
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")
 */
  __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_u_interval_of_size_0); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(0, 1538, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);

  /* "pysam/libcalignmentfile.pyx":1540
 *             raise ValueError("interval of size 0")
 *         if _stop < _start:
 *             raise ValueError("interval of size less than 0")             # <<<<<<<<<<<<<<
 * 
 *         cdef int length = _stop - _start
 */
  __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_u_interval_of_size_less_than_0); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 1540, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);

  /* "pysam/libcalignmentfile.pyx":1854
 * 
 *         if not self.is_bam and self.header.nreferences == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
  __pyx_tuple__73 = PyTuple_Pack(1, __pyx_kp_u_can_not_iterate_over_samfile_wit); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 1854, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);

  /* "pysam/libcalignmentfile.pyx":1891
 *         """
 *         if self.header is None:
 *             raise ValueError("header not available in closed files")             # <<<<<<<<<<<<<<
 *         return self.header.is_valid_tid(tid)
 * 
 */
  __pyx_tuple__75 = PyTuple_Pack(1, __pyx_kp_u_header_not_available_in_closed_f); if (unlikely(!__pyx_tuple__75)) __PYX_ERR(0, 1891, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__75);
  __Pyx_GIVEREF(__pyx_tuple__75);

  /* "pysam/libcalignmentfile.pyx":2029
 *                 hdr = sam_hdr_read(self.htsfile)
 *             if hdr is NULL:
 *                 raise IOError("unable to read header information")             # <<<<<<<<<<<<<<
 *             self.header = makeAlignmentHeader(hdr)
 * 
 */
  __pyx_tuple__83 = PyTuple_Pack(1, __pyx_kp_u_unable_to_read_header_informatio); if (unlikely(!__pyx_tuple__83)) __PYX_ERR(0, 2029, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__83);
  __Pyx_GIVEREF(__pyx_tuple__83);

  /* "pysam/libcalignmentfile.pyx":2077
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for iteration")             # <<<<<<<<<<<<<<
 * 
 *         super().__init__(samfile, multiple_iterators=multiple_iterators)
 */
  __pyx_tuple__86 = PyTuple_Pack(1, __pyx_kp_u_no_index_available_for_iteration); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 2077, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__86);
  __Pyx_GIVEREF(__pyx_tuple__86);

  /* "pysam/libcalignmentfile.pyx":2111
 *             # returns -2 for a truncated file.
 *             # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise IOError("error while reading file {}: {}".format(self.samfile.filename, self.retval))
 */
  __pyx_tuple__87 = PyTuple_Pack(1, __pyx_kp_u_truncated_file); if (unlikely(!__pyx_tuple__87)) __PYX_ERR(0, 2111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__87);
  __Pyx_GIVEREF(__pyx_tuple__87);

  /* "pysam/libcalignmentfile.pyx":2227
 * 
 *         if not samfile.has_index():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
  __pyx_tuple__94 = PyTuple_Pack(1, __pyx_kp_u_no_index_available_for_fetch); if (unlikely(!__pyx_tuple__94)) __PYX_ERR(0, 2227, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__94);
  __Pyx_GIVEREF(__pyx_tuple__94);

  /* "pysam/libcalignmentfile.pyx":2647
 *         '''
 *         if self.iter is None:
 *             raise TypeError("Raw iterator set up without region cannot be reset")             # <<<<<<<<<<<<<<
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, stop, multiple_iterators=0)
 */
  __pyx_tuple__102 = PyTuple_Pack(1, __pyx_kp_u_Raw_iterator_set_up_without_regi); if (unlikely(!__pyx_tuple__102)) __PYX_ERR(0, 2647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__102);
  __Pyx_GIVEREF(__pyx_tuple__102);

  /* "pysam/libcalignmentfile.pyx":2726
 *             n = self.cnext()
 *             if n < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if n == 0:
 */
  __pyx_tuple__108 = PyTuple_Pack(1, __pyx_kp_u_error_during_iteration); if (unlikely(!__pyx_tuple__108)) __PYX_ERR(0, 2726, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__108);
  __Pyx_GIVEREF(__pyx_tuple__108);

  /* "pysam/libcalignmentfile.pyx":2914
 *                 self.htsfile = hts_open(cfilename, 'r')
 *             if self.htsfile == NULL:
 *                 raise OSError("unable to reopen htsfile")             # <<<<<<<<<<<<<<
 * 
 *             # need to advance in newly opened file to position after header
 */
  __pyx_tuple__117 = PyTuple_Pack(1, __pyx_kp_u_unable_to_reopen_htsfile); if (unlikely(!__pyx_tuple__117)) __PYX_ERR(0, 2914, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__117);
  __Pyx_GIVEREF(__pyx_tuple__117);

  /* "(tree fragment)":4
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 *     if __pyx_checksum not in (0xe45c101, 0x1134a9c, 0x50b2281):             # <<<<<<<<<<<<<<
 *         from pickle import PickleError as __pyx_PickleError
 *         raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xe45c101, 0x1134a9c, 0x50b2281) = (_consensus_quality, _coverage, _genotype, _pos, _reference_base, _rms_mapping_quality, _snp_quality, _tid))" % __pyx_checksum
 */
  __pyx_tuple__123 = PyTuple_Pack(3, __pyx_int_239452417, __pyx_int_18041500, __pyx_int_84615809); if (unlikely(!__pyx_tuple__123)) __PYX_ERR(3, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__123);
  __Pyx_GIVEREF(__pyx_tuple__123);

  /* "pysam/libcalignmentfile.pyx":92
 * 
 * IndexStats = collections.namedtuple("IndexStats",
 *                                     ("contig",             # <<<<<<<<<<<<<<
 *                                      "mapped",
 *                                      "unmapped",
 */
  __pyx_tuple__126 = PyTuple_Pack(4, __pyx_n_u_contig, __pyx_n_u_mapped, __pyx_n_u_unmapped, __pyx_n_u_total); if (unlikely(!__pyx_tuple__126)) __PYX_ERR(0, 92, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__126);
  __Pyx_GIVEREF(__pyx_tuple__126);

  /* "pysam/libcalignmentfile.pyx":91
 *     "IndexedReads"]
 * 
 * IndexStats = collections.namedtuple("IndexStats",             # <<<<<<<<<<<<<<
 *                                     ("contig",
 *                                      "mapped",
 */
  __pyx_tuple__127 = PyTuple_Pack(2, __pyx_n_u_IndexStats, __pyx_tuple__126); if (unlikely(!__pyx_tuple__127)) __PYX_ERR(0, 91, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__127);
  __Pyx_GIVEREF(__pyx_tuple__127);

  /* "pysam/libcalignmentfile.pyx":111
 * 
 * # order of records within SAM headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO")             # <<<<<<<<<<<<<<
 * 
 * # default type conversions within SAM header records
 */
  __pyx_tuple__128 = PyTuple_Pack(5, __pyx_n_u_HD, __pyx_n_u_SQ_2, __pyx_n_u_RG, __pyx_n_u_PG, __pyx_n_u_CO); if (unlikely(!__pyx_tuple__128)) __PYX_ERR(0, 111, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__128);
  __Pyx_GIVEREF(__pyx_tuple__128);

  /* "pysam/libcalignmentfile.pyx":130
 * # output order of fields within records. Ensure that CL is at
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "SS", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                               "UR", "SP", "AH", "TP",
 */
  __pyx_tuple__129 = PyTuple_Pack(4, __pyx_n_u_VN, __pyx_n_u_SO, __pyx_n_u_SS, __pyx_n_u_GO); if (unlikely(!__pyx_tuple__129)) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__129);
  __Pyx_GIVEREF(__pyx_tuple__129);

  /* "pysam/libcalignmentfile.pyx":131
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "SS", "GO"),
 *                       "SQ" : ("SN", "LN", "AS", "M5",             # <<<<<<<<<<<<<<
 *                               "UR", "SP", "AH", "TP",
 *                               "DS", "AN"),
 */
  __pyx_tuple__130 = PyTuple_Pack(10, __pyx_n_u_SN, __pyx_n_u_LN, __pyx_n_u_AS, __pyx_n_u_M5, __pyx_n_u_UR, __pyx_n_u_SP, __pyx_n_u_AH, __pyx_n_u_TP, __pyx_n_u_DS, __pyx_n_u_AN); if (unlikely(!__pyx_tuple__130)) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__130);
  __Pyx_GIVEREF(__pyx_tuple__130);

  /* "pysam/libcalignmentfile.pyx":134
 *                               "UR", "SP", "AH", "TP",
 *                               "DS", "AN"),
 *                       "RG" : ("ID", "CN", "SM", "LB",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "DT", "DS",
 *                               "PL", "FO", "KS", "PG",
 */
  __pyx_tuple__131 = PyTuple_Pack(14, __pyx_n_u_ID, __pyx_n_u_CN, __pyx_n_u_SM, __pyx_n_u_LB, __pyx_n_u_PU, __pyx_n_u_PI, __pyx_n_u_DT, __pyx_n_u_DS, __pyx_n_u_PL, __pyx_n_u_FO, __pyx_n_u_KS, __pyx_n_u_PG, __pyx_n_u_PM, __pyx_n_u_BC); if (unlikely(!__pyx_tuple__131)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__131);
  __Pyx_GIVEREF(__pyx_tuple__131);

  /* "pysam/libcalignmentfile.pyx":138
 *                               "PL", "FO", "KS", "PG",
 *                               "PM", "BC"),
 *                       "PG" : ("PN", "ID", "VN", "PP",             # <<<<<<<<<<<<<<
 *                               "DS", "CL"),}
 * 
 */
  __pyx_tuple__132 = PyTuple_Pack(6, __pyx_n_u_PN, __pyx_n_u_ID, __pyx_n_u_VN, __pyx_n_u_PP, __pyx_n_u_DS, __pyx_n_u_CL); if (unlikely(!__pyx_tuple__132)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__132);
  __Pyx_GIVEREF(__pyx_tuple__132);

  /* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(fields, record):             # <<<<<<<<<<<<<<
 *     '''build a header line from `fields` dictionary for `record`'''
 * 
 */
  __pyx_tuple__133 = PyTuple_Pack(4, __pyx_n_s_fields, __pyx_n_s_record, __pyx_n_s_line, __pyx_n_s_key); if (unlikely(!__pyx_tuple__133)) __PYX_ERR(0, 142, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__133);
  __Pyx_GIVEREF(__pyx_tuple__133);
  __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__133, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_build_header_line, 142, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 142, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */
  __pyx_tuple__134 = PyTuple_Pack(1, __pyx_n_s_code); if (unlikely(!__pyx_tuple__134)) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__134);
  __Pyx_GIVEREF(__pyx_tuple__134);
  __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__134, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_read_failure_reason, 178, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 178, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":237
 *             raise MemoryError("could not create header")
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):
 * 
 */
  __pyx_tuple__135 = PyTuple_Pack(12, __pyx_n_s_cls, __pyx_n_s_text, __pyx_n_s_reference_names, __pyx_n_s_reference_lengths, __pyx_n_s_self, __pyx_n_s_ctext, __pyx_n_s_l_text, __pyx_n_s_n, __pyx_n_s_x, __pyx_n_s_btext, __pyx_n_s_name, __pyx_n_s_ref); if (unlikely(!__pyx_tuple__135)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__135);
  __Pyx_GIVEREF(__pyx_tuple__135);
  __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(4, 0, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__135, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_from_text_and_lengths, 237, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 237, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":278
 *         return self
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_text(cls, text):
 * 
 */
  __pyx_tuple__136 = PyTuple_Pack(7, __pyx_n_s_cls, __pyx_n_s_text, __pyx_n_s_reference_names, __pyx_n_s_reference_lengths, __pyx_n_s_line, __pyx_n_s_fields, __pyx_n_s_x); if (unlikely(!__pyx_tuple__136)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__136);
  __Pyx_GIVEREF(__pyx_tuple__136);
  __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__136, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_from_text, 278, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 278, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":295
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_dict(cls, header_dict):
 * 
 */
  __pyx_tuple__137 = PyTuple_Pack(9, __pyx_n_s_cls, __pyx_n_s_header_dict, __pyx_n_s_lines, __pyx_n_s_record, __pyx_n_s_data, __pyx_n_s_fields, __pyx_n_s_text, __pyx_n_s_reference_names, __pyx_n_s_reference_lengths); if (unlikely(!__pyx_tuple__137)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__137);
  __Pyx_GIVEREF(__pyx_tuple__137);
  __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__137, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_from_dict, 295, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 295, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":336
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 */
  __pyx_tuple__138 = PyTuple_Pack(7, __pyx_n_s_cls, __pyx_n_s_reference_names, __pyx_n_s_reference_lengths, __pyx_n_s_text, __pyx_n_s_add_sq_text, __pyx_n_s_x, __pyx_n_s_y); if (unlikely(!__pyx_tuple__138)) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__138);
  __Pyx_GIVEREF(__pyx_tuple__138);
  __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(5, 0, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__138, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_from_references, 336, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 336, __pyx_L1_error)
  __pyx_tuple__139 = PyTuple_Pack(2, Py_None, Py_True); if (unlikely(!__pyx_tuple__139)) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__139);
  __Pyx_GIVEREF(__pyx_tuple__139);

  /* "pysam/libcalignmentfile.pyx":356
 *         return self.ptr != NULL
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))
 * 
 */
  __pyx_tuple__140 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__140)) __PYX_ERR(0, 356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__140);
  __Pyx_GIVEREF(__pyx_tuple__140);
  __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_copy, 356, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 356, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":388
 *             return tuple(t)
 * 
 *     def _build_sequence_section(self):             # <<<<<<<<<<<<<<
 *         """return sequence section of header.
 * 
 */
  __pyx_tuple__141 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_x, __pyx_n_s_text); if (unlikely(!__pyx_tuple__141)) __PYX_ERR(0, 388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__141);
  __Pyx_GIVEREF(__pyx_tuple__141);
  __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__141, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_build_sequence_section, 388, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 388, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":404
 *         return "".join(text)
 * 
 *     def to_dict(self):             # <<<<<<<<<<<<<<
 *         """return two-level dictionary with header information from the file.
 * 
 */
  __pyx_tuple__142 = PyTuple_Pack(14, __pyx_n_s_self, __pyx_n_s_result, __pyx_n_s_t, __pyx_n_s_line, __pyx_n_s_fields, __pyx_n_s_record, __pyx_n_s_x, __pyx_n_s_idx, __pyx_n_s_field, __pyx_n_s_key, __pyx_n_s_value, __pyx_n_s_sq, __pyx_n_s_ref, __pyx_n_s_length); if (unlikely(!__pyx_tuple__142)) __PYX_ERR(0, 404, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__142);
  __Pyx_GIVEREF(__pyx_tuple__142);
  __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__142, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_to_dict, 404, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 404, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":496
 *         return result
 * 
 *     def as_dict(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()
 */
  __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_as_dict, 496, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) __PYX_ERR(0, 496, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":500
 *         return self.to_dict()
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         if tid == -1:
 *             return None
 */
  __pyx_tuple__143 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_tid); if (unlikely(!__pyx_tuple__143)) __PYX_ERR(0, 500, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__143);
  __Pyx_GIVEREF(__pyx_tuple__143);
  __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__143, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get_reference_name, 500, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 500, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":508
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:
 */
  __pyx_tuple__144 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_reference, __pyx_n_s_tid); if (unlikely(!__pyx_tuple__144)) __PYX_ERR(0, 508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__144);
  __Pyx_GIVEREF(__pyx_tuple__144);
  __pyx_codeobj__26 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__144, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get_reference_length, 508, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__26)) __PYX_ERR(0, 508, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":515
 *             return self.ptr.target_len[tid]
 * 
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */
  __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__143, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_is_valid_tid, 515, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 515, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":523
 *         return 0 <= tid < self.ptr.n_targets
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */
  __pyx_codeobj__28 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__144, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get_tid, 523, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__28)) __PYX_ERR(0, 523, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":559
 *         return self.to_dict().__getitem__(key)
 * 
 *     def items(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */
  __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_items, 559, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 559, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":563
 * 
 *     # PY2 compatibility
 *     def iteritems(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */
  __pyx_codeobj__32 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_iteritems, 563, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__32)) __PYX_ERR(0, 563, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":566
 *         return self.to_dict().items()
 * 
 *     def keys(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().keys()
 * 
 */
  __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_keys, 566, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 566, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":569
 *         return self.to_dict().keys()
 * 
 *     def values(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().values()
 * 
 */
  __pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_values, 569, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) __PYX_ERR(0, 569, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":572
 *         return self.to_dict().values()
 * 
 *     def get(self, *args):             # <<<<<<<<<<<<<<
 *         return self.to_dict().get(*args)
 * 
 */
  __pyx_tuple__145 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_args); if (unlikely(!__pyx_tuple__145)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__145);
  __Pyx_GIVEREF(__pyx_tuple__145);
  __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARARGS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__145, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get, 572, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 572, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_tuple__146 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_pyx_state); if (unlikely(!__pyx_tuple__146)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__146);
  __Pyx_GIVEREF(__pyx_tuple__146);
  __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":758
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 *     def has_index(self):             # <<<<<<<<<<<<<<
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 */
  __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_has_index, 758, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 758, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":763
 *         return self.index != NULL
 * 
 *     def check_index(self):             # <<<<<<<<<<<<<<
 *         """return True if index is present.
 * 
 */
  __pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_check_index, 763, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(0, 763, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               mode=None,
 */
  __pyx_tuple__147 = PyTuple_Pack(30, __pyx_n_s_self, __pyx_n_s_filepath_or_object, __pyx_n_s_mode, __pyx_n_s_template, __pyx_n_s_reference_names, __pyx_n_s_reference_lengths, __pyx_n_s_reference_filename, __pyx_n_s_text, __pyx_n_s_header, __pyx_n_s_port, __pyx_n_s_add_sq_text, __pyx_n_s_add_sam_header, __pyx_n_s_check_header, __pyx_n_s_check_sq, __pyx_n_s_index_filename, __pyx_n_s_filepath_index, __pyx_n_s_require_index, __pyx_n_s_referencenames, __pyx_n_s_referencelengths, __pyx_n_s_duplicate_filehandle, __pyx_n_s_ignore_truncation, __pyx_n_s_format_options, __pyx_n_s_threads, __pyx_n_s_cfilename, __pyx_n_s_creference_filename, __pyx_n_s_cindexname, __pyx_n_s_cmode, __pyx_n_s_hdr, __pyx_n_s_filename, __pyx_n_s_bfile_name); if (unlikely(!__pyx_tuple__147)) __PYX_ERR(0, 787, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__147);
  __Pyx_GIVEREF(__pyx_tuple__147);
  __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(23, 0, 0, 30, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__147, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_open, 787, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 787, __pyx_L1_error)
  __pyx_tuple__148 = PyTuple_Pack(21, Py_None, Py_None, Py_None, Py_None, Py_None, Py_None, Py_None, Py_None, Py_True, Py_True, Py_True, Py_True, Py_None, Py_None, Py_False, Py_None, Py_None, Py_True, Py_False, Py_None, __pyx_int_1); if (unlikely(!__pyx_tuple__148)) __PYX_ERR(0, 787, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__148);
  __Pyx_GIVEREF(__pyx_tuple__148);

  /* "pysam/libcalignmentfile.pyx":1028
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */
  __pyx_tuple__149 = PyTuple_Pack(14, __pyx_n_s_self, __pyx_n_s_contig, __pyx_n_s_start, __pyx_n_s_stop, __pyx_n_s_region, __pyx_n_s_tid, __pyx_n_s_until_eof, __pyx_n_s_multiple_iterators, __pyx_n_s_reference, __pyx_n_s_end, __pyx_n_s_rtid, __pyx_n_s_rstart, __pyx_n_s_rstop, __pyx_n_s_has_coord); if (unlikely(!__pyx_tuple__149)) __PYX_ERR(0, 1028, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__149);
  __Pyx_GIVEREF(__pyx_tuple__149);
  __pyx_codeobj__53 = (PyObject*)__Pyx_PyCode_New(10, 0, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__149, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_fetch, 1028, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__53)) __PYX_ERR(0, 1028, __pyx_L1_error)
  __pyx_tuple__150 = PyTuple_Pack(9, Py_None, Py_None, Py_None, Py_None, Py_None, Py_False, Py_False, Py_None, Py_None); if (unlikely(!__pyx_tuple__150)) __PYX_ERR(0, 1028, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__150);
  __Pyx_GIVEREF(__pyx_tuple__150);

  /* "pysam/libcalignmentfile.pyx":1133
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return an iterator over the first n alignments.
 * 
 */
  __pyx_tuple__151 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_n, __pyx_n_s_multiple_iterators); if (unlikely(!__pyx_tuple__151)) __PYX_ERR(0, 1133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__151);
  __Pyx_GIVEREF(__pyx_tuple__151);
  __pyx_codeobj__57 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__151, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_head, 1133, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__57)) __PYX_ERR(0, 1133, __pyx_L1_error)
  __pyx_tuple__152 = PyTuple_Pack(1, Py_True); if (unlikely(!__pyx_tuple__152)) __PYX_ERR(0, 1133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__152);
  __Pyx_GIVEREF(__pyx_tuple__152);

  /* "pysam/libcalignmentfile.pyx":1155
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self, AlignedSegment read):             # <<<<<<<<<<<<<<
 *         '''return the mate of :class:`pysam.AlignedSegment` `read`.
 * 
 */
  __pyx_tuple__153 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_read, __pyx_n_s_flag, __pyx_n_s_x, __pyx_n_s_mate); if (unlikely(!__pyx_tuple__153)) __PYX_ERR(0, 1155, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__153);
  __Pyx_GIVEREF(__pyx_tuple__153);
  __pyx_codeobj__58 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__153, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_mate, 1155, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__58)) __PYX_ERR(0, 1155, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1214
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */
  __pyx_tuple__154 = PyTuple_Pack(12, __pyx_n_s_self, __pyx_n_s_contig, __pyx_n_s_start, __pyx_n_s_stop, __pyx_n_s_region, __pyx_n_s_reference, __pyx_n_s_end, __pyx_n_s_kwargs, __pyx_n_s_rtid, __pyx_n_s_has_coord, __pyx_n_s_rstart, __pyx_n_s_rstop); if (unlikely(!__pyx_tuple__154)) __PYX_ERR(0, 1214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__154);
  __Pyx_GIVEREF(__pyx_tuple__154);
  __pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(7, 0, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__154, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_pileup, 1214, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) __PYX_ERR(0, 1214, __pyx_L1_error)
  __pyx_tuple__155 = PyTuple_Pack(6, Py_None, Py_None, Py_None, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__155)) __PYX_ERR(0, 1214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__155);
  __Pyx_GIVEREF(__pyx_tuple__155);

  /* "pysam/libcalignmentfile.pyx":1354
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */
  __pyx_tuple__156 = PyTuple_Pack(12, __pyx_n_s_self, __pyx_n_s_contig, __pyx_n_s_start, __pyx_n_s_stop, __pyx_n_s_region, __pyx_n_s_until_eof, __pyx_n_s_read_callback, __pyx_n_s_reference, __pyx_n_s_end, __pyx_n_s_read, __pyx_n_s_counter, __pyx_n_s_filter_method); if (unlikely(!__pyx_tuple__156)) __PYX_ERR(0, 1354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__156);
  __Pyx_GIVEREF(__pyx_tuple__156);
  __pyx_codeobj__62 = (PyObject*)__Pyx_PyCode_New(9, 0, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__156, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_count, 1354, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__62)) __PYX_ERR(0, 1354, __pyx_L1_error)
  __pyx_tuple__157 = PyTuple_Pack(8, Py_None, Py_None, Py_None, Py_None, Py_False, __pyx_n_u_nofilter, Py_None, Py_None); if (unlikely(!__pyx_tuple__157)) __PYX_ERR(0, 1354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__157);
  __Pyx_GIVEREF(__pyx_tuple__157);

  /* "pysam/libcalignmentfile.pyx":1457
 *         return counter
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking             # <<<<<<<<<<<<<<
 *     def count_coverage(self,
 *                        contig,
 */
  __pyx_tuple__158 = PyTuple_Pack(26, __pyx_n_s_self, __pyx_n_s_contig, __pyx_n_s_start, __pyx_n_s_stop, __pyx_n_s_region, __pyx_n_s_quality_threshold, __pyx_n_s_read_callback, __pyx_n_s_reference, __pyx_n_s_end, __pyx_n_s_contig_length, __pyx_n_s_start_2, __pyx_n_s_stop_2, __pyx_n_s_length, __pyx_n_s_int_array_template, __pyx_n_s_count_a, __pyx_n_s_count_c, __pyx_n_s_count_g, __pyx_n_s_count_t, __pyx_n_s_read, __pyx_n_s_seq, __pyx_n_s_quality, __pyx_n_s_qpos, __pyx_n_s_refpos, __pyx_n_s_c, __pyx_n_s_filter_method, __pyx_n_s_threshold); if (unlikely(!__pyx_tuple__158)) __PYX_ERR(0, 1457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__158);
  __Pyx_GIVEREF(__pyx_tuple__158);
  __pyx_codeobj__63 = (PyObject*)__Pyx_PyCode_New(9, 0, 0, 26, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__158, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_count_coverage, 1457, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__63)) __PYX_ERR(0, 1457, __pyx_L1_error)
  __pyx_tuple__159 = PyTuple_Pack(7, Py_None, Py_None, Py_None, __pyx_int_15, __pyx_n_u_all, Py_None, Py_None); if (unlikely(!__pyx_tuple__159)) __PYX_ERR(0, 1457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__159);
  __Pyx_GIVEREF(__pyx_tuple__159);

  /* "pysam/libcalignmentfile.pyx":1609
 *         return count_a, count_c, count_g, count_t
 * 
 *     def find_introns_slow(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */
  __pyx_tuple__160 = PyTuple_Pack(9, __pyx_n_s_self, __pyx_n_s_read_iterator, __pyx_n_s_res, __pyx_n_s_r, __pyx_n_s_last_read_pos, __pyx_n_s_read_loc, __pyx_n_s_genome_loc, __pyx_n_s_start, __pyx_n_s_stop); if (unlikely(!__pyx_tuple__160)) __PYX_ERR(0, 1609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__160);
  __Pyx_GIVEREF(__pyx_tuple__160);
  __pyx_codeobj__66 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__160, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_find_introns_slow, 1609, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__66)) __PYX_ERR(0, 1609, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1633
 *         return res
 * 
 *     def find_introns(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */
  __pyx_tuple__161 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_read_iterator, __pyx_n_s_base_position, __pyx_n_s_junc_start, __pyx_n_s_nt, __pyx_n_s_op, __pyx_n_s_r, __pyx_n_s_BAM_CREF_SKIP, __pyx_n_s_res, __pyx_n_s_match_or_deletion, __pyx_n_s_cigar); if (unlikely(!__pyx_tuple__161)) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__161);
  __Pyx_GIVEREF(__pyx_tuple__161);
  __pyx_codeobj__67 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__161, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_find_introns, 1633, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__67)) __PYX_ERR(0, 1633, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1667
 * 
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 */
  __pyx_tuple__162 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_ret); if (unlikely(!__pyx_tuple__162)) __PYX_ERR(0, 1667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__162);
  __Pyx_GIVEREF(__pyx_tuple__162);
  __pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__162, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_close, 1667, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) __PYX_ERR(0, 1667, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1713
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedSegment` to disk.
 */
  __pyx_tuple__163 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_read); if (unlikely(!__pyx_tuple__163)) __PYX_ERR(0, 1713, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__163);
  __Pyx_GIVEREF(__pyx_tuple__163);
  __pyx_codeobj__69 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__163, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_write, 1713, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__69)) __PYX_ERR(0, 1713, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1751
 * 
 *     # context manager interface
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_enter, 1751, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) __PYX_ERR(0, 1751, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1754
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 *         return False
 */
  __pyx_tuple__164 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_exc_type, __pyx_n_s_exc_value, __pyx_n_s_traceback); if (unlikely(!__pyx_tuple__164)) __PYX_ERR(0, 1754, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__164);
  __Pyx_GIVEREF(__pyx_tuple__164);
  __pyx_codeobj__71 = (PyObject*)__Pyx_PyCode_New(4, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__164, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_exit, 1754, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__71)) __PYX_ERR(0, 1754, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1813
 *             return n
 * 
 *     def get_index_statistics(self):             # <<<<<<<<<<<<<<
 *         """return statistics about mapped/unmapped reads per chromosome as
 *         they are stored in the index, similarly to the statistics printed
 */
  __pyx_tuple__165 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_tid, __pyx_n_s_mapped, __pyx_n_s_unmapped, __pyx_n_s_results); if (unlikely(!__pyx_tuple__165)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__165);
  __Pyx_GIVEREF(__pyx_tuple__165);
  __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__165, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get_index_statistics, 1813, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(0, 1813, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1884
 *     ###########################################
 *     # methods/properties referencing the header
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */
  __pyx_codeobj__74 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__143, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_is_valid_tid, 1884, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__74)) __PYX_ERR(0, 1884, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1894
 *         return self.header.is_valid_tid(tid)
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */
  __pyx_tuple__166 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_reference); if (unlikely(!__pyx_tuple__166)) __PYX_ERR(0, 1894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__166);
  __Pyx_GIVEREF(__pyx_tuple__166);
  __pyx_codeobj__76 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__166, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get_tid, 1894, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__76)) __PYX_ERR(0, 1894, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1905
 *         return self.header.get_tid(reference)
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 */
  __pyx_codeobj__77 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__143, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get_reference_name, 1905, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__77)) __PYX_ERR(0, 1905, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1913
 *         return self.header.get_reference_name(tid)
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 */
  __pyx_codeobj__78 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__166, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_get_reference_length, 1913, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__78)) __PYX_ERR(0, 1913, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1961
 * 
 *     # Compatibility functions for pysam < 0.8.3
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)
 */
  __pyx_codeobj__79 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__166, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_gettid, 1961, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__79)) __PYX_ERR(0, 1961, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":1965
 *         return self.get_tid(reference)
 * 
 *     def getrname(self, tid):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)
 */
  __pyx_codeobj__80 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__143, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_getrname, 1965, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__80)) __PYX_ERR(0, 1965, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__81 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__81)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_codeobj__82 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__82)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__84 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__84)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_codeobj__85 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__85)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__88 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__88)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 */
  __pyx_codeobj__89 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__89)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__90 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__90)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_codeobj__91 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__91)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__92 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__92)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_codeobj__93 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__93)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2231
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 */
  __pyx_codeobj__95 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_nextiter, 2231, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__95)) __PYX_ERR(0, 2231, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__96 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__96)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_codeobj__97 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__97)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__98 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__98)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_codeobj__99 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__99)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2524
 *             return self.iterdata.seq_len
 * 
 *     def add_reference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 */
  __pyx_tuple__167 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_fastafile); if (unlikely(!__pyx_tuple__167)) __PYX_ERR(0, 2524, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__167);
  __Pyx_GIVEREF(__pyx_tuple__167);
  __pyx_codeobj__100 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__167, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_add_reference, 2524, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__100)) __PYX_ERR(0, 2524, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2533
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def has_reference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */
  __pyx_codeobj__101 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_has_reference, 2533, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__101)) __PYX_ERR(0, 2533, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2688
 *     # backwards compatibility
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 */
  __pyx_codeobj__103 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_hasReference, 2688, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__103)) __PYX_ERR(0, 2688, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2692
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *         return self.add_reference(fastafile)
 * 
 */
  __pyx_codeobj__104 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__167, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_addReference, 2692, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__104)) __PYX_ERR(0, 2692, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__105 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__105)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_codeobj__106 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__106)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__109 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__109)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_codeobj__110 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__110)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__111 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__111)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_codeobj__112 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__112)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__113 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__113)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_codeobj__114 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__114)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */
  __pyx_tuple__168 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_state, __pyx_n_s_dict_2, __pyx_n_s_use_setstate); if (unlikely(!__pyx_tuple__168)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__168);
  __Pyx_GIVEREF(__pyx_tuple__168);
  __pyx_codeobj__115 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__168, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__115)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */
  __pyx_codeobj__116 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 16, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__116)) __PYX_ERR(3, 16, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2929
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build the index.'''
 * 
 */
  __pyx_tuple__169 = PyTuple_Pack(6, __pyx_n_s_self, __pyx_n_s_ret, __pyx_n_s_b, __pyx_n_s_pos, __pyx_n_s_hdr, __pyx_n_s_qname); if (unlikely(!__pyx_tuple__169)) __PYX_ERR(0, 2929, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__169);
  __Pyx_GIVEREF(__pyx_tuple__169);
  __pyx_codeobj__118 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__169, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_build, 2929, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__118)) __PYX_ERR(0, 2929, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":2956
 *         bam_destroy1(b)
 * 
 *     def find(self, query_name):             # <<<<<<<<<<<<<<
 *         '''find `query_name` in index.
 * 
 */
  __pyx_tuple__170 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_query_name); if (unlikely(!__pyx_tuple__170)) __PYX_ERR(0, 2956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__170);
  __Pyx_GIVEREF(__pyx_tuple__170);
  __pyx_codeobj__119 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__170, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_pysam_libcalignmentfile_pyx, __pyx_n_s_find, 2956, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__119)) __PYX_ERR(0, 2956, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_codeobj__120 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__120)) __PYX_ERR(3, 1, __pyx_L1_error)

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 */
  __pyx_codeobj__121 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__146, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__121)) __PYX_ERR(3, 3, __pyx_L1_error)

  /* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_tuple__171 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__171)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__171);
  __Pyx_GIVEREF(__pyx_tuple__171);
  __pyx_codeobj__122 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__171, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_SNPCall, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__122)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}
/* #### Code section: init_constants ### */

static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) {
  __pyx_umethod_PyDict_Type_get.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_get.method_name = &__pyx_n_s_get;
  if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_13 = PyInt_FromLong(13); if (unlikely(!__pyx_int_13)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1796 = PyInt_FromLong(1796); if (unlikely(!__pyx_int_1796)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_18041500 = PyInt_FromLong(18041500L); if (unlikely(!__pyx_int_18041500)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_84615809 = PyInt_FromLong(84615809L); if (unlikely(!__pyx_int_84615809)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_239452417 = PyInt_FromLong(239452417L); if (unlikely(!__pyx_int_239452417)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_2 = PyInt_FromLong(-2); if (unlikely(!__pyx_int_neg_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### Code section: init_globals ### */

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  /* AssertionsEnabled.init */
  if (likely(__Pyx_init_assertions_enabled() == 0)); else

if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1, __pyx_L1_error)

  return 0;
  __pyx_L1_error:;
  return -1;
}
/* #### Code section: init_module ### */

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  #if CYTHON_USE_TYPE_SPECS
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader_spec, NULL); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader)) __PYX_ERR(0, 195, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader_spec, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 195, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader = &__pyx_type_5pysam_17libcalignmentfile_AlignmentHeader;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 195, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  #if CYTHON_UPDATE_DESCRIPTOR_DOC
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, "__str__"); if (unlikely(!wrapper)) __PYX_ERR(0, 195, __pyx_L1_error)
    if (__Pyx_IS_TYPE(wrapper, &PyWrapperDescr_Type)) {
      __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__.doc = __pyx_doc_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_17libcalignmentfile_15AlignmentHeader_32__str__;
    }
  }
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_AlignmentHeader, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 195, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader) < 0) __PYX_ERR(0, 195, __pyx_L1_error)
  #endif
  __pyx_t_1 = PyImport_ImportModule("pysam.libchtslib"); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5pysam_10libchtslib_HTSFile = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libchtslib", "HTSFile", sizeof(struct __pyx_obj_5pysam_10libchtslib_HTSFile), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_10libchtslib_HTSFile),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_10libchtslib_HTSFile) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_vtabptr_5pysam_10libchtslib_HTSFile = (struct __pyx_vtabstruct_5pysam_10libchtslib_HTSFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_10libchtslib_HTSFile); if (unlikely(!__pyx_vtabptr_5pysam_10libchtslib_HTSFile)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile = &__pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.__pyx_base = *__pyx_vtabptr_5pysam_10libchtslib_HTSFile;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_cnext;
  __pyx_vtable_5pysam_17libcalignmentfile_AlignmentFile.write = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *, int __pyx_skip_dispatch))__pyx_f_5pysam_17libcalignmentfile_13AlignmentFile_write;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_10libchtslib_HTSFile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_AlignmentFile_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile)) __PYX_ERR(0, 582, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_AlignmentFile_spec, __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile = &__pyx_type_5pysam_17libcalignmentfile_AlignmentFile;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile->tp_base = __pyx_ptype_5pysam_10libchtslib_HTSFile;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_vtabptr_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_AlignmentFile, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile) < 0) __PYX_ERR(0, 582, __pyx_L1_error)
  #endif
  #if CYTHON_USE_TYPE_SPECS
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorRow_spec, NULL); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow)) __PYX_ERR(0, 1970, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorRow_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1970, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow = &__pyx_type_5pysam_17libcalignmentfile_IteratorRow;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1970, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRow, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1970, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow) < 0) __PYX_ERR(0, 1970, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *))__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowRegion *))__pyx_f_5pysam_17libcalignmentfile_17IteratorRowRegion_cnext;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion)) __PYX_ERR(0, 2058, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2058, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowRegion;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2058, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2058, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2058, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowRegion, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2058, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowRegion) < 0) __PYX_ERR(0, 2058, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *))__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowHead.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowHead *))__pyx_f_5pysam_17libcalignmentfile_15IteratorRowHead_cnext;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead)) __PYX_ERR(0, 2119, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2119, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowHead;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2119, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2119, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2119, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowHead, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2119, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowHead) < 0) __PYX_ERR(0, 2119, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *))__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowAll *))__pyx_f_5pysam_17libcalignmentfile_14IteratorRowAll_cnext;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2170, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll)) __PYX_ERR(0, 2170, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2170, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAll;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2170, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2170, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2170, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowAll, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2170, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAll) < 0) __PYX_ERR(0, 2170, __pyx_L1_error)
  #endif
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2212, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs)) __PYX_ERR(0, 2212, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2212, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowAllRefs;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2212, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowAllRefs, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2212, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs) < 0) __PYX_ERR(0, 2212, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *))__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_getCurrent;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorRowSelection *))__pyx_f_5pysam_17libcalignmentfile_20IteratorRowSelection_cnext;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRow); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2274, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection)) __PYX_ERR(0, 2274, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2274, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection = &__pyx_type_5pysam_17libcalignmentfile_IteratorRowSelection;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorRow;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2274, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2274, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2274, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorRowSelection, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2274, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorRowSelection) < 0) __PYX_ERR(0, 2274, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.cnext = (int (*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_cnext;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.get_sequence = (char *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_get_sequence;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._setup_iterator = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator *__pyx_optional_args))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_iterator;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._setup_raw_rest_iterator = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__setup_raw_rest_iterator;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_reset;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn._free_pileup_iter = (PyObject *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn__free_pileup_iter;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_5pysam_17libcalignmentfile_IteratorColumn *))__pyx_f_5pysam_17libcalignmentfile_14IteratorColumn_getSequence;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorColumn_spec, NULL); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn)) __PYX_ERR(0, 2446, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumn_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2446, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumn;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2446, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2446, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2446, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumn, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2446, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn) < 0) __PYX_ERR(0, 2446, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2696, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion)) __PYX_ERR(0, 2696, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2696, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnRegion;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2696, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2696, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2696, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumnRegion, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2696, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnRegion) < 0) __PYX_ERR(0, 2696, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2746, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs)) __PYX_ERR(0, 2746, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2746, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAllRefs;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2746, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2746, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2746, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumnAllRefs, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2746, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAllRefs) < 0) __PYX_ERR(0, 2746, __pyx_L1_error)
  #endif
  __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll = &__pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAll;
  __pyx_vtable_5pysam_17libcalignmentfile_IteratorColumnAll.__pyx_base = *__pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumn;
  #if CYTHON_USE_TYPE_SPECS
  __pyx_t_2 = PyTuple_Pack(1, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2788, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll_spec, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll)) __PYX_ERR(0, 2788, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll_spec, __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2788, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll = &__pyx_type_5pysam_17libcalignmentfile_IteratorColumnAll;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll->tp_base = __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn;
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2788, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (__Pyx_SetVtable(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll, __pyx_vtabptr_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2788, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_MergeVtables(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2788, __pyx_L1_error)
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IteratorColumnAll, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2788, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IteratorColumnAll) < 0) __PYX_ERR(0, 2788, __pyx_L1_error)
  #endif
  #if CYTHON_USE_TYPE_SPECS
  __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_IndexedReads_spec, NULL); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads)) __PYX_ERR(0, 2876, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_IndexedReads_spec, __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2876, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads = &__pyx_type_5pysam_17libcalignmentfile_IndexedReads;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2876, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_IndexedReads, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2876, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_IndexedReads) < 0) __PYX_ERR(0, 2876, __pyx_L1_error)
  #endif
  #if CYTHON_USE_TYPE_SPECS
  __pyx_ptype_5pysam_17libcalignmentfile_SNPCall = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_5pysam_17libcalignmentfile_SNPCall_spec, NULL); if (unlikely(!__pyx_ptype_5pysam_17libcalignmentfile_SNPCall)) __PYX_ERR(0, 2817, __pyx_L1_error)
  if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_5pysam_17libcalignmentfile_SNPCall_spec, __pyx_ptype_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2817, __pyx_L1_error)
  #else
  __pyx_ptype_5pysam_17libcalignmentfile_SNPCall = &__pyx_type_5pysam_17libcalignmentfile_SNPCall;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  #endif
  #if !CYTHON_USE_TYPE_SPECS
  if (__Pyx_PyType_Ready(__pyx_ptype_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2817, __pyx_L1_error)
  #endif
  #if PY_MAJOR_VERSION < 3
  __pyx_ptype_5pysam_17libcalignmentfile_SNPCall->tp_print = 0;
  #endif
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_5pysam_17libcalignmentfile_SNPCall->tp_dictoffset && __pyx_ptype_5pysam_17libcalignmentfile_SNPCall->tp_getattro == PyObject_GenericGetAttr)) {
    __pyx_ptype_5pysam_17libcalignmentfile_SNPCall->tp_getattro = __Pyx_PyObject_GenericGetAttr;
  }
  #endif
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_SNPCall, (PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2817, __pyx_L1_error)
  #if !CYTHON_COMPILING_IN_LIMITED_API
  if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_5pysam_17libcalignmentfile_SNPCall) < 0) __PYX_ERR(0, 2817, __pyx_L1_error)
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType_3_0_11(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "type", 
  #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(PyTypeObject),
  #elif CYTHON_COMPILING_IN_LIMITED_API
  sizeof(PyTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(PyHeapTypeObject),
  #endif
  __Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_7cpython_4type_type) __PYX_ERR(5, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType_3_0_11(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(PyBoolObject),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_7cpython_4bool_bool) __PYX_ERR(6, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_t_1)) __PYX_ERR(7, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType_3_0_11(__pyx_t_1, __Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(PyComplexObject),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_7cpython_7complex_complex) __PYX_ERR(7, 15, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("array"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 69, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_7cpython_5array_array = __Pyx_ImportType_3_0_11(__pyx_t_1, "array", "array", sizeof(arrayobject), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(arrayobject),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_7cpython_5array_array) __PYX_ERR(2, 69, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("pysam.libcfaidx"); if (unlikely(!__pyx_t_1)) __PYX_ERR(8, 38, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5pysam_9libcfaidx_FastaFile = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastaFile), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_9libcfaidx_FastaFile),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_9libcfaidx_FastaFile) __PYX_ERR(8, 38, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastaFile); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastaFile)) __PYX_ERR(8, 38, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastqProxy = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_9libcfaidx_FastqProxy),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_9libcfaidx_FastqProxy) __PYX_ERR(8, 46, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastqProxy = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqProxy); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqProxy)) __PYX_ERR(8, 46, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastxRecord = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcfaidx", "FastxRecord", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_9libcfaidx_FastxRecord),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_9libcfaidx_FastxRecord) __PYX_ERR(8, 53, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastxRecord = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxRecord*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxRecord); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxRecord)) __PYX_ERR(8, 53, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastxFile = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastxFile), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_9libcfaidx_FastxFile),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_9libcfaidx_FastxFile) __PYX_ERR(8, 62, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastxFile); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastxFile)) __PYX_ERR(8, 62, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_FastqFile = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_FastqFile), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_9libcfaidx_FastqFile),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_9libcfaidx_FastqFile) __PYX_ERR(8, 74, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_FastqFile); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_FastqFile)) __PYX_ERR(8, 74, __pyx_L1_error)
  __pyx_ptype_5pysam_9libcfaidx_Fastafile = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_9libcfaidx_Fastafile), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_9libcfaidx_Fastafile),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_9libcfaidx_Fastafile) __PYX_ERR(8, 79, __pyx_L1_error)
  __pyx_vtabptr_5pysam_9libcfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_9libcfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9libcfaidx_Fastafile); if (unlikely(!__pyx_vtabptr_5pysam_9libcfaidx_Fastafile)) __PYX_ERR(8, 79, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("pysam.libcalignedsegment"); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 35, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcalignedsegment", "AlignedSegment", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment) __PYX_ERR(9, 35, __pyx_L1_error)
  __pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment = (struct __pyx_vtabstruct_5pysam_18libcalignedsegment_AlignedSegment*)__Pyx_GetVtable(__pyx_ptype_5pysam_18libcalignedsegment_AlignedSegment); if (unlikely(!__pyx_vtabptr_5pysam_18libcalignedsegment_AlignedSegment)) __PYX_ERR(9, 35, __pyx_L1_error)
  __pyx_ptype_5pysam_18libcalignedsegment_PileupColumn = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcalignedsegment", "PileupColumn", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_18libcalignedsegment_PileupColumn) __PYX_ERR(9, 66, __pyx_L1_error)
  __pyx_ptype_5pysam_18libcalignedsegment_PileupRead = __Pyx_ImportType_3_0_11(__pyx_t_1, "pysam.libcalignedsegment", "PileupRead", sizeof(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead), __PYX_GET_STRUCT_ALIGNMENT_3_0_11(struct __pyx_obj_5pysam_18libcalignedsegment_PileupRead),__Pyx_ImportType_CheckSize_Warn_3_0_11); if (!__pyx_ptype_5pysam_18libcalignedsegment_PileupRead) __PYX_ERR(9, 76, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __pyx_t_1 = PyImport_ImportModule("pysam.libcalignedsegment"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "makeAlignedSegment", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makeAlignedSegment, "struct __pyx_obj_5pysam_18libcalignedsegment_AlignedSegment *(bam1_t *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "makePileupColumn", (void (**)(void))&__pyx_f_5pysam_18libcalignedsegment_makePileupColumn, "struct __pyx_obj_5pysam_18libcalignedsegment_PileupColumn *(bam_pileup1_t const **, int, int, int, uint32_t, char *, struct __pyx_obj_5pysam_17libcalignmentfile_AlignmentHeader *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("pysam.libcutils"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_9libcutils_charptr_to_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "force_str", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_str *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "force_bytes", (void (**)(void))&__pyx_f_5pysam_9libcutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_9libcutils_force_bytes *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "encode_filename", (void (**)(void))&__pyx_f_5pysam_9libcutils_encode_filename, "PyObject *(PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction_3_0_11(__pyx_t_1, "from_string_and_size", (void (**)(void))&__pyx_f_5pysam_9libcutils_from_string_and_size, "PyObject *(char const *, size_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}


#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec_libcalignmentfile(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec_libcalignmentfile},
  {0, NULL}
};
#endif

#ifdef __cplusplus
namespace {
  struct PyModuleDef __pyx_moduledef =
  #else
  static struct PyModuleDef __pyx_moduledef =
  #endif
  {
      PyModuleDef_HEAD_INIT,
      "libcalignmentfile",
      0, /* m_doc */
    #if CYTHON_PEP489_MULTI_PHASE_INIT
      0, /* m_size */
    #elif CYTHON_USE_MODULE_STATE
      sizeof(__pyx_mstate), /* m_size */
    #else
      -1, /* m_size */
    #endif
      __pyx_methods /* m_methods */,
    #if CYTHON_PEP489_MULTI_PHASE_INIT
      __pyx_moduledef_slots, /* m_slots */
    #else
      NULL, /* m_reload */
    #endif
    #if CYTHON_USE_MODULE_STATE
      __pyx_m_traverse, /* m_traverse */
      __pyx_m_clear, /* m_clear */
      NULL /* m_free */
    #else
      NULL, /* m_traverse */
      NULL, /* m_clear */
      NULL /* m_free */
    #endif
  };
  #ifdef __cplusplus
} /* anonymous namespace */
#endif
#endif

#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC initlibcalignmentfile(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC initlibcalignmentfile(void)
#else
__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
#if CYTHON_COMPILING_IN_LIMITED_API
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none)
#else
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none)
#endif
{
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
#if CYTHON_COMPILING_IN_LIMITED_API
            result = PyModule_AddObject(module, to_name, value);
#else
            result = PyDict_SetItemString(moddict, to_name, value);
#endif
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    CYTHON_UNUSED_VAR(def);
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
#if CYTHON_COMPILING_IN_LIMITED_API
    moddict = module;
#else
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
#endif
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec_libcalignmentfile(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  int stringtab_initialized = 0;
  #if CYTHON_USE_MODULE_STATE
  int pystate_addmodule_run = 0;
  #endif
  __Pyx_TraceDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module 'libcalignmentfile' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  /*--- Module creation code ---*/
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("libcalignmentfile", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #elif CYTHON_USE_MODULE_STATE
  __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  {
    int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef);
    __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "libcalignmentfile" pseudovariable */
    if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
    pystate_addmodule_run = 1;
  }
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #endif
  CYTHON_UNUSED_VAR(__pyx_t_1);
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_REFNANNY
__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
if (!__Pyx_RefNanny) {
  PyErr_Clear();
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  if (!__Pyx_RefNanny)
      Py_FatalError("failed to import 'refnanny' module");
}
#endif
  __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)", 0);
  if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_AsyncGen_USED
  if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  PyEval_InitThreads();
  #endif
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  stringtab_initialized = 1;
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_pysam__libcalignmentfile) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "pysam.libcalignmentfile")) {
      if (unlikely((PyDict_SetItemString(modules, "pysam.libcalignmentfile", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  (void)__Pyx_modinit_function_export_code();
  if (unlikely((__Pyx_modinit_type_init_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely((__Pyx_modinit_type_import_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_variable_import_code();
  if (unlikely((__Pyx_modinit_function_import_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_libcalignmentfile(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error));

  /* "pysam/libcalignmentfile.pyx":58
 * #
 * ########################################################
 * import os             # <<<<<<<<<<<<<<
 * import collections
 * try:
 */
  __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_os, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_2) < 0) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":59
 * ########################################################
 * import os
 * import collections             # <<<<<<<<<<<<<<
 * try:
 *     from collections.abc import Sequence, Mapping  # noqa
 */
  __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_collections, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_2) < 0) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":60
 * import os
 * import collections
 * try:             # <<<<<<<<<<<<<<
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_3, &__pyx_t_4);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_4);
    /*try:*/ {

      /* "pysam/libcalignmentfile.pyx":61
 * import collections
 * try:
 *     from collections.abc import Sequence, Mapping  # noqa             # <<<<<<<<<<<<<<
 * except ImportError:
 *     from collections import Sequence, Mapping  # noqa
 */
      __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_n_s_Sequence);
      __Pyx_GIVEREF(__pyx_n_s_Sequence);
      if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Sequence)) __PYX_ERR(0, 61, __pyx_L2_error);
      __Pyx_INCREF(__pyx_n_s_Mapping);
      __Pyx_GIVEREF(__pyx_n_s_Mapping);
      if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_Mapping)) __PYX_ERR(0, 61, __pyx_L2_error);
      __pyx_t_5 = __Pyx_Import(__pyx_n_s_collections_abc, __pyx_t_2, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Sequence, __pyx_t_2) < 0) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Mapping, __pyx_t_2) < 0) __PYX_ERR(0, 61, __pyx_L2_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "pysam/libcalignmentfile.pyx":60
 * import os
 * import collections
 * try:             # <<<<<<<<<<<<<<
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 */
    }
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L7_try_end;
    __pyx_L2_error:;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysam/libcalignmentfile.pyx":62
 * try:
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:             # <<<<<<<<<<<<<<
 *     from collections import Sequence, Mapping  # noqa
 * import re
 */
    __pyx_t_6 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ImportError);
    if (__pyx_t_6) {
      __Pyx_AddTraceback("pysam.libcalignmentfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_2, &__pyx_t_7) < 0) __PYX_ERR(0, 62, __pyx_L4_except_error)
      __Pyx_XGOTREF(__pyx_t_5);
      __Pyx_XGOTREF(__pyx_t_2);
      __Pyx_XGOTREF(__pyx_t_7);

      /* "pysam/libcalignmentfile.pyx":63
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 *     from collections import Sequence, Mapping  # noqa             # <<<<<<<<<<<<<<
 * import re
 * import warnings
 */
      __pyx_t_8 = PyList_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_n_s_Sequence);
      __Pyx_GIVEREF(__pyx_n_s_Sequence);
      if (__Pyx_PyList_SET_ITEM(__pyx_t_8, 0, __pyx_n_s_Sequence)) __PYX_ERR(0, 63, __pyx_L4_except_error);
      __Pyx_INCREF(__pyx_n_s_Mapping);
      __Pyx_GIVEREF(__pyx_n_s_Mapping);
      if (__Pyx_PyList_SET_ITEM(__pyx_t_8, 1, __pyx_n_s_Mapping)) __PYX_ERR(0, 63, __pyx_L4_except_error);
      __pyx_t_9 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_8, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_ImportFrom(__pyx_t_9, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Sequence, __pyx_t_8) < 0) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_ImportFrom(__pyx_t_9, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_Mapping, __pyx_t_8) < 0) __PYX_ERR(0, 63, __pyx_L4_except_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      goto __pyx_L3_exception_handled;
    }
    goto __pyx_L4_except_error;

    /* "pysam/libcalignmentfile.pyx":60
 * import os
 * import collections
 * try:             # <<<<<<<<<<<<<<
 *     from collections.abc import Sequence, Mapping  # noqa
 * except ImportError:
 */
    __pyx_L4_except_error:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_3, __pyx_t_4);
    goto __pyx_L1_error;
    __pyx_L3_exception_handled:;
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_XGIVEREF(__pyx_t_4);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_3, __pyx_t_4);
    __pyx_L7_try_end:;
  }

  /* "pysam/libcalignmentfile.pyx":64
 * except ImportError:
 *     from collections import Sequence, Mapping  # noqa
 * import re             # <<<<<<<<<<<<<<
 * import warnings
 * import array
 */
  __pyx_t_7 = __Pyx_ImportDottedModule(__pyx_n_s_re, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 64, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_7) < 0) __PYX_ERR(0, 64, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":65
 *     from collections import Sequence, Mapping  # noqa
 * import re
 * import warnings             # <<<<<<<<<<<<<<
 * import array
 * from libc.errno  cimport errno, EPIPE
 */
  __pyx_t_7 = __Pyx_ImportDottedModule(__pyx_n_s_warnings, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 65, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_warnings, __pyx_t_7) < 0) __PYX_ERR(0, 65, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":66
 * import re
 * import warnings
 * import array             # <<<<<<<<<<<<<<
 * from libc.errno  cimport errno, EPIPE
 * from libc.string cimport strcmp, strpbrk, strerror
 */
  __pyx_t_7 = __Pyx_ImportDottedModule(__pyx_n_s_array, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_7) < 0) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":79
 *                               HTS_IDX_SAVE_REMOTE, HTS_IDX_SILENT_FAIL
 * 
 * from io import StringIO             # <<<<<<<<<<<<<<
 * 
 * cimport cython
 */
  __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 79, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_StringIO);
  __Pyx_GIVEREF(__pyx_n_s_StringIO);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_StringIO)) __PYX_ERR(0, 79, __pyx_L1_error);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_io, __pyx_t_7, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_StringIO); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 79, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_StringIO, __pyx_t_7) < 0) __PYX_ERR(0, 79, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":84
 * 
 * 
 * __all__ = [             # <<<<<<<<<<<<<<
 *     "AlignmentFile",
 *     "AlignmentHeader",
 */
  __pyx_t_2 = PyList_New(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_AlignmentFile);
  __Pyx_GIVEREF(__pyx_n_u_AlignmentFile);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_AlignmentFile)) __PYX_ERR(0, 84, __pyx_L1_error);
  __Pyx_INCREF(__pyx_n_u_AlignmentHeader);
  __Pyx_GIVEREF(__pyx_n_u_AlignmentHeader);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_AlignmentHeader)) __PYX_ERR(0, 84, __pyx_L1_error);
  __Pyx_INCREF(__pyx_n_u_IteratorRow);
  __Pyx_GIVEREF(__pyx_n_u_IteratorRow);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_u_IteratorRow)) __PYX_ERR(0, 84, __pyx_L1_error);
  __Pyx_INCREF(__pyx_n_u_IteratorColumn);
  __Pyx_GIVEREF(__pyx_n_u_IteratorColumn);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_u_IteratorColumn)) __PYX_ERR(0, 84, __pyx_L1_error);
  __Pyx_INCREF(__pyx_n_u_IndexedReads);
  __Pyx_GIVEREF(__pyx_n_u_IndexedReads);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 4, __pyx_n_u_IndexedReads)) __PYX_ERR(0, 84, __pyx_L1_error);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all_2, __pyx_t_2) < 0) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":91
 *     "IndexedReads"]
 * 
 * IndexStats = collections.namedtuple("IndexStats",             # <<<<<<<<<<<<<<
 *                                     ("contig",
 *                                      "mapped",
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_collections); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_namedtuple); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 91, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":92
 * 
 * IndexStats = collections.namedtuple("IndexStats",
 *                                     ("contig",             # <<<<<<<<<<<<<<
 *                                      "mapped",
 *                                      "unmapped",
 */
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__127, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_IndexStats, __pyx_t_2) < 0) __PYX_ERR(0, 91, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":101
 * # maximum genomic coordinace
 * # for some reason, using 'int' causes overflow
 * cdef int MAX_POS = (1 << 31) - 1             # <<<<<<<<<<<<<<
 * 
 * # valid types for SAM headers
 */
  __pyx_v_5pysam_17libcalignmentfile_MAX_POS = 0x7fffffff;

  /* "pysam/libcalignmentfile.pyx":104
 * 
 * # valid types for SAM headers
 * VALID_HEADER_TYPES = {"HD" : Mapping,             # <<<<<<<<<<<<<<
 *                       "SQ" : Sequence,
 *                       "RG" : Sequence,
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_Mapping); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_HD, __pyx_t_7) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":105
 * # valid types for SAM headers
 * VALID_HEADER_TYPES = {"HD" : Mapping,
 *                       "SQ" : Sequence,             # <<<<<<<<<<<<<<
 *                       "RG" : Sequence,
 *                       "PG" : Sequence,
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 105, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_SQ_2, __pyx_t_7) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":106
 * VALID_HEADER_TYPES = {"HD" : Mapping,
 *                       "SQ" : Sequence,
 *                       "RG" : Sequence,             # <<<<<<<<<<<<<<
 *                       "PG" : Sequence,
 *                       "CO" : Sequence}
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_RG, __pyx_t_7) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":107
 *                       "SQ" : Sequence,
 *                       "RG" : Sequence,
 *                       "PG" : Sequence,             # <<<<<<<<<<<<<<
 *                       "CO" : Sequence}
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 107, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_PG, __pyx_t_7) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":108
 *                       "RG" : Sequence,
 *                       "PG" : Sequence,
 *                       "CO" : Sequence}             # <<<<<<<<<<<<<<
 * 
 * # order of records within SAM headers
 */
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_Sequence); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 108, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_CO, __pyx_t_7) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_TYPES, __pyx_t_2) < 0) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":111
 * 
 * # order of records within SAM headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO")             # <<<<<<<<<<<<<<
 * 
 * # default type conversions within SAM header records
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADERS, __pyx_tuple__128) < 0) __PYX_ERR(0, 111, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":114
 * 
 * # default type conversions within SAM header records
 * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str,             # <<<<<<<<<<<<<<
 *                                "SS" : str,},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_VN, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_SO, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_GO, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":115
 * # default type conversions within SAM header records
 * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str,
 *                                "SS" : str,},             # <<<<<<<<<<<<<<
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_SS, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_HD, __pyx_t_7) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":116
 * KNOWN_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str,
 *                                "SS" : str,},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,             # <<<<<<<<<<<<<<
 *                                "M5" : str, "SP" : str, "UR" : str,
 *                                "AH" : str, "TP" : str, "DS" : str,
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_SN, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_LN, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_AS, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":117
 *                                "SS" : str,},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,             # <<<<<<<<<<<<<<
 *                                "AH" : str, "TP" : str, "DS" : str,
 *                                "AN" : str,},
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_M5, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_SP, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_UR, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":118
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,
 *                                "AH" : str, "TP" : str, "DS" : str,             # <<<<<<<<<<<<<<
 *                                "AN" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_AH, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_TP, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_DS, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":119
 *                                "M5" : str, "SP" : str, "UR" : str,
 *                                "AH" : str, "TP" : str, "DS" : str,
 *                                "AN" : str,},             # <<<<<<<<<<<<<<
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_AN, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_SQ_2, __pyx_t_7) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":120
 *                                "AH" : str, "TP" : str, "DS" : str,
 *                                "AN" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,             # <<<<<<<<<<<<<<
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(14); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_ID, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_CN, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_DS, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":121
 *                                "AN" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,             # <<<<<<<<<<<<<<
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PM" : str, "PU" : str,
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_DT, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_FO, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_KS, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":122
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,             # <<<<<<<<<<<<<<
 *                                "PL" : str, "PM" : str, "PU" : str,
 *                                "SM" : str, "BC" : str,},
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_LB, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_PG, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_PI, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":123
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PM" : str, "PU" : str,             # <<<<<<<<<<<<<<
 *                                "SM" : str, "BC" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_PL, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_PM, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_PU, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":124
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PM" : str, "PU" : str,
 *                                "SM" : str, "BC" : str,},             # <<<<<<<<<<<<<<
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_SM, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_BC, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 120, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_RG, __pyx_t_7) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "pysam/libcalignmentfile.pyx":125
 *                                "PL" : str, "PM" : str, "PU" : str,
 *                                "SM" : str, "BC" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,             # <<<<<<<<<<<<<<
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 * 
 */
  __pyx_t_7 = __Pyx_PyDict_NewPresized(6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_ID, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_PN, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_CL, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 125, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":126
 *                                "SM" : str, "BC" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}             # <<<<<<<<<<<<<<
 * 
 * # output order of fields within records. Ensure that CL is at
 */
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_PP, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_DS, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_u_VN, ((PyObject *)(&PyUnicode_Type))) < 0) __PYX_ERR(0, 125, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_PG, __pyx_t_7) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_KNOWN_HEADER_FIELDS, __pyx_t_2) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":130
 * # output order of fields within records. Ensure that CL is at
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "SS", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                               "UR", "SP", "AH", "TP",
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_HD, __pyx_tuple__129) < 0) __PYX_ERR(0, 130, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":131
 * # the end as parsing a CL will ignore any subsequent records.
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "SS", "GO"),
 *                       "SQ" : ("SN", "LN", "AS", "M5",             # <<<<<<<<<<<<<<
 *                               "UR", "SP", "AH", "TP",
 *                               "DS", "AN"),
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_SQ_2, __pyx_tuple__130) < 0) __PYX_ERR(0, 130, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":134
 *                               "UR", "SP", "AH", "TP",
 *                               "DS", "AN"),
 *                       "RG" : ("ID", "CN", "SM", "LB",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "DT", "DS",
 *                               "PL", "FO", "KS", "PG",
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_RG, __pyx_tuple__131) < 0) __PYX_ERR(0, 130, __pyx_L1_error)

  /* "pysam/libcalignmentfile.pyx":138
 *                               "PL", "FO", "KS", "PG",
 *                               "PM", "BC"),
 *                       "PG" : ("PN", "ID", "VN", "PP",             # <<<<<<<<<<<<<<
 *                               "DS", "CL"),}
 * 
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_u_PG, __pyx_tuple__132) < 0) __PYX_ERR(0, 130, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_ORDER, __pyx_t_2) < 0) __PYX_ERR(0, 130, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":142
 * 
 * 
 * def build_header_line(fields, record):             # <<<<<<<<<<<<<<
 *     '''build a header line from `fields` dictionary for `record`'''
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_1build_header_line, 0, __pyx_n_s_build_header_line, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj_)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_build_header_line, __pyx_t_2) < 0) __PYX_ERR(0, 142, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":178
 *     return header
 * 
 * def read_failure_reason(code):             # <<<<<<<<<<<<<<
 *     if code == -2:
 *         return 'truncated file'
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_3read_failure_reason, 0, __pyx_n_s_read_failure_reason, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__5)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_read_failure_reason, __pyx_t_2) < 0) __PYX_ERR(0, 178, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":237
 *             raise MemoryError("could not create header")
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def _from_text_and_lengths(cls, text, reference_names, reference_lengths):
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_5_from_text_and_lengths, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader__from_text_and_l, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__7)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text_and_lengths, __pyx_t_2) < 0) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);
  __Pyx_GetNameInClass(__pyx_t_2, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text_and_lengths); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_Method_ClassMethod(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text_and_lengths, __pyx_t_7) < 0) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":278
 *         return self
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_text(cls, text):
 * 
 */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_7from_text, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_from_text, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__8)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text, __pyx_t_7) < 0) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);
  __Pyx_GetNameInClass(__pyx_t_7, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_Method_ClassMethod(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_text, __pyx_t_2) < 0) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":295
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_dict(cls, header_dict):
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_9from_dict, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_from_dict, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_dict, __pyx_t_2) < 0) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);
  __Pyx_GetNameInClass(__pyx_t_2, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_dict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_Method_ClassMethod(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_dict, __pyx_t_7) < 0) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":336
 *         return cls._from_text_and_lengths(text, reference_names, reference_lengths)
 * 
 *     @classmethod             # <<<<<<<<<<<<<<
 *     def from_references(cls, reference_names, reference_lengths, text=None, add_sq_text=True):
 * 
 */
  __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_11from_references, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_from_references, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_7, __pyx_tuple__139);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_references, __pyx_t_7) < 0) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);
  __Pyx_GetNameInClass(__pyx_t_7, (PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_references); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = __Pyx_Method_ClassMethod(__pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_from_references, __pyx_t_2) < 0) __PYX_ERR(0, 336, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":356
 *         return self.ptr != NULL
 * 
 *     def copy(self):             # <<<<<<<<<<<<<<
 *         return makeAlignmentHeader(bam_hdr_dup(self.ptr))
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_17copy, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_copy, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 356, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_copy, __pyx_t_2) < 0) __PYX_ERR(0, 356, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":388
 *             return tuple(t)
 * 
 *     def _build_sequence_section(self):             # <<<<<<<<<<<<<<
 *         """return sequence section of header.
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_19_build_sequence_section, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader__build_sequence, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_build_sequence_section, __pyx_t_2) < 0) __PYX_ERR(0, 388, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":404
 *         return "".join(text)
 * 
 *     def to_dict(self):             # <<<<<<<<<<<<<<
 *         """return two-level dictionary with header information from the file.
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_21to_dict, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_to_dict, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 404, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_to_dict, __pyx_t_2) < 0) __PYX_ERR(0, 404, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":496
 *         return result
 * 
 *     def as_dict(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`to_dict()` instead"""
 *         return self.to_dict()
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_23as_dict, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_as_dict, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 496, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_as_dict, __pyx_t_2) < 0) __PYX_ERR(0, 496, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":500
 *         return self.to_dict()
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         if tid == -1:
 *             return None
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_25get_reference_name, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_get_reference_na, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_get_reference_name, __pyx_t_2) < 0) __PYX_ERR(0, 500, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":508
 *         return charptr_to_str(self.ptr.target_name[tid])
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         cdef int tid = self.get_tid(reference)
 *         if tid < 0:
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_27get_reference_length, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_get_reference_le, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__26)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_get_reference_length, __pyx_t_2) < 0) __PYX_ERR(0, 508, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":515
 *             return self.ptr.target_len[tid]
 * 
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_29is_valid_tid, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_is_valid_tid, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__27)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_is_valid_tid, __pyx_t_2) < 0) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":523
 *         return 0 <= tid < self.ptr.n_targets
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_31get_tid, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_get_tid, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 523, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_get_tid, __pyx_t_2) < 0) __PYX_ERR(0, 523, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":559
 *         return self.to_dict().__getitem__(key)
 * 
 *     def items(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_39items, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_items, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__31)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 559, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_items, __pyx_t_2) < 0) __PYX_ERR(0, 559, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":563
 * 
 *     # PY2 compatibility
 *     def iteritems(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().items()
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_41iteritems, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_iteritems, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__32)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 563, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_iteritems, __pyx_t_2) < 0) __PYX_ERR(0, 563, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":566
 *         return self.to_dict().items()
 * 
 *     def keys(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().keys()
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_43keys, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_keys, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__33)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_keys, __pyx_t_2) < 0) __PYX_ERR(0, 566, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":569
 *         return self.to_dict().keys()
 * 
 *     def values(self):             # <<<<<<<<<<<<<<
 *         return self.to_dict().values()
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_45values, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_values, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__34)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_values, __pyx_t_2) < 0) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "pysam/libcalignmentfile.pyx":572
 *         return self.to_dict().values()
 * 
 *     def get(self, *args):             # <<<<<<<<<<<<<<
 *         return self.to_dict().get(*args)
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_47get, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader_get, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__35)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader, __pyx_n_s_get, __pyx_t_2) < 0) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentHeader);

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_53__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__36)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15AlignmentHeader_55__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentHeader___setstate_cytho, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":758
 *             raise MemoryError("could not allocate memory of size {}".format(sizeof(bam1_t)))
 * 
 *     def has_index(self):             # <<<<<<<<<<<<<<
 *         """return true if htsfile has an existing (and opened) index.
 *         """
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_3has_index, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_has_index, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__38)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_has_index, __pyx_t_2) < 0) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":763
 *         return self.index != NULL
 * 
 *     def check_index(self):             # <<<<<<<<<<<<<<
 *         """return True if index is present.
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_5check_index, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_check_index, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__39)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_check_index, __pyx_t_2) < 0) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":787
 *         return True
 * 
 *     def _open(self,             # <<<<<<<<<<<<<<
 *               filepath_or_object,
 *               mode=None,
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_7_open, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile__open, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__43)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 787, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__148);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_open, __pyx_t_2) < 0) __PYX_ERR(0, 787, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1028
 *                     self.start_offset = self.tell()
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_9fetch, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_fetch, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__53)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__150);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_fetch, __pyx_t_2) < 0) __PYX_ERR(0, 1028, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1133
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return an iterator over the first n alignments.
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_11head, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_head, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__57)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1133, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__152);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_head, __pyx_t_2) < 0) __PYX_ERR(0, 1133, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1155
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self, AlignedSegment read):             # <<<<<<<<<<<<<<
 *         '''return the mate of :class:`pysam.AlignedSegment` `read`.
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_13mate, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_mate, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__58)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1155, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_mate, __pyx_t_2) < 0) __PYX_ERR(0, 1155, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1214
 *         return mate
 * 
 *     def pileup(self,             # <<<<<<<<<<<<<<
 *                contig=None,
 *                start=None,
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_15pileup, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_pileup, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__60)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__155);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_pileup, __pyx_t_2) < 0) __PYX_ERR(0, 1214, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1354
 *                 return IteratorColumnAll(self, **kwargs)
 * 
 *     def count(self,             # <<<<<<<<<<<<<<
 *               contig=None,
 *               start=None,
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_17count, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_count, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__62)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__157);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_count, __pyx_t_2) < 0) __PYX_ERR(0, 1354, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1457
 *         return counter
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking             # <<<<<<<<<<<<<<
 *     def count_coverage(self,
 *                        contig,
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_19count_coverage, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_count_coverage, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__63)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1457, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_2, __pyx_tuple__159);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_count_coverage, __pyx_t_2) < 0) __PYX_ERR(0, 1457, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1609
 *         return count_a, count_c, count_g, count_t
 * 
 *     def find_introns_slow(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_21find_introns_slow, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_find_introns_slow, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__66)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_find_introns_slow, __pyx_t_2) < 0) __PYX_ERR(0, 1609, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1633
 *         return res
 * 
 *     def find_introns(self, read_iterator):             # <<<<<<<<<<<<<<
 *         """Return a dictionary {(start, stop): count}
 *         Listing the intronic sites in the reads (identified by 'N' in the cigar strings),
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_23find_introns, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_find_introns, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__67)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_find_introns, __pyx_t_2) < 0) __PYX_ERR(0, 1633, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1667
 * 
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''closes the :class:`pysam.AlignmentFile`.'''
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_25close, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_close, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__68)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1667, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_close, __pyx_t_2) < 0) __PYX_ERR(0, 1667, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1713
 *                 raise IOError(errno, force_str(strerror(errno)))
 * 
 *     cpdef int write(self, AlignedSegment read) except -1:             # <<<<<<<<<<<<<<
 *         '''
 *         write a single :class:`pysam.AlignedSegment` to disk.
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_29write, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_write, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__69)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1713, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_write, __pyx_t_2) < 0) __PYX_ERR(0, 1713, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1751
 * 
 *     # context manager interface
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_31__enter__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile___enter, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__70)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_enter, __pyx_t_2) < 0) __PYX_ERR(0, 1751, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1754
 *         return self
 * 
 *     def __exit__(self, exc_type, exc_value, traceback):             # <<<<<<<<<<<<<<
 *         self.close()
 *         return False
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_33__exit__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile___exit, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__71)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1754, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_exit, __pyx_t_2) < 0) __PYX_ERR(0, 1754, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1813
 *             return n
 * 
 *     def get_index_statistics(self):             # <<<<<<<<<<<<<<
 *         """return statistics about mapped/unmapped reads per chromosome as
 *         they are stored in the index, similarly to the statistics printed
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_35get_index_statistics, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_get_index_statisti, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__72)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_get_index_statistics, __pyx_t_2) < 0) __PYX_ERR(0, 1813, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1884
 *     ###########################################
 *     # methods/properties referencing the header
 *     def is_valid_tid(self, int tid):             # <<<<<<<<<<<<<<
 *         """
 *         return True if the numerical :term:`tid` is valid; False otherwise.
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_41is_valid_tid, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_is_valid_tid, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__74)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_is_valid_tid, __pyx_t_2) < 0) __PYX_ERR(0, 1884, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1894
 *         return self.header.is_valid_tid(tid)
 * 
 *     def get_tid(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return the numerical :term:`tid` corresponding to
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_43get_tid, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_get_tid, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__76)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1894, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_get_tid, __pyx_t_2) < 0) __PYX_ERR(0, 1894, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1905
 *         return self.header.get_tid(reference)
 * 
 *     def get_reference_name(self, tid):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` name corresponding to numerical :term:`tid`
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_45get_reference_name, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_get_reference_name, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__77)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1905, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_get_reference_name, __pyx_t_2) < 0) __PYX_ERR(0, 1905, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1913
 *         return self.header.get_reference_name(tid)
 * 
 *     def get_reference_length(self, reference):             # <<<<<<<<<<<<<<
 *         """
 *         return :term:`reference` length corresponding to numerical :term:`tid`
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_47get_reference_length, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_get_reference_leng, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__78)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1913, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_get_reference_length, __pyx_t_2) < 0) __PYX_ERR(0, 1913, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1961
 * 
 *     # Compatibility functions for pysam < 0.8.3
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_tid` instead"""
 *         return self.get_tid(reference)
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_49gettid, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_gettid, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__79)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_gettid, __pyx_t_2) < 0) __PYX_ERR(0, 1961, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "pysam/libcalignmentfile.pyx":1965
 *         return self.get_tid(reference)
 * 
 *     def getrname(self, tid):             # <<<<<<<<<<<<<<
 *         """deprecated, use :meth:`get_reference_name` instead"""
 *         return self.get_reference_name(tid)
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_51getrname, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile_getrname, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__80)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1965, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile, __pyx_n_s_getrname, __pyx_t_2) < 0) __PYX_ERR(0, 1965, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_AlignmentFile);

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_53__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__81)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_13AlignmentFile_55__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_AlignmentFile___setstate_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__82)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_11IteratorRow_5__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRow___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__84)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_11IteratorRow_7__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRow___setstate_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__85)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_17IteratorRowRegion_9__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowRegion___reduce_cytho, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__88)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index,self.iter cannot be converted to a Python object for pickling"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_17IteratorRowRegion_11__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowRegion___setstate_cyt, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__89)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15IteratorRowHead_7__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowHead___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__90)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_15IteratorRowHead_9__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowHead___setstate_cytho, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__91)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorRowAll_7__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowAll___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__92)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorRowAll_9__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowAll___setstate_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__93)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":2231
 *         self.tid = -1
 * 
 *     def nextiter(self):             # <<<<<<<<<<<<<<
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_18IteratorRowAllRefs_3nextiter, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowAllRefs_nextiter, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__95)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2231, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs, __pyx_n_s_nextiter, __pyx_t_2) < 0) __PYX_ERR(0, 2231, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_IteratorRowAllRefs);

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_18IteratorRowAllRefs_9__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowAllRefs___reduce_cyth, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__96)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_18IteratorRowAllRefs_11__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowAllRefs___setstate_cy, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__97)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_20IteratorRowSelection_7__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowSelection___reduce_cy, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__98)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.b,self.htsfile,self.index cannot be converted to a Python object for pickling"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_20IteratorRowSelection_9__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorRowSelection___setstate, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__99)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":2524
 *             return self.iterdata.seq_len
 * 
 *     def add_reference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in `fastafile` to iterator.'''
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_5add_reference, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumn_add_reference, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__100)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2524, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn, __pyx_n_s_add_reference, __pyx_t_2) < 0) __PYX_ERR(0, 2524, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn);

  /* "pysam/libcalignmentfile.pyx":2533
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def has_reference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_7has_reference, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumn_has_reference, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__101)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2533, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn, __pyx_n_s_has_reference, __pyx_t_2) < 0) __PYX_ERR(0, 2533, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn);

  /* "pysam/libcalignmentfile.pyx":2688
 *     # backwards compatibility
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         return self.has_reference()
 *     cdef char * getSequence(self):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_11hasReference, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumn_hasReference, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__103)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2688, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn, __pyx_n_s_hasReference, __pyx_t_2) < 0) __PYX_ERR(0, 2688, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn);

  /* "pysam/libcalignmentfile.pyx":2692
 *     cdef char * getSequence(self):
 *         return self.get_sequence()
 *     def addReference(self, FastaFile fastafile):             # <<<<<<<<<<<<<<
 *         return self.add_reference(fastafile)
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_13addReference, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumn_addReference, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__104)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2692, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn, __pyx_n_s_addReference, __pyx_t_2) < 0) __PYX_ERR(0, 2692, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_IteratorColumn);

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_15__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumn___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__105)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_14IteratorColumn_17__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumn___setstate_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__106)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":2703
 *                   int tid = 0,
 *                   int start = 0,
 *                   int stop = MAX_POS,             # <<<<<<<<<<<<<<
 *                   int truncate = False,
 *                   int multiple_iterators = True,
 */
  __pyx_k__107 = __pyx_v_5pysam_17libcalignmentfile_MAX_POS;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_20IteratorColumnRegion_5__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumnRegion___reduce_cy, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__109)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_20IteratorColumnRegion_7__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumnRegion___setstate, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__110)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_5__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumnAllRefs___reduce_c, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__111)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_21IteratorColumnAllRefs_7__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumnAllRefs___setstate, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__112)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_17IteratorColumnAll_5__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumnAll___reduce_cytho, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__113)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "no default __reduce__ due to non-trivial __cinit__"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_17IteratorColumnAll_7__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IteratorColumnAll___setstate_cyt, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__114)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     cdef tuple state
 *     cdef object _dict
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_7SNPCall_3__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_SNPCall___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__115)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_SNPCall, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_SNPCall);

  /* "(tree fragment)":16
 *     else:
 *         return __pyx_unpickle_SNPCall, (type(self), 0xe45c101, state)
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     __pyx_unpickle_SNPCall__set_state(self, __pyx_state)
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_7SNPCall_5__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_SNPCall___setstate_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__116)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_SNPCall, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_SNPCall);

  /* "pysam/libcalignmentfile.pyx":2929
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build the index.'''
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_3build, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IndexedReads_build, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__118)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2929, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads, __pyx_n_s_build, __pyx_t_2) < 0) __PYX_ERR(0, 2929, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads);

  /* "pysam/libcalignmentfile.pyx":2956
 *         bam_destroy1(b)
 * 
 *     def find(self, query_name):             # <<<<<<<<<<<<<<
 *         '''find `query_name` in index.
 * 
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_5find, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IndexedReads_find, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__119)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2956, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads, __pyx_n_s_find, __pyx_t_2) < 0) __PYX_ERR(0, 2956, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  PyType_Modified(__pyx_ptype_5pysam_17libcalignmentfile_IndexedReads);

  /* "(tree fragment)":1
 * def __reduce_cython__(self):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_9__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IndexedReads___reduce_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__120)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":3
 * def __reduce_cython__(self):
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 * def __setstate_cython__(self, __pyx_state):             # <<<<<<<<<<<<<<
 *     raise TypeError, "self.htsfile cannot be converted to a Python object for pickling"
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_12IndexedReads_11__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_IndexedReads___setstate_cython, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__121)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(3, 3, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "(tree fragment)":1
 * def __pyx_unpickle_SNPCall(__pyx_type, long __pyx_checksum, __pyx_state):             # <<<<<<<<<<<<<<
 *     cdef object __pyx_PickleError
 *     cdef object __pyx_result
 */
  __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_5pysam_17libcalignmentfile_5__pyx_unpickle_SNPCall, 0, __pyx_n_s_pyx_unpickle_SNPCall, NULL, __pyx_n_s_pysam_libcalignmentfile, __pyx_d, ((PyObject *)__pyx_codeobj__122)); if (unlikely(!__pyx_t_2)) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_SNPCall, __pyx_t_2) < 0) __PYX_ERR(3, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/libcalignmentfile.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * # cython: profile=True
 * ########################################################
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_TraceReturn(Py_None, 0);

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  if (__pyx_m) {
    if (__pyx_d && stringtab_initialized) {
      __Pyx_AddTraceback("init pysam.libcalignmentfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    #if !CYTHON_USE_MODULE_STATE
    Py_CLEAR(__pyx_m);
    #else
    Py_DECREF(__pyx_m);
    if (pystate_addmodule_run) {
      PyObject *tp, *value, *tb;
      PyErr_Fetch(&tp, &value, &tb);
      PyState_RemoveModule(&__pyx_moduledef);
      PyErr_Restore(tp, value, tb);
    }
    #endif
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pysam.libcalignmentfile");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #endif
}
/* #### Code section: cleanup_globals ### */
/* #### Code section: cleanup_module ### */
/* #### Code section: main_method ### */
/* #### Code section: utility_code_pragmas ### */
#ifdef _MSC_VER
#pragma warning( push )
/* Warning 4127: conditional expression is constant
 * Cython uses constant conditional expressions to allow in inline functions to be optimized at
 * compile-time, so this warning is not useful
 */
#pragma warning( disable : 4127 )
#endif



/* #### Code section: utility_code_def ### */

/* --- Runtime support code --- */
/* Refnanny */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule(modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, "RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

/* PyErrExceptionMatches */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        if (__Pyx_PyErr_GivenExceptionMatches(exc_type, PyTuple_GET_ITEM(tuple, i))) return 1;
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    int result;
    PyObject *exc_type;
#if PY_VERSION_HEX >= 0x030C00A6
    PyObject *current_exception = tstate->current_exception;
    if (unlikely(!current_exception)) return 0;
    exc_type = (PyObject*) Py_TYPE(current_exception);
    if (exc_type == err) return 1;
#else
    exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
#endif
    #if CYTHON_AVOID_BORROWED_REFS
    Py_INCREF(exc_type);
    #endif
    if (unlikely(PyTuple_Check(err))) {
        result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err);
    } else {
        result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err);
    }
    #if CYTHON_AVOID_BORROWED_REFS
    Py_DECREF(exc_type);
    #endif
    return result;
}
#endif

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
#if PY_VERSION_HEX >= 0x030C00A6
    PyObject *tmp_value;
    assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value)));
    if (value) {
        #if CYTHON_COMPILING_IN_CPYTHON
        if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb))
        #endif
            PyException_SetTraceback(value, tb);
    }
    tmp_value = tstate->current_exception;
    tstate->current_exception = value;
    Py_XDECREF(tmp_value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
#else
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#if PY_VERSION_HEX >= 0x030C00A6
    PyObject* exc_value;
    exc_value = tstate->current_exception;
    tstate->current_exception = 0;
    *value = exc_value;
    *type = NULL;
    *tb = NULL;
    if (exc_value) {
        *type = (PyObject*) Py_TYPE(exc_value);
        Py_INCREF(*type);
        #if CYTHON_COMPILING_IN_CPYTHON
        *tb = ((PyBaseExceptionObject*) exc_value)->traceback;
        Py_XINCREF(*tb);
        #else
        *tb = PyException_GetTraceback(exc_value);
        #endif
    }
#else
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#endif
}
#endif

/* PyObjectGetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#endif

/* PyObjectGetAttrStrNoError */
#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1
static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        __Pyx_PyErr_Clear();
}
#endif
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
    PyObject *result;
#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1
    (void) PyObject_GetOptionalAttr(obj, attr_name, &result);
    return result;
#else
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
        return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
    }
#endif
    result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
    if (unlikely(!result)) {
        __Pyx_PyObject_GetAttrStr_ClearAttributeError();
    }
    return result;
#endif
}

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name);
    if (unlikely(!result) && !PyErr_Occurred()) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* TupleAndListFromArray */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
    PyObject *v;
    Py_ssize_t i;
    for (i = 0; i < length; i++) {
        v = dest[i] = src[i];
        Py_INCREF(v);
    }
}
static CYTHON_INLINE PyObject *
__Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
{
    PyObject *res;
    if (n <= 0) {
        Py_INCREF(__pyx_empty_tuple);
        return __pyx_empty_tuple;
    }
    res = PyTuple_New(n);
    if (unlikely(res == NULL)) return NULL;
    __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n);
    return res;
}
static CYTHON_INLINE PyObject *
__Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n)
{
    PyObject *res;
    if (n <= 0) {
        return PyList_New(0);
    }
    res = PyList_New(n);
    if (unlikely(res == NULL)) return NULL;
    __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n);
    return res;
}
#endif

/* BytesEquals */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result;
#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000)
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        #if PY_MAJOR_VERSION < 3
        Py_XDECREF(owned_ref);
        #endif
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* fastcall */
#if CYTHON_METH_FASTCALL
static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s)
{
    Py_ssize_t i, n = PyTuple_GET_SIZE(kwnames);
    for (i = 0; i < n; i++)
    {
        if (s == PyTuple_GET_ITEM(kwnames, i)) return kwvalues[i];
    }
    for (i = 0; i < n; i++)
    {
        int eq = __Pyx_PyUnicode_Equals(s, PyTuple_GET_ITEM(kwnames, i), Py_EQ);
        if (unlikely(eq != 0)) {
            if (unlikely(eq < 0)) return NULL;
            return kwvalues[i];
        }
    }
    return NULL;
}
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000
CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) {
    Py_ssize_t i, nkwargs = PyTuple_GET_SIZE(kwnames);
    PyObject *dict;
    dict = PyDict_New();
    if (unlikely(!dict))
        return NULL;
    for (i=0; i<nkwargs; i++) {
        PyObject *key = PyTuple_GET_ITEM(kwnames, i);
        if (unlikely(PyDict_SetItem(dict, key, kwvalues[i]) < 0))
            goto bad;
    }
    return dict;
bad:
    Py_DECREF(dict);
    return NULL;
}
#endif
#endif

/* RaiseArgTupleInvalid */
static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject *const *kwvalues,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    int kwds_is_tuple = CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds));
    while (1) {
        Py_XDECREF(key); key = NULL;
        Py_XDECREF(value); value = NULL;
        if (kwds_is_tuple) {
            Py_ssize_t size;
#if CYTHON_ASSUME_SAFE_MACROS
            size = PyTuple_GET_SIZE(kwds);
#else
            size = PyTuple_Size(kwds);
            if (size < 0) goto bad;
#endif
            if (pos >= size) break;
#if CYTHON_AVOID_BORROWED_REFS
            key = __Pyx_PySequence_ITEM(kwds, pos);
            if (!key) goto bad;
#elif CYTHON_ASSUME_SAFE_MACROS
            key = PyTuple_GET_ITEM(kwds, pos);
#else
            key = PyTuple_GetItem(kwds, pos);
            if (!key) goto bad;
#endif
            value = kwvalues[pos];
            pos++;
        }
        else
        {
            if (!PyDict_Next(kwds, &pos, &key, &value)) break;
#if CYTHON_AVOID_BORROWED_REFS
            Py_INCREF(key);
#endif
        }
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
#if CYTHON_AVOID_BORROWED_REFS
            Py_INCREF(value);
            Py_DECREF(key);
#endif
            key = NULL;
            value = NULL;
            continue;
        }
#if !CYTHON_AVOID_BORROWED_REFS
        Py_INCREF(key);
#endif
        Py_INCREF(value);
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
#if CYTHON_AVOID_BORROWED_REFS
                    value = NULL;
#endif
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key)
                );
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
#if CYTHON_AVOID_BORROWED_REFS
                    value = NULL;
#endif
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    Py_XDECREF(key);
    Py_XDECREF(value);
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    #if PY_MAJOR_VERSION < 3
    PyErr_Format(PyExc_TypeError,
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
    PyErr_Format(PyExc_TypeError,
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    Py_XDECREF(key);
    Py_XDECREF(value);
    return -1;
}

/* Profile */
#if CYTHON_PROFILE
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   PyThreadState* tstate,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    PyObject *type, *value, *traceback;
    int retval;
    if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
        if (*code == NULL) {
            *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
            if (*code == NULL) return 0;
        }
        *frame = PyFrame_New(
            tstate,                          /*PyThreadState *tstate*/
            *code,                           /*PyCodeObject *code*/
            __pyx_d,                  /*PyObject *globals*/
            0                                /*PyObject *locals*/
        );
        if (*frame == NULL) return 0;
        if (CYTHON_TRACE && (*frame)->f_trace == NULL) {
            Py_INCREF(Py_None);
            (*frame)->f_trace = Py_None;
        }
#if PY_VERSION_HEX < 0x030400B1
    } else {
        (*frame)->f_tstate = tstate;
#endif
    }
    __Pyx_PyFrame_SetLineNumber(*frame, firstlineno);
    retval = 1;
    __Pyx_EnterTracing(tstate);
    __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
    #if CYTHON_TRACE
    if (tstate->c_tracefunc)
        retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
    if (retval && tstate->c_profilefunc)
    #endif
        retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
    __Pyx_LeaveTracing(tstate);
    if (retval) {
        __Pyx_ErrRestoreInState(tstate, type, value, traceback);
        return __Pyx_IsTracing(tstate, 0, 0) && retval;
    } else {
        Py_XDECREF(type);
        Py_XDECREF(value);
        Py_XDECREF(traceback);
        return -1;
    }
}
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
    PyCodeObject *py_code = 0;
#if PY_MAJOR_VERSION >= 3
    py_code = PyCode_NewEmpty(srcfile, funcname, firstlineno);
    if (likely(py_code)) {
        py_code->co_flags |= CO_OPTIMIZED | CO_NEWLOCALS;
    }
#else
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    py_funcname = PyString_FromString(funcname);
    if (unlikely(!py_funcname)) goto bad;
    py_srcfile = PyString_FromString(srcfile);
    if (unlikely(!py_srcfile)) goto bad;
    py_code = PyCode_New(
        0,
        0,
        0,
        CO_OPTIMIZED | CO_NEWLOCALS,
        __pyx_empty_bytes,     /*PyObject *code,*/
        __pyx_empty_tuple,     /*PyObject *consts,*/
        __pyx_empty_tuple,     /*PyObject *names,*/
        __pyx_empty_tuple,     /*PyObject *varnames,*/
        __pyx_empty_tuple,     /*PyObject *freevars,*/
        __pyx_empty_tuple,     /*PyObject *cellvars,*/
        py_srcfile,       /*PyObject *filename,*/
        py_funcname,      /*PyObject *name,*/
        firstlineno,
        __pyx_empty_bytes      /*PyObject *lnotab*/
    );
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
#endif
    return py_code;
}
#endif

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    #if PY_MAJOR_VERSION < 3
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) {
        return NULL;
    }
    #else
    if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) {
        return NULL;
    }
    #endif
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif

/* PyObjectCall */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = Py_TYPE(func)->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    #if PY_MAJOR_VERSION < 3
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    #else
    if (unlikely(Py_EnterRecursiveCall(" while calling a Python object")))
        return NULL;
    #endif
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func);
    self = __Pyx_CyOrPyCFunction_GET_SELF(func);
    #if PY_MAJOR_VERSION < 3
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    #else
    if (unlikely(Py_EnterRecursiveCall(" while calling a Python object")))
        return NULL;
    #endif
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectFastCall */
#if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API
static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs) {
    PyObject *argstuple;
    PyObject *result = 0;
    size_t i;
    argstuple = PyTuple_New((Py_ssize_t)nargs);
    if (unlikely(!argstuple)) return NULL;
    for (i = 0; i < nargs; i++) {
        Py_INCREF(args[i]);
        if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) < 0) goto bad;
    }
    result = __Pyx_PyObject_Call(func, argstuple, kwargs);
  bad:
    Py_DECREF(argstuple);
    return result;
}
#endif
static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t _nargs, PyObject *kwargs) {
    Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs);
#if CYTHON_COMPILING_IN_CPYTHON
    if (nargs == 0 && kwargs == NULL) {
        if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS))
            return __Pyx_PyObject_CallMethO(func, NULL);
    }
    else if (nargs == 1 && kwargs == NULL) {
        if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_O))
            return __Pyx_PyObject_CallMethO(func, args[0]);
    }
#endif
    #if PY_VERSION_HEX < 0x030800B1
    #if CYTHON_FAST_PYCCALL
    if (PyCFunction_Check(func)) {
        if (kwargs) {
            return _PyCFunction_FastCallDict(func, args, nargs, kwargs);
        } else {
            return _PyCFunction_FastCallKeywords(func, args, nargs, NULL);
        }
    }
    #if PY_VERSION_HEX >= 0x030700A1
    if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) {
        return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL);
    }
    #endif
    #endif
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs);
    }
    #endif
    #endif
    if (kwargs == NULL) {
        #if CYTHON_VECTORCALL
        #if PY_VERSION_HEX < 0x03090000
        vectorcallfunc f = _PyVectorcall_Function(func);
        #else
        vectorcallfunc f = PyVectorcall_Function(func);
        #endif
        if (f) {
            return f(func, args, (size_t)nargs, NULL);
        }
        #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL
        if (__Pyx_CyFunction_CheckExact(func)) {
            __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func);
            if (f) return f(func, args, (size_t)nargs, NULL);
        }
        #endif
    }
    if (nargs == 0) {
        return __Pyx_PyObject_Call(func, __pyx_empty_tuple, kwargs);
    }
    #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API
    return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs);
    #else
    return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs);
    #endif
}

/* PyObjectFormatAndDecref */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) {
    if (unlikely(!s)) return NULL;
    if (likely(PyUnicode_CheckExact(s))) return s;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyString_CheckExact(s))) {
        PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict");
        Py_DECREF(s);
        return result;
    }
    #endif
    return __Pyx_PyObject_FormatAndDecref(s, f);
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) {
    PyObject *result;
    if (unlikely(!s)) return NULL;
    result = PyObject_Format(s, f);
    Py_DECREF(s);
    return result;
}

/* GetItemInt */
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (unlikely(!j)) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping;
        PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence;
        if (mm && mm->mp_subscript) {
            PyObject *r, *key = PyInt_FromSsize_t(i);
            if (unlikely(!key)) return NULL;
            r = mm->mp_subscript(o, key);
            Py_DECREF(key);
            return r;
        }
        if (likely(sm && sm->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) {
                Py_ssize_t l = sm->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return sm->sq_item(o, i);
        }
    }
#else
    if (is_list || !PyMapping_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* PyObjectCallOneArg */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *args[2] = {NULL, arg};
    return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
}

/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject *index) {
    PyObject *runerr = NULL;
    Py_ssize_t key_value;
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        __Pyx_TypeName index_type_name = __Pyx_PyType_GetName(Py_TYPE(index));
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError,
            "cannot fit '" __Pyx_FMT_TYPENAME "' into an index-sized integer", index_type_name);
        __Pyx_DECREF_TypeName(index_type_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem_Slow(PyObject *obj, PyObject *key) {
    __Pyx_TypeName obj_type_name;
    if (likely(PyType_Check(obj))) {
        PyObject *meth = __Pyx_PyObject_GetAttrStrNoError(obj, __pyx_n_s_class_getitem);
        if (!meth) {
            PyErr_Clear();
        } else {
            PyObject *result = __Pyx_PyObject_CallOneArg(meth, key);
            Py_DECREF(meth);
            return result;
        }
    }
    obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
    PyErr_Format(PyExc_TypeError,
        "'" __Pyx_FMT_TYPENAME "' object is not subscriptable", obj_type_name);
    __Pyx_DECREF_TypeName(obj_type_name);
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject *key) {
    PyTypeObject *tp = Py_TYPE(obj);
    PyMappingMethods *mm = tp->tp_as_mapping;
    PySequenceMethods *sm = tp->tp_as_sequence;
    if (likely(mm && mm->mp_subscript)) {
        return mm->mp_subscript(obj, key);
    }
    if (likely(sm && sm->sq_item)) {
        return __Pyx_PyObject_GetIndex(obj, key);
    }
    return __Pyx_PyObject_GetItem_Slow(obj, key);
}
#endif

/* JoinPyUnicode */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char) {
#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    PyObject *result_uval;
    int result_ukind, kind_shift;
    Py_ssize_t i, char_pos;
    void *result_udata;
    CYTHON_MAYBE_UNUSED_VAR(max_char);
#if CYTHON_PEP393_ENABLED
    result_uval = PyUnicode_New(result_ulength, max_char);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
    kind_shift = (result_ukind == PyUnicode_4BYTE_KIND) ? 2 : result_ukind - 1;
    result_udata = PyUnicode_DATA(result_uval);
#else
    result_uval = PyUnicode_FromUnicode(NULL, result_ulength);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = sizeof(Py_UNICODE);
    kind_shift = (result_ukind == 4) ? 2 : result_ukind - 1;
    result_udata = PyUnicode_AS_UNICODE(result_uval);
#endif
    assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0);
    char_pos = 0;
    for (i=0; i < value_count; i++) {
        int ukind;
        Py_ssize_t ulength;
        void *udata;
        PyObject *uval = PyTuple_GET_ITEM(value_tuple, i);
        if (unlikely(__Pyx_PyUnicode_READY(uval)))
            goto bad;
        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
        if (unlikely(!ulength))
            continue;
        if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos))
            goto overflow;
        ukind = __Pyx_PyUnicode_KIND(uval);
        udata = __Pyx_PyUnicode_DATA(uval);
        if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) {
            memcpy((char *)result_udata + (char_pos << kind_shift), udata, (size_t) (ulength << kind_shift));
        } else {
            #if PY_VERSION_HEX >= 0x030d0000
            if (unlikely(PyUnicode_CopyCharacters(result_uval, char_pos, uval, 0, ulength) < 0)) goto bad;
            #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters)
            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
            #else
            Py_ssize_t j;
            for (j=0; j < ulength; j++) {
                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
            }
            #endif
        }
        char_pos += ulength;
    }
    return result_uval;
overflow:
    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
bad:
    Py_DECREF(result_uval);
    return NULL;
#else
    CYTHON_UNUSED_VAR(max_char);
    CYTHON_UNUSED_VAR(result_ulength);
    CYTHON_UNUSED_VAR(value_count);
    return PyUnicode_Join(__pyx_empty_unicode, value_tuple);
#endif
}

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#elif CYTHON_COMPILING_IN_LIMITED_API
    if (unlikely(!__pyx_m)) {
        return NULL;
    }
    result = PyObject_GetAttr(__pyx_m, name);
    if (likely(result)) {
        return result;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    __Pyx_PyThreadState_declare
    CYTHON_UNUSED_VAR(cause);
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause) {
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
      #if PY_VERSION_HEX >= 0x030C00A6
        PyException_SetTraceback(value, tb);
      #elif CYTHON_FAST_THREAD_STATE
        PyThreadState *tstate = __Pyx_PyThreadState_Current;
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#else
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* PyIntCompare */
static CYTHON_INLINE int __Pyx_PyInt_BoolEqObjC(PyObject *op1, PyObject *op2, long intval, long inplace) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_UNUSED_VAR(inplace);
    if (op1 == op2) {
        return 1;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        return (a == b);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = __Pyx_PyLong_DigitCount(op1);
        const digit* digits = __Pyx_PyLong_Digits(op1);
        if (intval == 0) {
            return (__Pyx_PyLong_IsZero(op1) == 1);
        } else if (intval < 0) {
            if (__Pyx_PyLong_IsNonNeg(op1))
                return 0;
            intval = -intval;
        } else {
            if (__Pyx_PyLong_IsNeg(op1))
                return 0;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        return (unequal == 0);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
#if CYTHON_COMPILING_IN_LIMITED_API
        double a = __pyx_PyFloat_AsDouble(op1);
#else
        double a = PyFloat_AS_DOUBLE(op1);
#endif
        return ((double)a == (double)b);
    }
    return __Pyx_PyObject_IsTrueAndDecref(
        PyObject_RichCompare(op1, op2, Py_EQ));
}

/* KeywordStringCheck */
static int __Pyx_CheckKeywordStrings(
    PyObject *kw,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kw, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kw))) {
        Py_ssize_t kwsize;
#if CYTHON_ASSUME_SAFE_MACROS
        kwsize = PyTuple_GET_SIZE(kw);
#else
        kwsize = PyTuple_Size(kw);
        if (kwsize < 0) return 0;
#endif
        if (unlikely(kwsize == 0))
            return 1;
        if (!kw_allowed) {
#if CYTHON_ASSUME_SAFE_MACROS
            key = PyTuple_GET_ITEM(kw, 0);
#else
            key = PyTuple_GetItem(kw, pos);
            if (!key) return 0;
#endif
            goto invalid_keyword;
        }
#if PY_VERSION_HEX < 0x03090000
        for (pos = 0; pos < kwsize; pos++) {
#if CYTHON_ASSUME_SAFE_MACROS
            key = PyTuple_GET_ITEM(kw, pos);
#else
            key = PyTuple_GetItem(kw, pos);
            if (!key) return 0;
#endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
        }
#endif
        return 1;
    }
    while (PyDict_Next(kw, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if (!kw_allowed && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    #if PY_MAJOR_VERSION < 3
    PyErr_Format(PyExc_TypeError,
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
    PyErr_Format(PyExc_TypeError,
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

/* PyObjectCallNoArg */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
    PyObject *arg[2] = {NULL, NULL};
    return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
}

/* SliceObject */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, int wraparound) {
    __Pyx_TypeName obj_type_name;
#if CYTHON_USE_TYPE_SLOTS
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#else
    CYTHON_UNUSED_VAR(wraparound);
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#else
    CYTHON_UNUSED_VAR(wraparound);
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_USE_TYPE_SLOTS
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
    PyErr_Format(PyExc_TypeError,
        "'" __Pyx_FMT_TYPENAME "' object is unsliceable", obj_type_name);
    __Pyx_DECREF_TypeName(obj_type_name);
bad:
    return NULL;
}

/* DictGetItem */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            if (unlikely(PyTuple_Check(key))) {
                PyObject* args = PyTuple_Pack(1, key);
                if (likely(args)) {
                    PyErr_SetObject(PyExc_KeyError, args);
                    Py_DECREF(args);
                }
            } else {
                PyErr_SetObject(PyExc_KeyError, key);
            }
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#endif

/* GetTopmostException */
#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE
static _PyErr_StackItem *
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
    _PyErr_StackItem *exc_info = tstate->exc_info;
    while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
           exc_info->previous_item != NULL)
    {
        exc_info = exc_info->previous_item;
    }
    return exc_info;
}
#endif

/* SaveResetException */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    PyObject *exc_value = exc_info->exc_value;
    if (exc_value == NULL || exc_value == Py_None) {
        *value = NULL;
        *type = NULL;
        *tb = NULL;
    } else {
        *value = exc_value;
        Py_INCREF(*value);
        *type = (PyObject*) Py_TYPE(exc_value);
        Py_INCREF(*type);
        *tb = PyException_GetTraceback(exc_value);
    }
  #elif CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
    *type = exc_info->exc_type;
    *value = exc_info->exc_value;
    *tb = exc_info->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
  #else
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
  #endif
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
    _PyErr_StackItem *exc_info = tstate->exc_info;
    PyObject *tmp_value = exc_info->exc_value;
    exc_info->exc_value = value;
    Py_XDECREF(tmp_value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
  #else
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    #if CYTHON_USE_EXC_INFO_STACK
    _PyErr_StackItem *exc_info = tstate->exc_info;
    tmp_type = exc_info->exc_type;
    tmp_value = exc_info->exc_value;
    tmp_tb = exc_info->exc_traceback;
    exc_info->exc_type = type;
    exc_info->exc_value = value;
    exc_info->exc_traceback = tb;
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
  #endif
}
#endif

/* GetException */
#if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb)
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
#endif
{
    PyObject *local_type = NULL, *local_value, *local_tb = NULL;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
  #if PY_VERSION_HEX >= 0x030C00A6
    local_value = tstate->current_exception;
    tstate->current_exception = 0;
    if (likely(local_value)) {
        local_type = (PyObject*) Py_TYPE(local_value);
        Py_INCREF(local_type);
        local_tb = PyException_GetTraceback(local_value);
    }
  #else
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
  #endif
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE && PY_VERSION_HEX >= 0x030C00A6
    if (unlikely(tstate->current_exception))
#elif CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    #if CYTHON_USE_EXC_INFO_STACK
    {
        _PyErr_StackItem *exc_info = tstate->exc_info;
      #if PY_VERSION_HEX >= 0x030B00a4
        tmp_value = exc_info->exc_value;
        exc_info->exc_value = local_value;
        tmp_type = NULL;
        tmp_tb = NULL;
        Py_XDECREF(local_type);
        Py_XDECREF(local_tb);
      #else
        tmp_type = exc_info->exc_type;
        tmp_value = exc_info->exc_value;
        tmp_tb = exc_info->exc_traceback;
        exc_info->exc_type = local_type;
        exc_info->exc_value = local_value;
        exc_info->exc_traceback = local_tb;
      #endif
    }
    #else
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    #endif
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* RaiseTooManyValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
    PyObject* exc_type;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    exc_type = __Pyx_PyErr_CurrentExceptionType();
    if (unlikely(exc_type)) {
        if (unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
            return -1;
        __Pyx_PyErr_Clear();
        return 0;
    }
    return 0;
}

/* UnpackItemEndCheck */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    }
    return __Pyx_IterFinish();
}

/* UnicodeConcatInPlace */
# if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
static int
__Pyx_unicode_modifiable(PyObject *unicode)
{
    if (Py_REFCNT(unicode) != 1)
        return 0;
    if (!PyUnicode_CheckExact(unicode))
        return 0;
    if (PyUnicode_CHECK_INTERNED(unicode))
        return 0;
    return 1;
}
static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right
        #if CYTHON_REFNANNY
        , void* __pyx_refnanny
        #endif
    ) {
    PyObject *left = *p_left;
    Py_ssize_t left_len, right_len, new_len;
    if (unlikely(__Pyx_PyUnicode_READY(left) == -1))
        return NULL;
    if (unlikely(__Pyx_PyUnicode_READY(right) == -1))
        return NULL;
    left_len = PyUnicode_GET_LENGTH(left);
    if (left_len == 0) {
        Py_INCREF(right);
        return right;
    }
    right_len = PyUnicode_GET_LENGTH(right);
    if (right_len == 0) {
        Py_INCREF(left);
        return left;
    }
    if (unlikely(left_len > PY_SSIZE_T_MAX - right_len)) {
        PyErr_SetString(PyExc_OverflowError,
                        "strings are too large to concat");
        return NULL;
    }
    new_len = left_len + right_len;
    if (__Pyx_unicode_modifiable(left)
            && PyUnicode_CheckExact(right)
            && PyUnicode_KIND(right) <= PyUnicode_KIND(left)
            && !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right))) {
        int ret;
        __Pyx_GIVEREF(*p_left);
        ret = PyUnicode_Resize(p_left, new_len);
        __Pyx_GOTREF(*p_left);
        if (unlikely(ret != 0))
            return NULL;
        #if PY_VERSION_HEX >= 0x030d0000
        if (unlikely(PyUnicode_CopyCharacters(*p_left, left_len, right, 0, right_len) < 0)) return NULL;
        #else
        _PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len);
        #endif
        __Pyx_INCREF(*p_left);
        __Pyx_GIVEREF(*p_left);
        return *p_left;
    } else {
        return __Pyx_PyUnicode_Concat(left, right);
    }
  }
#endif

/* WriteUnraisableException */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
    else state = (PyGILState_STATE)0;
#endif
    CYTHON_UNUSED_VAR(clineno);
    CYTHON_UNUSED_VAR(lineno);
    CYTHON_UNUSED_VAR(filename);
    CYTHON_MAYBE_UNUSED_VAR(nogil);
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(0);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* PyObjectCall2Args */
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args[3] = {NULL, arg1, arg2};
    return __Pyx_PyObject_FastCall(function, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET);
}

/* PyObjectGetMethod */
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
    PyObject *attr;
#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
    __Pyx_TypeName type_name;
    PyTypeObject *tp = Py_TYPE(obj);
    PyObject *descr;
    descrgetfunc f = NULL;
    PyObject **dictptr, *dict;
    int meth_found = 0;
    assert (*method == NULL);
    if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
        attr = __Pyx_PyObject_GetAttrStr(obj, name);
        goto try_unpack;
    }
    if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
        return 0;
    }
    descr = _PyType_Lookup(tp, name);
    if (likely(descr != NULL)) {
        Py_INCREF(descr);
#if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR
        if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR))
#elif PY_MAJOR_VERSION >= 3
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type)))
        #endif
#else
        #ifdef __Pyx_CyFunction_USED
        if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr)))
        #else
        if (likely(PyFunction_Check(descr)))
        #endif
#endif
        {
            meth_found = 1;
        } else {
            f = Py_TYPE(descr)->tp_descr_get;
            if (f != NULL && PyDescr_IsData(descr)) {
                attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
                Py_DECREF(descr);
                goto try_unpack;
            }
        }
    }
    dictptr = _PyObject_GetDictPtr(obj);
    if (dictptr != NULL && (dict = *dictptr) != NULL) {
        Py_INCREF(dict);
        attr = __Pyx_PyDict_GetItemStr(dict, name);
        if (attr != NULL) {
            Py_INCREF(attr);
            Py_DECREF(dict);
            Py_XDECREF(descr);
            goto try_unpack;
        }
        Py_DECREF(dict);
    }
    if (meth_found) {
        *method = descr;
        return 1;
    }
    if (f != NULL) {
        attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
        Py_DECREF(descr);
        goto try_unpack;
    }
    if (likely(descr != NULL)) {
        *method = descr;
        return 0;
    }
    type_name = __Pyx_PyType_GetName(tp);
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'",
                 type_name, name);
#else
                 "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'",
                 type_name, PyString_AS_STRING(name));
#endif
    __Pyx_DECREF_TypeName(type_name);
    return 0;
#else
    attr = __Pyx_PyObject_GetAttrStr(obj, name);
    goto try_unpack;
#endif
try_unpack:
#if CYTHON_UNPACK_METHODS
    if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
        PyObject *function = PyMethod_GET_FUNCTION(attr);
        Py_INCREF(function);
        Py_DECREF(attr);
        *method = function;
        return 1;
    }
#endif
    *method = attr;
    return 0;
}

/* PyObjectCallMethod1 */
#if !(CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C00A2)
static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
    PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
    Py_DECREF(method);
    return result;
}
#endif
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
#if CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C00A2
    PyObject *args[2] = {obj, arg};
    (void) __Pyx_PyObject_GetMethod;
    (void) __Pyx_PyObject_CallOneArg;
    (void) __Pyx_PyObject_Call2Args;
    return PyObject_VectorcallMethod(method_name, args, 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
#else
    PyObject *method = NULL, *result;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_Call2Args(method, obj, arg);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) return NULL;
    return __Pyx__PyObject_CallMethod1(method, arg);
#endif
}

/* append */
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_MAYBE_UNUSED_VAR(inplace);
    CYTHON_UNUSED_VAR(zerodivision_check);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
        
            x = (long)((unsigned long)a + (unsigned long)b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        if (unlikely(__Pyx_PyLong_IsZero(op1))) {
            return __Pyx_NewRef(op2);
        }
        if (likely(__Pyx_PyLong_IsCompact(op1))) {
            a = __Pyx_PyLong_CompactValue(op1);
        } else {
            const digit* digits = __Pyx_PyLong_Digits(op1);
            const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1);
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
#if CYTHON_COMPILING_IN_LIMITED_API
        double a = __pyx_PyFloat_AsDouble(op1);
#else
        double a = PyFloat_AS_DOUBLE(op1);
#endif
            double result;
            
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* ArgTypeTest */
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{
    __Pyx_TypeName type_name;
    __Pyx_TypeName obj_type_name;
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    else if (exact) {
        #if PY_MAJOR_VERSION == 2
        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
    }
    type_name = __Pyx_PyType_GetName(type);
    obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME
        ", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name);
    __Pyx_DECREF_TypeName(type_name);
    __Pyx_DECREF_TypeName(obj_type_name);
    return 0;
}

/* GetAttr */
static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
#if CYTHON_USE_TYPE_SLOTS
#if PY_MAJOR_VERSION >= 3
    if (likely(PyUnicode_Check(n)))
#else
    if (likely(PyString_Check(n)))
#endif
        return __Pyx_PyObject_GetAttrStr(o, n);
#endif
    return PyObject_GetAttr(o, n);
}

/* HasAttr */
static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) {
    PyObject *r;
    if (unlikely(!__Pyx_PyBaseString_Check(n))) {
        PyErr_SetString(PyExc_TypeError,
                        "hasattr(): attribute name must be string");
        return -1;
    }
    r = __Pyx_GetAttr(o, n);
    if (!r) {
        PyErr_Clear();
        return 0;
    } else {
        Py_DECREF(r);
        return 1;
    }
}

/* ExtTypeTest */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    __Pyx_TypeName obj_type_name;
    __Pyx_TypeName type_name;
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(__Pyx_TypeCheck(obj, type)))
        return 1;
    obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
    type_name = __Pyx_PyType_GetName(type);
    PyErr_Format(PyExc_TypeError,
                 "Cannot convert " __Pyx_FMT_TYPENAME " to " __Pyx_FMT_TYPENAME,
                 obj_type_name, type_name);
    __Pyx_DECREF_TypeName(obj_type_name);
    __Pyx_DECREF_TypeName(type_name);
    return 0;
}

/* PyIntCompare */
static CYTHON_INLINE int __Pyx_PyInt_BoolNeObjC(PyObject *op1, PyObject *op2, long intval, long inplace) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_UNUSED_VAR(inplace);
    if (op1 == op2) {
        return 0;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        return (a != b);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = __Pyx_PyLong_DigitCount(op1);
        const digit* digits = __Pyx_PyLong_Digits(op1);
        if (intval == 0) {
            return (__Pyx_PyLong_IsZero(op1) != 1);
        } else if (intval < 0) {
            if (__Pyx_PyLong_IsNonNeg(op1))
                return 1;
            intval = -intval;
        } else {
            if (__Pyx_PyLong_IsNeg(op1))
                return 1;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        return (unequal != 0);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
#if CYTHON_COMPILING_IN_LIMITED_API
        double a = __pyx_PyFloat_AsDouble(op1);
#else
        double a = PyFloat_AS_DOUBLE(op1);
#endif
        return ((double)a != (double)b);
    }
    return __Pyx_PyObject_IsTrueAndDecref(
        PyObject_RichCompare(op1, op2, Py_NE));
}

/* PyObjectCallMethod0 */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
    PyObject *method = NULL, *result = NULL;
    int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
    if (likely(is_method)) {
        result = __Pyx_PyObject_CallOneArg(method, obj);
        Py_DECREF(method);
        return result;
    }
    if (unlikely(!method)) goto bad;
    result = __Pyx_PyObject_CallNoArg(method);
    Py_DECREF(method);
bad:
    return result;
}

/* RaiseNoneIterError */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* UnpackTupleError */
static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
    if (t == Py_None) {
      __Pyx_RaiseNoneNotIterableError();
    } else if (PyTuple_GET_SIZE(t) < index) {
      __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
    } else {
      __Pyx_RaiseTooManyValuesError(index);
    }
}

/* UnpackTuple2 */
static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
        PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) {
    PyObject *value1 = NULL, *value2 = NULL;
#if CYTHON_COMPILING_IN_PYPY
    value1 = PySequence_ITEM(tuple, 0);  if (unlikely(!value1)) goto bad;
    value2 = PySequence_ITEM(tuple, 1);  if (unlikely(!value2)) goto bad;
#else
    value1 = PyTuple_GET_ITEM(tuple, 0);  Py_INCREF(value1);
    value2 = PyTuple_GET_ITEM(tuple, 1);  Py_INCREF(value2);
#endif
    if (decref_tuple) {
        Py_DECREF(tuple);
    }
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
#if CYTHON_COMPILING_IN_PYPY
bad:
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
#endif
}
static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
                                       int has_known_size, int decref_tuple) {
    Py_ssize_t index;
    PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
    iternextfunc iternext;
    iter = PyObject_GetIter(tuple);
    if (unlikely(!iter)) goto bad;
    if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
    iternext = __Pyx_PyObject_GetIterNextFunc(iter);
    value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
    value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
    if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
    Py_DECREF(iter);
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
unpacking_failed:
    if (!has_known_size && __Pyx_IterFinish() == 0)
        __Pyx_RaiseNeedMoreValuesError(index);
bad:
    Py_XDECREF(iter);
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
}

/* dict_iter */
#if CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
#include <string.h>
#endif
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_source_is_dict) {
    is_dict = is_dict || likely(PyDict_CheckExact(iterable));
    *p_source_is_dict = is_dict;
    if (is_dict) {
#if !CYTHON_COMPILING_IN_PYPY
        *p_orig_length = PyDict_Size(iterable);
        Py_INCREF(iterable);
        return iterable;
#elif PY_MAJOR_VERSION >= 3
        static PyObject *py_items = NULL, *py_keys = NULL, *py_values = NULL;
        PyObject **pp = NULL;
        if (method_name) {
            const char *name = PyUnicode_AsUTF8(method_name);
            if (strcmp(name, "iteritems") == 0) pp = &py_items;
            else if (strcmp(name, "iterkeys") == 0) pp = &py_keys;
            else if (strcmp(name, "itervalues") == 0) pp = &py_values;
            if (pp) {
                if (!*pp) {
                    *pp = PyUnicode_FromString(name + 4);
                    if (!*pp)
                        return NULL;
                }
                method_name = *pp;
            }
        }
#endif
    }
    *p_orig_length = 0;
    if (method_name) {
        PyObject* iter;
        iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
        if (!iterable)
            return NULL;
#if !CYTHON_COMPILING_IN_PYPY
        if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
            return iterable;
#endif
        iter = PyObject_GetIter(iterable);
        Py_DECREF(iterable);
        return iter;
    }
    return PyObject_GetIter(iterable);
}
static CYTHON_INLINE int __Pyx_dict_iter_next(
        PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
        PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
    PyObject* next_item;
#if !CYTHON_COMPILING_IN_PYPY
    if (source_is_dict) {
        PyObject *key, *value;
        if (unlikely(orig_length != PyDict_Size(iter_obj))) {
            PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
            return -1;
        }
        if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
            return 0;
        }
        if (pitem) {
            PyObject* tuple = PyTuple_New(2);
            if (unlikely(!tuple)) {
                return -1;
            }
            Py_INCREF(key);
            Py_INCREF(value);
            PyTuple_SET_ITEM(tuple, 0, key);
            PyTuple_SET_ITEM(tuple, 1, value);
            *pitem = tuple;
        } else {
            if (pkey) {
                Py_INCREF(key);
                *pkey = key;
            }
            if (pvalue) {
                Py_INCREF(value);
                *pvalue = value;
            }
        }
        return 1;
    } else if (PyTuple_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyTuple_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else if (PyList_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyList_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else
#endif
    {
        next_item = PyIter_Next(iter_obj);
        if (unlikely(!next_item)) {
            return __Pyx_IterFinish();
        }
    }
    if (pitem) {
        *pitem = next_item;
    } else if (pkey && pvalue) {
        if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
            return -1;
    } else if (pkey) {
        *pkey = next_item;
    } else {
        *pvalue = next_item;
    }
    return 1;
}

/* MergeKeywords */
static int __Pyx_MergeKeywords(PyObject *kwdict, PyObject *source_mapping) {
    PyObject *iter, *key = NULL, *value = NULL;
    int source_is_dict, result;
    Py_ssize_t orig_length, ppos = 0;
    iter = __Pyx_dict_iterator(source_mapping, 0, __pyx_n_s_items, &orig_length, &source_is_dict);
    if (unlikely(!iter)) {
        PyObject *args;
        if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError))) goto bad;
        PyErr_Clear();
        args = PyTuple_Pack(1, source_mapping);
        if (likely(args)) {
            PyObject *fallback = PyObject_Call((PyObject*)&PyDict_Type, args, NULL);
            Py_DECREF(args);
            if (likely(fallback)) {
                iter = __Pyx_dict_iterator(fallback, 1, __pyx_n_s_items, &orig_length, &source_is_dict);
                Py_DECREF(fallback);
            }
        }
        if (unlikely(!iter)) goto bad;
    }
    while (1) {
        result = __Pyx_dict_iter_next(iter, orig_length, &ppos, &key, &value, NULL, source_is_dict);
        if (unlikely(result < 0)) goto bad;
        if (!result) break;
        if (unlikely(PyDict_Contains(kwdict, key))) {
            __Pyx_RaiseDoubleKeywordsError("function", key);
            result = -1;
        } else {
            result = PyDict_SetItem(kwdict, key, value);
        }
        Py_DECREF(key);
        Py_DECREF(value);
        if (unlikely(result < 0)) goto bad;
    }
    Py_XDECREF(iter);
    return 0;
bad:
    Py_XDECREF(iter);
    return -1;
}

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AndObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) {
    CYTHON_MAYBE_UNUSED_VAR(intval);
    CYTHON_MAYBE_UNUSED_VAR(inplace);
    CYTHON_UNUSED_VAR(zerodivision_check);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        
            return PyInt_FromLong(a & b);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        if ((intval & PyLong_MASK) == intval) {
            long last_digit = (long) __Pyx_PyLong_Digits(op1)[0];
            long result = intval & (likely(__Pyx_PyLong_IsPos(op1)) ? last_digit : (PyLong_MASK - last_digit + 1));
            return PyLong_FromLong(result);
        }
        if (unlikely(__Pyx_PyLong_IsZero(op1))) {
            return __Pyx_NewRef(op1);
        }
        if (likely(__Pyx_PyLong_IsCompact(op1))) {
            a = __Pyx_PyLong_CompactValue(op1);
        } else {
            const digit* digits = __Pyx_PyLong_Digits(op1);
            const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1);
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    #ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    #endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_and(op1, op2);
            }
        }
                x = a & b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla & llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    return (inplace ? PyNumber_InPlaceAnd : PyNumber_And)(op1, op2);
}
#endif

/* RaiseUnexpectedTypeError */
static int
__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj)
{
    __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj));
    PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME,
                 expected, obj_type_name);
    __Pyx_DECREF_TypeName(obj_type_name);
    return 0;
}

/* GetItemIntUnicode */
static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i,
                                                           int wraparound, int boundscheck) {
    Py_ssize_t length;
    if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return (Py_UCS4)-1;
    if (wraparound | boundscheck) {
        length = __Pyx_PyUnicode_GET_LENGTH(ustring);
        if (wraparound & unlikely(i < 0)) i += length;
        if ((!boundscheck) || likely(__Pyx_is_valid_index(i, length))) {
            return __Pyx_PyUnicode_READ_CHAR(ustring, i);
        } else {
            PyErr_SetString(PyExc_IndexError, "string index out of range");
            return (Py_UCS4)-1;
        }
    } else {
        return __Pyx_PyUnicode_READ_CHAR(ustring, i);
    }
}

/* RaiseUnboundLocalError */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* pyfrozenset_new */
static CYTHON_INLINE PyObject* __Pyx_PyFrozenSet_New(PyObject* it) {
    if (it) {
        PyObject* result;
#if CYTHON_COMPILING_IN_PYPY
        PyObject* args;
        args = PyTuple_Pack(1, it);
        if (unlikely(!args))
            return NULL;
        result = PyObject_Call((PyObject*)&PyFrozenSet_Type, args, NULL);
        Py_DECREF(args);
        return result;
#else
        if (PyFrozenSet_CheckExact(it)) {
            Py_INCREF(it);
            return it;
        }
        result = PyFrozenSet_New(it);
        if (unlikely(!result))
            return NULL;
        if ((PY_VERSION_HEX >= 0x031000A1) || likely(PySet_GET_SIZE(result)))
            return result;
        Py_DECREF(result);
#endif
    }
#if CYTHON_USE_TYPE_SLOTS
    return PyFrozenSet_Type.tp_new(&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#else
    return PyObject_Call((PyObject*)&PyFrozenSet_Type, __pyx_empty_tuple, NULL);
#endif
}

/* PySetContains */
static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) {
    int result = -1;
    if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) {
        PyObject *tmpkey;
        PyErr_Clear();
        tmpkey = __Pyx_PyFrozenSet_New(key);
        if (tmpkey != NULL) {
            result = PySet_Contains(set, tmpkey);
            Py_DECREF(tmpkey);
        }
    }
    return result;
}
static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) {
    int result = PySet_Contains(set, key);
    if (unlikely(result < 0)) {
        result = __Pyx_PySet_ContainsUnhashable(set, key);
    }
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* UnpackUnboundCMethod */
static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject *args, PyObject *kwargs) {
    PyObject *result;
    PyObject *selfless_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args));
    if (unlikely(!selfless_args)) return NULL;
    result = PyObject_Call(method, selfless_args, kwargs);
    Py_DECREF(selfless_args);
    return result;
}
static PyMethodDef __Pyx_UnboundCMethod_Def = {
     "CythonUnboundCMethod",
     __PYX_REINTERPRET_FUNCION(PyCFunction, __Pyx_SelflessCall),
     METH_VARARGS | METH_KEYWORDS,
     NULL
};
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
    #else
    if (likely(!__Pyx_CyOrPyCFunction_Check(method)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
    } else
#endif
#if CYTHON_COMPILING_IN_PYPY
#else
    if (PyCFunction_Check(method))
#endif
    {
        PyObject *self;
        int self_found;
#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
        self = PyObject_GetAttrString(method, "__self__");
        if (!self) {
            PyErr_Clear();
        }
#else
        self = PyCFunction_GET_SELF(method);
#endif
        self_found = (self && self != Py_None);
#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY
        Py_XDECREF(self);
#endif
        if (self_found) {
            PyObject *unbound_method = PyCFunction_New(&__Pyx_UnboundCMethod_Def, method);
            if (unlikely(!unbound_method)) return -1;
            Py_DECREF(method);
            target->method = unbound_method;
        }
    }
    return 0;
}

/* CallUnboundCMethod1 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
    if (likely(cfunc->func)) {
        int flag = cfunc->flag;
        if (flag == METH_O) {
            return (*(cfunc->func))(self, arg);
        } else if ((PY_VERSION_HEX >= 0x030600B1) && flag == METH_FASTCALL) {
            #if PY_VERSION_HEX >= 0x030700A0
                return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
            #else
                return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
            #endif
        } else if ((PY_VERSION_HEX >= 0x030700A0) && flag == (METH_FASTCALL | METH_KEYWORDS)) {
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
        }
    }
    return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(1);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 0, arg);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 1, arg);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(2, self, arg);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* CallUnboundCMethod2 */
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
    if (likely(cfunc->func)) {
        PyObject *args[2] = {arg1, arg2};
        if (cfunc->flag == METH_FASTCALL) {
            #if PY_VERSION_HEX >= 0x030700A0
            return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2);
            #else
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
            #endif
        }
        #if PY_VERSION_HEX >= 0x030700A0
        if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
        #endif
    }
    return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 0, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 1, arg2);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(3);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 1, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 2, arg2);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(3, self, arg1, arg2);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* dict_getitem_default */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000)
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (unlikely(PyErr_Occurred()))
            return NULL;
        value = default_value;
    }
    Py_INCREF(value);
    if ((1));
#else
    if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
        value = PyDict_GetItem(d, key);
        if (unlikely(!value)) {
            value = default_value;
        }
        Py_INCREF(value);
    }
#endif
    else {
        if (default_value == Py_None)
            value = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_get, d, key);
        else
            value = __Pyx_CallUnboundCMethod2(&__pyx_umethod_PyDict_Type_get, d, key, default_value);
    }
    return value;
}

/* GetAttr3 */
#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1
static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
        return NULL;
    __Pyx_PyErr_Clear();
    Py_INCREF(d);
    return d;
}
#endif
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) {
    PyObject *r;
#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1
    int res = PyObject_GetOptionalAttr(o, n, &r);
    return (res != 0) ? r : __Pyx_NewRef(d);
#else
  #if CYTHON_USE_TYPE_SLOTS
    if (likely(PyString_Check(n))) {
        r = __Pyx_PyObject_GetAttrStrNoError(o, n);
        if (unlikely(!r) && likely(!PyErr_Occurred())) {
            r = __Pyx_NewRef(d);
        }
        return r;
    }
  #endif
    r = PyObject_GetAttr(o, n);
    return (likely(r)) ? r : __Pyx_GetAttr3Default(d);
#endif
}

/* Import */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *module = 0;
    PyObject *empty_dict = 0;
    PyObject *empty_list = 0;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (unlikely(!py_import))
        goto bad;
    if (!from_list) {
        empty_list = PyList_New(0);
        if (unlikely(!empty_list))
            goto bad;
        from_list = empty_list;
    }
    #endif
    empty_dict = PyDict_New();
    if (unlikely(!empty_dict))
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.') != NULL) {
                module = PyImport_ImportModuleLevelObject(
                    name, __pyx_d, empty_dict, from_list, 1);
                if (unlikely(!module)) {
                    if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError)))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (unlikely(!py_level))
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, __pyx_d, empty_dict, from_list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, __pyx_d, empty_dict, from_list, level);
            #endif
        }
    }
bad:
    Py_XDECREF(empty_dict);
    Py_XDECREF(empty_list);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    return module;
}

/* ImportFrom */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        const char* module_name_str = 0;
        PyObject* module_name = 0;
        PyObject* module_dot = 0;
        PyObject* full_name = 0;
        PyErr_Clear();
        module_name_str = PyModule_GetName(module);
        if (unlikely(!module_name_str)) { goto modbad; }
        module_name = PyUnicode_FromString(module_name_str);
        if (unlikely(!module_name)) { goto modbad; }
        module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__124);
        if (unlikely(!module_dot)) { goto modbad; }
        full_name = PyUnicode_Concat(module_dot, name);
        if (unlikely(!full_name)) { goto modbad; }
        #if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM  < 0x07030400)
        {
            PyObject *modules = PyImport_GetModuleDict();
            if (unlikely(!modules))
                goto modbad;
            value = PyObject_GetItem(modules, full_name);
        }
        #else
        value = PyImport_GetModule(full_name);
        #endif
      modbad:
        Py_XDECREF(full_name);
        Py_XDECREF(module_dot);
        Py_XDECREF(module_name);
    }
    if (unlikely(!value)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* CallNextTpDealloc */
static void __Pyx_call_next_tp_dealloc(PyObject* obj, destructor current_tp_dealloc) {
    PyTypeObject* type = Py_TYPE(obj);
    destructor tp_dealloc = NULL;
    while (type && __Pyx_PyType_GetSlot(type, tp_dealloc, destructor) != current_tp_dealloc)
        type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
    while (type && (tp_dealloc = __Pyx_PyType_GetSlot(type, tp_dealloc, destructor)) == current_tp_dealloc)
        type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
    if (type)
        tp_dealloc(obj);
}

/* CallNextTpTraverse */
static int __Pyx_call_next_tp_traverse(PyObject* obj, visitproc v, void *a, traverseproc current_tp_traverse) {
    PyTypeObject* type = Py_TYPE(obj);
    traverseproc tp_traverse = NULL;
    while (type && __Pyx_PyType_GetSlot(type, tp_traverse, traverseproc) != current_tp_traverse)
        type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
    while (type && (tp_traverse = __Pyx_PyType_GetSlot(type, tp_traverse, traverseproc)) == current_tp_traverse)
        type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
    if (type && tp_traverse)
        return tp_traverse(obj, v, a);
    return 0;
}

/* CallNextTpClear */
static void __Pyx_call_next_tp_clear(PyObject* obj, inquiry current_tp_clear) {
    PyTypeObject* type = Py_TYPE(obj);
    inquiry tp_clear = NULL;
    while (type && __Pyx_PyType_GetSlot(type, tp_clear, inquiry) != current_tp_clear)
        type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
    while (type && (tp_clear = __Pyx_PyType_GetSlot(type, tp_clear, inquiry)) == current_tp_clear)
        type = __Pyx_PyType_GetSlot(type, tp_base, PyTypeObject*);
    if (type && tp_clear)
        tp_clear(obj);
}

/* FixUpExtensionType */
#if CYTHON_USE_TYPE_SPECS
static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) {
#if PY_VERSION_HEX > 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API
    CYTHON_UNUSED_VAR(spec);
    CYTHON_UNUSED_VAR(type);
#else
    const PyType_Slot *slot = spec->slots;
    while (slot && slot->slot && slot->slot != Py_tp_members)
        slot++;
    if (slot && slot->slot == Py_tp_members) {
        int changed = 0;
#if !(PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON)
        const
#endif
            PyMemberDef *memb = (PyMemberDef*) slot->pfunc;
        while (memb && memb->name) {
            if (memb->name[0] == '_' && memb->name[1] == '_') {
#if PY_VERSION_HEX < 0x030900b1
                if (strcmp(memb->name, "__weaklistoffset__") == 0) {
                    assert(memb->type == T_PYSSIZET);
                    assert(memb->flags == READONLY);
                    type->tp_weaklistoffset = memb->offset;
                    changed = 1;
                }
                else if (strcmp(memb->name, "__dictoffset__") == 0) {
                    assert(memb->type == T_PYSSIZET);
                    assert(memb->flags == READONLY);
                    type->tp_dictoffset = memb->offset;
                    changed = 1;
                }
#if CYTHON_METH_FASTCALL
                else if (strcmp(memb->name, "__vectorcalloffset__") == 0) {
                    assert(memb->type == T_PYSSIZET);
                    assert(memb->flags == READONLY);
#if PY_VERSION_HEX >= 0x030800b4
                    type->tp_vectorcall_offset = memb->offset;
#else
                    type->tp_print = (printfunc) memb->offset;
#endif
                    changed = 1;
                }
#endif
#else
                if ((0));
#endif
#if PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON
                else if (strcmp(memb->name, "__module__") == 0) {
                    PyObject *descr;
                    assert(memb->type == T_OBJECT);
                    assert(memb->flags == 0 || memb->flags == READONLY);
                    descr = PyDescr_NewMember(type, memb);
                    if (unlikely(!descr))
                        return -1;
                    if (unlikely(PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr) < 0)) {
                        Py_DECREF(descr);
                        return -1;
                    }
                    Py_DECREF(descr);
                    changed = 1;
                }
#endif
            }
            memb++;
        }
        if (changed)
            PyType_Modified(type);
    }
#endif
    return 0;
}
#endif

/* ValidateBasesTuple */
#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS
static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) {
    Py_ssize_t i, n;
#if CYTHON_ASSUME_SAFE_MACROS
    n = PyTuple_GET_SIZE(bases);
#else
    n = PyTuple_Size(bases);
    if (n < 0) return -1;
#endif
    for (i = 1; i < n; i++)
    {
#if CYTHON_AVOID_BORROWED_REFS
        PyObject *b0 = PySequence_GetItem(bases, i);
        if (!b0) return -1;
#elif CYTHON_ASSUME_SAFE_MACROS
        PyObject *b0 = PyTuple_GET_ITEM(bases, i);
#else
        PyObject *b0 = PyTuple_GetItem(bases, i);
        if (!b0) return -1;
#endif
        PyTypeObject *b;
#if PY_MAJOR_VERSION < 3
        if (PyClass_Check(b0))
        {
            PyErr_Format(PyExc_TypeError, "base class '%.200s' is an old-style class",
                         PyString_AS_STRING(((PyClassObject*)b0)->cl_name));
#if CYTHON_AVOID_BORROWED_REFS
            Py_DECREF(b0);
#endif
            return -1;
        }
#endif
        b = (PyTypeObject*) b0;
        if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE))
        {
            __Pyx_TypeName b_name = __Pyx_PyType_GetName(b);
            PyErr_Format(PyExc_TypeError,
                "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name);
            __Pyx_DECREF_TypeName(b_name);
#if CYTHON_AVOID_BORROWED_REFS
            Py_DECREF(b0);
#endif
            return -1;
        }
        if (dictoffset == 0)
        {
            Py_ssize_t b_dictoffset = 0;
#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
            b_dictoffset = b->tp_dictoffset;
#else
            PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__");
            if (!py_b_dictoffset) goto dictoffset_return;
            b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset);
            Py_DECREF(py_b_dictoffset);
            if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return;
#endif
            if (b_dictoffset) {
                {
                    __Pyx_TypeName b_name = __Pyx_PyType_GetName(b);
                    PyErr_Format(PyExc_TypeError,
                        "extension type '%.200s' has no __dict__ slot, "
                        "but base type '" __Pyx_FMT_TYPENAME "' has: "
                        "either add 'cdef dict __dict__' to the extension type "
                        "or add '__slots__ = [...]' to the base type",
                        type_name, b_name);
                    __Pyx_DECREF_TypeName(b_name);
                }
#if !(CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY)
              dictoffset_return:
#endif
#if CYTHON_AVOID_BORROWED_REFS
                Py_DECREF(b0);
#endif
                return -1;
            }
        }
#if CYTHON_AVOID_BORROWED_REFS
        Py_DECREF(b0);
#endif
    }
    return 0;
}
#endif

/* PyType_Ready */
static int __Pyx_PyType_Ready(PyTypeObject *t) {
#if CYTHON_USE_TYPE_SPECS || !(CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API) || defined(PYSTON_MAJOR_VERSION)
    (void)__Pyx_PyObject_CallMethod0;
#if CYTHON_USE_TYPE_SPECS
    (void)__Pyx_validate_bases_tuple;
#endif
    return PyType_Ready(t);
#else
    int r;
    PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*);
    if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1))
        return -1;
#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION)
    {
        int gc_was_enabled;
    #if PY_VERSION_HEX >= 0x030A00b1
        gc_was_enabled = PyGC_Disable();
        (void)__Pyx_PyObject_CallMethod0;
    #else
        PyObject *ret, *py_status;
        PyObject *gc = NULL;
        #if PY_VERSION_HEX >= 0x030700a1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400)
        gc = PyImport_GetModule(__pyx_kp_u_gc);
        #endif
        if (unlikely(!gc)) gc = PyImport_Import(__pyx_kp_u_gc);
        if (unlikely(!gc)) return -1;
        py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_isenabled);
        if (unlikely(!py_status)) {
            Py_DECREF(gc);
            return -1;
        }
        gc_was_enabled = __Pyx_PyObject_IsTrue(py_status);
        Py_DECREF(py_status);
        if (gc_was_enabled > 0) {
            ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_disable);
            if (unlikely(!ret)) {
                Py_DECREF(gc);
                return -1;
            }
            Py_DECREF(ret);
        } else if (unlikely(gc_was_enabled == -1)) {
            Py_DECREF(gc);
            return -1;
        }
    #endif
        t->tp_flags |= Py_TPFLAGS_HEAPTYPE;
#if PY_VERSION_HEX >= 0x030A0000
        t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE;
#endif
#else
        (void)__Pyx_PyObject_CallMethod0;
#endif
    r = PyType_Ready(t);
#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION)
        t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
    #if PY_VERSION_HEX >= 0x030A00b1
        if (gc_was_enabled)
            PyGC_Enable();
    #else
        if (gc_was_enabled) {
            PyObject *tp, *v, *tb;
            PyErr_Fetch(&tp, &v, &tb);
            ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_enable);
            if (likely(ret || r == -1)) {
                Py_XDECREF(ret);
                PyErr_Restore(tp, v, tb);
            } else {
                Py_XDECREF(tp);
                Py_XDECREF(v);
                Py_XDECREF(tb);
                r = -1;
            }
        }
        Py_DECREF(gc);
    #endif
    }
#endif
    return r;
#endif
}

/* PyObject_GenericGetAttrNoDict */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
    __Pyx_TypeName type_name = __Pyx_PyType_GetName(tp);
    PyErr_Format(PyExc_AttributeError,
#if PY_MAJOR_VERSION >= 3
                 "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'",
                 type_name, attr_name);
#else
                 "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'",
                 type_name, PyString_AS_STRING(attr_name));
#endif
    __Pyx_DECREF_TypeName(type_name);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
    PyObject *descr;
    PyTypeObject *tp = Py_TYPE(obj);
    if (unlikely(!PyString_Check(attr_name))) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    assert(!tp->tp_dictoffset);
    descr = _PyType_Lookup(tp, attr_name);
    if (unlikely(!descr)) {
        return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
    }
    Py_INCREF(descr);
    #if PY_MAJOR_VERSION < 3
    if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
    #endif
    {
        descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
        if (unlikely(f)) {
            PyObject *res = f(descr, obj, (PyObject *)tp);
            Py_DECREF(descr);
            return res;
        }
    }
    return descr;
}
#endif

/* PyObject_GenericGetAttr */
#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
    if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
        return PyObject_GenericGetAttr(obj, attr_name);
    }
    return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
}
#endif

/* SetupReduce */
#if !CYTHON_COMPILING_IN_LIMITED_API
static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) {
  int ret;
  PyObject *name_attr;
  name_attr = __Pyx_PyObject_GetAttrStrNoError(meth, __pyx_n_s_name_2);
  if (likely(name_attr)) {
      ret = PyObject_RichCompareBool(name_attr, name, Py_EQ);
  } else {
      ret = -1;
  }
  if (unlikely(ret < 0)) {
      PyErr_Clear();
      ret = 0;
  }
  Py_XDECREF(name_attr);
  return ret;
}
static int __Pyx_setup_reduce(PyObject* type_obj) {
    int ret = 0;
    PyObject *object_reduce = NULL;
    PyObject *object_getstate = NULL;
    PyObject *object_reduce_ex = NULL;
    PyObject *reduce = NULL;
    PyObject *reduce_ex = NULL;
    PyObject *reduce_cython = NULL;
    PyObject *setstate = NULL;
    PyObject *setstate_cython = NULL;
    PyObject *getstate = NULL;
#if CYTHON_USE_PYTYPE_LOOKUP
    getstate = _PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate);
#else
    getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_getstate);
    if (!getstate && PyErr_Occurred()) {
        goto __PYX_BAD;
    }
#endif
    if (getstate) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_getstate = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_getstate);
#else
        object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, __pyx_n_s_getstate);
        if (!object_getstate && PyErr_Occurred()) {
            goto __PYX_BAD;
        }
#endif
        if (object_getstate != getstate) {
            goto __PYX_GOOD;
        }
    }
#if CYTHON_USE_PYTYPE_LOOKUP
    object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#else
    object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD;
#endif
    reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD;
    if (reduce_ex == object_reduce_ex) {
#if CYTHON_USE_PYTYPE_LOOKUP
        object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#else
        object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD;
#endif
        reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD;
        if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) {
            reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython);
            if (likely(reduce_cython)) {
                ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
            } else if (reduce == object_reduce || PyErr_Occurred()) {
                goto __PYX_BAD;
            }
            setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate);
            if (!setstate) PyErr_Clear();
            if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) {
                setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython);
                if (likely(setstate_cython)) {
                    ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                    ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
                } else if (!setstate || PyErr_Occurred()) {
                    goto __PYX_BAD;
                }
            }
            PyType_Modified((PyTypeObject*)type_obj);
        }
    }
    goto __PYX_GOOD;
__PYX_BAD:
    if (!PyErr_Occurred()) {
        __Pyx_TypeName type_obj_name =
            __Pyx_PyType_GetName((PyTypeObject*)type_obj);
        PyErr_Format(PyExc_RuntimeError,
            "Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name);
        __Pyx_DECREF_TypeName(type_obj_name);
    }
    ret = -1;
__PYX_GOOD:
#if !CYTHON_USE_PYTYPE_LOOKUP
    Py_XDECREF(object_reduce);
    Py_XDECREF(object_reduce_ex);
    Py_XDECREF(object_getstate);
    Py_XDECREF(getstate);
#endif
    Py_XDECREF(reduce);
    Py_XDECREF(reduce_ex);
    Py_XDECREF(reduce_cython);
    Py_XDECREF(setstate);
    Py_XDECREF(setstate_cython);
    return ret;
}
#endif

/* TypeImport */
#ifndef __PYX_HAVE_RT_ImportType_3_0_11
#define __PYX_HAVE_RT_ImportType_3_0_11
static PyTypeObject *__Pyx_ImportType_3_0_11(PyObject *module, const char *module_name, const char *class_name,
    size_t size, size_t alignment, enum __Pyx_ImportType_CheckSize_3_0_11 check_size)
{
    PyObject *result = 0;
    char warning[200];
    Py_ssize_t basicsize;
    Py_ssize_t itemsize;
#if CYTHON_COMPILING_IN_LIMITED_API
    PyObject *py_basicsize;
    PyObject *py_itemsize;
#endif
    result = PyObject_GetAttrString(module, class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#if !CYTHON_COMPILING_IN_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
    itemsize = ((PyTypeObject *)result)->tp_itemsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
    py_itemsize = PyObject_GetAttrString(result, "__itemsize__");
    if (!py_itemsize)
        goto bad;
    itemsize = PyLong_AsSsize_t(py_itemsize);
    Py_DECREF(py_itemsize);
    py_itemsize = 0;
    if (itemsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (itemsize) {
        if (size % alignment) {
            alignment = size % alignment;
        }
        if (itemsize < (Py_ssize_t)alignment)
            itemsize = (Py_ssize_t)alignment;
    }
    if ((size_t)(basicsize + itemsize) < size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize+itemsize);
        goto bad;
    }
    if (check_size == __Pyx_ImportType_CheckSize_Error_3_0_11 &&
            ((size_t)basicsize > size || (size_t)(basicsize + itemsize) < size)) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd-%zd from PyObject",
            module_name, class_name, size, basicsize, basicsize+itemsize);
        goto bad;
    }
    else if (check_size == __Pyx_ImportType_CheckSize_Warn_3_0_11 && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return NULL;
}
#endif

/* GetVTable */
static void* __Pyx_GetVtable(PyTypeObject *type) {
    void* ptr;
#if CYTHON_COMPILING_IN_LIMITED_API
    PyObject *ob = PyObject_GetAttr((PyObject *)type, __pyx_n_s_pyx_vtable);
#else
    PyObject *ob = PyObject_GetItem(type->tp_dict, __pyx_n_s_pyx_vtable);
#endif
    if (!ob)
        goto bad;
    ptr = PyCapsule_GetPointer(ob, 0);
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

/* SetVTable */
static int __Pyx_SetVtable(PyTypeObject *type, void *vtable) {
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
    if (unlikely(!ob))
        goto bad;
#if CYTHON_COMPILING_IN_LIMITED_API
    if (unlikely(PyObject_SetAttr((PyObject *) type, __pyx_n_s_pyx_vtable, ob) < 0))
#else
    if (unlikely(PyDict_SetItem(type->tp_dict, __pyx_n_s_pyx_vtable, ob) < 0))
#endif
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

/* MergeVTables */
#if !CYTHON_COMPILING_IN_LIMITED_API
static int __Pyx_MergeVtables(PyTypeObject *type) {
    int i;
    void** base_vtables;
    __Pyx_TypeName tp_base_name;
    __Pyx_TypeName base_name;
    void* unknown = (void*)-1;
    PyObject* bases = type->tp_bases;
    int base_depth = 0;
    {
        PyTypeObject* base = type->tp_base;
        while (base) {
            base_depth += 1;
            base = base->tp_base;
        }
    }
    base_vtables = (void**) malloc(sizeof(void*) * (size_t)(base_depth + 1));
    base_vtables[0] = unknown;
    for (i = 1; i < PyTuple_GET_SIZE(bases); i++) {
        void* base_vtable = __Pyx_GetVtable(((PyTypeObject*)PyTuple_GET_ITEM(bases, i)));
        if (base_vtable != NULL) {
            int j;
            PyTypeObject* base = type->tp_base;
            for (j = 0; j < base_depth; j++) {
                if (base_vtables[j] == unknown) {
                    base_vtables[j] = __Pyx_GetVtable(base);
                    base_vtables[j + 1] = unknown;
                }
                if (base_vtables[j] == base_vtable) {
                    break;
                } else if (base_vtables[j] == NULL) {
                    goto bad;
                }
                base = base->tp_base;
            }
        }
    }
    PyErr_Clear();
    free(base_vtables);
    return 0;
bad:
    tp_base_name = __Pyx_PyType_GetName(type->tp_base);
    base_name = __Pyx_PyType_GetName((PyTypeObject*)PyTuple_GET_ITEM(bases, i));
    PyErr_Format(PyExc_TypeError,
        "multiple bases have vtable conflict: '" __Pyx_FMT_TYPENAME "' and '" __Pyx_FMT_TYPENAME "'", tp_base_name, base_name);
    __Pyx_DECREF_TypeName(tp_base_name);
    __Pyx_DECREF_TypeName(base_name);
    free(base_vtables);
    return -1;
}
#endif

/* ImportDottedModule */
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) {
    PyObject *partial_name = NULL, *slice = NULL, *sep = NULL;
    if (unlikely(PyErr_Occurred())) {
        PyErr_Clear();
    }
    if (likely(PyTuple_GET_SIZE(parts_tuple) == count)) {
        partial_name = name;
    } else {
        slice = PySequence_GetSlice(parts_tuple, 0, count);
        if (unlikely(!slice))
            goto bad;
        sep = PyUnicode_FromStringAndSize(".", 1);
        if (unlikely(!sep))
            goto bad;
        partial_name = PyUnicode_Join(sep, slice);
    }
    PyErr_Format(
#if PY_MAJOR_VERSION < 3
        PyExc_ImportError,
        "No module named '%s'", PyString_AS_STRING(partial_name));
#else
#if PY_VERSION_HEX >= 0x030600B1
        PyExc_ModuleNotFoundError,
#else
        PyExc_ImportError,
#endif
        "No module named '%U'", partial_name);
#endif
bad:
    Py_XDECREF(sep);
    Py_XDECREF(slice);
    Py_XDECREF(partial_name);
    return NULL;
}
#endif
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) {
    PyObject *imported_module;
#if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM  < 0x07030400)
    PyObject *modules = PyImport_GetModuleDict();
    if (unlikely(!modules))
        return NULL;
    imported_module = __Pyx_PyDict_GetItemStr(modules, name);
    Py_XINCREF(imported_module);
#else
    imported_module = PyImport_GetModule(name);
#endif
    return imported_module;
}
#endif
#if PY_MAJOR_VERSION >= 3
static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) {
    Py_ssize_t i, nparts;
    nparts = PyTuple_GET_SIZE(parts_tuple);
    for (i=1; i < nparts && module; i++) {
        PyObject *part, *submodule;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        part = PyTuple_GET_ITEM(parts_tuple, i);
#else
        part = PySequence_ITEM(parts_tuple, i);
#endif
        submodule = __Pyx_PyObject_GetAttrStrNoError(module, part);
#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
        Py_DECREF(part);
#endif
        Py_DECREF(module);
        module = submodule;
    }
    if (unlikely(!module)) {
        return __Pyx__ImportDottedModule_Error(name, parts_tuple, i);
    }
    return module;
}
#endif
static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
#if PY_MAJOR_VERSION < 3
    PyObject *module, *from_list, *star = __pyx_n_s__125;
    CYTHON_UNUSED_VAR(parts_tuple);
    from_list = PyList_New(1);
    if (unlikely(!from_list))
        return NULL;
    Py_INCREF(star);
    PyList_SET_ITEM(from_list, 0, star);
    module = __Pyx_Import(name, from_list, 0);
    Py_DECREF(from_list);
    return module;
#else
    PyObject *imported_module;
    PyObject *module = __Pyx_Import(name, NULL, 0);
    if (!parts_tuple || unlikely(!module))
        return module;
    imported_module = __Pyx__ImportDottedModule_Lookup(name);
    if (likely(imported_module)) {
        Py_DECREF(module);
        return imported_module;
    }
    PyErr_Clear();
    return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple);
#endif
}
static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030400B1
    PyObject *module = __Pyx__ImportDottedModule_Lookup(name);
    if (likely(module)) {
        PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_n_s_spec);
        if (likely(spec)) {
            PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_n_s_initializing);
            if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) {
                Py_DECREF(spec);
                spec = NULL;
            }
            Py_XDECREF(unsafe);
        }
        if (likely(!spec)) {
            PyErr_Clear();
            return module;
        }
        Py_DECREF(spec);
        Py_DECREF(module);
    } else if (PyErr_Occurred()) {
        PyErr_Clear();
    }
#endif
    return __Pyx__ImportDottedModule(name, parts_tuple);
}

/* FetchSharedCythonModule */
static PyObject *__Pyx_FetchSharedCythonABIModule(void) {
    return __Pyx_PyImport_AddModuleRef((char*) __PYX_ABI_MODULE_NAME);
}

/* FetchCommonType */
static int __Pyx_VerifyCachedType(PyObject *cached_type,
                               const char *name,
                               Py_ssize_t basicsize,
                               Py_ssize_t expected_basicsize) {
    if (!PyType_Check(cached_type)) {
        PyErr_Format(PyExc_TypeError,
            "Shared Cython type %.200s is not a type object", name);
        return -1;
    }
    if (basicsize != expected_basicsize) {
        PyErr_Format(PyExc_TypeError,
            "Shared Cython type %.200s has the wrong size, try recompiling",
            name);
        return -1;
    }
    return 0;
}
#if !CYTHON_USE_TYPE_SPECS
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* abi_module;
    const char* object_name;
    PyTypeObject *cached_type = NULL;
    abi_module = __Pyx_FetchSharedCythonABIModule();
    if (!abi_module) return NULL;
    object_name = strrchr(type->tp_name, '.');
    object_name = object_name ? object_name+1 : type->tp_name;
    cached_type = (PyTypeObject*) PyObject_GetAttrString(abi_module, object_name);
    if (cached_type) {
        if (__Pyx_VerifyCachedType(
              (PyObject *)cached_type,
              object_name,
              cached_type->tp_basicsize,
              type->tp_basicsize) < 0) {
            goto bad;
        }
        goto done;
    }
    if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
    PyErr_Clear();
    if (PyType_Ready(type) < 0) goto bad;
    if (PyObject_SetAttrString(abi_module, object_name, (PyObject *)type) < 0)
        goto bad;
    Py_INCREF(type);
    cached_type = type;
done:
    Py_DECREF(abi_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}
#else
static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) {
    PyObject *abi_module, *cached_type = NULL;
    const char* object_name = strrchr(spec->name, '.');
    object_name = object_name ? object_name+1 : spec->name;
    abi_module = __Pyx_FetchSharedCythonABIModule();
    if (!abi_module) return NULL;
    cached_type = PyObject_GetAttrString(abi_module, object_name);
    if (cached_type) {
        Py_ssize_t basicsize;
#if CYTHON_COMPILING_IN_LIMITED_API
        PyObject *py_basicsize;
        py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__");
        if (unlikely(!py_basicsize)) goto bad;
        basicsize = PyLong_AsSsize_t(py_basicsize);
        Py_DECREF(py_basicsize);
        py_basicsize = 0;
        if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
#else
        basicsize = likely(PyType_Check(cached_type)) ? ((PyTypeObject*) cached_type)->tp_basicsize : -1;
#endif
        if (__Pyx_VerifyCachedType(
              cached_type,
              object_name,
              basicsize,
              spec->basicsize) < 0) {
            goto bad;
        }
        goto done;
    }
    if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
    PyErr_Clear();
    CYTHON_UNUSED_VAR(module);
    cached_type = __Pyx_PyType_FromModuleAndSpec(abi_module, spec, bases);
    if (unlikely(!cached_type)) goto bad;
    if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad;
    if (PyObject_SetAttrString(abi_module, object_name, cached_type) < 0) goto bad;
done:
    Py_DECREF(abi_module);
    assert(cached_type == NULL || PyType_Check(cached_type));
    return (PyTypeObject *) cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}
#endif

/* PyVectorcallFastCallDict */
#if CYTHON_METH_FASTCALL
static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw)
{
    PyObject *res = NULL;
    PyObject *kwnames;
    PyObject **newargs;
    PyObject **kwvalues;
    Py_ssize_t i, pos;
    size_t j;
    PyObject *key, *value;
    unsigned long keys_are_strings;
    Py_ssize_t nkw = PyDict_GET_SIZE(kw);
    newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0]));
    if (unlikely(newargs == NULL)) {
        PyErr_NoMemory();
        return NULL;
    }
    for (j = 0; j < nargs; j++) newargs[j] = args[j];
    kwnames = PyTuple_New(nkw);
    if (unlikely(kwnames == NULL)) {
        PyMem_Free(newargs);
        return NULL;
    }
    kwvalues = newargs + nargs;
    pos = i = 0;
    keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS;
    while (PyDict_Next(kw, &pos, &key, &value)) {
        keys_are_strings &= Py_TYPE(key)->tp_flags;
        Py_INCREF(key);
        Py_INCREF(value);
        PyTuple_SET_ITEM(kwnames, i, key);
        kwvalues[i] = value;
        i++;
    }
    if (unlikely(!keys_are_strings)) {
        PyErr_SetString(PyExc_TypeError, "keywords must be strings");
        goto cleanup;
    }
    res = vc(func, newargs, nargs, kwnames);
cleanup:
    Py_DECREF(kwnames);
    for (i = 0; i < nkw; i++)
        Py_DECREF(kwvalues[i]);
    PyMem_Free(newargs);
    return res;
}
static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw)
{
    if (likely(kw == NULL) || PyDict_GET_SIZE(kw) == 0) {
        return vc(func, args, nargs, NULL);
    }
    return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw);
}
#endif

/* CythonFunctionShared */
#if CYTHON_COMPILING_IN_LIMITED_API
static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) {
    if (__Pyx_CyFunction_Check(func)) {
        return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc;
    } else if (PyCFunction_Check(func)) {
        return PyCFunction_GetFunction(func) == (PyCFunction) cfunc;
    }
    return 0;
}
#else
static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) {
    return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc;
}
#endif
static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) {
#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API
    __Pyx_Py_XDECREF_SET(
        __Pyx_CyFunction_GetClassObj(f),
            ((classobj) ? __Pyx_NewRef(classobj) : NULL));
#else
    __Pyx_Py_XDECREF_SET(
        ((PyCMethodObject *) (f))->mm_class,
        (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL));
#endif
}
static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure)
{
    CYTHON_UNUSED_VAR(closure);
    if (unlikely(op->func_doc == NULL)) {
#if CYTHON_COMPILING_IN_LIMITED_API
        op->func_doc = PyObject_GetAttrString(op->func, "__doc__");
        if (unlikely(!op->func_doc)) return NULL;
#else
        if (((PyCFunctionObject*)op)->m_ml->ml_doc) {
#if PY_MAJOR_VERSION >= 3
            op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc);
#else
            op->func_doc = PyString_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc);
#endif
            if (unlikely(op->func_doc == NULL))
                return NULL;
        } else {
            Py_INCREF(Py_None);
            return Py_None;
        }
#endif
    }
    Py_INCREF(op->func_doc);
    return op->func_doc;
}
static int
__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context)
{
    CYTHON_UNUSED_VAR(context);
    if (value == NULL) {
        value = Py_None;
    }
    Py_INCREF(value);
    __Pyx_Py_XDECREF_SET(op->func_doc, value);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context)
{
    CYTHON_UNUSED_VAR(context);
    if (unlikely(op->func_name == NULL)) {
#if CYTHON_COMPILING_IN_LIMITED_API
        op->func_name = PyObject_GetAttrString(op->func, "__name__");
#elif PY_MAJOR_VERSION >= 3
        op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name);
#else
        op->func_name = PyString_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name);
#endif
        if (unlikely(op->func_name == NULL))
            return NULL;
    }
    Py_INCREF(op->func_name);
    return op->func_name;
}
static int
__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context)
{
    CYTHON_UNUSED_VAR(context);
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    Py_INCREF(value);
    __Pyx_Py_XDECREF_SET(op->func_name, value);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context)
{
    CYTHON_UNUSED_VAR(context);
    Py_INCREF(op->func_qualname);
    return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context)
{
    CYTHON_UNUSED_VAR(context);
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value)))
#else
    if (unlikely(value == NULL || !PyString_Check(value)))
#endif
    {
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    Py_INCREF(value);
    __Pyx_Py_XDECREF_SET(op->func_qualname, value);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context)
{
    CYTHON_UNUSED_VAR(context);
    if (unlikely(op->func_dict == NULL)) {
        op->func_dict = PyDict_New();
        if (unlikely(op->func_dict == NULL))
            return NULL;
    }
    Py_INCREF(op->func_dict);
    return op->func_dict;
}
static int
__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context)
{
    CYTHON_UNUSED_VAR(context);
    if (unlikely(value == NULL)) {
        PyErr_SetString(PyExc_TypeError,
               "function's dictionary may not be deleted");
        return -1;
    }
    if (unlikely(!PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
               "setting function's dictionary to a non-dict");
        return -1;
    }
    Py_INCREF(value);
    __Pyx_Py_XDECREF_SET(op->func_dict, value);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context)
{
    CYTHON_UNUSED_VAR(context);
    Py_INCREF(op->func_globals);
    return op->func_globals;
}
static PyObject *
__Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context)
{
    CYTHON_UNUSED_VAR(op);
    CYTHON_UNUSED_VAR(context);
    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject *
__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context)
{
    PyObject* result = (op->func_code) ? op->func_code : Py_None;
    CYTHON_UNUSED_VAR(context);
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    int result = 0;
    PyObject *res = op->defaults_getter((PyObject *) op);
    if (unlikely(!res))
        return -1;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    Py_INCREF(op->defaults_tuple);
    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    Py_INCREF(op->defaults_kwdict);
    #else
    op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0);
    if (unlikely(!op->defaults_tuple)) result = -1;
    else {
        op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1);
        if (unlikely(!op->defaults_kwdict)) result = -1;
    }
    #endif
    Py_DECREF(res);
    return result;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) {
    CYTHON_UNUSED_VAR(context);
    if (!value) {
        value = Py_None;
    } else if (unlikely(value != Py_None && !PyTuple_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not "
                 "currently affect the values used in function calls", 1);
    Py_INCREF(value);
    __Pyx_Py_XDECREF_SET(op->defaults_tuple, value);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) {
    PyObject* result = op->defaults_tuple;
    CYTHON_UNUSED_VAR(context);
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL;
            result = op->defaults_tuple;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) {
    CYTHON_UNUSED_VAR(context);
    if (!value) {
        value = Py_None;
    } else if (unlikely(value != Py_None && !PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
                        "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not "
                 "currently affect the values used in function calls", 1);
    Py_INCREF(value);
    __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) {
    PyObject* result = op->defaults_kwdict;
    CYTHON_UNUSED_VAR(context);
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL;
            result = op->defaults_kwdict;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) {
    CYTHON_UNUSED_VAR(context);
    if (!value || value == Py_None) {
        value = NULL;
    } else if (unlikely(!PyDict_Check(value))) {
        PyErr_SetString(PyExc_TypeError,
                        "__annotations__ must be set to a dict object");
        return -1;
    }
    Py_XINCREF(value);
    __Pyx_Py_XDECREF_SET(op->func_annotations, value);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) {
    PyObject* result = op->func_annotations;
    CYTHON_UNUSED_VAR(context);
    if (unlikely(!result)) {
        result = PyDict_New();
        if (unlikely(!result)) return NULL;
        op->func_annotations = result;
    }
    Py_INCREF(result);
    return result;
}
static PyObject *
__Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) {
    int is_coroutine;
    CYTHON_UNUSED_VAR(context);
    if (op->func_is_coroutine) {
        return __Pyx_NewRef(op->func_is_coroutine);
    }
    is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE;
#if PY_VERSION_HEX >= 0x03050000
    if (is_coroutine) {
        PyObject *module, *fromlist, *marker = __pyx_n_s_is_coroutine;
        fromlist = PyList_New(1);
        if (unlikely(!fromlist)) return NULL;
        Py_INCREF(marker);
#if CYTHON_ASSUME_SAFE_MACROS
        PyList_SET_ITEM(fromlist, 0, marker);
#else
        if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) {
            Py_DECREF(marker);
            Py_DECREF(fromlist);
            return NULL;
        }
#endif
        module = PyImport_ImportModuleLevelObject(__pyx_n_s_asyncio_coroutines, NULL, NULL, fromlist, 0);
        Py_DECREF(fromlist);
        if (unlikely(!module)) goto ignore;
        op->func_is_coroutine = __Pyx_PyObject_GetAttrStr(module, marker);
        Py_DECREF(module);
        if (likely(op->func_is_coroutine)) {
            return __Pyx_NewRef(op->func_is_coroutine);
        }
ignore:
        PyErr_Clear();
    }
#endif
    op->func_is_coroutine = __Pyx_PyBool_FromLong(is_coroutine);
    return __Pyx_NewRef(op->func_is_coroutine);
}
#if CYTHON_COMPILING_IN_LIMITED_API
static PyObject *
__Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) {
    CYTHON_UNUSED_VAR(context);
    return PyObject_GetAttrString(op->func, "__module__");
}
static int
__Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) {
    CYTHON_UNUSED_VAR(context);
    return PyObject_SetAttrString(op->func, "__module__", value);
}
#endif
static PyGetSetDef __pyx_CyFunction_getsets[] = {
    {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
    {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    {(char *) "_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0},
#if CYTHON_COMPILING_IN_LIMITED_API
    {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0},
#endif
    {0, 0, 0, 0, 0}
};
static PyMemberDef __pyx_CyFunction_members[] = {
#if !CYTHON_COMPILING_IN_LIMITED_API
    {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0},
#endif
#if CYTHON_USE_TYPE_SPECS
    {(char *) "__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0},
#if CYTHON_METH_FASTCALL
#if CYTHON_BACKPORT_VECTORCALL
    {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0},
#else
#if !CYTHON_COMPILING_IN_LIMITED_API
    {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0},
#endif
#endif
#endif
#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API
    {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0},
#else
    {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0},
#endif
#endif
    {0, 0, 0,  0, 0}
};
static PyObject *
__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args)
{
    CYTHON_UNUSED_VAR(args);
#if PY_MAJOR_VERSION >= 3
    Py_INCREF(m->func_qualname);
    return m->func_qualname;
#else
    return PyString_FromString(((PyCFunctionObject*)m)->m_ml->ml_name);
#endif
}
static PyMethodDef __pyx_CyFunction_methods[] = {
    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    {0, 0, 0, 0}
};
#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
#else
#define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist)
#endif
static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname,
                                       PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
#if !CYTHON_COMPILING_IN_LIMITED_API
    PyCFunctionObject *cf = (PyCFunctionObject*) op;
#endif
    if (unlikely(op == NULL))
        return NULL;
#if CYTHON_COMPILING_IN_LIMITED_API
    op->func = PyCFunction_NewEx(ml, (PyObject*)op, module);
    if (unlikely(!op->func)) return NULL;
#endif
    op->flags = flags;
    __Pyx_CyFunction_weakreflist(op) = NULL;
#if !CYTHON_COMPILING_IN_LIMITED_API
    cf->m_ml = ml;
    cf->m_self = (PyObject *) op;
#endif
    Py_XINCREF(closure);
    op->func_closure = closure;
#if !CYTHON_COMPILING_IN_LIMITED_API
    Py_XINCREF(module);
    cf->m_module = module;
#endif
    op->func_dict = NULL;
    op->func_name = NULL;
    Py_INCREF(qualname);
    op->func_qualname = qualname;
    op->func_doc = NULL;
#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API
    op->func_classobj = NULL;
#else
    ((PyCMethodObject*)op)->mm_class = NULL;
#endif
    op->func_globals = globals;
    Py_INCREF(op->func_globals);
    Py_XINCREF(code);
    op->func_code = code;
    op->defaults_pyobjects = 0;
    op->defaults_size = 0;
    op->defaults = NULL;
    op->defaults_tuple = NULL;
    op->defaults_kwdict = NULL;
    op->defaults_getter = NULL;
    op->func_annotations = NULL;
    op->func_is_coroutine = NULL;
#if CYTHON_METH_FASTCALL
    switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) {
    case METH_NOARGS:
        __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS;
        break;
    case METH_O:
        __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O;
        break;
    case METH_METHOD | METH_FASTCALL | METH_KEYWORDS:
        __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD;
        break;
    case METH_FASTCALL | METH_KEYWORDS:
        __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS;
        break;
    case METH_VARARGS | METH_KEYWORDS:
        __Pyx_CyFunction_func_vectorcall(op) = NULL;
        break;
    default:
        PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction");
        Py_DECREF(op);
        return NULL;
    }
#endif
    return (PyObject *) op;
}
static int
__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
{
    Py_CLEAR(m->func_closure);
#if CYTHON_COMPILING_IN_LIMITED_API
    Py_CLEAR(m->func);
#else
    Py_CLEAR(((PyCFunctionObject*)m)->m_module);
#endif
    Py_CLEAR(m->func_dict);
    Py_CLEAR(m->func_name);
    Py_CLEAR(m->func_qualname);
    Py_CLEAR(m->func_doc);
    Py_CLEAR(m->func_globals);
    Py_CLEAR(m->func_code);
#if !CYTHON_COMPILING_IN_LIMITED_API
#if PY_VERSION_HEX < 0x030900B1
    Py_CLEAR(__Pyx_CyFunction_GetClassObj(m));
#else
    {
        PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class;
        ((PyCMethodObject *) (m))->mm_class = NULL;
        Py_XDECREF(cls);
    }
#endif
#endif
    Py_CLEAR(m->defaults_tuple);
    Py_CLEAR(m->defaults_kwdict);
    Py_CLEAR(m->func_annotations);
    Py_CLEAR(m->func_is_coroutine);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_XDECREF(pydefaults[i]);
        PyObject_Free(m->defaults);
        m->defaults = NULL;
    }
    return 0;
}
static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    if (__Pyx_CyFunction_weakreflist(m) != NULL)
        PyObject_ClearWeakRefs((PyObject *) m);
    __Pyx_CyFunction_clear(m);
    __Pyx_PyHeapTypeObject_GC_Del(m);
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    PyObject_GC_UnTrack(m);
    __Pyx__CyFunction_dealloc(m);
}
static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
{
    Py_VISIT(m->func_closure);
#if CYTHON_COMPILING_IN_LIMITED_API
    Py_VISIT(m->func);
#else
    Py_VISIT(((PyCFunctionObject*)m)->m_module);
#endif
    Py_VISIT(m->func_dict);
    Py_VISIT(m->func_name);
    Py_VISIT(m->func_qualname);
    Py_VISIT(m->func_doc);
    Py_VISIT(m->func_globals);
    Py_VISIT(m->func_code);
#if !CYTHON_COMPILING_IN_LIMITED_API
    Py_VISIT(__Pyx_CyFunction_GetClassObj(m));
#endif
    Py_VISIT(m->defaults_tuple);
    Py_VISIT(m->defaults_kwdict);
    Py_VISIT(m->func_is_coroutine);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_VISIT(pydefaults[i]);
    }
    return 0;
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<cyfunction %U at %p>",
                                op->func_qualname, (void *)op);
#else
    return PyString_FromFormat("<cyfunction %s at %p>",
                               PyString_AsString(op->func_qualname), (void *)op);
#endif
}
static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) {
#if CYTHON_COMPILING_IN_LIMITED_API
    PyObject *f = ((__pyx_CyFunctionObject*)func)->func;
    PyObject *py_name = NULL;
    PyCFunction meth;
    int flags;
    meth = PyCFunction_GetFunction(f);
    if (unlikely(!meth)) return NULL;
    flags = PyCFunction_GetFlags(f);
    if (unlikely(flags < 0)) return NULL;
#else
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = f->m_ml->ml_meth;
    int flags = f->m_ml->ml_flags;
#endif
    Py_ssize_t size;
    switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
    case METH_VARARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0))
            return (*meth)(self, arg);
        break;
    case METH_VARARGS | METH_KEYWORDS:
        return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw);
    case METH_NOARGS:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
#if CYTHON_ASSUME_SAFE_MACROS
            size = PyTuple_GET_SIZE(arg);
#else
            size = PyTuple_Size(arg);
            if (unlikely(size < 0)) return NULL;
#endif
            if (likely(size == 0))
                return (*meth)(self, NULL);
#if CYTHON_COMPILING_IN_LIMITED_API
            py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL);
            if (!py_name) return NULL;
            PyErr_Format(PyExc_TypeError,
                "%.200S() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
                py_name, size);
            Py_DECREF(py_name);
#else
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
#endif
            return NULL;
        }
        break;
    case METH_O:
        if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
#if CYTHON_ASSUME_SAFE_MACROS
            size = PyTuple_GET_SIZE(arg);
#else
            size = PyTuple_Size(arg);
            if (unlikely(size < 0)) return NULL;
#endif
            if (likely(size == 1)) {
                PyObject *result, *arg0;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                arg0 = PyTuple_GET_ITEM(arg, 0);
                #else
                arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL;
                #endif
                result = (*meth)(self, arg0);
                #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
                Py_DECREF(arg0);
                #endif
                return result;
            }
#if CYTHON_COMPILING_IN_LIMITED_API
            py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL);
            if (!py_name) return NULL;
            PyErr_Format(PyExc_TypeError,
                "%.200S() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
                py_name, size);
            Py_DECREF(py_name);
#else
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
                f->m_ml->ml_name, size);
#endif
            return NULL;
        }
        break;
    default:
        PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction");
        return NULL;
    }
#if CYTHON_COMPILING_IN_LIMITED_API
    py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL);
    if (!py_name) return NULL;
    PyErr_Format(PyExc_TypeError, "%.200S() takes no keyword arguments",
                 py_name);
    Py_DECREF(py_name);
#else
    PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
                 f->m_ml->ml_name);
#endif
    return NULL;
}
static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *self, *result;
#if CYTHON_COMPILING_IN_LIMITED_API
    self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func);
    if (unlikely(!self) && PyErr_Occurred()) return NULL;
#else
    self = ((PyCFunctionObject*)func)->m_self;
#endif
    result = __Pyx_CyFunction_CallMethod(func, self, arg, kw);
    return result;
}
static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
    PyObject *result;
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
#if CYTHON_METH_FASTCALL
     __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc);
    if (vc) {
#if CYTHON_ASSUME_SAFE_MACROS
        return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw);
#else
        (void) &__Pyx_PyVectorcall_FastCallDict;
        return PyVectorcall_Call(func, args, kw);
#endif
    }
#endif
    if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
        Py_ssize_t argc;
        PyObject *new_args;
        PyObject *self;
#if CYTHON_ASSUME_SAFE_MACROS
        argc = PyTuple_GET_SIZE(args);
#else
        argc = PyTuple_Size(args);
        if (unlikely(!argc) < 0) return NULL;
#endif
        new_args = PyTuple_GetSlice(args, 1, argc);
        if (unlikely(!new_args))
            return NULL;
        self = PyTuple_GetItem(args, 0);
        if (unlikely(!self)) {
            Py_DECREF(new_args);
#if PY_MAJOR_VERSION > 2
            PyErr_Format(PyExc_TypeError,
                         "unbound method %.200S() needs an argument",
                         cyfunc->func_qualname);
#else
            PyErr_SetString(PyExc_TypeError,
                            "unbound method needs an argument");
#endif
            return NULL;
        }
        result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw);
        Py_DECREF(new_args);
    } else {
        result = __Pyx_CyFunction_Call(func, args, kw);
    }
    return result;
}
#if CYTHON_METH_FASTCALL
static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames)
{
    int ret = 0;
    if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
        if (unlikely(nargs < 1)) {
            PyErr_Format(PyExc_TypeError, "%.200s() needs an argument",
                         ((PyCFunctionObject*)cyfunc)->m_ml->ml_name);
            return -1;
        }
        ret = 1;
    }
    if (unlikely(kwnames) && unlikely(PyTuple_GET_SIZE(kwnames))) {
        PyErr_Format(PyExc_TypeError,
                     "%.200s() takes no keyword arguments", ((PyCFunctionObject*)cyfunc)->m_ml->ml_name);
        return -1;
    }
    return ret;
}
static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
{
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func;
    PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml;
#if CYTHON_BACKPORT_VECTORCALL
    Py_ssize_t nargs = (Py_ssize_t)nargsf;
#else
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
#endif
    PyObject *self;
    switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) {
    case 1:
        self = args[0];
        args += 1;
        nargs -= 1;
        break;
    case 0:
        self = ((PyCFunctionObject*)cyfunc)->m_self;
        break;
    default:
        return NULL;
    }
    if (unlikely(nargs != 0)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
            def->ml_name, nargs);
        return NULL;
    }
    return def->ml_meth(self, NULL);
}
static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
{
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func;
    PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml;
#if CYTHON_BACKPORT_VECTORCALL
    Py_ssize_t nargs = (Py_ssize_t)nargsf;
#else
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
#endif
    PyObject *self;
    switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) {
    case 1:
        self = args[0];
        args += 1;
        nargs -= 1;
        break;
    case 0:
        self = ((PyCFunctionObject*)cyfunc)->m_self;
        break;
    default:
        return NULL;
    }
    if (unlikely(nargs != 1)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
            def->ml_name, nargs);
        return NULL;
    }
    return def->ml_meth(self, args[0]);
}
static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
{
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func;
    PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml;
#if CYTHON_BACKPORT_VECTORCALL
    Py_ssize_t nargs = (Py_ssize_t)nargsf;
#else
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
#endif
    PyObject *self;
    switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) {
    case 1:
        self = args[0];
        args += 1;
        nargs -= 1;
        break;
    case 0:
        self = ((PyCFunctionObject*)cyfunc)->m_self;
        break;
    default:
        return NULL;
    }
    return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))def->ml_meth)(self, args, nargs, kwnames);
}
static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames)
{
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func;
    PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml;
    PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc);
#if CYTHON_BACKPORT_VECTORCALL
    Py_ssize_t nargs = (Py_ssize_t)nargsf;
#else
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
#endif
    PyObject *self;
    switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) {
    case 1:
        self = args[0];
        args += 1;
        nargs -= 1;
        break;
    case 0:
        self = ((PyCFunctionObject*)cyfunc)->m_self;
        break;
    default:
        return NULL;
    }
    return ((__Pyx_PyCMethod)(void(*)(void))def->ml_meth)(self, cls, args, (size_t)nargs, kwnames);
}
#endif
#if CYTHON_USE_TYPE_SPECS
static PyType_Slot __pyx_CyFunctionType_slots[] = {
    {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc},
    {Py_tp_repr, (void *)__Pyx_CyFunction_repr},
    {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod},
    {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse},
    {Py_tp_clear, (void *)__Pyx_CyFunction_clear},
    {Py_tp_methods, (void *)__pyx_CyFunction_methods},
    {Py_tp_members, (void *)__pyx_CyFunction_members},
    {Py_tp_getset, (void *)__pyx_CyFunction_getsets},
    {Py_tp_descr_get, (void *)__Pyx_PyMethod_New},
    {0, 0},
};
static PyType_Spec __pyx_CyFunctionType_spec = {
    __PYX_TYPE_MODULE_PREFIX "cython_function_or_method",
    sizeof(__pyx_CyFunctionObject),
    0,
#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR
    Py_TPFLAGS_METHOD_DESCRIPTOR |
#endif
#if (defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL)
    _Py_TPFLAGS_HAVE_VECTORCALL |
#endif
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
    __pyx_CyFunctionType_slots
};
#else
static PyTypeObject __pyx_CyFunctionType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    __PYX_TYPE_MODULE_PREFIX "cython_function_or_method",
    sizeof(__pyx_CyFunctionObject),
    0,
    (destructor) __Pyx_CyFunction_dealloc,
#if !CYTHON_METH_FASTCALL
    0,
#elif CYTHON_BACKPORT_VECTORCALL
    (printfunc)offsetof(__pyx_CyFunctionObject, func_vectorcall),
#else
    offsetof(PyCFunctionObject, vectorcall),
#endif
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    (reprfunc) __Pyx_CyFunction_repr,
    0,
    0,
    0,
    0,
    __Pyx_CyFunction_CallAsMethod,
    0,
    0,
    0,
    0,
#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR
    Py_TPFLAGS_METHOD_DESCRIPTOR |
#endif
#if defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL
    _Py_TPFLAGS_HAVE_VECTORCALL |
#endif
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
    0,
    (traverseproc) __Pyx_CyFunction_traverse,
    (inquiry) __Pyx_CyFunction_clear,
    0,
#if PY_VERSION_HEX < 0x030500A0
    offsetof(__pyx_CyFunctionObject, func_weakreflist),
#else
    offsetof(PyCFunctionObject, m_weakreflist),
#endif
    0,
    0,
    __pyx_CyFunction_methods,
    __pyx_CyFunction_members,
    __pyx_CyFunction_getsets,
    0,
    0,
    __Pyx_PyMethod_New,
    0,
    offsetof(__pyx_CyFunctionObject, func_dict),
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#endif
#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800)
    0,
#endif
#if __PYX_NEED_TP_PRINT_SLOT
    0,
#endif
#if PY_VERSION_HEX >= 0x030C0000
    0,
#endif
#if PY_VERSION_HEX >= 0x030d00A4
    0,
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
    0,
#endif
};
#endif
static int __pyx_CyFunction_init(PyObject *module) {
#if CYTHON_USE_TYPE_SPECS
    __pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CyFunctionType_spec, NULL);
#else
    CYTHON_UNUSED_VAR(module);
    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
#endif
    if (unlikely(__pyx_CyFunctionType == NULL)) {
        return -1;
    }
    return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults = PyObject_Malloc(size);
    if (unlikely(!m->defaults))
        return PyErr_NoMemory();
    memset(m->defaults, 0, size);
    m->defaults_pyobjects = pyobjects;
    m->defaults_size = size;
    return m->defaults;
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_tuple = tuple;
    Py_INCREF(tuple);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_kwdict = dict;
    Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->func_annotations = dict;
    Py_INCREF(dict);
}

/* CythonFunction */
static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname,
                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    PyObject *op = __Pyx_CyFunction_Init(
        PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType),
        ml, flags, qualname, closure, module, globals, code
    );
    if (likely(op)) {
        PyObject_GC_Track(op);
    }
    return op;
}

/* ClassMethod */
static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
#if CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM <= 0x05080000
    if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) {
        return PyClassMethod_New(method);
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (PyMethodDescr_Check(method))
#else
    #if PY_MAJOR_VERSION == 2
    static PyTypeObject *methoddescr_type = NULL;
    if (unlikely(methoddescr_type == NULL)) {
       PyObject *meth = PyObject_GetAttrString((PyObject*)&PyList_Type, "append");
       if (unlikely(!meth)) return NULL;
       methoddescr_type = Py_TYPE(meth);
       Py_DECREF(meth);
    }
    #else
    PyTypeObject *methoddescr_type = &PyMethodDescr_Type;
    #endif
    if (__Pyx_TypeCheck(method, methoddescr_type))
#endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
        #if PY_VERSION_HEX < 0x03020000
        PyTypeObject *d_type = descr->d_type;
        #else
        PyTypeObject *d_type = descr->d_common.d_type;
        #endif
        return PyDescr_NewClassMethod(d_type, descr->d_method);
    }
#endif
    else if (PyMethod_Check(method)) {
        return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
    }
    else {
        return PyClassMethod_New(method);
    }
}

/* GetNameInClass */
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
    PyObject *result;
    PyObject *dict;
    assert(PyType_Check(nmspace));
#if CYTHON_USE_TYPE_SLOTS
    dict = ((PyTypeObject*)nmspace)->tp_dict;
    Py_XINCREF(dict);
#else
    dict = PyObject_GetAttr(nmspace, __pyx_n_s_dict);
#endif
    if (likely(dict)) {
        result = PyObject_GetItem(dict, name);
        Py_DECREF(dict);
        if (result) {
            return result;
        }
    }
    PyErr_Clear();
    __Pyx_GetModuleGlobalNameUncached(result, name);
    return result;
}

/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    CYTHON_MAYBE_UNUSED_VAR(tstate);
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* CodeObjectCache */
#if !CYTHON_COMPILING_IN_LIMITED_API
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}
#endif

/* AddTraceback */
#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API
  #ifndef Py_BUILD_CORE
    #define Py_BUILD_CORE 1
  #endif
  #include "internal/pycore_frame.h"
#endif
#if CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__Pyx_PyCode_Replace_For_AddTraceback(PyObject *code, PyObject *scratch_dict,
                                                       PyObject *firstlineno, PyObject *name) {
    PyObject *replace = NULL;
    if (unlikely(PyDict_SetItemString(scratch_dict, "co_firstlineno", firstlineno))) return NULL;
    if (unlikely(PyDict_SetItemString(scratch_dict, "co_name", name))) return NULL;
    replace = PyObject_GetAttrString(code, "replace");
    if (likely(replace)) {
        PyObject *result;
        result = PyObject_Call(replace, __pyx_empty_tuple, scratch_dict);
        Py_DECREF(replace);
        return result;
    }
    PyErr_Clear();
    #if __PYX_LIMITED_VERSION_HEX < 0x030780000
    {
        PyObject *compiled = NULL, *result = NULL;
        if (unlikely(PyDict_SetItemString(scratch_dict, "code", code))) return NULL;
        if (unlikely(PyDict_SetItemString(scratch_dict, "type", (PyObject*)(&PyType_Type)))) return NULL;
        compiled = Py_CompileString(
            "out = type(code)(\n"
            "  code.co_argcount, code.co_kwonlyargcount, code.co_nlocals, code.co_stacksize,\n"
            "  code.co_flags, code.co_code, code.co_consts, code.co_names,\n"
            "  code.co_varnames, code.co_filename, co_name, co_firstlineno,\n"
            "  code.co_lnotab)\n", "<dummy>", Py_file_input);
        if (!compiled) return NULL;
        result = PyEval_EvalCode(compiled, scratch_dict, scratch_dict);
        Py_DECREF(compiled);
        if (!result) PyErr_Print();
        Py_DECREF(result);
        result = PyDict_GetItemString(scratch_dict, "out");
        if (result) Py_INCREF(result);
        return result;
    }
    #else
    return NULL;
    #endif
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyObject *code_object = NULL, *py_py_line = NULL, *py_funcname = NULL, *dict = NULL;
    PyObject *replace = NULL, *getframe = NULL, *frame = NULL;
    PyObject *exc_type, *exc_value, *exc_traceback;
    int success = 0;
    if (c_line) {
        (void) __pyx_cfilenm;
        (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line);
    }
    PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
    code_object = Py_CompileString("_getframe()", filename, Py_eval_input);
    if (unlikely(!code_object)) goto bad;
    py_py_line = PyLong_FromLong(py_line);
    if (unlikely(!py_py_line)) goto bad;
    py_funcname = PyUnicode_FromString(funcname);
    if (unlikely(!py_funcname)) goto bad;
    dict = PyDict_New();
    if (unlikely(!dict)) goto bad;
    {
        PyObject *old_code_object = code_object;
        code_object = __Pyx_PyCode_Replace_For_AddTraceback(code_object, dict, py_py_line, py_funcname);
        Py_DECREF(old_code_object);
    }
    if (unlikely(!code_object)) goto bad;
    getframe = PySys_GetObject("_getframe");
    if (unlikely(!getframe)) goto bad;
    if (unlikely(PyDict_SetItemString(dict, "_getframe", getframe))) goto bad;
    frame = PyEval_EvalCode(code_object, dict, dict);
    if (unlikely(!frame) || frame == Py_None) goto bad;
    success = 1;
  bad:
    PyErr_Restore(exc_type, exc_value, exc_traceback);
    Py_XDECREF(code_object);
    Py_XDECREF(py_py_line);
    Py_XDECREF(py_funcname);
    Py_XDECREF(dict);
    Py_XDECREF(replace);
    if (success) {
        PyTraceBack_Here(
            (struct _frame*)frame);
    }
    Py_XDECREF(frame);
}
#else
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = NULL;
    PyObject *py_funcname = NULL;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_srcfile = NULL;
    py_srcfile = PyString_FromString(filename);
    if (!py_srcfile) goto bad;
    #endif
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        if (!py_funcname) goto bad;
        funcname = PyUnicode_AsUTF8(py_funcname);
        if (!funcname) goto bad;
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        if (!py_funcname) goto bad;
        #endif
    }
    #if PY_MAJOR_VERSION < 3
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    #else
    py_code = PyCode_NewEmpty(filename, funcname, py_line);
    #endif
    Py_XDECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_funcname);
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_srcfile);
    #endif
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject *ptype, *pvalue, *ptraceback;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
    if (!py_code) {
        __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) {
            /* If the code object creation fails, then we should clear the
               fetched exception references and propagate the new exception */
            Py_XDECREF(ptype);
            Py_XDECREF(pvalue);
            Py_XDECREF(ptraceback);
            goto bad;
        }
        __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
        __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        tstate,            /*PyThreadState *tstate,*/
        py_code,           /*PyCodeObject *code,*/
        __pyx_d,    /*PyObject *globals,*/
        0                  /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
#endif

/* CIntFromPyVerify */
#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL;
        PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(int));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        arg_tuple = PyTuple_Pack(2, py_bytes, order_str);
        if (!arg_tuple) goto limited_bad;
        if (!is_unsigned) {
            kwds = PyDict_New();
            if (!kwds) goto limited_bad;
            if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad;
        }
        result = PyObject_Call(from_bytes, arg_tuple, kwds);
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(arg_tuple);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(int) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    }
#endif
    if (unlikely(!PyLong_Check(x))) {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
    if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
        if (unlikely(__Pyx_PyLong_IsNeg(x))) {
            goto raise_neg_overflow;
        } else if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_DigitCount(x)) {
                case 2:
                    if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
        }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
        if (unlikely(Py_SIZE(x) < 0)) {
            goto raise_neg_overflow;
        }
#else
        {
            int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
            if (unlikely(result < 0))
                return (int) -1;
            if (unlikely(result == 1))
                goto raise_neg_overflow;
        }
#endif
        if ((sizeof(int) <= sizeof(unsigned long))) {
            __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
        }
    } else {
#if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_SignedDigitCount(x)) {
                case -2:
                    if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
        }
#endif
        if ((sizeof(int) <= sizeof(long))) {
            __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
        }
    }
    {
        int val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
        int one = 1; int is_little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        ret = _PyLong_AsByteArray((PyLongObject *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (int) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (int) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (int) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        val = (int) 0;
        mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
        shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
        for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
            PyObject *tmp, *digit;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((int) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long idigit = PyLong_AsLong(stepval);
            if (unlikely(idigit < 0)) goto done;
            remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
            if (unlikely(idigit >= (1L << remaining_bits)))
                goto raise_overflow;
            val |= ((int) idigit) << bits;
        }
        if (!is_unsigned) {
            if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
                goto raise_overflow;
            if (is_negative)
                val = ~val;
        }
        ret = 0;
    done:
        Py_XDECREF(shift);
        Py_XDECREF(mask);
        Py_XDECREF(stepval);
#endif
        if (unlikely(ret))
            return (int) -1;
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const char neg_one = (char) -1, const_zero = (char) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(char) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(char) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(char) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(char),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL;
        PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(char));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        arg_tuple = PyTuple_Pack(2, py_bytes, order_str);
        if (!arg_tuple) goto limited_bad;
        if (!is_unsigned) {
            kwds = PyDict_New();
            if (!kwds) goto limited_bad;
            if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad;
        }
        result = PyObject_Call(from_bytes, arg_tuple, kwds);
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(arg_tuple);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntFromPy */
static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const char neg_one = (char) -1, const_zero = (char) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(char) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(char, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (char) val;
        }
    }
#endif
    if (unlikely(!PyLong_Check(x))) {
        char val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (char) -1;
        val = __Pyx_PyInt_As_char(tmp);
        Py_DECREF(tmp);
        return val;
    }
    if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
        if (unlikely(__Pyx_PyLong_IsNeg(x))) {
            goto raise_neg_overflow;
        } else if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(char, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_DigitCount(x)) {
                case 2:
                    if ((8 * sizeof(char) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) >= 2 * PyLong_SHIFT)) {
                            return (char) (((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(char) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) >= 3 * PyLong_SHIFT)) {
                            return (char) (((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(char) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) >= 4 * PyLong_SHIFT)) {
                            return (char) (((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0]));
                        }
                    }
                    break;
            }
        }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
        if (unlikely(Py_SIZE(x) < 0)) {
            goto raise_neg_overflow;
        }
#else
        {
            int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
            if (unlikely(result < 0))
                return (char) -1;
            if (unlikely(result == 1))
                goto raise_neg_overflow;
        }
#endif
        if ((sizeof(char) <= sizeof(unsigned long))) {
            __PYX_VERIFY_RETURN_INT_EXC(char, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(char) <= sizeof(unsigned PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(char, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
        }
    } else {
#if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(char, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_SignedDigitCount(x)) {
                case -2:
                    if ((8 * sizeof(char) - 1 > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) - 1 > 2 * PyLong_SHIFT)) {
                            return (char) (((char)-1)*(((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if ((8 * sizeof(char) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) - 1 > 2 * PyLong_SHIFT)) {
                            return (char) ((((((char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if ((8 * sizeof(char) - 1 > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) - 1 > 3 * PyLong_SHIFT)) {
                            return (char) (((char)-1)*(((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(char) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) - 1 > 3 * PyLong_SHIFT)) {
                            return (char) ((((((((char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if ((8 * sizeof(char) - 1 > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) - 1 > 4 * PyLong_SHIFT)) {
                            return (char) (((char)-1)*(((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(char) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(char, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(char) - 1 > 4 * PyLong_SHIFT)) {
                            return (char) ((((((((((char)digits[3]) << PyLong_SHIFT) | (char)digits[2]) << PyLong_SHIFT) | (char)digits[1]) << PyLong_SHIFT) | (char)digits[0])));
                        }
                    }
                    break;
            }
        }
#endif
        if ((sizeof(char) <= sizeof(long))) {
            __PYX_VERIFY_RETURN_INT_EXC(char, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(char) <= sizeof(PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(char, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
        }
    }
    {
        char val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
        int one = 1; int is_little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        ret = _PyLong_AsByteArray((PyLongObject *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (char) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (char) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (char) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        val = (char) 0;
        mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
        shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
        for (bits = 0; bits < (int) sizeof(char) * 8 - chunk_size; bits += chunk_size) {
            PyObject *tmp, *digit;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((char) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long idigit = PyLong_AsLong(stepval);
            if (unlikely(idigit < 0)) goto done;
            remaining_bits = ((int) sizeof(char) * 8) - bits - (is_unsigned ? 0 : 1);
            if (unlikely(idigit >= (1L << remaining_bits)))
                goto raise_overflow;
            val |= ((char) idigit) << bits;
        }
        if (!is_unsigned) {
            if (unlikely(val & (((char) 1) << (sizeof(char) * 8 - 1))))
                goto raise_overflow;
            if (is_negative)
                val = ~val;
        }
        ret = 0;
    done:
        Py_XDECREF(shift);
        Py_XDECREF(mask);
        Py_XDECREF(stepval);
#endif
        if (unlikely(ret))
            return (char) -1;
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to char");
    return (char) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to char");
    return (char) -1;
}

/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(long) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    }
#endif
    if (unlikely(!PyLong_Check(x))) {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
    if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
        if (unlikely(__Pyx_PyLong_IsNeg(x))) {
            goto raise_neg_overflow;
        } else if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_DigitCount(x)) {
                case 2:
                    if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
        }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
        if (unlikely(Py_SIZE(x) < 0)) {
            goto raise_neg_overflow;
        }
#else
        {
            int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
            if (unlikely(result < 0))
                return (long) -1;
            if (unlikely(result == 1))
                goto raise_neg_overflow;
        }
#endif
        if ((sizeof(long) <= sizeof(unsigned long))) {
            __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
        }
    } else {
#if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_SignedDigitCount(x)) {
                case -2:
                    if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
        }
#endif
        if ((sizeof(long) <= sizeof(long))) {
            __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
        }
    }
    {
        long val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
        int one = 1; int is_little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        ret = _PyLong_AsByteArray((PyLongObject *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (long) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (long) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (long) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        val = (long) 0;
        mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
        shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
        for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
            PyObject *tmp, *digit;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((long) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long idigit = PyLong_AsLong(stepval);
            if (unlikely(idigit < 0)) goto done;
            remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
            if (unlikely(idigit >= (1L << remaining_bits)))
                goto raise_overflow;
            val |= ((long) idigit) << bits;
        }
        if (!is_unsigned) {
            if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
                goto raise_overflow;
            if (is_negative)
                val = ~val;
        }
        ret = 0;
    done:
        Py_XDECREF(shift);
        Py_XDECREF(mask);
        Py_XDECREF(stepval);
#endif
        if (unlikely(ret))
            return (long) -1;
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const long neg_one = (long) -1, const_zero = (long) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL;
        PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(long));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        arg_tuple = PyTuple_Pack(2, py_bytes, order_str);
        if (!arg_tuple) goto limited_bad;
        if (!is_unsigned) {
            kwds = PyDict_New();
            if (!kwds) goto limited_bad;
            if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad;
        }
        result = PyObject_Call(from_bytes, arg_tuple, kwds);
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(arg_tuple);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntFromPy */
static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(uint32_t) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(uint32_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint32_t) val;
        }
    }
#endif
    if (unlikely(!PyLong_Check(x))) {
        uint32_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (uint32_t) -1;
        val = __Pyx_PyInt_As_uint32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
    if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
        if (unlikely(__Pyx_PyLong_IsNeg(x))) {
            goto raise_neg_overflow;
        } else if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(uint32_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_DigitCount(x)) {
                case 2:
                    if ((8 * sizeof(uint32_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) >= 2 * PyLong_SHIFT)) {
                            return (uint32_t) (((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(uint32_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) >= 3 * PyLong_SHIFT)) {
                            return (uint32_t) (((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(uint32_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) >= 4 * PyLong_SHIFT)) {
                            return (uint32_t) (((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0]));
                        }
                    }
                    break;
            }
        }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
        if (unlikely(Py_SIZE(x) < 0)) {
            goto raise_neg_overflow;
        }
#else
        {
            int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
            if (unlikely(result < 0))
                return (uint32_t) -1;
            if (unlikely(result == 1))
                goto raise_neg_overflow;
        }
#endif
        if ((sizeof(uint32_t) <= sizeof(unsigned long))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
        }
    } else {
#if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(uint32_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_SignedDigitCount(x)) {
                case -2:
                    if ((8 * sizeof(uint32_t) - 1 > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (uint32_t) (((uint32_t)-1)*(((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if ((8 * sizeof(uint32_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (uint32_t) ((((((uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if ((8 * sizeof(uint32_t) - 1 > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (uint32_t) (((uint32_t)-1)*(((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(uint32_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (uint32_t) ((((((((uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if ((8 * sizeof(uint32_t) - 1 > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (uint32_t) (((uint32_t)-1)*(((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(uint32_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint32_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (uint32_t) ((((((((((uint32_t)digits[3]) << PyLong_SHIFT) | (uint32_t)digits[2]) << PyLong_SHIFT) | (uint32_t)digits[1]) << PyLong_SHIFT) | (uint32_t)digits[0])));
                        }
                    }
                    break;
            }
        }
#endif
        if ((sizeof(uint32_t) <= sizeof(long))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint32_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(uint32_t) <= sizeof(PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
        }
    }
    {
        uint32_t val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
        int one = 1; int is_little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        ret = _PyLong_AsByteArray((PyLongObject *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (uint32_t) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (uint32_t) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (uint32_t) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        val = (uint32_t) 0;
        mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
        shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
        for (bits = 0; bits < (int) sizeof(uint32_t) * 8 - chunk_size; bits += chunk_size) {
            PyObject *tmp, *digit;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((uint32_t) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long idigit = PyLong_AsLong(stepval);
            if (unlikely(idigit < 0)) goto done;
            remaining_bits = ((int) sizeof(uint32_t) * 8) - bits - (is_unsigned ? 0 : 1);
            if (unlikely(idigit >= (1L << remaining_bits)))
                goto raise_overflow;
            val |= ((uint32_t) idigit) << bits;
        }
        if (!is_unsigned) {
            if (unlikely(val & (((uint32_t) 1) << (sizeof(uint32_t) * 8 - 1))))
                goto raise_overflow;
            if (is_negative)
                val = ~val;
        }
        ret = 0;
    done:
        Py_XDECREF(shift);
        Py_XDECREF(mask);
        Py_XDECREF(stepval);
#endif
        if (unlikely(ret))
            return (uint32_t) -1;
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint32_t");
    return (uint32_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint32_t");
    return (uint32_t) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int32_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int32_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(int32_t),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL;
        PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(int32_t));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        arg_tuple = PyTuple_Pack(2, py_bytes, order_str);
        if (!arg_tuple) goto limited_bad;
        if (!is_unsigned) {
            kwds = PyDict_New();
            if (!kwds) goto limited_bad;
            if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad;
        }
        result = PyObject_Call(from_bytes, arg_tuple, kwds);
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(arg_tuple);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint32_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint32_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(uint32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL;
        PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(uint32_t));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        arg_tuple = PyTuple_Pack(2, py_bytes, order_str);
        if (!arg_tuple) goto limited_bad;
        if (!is_unsigned) {
            kwds = PyDict_New();
            if (!kwds) goto limited_bad;
            if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad;
        }
        result = PyObject_Call(from_bytes, arg_tuple, kwds);
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(arg_tuple);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntFromPy */
static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int64_t neg_one = (int64_t) -1, const_zero = (int64_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(int64_t) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(int64_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int64_t) val;
        }
    }
#endif
    if (unlikely(!PyLong_Check(x))) {
        int64_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int64_t) -1;
        val = __Pyx_PyInt_As_int64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
    if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
        if (unlikely(__Pyx_PyLong_IsNeg(x))) {
            goto raise_neg_overflow;
        } else if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(int64_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_DigitCount(x)) {
                case 2:
                    if ((8 * sizeof(int64_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) >= 2 * PyLong_SHIFT)) {
                            return (int64_t) (((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(int64_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) >= 3 * PyLong_SHIFT)) {
                            return (int64_t) (((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(int64_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) >= 4 * PyLong_SHIFT)) {
                            return (int64_t) (((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0]));
                        }
                    }
                    break;
            }
        }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
        if (unlikely(Py_SIZE(x) < 0)) {
            goto raise_neg_overflow;
        }
#else
        {
            int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
            if (unlikely(result < 0))
                return (int64_t) -1;
            if (unlikely(result == 1))
                goto raise_neg_overflow;
        }
#endif
        if ((sizeof(int64_t) <= sizeof(unsigned long))) {
            __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(int64_t) <= sizeof(unsigned PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(int64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
        }
    } else {
#if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(int64_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_SignedDigitCount(x)) {
                case -2:
                    if ((8 * sizeof(int64_t) - 1 > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (int64_t) (((int64_t)-1)*(((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if ((8 * sizeof(int64_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (int64_t) ((((((int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if ((8 * sizeof(int64_t) - 1 > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (int64_t) (((int64_t)-1)*(((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(int64_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (int64_t) ((((((((int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if ((8 * sizeof(int64_t) - 1 > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (int64_t) (((int64_t)-1)*(((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(int64_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int64_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (int64_t) ((((((((((int64_t)digits[3]) << PyLong_SHIFT) | (int64_t)digits[2]) << PyLong_SHIFT) | (int64_t)digits[1]) << PyLong_SHIFT) | (int64_t)digits[0])));
                        }
                    }
                    break;
            }
        }
#endif
        if ((sizeof(int64_t) <= sizeof(long))) {
            __PYX_VERIFY_RETURN_INT_EXC(int64_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(int64_t) <= sizeof(PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(int64_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
        }
    }
    {
        int64_t val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
        int one = 1; int is_little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        ret = _PyLong_AsByteArray((PyLongObject *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (int64_t) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (int64_t) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (int64_t) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        val = (int64_t) 0;
        mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
        shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
        for (bits = 0; bits < (int) sizeof(int64_t) * 8 - chunk_size; bits += chunk_size) {
            PyObject *tmp, *digit;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((int64_t) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long idigit = PyLong_AsLong(stepval);
            if (unlikely(idigit < 0)) goto done;
            remaining_bits = ((int) sizeof(int64_t) * 8) - bits - (is_unsigned ? 0 : 1);
            if (unlikely(idigit >= (1L << remaining_bits)))
                goto raise_overflow;
            val |= ((int64_t) idigit) << bits;
        }
        if (!is_unsigned) {
            if (unlikely(val & (((int64_t) 1) << (sizeof(int64_t) * 8 - 1))))
                goto raise_overflow;
            if (is_negative)
                val = ~val;
        }
        ret = 0;
    done:
        Py_XDECREF(shift);
        Py_XDECREF(mask);
        Py_XDECREF(stepval);
#endif
        if (unlikely(ret))
            return (int64_t) -1;
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int64_t");
    return (int64_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int64_t");
    return (int64_t) -1;
}

/* CIntFromPy */
static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(int32_t) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(int32_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int32_t) val;
        }
    }
#endif
    if (unlikely(!PyLong_Check(x))) {
        int32_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int32_t) -1;
        val = __Pyx_PyInt_As_int32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
    if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
        if (unlikely(__Pyx_PyLong_IsNeg(x))) {
            goto raise_neg_overflow;
        } else if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(int32_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_DigitCount(x)) {
                case 2:
                    if ((8 * sizeof(int32_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) >= 2 * PyLong_SHIFT)) {
                            return (int32_t) (((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(int32_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) >= 3 * PyLong_SHIFT)) {
                            return (int32_t) (((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(int32_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) >= 4 * PyLong_SHIFT)) {
                            return (int32_t) (((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0]));
                        }
                    }
                    break;
            }
        }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
        if (unlikely(Py_SIZE(x) < 0)) {
            goto raise_neg_overflow;
        }
#else
        {
            int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
            if (unlikely(result < 0))
                return (int32_t) -1;
            if (unlikely(result == 1))
                goto raise_neg_overflow;
        }
#endif
        if ((sizeof(int32_t) <= sizeof(unsigned long))) {
            __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
        }
    } else {
#if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(int32_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_SignedDigitCount(x)) {
                case -2:
                    if ((8 * sizeof(int32_t) - 1 > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (int32_t) (((int32_t)-1)*(((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if ((8 * sizeof(int32_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (int32_t) ((((((int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if ((8 * sizeof(int32_t) - 1 > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (int32_t) (((int32_t)-1)*(((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(int32_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (int32_t) ((((((((int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if ((8 * sizeof(int32_t) - 1 > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (int32_t) (((int32_t)-1)*(((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(int32_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(int32_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (int32_t) ((((((((((int32_t)digits[3]) << PyLong_SHIFT) | (int32_t)digits[2]) << PyLong_SHIFT) | (int32_t)digits[1]) << PyLong_SHIFT) | (int32_t)digits[0])));
                        }
                    }
                    break;
            }
        }
#endif
        if ((sizeof(int32_t) <= sizeof(long))) {
            __PYX_VERIFY_RETURN_INT_EXC(int32_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(int32_t) <= sizeof(PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(int32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
        }
    }
    {
        int32_t val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
        int one = 1; int is_little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        ret = _PyLong_AsByteArray((PyLongObject *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (int32_t) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (int32_t) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (int32_t) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        val = (int32_t) 0;
        mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
        shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
        for (bits = 0; bits < (int) sizeof(int32_t) * 8 - chunk_size; bits += chunk_size) {
            PyObject *tmp, *digit;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((int32_t) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long idigit = PyLong_AsLong(stepval);
            if (unlikely(idigit < 0)) goto done;
            remaining_bits = ((int) sizeof(int32_t) * 8) - bits - (is_unsigned ? 0 : 1);
            if (unlikely(idigit >= (1L << remaining_bits)))
                goto raise_overflow;
            val |= ((int32_t) idigit) << bits;
        }
        if (!is_unsigned) {
            if (unlikely(val & (((int32_t) 1) << (sizeof(int32_t) * 8 - 1))))
                goto raise_overflow;
            if (is_negative)
                val = ~val;
        }
        ret = 0;
    done:
        Py_XDECREF(shift);
        Py_XDECREF(mask);
        Py_XDECREF(stepval);
#endif
        if (unlikely(ret))
            return (int32_t) -1;
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int32_t");
    return (int32_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int32_t");
    return (int32_t) -1;
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint64_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint64_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(uint64_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint64_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
        if (is_unsigned) {
            return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
        } else {
            return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
        }
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
        int one = 1; int little = (int)*(unsigned char *)&one;
        return _PyLong_FromByteArray(bytes, sizeof(uint64_t),
                                     little, !is_unsigned);
#else
        int one = 1; int little = (int)*(unsigned char *)&one;
        PyObject *from_bytes, *result = NULL;
        PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
        from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
        if (!from_bytes) return NULL;
        py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(uint64_t));
        if (!py_bytes) goto limited_bad;
        order_str = PyUnicode_FromString(little ? "little" : "big");
        if (!order_str) goto limited_bad;
        arg_tuple = PyTuple_Pack(2, py_bytes, order_str);
        if (!arg_tuple) goto limited_bad;
        if (!is_unsigned) {
            kwds = PyDict_New();
            if (!kwds) goto limited_bad;
            if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad;
        }
        result = PyObject_Call(from_bytes, arg_tuple, kwds);
        limited_bad:
        Py_XDECREF(kwds);
        Py_XDECREF(arg_tuple);
        Py_XDECREF(order_str);
        Py_XDECREF(py_bytes);
        Py_XDECREF(from_bytes);
        return result;
#endif
    }
}

/* CIntFromPy */
static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const uint64_t neg_one = (uint64_t) -1, const_zero = (uint64_t) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if ((sizeof(uint64_t) < sizeof(long))) {
            __PYX_VERIFY_RETURN_INT(uint64_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint64_t) val;
        }
    }
#endif
    if (unlikely(!PyLong_Check(x))) {
        uint64_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (uint64_t) -1;
        val = __Pyx_PyInt_As_uint64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
    if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
        if (unlikely(__Pyx_PyLong_IsNeg(x))) {
            goto raise_neg_overflow;
        } else if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(uint64_t, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_DigitCount(x)) {
                case 2:
                    if ((8 * sizeof(uint64_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) >= 2 * PyLong_SHIFT)) {
                            return (uint64_t) (((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(uint64_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) >= 3 * PyLong_SHIFT)) {
                            return (uint64_t) (((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(uint64_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) >= 4 * PyLong_SHIFT)) {
                            return (uint64_t) (((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0]));
                        }
                    }
                    break;
            }
        }
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
        if (unlikely(Py_SIZE(x) < 0)) {
            goto raise_neg_overflow;
        }
#else
        {
            int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
            if (unlikely(result < 0))
                return (uint64_t) -1;
            if (unlikely(result == 1))
                goto raise_neg_overflow;
        }
#endif
        if ((sizeof(uint64_t) <= sizeof(unsigned long))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(uint64_t) <= sizeof(unsigned PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint64_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
        }
    } else {
#if CYTHON_USE_PYLONG_INTERNALS
        if (__Pyx_PyLong_IsCompact(x)) {
            __PYX_VERIFY_RETURN_INT(uint64_t, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
        } else {
            const digit* digits = __Pyx_PyLong_Digits(x);
            assert(__Pyx_PyLong_DigitCount(x) > 1);
            switch (__Pyx_PyLong_SignedDigitCount(x)) {
                case -2:
                    if ((8 * sizeof(uint64_t) - 1 > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (uint64_t) (((uint64_t)-1)*(((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if ((8 * sizeof(uint64_t) > 1 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) {
                            return (uint64_t) ((((((uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if ((8 * sizeof(uint64_t) - 1 > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (uint64_t) (((uint64_t)-1)*(((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if ((8 * sizeof(uint64_t) > 2 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) {
                            return (uint64_t) ((((((((uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if ((8 * sizeof(uint64_t) - 1 > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (uint64_t) (((uint64_t)-1)*(((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if ((8 * sizeof(uint64_t) > 3 * PyLong_SHIFT)) {
                        if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
                            __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if ((8 * sizeof(uint64_t) - 1 > 4 * PyLong_SHIFT)) {
                            return (uint64_t) ((((((((((uint64_t)digits[3]) << PyLong_SHIFT) | (uint64_t)digits[2]) << PyLong_SHIFT) | (uint64_t)digits[1]) << PyLong_SHIFT) | (uint64_t)digits[0])));
                        }
                    }
                    break;
            }
        }
#endif
        if ((sizeof(uint64_t) <= sizeof(long))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint64_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
        } else if ((sizeof(uint64_t) <= sizeof(PY_LONG_LONG))) {
            __PYX_VERIFY_RETURN_INT_EXC(uint64_t, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
        }
    }
    {
        uint64_t val;
        int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
        Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
            x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
        if (unlikely(bytes_copied == -1)) {
        } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
            goto raise_overflow;
        } else {
            ret = 0;
        }
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
        int one = 1; int is_little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        ret = _PyLong_AsByteArray((PyLongObject *)x,
                                    bytes, sizeof(val),
                                    is_little, !is_unsigned);
#else
        PyObject *v;
        PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
        int bits, remaining_bits, is_negative = 0;
        int chunk_size = (sizeof(long) < 8) ? 30 : 62;
        if (likely(PyLong_CheckExact(x))) {
            v = __Pyx_NewRef(x);
        } else {
            v = PyNumber_Long(x);
            if (unlikely(!v)) return (uint64_t) -1;
            assert(PyLong_CheckExact(v));
        }
        {
            int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
            if (unlikely(result < 0)) {
                Py_DECREF(v);
                return (uint64_t) -1;
            }
            is_negative = result == 1;
        }
        if (is_unsigned && unlikely(is_negative)) {
            Py_DECREF(v);
            goto raise_neg_overflow;
        } else if (is_negative) {
            stepval = PyNumber_Invert(v);
            Py_DECREF(v);
            if (unlikely(!stepval))
                return (uint64_t) -1;
        } else {
            stepval = v;
        }
        v = NULL;
        val = (uint64_t) 0;
        mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
        shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
        for (bits = 0; bits < (int) sizeof(uint64_t) * 8 - chunk_size; bits += chunk_size) {
            PyObject *tmp, *digit;
            long idigit;
            digit = PyNumber_And(stepval, mask);
            if (unlikely(!digit)) goto done;
            idigit = PyLong_AsLong(digit);
            Py_DECREF(digit);
            if (unlikely(idigit < 0)) goto done;
            val |= ((uint64_t) idigit) << bits;
            tmp = PyNumber_Rshift(stepval, shift);
            if (unlikely(!tmp)) goto done;
            Py_DECREF(stepval); stepval = tmp;
        }
        Py_DECREF(shift); shift = NULL;
        Py_DECREF(mask); mask = NULL;
        {
            long idigit = PyLong_AsLong(stepval);
            if (unlikely(idigit < 0)) goto done;
            remaining_bits = ((int) sizeof(uint64_t) * 8) - bits - (is_unsigned ? 0 : 1);
            if (unlikely(idigit >= (1L << remaining_bits)))
                goto raise_overflow;
            val |= ((uint64_t) idigit) << bits;
        }
        if (!is_unsigned) {
            if (unlikely(val & (((uint64_t) 1) << (sizeof(uint64_t) * 8 - 1))))
                goto raise_overflow;
            if (is_negative)
                val = ~val;
        }
        ret = 0;
    done:
        Py_XDECREF(shift);
        Py_XDECREF(mask);
        Py_XDECREF(stepval);
#endif
        if (unlikely(ret))
            return (uint64_t) -1;
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint64_t");
    return (uint64_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint64_t");
    return (uint64_t) -1;
}

/* FormatTypeName */
#if CYTHON_COMPILING_IN_LIMITED_API
static __Pyx_TypeName
__Pyx_PyType_GetName(PyTypeObject* tp)
{
    PyObject *name = __Pyx_PyObject_GetAttrStr((PyObject *)tp,
                                               __pyx_n_s_name_2);
    if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) {
        PyErr_Clear();
        Py_XDECREF(name);
        name = __Pyx_NewRef(__pyx_n_s__172);
    }
    return name;
}
#endif

/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = __Pyx_PyType_GetSlot(a, tp_base, PyTypeObject*);
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (cls == a || cls == b) return 1;
    mro = cls->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            PyObject *base = PyTuple_GET_ITEM(mro, i);
            if (base == (PyObject *)a || base == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(cls, a) || __Pyx_InBases(cls, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    if (exc_type1) {
        return __Pyx_IsAnySubtype2((PyTypeObject*)err, (PyTypeObject*)exc_type1, (PyTypeObject*)exc_type2);
    } else {
        return __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

/* CheckBinaryVersion */
static unsigned long __Pyx_get_runtime_version(void) {
#if __PYX_LIMITED_VERSION_HEX >= 0x030B00A4
    return Py_Version & ~0xFFUL;
#else
    const char* rt_version = Py_GetVersion();
    unsigned long version = 0;
    unsigned long factor = 0x01000000UL;
    unsigned int digit = 0;
    int i = 0;
    while (factor) {
        while ('0' <= rt_version[i] && rt_version[i] <= '9') {
            digit = digit * 10 + (unsigned int) (rt_version[i] - '0');
            ++i;
        }
        version += factor * digit;
        if (rt_version[i] != '.')
            break;
        digit = 0;
        factor >>= 8;
        ++i;
    }
    return version;
#endif
}
static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer) {
    const unsigned long MAJOR_MINOR = 0xFFFF0000UL;
    if ((rt_version & MAJOR_MINOR) == (ct_version & MAJOR_MINOR))
        return 0;
    if (likely(allow_newer && (rt_version & MAJOR_MINOR) > (ct_version & MAJOR_MINOR)))
        return 1;
    {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compile time Python version %d.%d "
                      "of module '%.100s' "
                      "%s "
                      "runtime version %d.%d",
                       (int) (ct_version >> 24), (int) ((ct_version >> 16) & 0xFF),
                       __Pyx_MODULE_NAME,
                       (allow_newer) ? "was newer than" : "does not match",
                       (int) (rt_version >> 24), (int) ((rt_version >> 16) & 0xFF)
       );
        return PyErr_WarnEx(NULL, message, 1);
    }
}

/* FunctionImport */
#ifndef __PYX_HAVE_RT_ImportFunction_3_0_11
#define __PYX_HAVE_RT_ImportFunction_3_0_11
static int __Pyx_ImportFunction_3_0_11(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, funcname);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C function %.200s",
                PyModule_GetName(module), funcname);
        goto bad;
    }
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    tmp.p = PyCapsule_GetPointer(cobj, sig);
    *f = tmp.fp;
    if (!(*f))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* InitStrings */
#if PY_MAJOR_VERSION >= 3
static int __Pyx_InitString(__Pyx_StringTabEntry t, PyObject **str) {
    if (t.is_unicode | t.is_str) {
        if (t.intern) {
            *str = PyUnicode_InternFromString(t.s);
        } else if (t.encoding) {
            *str = PyUnicode_Decode(t.s, t.n - 1, t.encoding, NULL);
        } else {
            *str = PyUnicode_FromStringAndSize(t.s, t.n - 1);
        }
    } else {
        *str = PyBytes_FromStringAndSize(t.s, t.n - 1);
    }
    if (!*str)
        return -1;
    if (PyObject_Hash(*str) == -1)
        return -1;
    return 0;
}
#endif
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION >= 3
        __Pyx_InitString(*t, t->p);
        #else
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        if (!*t->p)
            return -1;
        if (PyObject_Hash(*t->p) == -1)
            return -1;
        #endif
        ++t;
    }
    return 0;
}

#include <string.h>
static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) {
    size_t len = strlen(s);
    if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) {
        PyErr_SetString(PyExc_OverflowError, "byte string is too long");
        return -1;
    }
    return (Py_ssize_t) len;
}
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    Py_ssize_t len = __Pyx_ssize_strlen(c_str);
    if (unlikely(len < 0)) return NULL;
    return __Pyx_PyUnicode_FromStringAndSize(c_str, len);
}
static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) {
    Py_ssize_t len = __Pyx_ssize_strlen(c_str);
    if (unlikely(len < 0)) return NULL;
    return PyByteArray_FromStringAndSize(c_str, len);
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    char* defenc_c;
    PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
    if (!defenc) return NULL;
    defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    {
        char* end = defenc_c + PyBytes_GET_SIZE(defenc);
        char* c;
        for (c = defenc_c; c < end; c++) {
            if ((unsigned char) (*c) >= 128) {
                PyUnicode_AsASCIIString(o);
                return NULL;
            }
        }
    }
#endif
    *length = PyBytes_GET_SIZE(defenc);
    return defenc_c;
}
#else
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(PyUnicode_IS_ASCII(o))) {
        *length = PyUnicode_GET_LENGTH(o);
        return PyUnicode_AsUTF8(o);
    } else {
        PyUnicode_AsASCIIString(o);
        return NULL;
    }
#else
    return PyUnicode_AsUTF8AndSize(o, length);
#endif
}
#endif
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
    __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result));
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type " __Pyx_FMT_TYPENAME ").  "
                "The ability to return an instance of a strict subclass of int is deprecated, "
                "and may be removed in a future version of Python.",
                result_type_name)) {
            __Pyx_DECREF_TypeName(result_type_name);
            Py_DECREF(result);
            return NULL;
        }
        __Pyx_DECREF_TypeName(result_type_name);
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")",
                 type_name, type_name, result_type_name);
    __Pyx_DECREF_TypeName(result_type_name);
    Py_DECREF(result);
    return NULL;
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(PyLong_Check(x)))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(b);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(__Pyx_PyLong_IsCompact(b))) {
        return __Pyx_PyLong_CompactValue(b);
    } else {
      const digit* digits = __Pyx_PyLong_Digits(b);
      const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b);
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) {
  if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) {
    return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o);
#if PY_MAJOR_VERSION < 3
  } else if (likely(PyInt_CheckExact(o))) {
    return PyInt_AS_LONG(o);
#endif
  } else {
    Py_ssize_t ival;
    PyObject *x;
    x = PyNumber_Index(o);
    if (!x) return -1;
    ival = PyInt_AsLong(x);
    Py_DECREF(x);
    return ival;
  }
}
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


/* #### Code section: utility_code_pragmas_end ### */
#ifdef _MSC_VER
#pragma warning( pop )
#endif



/* #### Code section: end ### */
#endif /* Py_PYTHON_H */
