/* Generated by Cython 0.23.4 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_23_4"
#include <stddef.h>
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !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
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
#define CYTHON_USE_PYLONG_INTERNALS 1
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
#define Py_OptimizeFlag 0
#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_PyCode_New(a, 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)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, 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)
  #define __Pyx_DefaultClassType PyType_Type
#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
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #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_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #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_KIND(u)         (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]))
#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 && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? 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
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#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
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#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 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
#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   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if PY_VERSION_HEX >= 0x030500B1
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
typedef struct {
    unaryfunc am_await;
    unaryfunc am_aiter;
    unaryfunc am_anext;
} __Pyx_PyAsyncMethodsStruct;
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
#else
#define __Pyx_PyType_AsAsync(obj) NULL
#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
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)

#ifndef CYTHON_INLINE
  #if 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

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#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 PY_MAJOR_VERSION >= 3
  #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

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__pysam__calignedsegment
#define __PYX_HAVE_API__pysam__calignedsegment
#include "stdint.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "sys/types.h"
#include "zlib.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 "pythread.h"
#include "pysam_stream.h"
#include "samfile_util.h"
#include "pysam_util.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#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_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; 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_DEFAULT 0
#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)))  )
#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) && defined (_M_X64)
    #define __Pyx_sst_abs(value) _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 char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#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_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((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)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_COMPILING_IN_CPYTHON
#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 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
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] = 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
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));
    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 PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "pysam/calignedsegment.pyx",
  "array.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
  "pysam/cfaidx.pxd",
  "pysam/calignmentfile.pxd",
};

/*--- Type declarations ---*/
#ifndef _ARRAYARRAY_H
struct arrayobject;
typedef struct arrayobject arrayobject;
#endif
struct __pyx_obj_5pysam_6cfaidx_FastaFile;
struct __pyx_obj_5pysam_6cfaidx_FastqProxy;
struct __pyx_obj_5pysam_6cfaidx_PersistentFastqProxy;
struct __pyx_obj_5pysam_6cfaidx_FastxFile;
struct __pyx_obj_5pysam_6cfaidx_FastqFile;
struct __pyx_obj_5pysam_6cfaidx_Fastafile;
struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile;
struct __pyx_obj_5pysam_14calignmentfile_PileupColumn;
struct __pyx_obj_5pysam_14calignmentfile_PileupRead;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRow;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs;
struct __pyx_obj_5pysam_14calignmentfile_IndexedReads;
struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment;
struct __pyx_obj_5pysam_15calignedsegment_PileupColumn;
struct __pyx_obj_5pysam_15calignedsegment_PileupRead;
struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr;
struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr;
struct __pyx_opt_args_5pysam_6cfaidx_10FastqProxy_get_quality_array;
struct __pyx_opt_args_5pysam_6cfaidx_20PersistentFastqProxy_get_quality_array;

/* "pysam/cfaidx.pxd":51
 *     cdef kseq_t * _delegate
 *     cdef cython.str tostring(self)
 *     cpdef array.array get_quality_array(self, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_5pysam_6cfaidx_10FastqProxy_get_quality_array {
  int __pyx_n;
  int offset;
};

/* "pysam/cfaidx.pxd":60
 *     cdef public str comment, quality, sequence, name
 *     cdef cython.str tostring(self)
 *     cpdef array.array get_quality_array(self, int offset=*)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_5pysam_6cfaidx_20PersistentFastqProxy_get_quality_array {
  int __pyx_n;
  int offset;
};
struct __pyx_t_5pysam_14calignmentfile___iterdata;
typedef struct __pyx_t_5pysam_14calignmentfile___iterdata __pyx_t_5pysam_14calignmentfile___iterdata;
struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData;

/* "pysam/calignmentfile.pxd":29
 * # Utility types
 * 
 * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
 *     htsFile * htsfile
 *     bam_hdr_t * header
 */
struct __pyx_t_5pysam_14calignmentfile___iterdata {
  htsFile *htsfile;
  bam_hdr_t *header;
  hts_itr_t *iter;
  faidx_t *fastafile;
  int tid;
  char *seq;
  int seq_len;
};

/* "pysam/calignmentfile.pxd":140
 *     cdef char * getSequence(self)
 *     cdef setMask(self, mask)
 *     cdef setupIteratorData(self,             # <<<<<<<<<<<<<<
 *                            int tid,
 *                            int start,
 */
struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData {
  int __pyx_n;
  int multiple_iterators;
};
struct __pyx_opt_args_5pysam_6cutils_parse_region;
struct __pyx_opt_args_5pysam_6cutils_qualitystring_to_array;
struct __pyx_opt_args_5pysam_6cutils_array_to_qualitystring;
struct __pyx_opt_args_5pysam_6cutils_qualities_to_qualitystring;
struct __pyx_opt_args_5pysam_6cutils_charptr_to_str;
struct __pyx_opt_args_5pysam_6cutils_charptr_to_bytes;
struct __pyx_opt_args_5pysam_6cutils_charptr_to_str_w_len;
struct __pyx_opt_args_5pysam_6cutils_force_str;
struct __pyx_opt_args_5pysam_6cutils_force_bytes;

/* "pysam/cutils.pxd":7
 * from cpython cimport array as c_array
 * 
 * cpdef parse_region(reference=*, start=*, end=*, region=*)             # <<<<<<<<<<<<<<
 * 
 * #########################################################################
 */
struct __pyx_opt_args_5pysam_6cutils_parse_region {
  int __pyx_n;
  PyObject *reference;
  PyObject *start;
  PyObject *end;
  PyObject *region;
};

/* "pysam/cutils.pxd":12
 * # 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_6cutils_qualitystring_to_array {
  int __pyx_n;
  int offset;
};

/* "pysam/cutils.pxd":13
 * 
 * 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_6cutils_array_to_qualitystring {
  int __pyx_n;
  int offset;
};

/* "pysam/cutils.pxd":14
 * 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_6cutils_qualities_to_qualitystring {
  int __pyx_n;
  int offset;
};

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

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

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

/* "pysam/cutils.pxd":24
 * cdef bytes charptr_to_bytes(const char *s, encoding=*)
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*)
 * cdef force_str(object s, encoding=*)             # <<<<<<<<<<<<<<
 * cdef bytes force_bytes(object s, encoding=*)
 * cdef bytes encode_filename(object filename)
 */
struct __pyx_opt_args_5pysam_6cutils_force_str {
  int __pyx_n;
  PyObject *encoding;
};

/* "pysam/cutils.pxd":25
 * cdef charptr_to_str_w_len(const char* s, size_t n, encoding=*)
 * cdef force_str(object s, encoding=*)
 * cdef bytes force_bytes(object s, encoding=*)             # <<<<<<<<<<<<<<
 * cdef bytes encode_filename(object filename)
 * cdef from_string_and_size(const char *s, size_t length)
 */
struct __pyx_opt_args_5pysam_6cutils_force_bytes {
  int __pyx_n;
  PyObject *encoding;
};
struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag;
struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_get_tag;
struct __pyx_opt_args_5pysam_15calignedsegment_get_value_code;
struct __pyx_opt_args_5pysam_15calignedsegment_getTypecode;

/* "pysam/calignedsegment.pxd":36
 * 
 * from pysam.calignmentfile cimport AlignmentFile
 * ctypedef AlignmentFile AlignmentFile_t             # <<<<<<<<<<<<<<
 * 
 * 
 */
typedef struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_t_5pysam_15calignedsegment_AlignmentFile_t;

/* "pysam/calignedsegment.pxd":56
 *     # 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=?)             # <<<<<<<<<<<<<<
 * 
 *     # add an alignment tag with value to the AlignedSegment
 */
struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag {
  int __pyx_n;
  PyObject *value_type;
  PyObject *replace;
};

/* "pysam/calignedsegment.pxd":60
 *     # add an alignment tag with value to the AlignedSegment
 *     # an existing tag of the same name will be replaced.
 *     cpdef get_tag(self, tag, with_value_type=?)             # <<<<<<<<<<<<<<
 * 
 *     # return true if tag exists
 */
struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_get_tag {
  int __pyx_n;
  PyObject *with_value_type;
};

/* "pysam/calignedsegment.pyx":137
 * 
 * 
 * cdef inline uint8_t get_value_code(value, value_type=None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */
struct __pyx_opt_args_5pysam_15calignedsegment_get_value_code {
  int __pyx_n;
  PyObject *value_type;
};

/* "pysam/calignedsegment.pyx":169
 * 
 * 
 * cdef inline bytes getTypecode(value, maximum_value=None):             # <<<<<<<<<<<<<<
 *     '''returns the value typecode of a value.
 * 
 */
struct __pyx_opt_args_5pysam_15calignedsegment_getTypecode {
  int __pyx_n;
  PyObject *maximum_value;
};

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


/* "pysam/cfaidx.pxd":48
 * 
 * 
 * cdef class FastqProxy:             # <<<<<<<<<<<<<<
 *     cdef kseq_t * _delegate
 *     cdef cython.str tostring(self)
 */
struct __pyx_obj_5pysam_6cfaidx_FastqProxy {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastqProxy *__pyx_vtab;
  kseq_t *_delegate;
};


/* "pysam/cfaidx.pxd":54
 * 
 * 
 * cdef class PersistentFastqProxy:             # <<<<<<<<<<<<<<
 *     """
 *     Python container for pysam.cfaidx.FastqProxy with persistence.
 */
struct __pyx_obj_5pysam_6cfaidx_PersistentFastqProxy {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_6cfaidx_PersistentFastqProxy *__pyx_vtab;
  PyObject *comment;
  PyObject *quality;
  PyObject *sequence;
  PyObject *name;
};


/* "pysam/cfaidx.pxd":63
 * 
 * 
 * cdef class FastxFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef gzFile fastqfile
 */
struct __pyx_obj_5pysam_6cfaidx_FastxFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile *__pyx_vtab;
  PyObject *_filename;
  gzFile fastqfile;
  kseq_t *entry;
  int persist;
};


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


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


/* "pysam/calignmentfile.pxd":39
 * 
 * 
 * cdef class AlignmentFile:             # <<<<<<<<<<<<<<
 * 
 *     cdef object _filename
 */
struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile *__pyx_vtab;
  PyObject *_filename;
  htsFile *htsfile;
  hts_idx_t *index;
  bam_hdr_t *header;
  int is_bam;
  int is_cram;
  int is_stream;
  int is_remote;
  bam1_t *b;
  char *mode;
  int64_t start_offset;
};


/* "pysam/calignmentfile.pxd":72
 *     cpdef int write(self, AlignedSegment read) except -1
 * 
 * cdef class PileupColumn:             # <<<<<<<<<<<<<<
 *     cdef bam_pileup1_t ** plp
 *     cdef int tid
 */
struct __pyx_obj_5pysam_14calignmentfile_PileupColumn {
  PyObject_HEAD
  bam_pileup1_t **plp;
  int tid;
  int pos;
  int n_pu;
};


/* "pysam/calignmentfile.pxd":78
 *     cdef int n_pu
 * 
 * cdef class PileupRead:             # <<<<<<<<<<<<<<
 *     cdef AlignedSegment _alignment
 *     cdef int32_t  _qpos
 */
struct __pyx_obj_5pysam_14calignmentfile_PileupRead {
  PyObject_HEAD
  struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *_alignment;
  int32_t _qpos;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
  uint32_t _is_refskip;
};


/* "pysam/calignmentfile.pxd":88
 *     cdef uint32_t _is_refskip
 * 
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     cdef int retval
 *     cdef bam1_t * b
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRow {
  PyObject_HEAD
  int retval;
  bam1_t *b;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  bam_hdr_t *header;
  int owns_samfile;
};


/* "pysam/calignmentfile.pxd":96
 *     cdef int owns_samfile
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef hts_itr_t * iter
 *     cdef bam1_t * getCurrent(self)
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *__pyx_vtab;
  hts_itr_t *iter;
};


/* "pysam/calignmentfile.pxd":101
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int max_rows
 *     cdef int current_row
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead *__pyx_vtab;
  int max_rows;
  int current_row;
};


/* "pysam/calignmentfile.pxd":107
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * getCurrent(self)
 *     cdef int cnext(self)
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll *__pyx_vtab;
};


/* "pysam/calignmentfile.pxd":111
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int         tid
 *     cdef IteratorRowRegion rowiter
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  int tid;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *rowiter;
};


/* "pysam/calignmentfile.pxd":115
 *     cdef IteratorRowRegion rowiter
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int current_pos
 *     cdef positions
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection *__pyx_vtab;
  int current_pos;
  PyObject *positions;
};


/* "pysam/calignmentfile.pxd":121
 *     cdef int cnext(self)
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn *__pyx_vtab;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *iter;
  int tid;
  int pos;
  int n_plp;
  int mask;
  bam_pileup1_t *plp;
  bam_plp_t pileup_iter;
  __pyx_t_5pysam_14calignmentfile___iterdata iterdata;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *samfile;
  struct __pyx_obj_5pysam_6cfaidx_Fastafile *fastafile;
  PyObject *stepper;
  int max_depth;
};


/* "pysam/calignmentfile.pxd":149
 *     cdef _free_pileup_iter(self)
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int end
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn __pyx_base;
  int start;
  int end;
  int truncate;
};


/* "pysam/calignmentfile.pxd":154
 *     cdef int truncate
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn __pyx_base;
};


/* "pysam/calignmentfile.pxd":157
 *     pass
 * 
 * cdef class IndexedReads:             # <<<<<<<<<<<<<<
 *     cdef AlignmentFile samfile
 *     cdef htsFile * htsfile
 */
struct __pyx_obj_5pysam_14calignmentfile_IndexedReads {
  PyObject_HEAD
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  PyObject *index;
  int owns_samfile;
  bam_hdr_t *header;
};


/* "pysam/calignedsegment.pxd":40
 * 
 * # Note: need to declare all C fields and methods here
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedSegment represents
 */
struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_15calignedsegment_AlignedSegment *__pyx_vtab;
  bam1_t *_delegate;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *_alignment_file;
  PyObject *cache_query_qualities;
  PyObject *cache_query_alignment_qualities;
  PyObject *cache_query_sequence;
  PyObject *cache_query_alignment_sequence;
};


/* "pysam/calignedsegment.pxd":69
 * 
 * 
 * cdef class PileupColumn:             # <<<<<<<<<<<<<<
 *     cdef bam_pileup1_t ** plp
 *     cdef int tid
 */
struct __pyx_obj_5pysam_15calignedsegment_PileupColumn {
  PyObject_HEAD
  bam_pileup1_t **plp;
  int tid;
  int pos;
  int n_pu;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *_alignment_file;
};


/* "pysam/calignedsegment.pxd":77
 * 
 * 
 * cdef class PileupRead:             # <<<<<<<<<<<<<<
 *     cdef AlignedSegment _alignment
 *     cdef int32_t  _qpos
 */
struct __pyx_obj_5pysam_15calignedsegment_PileupRead {
  PyObject_HEAD
  struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *_alignment;
  int32_t _qpos;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
  uint32_t _is_refskip;
};


/* "pysam/calignedsegment.pyx":82
 * 
 * if PY_MAJOR_VERSION >= 3:
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))
 */
struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr {
  PyObject_HEAD
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_y;
  PyObject *__pyx_t_0;
  PyObject *__pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysam/calignedsegment.pyx":84
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))
 * else:
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))             # <<<<<<<<<<<<<<
 * 
 * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=X])")
 */
struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr {
  PyObject_HEAD
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_y;
  PyObject *__pyx_t_0;
  PyObject *__pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};



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

struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile {
  char *(*_fetch)(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, char *, int, int, int *);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile *__pyx_vtabptr_5pysam_6cfaidx_FastaFile;


/* "pysam/cfaidx.pxd":48
 * 
 * 
 * cdef class FastqProxy:             # <<<<<<<<<<<<<<
 *     cdef kseq_t * _delegate
 *     cdef cython.str tostring(self)
 */

struct __pyx_vtabstruct_5pysam_6cfaidx_FastqProxy {
  PyObject *(*tostring)(struct __pyx_obj_5pysam_6cfaidx_FastqProxy *);
  arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_6cfaidx_FastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cfaidx_10FastqProxy_get_quality_array *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastqProxy *__pyx_vtabptr_5pysam_6cfaidx_FastqProxy;


/* "pysam/cfaidx.pxd":54
 * 
 * 
 * cdef class PersistentFastqProxy:             # <<<<<<<<<<<<<<
 *     """
 *     Python container for pysam.cfaidx.FastqProxy with persistence.
 */

struct __pyx_vtabstruct_5pysam_6cfaidx_PersistentFastqProxy {
  PyObject *(*tostring)(struct __pyx_obj_5pysam_6cfaidx_PersistentFastqProxy *);
  arrayobject *(*get_quality_array)(struct __pyx_obj_5pysam_6cfaidx_PersistentFastqProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cfaidx_20PersistentFastqProxy_get_quality_array *__pyx_optional_args);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_PersistentFastqProxy *__pyx_vtabptr_5pysam_6cfaidx_PersistentFastqProxy;


/* "pysam/cfaidx.pxd":63
 * 
 * 
 * cdef class FastxFile:             # <<<<<<<<<<<<<<
 *     cdef object _filename
 *     cdef gzFile fastqfile
 */

struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile {
  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_6cfaidx_FastxFile *);
  int (*cnext)(struct __pyx_obj_5pysam_6cfaidx_FastxFile *);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile *__pyx_vtabptr_5pysam_6cfaidx_FastxFile;


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

struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile {
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile *__pyx_vtabptr_5pysam_6cfaidx_FastqFile;


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

struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile {
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile *__pyx_vtabptr_5pysam_6cfaidx_Fastafile;


/* "pysam/calignmentfile.pxd":39
 * 
 * 
 * cdef class AlignmentFile:             # <<<<<<<<<<<<<<
 * 
 *     cdef object _filename
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *);
  int (*write)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile *__pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile;


/* "pysam/calignmentfile.pxd":96
 *     cdef int owns_samfile
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef hts_itr_t * iter
 *     cdef bam1_t * getCurrent(self)
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion;


/* "pysam/calignmentfile.pxd":101
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int max_rows
 *     cdef int current_row
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead;


/* "pysam/calignmentfile.pxd":107
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * getCurrent(self)
 *     cdef int cnext(self)
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll;


/* "pysam/calignmentfile.pxd":115
 *     cdef IteratorRowRegion rowiter
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int current_pos
 *     cdef positions
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection;


/* "pysam/calignmentfile.pxd":121
 *     cdef int cnext(self)
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn {
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *);
  char *(*getSequence)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *);
  PyObject *(*setMask)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, PyObject *);
  PyObject *(*setupIteratorData)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args);
  PyObject *(*reset)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *);
  PyObject *(*_free_pileup_iter)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn;


/* "pysam/calignmentfile.pxd":149
 *     cdef _free_pileup_iter(self)
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int end
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion {
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion;


/* "pysam/calignmentfile.pxd":154
 *     cdef int truncate
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs {
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs;


/* "pysam/calignedsegment.pyx":620
 * 
 * 
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 *     '''Class representing an aligned segment.
 * 
 */

struct __pyx_vtabstruct_5pysam_15calignedsegment_AlignedSegment {
  PyObject *(*set_tag)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag *__pyx_optional_args);
  PyObject *(*get_tag)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_get_tag *__pyx_optional_args);
  PyObject *(*has_tag)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*tostring)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, __pyx_t_5pysam_15calignedsegment_AlignmentFile_t, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_5pysam_15calignedsegment_AlignedSegment *__pyx_vtabptr_5pysam_15calignedsegment_AlignedSegment;

/* --- Runtime support code (head) --- */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, 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__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #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) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #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_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)

#if CYTHON_COMPILING_IN_CPYTHON
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);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name);

#ifndef CYTHON_PROFILE
  #define CYTHON_PROFILE 1
#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 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;
  #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 = PyThreadState_GET();\
          if (unlikely(tstate->use_tracing) && !tstate->tracing &&\
                  (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
              __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, funcname, srcfile, firstlineno);\
          }\
          PyGILState_Release(state);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  } else {\
      PyThreadState* tstate = PyThreadState_GET();\
      if (unlikely(tstate->use_tracing) && !tstate->tracing &&\
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, 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 (unlikely(tstate->use_tracing) && !tstate->tracing &&\
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, funcname, srcfile, firstlineno);\
          if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
      }\
  }
  #endif
  #define __Pyx_TraceException()\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = PyThreadState_GET();\
      if (tstate->use_tracing &&\
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
          tstate->tracing++;\
          tstate->use_tracing = 0;\
          PyObject *exc_info = __Pyx_GetExceptionTuple();\
          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);\
          }\
          tstate->use_tracing = 1;\
          tstate->tracing--;\
      }\
  }
  static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
      PyObject *type, *value, *traceback;
      PyErr_Fetch(&type, &value, &traceback);
      tstate->tracing++;
      tstate->use_tracing = 0;
      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);
      tstate->use_tracing = 1;
      tstate->tracing--;
      PyErr_Restore(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 = PyThreadState_GET();\
              if (tstate->use_tracing) {\
                  __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
              }\
              PyGILState_Release(state);\
          }\
      } else {\
          PyThreadState* tstate = PyThreadState_GET();\
          if (tstate->use_tracing) {\
              __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
          }\
      }\
  }
  #else
  #define __Pyx_TraceReturn(result, nogil)\
  if (likely(!__Pyx_use_tracing)); else {\
      PyThreadState* tstate = PyThreadState_GET();\
      if (tstate->use_tracing) {\
          __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, 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;
      PyErr_Fetch(&type, &value, &traceback);
      frame->f_lineno = lineno;
      tstate->tracing++;
      tstate->use_tracing = 0;
      ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
      tstate->use_tracing = 1;
      tstate->tracing--;
      if (likely(!ret)) {
          PyErr_Restore(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 = PyGILState_Ensure();\
              tstate = PyThreadState_GET();\
              if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) {\
                  ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
              }\
              PyGILState_Release(state);\
              if (unlikely(ret)) goto_error;\
          }\
      } else {\
          PyThreadState* tstate = PyThreadState_GET();\
          if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) {\
              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 = PyThreadState_GET();\
      if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) {\
          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

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);

#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyObject_Ord(c)\
    (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c))
#else
#define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c)
#endif
static long __Pyx__PyObject_Ord(PyObject* c);

#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

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb);

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

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

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

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));
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE int __Pyx_IterFinish(void);

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

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));
}

#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()) {
            PyObject* args = PyTuple_Pack(1, key);
            if (likely(args))
                PyErr_SetObject(PyExc_KeyError, args);
            Py_XDECREF(args);
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#else
    #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#endif

#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 CYTHON_INLINE 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);

static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject* none = _PyList_Extend((PyListObject*)L, v);
    if (unlikely(!none))
        return -1;
    Py_DECREF(none);
    return 0;
#else
    return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
#endif
}

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);

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

#include <string.h>

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

#if CYTHON_COMPILING_IN_CPYTHON
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);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

#if PY_MAJOR_VERSION < 3
#define __Pyx_PyString_Join __Pyx_PyBytes_Join
#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v))
#else
#define __Pyx_PyString_Join PyUnicode_Join
#define __Pyx_PyBaseString_Join PyUnicode_Join
#endif
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION < 3
    #define __Pyx_PyBytes_Join _PyString_Join
    #else
    #define __Pyx_PyBytes_Join _PyBytes_Join
    #endif
#else
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values);
#endif

static CYTHON_INLINE long __Pyx_div_long(long, long);

static CYTHON_INLINE long __Pyx_mod_long(long, long);

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);

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed);

static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact);

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_EqObjC(op1, op2, intval, inplace)\
    PyObject_RichCompare(op1, op2, Py_EQ)
    #endif

#if CYTHON_COMPILING_IN_CPYTHON
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);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o,n,NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

static int __Pyx_SetVtable(PyObject *dict, void *vtable);

static void* __Pyx_GetVtable(PyObject *dict);

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

typedef struct {
    int code_line;
    PyCodeObject* code_object;
} __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);

static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

#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;
        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;
    op->ob_size = 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;
    self->ob_size = 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->ob_size) {
        self->ob_size = n;
        return 0;
    }
    newsize = n + (n / 2) + 1;
    if (newsize <= self->allocated) {
        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;
    self->ob_size = n;
    self->allocated = newsize;
    return 0;
}
#endif

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value);

static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *);

static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);

static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyObject *);
typedef struct {
    PyObject_HEAD
    __pyx_coroutine_body_t body;
    PyObject *closure;
    PyObject *exc_type;
    PyObject *exc_value;
    PyObject *exc_traceback;
    PyObject *gi_weakreflist;
    PyObject *classobj;
    PyObject *yieldfrom;
    PyObject *gi_name;
    PyObject *gi_qualname;
    int resume_label;
    char is_running;
} __pyx_CoroutineObject;
static __pyx_CoroutineObject *__Pyx__Coroutine_New(PyTypeObject *type, __pyx_coroutine_body_t body,
                                                   PyObject *closure, PyObject *name, PyObject *qualname);
static int __Pyx_Coroutine_clear(PyObject *self);
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue);
#else
#define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue)
#endif

static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code);

static int __Pyx_patch_abc(void);

#define __Pyx_Generator_USED
static PyTypeObject *__pyx_GeneratorType = 0;
#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
#define __Pyx_Generator_New(body, closure, name, qualname)\
    __Pyx__Coroutine_New(__pyx_GeneratorType, body, closure, name, qualname)
static PyObject *__Pyx_Generator_Next(PyObject *self);
static int __pyx_Generator_init(void);

static int __Pyx_check_binary_version(void);

static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);

#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

static PyObject *__Pyx_ImportModule(const char *name);

static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);

static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig);

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_tostring(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_15calignedsegment_AlignmentFile_t __pyx_v_htsfile, int __pyx_skip_dispatch); /* proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_set_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_has_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch); /* proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_get_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_get_tag *__pyx_optional_args); /* proto*/

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

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

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

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

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

/* Module declarations from 'pysam.chtslib' */

/* Module declarations from 'cython' */

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

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.type' */
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;

/* 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' */
static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;

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

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

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.complex' */
static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;

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

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

/* 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' */

/* Module declarations from 'array' */

/* Module declarations from 'cpython.array' */
static PyTypeObject *__pyx_ptype_7cpython_5array_array = 0;
static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, char *, Py_ssize_t); /*proto*/

/* Module declarations from 'pysam.cfaidx' */
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastaFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastqProxy = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_PersistentFastqProxy = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastxFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_FastqFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_6cfaidx_Fastafile = 0;

/* Module declarations from 'pysam.calignmentfile' */
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_AlignmentFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_PileupColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_PileupRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRow = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IndexedReads = 0;

/* Module declarations from 'pysam.cutils' */
static arrayobject *(*__pyx_f_5pysam_6cutils_qualitystring_to_array)(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cutils_qualitystring_to_array *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_6cutils_array_to_qualitystring)(arrayobject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cutils_array_to_qualitystring *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_6cutils_qualities_to_qualitystring)(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cutils_qualities_to_qualitystring *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_6cutils_charptr_to_str)(char const *, struct __pyx_opt_args_5pysam_6cutils_charptr_to_str *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_6cutils_charptr_to_bytes)(char const *, struct __pyx_opt_args_5pysam_6cutils_charptr_to_bytes *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_6cutils_force_str)(PyObject *, struct __pyx_opt_args_5pysam_6cutils_force_str *__pyx_optional_args); /*proto*/
static PyObject *(*__pyx_f_5pysam_6cutils_force_bytes)(PyObject *, struct __pyx_opt_args_5pysam_6cutils_force_bytes *__pyx_optional_args); /*proto*/

/* Module declarations from 'pysam.calignedsegment' */
static PyTypeObject *__pyx_ptype_5pysam_15calignedsegment_AlignedSegment = 0;
static PyTypeObject *__pyx_ptype_5pysam_15calignedsegment_PileupColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_15calignedsegment_PileupRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_15calignedsegment___pyx_scope_struct__genexpr = 0;
static PyTypeObject *__pyx_ptype_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr = 0;
static char *__pyx_v_5pysam_15calignedsegment_htslib_types;
static char *__pyx_v_5pysam_15calignedsegment_parray_types;
static char *__pyx_v_5pysam_15calignedsegment_CODE2CIGAR;
static PyObject *__pyx_f_5pysam_15calignedsegment_makeAlignedSegment(bam1_t *, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_makePileupRead(bam_pileup1_t *, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *); /*proto*/
static CYTHON_INLINE uint32_t __pyx_f_5pysam_15calignedsegment_get_alignment_length(bam1_t *); /*proto*/
static CYTHON_INLINE char __pyx_f_5pysam_15calignedsegment_map_typecode_htslib_to_python(uint8_t); /*proto*/
static CYTHON_INLINE uint8_t __pyx_f_5pysam_15calignedsegment_map_typecode_python_to_htslib(char); /*proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_convert_binary_tag(uint8_t *); /*proto*/
static CYTHON_INLINE uint8_t __pyx_f_5pysam_15calignedsegment_get_value_code(PyObject *, struct __pyx_opt_args_5pysam_15calignedsegment_get_value_code *__pyx_optional_args); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_getTypecode(PyObject *, struct __pyx_opt_args_5pysam_15calignedsegment_getTypecode *__pyx_optional_args); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_packTags(PyObject *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_5pysam_15calignedsegment_calculateQueryLength(bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_5pysam_15calignedsegment_getQueryStart(bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_5pysam_15calignedsegment_getQueryEnd(bam1_t *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_getSequenceInRange(bam1_t *, uint32_t, uint32_t); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_getQualitiesInRange(bam1_t *, uint32_t, uint32_t); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_build_alignment_sequence(bam1_t *); /*proto*/
#define __Pyx_MODULE_NAME "pysam.calignedsegment"
int __pyx_module_is_main_pysam__calignedsegment = 0;

/* Implementation of 'pysam.calignedsegment' */
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_chr;
static PyObject *__pyx_builtin_min;
static PyObject *__pyx_builtin_max;
static PyObject *__pyx_builtin_NotImplementedError;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_NotImplemented;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_MemoryError;
static char __pyx_k_A[] = "A";
static char __pyx_k_B[] = "B";
static char __pyx_k_C[] = "C";
static char __pyx_k_D[] = "D";
static char __pyx_k_F[] = "F";
static char __pyx_k_H[] = "H";
static char __pyx_k_I[] = "I";
static char __pyx_k_S[] = "S";
static char __pyx_k_Z[] = "Z";
static char __pyx_k_b[] = "b";
static char __pyx_k_c[] = "c";
static char __pyx_k_d[] = "d";
static char __pyx_k_f[] = "f";
static char __pyx_k_h[] = "h";
static char __pyx_k_i[] = "i";
static char __pyx_k_s[] = "s";
static char __pyx_k_AZ[] = "AZ";
static char __pyx_k_MD[] = "MD";
static char __pyx_k__4[] = "<";
static char __pyx_k_re[] = "re";
static char __pyx_k__16[] = "";
static char __pyx_k__19[] = "\t";
static char __pyx_k__30[] = "\n";
static char __pyx_k_all[] = "__all__";
static char __pyx_k_c_2[] = "%c";
static char __pyx_k_chr[] = "chr";
static char __pyx_k_end[] = "end";
static char __pyx_k_i_c[] = "%i%c";
static char __pyx_k_map[] = "map";
static char __pyx_k_max[] = "max";
static char __pyx_k_min[] = "min";
static char __pyx_k_raw[] = "raw";
static char __pyx_k_tag[] = "tag";
static char __pyx_k_Zidf[] = "Zidf";
static char __pyx_k_args[] = "args";
static char __pyx_k_flag[] = "flag";
static char __pyx_k_join[] = "join";
static char __pyx_k_main[] = "__main__";
static char __pyx_k_send[] = "send";
static char __pyx_k_tags[] = "tags";
static char __pyx_k_test[] = "__test__";
static char __pyx_k_2sc_s[] = "2sc%s";
static char __pyx_k_array[] = "array";
static char __pyx_k_ascii[] = "ascii";
static char __pyx_k_close[] = "close";
static char __pyx_k_indel[] = "indel";
static char __pyx_k_level[] = "level";
static char __pyx_k_start[] = "start";
static char __pyx_k_throw[] = "throw";
static char __pyx_k_value[] = "value";
static char __pyx_k_2sc_is[] = "2sc%is";
static char __pyx_k_always[] = "always";
static char __pyx_k_ctypes[] = "ctypes";
static char __pyx_k_encode[] = "encode";
static char __pyx_k_import[] = "__import__";
static char __pyx_k_is_del[] = "is_del";
static char __pyx_k_struct[] = "struct";
static char __pyx_k_bBhHiIf[] = "bBhHiIf";
static char __pyx_k_cCsSiIf[] = "cCsSiIf";
static char __pyx_k_compare[] = "compare";
static char __pyx_k_compile[] = "compile";
static char __pyx_k_findall[] = "findall";
static char __pyx_k_genexpr[] = "genexpr";
static char __pyx_k_get_tag[] = "get_tag";
static char __pyx_k_has_tag[] = "has_tag";
static char __pyx_k_is_head[] = "is_head";
static char __pyx_k_is_tail[] = "is_tail";
static char __pyx_k_pileups[] = "pileups";
static char __pyx_k_replace[] = "replace";
static char __pyx_k_set_tag[] = "set_tag";
static char __pyx_k_2sccI_is[] = "2sccI%is";
static char __pyx_k_KeyError[] = "KeyError";
static char __pyx_k_calcsize[] = "calcsize";
static char __pyx_k_get_tags[] = "get_tags";
static char __pyx_k_getrname[] = "getrname";
static char __pyx_k_set_tags[] = "set_tags";
static char __pyx_k_tostring[] = "tostring";
static char __pyx_k_typecode[] = "typecode";
static char __pyx_k_with_seq[] = "with_seq";
static char __pyx_k_2sccI_i_s[] = "2sccI%i%s";
static char __pyx_k_MIDNSHP_X[] = "MIDNSHP=X";
static char __pyx_k_TypeError[] = "TypeError";
static char __pyx_k_alignment[] = "alignment";
static char __pyx_k_enumerate[] = "enumerate";
static char __pyx_k_nsegments[] = "nsegments";
static char __pyx_k_pack_into[] = "pack_into";
static char __pyx_k_CIGAR2CODE[] = "CIGAR2CODE";
static char __pyx_k_PileupRead[] = "PileupRead";
static char __pyx_k_ValueError[] = "ValueError";
static char __pyx_k_get_blocks[] = "get_blocks";
static char __pyx_k_is_refskip[] = "is_refskip";
static char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static char __pyx_k_query_name[] = "query_name";
static char __pyx_k_value_type[] = "value_type";
static char __pyx_k_CIGAR_REGEX[] = "CIGAR_REGEX";
static char __pyx_k_MemoryError[] = "MemoryError";
static char __pyx_k_cigarstring[] = "cigarstring";
static char __pyx_k_cigartuples[] = "cigartuples";
static char __pyx_k_d_MIDNSHP_X[] = "(\\d+)([MIDNSHP=X])";
static char __pyx_k_full_length[] = "full_length";
static char __pyx_k_get_overlap[] = "get_overlap";
static char __pyx_k_PileupColumn[] = "PileupColumn";
static char __pyx_k_matches_only[] = "matches_only";
static char __pyx_k_query_length[] = "query_length";
static char __pyx_k_reference_id[] = "reference_id";
static char __pyx_k_Invalid_tag_s[] = "Invalid tag: %s";
static char __pyx_k_reference_end[] = "reference_end";
static char __pyx_k_reference_pos[] = "reference_pos";
static char __pyx_k_AlignedSegment[] = "AlignedSegment";
static char __pyx_k_NotImplemented[] = "NotImplemented";
static char __pyx_k_properties_bin[] = "properties bin";
static char __pyx_k_query_position[] = "query_position";
static char __pyx_k_query_sequence[] = "query_sequence";
static char __pyx_k_unknown_type_s[] = "unknown type '%s'";
static char __pyx_k_mapping_quality[] = "mapping_quality";
static char __pyx_k_properties_flag[] = "properties flag";
static char __pyx_k_query_qualities[] = "query_qualities";
static char __pyx_k_reference_start[] = "reference_start";
static char __pyx_k_template_length[] = "template_length";
static char __pyx_k_with_value_type[] = "with_value_type";
static char __pyx_k_reference_length[] = "reference_length";
static char __pyx_k_get_aligned_pairs[] = "get_aligned_pairs";
static char __pyx_k_mapping_quality_2[] = "mapping quality";
static char __pyx_k_next_reference_id[] = "next_reference_id";
static char __pyx_k_sam_format_failed[] = "sam_format failed";
static char __pyx_k_tag_s_not_present[] = "tag '%s' not present";
static char __pyx_k_MD_tag_not_present[] = "MD tag not present";
static char __pyx_k_infer_query_length[] = "infer_query_length";
static char __pyx_k_malformatted_tag_s[] = "malformatted tag: %s";
static char __pyx_k_true_if_QC_failure[] = "true if QC failure";
static char __pyx_k_NotImplementedError[] = "NotImplementedError";
static char __pyx_k_query_alignment_end[] = "query_alignment_end";
static char __pyx_k_create_string_buffer[] = "create_string_buffer";
static char __pyx_k_invalid_value_type_s[] = "invalid value type '%s'";
static char __pyx_k_next_reference_start[] = "next_reference_start";
static char __pyx_k_query_alignment_start[] = "query_alignment_start";
static char __pyx_k_true_if_this_is_read1[] = "true if this is read1";
static char __pyx_k_true_if_this_is_read2[] = "true if this is read2";
static char __pyx_k_get_reference_sequence[] = "get_reference_sequence";
static char __pyx_k_invalid_value_type_s_s[] = "invalid value type '%s' (%s)";
static char __pyx_k_query_alignment_length[] = "query_alignment_length";
static char __pyx_k_get_reference_positions[] = "get_reference_positions";
static char __pyx_k_query_alignment_sequence[] = "query_alignment_sequence";
static char __pyx_k_unknown_auxiliary_type_s[] = "unknown auxiliary type '%s'";
static char __pyx_k_query_alignment_qualities[] = "query_alignment_qualities";
static char __pyx_k_0_based_leftmost_coordinate[] = "0-based leftmost coordinate";
static char __pyx_k_true_if_the_mate_is_unmapped[] = "true if the mate is unmapped";
static char __pyx_k_true_if_not_primary_alignment[] = "true if not primary alignment";
static char __pyx_k_unknown_htslib_tag_typecode_s[] = "unknown htslib tag typecode '%s'";
static char __pyx_k_term_reference_name_None_if_no[] = ":term:`reference` name (None if no AlignmentFile is associated)";
static char __pyx_k_Padding_BAM_CPAD_6_is_currently[] = "Padding (BAM_CPAD, 6) is currently not supported. Please implement. Sorry about that.";
static char __pyx_k_at_least_one_signed_integer_out[] = "at least one signed integer out of range of BAM/SAM specification";
static char __pyx_k_could_not_allocated_sequence_of[] = "could not allocated sequence of length %i";
static char __pyx_k_deprecated_query_length_instead[] = "deprecated, query_length instead";
static char __pyx_k_deprecated_use_get_tags_instead[] = "deprecated, use get_tags() instead";
static char __pyx_k_number_of_reads_mapping_to_this[] = "number of reads mapping to this column.";
static char __pyx_k_quality_and_sequence_mismatch_i[] = "quality and sequence mismatch: %i != %i";
static char __pyx_k_term_reference_ID_note_This_fie[] = ":term:`reference` ID\n\n        .. note::\n\n            This field contains the index of the reference sequence in\n            the sequence dictionary. To obtain the name of the\n            reference sequence, use\n            :meth:`pysam.AlignmentFile.getrname()`\n\n        ";
static char __pyx_k_term_reference_name_of_the_mate[] = ":term:`reference` name of the mate/next read (None if no\n        AlignmentFile is associated)";
static char __pyx_k_the_query_template_name_None_if[] = "the query template name (None if not present)";
static char __pyx_k_true_if_read_itself_is_unmapped[] = "true if read itself is unmapped";
static char __pyx_k_true_if_this_is_a_supplementary[] = "true if this is a supplementary alignment";
static char __pyx_k_1_iff_the_base_on_the_padded_rea[] = "1 iff the base on the padded read is a deletion";
static char __pyx_k_Invalid_clipping_in_CIGAR_string[] = "Invalid clipping in CIGAR string";
static char __pyx_k_PileupColumn_accessed_after_iter[] = "PileupColumn accessed after iterator finished";
static char __pyx_k_a_class_pysam_AlignedSegment_obj[] = "a :class:`pysam.AlignedSegment` object of the aligned read";
static char __pyx_k_aligned_length_of_the_read_on_th[] = "aligned length of the read on the reference genome.\n\n        This is equal to `aend - pos`. Returns None if not available.";
static char __pyx_k_aligned_portion_of_the_read_This[] = "aligned portion of the read.\n\n        This is a substring of :attr:`seq` that excludes flanking\n        bases that were :term:`soft clipped` (None if not present). It\n        is equal to ``seq[qstart:qend]``.\n\n        SAM/BAM files may include extra flanking bases that are not\n        part of the alignment.  These bases may be the result of the\n        Smith-Waterman or other algorithms, which may not require\n        alignments that begin at the first residue or end at the last.\n        In addition, extra sequencing adapters, multiplex identifiers,\n        and low-quality bases that were not considered for alignment\n        may have been retained.\n\n        ";
static char __pyx_k_aligned_query_sequence_quality_v[] = "aligned query sequence quality values (None if not present). These\n        are the quality values that correspond to :attr:`query`, that\n        is, they exclude qualities of :term:`soft clipped` bases. This\n        is equal to ``qual[qstart:qend]``.\n\n        Quality scores are returned as a python array of unsigned\n        chars. Note that this is not the ASCII-encoded value typically\n        seen in FASTQ or SAM formatted files. Thus, no offset of 33\n        needs to be subtracted.\n\n        This property is read-only.\n\n        ";
static char __pyx_k_aligned_reference_position_of_th[] = "aligned reference position of the read on the reference genome.\n\n        reference_end points to one past the last aligned residue.\n        Returns None if not available (read is unmapped or no cigar\n        alignment present).\n\n        ";
static char __pyx_k_at_least_one_integer_out_of_rang[] = "at least one integer out of range of BAM/SAM specification";
static char __pyx_k_can_t_guess_type_or_invalid_type[] = "can't guess type or invalid type code specified";
static char __pyx_k_could_not_determine_alignment_le[] = "could not determine alignment length";
static char __pyx_k_deprecated_query_alignment_quali[] = "deprecated, query_alignment_qualities instead";
static char __pyx_k_deprecated_query_alignment_seque[] = "deprecated, query_alignment_sequence instead";
static char __pyx_k_deprecated_query_qualities_inste[] = "deprecated, query_qualities instead";
static char __pyx_k_deprecated_reference_end_instead[] = "deprecated, reference_end instead";
static char __pyx_k_deprecated_reference_length_inst[] = "deprecated, reference_length instead";
static char __pyx_k_deprecated_use_cigartuples_inste[] = "deprecated, use cigartuples instead";
static char __pyx_k_deprecated_use_get_aligned_pairs[] = "deprecated, use get_aligned_pairs() instead";
static char __pyx_k_deprecated_use_get_blocks_instea[] = "deprecated, use get_blocks() instead";
static char __pyx_k_deprecated_use_get_reference_pos[] = "deprecated, use get_reference_positions() instead";
static char __pyx_k_deprecated_use_infer_query_lengt[] = "deprecated, use infer_query_length() instead";
static char __pyx_k_deprecated_use_mapping_quality_i[] = "deprecated, use mapping_quality instead";
static char __pyx_k_deprecated_use_next_reference_id[] = "deprecated, use next_reference_id instead";
static char __pyx_k_deprecated_use_next_reference_st[] = "deprecated, use next_reference_start instead";
static char __pyx_k_deprecated_use_query_alignment_e[] = "deprecated, use query_alignment_end instead";
static char __pyx_k_deprecated_use_query_alignment_l[] = "deprecated, use query_alignment_length instead";
static char __pyx_k_deprecated_use_query_alignment_s[] = "deprecated, use query_alignment_start instead";
static char __pyx_k_deprecated_use_query_name_instea[] = "deprecated, use query_name instead";
static char __pyx_k_deprecated_use_query_sequence_in[] = "deprecated, use query_sequence instead";
static char __pyx_k_deprecated_use_reference_id_inst[] = "deprecated, use reference_id instead";
static char __pyx_k_deprecated_use_reference_start_i[] = "deprecated, use reference_start instead";
static char __pyx_k_deprecated_use_template_length_i[] = "deprecated, use template_length instead";
static char __pyx_k_end_index_of_the_aligned_query_p[] = "end index of the aligned query portion of the sequence (0-based,\n        exclusive)";
static char __pyx_k_indel_length_for_the_position_fo[] = "indel length for the position follwing the current pileup site.\n\n        This quantity peeks ahead to the next cigar operation in this\n        alignment. If the next operation is and insertion, indel will\n        be positve. If the next operation is a deletion, it will be\n        negation. 0 if the next operation is not an indel.\n\n        ";
static char __pyx_k_length_of_the_aligned_query_sequ[] = "length of the aligned query sequence.\n\n        This is equal to :attr:`qend` - :attr:`qstart`";
static char __pyx_k_list_of_reads_class_pysam_Pileup[] = "list of reads (:class:`pysam.PileupRead`) aligned to this column";
static char __pyx_k_position_of_the_read_base_at_the[] = "position of the read base at the pileup site, 0-based.\n        None if is_del or is_refskip is set.\n\n        ";
static char __pyx_k_read_sequence_base_qualities_inc[] = "read sequence base qualities, including :term:`soft\n        clipped` bases (None if not present).\n\n        Quality scores are returned as a python array of unsigned\n        chars. Note that this is not the ASCII-encoded value typically\n        seen in FASTQ or SAM formatted files. Thus, no offset of 33\n        needs to be subtracted.\n\n        Note that to set quality scores the sequence has to be set\n        beforehand as this will determine the expected length of the\n        quality score array.\n\n        This method raises a ValueError if the length of the\n        quality scores and the sequence are not the same.\n\n        ";
static char __pyx_k_read_sequence_bases_including_te[] = "read sequence bases, including :term:`soft clipped` bases\n        (None if not present).\n\n        Note that assigning to seq will invalidate any quality scores.\n        Thus, to in-place edit the sequence and quality scores, copies of\n        the quality scores need to be taken. Consider trimming for example::\n\n           q = read.query_qualities\n           read.query_squence = read.query_sequence[5:10]\n           read.query_qualities = q[5:10]\n\n        The sequence is returned as it is stored in the BAM file. Some mappers\n        might have stored a reverse complement of the original read\n        sequence.\n        ";
static char __pyx_k_start_index_of_the_aligned_query[] = "start index of the aligned query portion of the sequence (0-based,\n        inclusive).\n\n        This the index of the first base in :attr:`seq` that is not\n        soft-clipped.\n\n        ";
static char __pyx_k_the_length_of_the_query_read_Thi[] = "the length of the query/read.\n\n        This value corresponds to the length of the sequence supplied\n        in the BAM/SAM file. The length of a query is 0 if there is no\n        sequence in the BAM/SAM file. In those cases, the read length\n        can be inferred from the CIGAR alignment, see\n        :meth:`pysam.AlignmentFile.infer_query_length.`.\n\n        The length includes soft-clipped bases and is equal to\n        ``len(query_sequence)``.\n\n        This property is read-only but can be set by providing a\n        sequence.\n\n        Returns 0 if not available.\n\n        ";
static char __pyx_k_the_level_of_the_read_in_the_vie[] = "the level of the read in the \"viewer\" mode";
static char __pyx_k_the_observed_query_template_leng[] = "the observed query template length";
static char __pyx_k_the_position_in_the_reference_se[] = "the position in the reference sequence (0-based).";
static char __pyx_k_the_position_of_the_mate_next_re[] = "the position of the mate/next read.";
static char __pyx_k_the_reference_sequence_number_as[] = "the reference sequence number as defined in the header";
static char __pyx_k_the_term_cigar_alignment_The_ali[] = "the :term:`cigar` alignment. The alignment\n        is returned as a list of tuples of (operation, length).\n\n        If the alignment is not present, None is returned.\n\n        The operations are:\n\n        +-----+--------------+-----+\n        |M    |BAM_CMATCH    |0    |\n        +-----+--------------+-----+\n        |I    |BAM_CINS      |1    |\n        +-----+--------------+-----+\n        |D    |BAM_CDEL      |2    |\n        +-----+--------------+-----+\n        |N    |BAM_CREF_SKIP |3    |\n        +-----+--------------+-----+\n        |S    |BAM_CSOFT_CLIP|4    |\n        +-----+--------------+-----+\n        |H    |BAM_CHARD_CLIP|5    |\n        +-----+--------------+-----+\n        |P    |BAM_CPAD      |6    |\n        +-----+--------------+-----+\n        |=    |BAM_CEQUAL    |7    |\n        +-----+--------------+-----+\n        |X    |BAM_CDIFF     |8    |\n        +-----+--------------+-----+\n\n        .. note::\n            The output is a list of (operation, length) tuples, such as\n            ``[(0, 30)]``.\n            This is different from the SAM specification and\n            the :attr:`cigarstring` property, which uses a\n            (length, operation) order, for example: ``30M``.\n\n        To unset the cigar property, assign an empty list\n        or None.\n        ";
static char __pyx_k_the_term_cigar_alignment_as_a_st[] = "the :term:`cigar` alignment as a string.\n\n        The cigar string is a string of alternating integers\n        and characters denoting the length and the type of\n        an operation.\n\n        .. note::\n            The order length,operation is specified in the\n            SAM format. It is different from the order of\n            the :attr:`cigar` property.\n\n        Returns None if not present.\n\n        To unset the cigarstring, assign None or the\n        empty string.\n        ";
static char __pyx_k_the_term_reference_id_of_the_mat[] = "the :term:`reference` id of the mate/next read.";
static char __pyx_k_this_class_cannot_be_instantiate[] = "this class cannot be instantiated from Python";
static char __pyx_k_true_if_optical_or_PCR_duplicate[] = "true if optical or PCR duplicate";
static char __pyx_k_true_if_read_is_mapped_in_a_prop[] = "true if read is mapped in a proper pair";
static char __pyx_k_true_if_read_is_mapped_to_revers[] = "true if read is mapped to reverse strand";
static char __pyx_k_true_if_read_is_paired_in_sequen[] = "true if read is paired in sequencing";
static char __pyx_k_true_is_read_is_mapped_to_revers[] = "true is read is mapped to reverse strand";
static char __pyx_k_unknown_conversion_for_array_typ[] = "unknown conversion for array typecode '%s'";
static char __pyx_k_unsupported_value_type_in_set_op[] = "unsupported value_type in set_option";
static char __pyx_k_1_iff_the_base_on_the_padded_rea_2[] = "1 iff the base on the padded read is the left-most base.";
static char __pyx_k_1_iff_the_base_on_the_padded_rea_3[] = "1 iff the base on the padded read is the right-most base.";
static char __pyx_k_position_of_the_read_base_at_the_2[] = "position of the read base at the pileup site, 0-based.\n\n        If the current position is a deletion, returns the next\n        aligned base.\n\n        ";
static PyObject *__pyx_kp_s_2sc_is;
static PyObject *__pyx_kp_s_2sc_s;
static PyObject *__pyx_kp_s_2sccI_i_s;
static PyObject *__pyx_kp_s_2sccI_is;
static PyObject *__pyx_n_b_A;
static PyObject *__pyx_n_s_A;
static PyObject *__pyx_n_b_AZ;
static PyObject *__pyx_n_s_AlignedSegment;
static PyObject *__pyx_n_b_B;
static PyObject *__pyx_n_s_B;
static PyObject *__pyx_n_b_C;
static PyObject *__pyx_n_s_C;
static PyObject *__pyx_n_s_CIGAR2CODE;
static PyObject *__pyx_n_s_CIGAR_REGEX;
static PyObject *__pyx_n_s_D;
static PyObject *__pyx_n_s_F;
static PyObject *__pyx_n_s_H;
static PyObject *__pyx_n_b_I;
static PyObject *__pyx_n_s_I;
static PyObject *__pyx_kp_s_Invalid_tag_s;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_kp_s_MD_tag_not_present;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_n_s_NotImplemented;
static PyObject *__pyx_n_s_NotImplementedError;
static PyObject *__pyx_kp_s_Padding_BAM_CPAD_6_is_currently;
static PyObject *__pyx_n_s_PileupColumn;
static PyObject *__pyx_kp_s_PileupColumn_accessed_after_iter;
static PyObject *__pyx_n_s_PileupRead;
static PyObject *__pyx_n_b_S;
static PyObject *__pyx_n_s_S;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_b_Z;
static PyObject *__pyx_n_s_Z;
static PyObject *__pyx_n_s_Zidf;
static PyObject *__pyx_kp_s__16;
static PyObject *__pyx_kp_s__19;
static PyObject *__pyx_kp_s__30;
static PyObject *__pyx_kp_s__4;
static PyObject *__pyx_n_s_alignment;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_always;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_ascii;
static PyObject *__pyx_kp_s_at_least_one_integer_out_of_rang;
static PyObject *__pyx_kp_s_at_least_one_signed_integer_out;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_b_c;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_kp_s_c_2;
static PyObject *__pyx_n_s_calcsize;
static PyObject *__pyx_kp_s_can_t_guess_type_or_invalid_type;
static PyObject *__pyx_n_s_chr;
static PyObject *__pyx_n_s_cigarstring;
static PyObject *__pyx_n_s_cigartuples;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_compare;
static PyObject *__pyx_n_s_compile;
static PyObject *__pyx_kp_s_could_not_allocated_sequence_of;
static PyObject *__pyx_kp_s_could_not_determine_alignment_le;
static PyObject *__pyx_n_s_create_string_buffer;
static PyObject *__pyx_n_s_ctypes;
static PyObject *__pyx_n_s_d;
static PyObject *__pyx_kp_s_d_MIDNSHP_X;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_b_f;
static PyObject *__pyx_n_s_f;
static PyObject *__pyx_n_s_findall;
static PyObject *__pyx_n_s_flag;
static PyObject *__pyx_n_s_full_length;
static PyObject *__pyx_n_s_genexpr;
static PyObject *__pyx_n_s_get_aligned_pairs;
static PyObject *__pyx_n_s_get_blocks;
static PyObject *__pyx_n_s_get_overlap;
static PyObject *__pyx_n_s_get_reference_positions;
static PyObject *__pyx_n_s_get_reference_sequence;
static PyObject *__pyx_n_s_get_tag;
static PyObject *__pyx_n_s_get_tags;
static PyObject *__pyx_n_s_getrname;
static PyObject *__pyx_n_s_h;
static PyObject *__pyx_n_s_has_tag;
static PyObject *__pyx_n_b_i;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_kp_s_i_c;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_indel;
static PyObject *__pyx_n_s_infer_query_length;
static PyObject *__pyx_kp_s_invalid_value_type_s;
static PyObject *__pyx_kp_s_invalid_value_type_s_s;
static PyObject *__pyx_n_s_is_del;
static PyObject *__pyx_n_s_is_head;
static PyObject *__pyx_n_s_is_refskip;
static PyObject *__pyx_n_s_is_tail;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_level;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_kp_s_malformatted_tag_s;
static PyObject *__pyx_n_s_map;
static PyObject *__pyx_n_s_mapping_quality;
static PyObject *__pyx_n_s_matches_only;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_min;
static PyObject *__pyx_n_s_next_reference_id;
static PyObject *__pyx_n_s_next_reference_start;
static PyObject *__pyx_n_s_nsegments;
static PyObject *__pyx_n_s_pack_into;
static PyObject *__pyx_n_s_pileups;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_kp_s_quality_and_sequence_mismatch_i;
static PyObject *__pyx_n_s_query_alignment_end;
static PyObject *__pyx_n_s_query_alignment_length;
static PyObject *__pyx_n_s_query_alignment_qualities;
static PyObject *__pyx_n_s_query_alignment_sequence;
static PyObject *__pyx_n_s_query_alignment_start;
static PyObject *__pyx_n_s_query_length;
static PyObject *__pyx_n_s_query_name;
static PyObject *__pyx_n_s_query_position;
static PyObject *__pyx_n_s_query_qualities;
static PyObject *__pyx_n_s_query_sequence;
static PyObject *__pyx_n_s_raw;
static PyObject *__pyx_n_s_re;
static PyObject *__pyx_n_s_reference_end;
static PyObject *__pyx_n_s_reference_id;
static PyObject *__pyx_n_s_reference_length;
static PyObject *__pyx_n_s_reference_pos;
static PyObject *__pyx_n_s_reference_start;
static PyObject *__pyx_n_s_replace;
static PyObject *__pyx_n_b_s;
static PyObject *__pyx_n_s_s;
static PyObject *__pyx_kp_s_sam_format_failed;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_set_tag;
static PyObject *__pyx_n_s_set_tags;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_n_s_struct;
static PyObject *__pyx_n_s_tag;
static PyObject *__pyx_kp_s_tag_s_not_present;
static PyObject *__pyx_n_s_tags;
static PyObject *__pyx_n_s_template_length;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_kp_s_this_class_cannot_be_instantiate;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_tostring;
static PyObject *__pyx_n_s_typecode;
static PyObject *__pyx_kp_s_unknown_auxiliary_type_s;
static PyObject *__pyx_kp_s_unknown_conversion_for_array_typ;
static PyObject *__pyx_kp_s_unknown_htslib_tag_typecode_s;
static PyObject *__pyx_kp_s_unknown_type_s;
static PyObject *__pyx_kp_s_unsupported_value_type_in_set_op;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_n_s_value_type;
static PyObject *__pyx_n_s_with_seq;
static PyObject *__pyx_n_s_with_value_type;
static PyObject *__pyx_pf_5pysam_15calignedsegment_genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_3genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment___init__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_2__dealloc__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4__str__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6__copy__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8__deepcopy__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10compare(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12__richcmp__(PyObject *__pyx_v_self, struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_other, int __pyx_v_op); /* proto */
static Py_hash_t __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14__hash__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16tostring(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_15calignedsegment_AlignmentFile_t __pyx_v_htsfile); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10query_name___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10query_name_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qname); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4flag___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4flag_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14reference_name___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12reference_id___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12reference_id_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15reference_start___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15reference_start_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_pos); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigarstring___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_cigar); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mtid); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_19next_reference_name___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mpos); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12query_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15template_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15template_length_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_isize); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14query_sequence___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_seq); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15query_qualities___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3bin___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3bin_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_bin); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_paired___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_paired_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10is_reverse___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read1___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read1_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read2___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read2_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_secondary___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_13reference_end___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16reference_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_24query_alignment_sequence___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_25query_alignment_qualities___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_21query_alignment_start___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_19query_alignment_end___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_22query_alignment_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_18get_reference_positions(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20infer_query_length(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_22get_reference_sequence(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_24get_aligned_pairs(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only, PyObject *__pyx_v_with_seq); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_26get_blocks(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_28get_overlap(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigartuples___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_values); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_30set_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_32has_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_34get_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_with_value_type); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_36get_tags(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_with_value_type); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_38set_tags(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qname___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qname_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3tid___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3tid_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3pos___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3pos_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mapq___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mapq_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rnext___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rnext_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5pnext___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5pnext_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5cigar___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5cigar_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tlen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tlen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3seq___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3seq_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qual___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qual_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4alen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4alen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4aend___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4aend_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4rlen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4rlen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5query___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5query_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qqual___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qqual_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6qstart___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6qstart_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qend___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qend_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qlen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qlen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mrnm___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mrnm_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mpos___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mpos_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rname___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rname_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5isize___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5isize_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6blocks___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_13aligned_pairs___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15inferred_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9positions___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tags___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tags_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_40overlap(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_42opt(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_44setTag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_2__str__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_12reference_id___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_14reference_name___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_9nsegments___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_9nsegments_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_n); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_13reference_pos___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_7pileups___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_3pos___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3pos_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_3tid___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3tid_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_1n___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_1n_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static int __pyx_pf_5pysam_15calignedsegment_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_2__str__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_14query_position___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_22query_position_or_next___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_5level___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_10is_refskip___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self); /* proto */
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_tp_new_5pysam_15calignedsegment_AlignedSegment(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_15calignedsegment_PileupColumn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_15calignedsegment_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct__genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_4;
static PyObject *__pyx_int_128;
static PyObject *__pyx_int_256;
static PyObject *__pyx_int_32768;
static PyObject *__pyx_int_65536;
static PyObject *__pyx_int_2147483648;
static PyObject *__pyx_int_4294967296;
static PyObject *__pyx_int_neg_128;
static PyObject *__pyx_int_neg_32768;
static PyObject *__pyx_int_neg_2147483648;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_slice__13;
static PyObject *__pyx_slice__14;
static PyObject *__pyx_slice__15;
static PyObject *__pyx_slice__26;
static PyObject *__pyx_slice__27;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_gb_5pysam_15calignedsegment_2generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysam/calignedsegment.pyx":82
 * 
 * if PY_MAJOR_VERSION >= 3:
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))
 */

static PyObject *__pyx_pf_5pysam_15calignedsegment_genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *)__pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct__genexpr(__pyx_ptype_5pysam_15calignedsegment___pyx_scope_struct__genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 82, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_15calignedsegment_2generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5pysam_15calignedsegment_2generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *(*__pyx_t_4)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_1 = __pyx_int_0;
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_15calignedsegment_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    {
      __pyx_t_2 = __pyx_t_4(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_y);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_y, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_y);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_y);
    PyList_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_y);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_x);
    PyList_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_x);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = 0;
    __Pyx_XGOTREF(__pyx_t_3);
    __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_5pysam_15calignedsegment_5generator1(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysam/calignedsegment.pyx":84
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))
 * else:
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))             # <<<<<<<<<<<<<<
 * 
 * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=X])")
 */

static PyObject *__pyx_pf_5pysam_15calignedsegment_3genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *)__pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr(__pyx_ptype_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 84, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  {
    __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_5pysam_15calignedsegment_5generator1, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_5pysam_15calignedsegment_5generator1(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *(*__pyx_t_4)(PyObject *);
  long __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L6_resume_from_yield;
    default: /* CPython raises the right error here */
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __pyx_L3_first_run:;
  if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_1 = __pyx_int_0;
  __pyx_t_2 = __Pyx_PyBytes_FromString(__pyx_v_5pysam_15calignedsegment_CODE2CIGAR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    {
      __pyx_t_2 = __pyx_t_4(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_y);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_y, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    __pyx_t_5 = __Pyx_PyObject_Ord(__pyx_cur_scope->__pyx_v_y); if (unlikely(__pyx_t_5 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyInt_From_long(__pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_2);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_x);
    PyList_SET_ITEM(__pyx_t_6, 1, __pyx_cur_scope->__pyx_v_x);
    __pyx_t_2 = 0;
    __pyx_r = __pyx_t_6;
    __pyx_t_6 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L6_resume_from_yield:;
    __pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_1);
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = 0;
    __Pyx_XGOTREF(__pyx_t_3);
    __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* function exit code */
  PyErr_SetNone(PyExc_StopIteration);
  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("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_r); __pyx_r = 0;
  __pyx_generator->resume_label = -1;
  __Pyx_Coroutine_clear((PyObject*)__pyx_generator);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":90
 * #####################################################################
 * # typecode guessing
 * cdef inline char map_typecode_htslib_to_python(uint8_t s):             # <<<<<<<<<<<<<<
 *     """map an htslib typecode to the corresponding python typecode
 *     to be used in the struct or array modules."""
 */

static CYTHON_INLINE char __pyx_f_5pysam_15calignedsegment_map_typecode_htslib_to_python(uint8_t __pyx_v_s) {
  char *__pyx_v_f;
  char __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("map_typecode_htslib_to_python", 0);
  __Pyx_TraceCall("map_typecode_htslib_to_python", __pyx_f[0], 90, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":95
 * 
 *     # map type from htslib to python array
 *     cdef char * f = strchr(htslib_types, s)             # <<<<<<<<<<<<<<
 *     if f == NULL:
 *         raise ValueError("unknown htslib tag typecode '%s'" % chr(s))
 */
  __pyx_v_f = strchr(__pyx_v_5pysam_15calignedsegment_htslib_types, __pyx_v_s);

  /* "pysam/calignedsegment.pyx":96
 *     # map type from htslib to python array
 *     cdef char * f = strchr(htslib_types, s)
 *     if f == NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError("unknown htslib tag typecode '%s'" % chr(s))
 *     return parray_types[f - htslib_types]
 */
  __pyx_t_1 = ((__pyx_v_f == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":97
 *     cdef char * f = strchr(htslib_types, s)
 *     if f == NULL:
 *         raise ValueError("unknown htslib tag typecode '%s'" % chr(s))             # <<<<<<<<<<<<<<
 *     return parray_types[f - htslib_types]
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_From_uint8_t(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_unknown_htslib_tag_typecode_s, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":96
 *     # map type from htslib to python array
 *     cdef char * f = strchr(htslib_types, s)
 *     if f == NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError("unknown htslib tag typecode '%s'" % chr(s))
 *     return parray_types[f - htslib_types]
 */
  }

  /* "pysam/calignedsegment.pyx":98
 *     if f == NULL:
 *         raise ValueError("unknown htslib tag typecode '%s'" % chr(s))
 *     return parray_types[f - htslib_types]             # <<<<<<<<<<<<<<
 * 
 * cdef inline uint8_t map_typecode_python_to_htslib(char s):
 */
  __pyx_r = (__pyx_v_5pysam_15calignedsegment_parray_types[(__pyx_v_f - __pyx_v_5pysam_15calignedsegment_htslib_types)]);
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":90
 * #####################################################################
 * # typecode guessing
 * cdef inline char map_typecode_htslib_to_python(uint8_t s):             # <<<<<<<<<<<<<<
 *     """map an htslib typecode to the corresponding python typecode
 *     to be used in the struct or array modules."""
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pysam.calignedsegment.map_typecode_htslib_to_python", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":100
 *     return parray_types[f - htslib_types]
 * 
 * cdef inline uint8_t map_typecode_python_to_htslib(char s):             # <<<<<<<<<<<<<<
 *     """determine value type from type code of array"""
 *     cdef char * f = strchr(parray_types, s)
 */

static CYTHON_INLINE uint8_t __pyx_f_5pysam_15calignedsegment_map_typecode_python_to_htslib(char __pyx_v_s) {
  char *__pyx_v_f;
  uint8_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("map_typecode_python_to_htslib", 0);
  __Pyx_TraceCall("map_typecode_python_to_htslib", __pyx_f[0], 100, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":102
 * cdef inline uint8_t map_typecode_python_to_htslib(char s):
 *     """determine value type from type code of array"""
 *     cdef char * f = strchr(parray_types, s)             # <<<<<<<<<<<<<<
 *     if f == NULL:
 *         raise ValueError(
 */
  __pyx_v_f = strchr(__pyx_v_5pysam_15calignedsegment_parray_types, __pyx_v_s);

  /* "pysam/calignedsegment.pyx":103
 *     """determine value type from type code of array"""
 *     cdef char * f = strchr(parray_types, s)
 *     if f == NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "unknown conversion for array typecode '%s'" % s)
 */
  __pyx_t_1 = ((__pyx_v_f == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":105
 *     if f == NULL:
 *         raise ValueError(
 *             "unknown conversion for array typecode '%s'" % s)             # <<<<<<<<<<<<<<
 *     return htslib_types[f - parray_types]
 * 
 */
    __pyx_t_2 = __Pyx_PyInt_From_char(__pyx_v_s); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_unknown_conversion_for_array_typ, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/calignedsegment.pyx":104
 *     cdef char * f = strchr(parray_types, s)
 *     if f == NULL:
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "unknown conversion for array typecode '%s'" % s)
 *     return htslib_types[f - parray_types]
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":103
 *     """determine value type from type code of array"""
 *     cdef char * f = strchr(parray_types, s)
 *     if f == NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "unknown conversion for array typecode '%s'" % s)
 */
  }

  /* "pysam/calignedsegment.pyx":106
 *         raise ValueError(
 *             "unknown conversion for array typecode '%s'" % s)
 *     return htslib_types[f - parray_types]             # <<<<<<<<<<<<<<
 * 
 * # optional tag data manipulation
 */
  __pyx_r = (__pyx_v_5pysam_15calignedsegment_htslib_types[(__pyx_v_f - __pyx_v_5pysam_15calignedsegment_parray_types)]);
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":100
 *     return parray_types[f - htslib_types]
 * 
 * cdef inline uint8_t map_typecode_python_to_htslib(char s):             # <<<<<<<<<<<<<<
 *     """determine value type from type code of array"""
 *     cdef char * f = strchr(parray_types, s)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pysam.calignedsegment.map_typecode_python_to_htslib", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":109
 * 
 * # optional tag data manipulation
 * cdef convert_binary_tag(uint8_t * tag):             # <<<<<<<<<<<<<<
 *     """return bytesize, number of values and array of values
 *     in aux_data memory location pointed to by tag."""
 */

static PyObject *__pyx_f_5pysam_15calignedsegment_convert_binary_tag(uint8_t *__pyx_v_tag) {
  uint8_t __pyx_v_auxtype;
  uint8_t __pyx_v_byte_size;
  int32_t __pyx_v_nvalues;
  arrayobject *__pyx_v_c_values = 0;
  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;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("convert_binary_tag", 0);
  __Pyx_TraceCall("convert_binary_tag", __pyx_f[0], 109, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":116
 *     cdef int32_t nvalues
 *     # get byte size
 *     auxtype = tag[0]             # <<<<<<<<<<<<<<
 *     byte_size = aux_type2size(auxtype)
 *     tag += 1
 */
  __pyx_v_auxtype = (__pyx_v_tag[0]);

  /* "pysam/calignedsegment.pyx":117
 *     # get byte size
 *     auxtype = tag[0]
 *     byte_size = aux_type2size(auxtype)             # <<<<<<<<<<<<<<
 *     tag += 1
 *     # get number of values in array
 */
  __pyx_v_byte_size = aux_type2size(__pyx_v_auxtype);

  /* "pysam/calignedsegment.pyx":118
 *     auxtype = tag[0]
 *     byte_size = aux_type2size(auxtype)
 *     tag += 1             # <<<<<<<<<<<<<<
 *     # get number of values in array
 *     nvalues = (<int32_t*>tag)[0]
 */
  __pyx_v_tag = (__pyx_v_tag + 1);

  /* "pysam/calignedsegment.pyx":120
 *     tag += 1
 *     # get number of values in array
 *     nvalues = (<int32_t*>tag)[0]             # <<<<<<<<<<<<<<
 *     tag += 4
 * 
 */
  __pyx_v_nvalues = (((int32_t *)__pyx_v_tag)[0]);

  /* "pysam/calignedsegment.pyx":121
 *     # get number of values in array
 *     nvalues = (<int32_t*>tag)[0]
 *     tag += 4             # <<<<<<<<<<<<<<
 * 
 *     # define python array
 */
  __pyx_v_tag = (__pyx_v_tag + 4);

  /* "pysam/calignedsegment.pyx":124
 * 
 *     # define python array
 *     cdef c_array.array c_values = array.array(             # <<<<<<<<<<<<<<
 *         chr(map_typecode_htslib_to_python(auxtype)))
 *     c_array.resize(c_values, nvalues)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":125
 *     # define python array
 *     cdef c_array.array c_values = array.array(
 *         chr(map_typecode_htslib_to_python(auxtype)))             # <<<<<<<<<<<<<<
 *     c_array.resize(c_values, nvalues)
 * 
 */
  __pyx_t_2 = __Pyx_PyInt_From_char(__pyx_f_5pysam_15calignedsegment_map_typecode_htslib_to_python(__pyx_v_auxtype)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":124
 * 
 *     # define python array
 *     cdef c_array.array c_values = array.array(             # <<<<<<<<<<<<<<
 *         chr(map_typecode_htslib_to_python(auxtype)))
 *     c_array.resize(c_values, nvalues)
 */
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_7cpython_5array_array))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_c_values = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":126
 *     cdef c_array.array c_values = array.array(
 *         chr(map_typecode_htslib_to_python(auxtype)))
 *     c_array.resize(c_values, nvalues)             # <<<<<<<<<<<<<<
 * 
 *     # copy data
 */
  __pyx_t_6 = resize(__pyx_v_c_values, __pyx_v_nvalues); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 126; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":129
 * 
 *     # copy data
 *     memcpy(c_values.data.as_voidptr, <uint8_t*>tag, nvalues * byte_size)             # <<<<<<<<<<<<<<
 * 
 *     # no need to check for endian-ness as bam1_core_t fields
 */
  memcpy(__pyx_v_c_values->data.as_voidptr, ((uint8_t *)__pyx_v_tag), (__pyx_v_nvalues * __pyx_v_byte_size));

  /* "pysam/calignedsegment.pyx":134
 *     # and aux_data are in host endian-ness. See sam.c and calls
 *     # to swap_data
 *     return byte_size, nvalues, c_values             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_byte_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_c_values));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_c_values));
  PyTuple_SET_ITEM(__pyx_t_5, 2, ((PyObject *)__pyx_v_c_values));
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":109
 * 
 * # optional tag data manipulation
 * cdef convert_binary_tag(uint8_t * tag):             # <<<<<<<<<<<<<<
 *     """return bytesize, number of values and array of values
 *     in aux_data memory location pointed to by tag."""
 */

  /* 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_AddTraceback("pysam.calignedsegment.convert_binary_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_c_values);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":137
 * 
 * 
 * cdef inline uint8_t get_value_code(value, value_type=None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */

static CYTHON_INLINE uint8_t __pyx_f_5pysam_15calignedsegment_get_value_code(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_15calignedsegment_get_value_code *__pyx_optional_args) {
  PyObject *__pyx_v_value_type = ((PyObject *)Py_None);
  uint8_t __pyx_v_typecode;
  char *__pyx_v__char_type;
  uint8_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  char *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_value_code", 0);
  __Pyx_TraceCall("get_value_code", __pyx_f[0], 137, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_value_type = __pyx_optional_args->value_type;
    }
  }
  __Pyx_INCREF(__pyx_v_value_type);

  /* "pysam/calignedsegment.pyx":144
 *     cdef char * _char_type
 * 
 *     if value_type is None:             # <<<<<<<<<<<<<<
 *         if isinstance(value, int):
 *             typecode = 'i'
 */
  __pyx_t_1 = (__pyx_v_value_type == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":145
 * 
 *     if value_type is None:
 *         if isinstance(value, int):             # <<<<<<<<<<<<<<
 *             typecode = 'i'
 *         elif isinstance(value, float):
 */
    __pyx_t_2 = PyInt_Check(__pyx_v_value); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":146
 *     if value_type is None:
 *         if isinstance(value, int):
 *             typecode = 'i'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, float):
 *             typecode = 'd'
 */
      __pyx_v_typecode = 'i';

      /* "pysam/calignedsegment.pyx":145
 * 
 *     if value_type is None:
 *         if isinstance(value, int):             # <<<<<<<<<<<<<<
 *             typecode = 'i'
 *         elif isinstance(value, float):
 */
      goto __pyx_L4;
    }

    /* "pysam/calignedsegment.pyx":147
 *         if isinstance(value, int):
 *             typecode = 'i'
 *         elif isinstance(value, float):             # <<<<<<<<<<<<<<
 *             typecode = 'd'
 *         elif isinstance(value, str):
 */
    __pyx_t_1 = PyFloat_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":148
 *             typecode = 'i'
 *         elif isinstance(value, float):
 *             typecode = 'd'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, str):
 *             typecode = 'Z'
 */
      __pyx_v_typecode = 'd';

      /* "pysam/calignedsegment.pyx":147
 *         if isinstance(value, int):
 *             typecode = 'i'
 *         elif isinstance(value, float):             # <<<<<<<<<<<<<<
 *             typecode = 'd'
 *         elif isinstance(value, str):
 */
      goto __pyx_L4;
    }

    /* "pysam/calignedsegment.pyx":149
 *         elif isinstance(value, float):
 *             typecode = 'd'
 *         elif isinstance(value, str):             # <<<<<<<<<<<<<<
 *             typecode = 'Z'
 *         elif isinstance(value, bytes):
 */
    __pyx_t_2 = PyString_Check(__pyx_v_value); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":150
 *             typecode = 'd'
 *         elif isinstance(value, str):
 *             typecode = 'Z'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, bytes):
 *             typecode = 'Z'
 */
      __pyx_v_typecode = 'Z';

      /* "pysam/calignedsegment.pyx":149
 *         elif isinstance(value, float):
 *             typecode = 'd'
 *         elif isinstance(value, str):             # <<<<<<<<<<<<<<
 *             typecode = 'Z'
 *         elif isinstance(value, bytes):
 */
      goto __pyx_L4;
    }

    /* "pysam/calignedsegment.pyx":151
 *         elif isinstance(value, str):
 *             typecode = 'Z'
 *         elif isinstance(value, bytes):             # <<<<<<<<<<<<<<
 *             typecode = 'Z'
 *         elif isinstance(value, array.array) or \
 */
    __pyx_t_1 = PyBytes_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":152
 *             typecode = 'Z'
 *         elif isinstance(value, bytes):
 *             typecode = 'Z'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, array.array) or \
 *                 isinstance(value, list) or \
 */
      __pyx_v_typecode = 'Z';

      /* "pysam/calignedsegment.pyx":151
 *         elif isinstance(value, str):
 *             typecode = 'Z'
 *         elif isinstance(value, bytes):             # <<<<<<<<<<<<<<
 *             typecode = 'Z'
 *         elif isinstance(value, array.array) or \
 */
      goto __pyx_L4;
    }

    /* "pysam/calignedsegment.pyx":153
 *         elif isinstance(value, bytes):
 *             typecode = 'Z'
 *         elif isinstance(value, array.array) or \             # <<<<<<<<<<<<<<
 *                 isinstance(value, list) or \
 *                 isinstance(value, tuple):
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = PyObject_IsInstance(__pyx_v_value, __pyx_t_4); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = (__pyx_t_1 != 0);
    if (!__pyx_t_5) {
    } else {
      __pyx_t_2 = __pyx_t_5;
      goto __pyx_L5_bool_binop_done;
    }

    /* "pysam/calignedsegment.pyx":154
 *             typecode = 'Z'
 *         elif isinstance(value, array.array) or \
 *                 isinstance(value, list) or \             # <<<<<<<<<<<<<<
 *                 isinstance(value, tuple):
 *             typecode = 'B'
 */
    __pyx_t_5 = PyList_Check(__pyx_v_value); 
    __pyx_t_1 = (__pyx_t_5 != 0);
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L5_bool_binop_done;
    }

    /* "pysam/calignedsegment.pyx":155
 *         elif isinstance(value, array.array) or \
 *                 isinstance(value, list) or \
 *                 isinstance(value, tuple):             # <<<<<<<<<<<<<<
 *             typecode = 'B'
 *         else:
 */
    __pyx_t_1 = PyTuple_Check(__pyx_v_value); 
    __pyx_t_5 = (__pyx_t_1 != 0);
    __pyx_t_2 = __pyx_t_5;
    __pyx_L5_bool_binop_done:;

    /* "pysam/calignedsegment.pyx":153
 *         elif isinstance(value, bytes):
 *             typecode = 'Z'
 *         elif isinstance(value, array.array) or \             # <<<<<<<<<<<<<<
 *                 isinstance(value, list) or \
 *                 isinstance(value, tuple):
 */
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":156
 *                 isinstance(value, list) or \
 *                 isinstance(value, tuple):
 *             typecode = 'B'             # <<<<<<<<<<<<<<
 *         else:
 *             return 0
 */
      __pyx_v_typecode = 'B';

      /* "pysam/calignedsegment.pyx":153
 *         elif isinstance(value, bytes):
 *             typecode = 'Z'
 *         elif isinstance(value, array.array) or \             # <<<<<<<<<<<<<<
 *                 isinstance(value, list) or \
 *                 isinstance(value, tuple):
 */
      goto __pyx_L4;
    }

    /* "pysam/calignedsegment.pyx":158
 *             typecode = 'B'
 *         else:
 *             return 0             # <<<<<<<<<<<<<<
 *     else:
 *         if value_type not in 'Zidf':
 */
    /*else*/ {
      __pyx_r = 0;
      goto __pyx_L0;
    }
    __pyx_L4:;

    /* "pysam/calignedsegment.pyx":144
 *     cdef char * _char_type
 * 
 *     if value_type is None:             # <<<<<<<<<<<<<<
 *         if isinstance(value, int):
 *             typecode = 'i'
 */
    goto __pyx_L3;
  }

  /* "pysam/calignedsegment.pyx":160
 *             return 0
 *     else:
 *         if value_type not in 'Zidf':             # <<<<<<<<<<<<<<
 *             return 0
 *         value_type = force_bytes(value_type)
 */
  /*else*/ {
    __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_value_type, __pyx_n_s_Zidf, Py_NE)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = (__pyx_t_2 != 0);
    if (__pyx_t_5) {

      /* "pysam/calignedsegment.pyx":161
 *     else:
 *         if value_type not in 'Zidf':
 *             return 0             # <<<<<<<<<<<<<<
 *         value_type = force_bytes(value_type)
 *         _char_type = value_type
 */
      __pyx_r = 0;
      goto __pyx_L0;

      /* "pysam/calignedsegment.pyx":160
 *             return 0
 *     else:
 *         if value_type not in 'Zidf':             # <<<<<<<<<<<<<<
 *             return 0
 *         value_type = force_bytes(value_type)
 */
    }

    /* "pysam/calignedsegment.pyx":162
 *         if value_type not in 'Zidf':
 *             return 0
 *         value_type = force_bytes(value_type)             # <<<<<<<<<<<<<<
 *         _char_type = value_type
 *         typecode = (<uint8_t*>_char_type)[0]
 */
    __pyx_t_4 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_value_type, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF_SET(__pyx_v_value_type, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pysam/calignedsegment.pyx":163
 *             return 0
 *         value_type = force_bytes(value_type)
 *         _char_type = value_type             # <<<<<<<<<<<<<<
 *         typecode = (<uint8_t*>_char_type)[0]
 * 
 */
    __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_value_type); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v__char_type = __pyx_t_6;

    /* "pysam/calignedsegment.pyx":164
 *         value_type = force_bytes(value_type)
 *         _char_type = value_type
 *         typecode = (<uint8_t*>_char_type)[0]             # <<<<<<<<<<<<<<
 * 
 *     return typecode
 */
    __pyx_v_typecode = (((uint8_t *)__pyx_v__char_type)[0]);
  }
  __pyx_L3:;

  /* "pysam/calignedsegment.pyx":166
 *         typecode = (<uint8_t*>_char_type)[0]
 * 
 *     return typecode             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_typecode;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":137
 * 
 * 
 * cdef inline uint8_t get_value_code(value, value_type=None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("pysam.calignedsegment.get_value_code", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_value_type);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":169
 * 
 * 
 * cdef inline bytes getTypecode(value, maximum_value=None):             # <<<<<<<<<<<<<<
 *     '''returns the value typecode of a value.
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_getTypecode(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_15calignedsegment_getTypecode *__pyx_optional_args) {
  PyObject *__pyx_v_maximum_value = ((PyObject *)Py_None);
  PyObject *__pyx_v_valuetype = 0;
  PyTypeObject *__pyx_v_t = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getTypecode", 0);
  __Pyx_TraceCall("getTypecode", __pyx_f[0], 169, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_maximum_value = __pyx_optional_args->maximum_value;
    }
  }
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_INCREF(__pyx_v_maximum_value);

  /* "pysam/calignedsegment.pyx":176
 *     '''
 * 
 *     if maximum_value is None:             # <<<<<<<<<<<<<<
 *         maximum_value = value
 * 
 */
  __pyx_t_1 = (__pyx_v_maximum_value == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":177
 * 
 *     if maximum_value is None:
 *         maximum_value = value             # <<<<<<<<<<<<<<
 * 
 *     cdef bytes valuetype
 */
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_DECREF_SET(__pyx_v_maximum_value, __pyx_v_value);

    /* "pysam/calignedsegment.pyx":176
 *     '''
 * 
 *     if maximum_value is None:             # <<<<<<<<<<<<<<
 *         maximum_value = value
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":181
 *     cdef bytes valuetype
 * 
 *     t = type(value)             # <<<<<<<<<<<<<<
 * 
 *     if t is float:
 */
  __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
  __pyx_v_t = ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_value)));

  /* "pysam/calignedsegment.pyx":183
 *     t = type(value)
 * 
 *     if t is float:             # <<<<<<<<<<<<<<
 *         valuetype = b'f'
 *     elif t is int:
 */
  __pyx_t_2 = (__pyx_v_t == (&PyFloat_Type));
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":184
 * 
 *     if t is float:
 *         valuetype = b'f'             # <<<<<<<<<<<<<<
 *     elif t is int:
 *         # signed ints
 */
    __Pyx_INCREF(__pyx_n_b_f);
    __pyx_v_valuetype = __pyx_n_b_f;

    /* "pysam/calignedsegment.pyx":183
 *     t = type(value)
 * 
 *     if t is float:             # <<<<<<<<<<<<<<
 *         valuetype = b'f'
 *     elif t is int:
 */
    goto __pyx_L4;
  }

  /* "pysam/calignedsegment.pyx":185
 *     if t is float:
 *         valuetype = b'f'
 *     elif t is int:             # <<<<<<<<<<<<<<
 *         # signed ints
 *         if value < 0:
 */
  __pyx_t_1 = (__pyx_v_t == (&PyInt_Type));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":187
 *     elif t is int:
 *         # signed ints
 *         if value < 0:             # <<<<<<<<<<<<<<
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'
 */
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":188
 *         # signed ints
 *         if value < 0:
 *             if value >= -128 and maximum_value < 128:             # <<<<<<<<<<<<<<
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_128, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_1) {
      } else {
        __pyx_t_2 = __pyx_t_1;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_128, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __pyx_t_1;
      __pyx_L7_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":189
 *         if value < 0:
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'             # <<<<<<<<<<<<<<
 *             elif value >= -32768 and maximum_value < 32768:
 *                 valuetype = b's'
 */
        __Pyx_INCREF(__pyx_n_b_c);
        __pyx_v_valuetype = __pyx_n_b_c;

        /* "pysam/calignedsegment.pyx":188
 *         # signed ints
 *         if value < 0:
 *             if value >= -128 and maximum_value < 128:             # <<<<<<<<<<<<<<
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:
 */
        goto __pyx_L6;
      }

      /* "pysam/calignedsegment.pyx":190
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:             # <<<<<<<<<<<<<<
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32768, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_1) {
      } else {
        __pyx_t_2 = __pyx_t_1;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_32768, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __pyx_t_1;
      __pyx_L9_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":191
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:
 *                 valuetype = b's'             # <<<<<<<<<<<<<<
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 *                 raise ValueError(
 */
        __Pyx_INCREF(__pyx_n_b_s);
        __pyx_v_valuetype = __pyx_n_b_s;

        /* "pysam/calignedsegment.pyx":190
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:             # <<<<<<<<<<<<<<
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 */
        goto __pyx_L6;
      }

      /* "pysam/calignedsegment.pyx":192
 *             elif value >= -32768 and maximum_value < 32768:
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "at least one signed integer out of range of "
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_1) {
      } else {
        __pyx_t_2 = __pyx_t_1;
        goto __pyx_L11_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_2147483648, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __pyx_t_1;
      __pyx_L11_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":193
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one signed integer out of range of "
 *                     "BAM/SAM specification")
 */
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/calignedsegment.pyx":192
 *             elif value >= -32768 and maximum_value < 32768:
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "at least one signed integer out of range of "
 */
      }

      /* "pysam/calignedsegment.pyx":197
 *                     "BAM/SAM specification")
 *             else:
 *                 valuetype = b'i'             # <<<<<<<<<<<<<<
 *         # unsigned ints
 *         else:
 */
      /*else*/ {
        __Pyx_INCREF(__pyx_n_b_i);
        __pyx_v_valuetype = __pyx_n_b_i;
      }
      __pyx_L6:;

      /* "pysam/calignedsegment.pyx":187
 *     elif t is int:
 *         # signed ints
 *         if value < 0:             # <<<<<<<<<<<<<<
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'
 */
      goto __pyx_L5;
    }

    /* "pysam/calignedsegment.pyx":200
 *         # unsigned ints
 *         else:
 *             if maximum_value < 256:             # <<<<<<<<<<<<<<
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:
 */
    /*else*/ {
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_256, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":201
 *         else:
 *             if maximum_value < 256:
 *                 valuetype = b'C'             # <<<<<<<<<<<<<<
 *             elif maximum_value < 65536:
 *                 valuetype = b'S'
 */
        __Pyx_INCREF(__pyx_n_b_C);
        __pyx_v_valuetype = __pyx_n_b_C;

        /* "pysam/calignedsegment.pyx":200
 *         # unsigned ints
 *         else:
 *             if maximum_value < 256:             # <<<<<<<<<<<<<<
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:
 */
        goto __pyx_L13;
      }

      /* "pysam/calignedsegment.pyx":202
 *             if maximum_value < 256:
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:             # <<<<<<<<<<<<<<
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_65536, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":203
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:
 *                 valuetype = b'S'             # <<<<<<<<<<<<<<
 *             elif maximum_value >= 4294967296:
 *                 raise ValueError(
 */
        __Pyx_INCREF(__pyx_n_b_S);
        __pyx_v_valuetype = __pyx_n_b_S;

        /* "pysam/calignedsegment.pyx":202
 *             if maximum_value < 256:
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:             # <<<<<<<<<<<<<<
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:
 */
        goto __pyx_L13;
      }

      /* "pysam/calignedsegment.pyx":204
 *             elif maximum_value < 65536:
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "at least one integer out of range of BAM/SAM specification")
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_4294967296, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":205
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one integer out of range of BAM/SAM specification")
 *             else:
 */
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/calignedsegment.pyx":204
 *             elif maximum_value < 65536:
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "at least one integer out of range of BAM/SAM specification")
 */
      }

      /* "pysam/calignedsegment.pyx":208
 *                     "at least one integer out of range of BAM/SAM specification")
 *             else:
 *                 valuetype = b'I'             # <<<<<<<<<<<<<<
 *     else:
 *         # Note: hex strings (H) are not supported yet
 */
      /*else*/ {
        __Pyx_INCREF(__pyx_n_b_I);
        __pyx_v_valuetype = __pyx_n_b_I;
      }
      __pyx_L13:;
    }
    __pyx_L5:;

    /* "pysam/calignedsegment.pyx":185
 *     if t is float:
 *         valuetype = b'f'
 *     elif t is int:             # <<<<<<<<<<<<<<
 *         # signed ints
 *         if value < 0:
 */
    goto __pyx_L4;
  }

  /* "pysam/calignedsegment.pyx":211
 *     else:
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:             # <<<<<<<<<<<<<<
 *             value = value.encode('ascii')
 *         if len(value) == 1:
 */
  /*else*/ {
    __pyx_t_2 = (__pyx_v_t != (&PyBytes_Type));
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":212
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:
 *             value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *         if len(value) == 1:
 *             valuetype = b'A'
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysam/calignedsegment.pyx":211
 *     else:
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:             # <<<<<<<<<<<<<<
 *             value = value.encode('ascii')
 *         if len(value) == 1:
 */
    }

    /* "pysam/calignedsegment.pyx":213
 *         if t is not bytes:
 *             value = value.encode('ascii')
 *         if len(value) == 1:             # <<<<<<<<<<<<<<
 *             valuetype = b'A'
 *         else:
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = ((__pyx_t_5 == 1) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":214
 *             value = value.encode('ascii')
 *         if len(value) == 1:
 *             valuetype = b'A'             # <<<<<<<<<<<<<<
 *         else:
 *             valuetype = b'Z'
 */
      __Pyx_INCREF(__pyx_n_b_A);
      __pyx_v_valuetype = __pyx_n_b_A;

      /* "pysam/calignedsegment.pyx":213
 *         if t is not bytes:
 *             value = value.encode('ascii')
 *         if len(value) == 1:             # <<<<<<<<<<<<<<
 *             valuetype = b'A'
 *         else:
 */
      goto __pyx_L15;
    }

    /* "pysam/calignedsegment.pyx":216
 *             valuetype = b'A'
 *         else:
 *             valuetype = b'Z'             # <<<<<<<<<<<<<<
 * 
 *     return valuetype
 */
    /*else*/ {
      __Pyx_INCREF(__pyx_n_b_Z);
      __pyx_v_valuetype = __pyx_n_b_Z;
    }
    __pyx_L15:;
  }
  __pyx_L4:;

  /* "pysam/calignedsegment.pyx":218
 *             valuetype = b'Z'
 * 
 *     return valuetype             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_valuetype);
  __pyx_r = __pyx_v_valuetype;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":169
 * 
 * 
 * cdef inline bytes getTypecode(value, maximum_value=None):             # <<<<<<<<<<<<<<
 *     '''returns the value typecode of a value.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignedsegment.getTypecode", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_valuetype);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_maximum_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":221
 * 
 * 
 * cdef inline packTags(tags):             # <<<<<<<<<<<<<<
 *     """pack a list of tags. Each tag is a tuple of (tag, tuple).
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_packTags(PyObject *__pyx_v_tags) {
  PyObject *__pyx_v_fmts = NULL;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_v_datatype2format = NULL;
  PyObject *__pyx_v_tag = NULL;
  PyObject *__pyx_v_pytag = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_valuetype = NULL;
  PyTypeObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_datafmt = 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 *);
  Py_ssize_t __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_t_12;
  struct __pyx_opt_args_5pysam_15calignedsegment_getTypecode __pyx_t_13;
  int __pyx_t_14;
  long __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("packTags", 0);
  __Pyx_TraceCall("packTags", __pyx_f[0], 221, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":230
 *     to be used in a call to struct.pack_into.
 *     """
 *     fmts, args = ["<"], []             # <<<<<<<<<<<<<<
 * 
 *     datatype2format = {
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_kp_s__4);
  __Pyx_GIVEREF(__pyx_kp_s__4);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s__4);
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_fmts = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_args = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":233
 * 
 *     datatype2format = {
 *         b'c': ('b', 1),             # <<<<<<<<<<<<<<
 *         b'C': ('B', 1),
 *         b's': ('h', 2),
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_c, __pyx_tuple__5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":234
 *     datatype2format = {
 *         b'c': ('b', 1),
 *         b'C': ('B', 1),             # <<<<<<<<<<<<<<
 *         b's': ('h', 2),
 *         b'S': ('H', 2),
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_C, __pyx_tuple__6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":235
 *         b'c': ('b', 1),
 *         b'C': ('B', 1),
 *         b's': ('h', 2),             # <<<<<<<<<<<<<<
 *         b'S': ('H', 2),
 *         b'i': ('i', 4),
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_s, __pyx_tuple__7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":236
 *         b'C': ('B', 1),
 *         b's': ('h', 2),
 *         b'S': ('H', 2),             # <<<<<<<<<<<<<<
 *         b'i': ('i', 4),
 *         b'I': ('I', 4),
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_S, __pyx_tuple__8) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":237
 *         b's': ('h', 2),
 *         b'S': ('H', 2),
 *         b'i': ('i', 4),             # <<<<<<<<<<<<<<
 *         b'I': ('I', 4),
 *         b'f': ('f', 4),
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_i, __pyx_tuple__9) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":238
 *         b'S': ('H', 2),
 *         b'i': ('i', 4),
 *         b'I': ('I', 4),             # <<<<<<<<<<<<<<
 *         b'f': ('f', 4),
 *         b'A': ('c', 1)}
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_I, __pyx_tuple__10) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":239
 *         b'i': ('i', 4),
 *         b'I': ('I', 4),
 *         b'f': ('f', 4),             # <<<<<<<<<<<<<<
 *         b'A': ('c', 1)}
 * 
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_f, __pyx_tuple__11) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":240
 *         b'I': ('I', 4),
 *         b'f': ('f', 4),
 *         b'A': ('c', 1)}             # <<<<<<<<<<<<<<
 * 
 *     for tag in tags:
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_b_A, __pyx_tuple__12) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_datatype2format = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":242
 *         b'A': ('c', 1)}
 * 
 *     for tag in tags:             # <<<<<<<<<<<<<<
 * 
 *         if len(tag) == 2:
 */
  if (likely(PyList_CheckExact(__pyx_v_tags)) || PyTuple_CheckExact(__pyx_v_tags)) {
    __pyx_t_2 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __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_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __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_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __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(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_tag, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/calignedsegment.pyx":244
 *     for tag in tags:
 * 
 *         if len(tag) == 2:             # <<<<<<<<<<<<<<
 *             pytag, value = tag
 *             valuetype = None
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = ((__pyx_t_5 == 2) != 0);
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":245
 * 
 *         if len(tag) == 2:
 *             pytag, value = tag             # <<<<<<<<<<<<<<
 *             valuetype = None
 *         elif len(tag) == 3:
 */
      if ((likely(PyTuple_CheckExact(__pyx_v_tag))) || (PyList_CheckExact(__pyx_v_tag))) {
        PyObject* sequence = __pyx_v_tag;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        Py_ssize_t index = -1;
        __pyx_t_8 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
        index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_pytag, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/calignedsegment.pyx":246
 *         if len(tag) == 2:
 *             pytag, value = tag
 *             valuetype = None             # <<<<<<<<<<<<<<
 *         elif len(tag) == 3:
 *             pytag, value, valuetype = tag
 */
      __Pyx_INCREF(Py_None);
      __Pyx_XDECREF_SET(__pyx_v_valuetype, Py_None);

      /* "pysam/calignedsegment.pyx":244
 *     for tag in tags:
 * 
 *         if len(tag) == 2:             # <<<<<<<<<<<<<<
 *             pytag, value = tag
 *             valuetype = None
 */
      goto __pyx_L5;
    }

    /* "pysam/calignedsegment.pyx":247
 *             pytag, value = tag
 *             valuetype = None
 *         elif len(tag) == 3:             # <<<<<<<<<<<<<<
 *             pytag, value, valuetype = tag
 *         else:
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = ((__pyx_t_5 == 3) != 0);
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":248
 *             valuetype = None
 *         elif len(tag) == 3:
 *             pytag, value, valuetype = tag             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("malformatted tag: %s" % str(tag))
 */
      if ((likely(PyTuple_CheckExact(__pyx_v_tag))) || (PyList_CheckExact(__pyx_v_tag))) {
        PyObject* sequence = __pyx_v_tag;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 3)) {
          if (size > 3) __Pyx_RaiseTooManyValuesError(3);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); 
        } else {
          __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_8 = PyList_GET_ITEM(sequence, 2); 
        }
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_8);
        #else
        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        #endif
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = Py_TYPE(__pyx_t_10)->tp_iternext;
        index = 0; __pyx_t_7 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_7)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        index = 1; __pyx_t_1 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_1)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        index = 2; __pyx_t_8 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_10), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L9_unpacking_done;
        __pyx_L8_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L9_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_pytag, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_valuetype, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "pysam/calignedsegment.pyx":247
 *             pytag, value = tag
 *             valuetype = None
 *         elif len(tag) == 3:             # <<<<<<<<<<<<<<
 *             pytag, value, valuetype = tag
 *         else:
 */
      goto __pyx_L5;
    }

    /* "pysam/calignedsegment.pyx":250
 *             pytag, value, valuetype = tag
 *         else:
 *             raise ValueError("malformatted tag: %s" % str(tag))             # <<<<<<<<<<<<<<
 * 
 *         pytag = force_bytes(pytag)
 */
    /*else*/ {
      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_tag);
      __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyString_Type)), __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_malformatted_tag_s, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L5:;

    /* "pysam/calignedsegment.pyx":252
 *             raise ValueError("malformatted tag: %s" % str(tag))
 * 
 *         pytag = force_bytes(pytag)             # <<<<<<<<<<<<<<
 *         valuetype = force_bytes(valuetype)
 *         t = type(value)
 */
    __pyx_t_8 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_pytag, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF_SET(__pyx_v_pytag, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "pysam/calignedsegment.pyx":253
 * 
 *         pytag = force_bytes(pytag)
 *         valuetype = force_bytes(valuetype)             # <<<<<<<<<<<<<<
 *         t = type(value)
 * 
 */
    __pyx_t_8 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_valuetype, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "pysam/calignedsegment.pyx":254
 *         pytag = force_bytes(pytag)
 *         valuetype = force_bytes(valuetype)
 *         t = type(value)             # <<<<<<<<<<<<<<
 * 
 *         if t is tuple or t is list:
 */
    __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
    __Pyx_XDECREF_SET(__pyx_v_t, ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_value))));

    /* "pysam/calignedsegment.pyx":256
 *         t = type(value)
 * 
 *         if t is tuple or t is list:             # <<<<<<<<<<<<<<
 *             # binary tags from tuples or lists
 *             if valuetype is None:
 */
    __pyx_t_11 = (__pyx_v_t == (&PyTuple_Type));
    __pyx_t_12 = (__pyx_t_11 != 0);
    if (!__pyx_t_12) {
    } else {
      __pyx_t_6 = __pyx_t_12;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_12 = (__pyx_v_t == (&PyList_Type));
    __pyx_t_11 = (__pyx_t_12 != 0);
    __pyx_t_6 = __pyx_t_11;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":258
 *         if t is tuple or t is list:
 *             # binary tags from tuples or lists
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 # automatically determine value type - first value
 *                 # determines type. If there is a mix of types, the
 */
      __pyx_t_6 = (__pyx_v_valuetype == Py_None);
      __pyx_t_11 = (__pyx_t_6 != 0);
      if (__pyx_t_11) {

        /* "pysam/calignedsegment.pyx":262
 *                 # determines type. If there is a mix of types, the
 *                 # result is undefined.
 *                 valuetype = getTypecode(min(value), max(value))             # <<<<<<<<<<<<<<
 * 
 *             if valuetype not in datatype2format:
 */
        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_value);
        __Pyx_GIVEREF(__pyx_v_value);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_value);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_v_value);
        __Pyx_GIVEREF(__pyx_v_value);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_value);
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_13.__pyx_n = 1;
        __pyx_t_13.maximum_value = __pyx_t_7;
        __pyx_t_8 = __pyx_f_5pysam_15calignedsegment_getTypecode(__pyx_t_1, &__pyx_t_13); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "pysam/calignedsegment.pyx":258
 *         if t is tuple or t is list:
 *             # binary tags from tuples or lists
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 # automatically determine value type - first value
 *                 # determines type. If there is a mix of types, the
 */
      }

      /* "pysam/calignedsegment.pyx":264
 *                 valuetype = getTypecode(min(value), max(value))
 * 
 *             if valuetype not in datatype2format:             # <<<<<<<<<<<<<<
 *                 raise ValueError("invalid value type '%s'" % valuetype)
 * 
 */
      __pyx_t_11 = (__Pyx_PyDict_ContainsTF(__pyx_v_valuetype, __pyx_v_datatype2format, Py_NE)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_6 = (__pyx_t_11 != 0);
      if (__pyx_t_6) {

        /* "pysam/calignedsegment.pyx":265
 * 
 *             if valuetype not in datatype2format:
 *                 raise ValueError("invalid value type '%s'" % valuetype)             # <<<<<<<<<<<<<<
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0])
 */
        __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_invalid_value_type_s, __pyx_v_valuetype); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_8, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/calignedsegment.pyx":264
 *                 valuetype = getTypecode(min(value), max(value))
 * 
 *             if valuetype not in datatype2format:             # <<<<<<<<<<<<<<
 *                 raise ValueError("invalid value type '%s'" % valuetype)
 * 
 */
      }

      /* "pysam/calignedsegment.pyx":267
 *                 raise ValueError("invalid value type '%s'" % valuetype)
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0])             # <<<<<<<<<<<<<<
 *             args.extend([pytag[:2],
 *                          b"B",
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_7, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
      __pyx_t_8 = 0;
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_2sccI_i_s, __pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/calignedsegment.pyx":268
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0])
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__13, 0, 1, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);

      /* "pysam/calignedsegment.pyx":271
 *                          b"B",
 *                          valuetype,
 *                          len(value)] + list(value))             # <<<<<<<<<<<<<<
 * 
 *         elif isinstance(value, array.array):
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);

      /* "pysam/calignedsegment.pyx":268
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0])
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_8 = PyList_New(4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
      __Pyx_INCREF(__pyx_n_b_B);
      __Pyx_GIVEREF(__pyx_n_b_B);
      PyList_SET_ITEM(__pyx_t_8, 1, __pyx_n_b_B);
      __Pyx_INCREF(__pyx_v_valuetype);
      __Pyx_GIVEREF(__pyx_v_valuetype);
      PyList_SET_ITEM(__pyx_t_8, 2, __pyx_v_valuetype);
      __Pyx_GIVEREF(__pyx_t_7);
      PyList_SET_ITEM(__pyx_t_8, 3, __pyx_t_7);
      __pyx_t_1 = 0;
      __pyx_t_7 = 0;

      /* "pysam/calignedsegment.pyx":271
 *                          b"B",
 *                          valuetype,
 *                          len(value)] + list(value))             # <<<<<<<<<<<<<<
 * 
 *         elif isinstance(value, array.array):
 */
      __pyx_t_7 = PySequence_List(__pyx_v_value); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = PyNumber_Add(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/calignedsegment.pyx":268
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0])
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_14 = __Pyx_PyList_Extend(__pyx_v_args, __pyx_t_1); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "pysam/calignedsegment.pyx":256
 *         t = type(value)
 * 
 *         if t is tuple or t is list:             # <<<<<<<<<<<<<<
 *             # binary tags from tuples or lists
 *             if valuetype is None:
 */
      goto __pyx_L10;
    }

    /* "pysam/calignedsegment.pyx":273
 *                          len(value)] + list(value))
 * 
 *         elif isinstance(value, array.array):             # <<<<<<<<<<<<<<
 *             # binary tags from arrays
 *             if valuetype is None:
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = PyObject_IsInstance(__pyx_v_value, __pyx_t_7); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 273; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_11 = (__pyx_t_6 != 0);
    if (__pyx_t_11) {

      /* "pysam/calignedsegment.pyx":275
 *         elif isinstance(value, array.array):
 *             # binary tags from arrays
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 valuetype = force_bytes(chr(
 *                     map_typecode_python_to_htslib(ord(value.typecode))))
 */
      __pyx_t_11 = (__pyx_v_valuetype == Py_None);
      __pyx_t_6 = (__pyx_t_11 != 0);
      if (__pyx_t_6) {

        /* "pysam/calignedsegment.pyx":277
 *             if valuetype is None:
 *                 valuetype = force_bytes(chr(
 *                     map_typecode_python_to_htslib(ord(value.typecode))))             # <<<<<<<<<<<<<<
 * 
 *             if valuetype not in datatype2format:
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_typecode); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_15 = __Pyx_PyObject_Ord(__pyx_t_7); if (unlikely(__pyx_t_15 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyInt_From_uint8_t(__pyx_f_5pysam_15calignedsegment_map_typecode_python_to_htslib(__pyx_t_15)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);

        /* "pysam/calignedsegment.pyx":276
 *             # binary tags from arrays
 *             if valuetype is None:
 *                 valuetype = force_bytes(chr(             # <<<<<<<<<<<<<<
 *                     map_typecode_python_to_htslib(ord(value.typecode))))
 * 
 */
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
        __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "pysam/calignedsegment.pyx":275
 *         elif isinstance(value, array.array):
 *             # binary tags from arrays
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 valuetype = force_bytes(chr(
 *                     map_typecode_python_to_htslib(ord(value.typecode))))
 */
      }

      /* "pysam/calignedsegment.pyx":279
 *                     map_typecode_python_to_htslib(ord(value.typecode))))
 * 
 *             if valuetype not in datatype2format:             # <<<<<<<<<<<<<<
 *                 raise ValueError("invalid value type '%s' (%s)" %
 *                                  (valuetype, type(valuetype)))
 */
      __pyx_t_6 = (__Pyx_PyDict_ContainsTF(__pyx_v_valuetype, __pyx_v_datatype2format, Py_NE)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = (__pyx_t_6 != 0);
      if (__pyx_t_11) {

        /* "pysam/calignedsegment.pyx":281
 *             if valuetype not in datatype2format:
 *                 raise ValueError("invalid value type '%s' (%s)" %
 *                                  (valuetype, type(valuetype)))             # <<<<<<<<<<<<<<
 * 
 *             # use array.tostring() to retrieve byte representation and
 */
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_valuetype);
        __Pyx_GIVEREF(__pyx_v_valuetype);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_valuetype);
        __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_valuetype)));
        __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_valuetype)));
        PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)Py_TYPE(__pyx_v_valuetype)));

        /* "pysam/calignedsegment.pyx":280
 * 
 *             if valuetype not in datatype2format:
 *                 raise ValueError("invalid value type '%s' (%s)" %             # <<<<<<<<<<<<<<
 *                                  (valuetype, type(valuetype)))
 * 
 */
        __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_invalid_value_type_s_s, __pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
        __pyx_t_7 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_Raise(__pyx_t_7, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/calignedsegment.pyx":279
 *                     map_typecode_python_to_htslib(ord(value.typecode))))
 * 
 *             if valuetype not in datatype2format:             # <<<<<<<<<<<<<<
 *                 raise ValueError("invalid value type '%s' (%s)" %
 *                                  (valuetype, type(valuetype)))
 */
      }

      /* "pysam/calignedsegment.pyx":285
 *             # use array.tostring() to retrieve byte representation and
 *             # save as bytes
 *             datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1])             # <<<<<<<<<<<<<<
 *             args.extend([pytag[:2],
 *                          b"B",
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Multiply(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_2sccI_is, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "pysam/calignedsegment.pyx":286
 *             # save as bytes
 *             datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1])
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__14, 0, 1, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);

      /* "pysam/calignedsegment.pyx":289
 *                          b"B",
 *                          valuetype,
 *                          len(value),             # <<<<<<<<<<<<<<
 *                          force_bytes(value.tostring())])
 * 
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);

      /* "pysam/calignedsegment.pyx":290
 *                          valuetype,
 *                          len(value),
 *                          force_bytes(value.tostring())])             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_tostring); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_16 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_16)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_16);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
        }
      }
      if (__pyx_t_16) {
        __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_16); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else {
        __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_t_7, NULL); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/calignedsegment.pyx":286
 *             # save as bytes
 *             datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1])
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_7 = PyList_New(5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_8);
      PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
      __Pyx_INCREF(__pyx_n_b_B);
      __Pyx_GIVEREF(__pyx_n_b_B);
      PyList_SET_ITEM(__pyx_t_7, 1, __pyx_n_b_B);
      __Pyx_INCREF(__pyx_v_valuetype);
      __Pyx_GIVEREF(__pyx_v_valuetype);
      PyList_SET_ITEM(__pyx_t_7, 2, __pyx_v_valuetype);
      __Pyx_GIVEREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_7, 3, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_10);
      PyList_SET_ITEM(__pyx_t_7, 4, __pyx_t_10);
      __pyx_t_8 = 0;
      __pyx_t_1 = 0;
      __pyx_t_10 = 0;
      __pyx_t_14 = __Pyx_PyList_Extend(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/calignedsegment.pyx":273
 *                          len(value)] + list(value))
 * 
 *         elif isinstance(value, array.array):             # <<<<<<<<<<<<<<
 *             # binary tags from arrays
 *             if valuetype is None:
 */
      goto __pyx_L10;
    }

    /* "pysam/calignedsegment.pyx":293
 * 
 *         else:
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 valuetype = getTypecode(value)
 * 
 */
    /*else*/ {
      __pyx_t_11 = (__pyx_v_valuetype == Py_None);
      __pyx_t_6 = (__pyx_t_11 != 0);
      if (__pyx_t_6) {

        /* "pysam/calignedsegment.pyx":294
 *         else:
 *             if valuetype is None:
 *                 valuetype = getTypecode(value)             # <<<<<<<<<<<<<<
 * 
 *             if valuetype in b"AZ":
 */
        __pyx_t_7 = __pyx_f_5pysam_15calignedsegment_getTypecode(__pyx_v_value, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "pysam/calignedsegment.pyx":293
 * 
 *         else:
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 valuetype = getTypecode(value)
 * 
 */
      }

      /* "pysam/calignedsegment.pyx":296
 *                 valuetype = getTypecode(value)
 * 
 *             if valuetype in b"AZ":             # <<<<<<<<<<<<<<
 *                 value = force_bytes(value)
 * 
 */
      __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_v_valuetype, __pyx_n_b_AZ, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = (__pyx_t_6 != 0);
      if (__pyx_t_11) {

        /* "pysam/calignedsegment.pyx":297
 * 
 *             if valuetype in b"AZ":
 *                 value = force_bytes(value)             # <<<<<<<<<<<<<<
 * 
 *             if valuetype == b"Z":
 */
        __pyx_t_7 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "pysam/calignedsegment.pyx":296
 *                 valuetype = getTypecode(value)
 * 
 *             if valuetype in b"AZ":             # <<<<<<<<<<<<<<
 *                 value = force_bytes(value)
 * 
 */
      }

      /* "pysam/calignedsegment.pyx":299
 *                 value = force_bytes(value)
 * 
 *             if valuetype == b"Z":             # <<<<<<<<<<<<<<
 *                 datafmt = "2sc%is" % (len(value)+1)
 *             else:
 */
      __pyx_t_11 = (__Pyx_PyBytes_Equals(__pyx_v_valuetype, __pyx_n_b_Z, Py_EQ)); if (unlikely(__pyx_t_11 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_11) {

        /* "pysam/calignedsegment.pyx":300
 * 
 *             if valuetype == b"Z":
 *                 datafmt = "2sc%is" % (len(value)+1)             # <<<<<<<<<<<<<<
 *             else:
 *                 datafmt = "2sc%s" % datatype2format[valuetype][0]
 */
        __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_7 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_2sc_is, __pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_10);
        __pyx_t_10 = 0;

        /* "pysam/calignedsegment.pyx":299
 *                 value = force_bytes(value)
 * 
 *             if valuetype == b"Z":             # <<<<<<<<<<<<<<
 *                 datafmt = "2sc%is" % (len(value)+1)
 *             else:
 */
        goto __pyx_L19;
      }

      /* "pysam/calignedsegment.pyx":302
 *                 datafmt = "2sc%is" % (len(value)+1)
 *             else:
 *                 datafmt = "2sc%s" % datatype2format[valuetype][0]             # <<<<<<<<<<<<<<
 * 
 *             args.extend([pytag[:2],
 */
      /*else*/ {
        __pyx_t_10 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_10, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_2sc_s, __pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF_SET(__pyx_v_datafmt, __pyx_t_10);
        __pyx_t_10 = 0;
      }
      __pyx_L19:;

      /* "pysam/calignedsegment.pyx":304
 *                 datafmt = "2sc%s" % datatype2format[valuetype][0]
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          valuetype,
 *                          value])
 */
      __pyx_t_10 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__15, 0, 1, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);

      /* "pysam/calignedsegment.pyx":306
 *             args.extend([pytag[:2],
 *                          valuetype,
 *                          value])             # <<<<<<<<<<<<<<
 * 
 *         fmts.append(datafmt)
 */
      __pyx_t_7 = PyList_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_10);
      PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_10);
      __Pyx_INCREF(__pyx_v_valuetype);
      __Pyx_GIVEREF(__pyx_v_valuetype);
      PyList_SET_ITEM(__pyx_t_7, 1, __pyx_v_valuetype);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyList_SET_ITEM(__pyx_t_7, 2, __pyx_v_value);
      __pyx_t_10 = 0;

      /* "pysam/calignedsegment.pyx":304
 *                 datafmt = "2sc%s" % datatype2format[valuetype][0]
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          valuetype,
 *                          value])
 */
      __pyx_t_14 = __Pyx_PyList_Extend(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __pyx_L10:;

    /* "pysam/calignedsegment.pyx":308
 *                          value])
 * 
 *         fmts.append(datafmt)             # <<<<<<<<<<<<<<
 * 
 *     return "".join(fmts), args
 */
    __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":242
 *         b'A': ('c', 1)}
 * 
 *     for tag in tags:             # <<<<<<<<<<<<<<
 * 
 *         if len(tag) == 2:
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":310
 *         fmts.append(datafmt)
 * 
 *     return "".join(fmts), args             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_v_fmts); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_args);
  __pyx_t_2 = 0;
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":221
 * 
 * 
 * cdef inline packTags(tags):             # <<<<<<<<<<<<<<
 *     """pack a list of tags. Each tag is a tuple of (tag, tuple).
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("pysam.calignedsegment.packTags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fmts);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_datatype2format);
  __Pyx_XDECREF(__pyx_v_tag);
  __Pyx_XDECREF(__pyx_v_pytag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_valuetype);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_datafmt);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":313
 * 
 * 
 * cdef inline int32_t calculateQueryLength(bam1_t * src):             # <<<<<<<<<<<<<<
 *     """return query length computed from CIGAR alignment.
 * 
 */

static CYTHON_INLINE int32_t __pyx_f_5pysam_15calignedsegment_calculateQueryLength(bam1_t *__pyx_v_src) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_qpos;
  int __pyx_v_op;
  int32_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  uint16_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("calculateQueryLength", 0);
  __Pyx_TraceCall("calculateQueryLength", __pyx_f[0], 313, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 313; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":319
 *     """
 * 
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *     if cigar_p == NULL:
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":321
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 * 
 *     if cigar_p == NULL:             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  __pyx_t_1 = ((__pyx_v_cigar_p == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":322
 * 
 *     if cigar_p == NULL:
 *         return 0             # <<<<<<<<<<<<<<
 * 
 *     cdef uint32_t k, qpos
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":321
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 * 
 *     if cigar_p == NULL:             # <<<<<<<<<<<<<<
 *         return 0
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":326
 *     cdef uint32_t k, qpos
 *     cdef int op
 *     qpos = 0             # <<<<<<<<<<<<<<
 * 
 *     for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_qpos = 0;

  /* "pysam/calignedsegment.pyx":328
 *     qpos = 0
 * 
 *     for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 */
  __pyx_t_2 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":329
 * 
 *     for k from 0 <= k < pysam_get_n_cigar(src):
 *         op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 * 
 *         if op == BAM_CMATCH or op == BAM_CINS or \
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":331
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 *         if op == BAM_CMATCH or op == BAM_CINS or \             # <<<<<<<<<<<<<<
 *            op == BAM_CSOFT_CLIP or \
 *            op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    __pyx_t_3 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_op == BAM_CINS) != 0);
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L7_bool_binop_done;
    }

    /* "pysam/calignedsegment.pyx":332
 * 
 *         if op == BAM_CMATCH or op == BAM_CINS or \
 *            op == BAM_CSOFT_CLIP or \             # <<<<<<<<<<<<<<
 *            op == BAM_CEQUAL or op == BAM_CDIFF:
 *             qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 */
    __pyx_t_3 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L7_bool_binop_done;
    }

    /* "pysam/calignedsegment.pyx":333
 *         if op == BAM_CMATCH or op == BAM_CINS or \
 *            op == BAM_CSOFT_CLIP or \
 *            op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *             qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_t_3 = ((__pyx_v_op == BAM_CEQUAL) != 0);
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_op == BAM_CDIFF) != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L7_bool_binop_done:;

    /* "pysam/calignedsegment.pyx":331
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 *         if op == BAM_CMATCH or op == BAM_CINS or \             # <<<<<<<<<<<<<<
 *            op == BAM_CSOFT_CLIP or \
 *            op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":334
 *            op == BAM_CSOFT_CLIP or \
 *            op == BAM_CEQUAL or op == BAM_CDIFF:
 *             qpos += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *     return qpos
 */
      __pyx_v_qpos = (__pyx_v_qpos + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));

      /* "pysam/calignedsegment.pyx":331
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 *         if op == BAM_CMATCH or op == BAM_CINS or \             # <<<<<<<<<<<<<<
 *            op == BAM_CSOFT_CLIP or \
 *            op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    }
  }

  /* "pysam/calignedsegment.pyx":336
 *             qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *     return qpos             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_qpos;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":313
 * 
 * 
 * cdef inline int32_t calculateQueryLength(bam1_t * src):             # <<<<<<<<<<<<<<
 *     """return query length computed from CIGAR alignment.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.calignedsegment.calculateQueryLength", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":339
 * 
 * 
 * cdef inline int32_t getQueryStart(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

static CYTHON_INLINE int32_t __pyx_f_5pysam_15calignedsegment_getQueryStart(bam1_t *__pyx_v_src) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_start_offset;
  int32_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  uint16_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getQueryStart", 0);
  __Pyx_TraceCall("getQueryStart", __pyx_f[0], 339, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 339; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":342
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 *     cdef uint32_t start_offset = 0             # <<<<<<<<<<<<<<
 * 
 *     if pysam_get_n_cigar(src):
 */
  __pyx_v_start_offset = 0;

  /* "pysam/calignedsegment.pyx":344
 *     cdef uint32_t start_offset = 0
 * 
 *     if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_t_1 = (pysam_get_n_cigar(__pyx_v_src) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":345
 * 
 *     if pysam_get_n_cigar(src):
 *         cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

    /* "pysam/calignedsegment.pyx":346
 *     if pysam_get_n_cigar(src):
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 */
    __pyx_t_2 = pysam_get_n_cigar(__pyx_v_src);
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) {

      /* "pysam/calignedsegment.pyx":347
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             if op == BAM_CHARD_CLIP:
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 */
      __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

      /* "pysam/calignedsegment.pyx":348
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 */
      __pyx_t_1 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignedsegment.pyx":349
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 */
        __pyx_t_3 = ((__pyx_v_start_offset != 0) != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_1 = __pyx_t_3;
          goto __pyx_L8_bool_binop_done;
        }
        __pyx_t_3 = ((__pyx_v_start_offset != __pyx_v_src->core.l_qseq) != 0);
        __pyx_t_1 = __pyx_t_3;
        __pyx_L8_bool_binop_done:;
        if (__pyx_t_1) {

          /* "pysam/calignedsegment.pyx":350
 *             if op == BAM_CHARD_CLIP:
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 */
          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_Invalid_clipping_in_CIGAR_string);

          /* "pysam/calignedsegment.pyx":351
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1             # <<<<<<<<<<<<<<
 *             elif op == BAM_CSOFT_CLIP:
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 */
          __pyx_r = -1;
          goto __pyx_L0;

          /* "pysam/calignedsegment.pyx":349
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 */
        }

        /* "pysam/calignedsegment.pyx":348
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 */
        goto __pyx_L6;
      }

      /* "pysam/calignedsegment.pyx":352
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
      __pyx_t_1 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignedsegment.pyx":353
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_start_offset = (__pyx_v_start_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));

        /* "pysam/calignedsegment.pyx":352
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
        goto __pyx_L6;
      }

      /* "pysam/calignedsegment.pyx":355
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     return start_offset
 */
      /*else*/ {
        goto __pyx_L5_break;
      }
      __pyx_L6:;
    }
    __pyx_L5_break:;

    /* "pysam/calignedsegment.pyx":344
 *     cdef uint32_t start_offset = 0
 * 
 *     if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  }

  /* "pysam/calignedsegment.pyx":357
 *                 break
 * 
 *     return start_offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_start_offset;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":339
 * 
 * 
 * cdef inline int32_t getQueryStart(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

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

/* "pysam/calignedsegment.pyx":360
 * 
 * 
 * cdef inline int32_t getQueryEnd(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

static CYTHON_INLINE int32_t __pyx_f_5pysam_15calignedsegment_getQueryEnd(bam1_t *__pyx_v_src) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_end_offset;
  int32_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getQueryEnd", 0);
  __Pyx_TraceCall("getQueryEnd", __pyx_f[0], 360, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 360; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":363
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 *     cdef uint32_t end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     # if there is no sequence, compute length from cigar string
 */
  __pyx_t_1 = __pyx_v_src->core.l_qseq;
  __pyx_v_end_offset = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":366
 * 
 *     # if there is no sequence, compute length from cigar string
 *     if end_offset == 0:             # <<<<<<<<<<<<<<
 *         end_offset = calculateQueryLength(src)
 * 
 */
  __pyx_t_2 = ((__pyx_v_end_offset == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":367
 *     # if there is no sequence, compute length from cigar string
 *     if end_offset == 0:
 *         end_offset = calculateQueryLength(src)             # <<<<<<<<<<<<<<
 * 
 *     # walk backwards in cigar string
 */
    __pyx_v_end_offset = __pyx_f_5pysam_15calignedsegment_calculateQueryLength(__pyx_v_src);

    /* "pysam/calignedsegment.pyx":366
 * 
 *     # if there is no sequence, compute length from cigar string
 *     if end_offset == 0:             # <<<<<<<<<<<<<<
 *         end_offset = calculateQueryLength(src)
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":370
 * 
 *     # walk backwards in cigar string
 *     if pysam_get_n_cigar(src) > 1:             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) > 1) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":371
 *     # walk backwards in cigar string
 *     if pysam_get_n_cigar(src) > 1:
 *         cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

    /* "pysam/calignedsegment.pyx":372
 *     if pysam_get_n_cigar(src) > 1:
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 */
    for (__pyx_v_k = pysam_get_n_cigar(__pyx_v_src)-1 + 1; __pyx_v_k >= 1 + 1; ) { __pyx_v_k--;

      /* "pysam/calignedsegment.pyx":373
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             if op == BAM_CHARD_CLIP:
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:
 */
      __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

      /* "pysam/calignedsegment.pyx":374
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError,
 */
      __pyx_t_2 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":375
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError,
 *                                     'Invalid clipping in CIGAR string')
 */
        __pyx_t_3 = ((__pyx_v_end_offset != 0) != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_2 = __pyx_t_3;
          goto __pyx_L9_bool_binop_done;
        }
        __pyx_t_3 = ((__pyx_v_end_offset != __pyx_v_src->core.l_qseq) != 0);
        __pyx_t_2 = __pyx_t_3;
        __pyx_L9_bool_binop_done:;
        if (__pyx_t_2) {

          /* "pysam/calignedsegment.pyx":376
 *             if op == BAM_CHARD_CLIP:
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError,             # <<<<<<<<<<<<<<
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1
 */
          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_Invalid_clipping_in_CIGAR_string);

          /* "pysam/calignedsegment.pyx":378
 *                     PyErr_SetString(ValueError,
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1             # <<<<<<<<<<<<<<
 *             elif op == BAM_CSOFT_CLIP:
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 */
          __pyx_r = -1;
          goto __pyx_L0;

          /* "pysam/calignedsegment.pyx":375
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError,
 *                                     'Invalid clipping in CIGAR string')
 */
        }

        /* "pysam/calignedsegment.pyx":374
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError,
 */
        goto __pyx_L7;
      }

      /* "pysam/calignedsegment.pyx":379
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
      __pyx_t_2 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
      if (__pyx_t_2) {

        /* "pysam/calignedsegment.pyx":380
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_end_offset = (__pyx_v_end_offset - ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));

        /* "pysam/calignedsegment.pyx":379
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
        goto __pyx_L7;
      }

      /* "pysam/calignedsegment.pyx":382
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     return end_offset
 */
      /*else*/ {
        goto __pyx_L6_break;
      }
      __pyx_L7:;
    }
    __pyx_L6_break:;

    /* "pysam/calignedsegment.pyx":370
 * 
 *     # walk backwards in cigar string
 *     if pysam_get_n_cigar(src) > 1:             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 */
  }

  /* "pysam/calignedsegment.pyx":384
 *                 break
 * 
 *     return end_offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_end_offset;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":360
 * 
 * 
 * cdef inline int32_t getQueryEnd(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

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

/* "pysam/calignedsegment.pyx":387
 * 
 * 
 * cdef inline bytes getSequenceInRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                      uint32_t start,
 *                                      uint32_t end):
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_getSequenceInRange(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint8_t *__pyx_v_p;
  uint32_t __pyx_v_k;
  char *__pyx_v_s;
  PyObject *__pyx_v_seq = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  uint32_t __pyx_t_4;
  char const *__pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getSequenceInRange", 0);
  __Pyx_TraceCall("getSequenceInRange", __pyx_f[0], 387, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":397
 *     cdef char * s
 * 
 *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((!(__pyx_v_src->core.l_qseq != 0)) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":398
 * 
 *     if not src.core.l_qseq:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = ((PyObject*)Py_None);
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":397
 *     cdef char * s
 * 
 *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":400
 *         return None
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)
 */
  __pyx_t_2 = PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_seq = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":401
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 *     s   = <char*>seq             # <<<<<<<<<<<<<<
 *     p   = pysam_bam_get_seq(src)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_s = ((char *)__pyx_t_3);

  /* "pysam/calignedsegment.pyx":402
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 * 
 *     for k from start <= k < end:
 */
  __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":404
 *     p   = pysam_bam_get_seq(src)
 * 
 *     for k from start <= k < end:             # <<<<<<<<<<<<<<
 *         # equivalent to seq_nt16_str[bam1_seqi(s, i)] (see bam.c)
 *         # note: do not use string literal as it will be a python string
 */
  __pyx_t_4 = __pyx_v_end;
  for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":407
 *         # equivalent to seq_nt16_str[bam1_seqi(s, i)] (see bam.c)
 *         # note: do not use string literal as it will be a python string
 *         s[k-start] = seq_nt16_str[p[k/2] >> 4 * (1 - k%2) & 0xf]             # <<<<<<<<<<<<<<
 * 
 *     return charptr_to_bytes(seq)
 */
    (__pyx_v_s[(__pyx_v_k - __pyx_v_start)]) = (seq_nt16_str[(((__pyx_v_p[__Pyx_div_long(__pyx_v_k, 2)]) >> (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))) & 0xf)]);
  }

  /* "pysam/calignedsegment.pyx":409
 *         s[k-start] = seq_nt16_str[p[k/2] >> 4 * (1 - k%2) & 0xf]
 * 
 *     return charptr_to_bytes(seq)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_f_5pysam_6cutils_charptr_to_bytes(__pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":387
 * 
 * 
 * cdef inline bytes getSequenceInRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                      uint32_t start,
 *                                      uint32_t end):
 */

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

/* "pysam/calignedsegment.pyx":412
 * 
 * 
 * cdef inline object getQualitiesInRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                        uint32_t start,
 *                                        uint32_t end):
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_getQualitiesInRange(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint8_t *__pyx_v_p;
  arrayobject *__pyx_v_result = 0;
  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;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("getQualitiesInRange", 0);
  __Pyx_TraceCall("getQualitiesInRange", __pyx_f[0], 412, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":420
 *     cdef uint32_t k
 * 
 *     p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *     if p[0] == 0xff:
 *         return None
 */
  __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":421
 * 
 *     p = pysam_bam_get_qual(src)
 *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = (((__pyx_v_p[0]) == 0xff) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":422
 *     p = pysam_bam_get_qual(src)
 *     if p[0] == 0xff:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     # 'B': unsigned char
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":421
 * 
 *     p = pysam_bam_get_qual(src)
 *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":425
 * 
 *     # 'B': unsigned char
 *     cdef c_array.array result = array.array('B', [0])             # <<<<<<<<<<<<<<
 *     c_array.resize(result, end - start)
 * 
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_array); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_array); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_int_0);
  __pyx_t_5 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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;
    }
  }
  __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (__pyx_t_5) {
    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
  }
  __Pyx_INCREF(__pyx_n_s_B);
  __Pyx_GIVEREF(__pyx_n_s_B);
  PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_n_s_B);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_7cpython_5array_array))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_result = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":426
 *     # 'B': unsigned char
 *     cdef c_array.array result = array.array('B', [0])
 *     c_array.resize(result, end - start)             # <<<<<<<<<<<<<<
 * 
 *     # copy data
 */
  __pyx_t_8 = resize(__pyx_v_result, (__pyx_v_end - __pyx_v_start)); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":429
 * 
 *     # copy data
 *     memcpy(result.data.as_voidptr, <void*>&p[start], end - start)             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
  memcpy(__pyx_v_result->data.as_voidptr, ((void *)(&(__pyx_v_p[__pyx_v_start]))), (__pyx_v_end - __pyx_v_start));

  /* "pysam/calignedsegment.pyx":431
 *     memcpy(result.data.as_voidptr, <void*>&p[start], end - start)
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":412
 * 
 * 
 * cdef inline object getQualitiesInRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                        uint32_t start,
 *                                        uint32_t end):
 */

  /* 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_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.calignedsegment.getQualitiesInRange", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":437
 * ## private factory methods
 * cdef class AlignedSegment
 * cdef makeAlignedSegment(bam1_t * src, AlignmentFile alignment_file):             # <<<<<<<<<<<<<<
 *     '''return an AlignedSegment object constructed from `src`'''
 *     # note that the following does not call __init__
 */

static PyObject *__pyx_f_5pysam_15calignedsegment_makeAlignedSegment(bam1_t *__pyx_v_src, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignment_file) {
  struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_dest = 0;
  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("makeAlignedSegment", 0);
  __Pyx_TraceCall("makeAlignedSegment", __pyx_f[0], 437, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 437; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":440
 *     '''return an AlignedSegment object constructed from `src`'''
 *     # note that the following does not call __init__
 *     cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment)             # <<<<<<<<<<<<<<
 *     dest._delegate = bam_dup1(src)
 *     dest._alignment_file = alignment_file
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_15calignedsegment_AlignedSegment(((PyTypeObject *)__pyx_ptype_5pysam_15calignedsegment_AlignedSegment), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_15calignedsegment_AlignedSegment)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":441
 *     # note that the following does not call __init__
 *     cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment)
 *     dest._delegate = bam_dup1(src)             # <<<<<<<<<<<<<<
 *     dest._alignment_file = alignment_file
 *     return dest
 */
  __pyx_v_dest->_delegate = bam_dup1(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":442
 *     cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment)
 *     dest._delegate = bam_dup1(src)
 *     dest._alignment_file = alignment_file             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_alignment_file));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alignment_file));
  __Pyx_GOTREF(__pyx_v_dest->_alignment_file);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment_file));
  __pyx_v_dest->_alignment_file = __pyx_v_alignment_file;

  /* "pysam/calignedsegment.pyx":443
 *     dest._delegate = bam_dup1(src)
 *     dest._alignment_file = alignment_file
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":437
 * ## private factory methods
 * cdef class AlignedSegment
 * cdef makeAlignedSegment(bam1_t * src, AlignmentFile alignment_file):             # <<<<<<<<<<<<<<
 *     '''return an AlignedSegment object constructed from `src`'''
 *     # note that the following does not call __init__
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.makeAlignedSegment", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":447
 * 
 * cdef class PileupColumn
 * cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos,             # <<<<<<<<<<<<<<
 *                       int n_pu, AlignmentFile alignment_file):
 *     '''return a PileupColumn object constructed from pileup in `plp` and
 */

static PyObject *__pyx_f_5pysam_15calignedsegment_makePileupColumn(bam_pileup1_t **__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n_pu, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignment_file) {
  struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_dest = 0;
  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("makePileupColumn", 0);
  __Pyx_TraceCall("makePileupColumn", __pyx_f[0], 447, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":454
 *     '''
 *     # note that the following does not call __init__
 *     cdef PileupColumn dest = PileupColumn.__new__(PileupColumn)             # <<<<<<<<<<<<<<
 *     dest._alignment_file = alignment_file
 *     dest.plp = plp
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_15calignedsegment_PileupColumn(((PyTypeObject *)__pyx_ptype_5pysam_15calignedsegment_PileupColumn), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_15calignedsegment_PileupColumn)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":455
 *     # note that the following does not call __init__
 *     cdef PileupColumn dest = PileupColumn.__new__(PileupColumn)
 *     dest._alignment_file = alignment_file             # <<<<<<<<<<<<<<
 *     dest.plp = plp
 *     dest.tid = tid
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_alignment_file));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_alignment_file));
  __Pyx_GOTREF(__pyx_v_dest->_alignment_file);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment_file));
  __pyx_v_dest->_alignment_file = __pyx_v_alignment_file;

  /* "pysam/calignedsegment.pyx":456
 *     cdef PileupColumn dest = PileupColumn.__new__(PileupColumn)
 *     dest._alignment_file = alignment_file
 *     dest.plp = plp             # <<<<<<<<<<<<<<
 *     dest.tid = tid
 *     dest.pos = pos
 */
  __pyx_v_dest->plp = __pyx_v_plp;

  /* "pysam/calignedsegment.pyx":457
 *     dest._alignment_file = alignment_file
 *     dest.plp = plp
 *     dest.tid = tid             # <<<<<<<<<<<<<<
 *     dest.pos = pos
 *     dest.n_pu = n_pu
 */
  __pyx_v_dest->tid = __pyx_v_tid;

  /* "pysam/calignedsegment.pyx":458
 *     dest.plp = plp
 *     dest.tid = tid
 *     dest.pos = pos             # <<<<<<<<<<<<<<
 *     dest.n_pu = n_pu
 *     return dest
 */
  __pyx_v_dest->pos = __pyx_v_pos;

  /* "pysam/calignedsegment.pyx":459
 *     dest.tid = tid
 *     dest.pos = pos
 *     dest.n_pu = n_pu             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_v_dest->n_pu = __pyx_v_n_pu;

  /* "pysam/calignedsegment.pyx":460
 *     dest.pos = pos
 *     dest.n_pu = n_pu
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupRead
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":447
 * 
 * cdef class PileupColumn
 * cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos,             # <<<<<<<<<<<<<<
 *                       int n_pu, AlignmentFile alignment_file):
 *     '''return a PileupColumn object constructed from pileup in `plp` and
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.makePileupColumn", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":463
 * 
 * cdef class PileupRead
 * cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file):             # <<<<<<<<<<<<<<
 *     '''return a PileupRead object construted from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_makePileupRead(bam_pileup1_t *__pyx_v_src, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_alignment_file) {
  struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_dest = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int32_t __pyx_t_2;
  int __pyx_t_3;
  uint32_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("makePileupRead", 0);
  __Pyx_TraceCall("makePileupRead", __pyx_f[0], 463, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 463; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":465
 * cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file):
 *     '''return a PileupRead object construted from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)             # <<<<<<<<<<<<<<
 *     dest._alignment = makeAlignedSegment(src.b, alignment_file)
 *     dest._qpos = src.qpos
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_15calignedsegment_PileupRead(((PyTypeObject *)__pyx_ptype_5pysam_15calignedsegment_PileupRead), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_15calignedsegment_PileupRead)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":466
 *     '''return a PileupRead object construted from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 *     dest._alignment = makeAlignedSegment(src.b, alignment_file)             # <<<<<<<<<<<<<<
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel
 */
  __pyx_t_1 = __pyx_f_5pysam_15calignedsegment_makeAlignedSegment(__pyx_v_src->b, __pyx_v_alignment_file); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_15calignedsegment_AlignedSegment))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_dest->_alignment);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment));
  __pyx_v_dest->_alignment = ((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":467
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 *     dest._alignment = makeAlignedSegment(src.b, alignment_file)
 *     dest._qpos = src.qpos             # <<<<<<<<<<<<<<
 *     dest._indel = src.indel
 *     dest._level = src.level
 */
  __pyx_t_2 = __pyx_v_src->qpos;
  __pyx_v_dest->_qpos = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":468
 *     dest._alignment = makeAlignedSegment(src.b, alignment_file)
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel             # <<<<<<<<<<<<<<
 *     dest._level = src.level
 *     dest._is_del = src.is_del
 */
  __pyx_t_3 = __pyx_v_src->indel;
  __pyx_v_dest->_indel = __pyx_t_3;

  /* "pysam/calignedsegment.pyx":469
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel
 *     dest._level = src.level             # <<<<<<<<<<<<<<
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head
 */
  __pyx_t_3 = __pyx_v_src->level;
  __pyx_v_dest->_level = __pyx_t_3;

  /* "pysam/calignedsegment.pyx":470
 *     dest._indel = src.indel
 *     dest._level = src.level
 *     dest._is_del = src.is_del             # <<<<<<<<<<<<<<
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail
 */
  __pyx_t_4 = __pyx_v_src->is_del;
  __pyx_v_dest->_is_del = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":471
 *     dest._level = src.level
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head             # <<<<<<<<<<<<<<
 *     dest._is_tail = src.is_tail
 *     dest._is_refskip = src.is_refskip
 */
  __pyx_t_4 = __pyx_v_src->is_head;
  __pyx_v_dest->_is_head = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":472
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail             # <<<<<<<<<<<<<<
 *     dest._is_refskip = src.is_refskip
 *     return dest
 */
  __pyx_t_4 = __pyx_v_src->is_tail;
  __pyx_v_dest->_is_tail = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":473
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail
 *     dest._is_refskip = src.is_refskip             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_t_4 = __pyx_v_src->is_refskip;
  __pyx_v_dest->_is_refskip = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":474
 *     dest._is_tail = src.is_tail
 *     dest._is_refskip = src.is_refskip
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":463
 * 
 * cdef class PileupRead
 * cdef inline makePileupRead(bam_pileup1_t * src, AlignmentFile alignment_file):             # <<<<<<<<<<<<<<
 *     '''return a PileupRead object construted from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.makePileupRead", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_dest);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":477
 * 
 * 
 * cdef inline uint32_t get_alignment_length(bam1_t * src):             # <<<<<<<<<<<<<<
 *     cdef int k = 0
 *     cdef uint32_t l = 0
 */

static CYTHON_INLINE uint32_t __pyx_f_5pysam_15calignedsegment_get_alignment_length(bam1_t *__pyx_v_src) {
  int __pyx_v_k;
  uint32_t __pyx_v_l;
  uint32_t *__pyx_v_cigar_p;
  int __pyx_v_op;
  int __pyx_v_n;
  uint32_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_alignment_length", 0);
  __Pyx_TraceCall("get_alignment_length", __pyx_f[0], 477, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":478
 * 
 * cdef inline uint32_t get_alignment_length(bam1_t * src):
 *     cdef int k = 0             # <<<<<<<<<<<<<<
 *     cdef uint32_t l = 0
 *     if src == NULL:
 */
  __pyx_v_k = 0;

  /* "pysam/calignedsegment.pyx":479
 * cdef inline uint32_t get_alignment_length(bam1_t * src):
 *     cdef int k = 0
 *     cdef uint32_t l = 0             # <<<<<<<<<<<<<<
 *     if src == NULL:
 *         return 0
 */
  __pyx_v_l = 0;

  /* "pysam/calignedsegment.pyx":480
 *     cdef int k = 0
 *     cdef uint32_t l = 0
 *     if src == NULL:             # <<<<<<<<<<<<<<
 *         return 0
 *     cdef uint32_t * cigar_p = bam_get_cigar(src)
 */
  __pyx_t_1 = ((__pyx_v_src == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":481
 *     cdef uint32_t l = 0
 *     if src == NULL:
 *         return 0             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p = bam_get_cigar(src)
 *     if cigar_p == NULL:
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":480
 *     cdef int k = 0
 *     cdef uint32_t l = 0
 *     if src == NULL:             # <<<<<<<<<<<<<<
 *         return 0
 *     cdef uint32_t * cigar_p = bam_get_cigar(src)
 */
  }

  /* "pysam/calignedsegment.pyx":482
 *     if src == NULL:
 *         return 0
 *     cdef uint32_t * cigar_p = bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *     if cigar_p == NULL:
 *         return 0
 */
  __pyx_v_cigar_p = bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":483
 *         return 0
 *     cdef uint32_t * cigar_p = bam_get_cigar(src)
 *     if cigar_p == NULL:             # <<<<<<<<<<<<<<
 *         return 0
 *     cdef int op
 */
  __pyx_t_1 = ((__pyx_v_cigar_p == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":484
 *     cdef uint32_t * cigar_p = bam_get_cigar(src)
 *     if cigar_p == NULL:
 *         return 0             # <<<<<<<<<<<<<<
 *     cdef int op
 *     cdef int n = pysam_get_n_cigar(src)
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":483
 *         return 0
 *     cdef uint32_t * cigar_p = bam_get_cigar(src)
 *     if cigar_p == NULL:             # <<<<<<<<<<<<<<
 *         return 0
 *     cdef int op
 */
  }

  /* "pysam/calignedsegment.pyx":486
 *         return 0
 *     cdef int op
 *     cdef int n = pysam_get_n_cigar(src)             # <<<<<<<<<<<<<<
 *     for k from 0 <= k < n:
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_n = pysam_get_n_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":487
 *     cdef int op
 *     cdef int n = pysam_get_n_cigar(src)
 *     for k from 0 <= k < n:             # <<<<<<<<<<<<<<
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP:
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":488
 *     cdef int n = pysam_get_n_cigar(src)
 *     for k from 0 <= k < n:
 *         op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *         if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP:
 *             continue
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":489
 *     for k from 0 <= k < n:
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *             continue
 *         l += cigar_p[k] >> BAM_CIGAR_SHIFT
 */
    __pyx_t_3 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    if (!__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L8_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L8_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":490
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP:
 *             continue             # <<<<<<<<<<<<<<
 *         l += cigar_p[k] >> BAM_CIGAR_SHIFT
 *     return l
 */
      goto __pyx_L5_continue;

      /* "pysam/calignedsegment.pyx":489
 *     for k from 0 <= k < n:
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *             continue
 *         l += cigar_p[k] >> BAM_CIGAR_SHIFT
 */
    }

    /* "pysam/calignedsegment.pyx":491
 *         if op == BAM_CSOFT_CLIP or op == BAM_CHARD_CLIP:
 *             continue
 *         l += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *     return l
 * 
 */
    __pyx_v_l = (__pyx_v_l + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));
    __pyx_L5_continue:;
  }

  /* "pysam/calignedsegment.pyx":492
 *             continue
 *         l += cigar_p[k] >> BAM_CIGAR_SHIFT
 *     return l             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_l;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":477
 * 
 * 
 * cdef inline uint32_t get_alignment_length(bam1_t * src):             # <<<<<<<<<<<<<<
 *     cdef int k = 0
 *     cdef uint32_t l = 0
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("pysam.calignedsegment.get_alignment_length", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":496
 * 
 * # TODO: avoid string copying for getSequenceInRange, reconstituneSequenceFromMD, ...
 * cdef inline bytes build_alignment_sequence(bam1_t * src):             # <<<<<<<<<<<<<<
 *     """return expanded sequence from MD tag.
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_15calignedsegment_build_alignment_sequence(bam1_t *__pyx_v_src) {
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_v_r = NULL;
  char *__pyx_v_read_sequence;
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_r_idx;
  int __pyx_v_op;
  uint32_t __pyx_v_k;
  CYTHON_UNUSED uint32_t __pyx_v_i;
  uint32_t __pyx_v_l;
  CYTHON_UNUSED uint32_t __pyx_v_x;
  int __pyx_v_nmatches;
  int __pyx_v_s_idx;
  uint32_t __pyx_v_max_len;
  char *__pyx_v_s;
  uint8_t *__pyx_v_md_tag_ptr;
  PyObject *__pyx_v_seq = NULL;
  char *__pyx_v_md_tag;
  int __pyx_v_md_idx;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int32_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  uint16_t __pyx_t_6;
  int __pyx_t_7;
  uint32_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("build_alignment_sequence", 0);
  __Pyx_TraceCall("build_alignment_sequence", __pyx_f[0], 496, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":510
 * 
 *     """
 *     if src == NULL:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((__pyx_v_src == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":511
 *     """
 *     if src == NULL:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     cdef uint32_t start = getQueryStart(src)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = ((PyObject*)Py_None);
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":510
 * 
 *     """
 *     if src == NULL:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":513
 *         return None
 * 
 *     cdef uint32_t start = getQueryStart(src)             # <<<<<<<<<<<<<<
 *     cdef uint32_t end = getQueryEnd(src)
 *     # get read sequence, taking into account soft-clipping
 */
  __pyx_t_2 = __pyx_f_5pysam_15calignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":514
 * 
 *     cdef uint32_t start = getQueryStart(src)
 *     cdef uint32_t end = getQueryEnd(src)             # <<<<<<<<<<<<<<
 *     # get read sequence, taking into account soft-clipping
 *     r = getSequenceInRange(src, start, end)
 */
  __pyx_t_2 = __pyx_f_5pysam_15calignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 514; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":516
 *     cdef uint32_t end = getQueryEnd(src)
 *     # get read sequence, taking into account soft-clipping
 *     r = getSequenceInRange(src, start, end)             # <<<<<<<<<<<<<<
 *     cdef char * read_sequence = r
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getSequenceInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":517
 *     # get read sequence, taking into account soft-clipping
 *     r = getSequenceInRange(src, start, end)
 *     cdef char * read_sequence = r             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 *     if cigar_p == NULL:
 */
  __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_r); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_read_sequence = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":518
 *     r = getSequenceInRange(src, start, end)
 *     cdef char * read_sequence = r
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *     if cigar_p == NULL:
 *         return None
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":519
 *     cdef char * read_sequence = r
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 *     if cigar_p == NULL:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((__pyx_v_cigar_p == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":520
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 *     if cigar_p == NULL:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     cdef uint32_t r_idx = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = ((PyObject*)Py_None);
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":519
 *     cdef char * read_sequence = r
 *     cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 *     if cigar_p == NULL:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":522
 *         return None
 * 
 *     cdef uint32_t r_idx = 0             # <<<<<<<<<<<<<<
 *     cdef int op
 *     cdef uint32_t k, i, l, x
 */
  __pyx_v_r_idx = 0;

  /* "pysam/calignedsegment.pyx":525
 *     cdef int op
 *     cdef uint32_t k, i, l, x
 *     cdef int nmatches = 0             # <<<<<<<<<<<<<<
 *     cdef int s_idx = 0
 * 
 */
  __pyx_v_nmatches = 0;

  /* "pysam/calignedsegment.pyx":526
 *     cdef uint32_t k, i, l, x
 *     cdef int nmatches = 0
 *     cdef int s_idx = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef uint32_t max_len = get_alignment_length(src)
 */
  __pyx_v_s_idx = 0;

  /* "pysam/calignedsegment.pyx":528
 *     cdef int s_idx = 0
 * 
 *     cdef uint32_t max_len = get_alignment_length(src)             # <<<<<<<<<<<<<<
 *     if max_len == 0:
 *         raise ValueError("could not determine alignment length")
 */
  __pyx_v_max_len = __pyx_f_5pysam_15calignedsegment_get_alignment_length(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":529
 * 
 *     cdef uint32_t max_len = get_alignment_length(src)
 *     if max_len == 0:             # <<<<<<<<<<<<<<
 *         raise ValueError("could not determine alignment length")
 * 
 */
  __pyx_t_1 = ((__pyx_v_max_len == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":530
 *     cdef uint32_t max_len = get_alignment_length(src)
 *     if max_len == 0:
 *         raise ValueError("could not determine alignment length")             # <<<<<<<<<<<<<<
 * 
 *     cdef char * s = <char*>calloc(max_len + 1, sizeof(char))
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":529
 * 
 *     cdef uint32_t max_len = get_alignment_length(src)
 *     if max_len == 0:             # <<<<<<<<<<<<<<
 *         raise ValueError("could not determine alignment length")
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":532
 *         raise ValueError("could not determine alignment length")
 * 
 *     cdef char * s = <char*>calloc(max_len + 1, sizeof(char))             # <<<<<<<<<<<<<<
 *     if s == NULL:
 *         raise ValueError(
 */
  __pyx_v_s = ((char *)calloc((__pyx_v_max_len + 1), (sizeof(char))));

  /* "pysam/calignedsegment.pyx":533
 * 
 *     cdef char * s = <char*>calloc(max_len + 1, sizeof(char))
 *     if s == NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "could not allocated sequence of length %i" % max_len)
 */
  __pyx_t_1 = ((__pyx_v_s == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":535
 *     if s == NULL:
 *         raise ValueError(
 *             "could not allocated sequence of length %i" % max_len)             # <<<<<<<<<<<<<<
 * 
 *     for k from 0 <= k < pysam_get_n_cigar(src):
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_max_len); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_could_not_allocated_sequence_of, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":534
 *     cdef char * s = <char*>calloc(max_len + 1, sizeof(char))
 *     if s == NULL:
 *         raise ValueError(             # <<<<<<<<<<<<<<
 *             "could not allocated sequence of length %i" % max_len)
 * 
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":533
 * 
 *     cdef char * s = <char*>calloc(max_len + 1, sizeof(char))
 *     if s == NULL:             # <<<<<<<<<<<<<<
 *         raise ValueError(
 *             "could not allocated sequence of length %i" % max_len)
 */
  }

  /* "pysam/calignedsegment.pyx":537
 *             "could not allocated sequence of length %i" % max_len)
 * 
 *     for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_6 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":538
 * 
 *     for k from 0 <= k < pysam_get_n_cigar(src):
 *         op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *         l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *         if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":539
 *     for k from 0 <= k < pysam_get_n_cigar(src):
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *         if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *             for i from 0 <= i < l:
 */
    __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT);

    /* "pysam/calignedsegment.pyx":540
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *         if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < l:
 *                 s[s_idx] = read_sequence[r_idx]
 */
    __pyx_t_7 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_1 = __pyx_t_7;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_7 = ((__pyx_v_op == BAM_CEQUAL) != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_1 = __pyx_t_7;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_7 = ((__pyx_v_op == BAM_CDIFF) != 0);
    __pyx_t_1 = __pyx_t_7;
    __pyx_L10_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":541
 *         l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *         if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *             for i from 0 <= i < l:             # <<<<<<<<<<<<<<
 *                 s[s_idx] = read_sequence[r_idx]
 *                 r_idx += 1
 */
      __pyx_t_8 = __pyx_v_l;
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

        /* "pysam/calignedsegment.pyx":542
 *         if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *             for i from 0 <= i < l:
 *                 s[s_idx] = read_sequence[r_idx]             # <<<<<<<<<<<<<<
 *                 r_idx += 1
 *                 s_idx += 1
 */
        (__pyx_v_s[__pyx_v_s_idx]) = (__pyx_v_read_sequence[__pyx_v_r_idx]);

        /* "pysam/calignedsegment.pyx":543
 *             for i from 0 <= i < l:
 *                 s[s_idx] = read_sequence[r_idx]
 *                 r_idx += 1             # <<<<<<<<<<<<<<
 *                 s_idx += 1
 *         elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
        __pyx_v_r_idx = (__pyx_v_r_idx + 1);

        /* "pysam/calignedsegment.pyx":544
 *                 s[s_idx] = read_sequence[r_idx]
 *                 r_idx += 1
 *                 s_idx += 1             # <<<<<<<<<<<<<<
 *         elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *             for i from 0 <= i < l:
 */
        __pyx_v_s_idx = (__pyx_v_s_idx + 1);
      }

      /* "pysam/calignedsegment.pyx":540
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *         if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < l:
 *                 s[s_idx] = read_sequence[r_idx]
 */
      goto __pyx_L9;
    }

    /* "pysam/calignedsegment.pyx":545
 *                 r_idx += 1
 *                 s_idx += 1
 *         elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < l:
 *                 s[s_idx] = '-'
 */
    __pyx_t_7 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_1 = __pyx_t_7;
      goto __pyx_L15_bool_binop_done;
    }
    __pyx_t_7 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_1 = __pyx_t_7;
    __pyx_L15_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":546
 *                 s_idx += 1
 *         elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *             for i from 0 <= i < l:             # <<<<<<<<<<<<<<
 *                 s[s_idx] = '-'
 *                 s_idx += 1
 */
      __pyx_t_8 = __pyx_v_l;
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

        /* "pysam/calignedsegment.pyx":547
 *         elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *             for i from 0 <= i < l:
 *                 s[s_idx] = '-'             # <<<<<<<<<<<<<<
 *                 s_idx += 1
 *         elif op == BAM_CINS:
 */
        (__pyx_v_s[__pyx_v_s_idx]) = '-';

        /* "pysam/calignedsegment.pyx":548
 *             for i from 0 <= i < l:
 *                 s[s_idx] = '-'
 *                 s_idx += 1             # <<<<<<<<<<<<<<
 *         elif op == BAM_CINS:
 *             for i from 0 <= i < l:
 */
        __pyx_v_s_idx = (__pyx_v_s_idx + 1);
      }

      /* "pysam/calignedsegment.pyx":545
 *                 r_idx += 1
 *                 s_idx += 1
 *         elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < l:
 *                 s[s_idx] = '-'
 */
      goto __pyx_L9;
    }

    /* "pysam/calignedsegment.pyx":549
 *                 s[s_idx] = '-'
 *                 s_idx += 1
 *         elif op == BAM_CINS:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < l:
 *                 # encode insertions into reference as lowercase
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CINS) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":550
 *                 s_idx += 1
 *         elif op == BAM_CINS:
 *             for i from 0 <= i < l:             # <<<<<<<<<<<<<<
 *                 # encode insertions into reference as lowercase
 *                 s[s_idx] = read_sequence[r_idx] + 32
 */
      __pyx_t_8 = __pyx_v_l;
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

        /* "pysam/calignedsegment.pyx":552
 *             for i from 0 <= i < l:
 *                 # encode insertions into reference as lowercase
 *                 s[s_idx] = read_sequence[r_idx] + 32             # <<<<<<<<<<<<<<
 *                 r_idx += 1
 *                 s_idx += 1
 */
        (__pyx_v_s[__pyx_v_s_idx]) = ((__pyx_v_read_sequence[__pyx_v_r_idx]) + 32);

        /* "pysam/calignedsegment.pyx":553
 *                 # encode insertions into reference as lowercase
 *                 s[s_idx] = read_sequence[r_idx] + 32
 *                 r_idx += 1             # <<<<<<<<<<<<<<
 *                 s_idx += 1
 *         elif op == BAM_CSOFT_CLIP:
 */
        __pyx_v_r_idx = (__pyx_v_r_idx + 1);

        /* "pysam/calignedsegment.pyx":554
 *                 s[s_idx] = read_sequence[r_idx] + 32
 *                 r_idx += 1
 *                 s_idx += 1             # <<<<<<<<<<<<<<
 *         elif op == BAM_CSOFT_CLIP:
 *             pass
 */
        __pyx_v_s_idx = (__pyx_v_s_idx + 1);
      }

      /* "pysam/calignedsegment.pyx":549
 *                 s[s_idx] = '-'
 *                 s_idx += 1
 *         elif op == BAM_CINS:             # <<<<<<<<<<<<<<
 *             for i from 0 <= i < l:
 *                 # encode insertions into reference as lowercase
 */
      goto __pyx_L9;
    }

    /* "pysam/calignedsegment.pyx":555
 *                 r_idx += 1
 *                 s_idx += 1
 *         elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *             pass
 *         elif op == BAM_CHARD_CLIP:
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    if (__pyx_t_1) {
      goto __pyx_L9;
    }

    /* "pysam/calignedsegment.pyx":557
 *         elif op == BAM_CSOFT_CLIP:
 *             pass
 *         elif op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *             pass # advances neither
 *         elif op == BAM_CPAD:
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
    if (__pyx_t_1) {
      goto __pyx_L9;
    }

    /* "pysam/calignedsegment.pyx":559
 *         elif op == BAM_CHARD_CLIP:
 *             pass # advances neither
 *         elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "Padding (BAM_CPAD, 6) is currently not supported. "
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CPAD) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":560
 *             pass # advances neither
 *         elif op == BAM_CPAD:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "Padding (BAM_CPAD, 6) is currently not supported. "
 *                 "Please implement. Sorry about that.")
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignedsegment.pyx":559
 *         elif op == BAM_CHARD_CLIP:
 *             pass # advances neither
 *         elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "Padding (BAM_CPAD, 6) is currently not supported. "
 */
    }
    __pyx_L9:;
  }

  /* "pysam/calignedsegment.pyx":564
 *                 "Please implement. Sorry about that.")
 * 
 *     cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD")             # <<<<<<<<<<<<<<
 *     if md_tag_ptr == NULL:
 *         seq = PyBytes_FromStringAndSize(s, s_idx)
 */
  __pyx_v_md_tag_ptr = bam_aux_get(__pyx_v_src, __pyx_k_MD);

  /* "pysam/calignedsegment.pyx":565
 * 
 *     cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD")
 *     if md_tag_ptr == NULL:             # <<<<<<<<<<<<<<
 *         seq = PyBytes_FromStringAndSize(s, s_idx)
 *         free(s)
 */
  __pyx_t_1 = ((__pyx_v_md_tag_ptr == NULL) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":566
 *     cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD")
 *     if md_tag_ptr == NULL:
 *         seq = PyBytes_FromStringAndSize(s, s_idx)             # <<<<<<<<<<<<<<
 *         free(s)
 *         return seq
 */
    __pyx_t_5 = PyBytes_FromStringAndSize(__pyx_v_s, __pyx_v_s_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_v_seq = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysam/calignedsegment.pyx":567
 *     if md_tag_ptr == NULL:
 *         seq = PyBytes_FromStringAndSize(s, s_idx)
 *         free(s)             # <<<<<<<<<<<<<<
 *         return seq
 * 
 */
    free(__pyx_v_s);

    /* "pysam/calignedsegment.pyx":568
 *         seq = PyBytes_FromStringAndSize(s, s_idx)
 *         free(s)
 *         return seq             # <<<<<<<<<<<<<<
 * 
 *     cdef char * md_tag = <char*>bam_aux2Z(md_tag_ptr)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_seq);
    __pyx_r = __pyx_v_seq;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":565
 * 
 *     cdef uint8_t * md_tag_ptr = bam_aux_get(src, "MD")
 *     if md_tag_ptr == NULL:             # <<<<<<<<<<<<<<
 *         seq = PyBytes_FromStringAndSize(s, s_idx)
 *         free(s)
 */
  }

  /* "pysam/calignedsegment.pyx":570
 *         return seq
 * 
 *     cdef char * md_tag = <char*>bam_aux2Z(md_tag_ptr)             # <<<<<<<<<<<<<<
 *     cdef int md_idx = 0
 *     s_idx = 0
 */
  __pyx_v_md_tag = ((char *)bam_aux2Z(__pyx_v_md_tag_ptr));

  /* "pysam/calignedsegment.pyx":571
 * 
 *     cdef char * md_tag = <char*>bam_aux2Z(md_tag_ptr)
 *     cdef int md_idx = 0             # <<<<<<<<<<<<<<
 *     s_idx = 0
 * 
 */
  __pyx_v_md_idx = 0;

  /* "pysam/calignedsegment.pyx":572
 *     cdef char * md_tag = <char*>bam_aux2Z(md_tag_ptr)
 *     cdef int md_idx = 0
 *     s_idx = 0             # <<<<<<<<<<<<<<
 * 
 *     while md_tag[md_idx] != 0:
 */
  __pyx_v_s_idx = 0;

  /* "pysam/calignedsegment.pyx":574
 *     s_idx = 0
 * 
 *     while md_tag[md_idx] != 0:             # <<<<<<<<<<<<<<
 *         # c is numerical
 *         if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57:
 */
  while (1) {
    __pyx_t_1 = (((__pyx_v_md_tag[__pyx_v_md_idx]) != 0) != 0);
    if (!__pyx_t_1) break;

    /* "pysam/calignedsegment.pyx":576
 *     while md_tag[md_idx] != 0:
 *         # c is numerical
 *         if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57:             # <<<<<<<<<<<<<<
 *             nmatches *= 10
 *             nmatches += md_tag[md_idx] - 48
 */
    __pyx_t_7 = (((__pyx_v_md_tag[__pyx_v_md_idx]) >= 48) != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_1 = __pyx_t_7;
      goto __pyx_L25_bool_binop_done;
    }
    __pyx_t_7 = (((__pyx_v_md_tag[__pyx_v_md_idx]) <= 57) != 0);
    __pyx_t_1 = __pyx_t_7;
    __pyx_L25_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":577
 *         # c is numerical
 *         if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57:
 *             nmatches *= 10             # <<<<<<<<<<<<<<
 *             nmatches += md_tag[md_idx] - 48
 *             md_idx += 1
 */
      __pyx_v_nmatches = (__pyx_v_nmatches * 10);

      /* "pysam/calignedsegment.pyx":578
 *         if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57:
 *             nmatches *= 10
 *             nmatches += md_tag[md_idx] - 48             # <<<<<<<<<<<<<<
 *             md_idx += 1
 *             continue
 */
      __pyx_v_nmatches = (__pyx_v_nmatches + ((__pyx_v_md_tag[__pyx_v_md_idx]) - 48));

      /* "pysam/calignedsegment.pyx":579
 *             nmatches *= 10
 *             nmatches += md_tag[md_idx] - 48
 *             md_idx += 1             # <<<<<<<<<<<<<<
 *             continue
 *         else:
 */
      __pyx_v_md_idx = (__pyx_v_md_idx + 1);

      /* "pysam/calignedsegment.pyx":580
 *             nmatches += md_tag[md_idx] - 48
 *             md_idx += 1
 *             continue             # <<<<<<<<<<<<<<
 *         else:
 *             # save matches up to this point, skipping insertions
 */
      goto __pyx_L22_continue;

      /* "pysam/calignedsegment.pyx":576
 *     while md_tag[md_idx] != 0:
 *         # c is numerical
 *         if md_tag[md_idx] >= 48 and md_tag[md_idx] <= 57:             # <<<<<<<<<<<<<<
 *             nmatches *= 10
 *             nmatches += md_tag[md_idx] - 48
 */
    }

    /* "pysam/calignedsegment.pyx":583
 *         else:
 *             # save matches up to this point, skipping insertions
 *             for x from 0 <= x < nmatches:             # <<<<<<<<<<<<<<
 *                 while s[s_idx] >= 'a':
 *                     s_idx += 1
 */
    /*else*/ {
      __pyx_t_9 = __pyx_v_nmatches;
      for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_9; __pyx_v_x++) {

        /* "pysam/calignedsegment.pyx":584
 *             # save matches up to this point, skipping insertions
 *             for x from 0 <= x < nmatches:
 *                 while s[s_idx] >= 'a':             # <<<<<<<<<<<<<<
 *                     s_idx += 1
 *                 s_idx += 1
 */
        while (1) {
          __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0);
          if (!__pyx_t_1) break;

          /* "pysam/calignedsegment.pyx":585
 *             for x from 0 <= x < nmatches:
 *                 while s[s_idx] >= 'a':
 *                     s_idx += 1             # <<<<<<<<<<<<<<
 *                 s_idx += 1
 *             while s[s_idx] >= 'a':
 */
          __pyx_v_s_idx = (__pyx_v_s_idx + 1);
        }

        /* "pysam/calignedsegment.pyx":586
 *                 while s[s_idx] >= 'a':
 *                     s_idx += 1
 *                 s_idx += 1             # <<<<<<<<<<<<<<
 *             while s[s_idx] >= 'a':
 *                 s_idx += 1
 */
        __pyx_v_s_idx = (__pyx_v_s_idx + 1);
      }

      /* "pysam/calignedsegment.pyx":587
 *                     s_idx += 1
 *                 s_idx += 1
 *             while s[s_idx] >= 'a':             # <<<<<<<<<<<<<<
 *                 s_idx += 1
 * 
 */
      while (1) {
        __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0);
        if (!__pyx_t_1) break;

        /* "pysam/calignedsegment.pyx":588
 *                 s_idx += 1
 *             while s[s_idx] >= 'a':
 *                 s_idx += 1             # <<<<<<<<<<<<<<
 * 
 *             r_idx += nmatches
 */
        __pyx_v_s_idx = (__pyx_v_s_idx + 1);
      }

      /* "pysam/calignedsegment.pyx":590
 *                 s_idx += 1
 * 
 *             r_idx += nmatches             # <<<<<<<<<<<<<<
 *             nmatches = 0
 *             if md_tag[md_idx] == '^':
 */
      __pyx_v_r_idx = (__pyx_v_r_idx + __pyx_v_nmatches);

      /* "pysam/calignedsegment.pyx":591
 * 
 *             r_idx += nmatches
 *             nmatches = 0             # <<<<<<<<<<<<<<
 *             if md_tag[md_idx] == '^':
 *                 md_idx += 1
 */
      __pyx_v_nmatches = 0;

      /* "pysam/calignedsegment.pyx":592
 *             r_idx += nmatches
 *             nmatches = 0
 *             if md_tag[md_idx] == '^':             # <<<<<<<<<<<<<<
 *                 md_idx += 1
 *                 while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90:
 */
      __pyx_t_1 = (((__pyx_v_md_tag[__pyx_v_md_idx]) == '^') != 0);
      if (__pyx_t_1) {

        /* "pysam/calignedsegment.pyx":593
 *             nmatches = 0
 *             if md_tag[md_idx] == '^':
 *                 md_idx += 1             # <<<<<<<<<<<<<<
 *                 while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90:
 *                     assert s[s_idx] == '-'
 */
        __pyx_v_md_idx = (__pyx_v_md_idx + 1);

        /* "pysam/calignedsegment.pyx":594
 *             if md_tag[md_idx] == '^':
 *                 md_idx += 1
 *                 while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90:             # <<<<<<<<<<<<<<
 *                     assert s[s_idx] == '-'
 *                     s[s_idx] = md_tag[md_idx]
 */
        while (1) {
          __pyx_t_7 = (((__pyx_v_md_tag[__pyx_v_md_idx]) >= 65) != 0);
          if (__pyx_t_7) {
          } else {
            __pyx_t_1 = __pyx_t_7;
            goto __pyx_L36_bool_binop_done;
          }
          __pyx_t_7 = (((__pyx_v_md_tag[__pyx_v_md_idx]) <= 90) != 0);
          __pyx_t_1 = __pyx_t_7;
          __pyx_L36_bool_binop_done:;
          if (!__pyx_t_1) break;

          /* "pysam/calignedsegment.pyx":595
 *                 md_idx += 1
 *                 while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90:
 *                     assert s[s_idx] == '-'             # <<<<<<<<<<<<<<
 *                     s[s_idx] = md_tag[md_idx]
 *                     s_idx += 1
 */
          #ifndef CYTHON_WITHOUT_ASSERTIONS
          if (unlikely(!Py_OptimizeFlag)) {
            if (unlikely(!(((__pyx_v_s[__pyx_v_s_idx]) == '-') != 0))) {
              PyErr_SetNone(PyExc_AssertionError);
              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
          }
          #endif

          /* "pysam/calignedsegment.pyx":596
 *                 while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90:
 *                     assert s[s_idx] == '-'
 *                     s[s_idx] = md_tag[md_idx]             # <<<<<<<<<<<<<<
 *                     s_idx += 1
 *                     md_idx += 1
 */
          (__pyx_v_s[__pyx_v_s_idx]) = (__pyx_v_md_tag[__pyx_v_md_idx]);

          /* "pysam/calignedsegment.pyx":597
 *                     assert s[s_idx] == '-'
 *                     s[s_idx] = md_tag[md_idx]
 *                     s_idx += 1             # <<<<<<<<<<<<<<
 *                     md_idx += 1
 *             else:
 */
          __pyx_v_s_idx = (__pyx_v_s_idx + 1);

          /* "pysam/calignedsegment.pyx":598
 *                     s[s_idx] = md_tag[md_idx]
 *                     s_idx += 1
 *                     md_idx += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 # save mismatch and change to lower case
 */
          __pyx_v_md_idx = (__pyx_v_md_idx + 1);
        }

        /* "pysam/calignedsegment.pyx":592
 *             r_idx += nmatches
 *             nmatches = 0
 *             if md_tag[md_idx] == '^':             # <<<<<<<<<<<<<<
 *                 md_idx += 1
 *                 while md_tag[md_idx] >= 65 and md_tag[md_idx] <= 90:
 */
        goto __pyx_L33;
      }

      /* "pysam/calignedsegment.pyx":601
 *             else:
 *                 # save mismatch and change to lower case
 *                 s[s_idx] = md_tag[md_idx] + 32             # <<<<<<<<<<<<<<
 *                 s_idx += 1
 *                 r_idx += 1
 */
      /*else*/ {
        (__pyx_v_s[__pyx_v_s_idx]) = ((__pyx_v_md_tag[__pyx_v_md_idx]) + 32);

        /* "pysam/calignedsegment.pyx":602
 *                 # save mismatch and change to lower case
 *                 s[s_idx] = md_tag[md_idx] + 32
 *                 s_idx += 1             # <<<<<<<<<<<<<<
 *                 r_idx += 1
 *                 md_idx += 1
 */
        __pyx_v_s_idx = (__pyx_v_s_idx + 1);

        /* "pysam/calignedsegment.pyx":603
 *                 s[s_idx] = md_tag[md_idx] + 32
 *                 s_idx += 1
 *                 r_idx += 1             # <<<<<<<<<<<<<<
 *                 md_idx += 1
 * 
 */
        __pyx_v_r_idx = (__pyx_v_r_idx + 1);

        /* "pysam/calignedsegment.pyx":604
 *                 s_idx += 1
 *                 r_idx += 1
 *                 md_idx += 1             # <<<<<<<<<<<<<<
 * 
 *     # save matches up to this point, skipping insertions
 */
        __pyx_v_md_idx = (__pyx_v_md_idx + 1);
      }
      __pyx_L33:;
    }
    __pyx_L22_continue:;
  }

  /* "pysam/calignedsegment.pyx":607
 * 
 *     # save matches up to this point, skipping insertions
 *     for x from 0 <= x < nmatches:             # <<<<<<<<<<<<<<
 *         while s[s_idx] >= 'a':
 *             s_idx += 1
 */
  __pyx_t_9 = __pyx_v_nmatches;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_9; __pyx_v_x++) {

    /* "pysam/calignedsegment.pyx":608
 *     # save matches up to this point, skipping insertions
 *     for x from 0 <= x < nmatches:
 *         while s[s_idx] >= 'a':             # <<<<<<<<<<<<<<
 *             s_idx += 1
 *         s_idx += 1
 */
    while (1) {
      __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0);
      if (!__pyx_t_1) break;

      /* "pysam/calignedsegment.pyx":609
 *     for x from 0 <= x < nmatches:
 *         while s[s_idx] >= 'a':
 *             s_idx += 1             # <<<<<<<<<<<<<<
 *         s_idx += 1
 *     while s[s_idx] >= 'a':
 */
      __pyx_v_s_idx = (__pyx_v_s_idx + 1);
    }

    /* "pysam/calignedsegment.pyx":610
 *         while s[s_idx] >= 'a':
 *             s_idx += 1
 *         s_idx += 1             # <<<<<<<<<<<<<<
 *     while s[s_idx] >= 'a':
 *         s_idx += 1
 */
    __pyx_v_s_idx = (__pyx_v_s_idx + 1);
  }

  /* "pysam/calignedsegment.pyx":611
 *             s_idx += 1
 *         s_idx += 1
 *     while s[s_idx] >= 'a':             # <<<<<<<<<<<<<<
 *         s_idx += 1
 * 
 */
  while (1) {
    __pyx_t_1 = (((__pyx_v_s[__pyx_v_s_idx]) >= 'a') != 0);
    if (!__pyx_t_1) break;

    /* "pysam/calignedsegment.pyx":612
 *         s_idx += 1
 *     while s[s_idx] >= 'a':
 *         s_idx += 1             # <<<<<<<<<<<<<<
 * 
 *     seq = PyBytes_FromStringAndSize(s, s_idx)
 */
    __pyx_v_s_idx = (__pyx_v_s_idx + 1);
  }

  /* "pysam/calignedsegment.pyx":614
 *         s_idx += 1
 * 
 *     seq = PyBytes_FromStringAndSize(s, s_idx)             # <<<<<<<<<<<<<<
 *     free(s)
 * 
 */
  __pyx_t_5 = PyBytes_FromStringAndSize(__pyx_v_s, __pyx_v_s_idx); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_v_seq = ((PyObject*)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "pysam/calignedsegment.pyx":615
 * 
 *     seq = PyBytes_FromStringAndSize(s, s_idx)
 *     free(s)             # <<<<<<<<<<<<<<
 * 
 *     return seq
 */
  free(__pyx_v_s);

  /* "pysam/calignedsegment.pyx":617
 *     free(s)
 * 
 *     return seq             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_seq);
  __pyx_r = __pyx_v_seq;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":496
 * 
 * # TODO: avoid string copying for getSequenceInRange, reconstituneSequenceFromMD, ...
 * cdef inline bytes build_alignment_sequence(bam1_t * src):             # <<<<<<<<<<<<<<
 *     """return expanded sequence from MD tag.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignedsegment.build_alignment_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_r);
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":640
 * 
 *     # Now only called when instances are created from Python
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc(1, sizeof(bam1_t))
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment___init__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment___init__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 640, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":642
 *     def __init__(self):
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
 *         # allocate some memory. If size is 0, calloc does not return a
 *         # pointer that can be passed to free() so allocate 40 bytes
 */
  __pyx_v_self->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/calignedsegment.pyx":646
 *         # pointer that can be passed to free() so allocate 40 bytes
 *         # for a new read
 *         self._delegate.m_data = 40             # <<<<<<<<<<<<<<
 *         self._delegate.data = <uint8_t *>calloc(
 *             self._delegate.m_data, 1)
 */
  __pyx_v_self->_delegate->m_data = 40;

  /* "pysam/calignedsegment.pyx":647
 *         # for a new read
 *         self._delegate.m_data = 40
 *         self._delegate.data = <uint8_t *>calloc(             # <<<<<<<<<<<<<<
 *             self._delegate.m_data, 1)
 *         self._delegate.l_data = 0
 */
  __pyx_v_self->_delegate->data = ((uint8_t *)calloc(__pyx_v_self->_delegate->m_data, 1));

  /* "pysam/calignedsegment.pyx":649
 *         self._delegate.data = <uint8_t *>calloc(
 *             self._delegate.m_data, 1)
 *         self._delegate.l_data = 0             # <<<<<<<<<<<<<<
 * 
 *         # caching for selected fields
 */
  __pyx_v_self->_delegate->l_data = 0;

  /* "pysam/calignedsegment.pyx":652
 * 
 *         # caching for selected fields
 *         self.cache_query_qualities = None             # <<<<<<<<<<<<<<
 *         self.cache_query_alignment_qualities = None
 *         self.cache_query_sequence = None
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->cache_query_qualities);
  __Pyx_DECREF(__pyx_v_self->cache_query_qualities);
  __pyx_v_self->cache_query_qualities = Py_None;

  /* "pysam/calignedsegment.pyx":653
 *         # caching for selected fields
 *         self.cache_query_qualities = None
 *         self.cache_query_alignment_qualities = None             # <<<<<<<<<<<<<<
 *         self.cache_query_sequence = None
 *         self.cache_query_alignment_sequence = None
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities);
  __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities);
  __pyx_v_self->cache_query_alignment_qualities = Py_None;

  /* "pysam/calignedsegment.pyx":654
 *         self.cache_query_qualities = None
 *         self.cache_query_alignment_qualities = None
 *         self.cache_query_sequence = None             # <<<<<<<<<<<<<<
 *         self.cache_query_alignment_sequence = None
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->cache_query_sequence);
  __Pyx_DECREF(__pyx_v_self->cache_query_sequence);
  __pyx_v_self->cache_query_sequence = Py_None;

  /* "pysam/calignedsegment.pyx":655
 *         self.cache_query_alignment_qualities = None
 *         self.cache_query_sequence = None
 *         self.cache_query_alignment_sequence = None             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_sequence);
  __Pyx_DECREF(__pyx_v_self->cache_query_alignment_sequence);
  __pyx_v_self->cache_query_alignment_sequence = Py_None;

  /* "pysam/calignedsegment.pyx":640
 * 
 *     # Now only called when instances are created from Python
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc(1, sizeof(bam1_t))
 */

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

/* "pysam/calignedsegment.pyx":657
 *         self.cache_query_alignment_sequence = None
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self._delegate)
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_2__dealloc__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static void __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_2__dealloc__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 657, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 657; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":658
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  bam_destroy1(__pyx_v_self->_delegate);

  /* "pysam/calignedsegment.pyx":657
 *         self.cache_query_alignment_sequence = None
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self._delegate)
 * 
 */

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

/* "pysam/calignedsegment.pyx":660
 *         bam_destroy1(self._delegate)
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """return string representation of alignment.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5__str__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_4__str__[] = "return string representation of alignment.\n\n        The representation is an approximate :term:`SAM` format, because\n        an aligned read might not be associated with a :term:`AlignmentFile`.\n        As a result :term:`tid` is shown instead of the reference name.\n        Similarly, the tags field is returned in its parsed state.\n\n        To get a valid SAM record, use :meth:`tostring`.\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_15calignedsegment_14AlignedSegment_4__str__;
#endif
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4__str__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4__str__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 660, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":672
 *         # sam-parsing is done in sam.c/bam_format1_core which
 *         # requires a valid header.
 *         return "\t".join(map(str, (self.query_name,             # <<<<<<<<<<<<<<
 *                                    self.flag,
 *                                    self.reference_id,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/calignedsegment.pyx":673
 *         # requires a valid header.
 *         return "\t".join(map(str, (self.query_name,
 *                                    self.flag,             # <<<<<<<<<<<<<<
 *                                    self.reference_id,
 *                                    self.reference_start,
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignedsegment.pyx":674
 *         return "\t".join(map(str, (self.query_name,
 *                                    self.flag,
 *                                    self.reference_id,             # <<<<<<<<<<<<<<
 *                                    self.reference_start,
 *                                    self.mapping_quality,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignedsegment.pyx":675
 *                                    self.flag,
 *                                    self.reference_id,
 *                                    self.reference_start,             # <<<<<<<<<<<<<<
 *                                    self.mapping_quality,
 *                                    self.cigarstring,
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignedsegment.pyx":676
 *                                    self.reference_id,
 *                                    self.reference_start,
 *                                    self.mapping_quality,             # <<<<<<<<<<<<<<
 *                                    self.cigarstring,
 *                                    self.next_reference_id,
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/calignedsegment.pyx":677
 *                                    self.reference_start,
 *                                    self.mapping_quality,
 *                                    self.cigarstring,             # <<<<<<<<<<<<<<
 *                                    self.next_reference_id,
 *                                    self.next_reference_start,
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/calignedsegment.pyx":678
 *                                    self.mapping_quality,
 *                                    self.cigarstring,
 *                                    self.next_reference_id,             # <<<<<<<<<<<<<<
 *                                    self.next_reference_start,
 *                                    self.query_alignment_length,
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/calignedsegment.pyx":679
 *                                    self.cigarstring,
 *                                    self.next_reference_id,
 *                                    self.next_reference_start,             # <<<<<<<<<<<<<<
 *                                    self.query_alignment_length,
 *                                    self.query_sequence,
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/calignedsegment.pyx":680
 *                                    self.next_reference_id,
 *                                    self.next_reference_start,
 *                                    self.query_alignment_length,             # <<<<<<<<<<<<<<
 *                                    self.query_sequence,
 *                                    self.query_qualities,
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);

  /* "pysam/calignedsegment.pyx":681
 *                                    self.next_reference_start,
 *                                    self.query_alignment_length,
 *                                    self.query_sequence,             # <<<<<<<<<<<<<<
 *                                    self.query_qualities,
 *                                    self.tags)))
 */
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);

  /* "pysam/calignedsegment.pyx":682
 *                                    self.query_alignment_length,
 *                                    self.query_sequence,
 *                                    self.query_qualities,             # <<<<<<<<<<<<<<
 *                                    self.tags)))
 * 
 */
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);

  /* "pysam/calignedsegment.pyx":683
 *                                    self.query_sequence,
 *                                    self.query_qualities,
 *                                    self.tags)))             # <<<<<<<<<<<<<<
 * 
 *     def __copy__(self):
 */
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tags); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);

  /* "pysam/calignedsegment.pyx":672
 *         # sam-parsing is done in sam.c/bam_format1_core which
 *         # requires a valid header.
 *         return "\t".join(map(str, (self.query_name,             # <<<<<<<<<<<<<<
 *                                    self.flag,
 *                                    self.reference_id,
 */
  __pyx_t_13 = PyTuple_New(12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_13, 7, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_13, 8, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_13, 9, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_13, 10, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_13, 11, __pyx_t_12);
  __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_t_9 = 0;
  __pyx_t_10 = 0;
  __pyx_t_11 = 0;
  __pyx_t_12 = 0;
  __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_INCREF(((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_13);
  __pyx_t_13 = 0;
  __pyx_t_13 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_12, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyString_Join(__pyx_kp_s__19, __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_r = __pyx_t_12;
  __pyx_t_12 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":660
 *         bam_destroy1(self._delegate)
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """return string representation of alignment.
 * 
 */

  /* 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_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.__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;
}

/* "pysam/calignedsegment.pyx":685
 *                                    self.tags)))
 * 
 *     def __copy__(self):             # <<<<<<<<<<<<<<
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_7__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_6__copy__[] = "AlignedSegment.__copy__(self)";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_7__copy__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6__copy__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6__copy__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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("__copy__", 0);
  __Pyx_TraceCall("__copy__", __pyx_f[0], 685, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":686
 * 
 *     def __copy__(self):
 *         return makeAlignedSegment(self._delegate, self._alignment_file)             # <<<<<<<<<<<<<<
 * 
 *     def __deepcopy__(self, memo):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_v_self->_alignment_file);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_f_5pysam_15calignedsegment_makeAlignedSegment(__pyx_v_self->_delegate, ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":685
 *                                    self.tags)))
 * 
 *     def __copy__(self):             # <<<<<<<<<<<<<<
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.__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/calignedsegment.pyx":688
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 *     def __deepcopy__(self, memo):             # <<<<<<<<<<<<<<
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_8__deepcopy__[] = "AlignedSegment.__deepcopy__(self, memo)";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9__deepcopy__(PyObject *__pyx_v_self, PyObject *__pyx_v_memo) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8__deepcopy__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_memo));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8__deepcopy__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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("__deepcopy__", 0);
  __Pyx_TraceCall("__deepcopy__", __pyx_f[0], 688, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":689
 * 
 *     def __deepcopy__(self, memo):
 *         return makeAlignedSegment(self._delegate, self._alignment_file)             # <<<<<<<<<<<<<<
 * 
 *     def compare(self, AlignedSegment other):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_v_self->_alignment_file);
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = __pyx_f_5pysam_15calignedsegment_makeAlignedSegment(__pyx_v_self->_delegate, ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":688
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 *     def __deepcopy__(self, memo):             # <<<<<<<<<<<<<<
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.__deepcopy__", __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/calignedsegment.pyx":691
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 *     def compare(self, AlignedSegment other):             # <<<<<<<<<<<<<<
 *         '''return -1,0,1, if contents in this are binary
 *         <,=,> to *other*
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_10compare[] = "AlignedSegment.compare(self, AlignedSegment other)\nreturn -1,0,1, if contents in this are binary\n        <,=,> to *other*\n\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("compare (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_15calignedsegment_AlignedSegment, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10compare(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_other));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10compare(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_other) {
  int __pyx_v_retval;
  bam1_t *__pyx_v_t;
  bam1_t *__pyx_v_o;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__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("compare", 0);
  __Pyx_TraceCall("compare", __pyx_f[0], 691, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":701
 *         cdef bam1_t *o
 * 
 *         t = self._delegate             # <<<<<<<<<<<<<<
 *         o = other._delegate
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_t = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":702
 * 
 *         t = self._delegate
 *         o = other._delegate             # <<<<<<<<<<<<<<
 * 
 *         # uncomment for debugging purposes
 */
  __pyx_t_1 = __pyx_v_other->_delegate;
  __pyx_v_o = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":714
 * 
 *         # Fast-path test for object identity
 *         if t == o:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_2 = ((__pyx_v_t == __pyx_v_o) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":715
 *         # Fast-path test for object identity
 *         if t == o:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":714
 * 
 *         # Fast-path test for object identity
 *         if t == o:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":717
 *             return 0
 * 
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))             # <<<<<<<<<<<<<<
 * 
 *         if retval:
 */
  __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t)));

  /* "pysam/calignedsegment.pyx":719
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 * 
 *         if retval:             # <<<<<<<<<<<<<<
 *             return retval
 *         # cmp(t.l_data, o.l_data)
 */
  __pyx_t_2 = (__pyx_v_retval != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":720
 * 
 *         if retval:
 *             return retval             # <<<<<<<<<<<<<<
 *         # cmp(t.l_data, o.l_data)
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":719
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 * 
 *         if retval:             # <<<<<<<<<<<<<<
 *             return retval
 *         # cmp(t.l_data, o.l_data)
 */
  }

  /* "pysam/calignedsegment.pyx":722
 *             return retval
 *         # cmp(t.l_data, o.l_data)
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)             # <<<<<<<<<<<<<<
 *         if retval:
 *             return retval
 */
  __pyx_v_retval = ((__pyx_v_t->l_data > __pyx_v_o->l_data) - (__pyx_v_t->l_data < __pyx_v_o->l_data));

  /* "pysam/calignedsegment.pyx":723
 *         # cmp(t.l_data, o.l_data)
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)
 *         if retval:             # <<<<<<<<<<<<<<
 *             return retval
 *         return memcmp(t.data, o.data, t.l_data)
 */
  __pyx_t_2 = (__pyx_v_retval != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":724
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)
 *         if retval:
 *             return retval             # <<<<<<<<<<<<<<
 *         return memcmp(t.data, o.data, t.l_data)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":723
 *         # cmp(t.l_data, o.l_data)
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)
 *         if retval:             # <<<<<<<<<<<<<<
 *             return retval
 *         return memcmp(t.data, o.data, t.l_data)
 */
  }

  /* "pysam/calignedsegment.pyx":725
 *         if retval:
 *             return retval
 *         return memcmp(t.data, o.data, t.l_data)             # <<<<<<<<<<<<<<
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_From_int(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->l_data)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":691
 *         return makeAlignedSegment(self._delegate, self._alignment_file)
 * 
 *     def compare(self, AlignedSegment other):             # <<<<<<<<<<<<<<
 *         '''return -1,0,1, if contents in this are binary
 *         <,=,> to *other*
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.compare", __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/calignedsegment.pyx":727
 *         return memcmp(t.data, o.data, t.l_data)
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):             # <<<<<<<<<<<<<<
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_15calignedsegment_AlignedSegment, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12__richcmp__(((PyObject *)__pyx_v_self), ((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_other), ((int)__pyx_v_op));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12__richcmp__(PyObject *__pyx_v_self, struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_other, int __pyx_v_op) {
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__richcmp__", 0);
  __Pyx_TraceCall("__richcmp__", __pyx_f[0], 727, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":728
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):
 *         if op == 2:  # == operator             # <<<<<<<<<<<<<<
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator
 */
  switch (__pyx_v_op) {
    case 2:

    /* "pysam/calignedsegment.pyx":729
 *     def __richcmp__(self, AlignedSegment other, int op):
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0             # <<<<<<<<<<<<<<
 *         elif op == 3:  # != operator
 *             return self.compare(other) != 0
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_compare); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_other));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_1, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 729; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":728
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):
 *         if op == 2:  # == operator             # <<<<<<<<<<<<<<
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator
 */
    break;

    /* "pysam/calignedsegment.pyx":730
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator             # <<<<<<<<<<<<<<
 *             return self.compare(other) != 0
 *         else:
 */
    case 3:

    /* "pysam/calignedsegment.pyx":731
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator
 *             return self.compare(other) != 0             # <<<<<<<<<<<<<<
 *         else:
 *             return NotImplemented
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, ((PyObject *)__pyx_v_other));
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":730
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator             # <<<<<<<<<<<<<<
 *             return self.compare(other) != 0
 *         else:
 */
    break;
    default:

    /* "pysam/calignedsegment.pyx":733
 *             return self.compare(other) != 0
 *         else:
 *             return NotImplemented             # <<<<<<<<<<<<<<
 * 
 *     def __hash__(self):
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_builtin_NotImplemented);
    __pyx_r = __pyx_builtin_NotImplemented;
    goto __pyx_L0;
    break;
  }

  /* "pysam/calignedsegment.pyx":727
 *         return memcmp(t.data, o.data, t.l_data)
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):             # <<<<<<<<<<<<<<
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 */

  /* 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.calignedsegment.AlignedSegment.__richcmp__", __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/calignedsegment.pyx":735
 *             return NotImplemented
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         cdef bam1_t * src
 *         src = self._delegate
 */

/* Python wrapper */
static Py_hash_t __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15__hash__(PyObject *__pyx_v_self); /*proto*/
static Py_hash_t __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15__hash__(PyObject *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14__hash__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static Py_hash_t __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14__hash__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_hash_value;
  Py_hash_t __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__hash__", 0);
  __Pyx_TraceCall("__hash__", __pyx_f[0], 735, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 735; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":737
 *     def __hash__(self):
 *         cdef bam1_t * src
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         # shift and xor values in the core structure
 *         # make sure tid and mtid are shifted by different amounts
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":746
 *             src.core.flag ^ \
 *             src.core.isize << 24 ^ \
 *             src.core.mtid << 16 ^ \             # <<<<<<<<<<<<<<
 *             src.core.mpos << 8
 * 
 */
  __pyx_v_hash_value = (((((((__pyx_v_src->core.tid << 24) ^ (__pyx_v_src->core.pos << 16)) ^ (__pyx_v_src->core.qual << 8)) ^ __pyx_v_src->core.flag) ^ (__pyx_v_src->core.isize << 24)) ^ (__pyx_v_src->core.mtid << 16)) ^ (__pyx_v_src->core.mpos << 8));

  /* "pysam/calignedsegment.pyx":749
 *             src.core.mpos << 8
 * 
 *         return hash_value             # <<<<<<<<<<<<<<
 * 
 *     cpdef tostring(self, AlignmentFile_t htsfile):
 */
  __pyx_r = __pyx_v_hash_value;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":735
 *             return NotImplemented
 * 
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         cdef bam1_t * src
 *         src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":751
 *         return hash_value
 * 
 *     cpdef tostring(self, AlignmentFile_t htsfile):             # <<<<<<<<<<<<<<
 *         """returns a string representation of the aligned segment.
 * 
 */

static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17tostring(PyObject *__pyx_v_self, PyObject *__pyx_v_htsfile); /*proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_tostring(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_15calignedsegment_AlignmentFile_t __pyx_v_htsfile, int __pyx_skip_dispatch) {
  kstring_t __pyx_v_line;
  PyObject *__pyx_v_ret = NULL;
  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;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("tostring", 0);
  __Pyx_TraceCall("tostring", __pyx_f[0], 751, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tostring); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17tostring)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_htsfile)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_INCREF(((PyObject *)__pyx_v_htsfile));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_htsfile));
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_htsfile));
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignedsegment.pyx":764
 * 
 *         cdef kstring_t line
 *         line.l = line.m = 0             # <<<<<<<<<<<<<<
 *         line.s = NULL
 * 
 */
  __pyx_v_line.l = 0;
  __pyx_v_line.m = 0;

  /* "pysam/calignedsegment.pyx":765
 *         cdef kstring_t line
 *         line.l = line.m = 0
 *         line.s = NULL             # <<<<<<<<<<<<<<
 * 
 *         if sam_format1(htsfile.header, self._delegate, &line) < 0:
 */
  __pyx_v_line.s = NULL;

  /* "pysam/calignedsegment.pyx":767
 *         line.s = NULL
 * 
 *         if sam_format1(htsfile.header, self._delegate, &line) < 0:             # <<<<<<<<<<<<<<
 *             if line.m:
 *                 free(line.s)
 */
  __pyx_t_6 = ((sam_format1(__pyx_v_htsfile->header, __pyx_v_self->_delegate, (&__pyx_v_line)) < 0) != 0);
  if (__pyx_t_6) {

    /* "pysam/calignedsegment.pyx":768
 * 
 *         if sam_format1(htsfile.header, self._delegate, &line) < 0:
 *             if line.m:             # <<<<<<<<<<<<<<
 *                 free(line.s)
 *             raise ValueError('sam_format failed')
 */
    __pyx_t_6 = (__pyx_v_line.m != 0);
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":769
 *         if sam_format1(htsfile.header, self._delegate, &line) < 0:
 *             if line.m:
 *                 free(line.s)             # <<<<<<<<<<<<<<
 *             raise ValueError('sam_format failed')
 * 
 */
      free(__pyx_v_line.s);

      /* "pysam/calignedsegment.pyx":768
 * 
 *         if sam_format1(htsfile.header, self._delegate, &line) < 0:
 *             if line.m:             # <<<<<<<<<<<<<<
 *                 free(line.s)
 *             raise ValueError('sam_format failed')
 */
    }

    /* "pysam/calignedsegment.pyx":770
 *             if line.m:
 *                 free(line.s)
 *             raise ValueError('sam_format failed')             # <<<<<<<<<<<<<<
 * 
 *         ret = force_str(line.s[:line.l])
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":767
 *         line.s = NULL
 * 
 *         if sam_format1(htsfile.header, self._delegate, &line) < 0:             # <<<<<<<<<<<<<<
 *             if line.m:
 *                 free(line.s)
 */
  }

  /* "pysam/calignedsegment.pyx":772
 *             raise ValueError('sam_format failed')
 * 
 *         ret = force_str(line.s[:line.l])             # <<<<<<<<<<<<<<
 * 
 *         if line.m:
 */
  __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_line.s + 0, __pyx_v_line.l - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_f_5pysam_6cutils_force_str(__pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ret = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":774
 *         ret = force_str(line.s[:line.l])
 * 
 *         if line.m:             # <<<<<<<<<<<<<<
 *             free(line.s)
 * 
 */
  __pyx_t_6 = (__pyx_v_line.m != 0);
  if (__pyx_t_6) {

    /* "pysam/calignedsegment.pyx":775
 * 
 *         if line.m:
 *             free(line.s)             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
    free(__pyx_v_line.s);

    /* "pysam/calignedsegment.pyx":774
 *         ret = force_str(line.s[:line.l])
 * 
 *         if line.m:             # <<<<<<<<<<<<<<
 *             free(line.s)
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":777
 *             free(line.s)
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     ########################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ret);
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":751
 *         return hash_value
 * 
 *     cpdef tostring(self, AlignmentFile_t htsfile):             # <<<<<<<<<<<<<<
 *         """returns a string representation of the aligned segment.
 * 
 */

  /* 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_AddTraceback("pysam.calignedsegment.AlignedSegment.tostring", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ret);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17tostring(PyObject *__pyx_v_self, PyObject *__pyx_v_htsfile); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_16tostring[] = "AlignedSegment.tostring(self, AlignmentFile_t htsfile)\nreturns a string representation of the aligned segment.\n\n        The output format is valid SAM format.\n\n        Parameters\n        ----------\n\n        htsfile -- AlignmentFile object to map numerical\n                   identifers to chromosome names.\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17tostring(PyObject *__pyx_v_self, PyObject *__pyx_v_htsfile) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tostring (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_htsfile), __pyx_ptype_5pysam_14calignmentfile_AlignmentFile, 1, "htsfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16tostring(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((__pyx_t_5pysam_15calignedsegment_AlignmentFile_t)__pyx_v_htsfile));

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16tostring(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, __pyx_t_5pysam_15calignedsegment_AlignmentFile_t __pyx_v_htsfile) {
  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("tostring", 0);
  __Pyx_TraceCall("tostring", __pyx_f[0], 751, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_15calignedsegment_14AlignedSegment_tostring(__pyx_v_self, __pyx_v_htsfile, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 751; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.tostring", __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/calignedsegment.pyx":783
 *     property query_name:
 *         """the query template name (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10query_name___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10query_name___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 783, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":785
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_l_qname(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":786
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if pysam_get_l_qname(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return charptr_to_str(<char *>pysam_bam_get_qname(src))
 */
  __pyx_t_2 = ((pysam_get_l_qname(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":787
 *             src = self._delegate
 *             if pysam_get_l_qname(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":786
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if pysam_get_l_qname(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return charptr_to_str(<char *>pysam_bam_get_qname(src))
 */
  }

  /* "pysam/calignedsegment.pyx":788
 *             if pysam_get_l_qname(src) == 0:
 *                 return None
 *             return charptr_to_str(<char *>pysam_bam_get_qname(src))             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, qname):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_5pysam_6cutils_charptr_to_str(((char *)pysam_bam_get_qname(__pyx_v_src)), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 788; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":783
 *     property query_name:
 *         """the query template name (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_name.__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/calignedsegment.pyx":790
 *             return charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 *         def __set__(self, qname):             # <<<<<<<<<<<<<<
 *             if qname is None or len(qname) == 0:
 *                 return
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10query_name_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qname));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10query_name_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qname) {
  bam1_t *__pyx_v_src;
  int __pyx_v_l;
  char *__pyx_v_p;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  bam1_t *__pyx_t_6;
  char const *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 790, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 790; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_INCREF(__pyx_v_qname);

  /* "pysam/calignedsegment.pyx":791
 * 
 *         def __set__(self, qname):
 *             if qname is None or len(qname) == 0:             # <<<<<<<<<<<<<<
 *                 return
 *             qname = force_bytes(qname)
 */
  __pyx_t_2 = (__pyx_v_qname == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = ((__pyx_t_4 == 0) != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":792
 *         def __set__(self, qname):
 *             if qname is None or len(qname) == 0:
 *                 return             # <<<<<<<<<<<<<<
 *             qname = force_bytes(qname)
 *             cdef bam1_t * src
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":791
 * 
 *         def __set__(self, qname):
 *             if qname is None or len(qname) == 0:             # <<<<<<<<<<<<<<
 *                 return
 *             qname = force_bytes(qname)
 */
  }

  /* "pysam/calignedsegment.pyx":793
 *             if qname is None or len(qname) == 0:
 *                 return
 *             qname = force_bytes(qname)             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef int l
 */
  __pyx_t_5 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_qname, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF_SET(__pyx_v_qname, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pysam/calignedsegment.pyx":798
 *             cdef char * p
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = pysam_bam_get_qname(src)
 * 
 */
  __pyx_t_6 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_6;

  /* "pysam/calignedsegment.pyx":799
 * 
 *             src = self._delegate
 *             p = pysam_bam_get_qname(src)             # <<<<<<<<<<<<<<
 * 
 *             # the qname is \0 terminated
 */
  __pyx_v_p = pysam_bam_get_qname(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":802
 * 
 *             # the qname is \0 terminated
 *             l = len(qname) + 1             # <<<<<<<<<<<<<<
 *             pysam_bam_update(src,
 *                              pysam_get_l_qname(src),
 */
  __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = (__pyx_t_4 + 1);

  /* "pysam/calignedsegment.pyx":803
 *             # the qname is \0 terminated
 *             l = len(qname) + 1
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              pysam_get_l_qname(src),
 *                              l,
 */
  pysam_bam_update(__pyx_v_src, pysam_get_l_qname(__pyx_v_src), __pyx_v_l, ((uint8_t *)__pyx_v_p));

  /* "pysam/calignedsegment.pyx":809
 * 
 * 
 *             pysam_set_l_qname(src, l)             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  pysam_set_l_qname(__pyx_v_src, __pyx_v_l);

  /* "pysam/calignedsegment.pyx":813
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = pysam_bam_get_qname(src)             # <<<<<<<<<<<<<<
 * 
 *             strncpy(p, qname, l)
 */
  __pyx_v_p = pysam_bam_get_qname(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":815
 *             p = pysam_bam_get_qname(src)
 * 
 *             strncpy(p, qname, l)             # <<<<<<<<<<<<<<
 * 
 *     property flag:
 */
  __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  strncpy(__pyx_v_p, __pyx_t_7, __pyx_v_l);

  /* "pysam/calignedsegment.pyx":790
 *             return charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 *         def __set__(self, qname):             # <<<<<<<<<<<<<<
 *             if qname is None or len(qname) == 0:
 *                 return
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qname);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":819
 *     property flag:
 *         """properties flag"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4flag___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4flag___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 819, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":820
 *         """properties flag"""
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, flag):
 *             pysam_set_flag(self._delegate, flag)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_flag(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":819
 *     property flag:
 *         """properties flag"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.flag.__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/calignedsegment.pyx":821
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):             # <<<<<<<<<<<<<<
 *             pysam_set_flag(self._delegate, flag)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4flag_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_flag));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4flag_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_flag) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 821, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":822
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 *             pysam_set_flag(self._delegate, flag)             # <<<<<<<<<<<<<<
 * 
 *     property reference_name:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_flag(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/calignedsegment.pyx":821
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):             # <<<<<<<<<<<<<<
 *             pysam_set_flag(self._delegate, flag)
 * 
 */

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

/* "pysam/calignedsegment.pyx":826
 *     property reference_name:
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.tid)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14reference_name_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14reference_name___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14reference_name___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __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;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 826, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":827
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):
 *             if self._alignment_file is not None:             # <<<<<<<<<<<<<<
 *                 return self._alignment_file.getrname(self._delegate.core.tid)
 *             return None
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->_alignment_file) != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":828
 *         def __get__(self):
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.tid)             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_alignment_file), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":827
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):
 *             if self._alignment_file is not None:             # <<<<<<<<<<<<<<
 *                 return self._alignment_file.getrname(self._delegate.core.tid)
 *             return None
 */
  }

  /* "pysam/calignedsegment.pyx":829
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.tid)
 *             return None             # <<<<<<<<<<<<<<
 * 
 *     property reference_id:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":826
 *     property reference_name:
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.tid)
 */

  /* 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_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.reference_name.__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/calignedsegment.pyx":842
 * 
 *         """
 *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
 *         def __set__(self, tid): self._delegate.core.tid = tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12reference_id___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12reference_id___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 842, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.reference_id.__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/calignedsegment.pyx":843
 *         """
 *         def __get__(self): return self._delegate.core.tid
 *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
 * 
 *     property reference_start:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12reference_id_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12reference_id_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 843, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 843; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.tid = __pyx_t_1;

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

/* "pysam/calignedsegment.pyx":847
 *     property reference_start:
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos             # <<<<<<<<<<<<<<
 *         def __set__(self, pos):
 *             ## setting the position requires updating the "bin" attribute
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15reference_start___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15reference_start___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 847, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 847; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.reference_start.__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/calignedsegment.pyx":848
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos
 *         def __set__(self, pos):             # <<<<<<<<<<<<<<
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15reference_start_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_pos));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15reference_start_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_pos) {
  bam1_t *__pyx_v_src;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int32_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 848, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 848; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":851
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":852
 *             cdef bam1_t * src
 *             src = self._delegate
 *             src.core.pos = pos             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src):
 *                 pysam_set_bin(src,
 */
  __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_2 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_src->core.pos = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":853
 *             src = self._delegate
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 pysam_set_bin(src,
 *                               hts_reg2bin(
 */
  __pyx_t_3 = (pysam_get_n_cigar(__pyx_v_src) != 0);
  if (__pyx_t_3) {

    /* "pysam/calignedsegment.pyx":854
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):
 *                 pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                               hts_reg2bin(
 *                                   src.core.pos,
 */
    pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5));

    /* "pysam/calignedsegment.pyx":853
 *             src = self._delegate
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 pysam_set_bin(src,
 *                               hts_reg2bin(
 */
    goto __pyx_L3;
  }

  /* "pysam/calignedsegment.pyx":861
 *                                   5))
 *             else:
 *                 pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                               hts_reg2bin(
 *                                   src.core.pos,
 */
  /*else*/ {

    /* "pysam/calignedsegment.pyx":862
 *             else:
 *                 pysam_set_bin(src,
 *                               hts_reg2bin(             # <<<<<<<<<<<<<<
 *                                   src.core.pos,
 *                                   src.core.pos + 1,
 */
    pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1), 14, 5));
  }
  __pyx_L3:;

  /* "pysam/calignedsegment.pyx":848
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos
 *         def __set__(self, pos):             # <<<<<<<<<<<<<<
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 */

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

/* "pysam/calignedsegment.pyx":870
 *     property mapping_quality:
 *         """mapping quality"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 870, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 870; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":871
 *         """mapping quality"""
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, qual):
 *             pysam_set_qual(self._delegate, qual)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t(pysam_get_qual(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":870
 *     property mapping_quality:
 *         """mapping quality"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.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/calignedsegment.pyx":872
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             pysam_set_qual(self._delegate, qual)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint8_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 872, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 872; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":873
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 *             pysam_set_qual(self._delegate, qual)             # <<<<<<<<<<<<<<
 * 
 *     property cigarstring:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint8_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_qual(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/calignedsegment.pyx":872
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             pysam_set_qual(self._delegate, qual)
 * 
 */

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

/* "pysam/calignedsegment.pyx":892
 *         empty string.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             c = self.cigartuples
 *             if c is None:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigarstring___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigarstring___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_v_c = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  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;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  Py_ssize_t __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 892, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":893
 *         '''
 *         def __get__(self):
 *             c = self.cigartuples             # <<<<<<<<<<<<<<
 *             if c is None:
 *                 return None
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_c = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":894
 *         def __get__(self):
 *             c = self.cigartuples
 *             if c is None:             # <<<<<<<<<<<<<<
 *                 return None
 *             # reverse order
 */
  __pyx_t_2 = (__pyx_v_c == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/calignedsegment.pyx":895
 *             c = self.cigartuples
 *             if c is None:
 *                 return None             # <<<<<<<<<<<<<<
 *             # reverse order
 *             else:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":894
 *         def __get__(self):
 *             c = self.cigartuples
 *             if c is None:             # <<<<<<<<<<<<<<
 *                 return None
 *             # reverse order
 */
  }

  /* "pysam/calignedsegment.pyx":898
 *             # reverse order
 *             else:
 *                 return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, cigar):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_v_c)) || PyTuple_CheckExact(__pyx_v_c)) {
      __pyx_t_4 = __pyx_v_c; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_4))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          #endif
        }
      } else {
        __pyx_t_7 = __pyx_t_6(__pyx_t_4);
        if (unlikely(!__pyx_t_7)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_7);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
        PyObject* sequence = __pyx_t_7;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        #else
        __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        #endif
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
        index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_8);
      __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_7 = __Pyx_PyInt_From_char((__pyx_v_5pysam_15calignedsegment_CODE2CIGAR[__pyx_t_12])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_v_y);
      __Pyx_GIVEREF(__pyx_v_y);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_y);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_i_c, __pyx_t_9); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 898; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignedsegment.pyx":892
 *         empty string.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             c = self.cigartuples
 *             if c is None:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.cigarstring.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_c);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":900
 *                 return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
 * 
 *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigartuples = []
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_cigar));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_cigar) {
  PyObject *__pyx_v_parts = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_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)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  long __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 900, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 900; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":901
 * 
 *         def __set__(self, cigar):
 *             if cigar is None or len(cigar) == 0:             # <<<<<<<<<<<<<<
 *                 self.cigartuples = []
 *             else:
 */
  __pyx_t_2 = (__pyx_v_cigar == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = ((__pyx_t_4 == 0) != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":902
 *         def __set__(self, cigar):
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigartuples = []             # <<<<<<<<<<<<<<
 *             else:
 *                 parts = CIGAR_REGEX.findall(cigar)
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "pysam/calignedsegment.pyx":901
 * 
 *         def __set__(self, cigar):
 *             if cigar is None or len(cigar) == 0:             # <<<<<<<<<<<<<<
 *                 self.cigartuples = []
 *             else:
 */
    goto __pyx_L3;
  }

  /* "pysam/calignedsegment.pyx":904
 *                 self.cigartuples = []
 *             else:
 *                 parts = CIGAR_REGEX.findall(cigar)             # <<<<<<<<<<<<<<
 *                 # reverse order
 *                 self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts]
 */
  /*else*/ {
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_REGEX); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_findall); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_cigar); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_cigar);
      __Pyx_GIVEREF(__pyx_v_cigar);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_cigar);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_parts = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "pysam/calignedsegment.pyx":906
 *                 parts = CIGAR_REGEX.findall(cigar)
 *                 # reverse order
 *                 self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts]             # <<<<<<<<<<<<<<
 * 
 *     # TODO
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    if (likely(PyList_CheckExact(__pyx_v_parts)) || PyTuple_CheckExact(__pyx_v_parts)) {
      __pyx_t_7 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_7); __pyx_t_4 = 0;
      __pyx_t_9 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_9)) {
        if (likely(PyList_CheckExact(__pyx_t_7))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          #endif
        }
      } else {
        __pyx_t_8 = __pyx_t_9(__pyx_t_7);
        if (unlikely(!__pyx_t_8)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_8);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
        PyObject* sequence = __pyx_t_8;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_10);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_6)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_12 = NULL;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L9_unpacking_done;
        __pyx_L8_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L9_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR2CODE); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_13 = __Pyx_PyObject_Ord(__pyx_v_y); if (unlikely(__pyx_t_13 == (long)(Py_UCS4)-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_8, __pyx_t_13, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_Int(__pyx_v_x); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_8);
      __pyx_t_10 = 0;
      __pyx_t_8 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_6))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_L3:;

  /* "pysam/calignedsegment.pyx":900
 *                 return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
 * 
 *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigartuples = []
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __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_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.cigarstring.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_parts);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":914
 *     property next_reference_id:
 *         """the :term:`reference` id of the mate/next read."""
 *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
 *         def __set__(self, mtid):
 *             self._delegate.core.mtid = mtid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 914, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 914; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 914; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.next_reference_id.__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/calignedsegment.pyx":915
 *         """the :term:`reference` id of the mate/next read."""
 *         def __get__(self): return self._delegate.core.mtid
 *         def __set__(self, mtid):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mtid = mtid
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mtid));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 915, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":916
 *         def __get__(self): return self._delegate.core.mtid
 *         def __set__(self, mtid):
 *             self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
 * 
 *     property next_reference_name:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 916; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mtid = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":915
 *         """the :term:`reference` id of the mate/next read."""
 *         def __get__(self): return self._delegate.core.mtid
 *         def __set__(self, mtid):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mtid = mtid
 * 
 */

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

/* "pysam/calignedsegment.pyx":921
 *         """:term:`reference` name of the mate/next read (None if no
 *         AlignmentFile is associated)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.mtid)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19next_reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19next_reference_name_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_19next_reference_name___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_19next_reference_name___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __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;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 921, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 921; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":922
 *         AlignmentFile is associated)"""
 *         def __get__(self):
 *             if self._alignment_file is not None:             # <<<<<<<<<<<<<<
 *                 return self._alignment_file.getrname(self._delegate.core.mtid)
 *             return None
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->_alignment_file) != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":923
 *         def __get__(self):
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.mtid)             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_alignment_file), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":922
 *         AlignmentFile is associated)"""
 *         def __get__(self):
 *             if self._alignment_file is not None:             # <<<<<<<<<<<<<<
 *                 return self._alignment_file.getrname(self._delegate.core.mtid)
 *             return None
 */
  }

  /* "pysam/calignedsegment.pyx":924
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.mtid)
 *             return None             # <<<<<<<<<<<<<<
 * 
 *     property next_reference_start:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":921
 *         """:term:`reference` name of the mate/next read (None if no
 *         AlignmentFile is associated)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self._delegate.core.mtid)
 */

  /* 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_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.next_reference_name.__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/calignedsegment.pyx":928
 *     property next_reference_start:
 *         """the position of the mate/next read."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 928, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 928; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":929
 *         """the position of the mate/next read."""
 *         def __get__(self):
 *             return self._delegate.core.mpos             # <<<<<<<<<<<<<<
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":928
 *     property next_reference_start:
 *         """the position of the mate/next read."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.next_reference_start.__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/calignedsegment.pyx":930
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mpos));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 930, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 930; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":931
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
 * 
 *     property query_length:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mpos = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":930
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

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

/* "pysam/calignedsegment.pyx":951
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.l_qseq
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12query_length___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12query_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 951, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 951; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":952
 *         """
 *         def __get__(self):
 *             return self._delegate.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     property template_length:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":951
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.l_qseq
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_length.__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/calignedsegment.pyx":956
 *     property template_length:
 *         """the observed query template length"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15template_length___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15template_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 956, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":957
 *         """the observed query template length"""
 *         def __get__(self):
 *             return self._delegate.core.isize             # <<<<<<<<<<<<<<
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":956
 *     property template_length:
 *         """the observed query template length"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.template_length.__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/calignedsegment.pyx":958
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15template_length_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_isize));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15template_length_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 958, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 958; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":959
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
 * 
 *     property query_sequence:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.isize = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":958
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 * 
 */

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

/* "pysam/calignedsegment.pyx":977
 *         sequence.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.cache_query_sequence:
 *                 return self.cache_query_sequence
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14query_sequence___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14query_sequence___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  bam1_t *__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("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 977, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":978
 *         """
 *         def __get__(self):
 *             if self.cache_query_sequence:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_sequence
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_sequence); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":979
 *         def __get__(self):
 *             if self.cache_query_sequence:
 *                 return self.cache_query_sequence             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->cache_query_sequence);
    __pyx_r = __pyx_v_self->cache_query_sequence;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":978
 *         """
 *         def __get__(self):
 *             if self.cache_query_sequence:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_sequence
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":983
 *             cdef bam1_t * src
 *             cdef char * s
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0:
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":985
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":986
 * 
 *             if src.core.l_qseq == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             self.cache_query_sequence = force_str(getSequenceInRange(
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":985
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":988
 *                 return None
 * 
 *             self.cache_query_sequence = force_str(getSequenceInRange(             # <<<<<<<<<<<<<<
 *                 src, 0, src.core.l_qseq))
 *             return self.cache_query_sequence
 */
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getSequenceInRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __pyx_f_5pysam_6cutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_GOTREF(__pyx_v_self->cache_query_sequence);
  __Pyx_DECREF(__pyx_v_self->cache_query_sequence);
  __pyx_v_self->cache_query_sequence = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysam/calignedsegment.pyx":990
 *             self.cache_query_sequence = force_str(getSequenceInRange(
 *                 src, 0, src.core.l_qseq))
 *             return self.cache_query_sequence             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, seq):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cache_query_sequence);
  __pyx_r = __pyx_v_self->cache_query_sequence;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":977
 *         sequence.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.cache_query_sequence:
 *                 return self.cache_query_sequence
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_sequence.__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/calignedsegment.pyx":992
 *             return self.cache_query_sequence
 * 
 *         def __set__(self, seq):             # <<<<<<<<<<<<<<
 *             # samtools manages sequence and quality length memory together
 *             # if no quality information is present, the first byte says 0xff.
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_seq));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_seq) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_p;
  char *__pyx_v_s;
  int __pyx_v_l;
  int __pyx_v_k;
  Py_ssize_t __pyx_v_nbytes_new;
  Py_ssize_t __pyx_v_nbytes_old;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  bam1_t *__pyx_t_4;
  char *__pyx_t_5;
  int __pyx_t_6;
  long __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 992, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_INCREF(__pyx_v_seq);

  /* "pysam/calignedsegment.pyx":1001
 *             cdef Py_ssize_t nbytes_new, nbytes_old
 * 
 *             if seq == None:             # <<<<<<<<<<<<<<
 *                 l = 0
 *             else:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1002
 * 
 *             if seq == None:
 *                 l = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 l = len(seq)
 */
    __pyx_v_l = 0;

    /* "pysam/calignedsegment.pyx":1001
 *             cdef Py_ssize_t nbytes_new, nbytes_old
 * 
 *             if seq == None:             # <<<<<<<<<<<<<<
 *                 l = 0
 *             else:
 */
    goto __pyx_L3;
  }

  /* "pysam/calignedsegment.pyx":1004
 *                 l = 0
 *             else:
 *                 l = len(seq)             # <<<<<<<<<<<<<<
 *                 seq = force_bytes(seq)
 * 
 */
  /*else*/ {
    __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1004; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_l = __pyx_t_3;

    /* "pysam/calignedsegment.pyx":1005
 *             else:
 *                 l = len(seq)
 *                 seq = force_bytes(seq)             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
    __pyx_t_1 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1005; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_seq, __pyx_t_1);
    __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "pysam/calignedsegment.pyx":1007
 *                 seq = force_bytes(seq)
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             # as the sequence is stored in half-bytes, the total length (sequence
 */
  __pyx_t_4 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":1011
 *             # as the sequence is stored in half-bytes, the total length (sequence
 *             # plus quality scores) is (l+1)/2 + l
 *             nbytes_new = (l + 1) / 2 + l             # <<<<<<<<<<<<<<
 *             nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq
 * 
 */
  __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l);

  /* "pysam/calignedsegment.pyx":1012
 *             # plus quality scores) is (l+1)/2 + l
 *             nbytes_new = (l + 1) / 2 + l
 *             nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *             # acquire pointer to location in memory
 */
  __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq);

  /* "pysam/calignedsegment.pyx":1015
 * 
 *             # acquire pointer to location in memory
 *             p = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 *             src.core.l_qseq = l
 * 
 */
  __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1016
 *             # acquire pointer to location in memory
 *             p = pysam_bam_get_seq(src)
 *             src.core.l_qseq = l             # <<<<<<<<<<<<<<
 * 
 *             # change length of data field
 */
  __pyx_v_src->core.l_qseq = __pyx_v_l;

  /* "pysam/calignedsegment.pyx":1019
 * 
 *             # change length of data field
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              nbytes_old,
 *                              nbytes_new,
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p);

  /* "pysam/calignedsegment.pyx":1024
 *                              p)
 * 
 *             if l > 0:             # <<<<<<<<<<<<<<
 *                 # re-acquire pointer to location in memory
 *                 # as it might have moved
 */
  __pyx_t_2 = ((__pyx_v_l > 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1027
 *                 # re-acquire pointer to location in memory
 *                 # as it might have moved
 *                 p = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 *                 for k from 0 <= k < nbytes_new:
 *                     p[k] = 0
 */
    __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

    /* "pysam/calignedsegment.pyx":1028
 *                 # as it might have moved
 *                 p = pysam_bam_get_seq(src)
 *                 for k from 0 <= k < nbytes_new:             # <<<<<<<<<<<<<<
 *                     p[k] = 0
 *                 # convert to C string
 */
    __pyx_t_3 = __pyx_v_nbytes_new;
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_3; __pyx_v_k++) {

      /* "pysam/calignedsegment.pyx":1029
 *                 p = pysam_bam_get_seq(src)
 *                 for k from 0 <= k < nbytes_new:
 *                     p[k] = 0             # <<<<<<<<<<<<<<
 *                 # convert to C string
 *                 s = seq
 */
      (__pyx_v_p[__pyx_v_k]) = 0;
    }

    /* "pysam/calignedsegment.pyx":1031
 *                     p[k] = 0
 *                 # convert to C string
 *                 s = seq             # <<<<<<<<<<<<<<
 *                 for k from 0 <= k < l:
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)
 */
    __pyx_t_5 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_s = __pyx_t_5;

    /* "pysam/calignedsegment.pyx":1032
 *                 # convert to C string
 *                 s = seq
 *                 for k from 0 <= k < l:             # <<<<<<<<<<<<<<
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)
 * 
 */
    __pyx_t_6 = __pyx_v_l;
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {

      /* "pysam/calignedsegment.pyx":1033
 *                 s = seq
 *                 for k from 0 <= k < l:
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)             # <<<<<<<<<<<<<<
 * 
 *                 # erase qualities
 */
      __pyx_t_7 = __Pyx_div_long(__pyx_v_k, 2);
      (__pyx_v_p[__pyx_t_7]) = ((__pyx_v_p[__pyx_t_7]) | ((seq_nt16_table[((unsigned char)(__pyx_v_s[__pyx_v_k]))]) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))));
    }

    /* "pysam/calignedsegment.pyx":1036
 * 
 *                 # erase qualities
 *                 p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *                 p[0] = 0xff
 * 
 */
    __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

    /* "pysam/calignedsegment.pyx":1037
 *                 # erase qualities
 *                 p = pysam_bam_get_qual(src)
 *                 p[0] = 0xff             # <<<<<<<<<<<<<<
 * 
 *             self.cache_query_sequence = force_str(seq)
 */
    (__pyx_v_p[0]) = 0xff;

    /* "pysam/calignedsegment.pyx":1024
 *                              p)
 * 
 *             if l > 0:             # <<<<<<<<<<<<<<
 *                 # re-acquire pointer to location in memory
 *                 # as it might have moved
 */
  }

  /* "pysam/calignedsegment.pyx":1039
 *                 p[0] = 0xff
 * 
 *             self.cache_query_sequence = force_str(seq)             # <<<<<<<<<<<<<<
 * 
 *             # clear cached values for quality values
 */
  __pyx_t_1 = __pyx_f_5pysam_6cutils_force_str(__pyx_v_seq, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->cache_query_sequence);
  __Pyx_DECREF(__pyx_v_self->cache_query_sequence);
  __pyx_v_self->cache_query_sequence = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":1042
 * 
 *             # clear cached values for quality values
 *             self.cache_query_qualities = None             # <<<<<<<<<<<<<<
 *             self.cache_query_alignment_qualities = None
 * 
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->cache_query_qualities);
  __Pyx_DECREF(__pyx_v_self->cache_query_qualities);
  __pyx_v_self->cache_query_qualities = Py_None;

  /* "pysam/calignedsegment.pyx":1043
 *             # clear cached values for quality values
 *             self.cache_query_qualities = None
 *             self.cache_query_alignment_qualities = None             # <<<<<<<<<<<<<<
 * 
 *     property query_qualities:
 */
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities);
  __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities);
  __pyx_v_self->cache_query_alignment_qualities = Py_None;

  /* "pysam/calignedsegment.pyx":992
 *             return self.cache_query_sequence
 * 
 *         def __set__(self, seq):             # <<<<<<<<<<<<<<
 *             # samtools manages sequence and quality length memory together
 *             # if no quality information is present, the first byte says 0xff.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_sequence.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1062
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             if self.cache_query_qualities:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15query_qualities___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15query_qualities___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  bam1_t *__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1062, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1064
 *         def __get__(self):
 * 
 *             if self.cache_query_qualities:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_qualities
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_qualities); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":1065
 * 
 *             if self.cache_query_qualities:
 *                 return self.cache_query_qualities             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->cache_query_qualities);
    __pyx_r = __pyx_v_self->cache_query_qualities;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1064
 *         def __get__(self):
 * 
 *             if self.cache_query_qualities:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_qualities
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1070
 *             cdef char * q
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0:
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":1072
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":1073
 * 
 *             if src.core.l_qseq == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1072
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1075
 *                 return None
 * 
 *             self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
 *             return self.cache_query_qualities
 * 
 */
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getQualitiesInRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->cache_query_qualities);
  __Pyx_DECREF(__pyx_v_self->cache_query_qualities);
  __pyx_v_self->cache_query_qualities = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":1076
 * 
 *             self.cache_query_qualities = getQualitiesInRange(src, 0, src.core.l_qseq)
 *             return self.cache_query_qualities             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, qual):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cache_query_qualities);
  __pyx_r = __pyx_v_self->cache_query_qualities;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1062
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             if self.cache_query_qualities:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_qualities.__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/calignedsegment.pyx":1078
 *             return self.cache_query_qualities
 * 
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 * 
 *             # note that memory is already allocated via setting the sequence
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_p;
  int __pyx_v_l;
  arrayobject *__pyx_v_result = 0;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1078, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1078; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1086
 *             cdef int l
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = pysam_bam_get_qual(src)
 *             if qual is None or len(qual) == 0:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1087
 * 
 *             src = self._delegate
 *             p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *             if qual is None or len(qual) == 0:
 *                 # if absent and there is a sequence: set to 0xff
 */
  __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1088
 *             src = self._delegate
 *             p = pysam_bam_get_qual(src)
 *             if qual is None or len(qual) == 0:             # <<<<<<<<<<<<<<
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:
 */
  __pyx_t_3 = (__pyx_v_qual == Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((__pyx_t_5 == 0) != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1090
 *             if qual is None or len(qual) == 0:
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:             # <<<<<<<<<<<<<<
 *                     p[0] = 0xff
 *                 return
 */
    __pyx_t_2 = ((__pyx_v_src->core.l_qseq != 0) != 0);
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":1091
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:
 *                     p[0] = 0xff             # <<<<<<<<<<<<<<
 *                 return
 * 
 */
      (__pyx_v_p[0]) = 0xff;

      /* "pysam/calignedsegment.pyx":1090
 *             if qual is None or len(qual) == 0:
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:             # <<<<<<<<<<<<<<
 *                     p[0] = 0xff
 *                 return
 */
    }

    /* "pysam/calignedsegment.pyx":1092
 *                 if src.core.l_qseq != 0:
 *                     p[0] = 0xff
 *                 return             # <<<<<<<<<<<<<<
 * 
 *             # check for length match
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1088
 *             src = self._delegate
 *             p = pysam_bam_get_qual(src)
 *             if qual is None or len(qual) == 0:             # <<<<<<<<<<<<<<
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:
 */
  }

  /* "pysam/calignedsegment.pyx":1095
 * 
 *             # check for length match
 *             l = len(qual)             # <<<<<<<<<<<<<<
 *             if src.core.l_qseq != l:
 *                 raise ValueError(
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = __pyx_t_5;

  /* "pysam/calignedsegment.pyx":1096
 *             # check for length match
 *             l = len(qual)
 *             if src.core.l_qseq != l:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "quality and sequence mismatch: %i != %i" %
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq != __pyx_v_l) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1099
 *                 raise ValueError(
 *                     "quality and sequence mismatch: %i != %i" %
 *                     (l, src.core.l_qseq))             # <<<<<<<<<<<<<<
 * 
 *             # create a python array object filling it
 */
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;

    /* "pysam/calignedsegment.pyx":1098
 *             if src.core.l_qseq != l:
 *                 raise ValueError(
 *                     "quality and sequence mismatch: %i != %i" %             # <<<<<<<<<<<<<<
 *                     (l, src.core.l_qseq))
 * 
 */
    __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pysam/calignedsegment.pyx":1097
 *             l = len(qual)
 *             if src.core.l_qseq != l:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "quality and sequence mismatch: %i != %i" %
 *                     (l, src.core.l_qseq))
 */
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_7, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":1096
 *             # check for length match
 *             l = len(qual)
 *             if src.core.l_qseq != l:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "quality and sequence mismatch: %i != %i" %
 */
  }

  /* "pysam/calignedsegment.pyx":1106
 *             # NB: should avoid this copying if qual is
 *             # already of the correct type.
 *             cdef c_array.array result = c_array.array('B', qual)             # <<<<<<<<<<<<<<
 * 
 *             # copy data
 */
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_B);
  __Pyx_GIVEREF(__pyx_n_s_B);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_B);
  __Pyx_INCREF(__pyx_v_qual);
  __Pyx_GIVEREF(__pyx_v_qual);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_qual);
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_result = ((arrayobject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pysam/calignedsegment.pyx":1109
 * 
 *             # copy data
 *             memcpy(p, result.data.as_voidptr, l)             # <<<<<<<<<<<<<<
 * 
 *             # save in cache
 */
  memcpy(__pyx_v_p, __pyx_v_result->data.as_voidptr, __pyx_v_l);

  /* "pysam/calignedsegment.pyx":1112
 * 
 *             # save in cache
 *             self.cache_query_qualities = qual             # <<<<<<<<<<<<<<
 * 
 *     property bin:
 */
  __Pyx_INCREF(__pyx_v_qual);
  __Pyx_GIVEREF(__pyx_v_qual);
  __Pyx_GOTREF(__pyx_v_self->cache_query_qualities);
  __Pyx_DECREF(__pyx_v_self->cache_query_qualities);
  __pyx_v_self->cache_query_qualities = __pyx_v_qual;

  /* "pysam/calignedsegment.pyx":1078
 *             return self.cache_query_qualities
 * 
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 * 
 *             # note that memory is already allocated via setting the sequence
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_qualities.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1116
 *     property bin:
 *         """properties bin"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3bin___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3bin___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1116, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1116; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1117
 *         """properties bin"""
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, bin):
 *             pysam_set_bin(self._delegate, bin)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_bin(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1116
 *     property bin:
 *         """properties bin"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.bin.__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/calignedsegment.pyx":1118
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):             # <<<<<<<<<<<<<<
 *             pysam_set_bin(self._delegate, bin)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3bin_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_bin));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3bin_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_bin) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1118, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1119
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 *             pysam_set_bin(self._delegate, bin)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_bin(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/calignedsegment.pyx":1118
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):             # <<<<<<<<<<<<<<
 *             pysam_set_bin(self._delegate, bin)
 * 
 */

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

/* "pysam/calignedsegment.pyx":1130
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_paired___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_paired___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1130, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1131
 *         """true if read is paired in sequencing"""
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPAIRED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1130
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_paired.__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/calignedsegment.pyx":1132
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_paired_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_paired_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1132, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1132; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1133
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)             # <<<<<<<<<<<<<<
 * 
 *     property is_proper_pair:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPAIRED);

  /* "pysam/calignedsegment.pyx":1132
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 * 
 */

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

/* "pysam/calignedsegment.pyx":1137
 *     property is_proper_pair:
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1137, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1137; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1138
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPROPER_PAIR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1137
 *     property is_proper_pair:
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_proper_pair.__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/calignedsegment.pyx":1139
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 *     property is_unmapped:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1139, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1139; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1140
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPROPER_PAIR);

  /* "pysam/calignedsegment.pyx":1139
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 *     property is_unmapped:
 */

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

/* "pysam/calignedsegment.pyx":1143
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1143, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1144
 *         """true if read itself is unmapped"""
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1143
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_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/calignedsegment.pyx":1145
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 *     property mate_is_unmapped:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1145, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1146
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FUNMAP);

  /* "pysam/calignedsegment.pyx":1145
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 *     property mate_is_unmapped:
 */

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

/* "pysam/calignedsegment.pyx":1149
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1149, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1149; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1150
 *         """true if the mate is unmapped"""
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMUNMAP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1149
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.mate_is_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/calignedsegment.pyx":1151
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 *     property is_reverse:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1151, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1151; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1152
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMUNMAP);

  /* "pysam/calignedsegment.pyx":1151
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 *     property is_reverse:
 */

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

/* "pysam/calignedsegment.pyx":1155
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10is_reverse___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10is_reverse___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1155, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1156
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREVERSE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1156; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1155
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_reverse.__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/calignedsegment.pyx":1157
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 *     property mate_is_reverse:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1157, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1157; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1158
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREVERSE);

  /* "pysam/calignedsegment.pyx":1157
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 *     property mate_is_reverse:
 */

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

/* "pysam/calignedsegment.pyx":1161
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1161, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1161; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1162
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMREVERSE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1161
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.mate_is_reverse.__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/calignedsegment.pyx":1163
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 *     property is_read1:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1163, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1163; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1164
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)             # <<<<<<<<<<<<<<
 *     property is_read1:
 *         """true if this is read1"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMREVERSE);

  /* "pysam/calignedsegment.pyx":1163
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 *     property is_read1:
 */

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

/* "pysam/calignedsegment.pyx":1167
 *     property is_read1:
 *         """true if this is read1"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read1___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read1___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1167, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1167; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1168
 *         """true if this is read1"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1168; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1167
 *     property is_read1:
 *         """true if this is read1"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_read1.__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/calignedsegment.pyx":1169
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 *     property is_read2:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read1_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read1_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1169, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1169; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1170
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)             # <<<<<<<<<<<<<<
 *     property is_read2:
 *         """true if this is read2"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD1);

  /* "pysam/calignedsegment.pyx":1169
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 *     property is_read2:
 */

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

/* "pysam/calignedsegment.pyx":1173
 *     property is_read2:
 *         """true if this is read2"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read2___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read2___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1173, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1174
 *         """true if this is read2"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1173
 *     property is_read2:
 *         """true if this is read2"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_read2.__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/calignedsegment.pyx":1175
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 *     property is_secondary:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read2_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_8is_read2_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1175, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1176
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)             # <<<<<<<<<<<<<<
 *     property is_secondary:
 *         """true if not primary alignment"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD2);

  /* "pysam/calignedsegment.pyx":1175
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 *     property is_secondary:
 */

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

/* "pysam/calignedsegment.pyx":1179
 *     property is_secondary:
 *         """true if not primary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_secondary___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_secondary___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1179, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1180
 *         """true if not primary alignment"""
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSECONDARY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1179
 *     property is_secondary:
 *         """true if not primary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_secondary.__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/calignedsegment.pyx":1181
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 *     property is_qcfail:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1181, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1182
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)             # <<<<<<<<<<<<<<
 *     property is_qcfail:
 *         """true if QC failure"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSECONDARY);

  /* "pysam/calignedsegment.pyx":1181
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 *     property is_qcfail:
 */

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

/* "pysam/calignedsegment.pyx":1185
 *     property is_qcfail:
 *         """true if QC failure"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1185, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1186
 *         """true if QC failure"""
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FQCFAIL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1186; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1185
 *     property is_qcfail:
 *         """true if QC failure"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_qcfail.__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/calignedsegment.pyx":1187
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 *     property is_duplicate:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1187, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1187; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1188
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)             # <<<<<<<<<<<<<<
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FQCFAIL);

  /* "pysam/calignedsegment.pyx":1187
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 *     property is_duplicate:
 */

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

/* "pysam/calignedsegment.pyx":1191
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1191, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1192
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FDUP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1191
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_duplicate.__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/calignedsegment.pyx":1193
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 *     property is_supplementary:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1193, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1194
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)             # <<<<<<<<<<<<<<
 *     property is_supplementary:
 *         """true if this is a supplementary alignment"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FDUP);

  /* "pysam/calignedsegment.pyx":1193
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 *     property is_supplementary:
 */

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

/* "pysam/calignedsegment.pyx":1197
 *     property is_supplementary:
 *         """true if this is a supplementary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1197, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1198
 *         """true if this is a supplementary alignment"""
 *         def __get__(self):
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSUPPLEMENTARY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1198; __pyx_clineno = __LINE__; goto __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_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1197
 *     property is_supplementary:
 *         """true if this is a supplementary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.is_supplementary.__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/calignedsegment.pyx":1199
 *         def __get__(self):
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1199, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1199; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1200
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)             # <<<<<<<<<<<<<<
 * 
 *     # 2. Coordinates and lengths
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSUPPLEMENTARY);

  /* "pysam/calignedsegment.pyx":1199
 *         def __get__(self):
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)
 * 
 */

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

/* "pysam/calignedsegment.pyx":1211
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_13reference_end___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_13reference_end___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1211, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1213
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1214
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  __pyx_t_2 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1215
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_endpos(src)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1214
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src)
 */
  }

  /* "pysam/calignedsegment.pyx":1216
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 *             return bam_endpos(src)             # <<<<<<<<<<<<<<
 * 
 *     property reference_length:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyInt_From_int32_t(bam_endpos(__pyx_v_src)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1211
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.reference_end.__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/calignedsegment.pyx":1222
 * 
 *         This is equal to `aend - pos`. Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16reference_length___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_16reference_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1222, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1224
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1225
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src) - \
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  __pyx_t_2 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1226
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_endpos(src) - \
 *                 self._delegate.core.pos
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1225
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src) - \
 */
  }

  /* "pysam/calignedsegment.pyx":1227
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 *             return bam_endpos(src) - \             # <<<<<<<<<<<<<<
 *                 self._delegate.core.pos
 * 
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/calignedsegment.pyx":1228
 *                 return None
 *             return bam_endpos(src) - \
 *                 self._delegate.core.pos             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_sequence:
 */
  __pyx_t_5 = __Pyx_PyInt_From_int32_t((bam_endpos(__pyx_v_src) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1227; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1222
 * 
 *         This is equal to `aend - pos`. Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.reference_length.__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/calignedsegment.pyx":1247
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.cache_query_alignment_sequence:
 *                 return self.cache_query_alignment_sequence
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_24query_alignment_sequence___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_24query_alignment_sequence___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  bam1_t *__pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1247, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1248
 * 
 *         def __get__(self):
 *             if self.cache_query_alignment_sequence:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_alignment_sequence
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_alignment_sequence); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":1249
 *         def __get__(self):
 *             if self.cache_query_alignment_sequence:
 *                 return self.cache_query_alignment_sequence             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->cache_query_alignment_sequence);
    __pyx_r = __pyx_v_self->cache_query_alignment_sequence;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1248
 * 
 *         def __get__(self):
 *             if self.cache_query_alignment_sequence:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_alignment_sequence
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1254
 *             cdef uint32_t start, end
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0:
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":1256
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":1257
 * 
 *             if src.core.l_qseq == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             start = getQueryStart(src)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1256
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1259
 *                 return None
 * 
 *             start = getQueryStart(src)             # <<<<<<<<<<<<<<
 *             end   = getQueryEnd(src)
 * 
 */
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_3;

  /* "pysam/calignedsegment.pyx":1260
 * 
 *             start = getQueryStart(src)
 *             end   = getQueryEnd(src)             # <<<<<<<<<<<<<<
 * 
 *             self.cache_query_alignment_sequence = force_str(
 */
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_3;

  /* "pysam/calignedsegment.pyx":1263
 * 
 *             self.cache_query_alignment_sequence = force_str(
 *                 getSequenceInRange(src, start, end))             # <<<<<<<<<<<<<<
 *             return self.cache_query_alignment_sequence
 * 
 */
  __pyx_t_4 = __pyx_f_5pysam_15calignedsegment_getSequenceInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignedsegment.pyx":1262
 *             end   = getQueryEnd(src)
 * 
 *             self.cache_query_alignment_sequence = force_str(             # <<<<<<<<<<<<<<
 *                 getSequenceInRange(src, start, end))
 *             return self.cache_query_alignment_sequence
 */
  __pyx_t_5 = __pyx_f_5pysam_6cutils_force_str(__pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GIVEREF(__pyx_t_5);
  __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_sequence);
  __Pyx_DECREF(__pyx_v_self->cache_query_alignment_sequence);
  __pyx_v_self->cache_query_alignment_sequence = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "pysam/calignedsegment.pyx":1264
 *             self.cache_query_alignment_sequence = force_str(
 *                 getSequenceInRange(src, start, end))
 *             return self.cache_query_alignment_sequence             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_qualities:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cache_query_alignment_sequence);
  __pyx_r = __pyx_v_self->cache_query_alignment_sequence;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1247
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.cache_query_alignment_sequence:
 *                 return self.cache_query_alignment_sequence
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_alignment_sequence.__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/calignedsegment.pyx":1280
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             if self.cache_query_alignment_qualities:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_25query_alignment_qualities___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_25query_alignment_qualities___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  bam1_t *__pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1280, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1282
 *         def __get__(self):
 * 
 *             if self.cache_query_alignment_qualities:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_alignment_qualities
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->cache_query_alignment_qualities); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":1283
 * 
 *             if self.cache_query_alignment_qualities:
 *                 return self.cache_query_alignment_qualities             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_self->cache_query_alignment_qualities);
    __pyx_r = __pyx_v_self->cache_query_alignment_qualities;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1282
 *         def __get__(self):
 * 
 *             if self.cache_query_alignment_qualities:             # <<<<<<<<<<<<<<
 *                 return self.cache_query_alignment_qualities
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1288
 *             cdef uint32_t start, end
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0:
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":1290
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_1 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":1291
 * 
 *             if src.core.l_qseq == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             start = getQueryStart(src)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1290
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1293
 *                 return None
 * 
 *             start = getQueryStart(src)             # <<<<<<<<<<<<<<
 *             end   = getQueryEnd(src)
 *             self.cache_query_alignment_qualities = \
 */
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_3;

  /* "pysam/calignedsegment.pyx":1294
 * 
 *             start = getQueryStart(src)
 *             end   = getQueryEnd(src)             # <<<<<<<<<<<<<<
 *             self.cache_query_alignment_qualities = \
 *                 getQualitiesInRange(src, start, end)
 */
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_3;

  /* "pysam/calignedsegment.pyx":1296
 *             end   = getQueryEnd(src)
 *             self.cache_query_alignment_qualities = \
 *                 getQualitiesInRange(src, start, end)             # <<<<<<<<<<<<<<
 *             return self.cache_query_alignment_qualities
 * 
 */
  __pyx_t_4 = __pyx_f_5pysam_15calignedsegment_getQualitiesInRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignedsegment.pyx":1295
 *             start = getQueryStart(src)
 *             end   = getQueryEnd(src)
 *             self.cache_query_alignment_qualities = \             # <<<<<<<<<<<<<<
 *                 getQualitiesInRange(src, start, end)
 *             return self.cache_query_alignment_qualities
 */
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_GOTREF(__pyx_v_self->cache_query_alignment_qualities);
  __Pyx_DECREF(__pyx_v_self->cache_query_alignment_qualities);
  __pyx_v_self->cache_query_alignment_qualities = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysam/calignedsegment.pyx":1297
 *             self.cache_query_alignment_qualities = \
 *                 getQualitiesInRange(src, start, end)
 *             return self.cache_query_alignment_qualities             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_start:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_self->cache_query_alignment_qualities);
  __pyx_r = __pyx_v_self->cache_query_alignment_qualities;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1280
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             if self.cache_query_alignment_qualities:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_alignment_qualities.__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/calignedsegment.pyx":1307
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return getQueryStart(self._delegate)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_21query_alignment_start___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_21query_alignment_start___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1307, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1308
 *         """
 *         def __get__(self):
 *             return getQueryStart(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_end:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_15calignedsegment_getQueryStart(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1307
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return getQueryStart(self._delegate)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_alignment_start.__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/calignedsegment.pyx":1313
 *         """end index of the aligned query portion of the sequence (0-based,
 *         exclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return getQueryEnd(self._delegate)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_19query_alignment_end___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_19query_alignment_end___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1313, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1314
 *         exclusive)"""
 *         def __get__(self):
 *             return getQueryEnd(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_length:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_15calignedsegment_getQueryEnd(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1314; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1313
 *         """end index of the aligned query portion of the sequence (0-based,
 *         exclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return getQueryEnd(self._delegate)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_alignment_end.__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/calignedsegment.pyx":1320
 * 
 *         This is equal to :attr:`qend` - :attr:`qstart`"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_22query_alignment_length___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_22query_alignment_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int32_t __pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1320, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1320; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1322
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             return getQueryEnd(src) - getQueryStart(src)
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1323
 *             cdef bam1_t * src
 *             src = self._delegate
 *             return getQueryEnd(src) - getQueryStart(src)             # <<<<<<<<<<<<<<
 * 
 *     #####################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_5pysam_15calignedsegment_getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __pyx_f_5pysam_15calignedsegment_getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_int32_t((__pyx_t_2 - __pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1320
 * 
 *         This is equal to :attr:`qend` - :attr:`qstart`"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query_alignment_length.__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/calignedsegment.pyx":1328
 *     # Computed properties
 * 
 *     def get_reference_positions(self, full_length=False):             # <<<<<<<<<<<<<<
 *         """a list of reference positions that this read aligns to.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_18get_reference_positions[] = "AlignedSegment.get_reference_positions(self, full_length=False)\na list of reference positions that this read aligns to.\n\n        By default, this method only returns positions in the\n        reference that are within the alignment. If *full_length* is\n        set, None values will be included for any soft-clipped or\n        unaligned positions within the read. The returned list will\n        thus be of the same length as the read.\n\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_full_length = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_positions (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_full_length,0};
    PyObject* values[1] = {0};
    values[0] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_full_length);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_reference_positions") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_full_length = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_reference_positions", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_18get_reference_positions(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_full_length);

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_18get_reference_positions(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_i;
  uint32_t __pyx_v_pos;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  int __pyx_v__full;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  bam1_t *__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  int __pyx_t_6;
  uint32_t __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_RefNannySetupContext("get_reference_positions", 0);
  __Pyx_TraceCall("get_reference_positions", __pyx_f[0], 1328, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1328; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1342
 *         cdef uint32_t * cigar_p
 *         cdef bam1_t * src
 *         cdef bint _full = full_length             # <<<<<<<<<<<<<<
 * 
 *         src = self._delegate
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_full_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__full = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1344
 *         cdef bint _full = full_length
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return []
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/calignedsegment.pyx":1345
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  __pyx_t_1 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":1346
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1345
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1348
 *             return []
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":1349
 * 
 *         result = []
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":1350
 *         result = []
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1352
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":1353
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":1354
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":1356
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:             # <<<<<<<<<<<<<<
 *                 if _full:
 *                     for i from 0 <= i < l:
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CINS) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":1357
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:
 *                 if _full:             # <<<<<<<<<<<<<<
 *                     for i from 0 <= i < l:
 *                         result.append(None)
 */
      __pyx_t_1 = (__pyx_v__full != 0);
      if (__pyx_t_1) {

        /* "pysam/calignedsegment.pyx":1358
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:
 *                 if _full:
 *                     for i from 0 <= i < l:             # <<<<<<<<<<<<<<
 *                         result.append(None)
 *             elif op == BAM_CMATCH:
 */
        __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_l); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

          /* "pysam/calignedsegment.pyx":1359
 *                 if _full:
 *                     for i from 0 <= i < l:
 *                         result.append(None)             # <<<<<<<<<<<<<<
 *             elif op == BAM_CMATCH:
 *                 for i from pos <= i < pos + l:
 */
          __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, Py_None); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }

        /* "pysam/calignedsegment.pyx":1357
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:
 *                 if _full:             # <<<<<<<<<<<<<<
 *                     for i from 0 <= i < l:
 *                         result.append(None)
 */
      }

      /* "pysam/calignedsegment.pyx":1356
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:             # <<<<<<<<<<<<<<
 *                 if _full:
 *                     for i from 0 <= i < l:
 */
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1360
 *                     for i from 0 <= i < l:
 *                         result.append(None)
 *             elif op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 for i from pos <= i < pos + l:
 *                     result.append(i)
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":1361
 *                         result.append(None)
 *             elif op == BAM_CMATCH:
 *                 for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                     result.append(i)
 *                 pos += l
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/calignedsegment.pyx":1362
 *             elif op == BAM_CMATCH:
 *                 for i from pos <= i < pos + l:
 *                     result.append(i)             # <<<<<<<<<<<<<<
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
        __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }

      /* "pysam/calignedsegment.pyx":1363
 *                 for i from pos <= i < pos + l:
 *                     result.append(i)
 *                 pos += l             # <<<<<<<<<<<<<<
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l
 */
      __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_pos = __pyx_t_7;

      /* "pysam/calignedsegment.pyx":1360
 *                     for i from 0 <= i < l:
 *                         result.append(None)
 *             elif op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 for i from pos <= i < pos + l:
 *                     result.append(i)
 */
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1364
 *                     result.append(i)
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignedsegment.pyx":1365
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_pos = __pyx_t_7;

      /* "pysam/calignedsegment.pyx":1364
 *                     result.append(i)
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    }
    __pyx_L6:;
  }

  /* "pysam/calignedsegment.pyx":1367
 *                 pos += l
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def infer_query_length(self, always=True):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1328
 *     # Computed properties
 * 
 *     def get_reference_positions(self, full_length=False):             # <<<<<<<<<<<<<<
 *         """a list of reference positions that this read aligns to.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1369
 *         return result
 * 
 *     def infer_query_length(self, always=True):             # <<<<<<<<<<<<<<
 *         """inferred read length from CIGAR string.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_21infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_20infer_query_length[] = "AlignedSegment.infer_query_length(self, always=True)\ninferred read length from CIGAR string.\n\n        If *always* is set to True, the read length\n        will be always inferred. If set to False, the length\n        of the read sequence will be returned if it is\n        available.\n\n        Returns None if CIGAR string is not present.\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_21infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_always = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("infer_query_length (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_always,0};
    PyObject* values[1] = {0};
    values[0] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_always);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "infer_query_length") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_always = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("infer_query_length", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.infer_query_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20infer_query_length(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_always);

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_20infer_query_length(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("infer_query_length", 0);
  __Pyx_TraceCall("infer_query_length", __pyx_f[0], 1369, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1383
 *         cdef bam1_t * src
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *         if not always and src.core.l_qseq:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1385
 *         src = self._delegate
 * 
 *         if not always and src.core.l_qseq:             # <<<<<<<<<<<<<<
 *             return src.core.l_qseq
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_always); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_src->core.l_qseq != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1386
 * 
 *         if not always and src.core.l_qseq:
 *             return src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *         return calculateQueryLength(src)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1385
 *         src = self._delegate
 * 
 *         if not always and src.core.l_qseq:             # <<<<<<<<<<<<<<
 *             return src.core.l_qseq
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1388
 *             return src.core.l_qseq
 * 
 *         return calculateQueryLength(src)             # <<<<<<<<<<<<<<
 * 
 *     def get_reference_sequence(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_f_5pysam_15calignedsegment_calculateQueryLength(__pyx_v_src)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1369
 *         return result
 * 
 *     def infer_query_length(self, always=True):             # <<<<<<<<<<<<<<
 *         """inferred read length from CIGAR string.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.infer_query_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/calignedsegment.pyx":1390
 *         return calculateQueryLength(src)
 * 
 *     def get_reference_sequence(self):             # <<<<<<<<<<<<<<
 *         """return the reference sequence.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_23get_reference_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_22get_reference_sequence[] = "AlignedSegment.get_reference_sequence(self)\nreturn the reference sequence.\n\n        This method requires the MD tag to be set.\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_23get_reference_sequence(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_sequence (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_22get_reference_sequence(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_22get_reference_sequence(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  uint32_t __pyx_v_k;
  CYTHON_UNUSED uint32_t __pyx_v_i;
  int __pyx_v_op;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_ref_seq = NULL;
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_r_idx;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  uint16_t __pyx_t_6;
  uint32_t __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_reference_sequence", 0);
  __Pyx_TraceCall("get_reference_sequence", __pyx_f[0], 1390, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1390; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1397
 *         cdef uint32_t k, i
 *         cdef int op
 *         cdef bam1_t * src = self._delegate             # <<<<<<<<<<<<<<
 *         ref_seq = force_str(build_alignment_sequence(src))
 *         if ref_seq is None:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1398
 *         cdef int op
 *         cdef bam1_t * src = self._delegate
 *         ref_seq = force_str(build_alignment_sequence(src))             # <<<<<<<<<<<<<<
 *         if ref_seq is None:
 *             raise ValueError("MD tag not present")
 */
  __pyx_t_2 = __pyx_f_5pysam_15calignedsegment_build_alignment_sequence(__pyx_v_src); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_f_5pysam_6cutils_force_str(__pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_ref_seq = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":1399
 *         cdef bam1_t * src = self._delegate
 *         ref_seq = force_str(build_alignment_sequence(src))
 *         if ref_seq is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("MD tag not present")
 * 
 */
  __pyx_t_4 = (__pyx_v_ref_seq == Py_None);
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "pysam/calignedsegment.pyx":1400
 *         ref_seq = force_str(build_alignment_sequence(src))
 *         if ref_seq is None:
 *             raise ValueError("MD tag not present")             # <<<<<<<<<<<<<<
 * 
 *         cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1400; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":1399
 *         cdef bam1_t * src = self._delegate
 *         ref_seq = force_str(build_alignment_sequence(src))
 *         if ref_seq is None:             # <<<<<<<<<<<<<<
 *             raise ValueError("MD tag not present")
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1402
 *             raise ValueError("MD tag not present")
 * 
 *         cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *         cdef uint32_t r_idx = 0
 *         result = []
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1403
 * 
 *         cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 *         cdef uint32_t r_idx = 0             # <<<<<<<<<<<<<<
 *         result = []
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_r_idx = 0;

  /* "pysam/calignedsegment.pyx":1404
 *         cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 *         cdef uint32_t r_idx = 0
 *         result = []             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":1405
 *         cdef uint32_t r_idx = 0
 *         result = []
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_6 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":1406
 *         result = []
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":1407
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 for i from 0 <= i < l:
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":1408
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])
 */
    __pyx_t_4 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_5 = __pyx_t_4;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_4 = ((__pyx_v_op == BAM_CEQUAL) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_5 = __pyx_t_4;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_4 = ((__pyx_v_op == BAM_CDIFF) != 0);
    __pyx_t_5 = __pyx_t_4;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_5) {

      /* "pysam/calignedsegment.pyx":1409
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 for i from 0 <= i < l:             # <<<<<<<<<<<<<<
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1
 */
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_l); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/calignedsegment.pyx":1410
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])             # <<<<<<<<<<<<<<
 *                     r_idx += 1
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pysam/calignedsegment.pyx":1411
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1             # <<<<<<<<<<<<<<
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 for i from 0 <= i < l:
 */
        __pyx_v_r_idx = (__pyx_v_r_idx + 1);
      }

      /* "pysam/calignedsegment.pyx":1408
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])
 */
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1412
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])
 */
    __pyx_t_4 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_5 = __pyx_t_4;
      goto __pyx_L12_bool_binop_done;
    }
    __pyx_t_4 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_5 = __pyx_t_4;
    __pyx_L12_bool_binop_done:;
    if (__pyx_t_5) {

      /* "pysam/calignedsegment.pyx":1413
 *                     r_idx += 1
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 for i from 0 <= i < l:             # <<<<<<<<<<<<<<
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1
 */
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_l); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/calignedsegment.pyx":1414
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])             # <<<<<<<<<<<<<<
 *                     r_idx += 1
 *             elif op == BAM_CINS:
 */
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pysam/calignedsegment.pyx":1415
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1             # <<<<<<<<<<<<<<
 *             elif op == BAM_CINS:
 *                 r_idx += l
 */
        __pyx_v_r_idx = (__pyx_v_r_idx + 1);
      }

      /* "pysam/calignedsegment.pyx":1412
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 for i from 0 <= i < l:
 *                     result.append(ref_seq[r_idx])
 */
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1416
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1
 *             elif op == BAM_CINS:             # <<<<<<<<<<<<<<
 *                 r_idx += l
 *             elif op == BAM_CSOFT_CLIP:
 */
    __pyx_t_5 = ((__pyx_v_op == BAM_CINS) != 0);
    if (__pyx_t_5) {

      /* "pysam/calignedsegment.pyx":1417
 *                     r_idx += 1
 *             elif op == BAM_CINS:
 *                 r_idx += l             # <<<<<<<<<<<<<<
 *             elif op == BAM_CSOFT_CLIP:
 *                 pass
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_r_idx); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_2); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_v_r_idx = __pyx_t_7;

      /* "pysam/calignedsegment.pyx":1416
 *                     result.append(ref_seq[r_idx])
 *                     r_idx += 1
 *             elif op == BAM_CINS:             # <<<<<<<<<<<<<<
 *                 r_idx += l
 *             elif op == BAM_CSOFT_CLIP:
 */
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1418
 *             elif op == BAM_CINS:
 *                 r_idx += l
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 pass
 *             elif op == BAM_CHARD_CLIP:
 */
    __pyx_t_5 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    if (__pyx_t_5) {
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1420
 *             elif op == BAM_CSOFT_CLIP:
 *                 pass
 *             elif op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 pass # advances neither
 *             elif op == BAM_CPAD:
 */
    __pyx_t_5 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
    if (__pyx_t_5) {
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1422
 *             elif op == BAM_CHARD_CLIP:
 *                 pass # advances neither
 *             elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *                 raise NotImplementedError(
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 */
    __pyx_t_5 = ((__pyx_v_op == BAM_CPAD) != 0);
    if (__pyx_t_5) {

      /* "pysam/calignedsegment.pyx":1423
 *                 pass # advances neither
 *             elif op == BAM_CPAD:
 *                 raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 *                     "Please implement. Sorry about that.")
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignedsegment.pyx":1422
 *             elif op == BAM_CHARD_CLIP:
 *                 pass # advances neither
 *             elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *                 raise NotImplementedError(
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 */
    }
    __pyx_L6:;
  }

  /* "pysam/calignedsegment.pyx":1427
 *                     "Please implement. Sorry about that.")
 * 
 *         return "".join(result)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__16, __pyx_v_result); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1390
 *         return calculateQueryLength(src)
 * 
 *     def get_reference_sequence(self):             # <<<<<<<<<<<<<<
 *         """return the reference sequence.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_reference_sequence", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ref_seq);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1430
 * 
 * 
 *     def get_aligned_pairs(self, matches_only=False, with_seq=False):             # <<<<<<<<<<<<<<
 *         """a list of aligned read (query) and reference positions.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_25get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_24get_aligned_pairs[] = "AlignedSegment.get_aligned_pairs(self, matches_only=False, with_seq=False)\na list of aligned read (query) and reference positions.\n\n        For inserts, deletions, skipping either query or reference\n        position may be None.\n\n        Padding is currently not supported and leads to an exception.\n\n        Parameters\n        ----------\n\n        matches_only : bool\n          If True, only matched bases are returned - no None on either\n          side.\n        with_seq : bool\n          If True, return a third element in the tuple containing the\n          reference sequence. Substitutions are lower-case. This option\n          requires an MD tag to be present.\n\n        Returns\n        -------\n\n        aligned_pairs : list of tuples\n\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_25get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_matches_only = 0;
  PyObject *__pyx_v_with_seq = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_aligned_pairs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_matches_only,&__pyx_n_s_with_seq,0};
    PyObject* values[2] = {0,0};
    values[0] = ((PyObject *)Py_False);
    values[1] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_matches_only);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_with_seq);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_aligned_pairs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1430; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_matches_only = values[0];
    __pyx_v_with_seq = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_aligned_pairs", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1430; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_24get_aligned_pairs(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_matches_only, __pyx_v_with_seq);

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_24get_aligned_pairs(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only, PyObject *__pyx_v_with_seq) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_i;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_qpos;
  uint32_t __pyx_v_r_idx;
  uint32_t __pyx_v_l;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  int __pyx_v__matches_only;
  int __pyx_v__with_seq;
  PyObject *__pyx_v_ref_seq = NULL;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int32_t __pyx_t_7;
  uint16_t __pyx_t_8;
  uint32_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_aligned_pairs", 0);
  __Pyx_TraceCall("get_aligned_pairs", __pyx_f[0], 1430, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1430; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1458
 *         cdef int op
 *         cdef uint32_t * cigar_p
 *         cdef bam1_t * src = self._delegate             # <<<<<<<<<<<<<<
 *         cdef bint _matches_only = bool(matches_only)
 *         cdef bint _with_seq = bool(with_seq)
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1459
 *         cdef uint32_t * cigar_p
 *         cdef bam1_t * src = self._delegate
 *         cdef bint _matches_only = bool(matches_only)             # <<<<<<<<<<<<<<
 *         cdef bint _with_seq = bool(with_seq)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_matches_only); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1459; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__matches_only = (!(!__pyx_t_2));

  /* "pysam/calignedsegment.pyx":1460
 *         cdef bam1_t * src = self._delegate
 *         cdef bint _matches_only = bool(matches_only)
 *         cdef bint _with_seq = bool(with_seq)             # <<<<<<<<<<<<<<
 * 
 *         # TODO: this method performs no checking and assumes that
 */
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_with_seq); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__with_seq = (!(!__pyx_t_2));

  /* "pysam/calignedsegment.pyx":1465
 *         # read sequence, cigar and MD tag are consistent.
 * 
 *         if _with_seq:             # <<<<<<<<<<<<<<
 *             ref_seq = force_str(self.get_reference_sequence())
 *             if ref_seq is None:
 */
  __pyx_t_2 = (__pyx_v__with_seq != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1466
 * 
 *         if _with_seq:
 *             ref_seq = force_str(self.get_reference_sequence())             # <<<<<<<<<<<<<<
 *             if ref_seq is None:
 *                 raise ValueError("MD tag not present")
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_sequence); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __pyx_f_5pysam_6cutils_force_str(__pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1466; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_ref_seq = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysam/calignedsegment.pyx":1467
 *         if _with_seq:
 *             ref_seq = force_str(self.get_reference_sequence())
 *             if ref_seq is None:             # <<<<<<<<<<<<<<
 *                 raise ValueError("MD tag not present")
 * 
 */
    __pyx_t_2 = (__pyx_v_ref_seq == Py_None);
    __pyx_t_6 = (__pyx_t_2 != 0);
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":1468
 *             ref_seq = force_str(self.get_reference_sequence())
 *             if ref_seq is None:
 *                 raise ValueError("MD tag not present")             # <<<<<<<<<<<<<<
 * 
 *         r_idx = 0
 */
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignedsegment.pyx":1467
 *         if _with_seq:
 *             ref_seq = force_str(self.get_reference_sequence())
 *             if ref_seq is None:             # <<<<<<<<<<<<<<
 *                 raise ValueError("MD tag not present")
 * 
 */
    }

    /* "pysam/calignedsegment.pyx":1465
 *         # read sequence, cigar and MD tag are consistent.
 * 
 *         if _with_seq:             # <<<<<<<<<<<<<<
 *             ref_seq = force_str(self.get_reference_sequence())
 *             if ref_seq is None:
 */
  }

  /* "pysam/calignedsegment.pyx":1470
 *                 raise ValueError("MD tag not present")
 * 
 *         r_idx = 0             # <<<<<<<<<<<<<<
 * 
 *         if pysam_get_n_cigar(src) == 0:
 */
  __pyx_v_r_idx = 0;

  /* "pysam/calignedsegment.pyx":1472
 *         r_idx = 0
 * 
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_6) {

    /* "pysam/calignedsegment.pyx":1473
 * 
 *         if pysam_get_n_cigar(src) == 0:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1472
 *         r_idx = 0
 * 
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1475
 *             return []
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         qpos = 0
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1475; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_result = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pysam/calignedsegment.pyx":1476
 * 
 *         result = []
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         qpos = 0
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_7 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_7;

  /* "pysam/calignedsegment.pyx":1477
 *         result = []
 *         pos = src.core.pos
 *         qpos = 0             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_qpos = 0;

  /* "pysam/calignedsegment.pyx":1478
 *         pos = src.core.pos
 *         qpos = 0
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1479
 *         qpos = 0
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_8 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_8; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":1480
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":1481
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT);

    /* "pysam/calignedsegment.pyx":1483
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                 if _with_seq:
 *                     for i from pos <= i < pos + l:
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_6 = __pyx_t_2;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_op == BAM_CEQUAL) != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_6 = __pyx_t_2;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_op == BAM_CDIFF) != 0);
    __pyx_t_6 = __pyx_t_2;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":1484
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 if _with_seq:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, i, ref_seq[r_idx]))
 */
      __pyx_t_6 = (__pyx_v__with_seq != 0);
      if (__pyx_t_6) {

        /* "pysam/calignedsegment.pyx":1485
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 if _with_seq:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append((qpos, i, ref_seq[r_idx]))
 *                         r_idx += 1
 */
        __pyx_t_9 = (__pyx_v_pos + __pyx_v_l);
        for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

          /* "pysam/calignedsegment.pyx":1486
 *                 if _with_seq:
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, i, ref_seq[r_idx]))             # <<<<<<<<<<<<<<
 *                         r_idx += 1
 *                         qpos += 1
 */
          __pyx_t_4 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          if (unlikely(!__pyx_v_ref_seq)) { __Pyx_RaiseUnboundLocalError("ref_seq"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
          __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_GIVEREF(__pyx_t_4);
          PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4);
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_5);
          __pyx_t_4 = 0;
          __pyx_t_3 = 0;
          __pyx_t_5 = 0;
          __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1486; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

          /* "pysam/calignedsegment.pyx":1487
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, i, ref_seq[r_idx]))
 *                         r_idx += 1             # <<<<<<<<<<<<<<
 *                         qpos += 1
 *                 else:
 */
          __pyx_v_r_idx = (__pyx_v_r_idx + 1);

          /* "pysam/calignedsegment.pyx":1488
 *                         result.append((qpos, i, ref_seq[r_idx]))
 *                         r_idx += 1
 *                         qpos += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     for i from pos <= i < pos + l:
 */
          __pyx_v_qpos = (__pyx_v_qpos + 1);
        }

        /* "pysam/calignedsegment.pyx":1484
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 if _with_seq:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, i, ref_seq[r_idx]))
 */
        goto __pyx_L12;
      }

      /* "pysam/calignedsegment.pyx":1490
 *                         qpos += 1
 *                 else:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append((qpos, i))
 *                         qpos += 1
 */
      /*else*/ {
        __pyx_t_9 = (__pyx_v_pos + __pyx_v_l);
        for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

          /* "pysam/calignedsegment.pyx":1491
 *                 else:
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, i))             # <<<<<<<<<<<<<<
 *                         qpos += 1
 *                 pos += l
 */
          __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_10);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_10);
          __Pyx_GIVEREF(__pyx_t_5);
          PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
          __pyx_t_10 = 0;
          __pyx_t_5 = 0;
          __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1491; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pysam/calignedsegment.pyx":1492
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, i))
 *                         qpos += 1             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
          __pyx_v_qpos = (__pyx_v_qpos + 1);
        }
      }
      __pyx_L12:;

      /* "pysam/calignedsegment.pyx":1493
 *                         result.append((qpos, i))
 *                         qpos += 1
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);

      /* "pysam/calignedsegment.pyx":1483
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                 if _with_seq:
 *                     for i from pos <= i < pos + l:
 */
      goto __pyx_L8;
    }

    /* "pysam/calignedsegment.pyx":1495
 *                 pos += l
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 if not _matches_only:
 *                     if _with_seq:
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CINS) != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_6 = __pyx_t_2;
      goto __pyx_L17_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    __pyx_t_6 = __pyx_t_2;
    __pyx_L17_bool_binop_done:;
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":1496
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 *                 if not _matches_only:             # <<<<<<<<<<<<<<
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:
 */
      __pyx_t_6 = ((!(__pyx_v__matches_only != 0)) != 0);
      if (__pyx_t_6) {

        /* "pysam/calignedsegment.pyx":1497
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 *                 if not _matches_only:
 *                     if _with_seq:             # <<<<<<<<<<<<<<
 *                         for i from pos <= i < pos + l:
 *                             result.append((qpos, None, None))
 */
        __pyx_t_6 = (__pyx_v__with_seq != 0);
        if (__pyx_t_6) {

          /* "pysam/calignedsegment.pyx":1498
 *                 if not _matches_only:
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                             result.append((qpos, None, None))
 *                             qpos += 1
 */
          __pyx_t_9 = (__pyx_v_pos + __pyx_v_l);
          for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

            /* "pysam/calignedsegment.pyx":1499
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:
 *                             result.append((qpos, None, None))             # <<<<<<<<<<<<<<
 *                             qpos += 1
 *                     else:
 */
            __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3);
            __Pyx_INCREF(Py_None);
            __Pyx_GIVEREF(Py_None);
            PyTuple_SET_ITEM(__pyx_t_5, 1, Py_None);
            __Pyx_INCREF(Py_None);
            __Pyx_GIVEREF(Py_None);
            PyTuple_SET_ITEM(__pyx_t_5, 2, Py_None);
            __pyx_t_3 = 0;
            __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "pysam/calignedsegment.pyx":1500
 *                         for i from pos <= i < pos + l:
 *                             result.append((qpos, None, None))
 *                             qpos += 1             # <<<<<<<<<<<<<<
 *                     else:
 *                         for i from pos <= i < pos + l:
 */
            __pyx_v_qpos = (__pyx_v_qpos + 1);
          }

          /* "pysam/calignedsegment.pyx":1497
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 *                 if not _matches_only:
 *                     if _with_seq:             # <<<<<<<<<<<<<<
 *                         for i from pos <= i < pos + l:
 *                             result.append((qpos, None, None))
 */
          goto __pyx_L20;
        }

        /* "pysam/calignedsegment.pyx":1502
 *                             qpos += 1
 *                     else:
 *                         for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                             result.append((qpos, None))
 *                             qpos += 1
 */
        /*else*/ {
          __pyx_t_9 = (__pyx_v_pos + __pyx_v_l);
          for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

            /* "pysam/calignedsegment.pyx":1503
 *                     else:
 *                         for i from pos <= i < pos + l:
 *                             result.append((qpos, None))             # <<<<<<<<<<<<<<
 *                             qpos += 1
 *                 else:
 */
            __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_5);
            PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
            __Pyx_INCREF(Py_None);
            __Pyx_GIVEREF(Py_None);
            PyTuple_SET_ITEM(__pyx_t_3, 1, Py_None);
            __pyx_t_5 = 0;
            __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

            /* "pysam/calignedsegment.pyx":1504
 *                         for i from pos <= i < pos + l:
 *                             result.append((qpos, None))
 *                             qpos += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     qpos += l
 */
            __pyx_v_qpos = (__pyx_v_qpos + 1);
          }
        }
        __pyx_L20:;

        /* "pysam/calignedsegment.pyx":1496
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 *                 if not _matches_only:             # <<<<<<<<<<<<<<
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:
 */
        goto __pyx_L19;
      }

      /* "pysam/calignedsegment.pyx":1506
 *                             qpos += 1
 *                 else:
 *                     qpos += l             # <<<<<<<<<<<<<<
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
      /*else*/ {
        __pyx_v_qpos = (__pyx_v_qpos + __pyx_v_l);
      }
      __pyx_L19:;

      /* "pysam/calignedsegment.pyx":1495
 *                 pos += l
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 if not _matches_only:
 *                     if _with_seq:
 */
      goto __pyx_L8;
    }

    /* "pysam/calignedsegment.pyx":1508
 *                     qpos += l
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 if not _matches_only:
 *                     if _with_seq:
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_6 = __pyx_t_2;
      goto __pyx_L25_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_6 = __pyx_t_2;
    __pyx_L25_bool_binop_done:;
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":1509
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 if not _matches_only:             # <<<<<<<<<<<<<<
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:
 */
      __pyx_t_6 = ((!(__pyx_v__matches_only != 0)) != 0);
      if (__pyx_t_6) {

        /* "pysam/calignedsegment.pyx":1510
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 if not _matches_only:
 *                     if _with_seq:             # <<<<<<<<<<<<<<
 *                         for i from pos <= i < pos + l:
 *                             result.append((None, i, ref_seq[r_idx]))
 */
        __pyx_t_6 = (__pyx_v__with_seq != 0);
        if (__pyx_t_6) {

          /* "pysam/calignedsegment.pyx":1511
 *                 if not _matches_only:
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                             result.append((None, i, ref_seq[r_idx]))
 *                             r_idx += 1
 */
          __pyx_t_9 = (__pyx_v_pos + __pyx_v_l);
          for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

            /* "pysam/calignedsegment.pyx":1512
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:
 *                             result.append((None, i, ref_seq[r_idx]))             # <<<<<<<<<<<<<<
 *                             r_idx += 1
 *                     else:
 */
            __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_3);
            if (unlikely(!__pyx_v_ref_seq)) { __Pyx_RaiseUnboundLocalError("ref_seq"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1512; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
            __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_ref_seq, __pyx_v_r_idx, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1512; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_INCREF(Py_None);
            __Pyx_GIVEREF(Py_None);
            PyTuple_SET_ITEM(__pyx_t_10, 0, Py_None);
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_5);
            PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_5);
            __pyx_t_3 = 0;
            __pyx_t_5 = 0;
            __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1512; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

            /* "pysam/calignedsegment.pyx":1513
 *                         for i from pos <= i < pos + l:
 *                             result.append((None, i, ref_seq[r_idx]))
 *                             r_idx += 1             # <<<<<<<<<<<<<<
 *                     else:
 *                         for i from pos <= i < pos + l:
 */
            __pyx_v_r_idx = (__pyx_v_r_idx + 1);
          }

          /* "pysam/calignedsegment.pyx":1510
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 if not _matches_only:
 *                     if _with_seq:             # <<<<<<<<<<<<<<
 *                         for i from pos <= i < pos + l:
 *                             result.append((None, i, ref_seq[r_idx]))
 */
          goto __pyx_L28;
        }

        /* "pysam/calignedsegment.pyx":1515
 *                             r_idx += 1
 *                     else:
 *                         for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                             result.append((None, i))
 *                 pos += l
 */
        /*else*/ {
          __pyx_t_9 = (__pyx_v_pos + __pyx_v_l);
          for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_9; __pyx_v_i++) {

            /* "pysam/calignedsegment.pyx":1516
 *                     else:
 *                         for i from pos <= i < pos + l:
 *                             result.append((None, i))             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
            __pyx_t_10 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_INCREF(Py_None);
            __Pyx_GIVEREF(Py_None);
            PyTuple_SET_ITEM(__pyx_t_5, 0, Py_None);
            __Pyx_GIVEREF(__pyx_t_10);
            PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_10);
            __pyx_t_10 = 0;
            __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1516; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
        }
        __pyx_L28:;

        /* "pysam/calignedsegment.pyx":1509
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 if not _matches_only:             # <<<<<<<<<<<<<<
 *                     if _with_seq:
 *                         for i from pos <= i < pos + l:
 */
      }

      /* "pysam/calignedsegment.pyx":1517
 *                         for i from pos <= i < pos + l:
 *                             result.append((None, i))
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *             elif op == BAM_CHARD_CLIP:
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);

      /* "pysam/calignedsegment.pyx":1508
 *                     qpos += l
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 if not _matches_only:
 *                     if _with_seq:
 */
      goto __pyx_L8;
    }

    /* "pysam/calignedsegment.pyx":1519
 *                 pos += l
 * 
 *             elif op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 pass # advances neither
 * 
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
    if (__pyx_t_6) {
      goto __pyx_L8;
    }

    /* "pysam/calignedsegment.pyx":1522
 *                 pass # advances neither
 * 
 *             elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *                 raise NotImplementedError(
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CPAD) != 0);
    if (__pyx_t_6) {

      /* "pysam/calignedsegment.pyx":1523
 * 
 *             elif op == BAM_CPAD:
 *                 raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 *                     "Please implement. Sorry about that.")
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1523; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignedsegment.pyx":1522
 *                 pass # advances neither
 * 
 *             elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *                 raise NotImplementedError(
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 */
    }
    __pyx_L8:;
  }

  /* "pysam/calignedsegment.pyx":1527
 *                     "Please implement. Sorry about that.")
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def get_blocks(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1430
 * 
 * 
 *     def get_aligned_pairs(self, matches_only=False, with_seq=False):             # <<<<<<<<<<<<<<
 *         """a list of aligned read (query) and reference positions.
 * 
 */

  /* 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_10);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ref_seq);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1529
 *         return result
 * 
 *     def get_blocks(self):             # <<<<<<<<<<<<<<
 *         """ a list of start and end positions of
 *         aligned gapless blocks.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_27get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_26get_blocks[] = "AlignedSegment.get_blocks(self)\n a list of start and end positions of\n        aligned gapless blocks.\n\n        The start and end positions are in genomic\n        coordinates.\n\n        Blocks are not normalized, i.e. two blocks\n        might be directly adjacent. This happens if\n        the two blocks are separated by an insertion\n        in the read.\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_27get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_blocks (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_26get_blocks(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_26get_blocks(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_l;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_blocks", 0);
  __Pyx_TraceCall("get_blocks", __pyx_f[0], 1529, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1529; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1547
 *         cdef bam1_t * src
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1548
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1549
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1548
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1551
 *             return []
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":1552
 * 
 *         result = []
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src)
 *         l = 0
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/calignedsegment.pyx":1553
 *         result = []
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *         l = 0
 * 
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1554
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)
 *         l = 0             # <<<<<<<<<<<<<<
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_l = 0;

  /* "pysam/calignedsegment.pyx":1556
 *         l = 0
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":1557
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH:
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":1558
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             if op == BAM_CMATCH:
 *                 result.append((pos, pos + l))
 */
    __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT);

    /* "pysam/calignedsegment.pyx":1559
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 result.append((pos, pos + l))
 *                 pos += l
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":1560
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH:
 *                 result.append((pos, pos + l))             # <<<<<<<<<<<<<<
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_pos + __pyx_v_l)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
      __pyx_t_3 = 0;
      __pyx_t_6 = 0;
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/calignedsegment.pyx":1561
 *             if op == BAM_CMATCH:
 *                 result.append((pos, pos + l))
 *                 pos += l             # <<<<<<<<<<<<<<
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);

      /* "pysam/calignedsegment.pyx":1559
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 result.append((pos, pos + l))
 *                 pos += l
 */
      goto __pyx_L6;
    }

    /* "pysam/calignedsegment.pyx":1562
 *                 result.append((pos, pos + l))
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    __pyx_t_9 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_9) {
    } else {
      __pyx_t_2 = __pyx_t_9;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_9 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_2 = __pyx_t_9;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":1563
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);

      /* "pysam/calignedsegment.pyx":1562
 *                 result.append((pos, pos + l))
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    }
    __pyx_L6:;
  }

  /* "pysam/calignedsegment.pyx":1565
 *                 pos += l
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def get_overlap(self, uint32_t start, uint32_t end):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1529
 *         return result
 * 
 *     def get_blocks(self):             # <<<<<<<<<<<<<<
 *         """ a list of start and end positions of
 *         aligned gapless blocks.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_blocks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1567
 *         return result
 * 
 *     def get_overlap(self, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *         """return number of aligned bases of read overlapping the interval
 *         *start* and *end* on the reference sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_29get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_28get_overlap[] = "AlignedSegment.get_overlap(self, uint32_t start, uint32_t end)\nreturn number of aligned bases of read overlapping the interval\n        *start* and *end* on the reference sequence.\n\n        Return None if cigar alignment is not available.\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_29get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_overlap (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start,&__pyx_n_s_end,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_overlap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_start == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_As_uint32_t(values[1]); if (unlikely((__pyx_v_end == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_28get_overlap(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_start, __pyx_v_end);

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_28get_overlap(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_overlap;
  int __pyx_v_op;
  int __pyx_v_o;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  uint16_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  uint32_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  uint32_t __pyx_t_10;
  uint32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_overlap", 0);
  __Pyx_TraceCall("get_overlap", __pyx_f[0], 1567, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1567; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1578
 *         cdef bam1_t * src
 * 
 *         overlap = 0             # <<<<<<<<<<<<<<
 * 
 *         src = self._delegate
 */
  __pyx_v_overlap = 0;

  /* "pysam/calignedsegment.pyx":1580
 *         overlap = 0
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1581
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return None
 *         pos = src.core.pos
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1582
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return None             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         o = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1581
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return None
 *         pos = src.core.pos
 */
  }

  /* "pysam/calignedsegment.pyx":1583
 *         if pysam_get_n_cigar(src) == 0:
 *             return None
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         o = 0
 * 
 */
  __pyx_t_3 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_3;

  /* "pysam/calignedsegment.pyx":1584
 *             return None
 *         pos = src.core.pos
 *         o = 0             # <<<<<<<<<<<<<<
 * 
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_v_o = 0;

  /* "pysam/calignedsegment.pyx":1586
 *         o = 0
 * 
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1587
 * 
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":1588
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":1589
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH:
 */
    __pyx_t_5 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1589; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysam/calignedsegment.pyx":1591
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 o = min( pos + l, end) - max( pos, start )
 *                 if o > 0: overlap += o
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":1592
 * 
 *             if op == BAM_CMATCH:
 *                 o = min( pos + l, end) - max( pos, start )             # <<<<<<<<<<<<<<
 *                 if o > 0: overlap += o
 * 
 */
      __pyx_t_6 = __pyx_v_end;
      __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_5 = __pyx_t_9;
        __pyx_t_9 = 0;
      } else {
        __Pyx_INCREF(__pyx_t_7);
        __pyx_t_5 = __pyx_t_7;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_6 = __pyx_v_start;
      __pyx_t_10 = __pyx_v_pos;
      if (((__pyx_t_6 > __pyx_t_10) != 0)) {
        __pyx_t_11 = __pyx_t_6;
      } else {
        __pyx_t_11 = __pyx_t_10;
      }
      __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = PyNumber_Subtract(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_o = __pyx_t_12;

      /* "pysam/calignedsegment.pyx":1593
 *             if op == BAM_CMATCH:
 *                 o = min( pos + l, end) - max( pos, start )
 *                 if o > 0: overlap += o             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
      __pyx_t_2 = ((__pyx_v_o > 0) != 0);
      if (__pyx_t_2) {
        __pyx_v_overlap = (__pyx_v_overlap + __pyx_v_o);
      }

      /* "pysam/calignedsegment.pyx":1591
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 o = min( pos + l, end) - max( pos, start )
 *                 if o > 0: overlap += o
 */
    }

    /* "pysam/calignedsegment.pyx":1595
 *                 if o > 0: overlap += o
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    __pyx_t_13 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_13) {
    } else {
      __pyx_t_2 = __pyx_t_13;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_13 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_13) {
    } else {
      __pyx_t_2 = __pyx_t_13;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_13 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_2 = __pyx_t_13;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":1596
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *         return overlap
 */
      __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_11 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_11 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1596; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_pos = __pyx_t_11;

      /* "pysam/calignedsegment.pyx":1595
 *                 if o > 0: overlap += o
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    }
  }

  /* "pysam/calignedsegment.pyx":1598
 *                 pos += l
 * 
 *         return overlap             # <<<<<<<<<<<<<<
 * 
 *     #####################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1567
 *         return result
 * 
 *     def get_overlap(self, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *         """return number of aligned bases of read overlapping the interval
 *         *start* and *end* on the reference sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1641
 *         or None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * cigar_p
 *             cdef bam1_t * src
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigartuples___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigartuples___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_l;
  int __pyx_v_k;
  PyObject *__pyx_v_cigar = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  uint16_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1641, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1641; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1647
 *             cdef int k
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1648
 * 
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1649
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             cigar = []
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1648
 * 
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1651
 *                 return None
 * 
 *             cigar = []             # <<<<<<<<<<<<<<
 * 
 *             cigar_p = pysam_bam_get_cigar(src);
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_cigar = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":1653
 *             cigar = []
 * 
 *             cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1654
 * 
 *             cigar_p = pysam_bam_get_cigar(src);
 *             for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/calignedsegment.pyx":1655
 *             cigar_p = pysam_bam_get_cigar(src);
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignedsegment.pyx":1656
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *                 cigar.append((op, l))
 *             return cigar
 */
    __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT);

    /* "pysam/calignedsegment.pyx":1657
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
 *             return cigar
 * 
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_op); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_cigar, __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }

  /* "pysam/calignedsegment.pyx":1658
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 *             return cigar             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, values):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_cigar);
  __pyx_r = __pyx_v_cigar;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1641
 *         or None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * cigar_p
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.cigartuples.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_cigar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1660
 *             return cigar
 * 
 *         def __set__(self, values):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * p
 *             cdef bam1_t * src
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_values));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_values) {
  uint32_t *__pyx_v_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_op = 0;
  PyObject *__pyx_v_l = 0;
  int __pyx_v_k;
  int __pyx_v_ncigar;
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  uint32_t __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 1660, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_INCREF(__pyx_v_values);

  /* "pysam/calignedsegment.pyx":1666
 *             cdef int k, ncigar
 * 
 *             k = 0             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
  __pyx_v_k = 0;

  /* "pysam/calignedsegment.pyx":1668
 *             k = 0
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             # get location of cigar string
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1671
 * 
 *             # get location of cigar string
 *             p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # empty values for cigar string
 */
  __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1674
 * 
 *             # empty values for cigar string
 *             if values is None:             # <<<<<<<<<<<<<<
 *                 values = []
 * 
 */
  __pyx_t_2 = (__pyx_v_values == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/calignedsegment.pyx":1675
 *             # empty values for cigar string
 *             if values is None:
 *                 values = []             # <<<<<<<<<<<<<<
 * 
 *             ncigar = len(values)
 */
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pysam/calignedsegment.pyx":1674
 * 
 *             # empty values for cigar string
 *             if values is None:             # <<<<<<<<<<<<<<
 *                 values = []
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1677
 *                 values = []
 * 
 *             ncigar = len(values)             # <<<<<<<<<<<<<<
 *             # create space for cigar data within src.data
 *             pysam_bam_update(src,
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_ncigar = __pyx_t_5;

  /* "pysam/calignedsegment.pyx":1679
 *             ncigar = len(values)
 *             # create space for cigar data within src.data
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              pysam_get_n_cigar(src) * 4,
 *                              ncigar * 4,
 */
  pysam_bam_update(__pyx_v_src, (pysam_get_n_cigar(__pyx_v_src) * 4), (__pyx_v_ncigar * 4), ((uint8_t *)__pyx_v_p));

  /* "pysam/calignedsegment.pyx":1685
 * 
 *             # length is number of cigar operations, not bytes
 *             pysam_set_n_cigar(src, ncigar)             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  pysam_set_n_cigar(__pyx_v_src, __pyx_v_ncigar);

  /* "pysam/calignedsegment.pyx":1689
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # insert cigar operations
 */
  __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1692
 * 
 *             # insert cigar operations
 *             for op, l in values:             # <<<<<<<<<<<<<<
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1
 */
  if (likely(PyList_CheckExact(__pyx_v_values)) || PyTuple_CheckExact(__pyx_v_values)) {
    __pyx_t_4 = __pyx_v_values; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
      PyObject* sequence = __pyx_t_7;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L7_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_op, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pysam/calignedsegment.pyx":1693
 *             # insert cigar operations
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op             # <<<<<<<<<<<<<<
 *                 k += 1
 * 
 */
    __pyx_t_7 = __Pyx_PyInt_From_int(BAM_CIGAR_SHIFT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyNumber_Lshift(__pyx_v_l, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Or(__pyx_t_9, __pyx_v_op); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_12 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_12 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    (__pyx_v_p[__pyx_v_k]) = __pyx_t_12;

    /* "pysam/calignedsegment.pyx":1694
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1             # <<<<<<<<<<<<<<
 * 
 *             ## setting the cigar string requires updating the bin
 */
    __pyx_v_k = (__pyx_v_k + 1);

    /* "pysam/calignedsegment.pyx":1692
 * 
 *             # insert cigar operations
 *             for op, l in values:             # <<<<<<<<<<<<<<
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignedsegment.pyx":1697
 * 
 *             ## setting the cigar string requires updating the bin
 *             pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                           hts_reg2bin(
 *                               src.core.pos,
 */
  pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5));

  /* "pysam/calignedsegment.pyx":1660
 *             return cigar
 * 
 *         def __set__(self, values):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * p
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.cigartuples.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_op);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1705
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */

static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_31set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_set_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag *__pyx_optional_args) {

  /* "pysam/calignedsegment.pyx":1708
 *                   tag,
 *                   value,
 *                   value_type=None,             # <<<<<<<<<<<<<<
 *                   replace=True):
 *         """sets a particular field *tag* to *value* in the optional alignment
 */
  PyObject *__pyx_v_value_type = ((PyObject *)Py_None);

  /* "pysam/calignedsegment.pyx":1709
 *                   value,
 *                   value_type=None,
 *                   replace=True):             # <<<<<<<<<<<<<<
 *         """sets a particular field *tag* to *value* in the optional alignment
 *         section.
 */
  PyObject *__pyx_v_replace = ((PyObject *)Py_True);
  int __pyx_v_value_size;
  uint8_t *__pyx_v_value_ptr;
  uint8_t *__pyx_v_existing_ptr;
  uint8_t __pyx_v_typecode;
  float __pyx_v_float_value;
  double __pyx_v_double_value;
  int32_t __pyx_v_int_value;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_buffer = 0;
  PyObject *__pyx_v_fmt = NULL;
  PyObject *__pyx_v_args = NULL;
  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;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  bam1_t *__pyx_t_7;
  int __pyx_t_8;
  char const *__pyx_t_9;
  int __pyx_t_10;
  uint8_t __pyx_t_11;
  struct __pyx_opt_args_5pysam_15calignedsegment_get_value_code __pyx_t_12;
  char *__pyx_t_13;
  int32_t __pyx_t_14;
  double __pyx_t_15;
  float __pyx_t_16;
  PyObject *(*__pyx_t_17)(PyObject *);
  int __pyx_t_18;
  char const *__pyx_t_19;
  uint8_t *__pyx_t_20;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_tag", 0);
  __Pyx_TraceCall("set_tag", __pyx_f[0], 1705, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_value_type = __pyx_optional_args->value_type;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_replace = __pyx_optional_args->replace;
      }
    }
  }
  __Pyx_INCREF(__pyx_v_tag);
  __Pyx_INCREF(__pyx_v_value);

  /* "pysam/calignedsegment.pyx":1705
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */
  /* 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_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_31set_tag)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && 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;
        }
      }
      __pyx_t_6 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_tag);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_value);
      __Pyx_INCREF(__pyx_v_value_type);
      __Pyx_GIVEREF(__pyx_v_value_type);
      PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_value_type);
      __Pyx_INCREF(__pyx_v_replace);
      __Pyx_GIVEREF(__pyx_v_replace);
      PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_5, __pyx_v_replace);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignedsegment.pyx":1732
 *         cdef double double_value
 *         cdef int32_t int_value
 *         cdef bam1_t * src = self._delegate             # <<<<<<<<<<<<<<
 *         cdef char * _value_type
 *         cdef c_array.array array_value
 */
  __pyx_t_7 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_7;

  /* "pysam/calignedsegment.pyx":1737
 *         cdef object buffer
 * 
 *         if len(tag) != 2:             # <<<<<<<<<<<<<<
 *             raise ValueError('Invalid tag: %s' % tag)
 * 
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = ((__pyx_t_5 != 2) != 0);
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1738
 * 
 *         if len(tag) != 2:
 *             raise ValueError('Invalid tag: %s' % tag)             # <<<<<<<<<<<<<<
 * 
 *         tag = force_bytes(tag)
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_tag_s, __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":1737
 *         cdef object buffer
 * 
 *         if len(tag) != 2:             # <<<<<<<<<<<<<<
 *             raise ValueError('Invalid tag: %s' % tag)
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1740
 *             raise ValueError('Invalid tag: %s' % tag)
 * 
 *         tag = force_bytes(tag)             # <<<<<<<<<<<<<<
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)
 */
  __pyx_t_1 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_tag, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":1741
 * 
 *         tag = force_bytes(tag)
 *         if replace:             # <<<<<<<<<<<<<<
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:
 */
  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_replace); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1742
 *         tag = force_bytes(tag)
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)             # <<<<<<<<<<<<<<
 *             if existing_ptr:
 *                 bam_aux_del(src, existing_ptr)
 */
    __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_existing_ptr = bam_aux_get(__pyx_v_src, __pyx_t_9);

    /* "pysam/calignedsegment.pyx":1743
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:             # <<<<<<<<<<<<<<
 *                 bam_aux_del(src, existing_ptr)
 * 
 */
    __pyx_t_8 = (__pyx_v_existing_ptr != 0);
    if (__pyx_t_8) {

      /* "pysam/calignedsegment.pyx":1744
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:
 *                 bam_aux_del(src, existing_ptr)             # <<<<<<<<<<<<<<
 * 
 *         # setting value to None deletes a tag
 */
      bam_aux_del(__pyx_v_src, __pyx_v_existing_ptr);

      /* "pysam/calignedsegment.pyx":1743
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:             # <<<<<<<<<<<<<<
 *                 bam_aux_del(src, existing_ptr)
 * 
 */
    }

    /* "pysam/calignedsegment.pyx":1741
 * 
 *         tag = force_bytes(tag)
 *         if replace:             # <<<<<<<<<<<<<<
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:
 */
  }

  /* "pysam/calignedsegment.pyx":1747
 * 
 *         # setting value to None deletes a tag
 *         if value is None:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_8 = (__pyx_v_value == Py_None);
  __pyx_t_10 = (__pyx_t_8 != 0);
  if (__pyx_t_10) {

    /* "pysam/calignedsegment.pyx":1748
 *         # setting value to None deletes a tag
 *         if value is None:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         typecode = get_value_code(value, value_type)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1747
 * 
 *         # setting value to None deletes a tag
 *         if value is None:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1750
 *             return
 * 
 *         typecode = get_value_code(value, value_type)             # <<<<<<<<<<<<<<
 *         if typecode == 0:
 *             raise ValueError("can't guess type or invalid type code specified")
 */
  __pyx_t_12.__pyx_n = 1;
  __pyx_t_12.value_type = __pyx_v_value_type;
  __pyx_t_11 = __pyx_f_5pysam_15calignedsegment_get_value_code(__pyx_v_value, &__pyx_t_12); 
  __pyx_v_typecode = __pyx_t_11;

  /* "pysam/calignedsegment.pyx":1751
 * 
 *         typecode = get_value_code(value, value_type)
 *         if typecode == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("can't guess type or invalid type code specified")
 * 
 */
  __pyx_t_10 = ((__pyx_v_typecode == 0) != 0);
  if (__pyx_t_10) {

    /* "pysam/calignedsegment.pyx":1752
 *         typecode = get_value_code(value, value_type)
 *         if typecode == 0:
 *             raise ValueError("can't guess type or invalid type code specified")             # <<<<<<<<<<<<<<
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1752; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":1751
 * 
 *         typecode = get_value_code(value, value_type)
 *         if typecode == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("can't guess type or invalid type code specified")
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":1755
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 *         if typecode == 'Z':             # <<<<<<<<<<<<<<
 *             value = force_bytes(value)
 *             value_ptr = <uint8_t*><char*>value
 */
  switch (__pyx_v_typecode) {
    case 'Z':

    /* "pysam/calignedsegment.pyx":1756
 *         # Not Endian-safe, but then again neither is samtools!
 *         if typecode == 'Z':
 *             value = force_bytes(value)             # <<<<<<<<<<<<<<
 *             value_ptr = <uint8_t*><char*>value
 *             value_size = len(value)+1
 */
    __pyx_t_1 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_value, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1756; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/calignedsegment.pyx":1757
 *         if typecode == 'Z':
 *             value = force_bytes(value)
 *             value_ptr = <uint8_t*><char*>value             # <<<<<<<<<<<<<<
 *             value_size = len(value)+1
 *         elif typecode == 'i':
 */
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_value_ptr = ((uint8_t *)((char *)__pyx_t_13));

    /* "pysam/calignedsegment.pyx":1758
 *             value = force_bytes(value)
 *             value_ptr = <uint8_t*><char*>value
 *             value_size = len(value)+1             # <<<<<<<<<<<<<<
 *         elif typecode == 'i':
 *             int_value = value
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1758; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_value_size = (__pyx_t_5 + 1);

    /* "pysam/calignedsegment.pyx":1755
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 *         if typecode == 'Z':             # <<<<<<<<<<<<<<
 *             value = force_bytes(value)
 *             value_ptr = <uint8_t*><char*>value
 */
    break;

    /* "pysam/calignedsegment.pyx":1759
 *             value_ptr = <uint8_t*><char*>value
 *             value_size = len(value)+1
 *         elif typecode == 'i':             # <<<<<<<<<<<<<<
 *             int_value = value
 *             value_ptr = <uint8_t*>&int_value
 */
    case 'i':

    /* "pysam/calignedsegment.pyx":1760
 *             value_size = len(value)+1
 *         elif typecode == 'i':
 *             int_value = value             # <<<<<<<<<<<<<<
 *             value_ptr = <uint8_t*>&int_value
 *             value_size = sizeof(int32_t)
 */
    __pyx_t_14 = __Pyx_PyInt_As_int32_t(__pyx_v_value); if (unlikely((__pyx_t_14 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_int_value = __pyx_t_14;

    /* "pysam/calignedsegment.pyx":1761
 *         elif typecode == 'i':
 *             int_value = value
 *             value_ptr = <uint8_t*>&int_value             # <<<<<<<<<<<<<<
 *             value_size = sizeof(int32_t)
 *         elif typecode == 'd':
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_int_value));

    /* "pysam/calignedsegment.pyx":1762
 *             int_value = value
 *             value_ptr = <uint8_t*>&int_value
 *             value_size = sizeof(int32_t)             # <<<<<<<<<<<<<<
 *         elif typecode == 'd':
 *             double_value = value
 */
    __pyx_v_value_size = (sizeof(int32_t));

    /* "pysam/calignedsegment.pyx":1759
 *             value_ptr = <uint8_t*><char*>value
 *             value_size = len(value)+1
 *         elif typecode == 'i':             # <<<<<<<<<<<<<<
 *             int_value = value
 *             value_ptr = <uint8_t*>&int_value
 */
    break;

    /* "pysam/calignedsegment.pyx":1763
 *             value_ptr = <uint8_t*>&int_value
 *             value_size = sizeof(int32_t)
 *         elif typecode == 'd':             # <<<<<<<<<<<<<<
 *             double_value = value
 *             value_ptr = <uint8_t*>&double_value
 */
    case 'd':

    /* "pysam/calignedsegment.pyx":1764
 *             value_size = sizeof(int32_t)
 *         elif typecode == 'd':
 *             double_value = value             # <<<<<<<<<<<<<<
 *             value_ptr = <uint8_t*>&double_value
 *             value_size = sizeof(double)
 */
    __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_double_value = __pyx_t_15;

    /* "pysam/calignedsegment.pyx":1765
 *         elif typecode == 'd':
 *             double_value = value
 *             value_ptr = <uint8_t*>&double_value             # <<<<<<<<<<<<<<
 *             value_size = sizeof(double)
 *         elif typecode == 'f':
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_double_value));

    /* "pysam/calignedsegment.pyx":1766
 *             double_value = value
 *             value_ptr = <uint8_t*>&double_value
 *             value_size = sizeof(double)             # <<<<<<<<<<<<<<
 *         elif typecode == 'f':
 *             float_value  = value
 */
    __pyx_v_value_size = (sizeof(double));

    /* "pysam/calignedsegment.pyx":1763
 *             value_ptr = <uint8_t*>&int_value
 *             value_size = sizeof(int32_t)
 *         elif typecode == 'd':             # <<<<<<<<<<<<<<
 *             double_value = value
 *             value_ptr = <uint8_t*>&double_value
 */
    break;

    /* "pysam/calignedsegment.pyx":1767
 *             value_ptr = <uint8_t*>&double_value
 *             value_size = sizeof(double)
 *         elif typecode == 'f':             # <<<<<<<<<<<<<<
 *             float_value  = value
 *             value_ptr = <uint8_t*>&float_value
 */
    case 'f':

    /* "pysam/calignedsegment.pyx":1768
 *             value_size = sizeof(double)
 *         elif typecode == 'f':
 *             float_value  = value             # <<<<<<<<<<<<<<
 *             value_ptr = <uint8_t*>&float_value
 *             value_size = sizeof(float)
 */
    __pyx_t_16 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_16 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_float_value = __pyx_t_16;

    /* "pysam/calignedsegment.pyx":1769
 *         elif typecode == 'f':
 *             float_value  = value
 *             value_ptr = <uint8_t*>&float_value             # <<<<<<<<<<<<<<
 *             value_size = sizeof(float)
 *         elif typecode == 'B':
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_float_value));

    /* "pysam/calignedsegment.pyx":1770
 *             float_value  = value
 *             value_ptr = <uint8_t*>&float_value
 *             value_size = sizeof(float)             # <<<<<<<<<<<<<<
 *         elif typecode == 'B':
 *             # the following goes through python, needs to be cleaned up
 */
    __pyx_v_value_size = (sizeof(float));

    /* "pysam/calignedsegment.pyx":1767
 *             value_ptr = <uint8_t*>&double_value
 *             value_size = sizeof(double)
 *         elif typecode == 'f':             # <<<<<<<<<<<<<<
 *             float_value  = value
 *             value_ptr = <uint8_t*>&float_value
 */
    break;

    /* "pysam/calignedsegment.pyx":1771
 *             value_ptr = <uint8_t*>&float_value
 *             value_size = sizeof(float)
 *         elif typecode == 'B':             # <<<<<<<<<<<<<<
 *             # the following goes through python, needs to be cleaned up
 *             # pack array using struct
 */
    case 'B':

    /* "pysam/calignedsegment.pyx":1774
 *             # the following goes through python, needs to be cleaned up
 *             # pack array using struct
 *             if value_type is None:             # <<<<<<<<<<<<<<
 *                 fmt, args = packTags([(tag, value)])
 *             else:
 */
    __pyx_t_10 = (__pyx_v_value_type == Py_None);
    __pyx_t_8 = (__pyx_t_10 != 0);
    if (__pyx_t_8) {

      /* "pysam/calignedsegment.pyx":1775
 *             # pack array using struct
 *             if value_type is None:
 *                 fmt, args = packTags([(tag, value)])             # <<<<<<<<<<<<<<
 *             else:
 *                 fmt, args = packTags([(tag, value, value_type)])
 */
      __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tag);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_value);
      __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __pyx_f_5pysam_15calignedsegment_packTags(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        #else
        __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_17 = Py_TYPE(__pyx_t_6)->tp_iternext;
        index = 0; __pyx_t_2 = __pyx_t_17(__pyx_t_6); if (unlikely(!__pyx_t_2)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_2);
        index = 1; __pyx_t_3 = __pyx_t_17(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L9_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_17 = NULL;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L10_unpacking_done;
        __pyx_L9_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_17 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L10_unpacking_done:;
      }
      __pyx_v_fmt = __pyx_t_2;
      __pyx_t_2 = 0;
      __pyx_v_args = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "pysam/calignedsegment.pyx":1774
 *             # the following goes through python, needs to be cleaned up
 *             # pack array using struct
 *             if value_type is None:             # <<<<<<<<<<<<<<
 *                 fmt, args = packTags([(tag, value)])
 *             else:
 */
      goto __pyx_L8;
    }

    /* "pysam/calignedsegment.pyx":1777
 *                 fmt, args = packTags([(tag, value)])
 *             else:
 *                 fmt, args = packTags([(tag, value, value_type)])             # <<<<<<<<<<<<<<
 * 
 *             # remove tag and type code as set by bam_aux_append
 */
    /*else*/ {
      __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tag);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_value);
      __Pyx_INCREF(__pyx_v_value_type);
      __Pyx_GIVEREF(__pyx_v_value_type);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_value_type);
      __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __pyx_f_5pysam_15calignedsegment_packTags(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
        PyObject* sequence = __pyx_t_1;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        #endif
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_6 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_17 = Py_TYPE(__pyx_t_6)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_17(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_2 = __pyx_t_17(__pyx_t_6); if (unlikely(!__pyx_t_2)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_2);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_17(__pyx_t_6), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_17 = NULL;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L12_unpacking_done;
        __pyx_L11_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_17 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L12_unpacking_done:;
      }
      __pyx_v_fmt = __pyx_t_3;
      __pyx_t_3 = 0;
      __pyx_v_args = __pyx_t_2;
      __pyx_t_2 = 0;
    }
    __pyx_L8:;

    /* "pysam/calignedsegment.pyx":1781
 *             # remove tag and type code as set by bam_aux_append
 *             # first four chars of format (<2sc)
 *             fmt = '<' + fmt[4:]             # <<<<<<<<<<<<<<
 *             # first two values to pack
 *             args = args[2:]
 */
    __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_fmt, 4, 0, NULL, NULL, &__pyx_slice__26, 1, 0, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Add(__pyx_kp_s__4, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_fmt, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/calignedsegment.pyx":1783
 *             fmt = '<' + fmt[4:]
 *             # first two values to pack
 *             args = args[2:]             # <<<<<<<<<<<<<<
 *             value_size = struct.calcsize(fmt)
 *             # buffer will be freed when object goes out of scope
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_args, 2, 0, NULL, NULL, &__pyx_slice__27, 1, 0, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_args, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/calignedsegment.pyx":1784
 *             # first two values to pack
 *             args = args[2:]
 *             value_size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
 *             # buffer will be freed when object goes out of scope
 *             buffer = ctypes.create_string_buffer(value_size)
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_fmt); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(__pyx_v_fmt);
      __Pyx_GIVEREF(__pyx_v_fmt);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_fmt);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_18 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_18 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_value_size = __pyx_t_18;

    /* "pysam/calignedsegment.pyx":1786
 *             value_size = struct.calcsize(fmt)
 *             # buffer will be freed when object goes out of scope
 *             buffer = ctypes.create_string_buffer(value_size)             # <<<<<<<<<<<<<<
 *             struct.pack_into(fmt, buffer, 0, *args)
 *             # bam_aux_append copies data from value_ptr
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_value_size); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_buffer = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysam/calignedsegment.pyx":1787
 *             # buffer will be freed when object goes out of scope
 *             buffer = ctypes.create_string_buffer(value_size)
 *             struct.pack_into(fmt, buffer, 0, *args)             # <<<<<<<<<<<<<<
 *             # bam_aux_append copies data from value_ptr
 *             bam_aux_append(src,
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_fmt);
    __Pyx_GIVEREF(__pyx_v_fmt);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fmt);
    __Pyx_INCREF(__pyx_v_buffer);
    __Pyx_GIVEREF(__pyx_v_buffer);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_buffer);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
    __pyx_t_4 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/calignedsegment.pyx":1790
 *             # bam_aux_append copies data from value_ptr
 *             bam_aux_append(src,
 *                            tag,             # <<<<<<<<<<<<<<
 *                            typecode,
 *                            value_size,
 */
    __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1790; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":1793
 *                            typecode,
 *                            value_size,
 *                            <uint8_t*>buffer.raw)             # <<<<<<<<<<<<<<
 *             return
 *         else:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_20 = __Pyx_PyObject_AsUString(__pyx_t_4); if (unlikely((!__pyx_t_20) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":1789
 *             struct.pack_into(fmt, buffer, 0, *args)
 *             # bam_aux_append copies data from value_ptr
 *             bam_aux_append(src,             # <<<<<<<<<<<<<<
 *                            tag,
 *                            typecode,
 */
    bam_aux_append(__pyx_v_src, __pyx_t_19, __pyx_v_typecode, __pyx_v_value_size, ((uint8_t *)__pyx_t_20));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "pysam/calignedsegment.pyx":1794
 *                            value_size,
 *                            <uint8_t*>buffer.raw)
 *             return             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError('unsupported value_type in set_option')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1771
 *             value_ptr = <uint8_t*>&float_value
 *             value_size = sizeof(float)
 *         elif typecode == 'B':             # <<<<<<<<<<<<<<
 *             # the following goes through python, needs to be cleaned up
 *             # pack array using struct
 */
    break;
    default:

    /* "pysam/calignedsegment.pyx":1796
 *             return
 *         else:
 *             raise ValueError('unsupported value_type in set_option')             # <<<<<<<<<<<<<<
 * 
 *         bam_aux_append(src,
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "pysam/calignedsegment.pyx":1799
 * 
 *         bam_aux_append(src,
 *                        tag,             # <<<<<<<<<<<<<<
 *                        typecode,
 *                        value_size,
 */
  __pyx_t_19 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_19) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":1798
 *             raise ValueError('unsupported value_type in set_option')
 * 
 *         bam_aux_append(src,             # <<<<<<<<<<<<<<
 *                        tag,
 *                        typecode,
 */
  bam_aux_append(__pyx_v_src, __pyx_t_19, __pyx_v_typecode, __pyx_v_value_size, __pyx_v_value_ptr);

  /* "pysam/calignedsegment.pyx":1705
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */

  /* 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_6);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_buffer);
  __Pyx_XDECREF(__pyx_v_fmt);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_tag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_31set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_30set_tag[] = "AlignedSegment.set_tag(self, tag, value, value_type=None, replace=True)\nsets a particular field *tag* to *value* in the optional alignment\n        section.\n\n        *value_type* describes the type of *value* that is to entered\n        into the alignment record.. It can be set explicitly to one\n        of the valid one-letter type codes. If unset, an appropriate\n        type will be chosen automatically.\n\n        An existing value of the same *tag* will be overwritten unless\n        replace is set to False. This is usually not recommened as a\n        tag may only appear once in the optional alignment section.\n\n        If *value* is None, the tag will be deleted.\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_31set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tag = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_v_value_type = 0;
  PyObject *__pyx_v_replace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_tag (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pysam/calignedsegment.pyx":1708
 *                   tag,
 *                   value,
 *                   value_type=None,             # <<<<<<<<<<<<<<
 *                   replace=True):
 *         """sets a particular field *tag* to *value* in the optional alignment
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/calignedsegment.pyx":1709
 *                   value,
 *                   value_type=None,
 *                   replace=True):             # <<<<<<<<<<<<<<
 *         """sets a particular field *tag* to *value* in the optional alignment
 *         section.
 */
    values[3] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value_type);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_replace);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_tag") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tag = values[0];
    __pyx_v_value = values[1];
    __pyx_v_value_type = values[2];
    __pyx_v_replace = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_30set_tag(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace);

  /* "pysam/calignedsegment.pyx":1705
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_30set_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_tag", 0);
  __Pyx_TraceCall("set_tag", __pyx_f[0], 1705, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.value_type = __pyx_v_value_type;
  __pyx_t_2.replace = __pyx_v_replace;
  __pyx_t_1 = __pyx_vtabptr_5pysam_15calignedsegment_AlignedSegment->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.set_tag", __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/calignedsegment.pyx":1804
 *                        value_ptr)
 * 
 *     cpdef has_tag(self, tag):             # <<<<<<<<<<<<<<
 *         """returns true if the optional alignment section
 *         contains a given *tag*."""
 */

static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_33has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_has_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch) {
  uint8_t *__pyx_v_v;
  PyObject *__pyx_v_btag = NULL;
  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;
  char const *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("has_tag", 0);
  __Pyx_TraceCall("has_tag", __pyx_f[0], 1804, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __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_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_33has_tag)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_tag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_INCREF(__pyx_v_tag);
        __Pyx_GIVEREF(__pyx_v_tag);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_tag);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignedsegment.pyx":1809
 *         cdef uint8_t * v
 *         cdef int nvalues
 *         btag = force_bytes(tag)             # <<<<<<<<<<<<<<
 *         v = bam_aux_get(self._delegate, btag)
 *         return v != NULL
 */
  __pyx_t_1 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_btag = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":1810
 *         cdef int nvalues
 *         btag = force_bytes(tag)
 *         v = bam_aux_get(self._delegate, btag)             # <<<<<<<<<<<<<<
 *         return v != NULL
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_6);

  /* "pysam/calignedsegment.pyx":1811
 *         btag = force_bytes(tag)
 *         v = bam_aux_get(self._delegate, btag)
 *         return v != NULL             # <<<<<<<<<<<<<<
 * 
 *     cpdef get_tag(self, tag, with_value_type=False):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_v != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1811; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1804
 *                        value_ptr)
 * 
 *     cpdef has_tag(self, tag):             # <<<<<<<<<<<<<<
 *         """returns true if the optional alignment section
 *         contains a given *tag*."""
 */

  /* 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_AddTraceback("pysam.calignedsegment.AlignedSegment.has_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_btag);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_33has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_32has_tag[] = "AlignedSegment.has_tag(self, tag)\nreturns true if the optional alignment section\n        contains a given *tag*.";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_33has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("has_tag (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_32has_tag(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_32has_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) {
  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("has_tag", 0);
  __Pyx_TraceCall("has_tag", __pyx_f[0], 1804, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_15calignedsegment_14AlignedSegment_has_tag(__pyx_v_self, __pyx_v_tag, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1804; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.has_tag", __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/calignedsegment.pyx":1813
 *         return v != NULL
 * 
 *     cpdef get_tag(self, tag, with_value_type=False):             # <<<<<<<<<<<<<<
 *         """
 *         retrieves data from the optional alignment section
 */

static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_35get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_5pysam_15calignedsegment_14AlignedSegment_get_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_get_tag *__pyx_optional_args) {
  PyObject *__pyx_v_with_value_type = ((PyObject *)Py_False);
  uint8_t *__pyx_v_v;
  CYTHON_UNUSED int __pyx_v_nvalues;
  PyObject *__pyx_v_btag = NULL;
  PyObject *__pyx_v_auxtype = NULL;
  PyObject *__pyx_v_value = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_bytesize = NULL;
  PyObject *__pyx_v_values = NULL;
  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;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  char const *__pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_tag", 0);
  __Pyx_TraceCall("get_tag", __pyx_f[0], 1813, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_with_value_type = __pyx_optional_args->with_value_type;
    }
  }
  /* 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_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_35get_tag)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && 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;
        }
      }
      __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_tag);
      __Pyx_INCREF(__pyx_v_with_value_type);
      __Pyx_GIVEREF(__pyx_v_with_value_type);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_with_value_type);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignedsegment.pyx":1848
 *         cdef uint8_t * v
 *         cdef int nvalues
 *         btag = force_bytes(tag)             # <<<<<<<<<<<<<<
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL:
 */
  __pyx_t_1 = __pyx_f_5pysam_6cutils_force_bytes(__pyx_v_tag, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_btag = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":1849
 *         cdef int nvalues
 *         btag = force_bytes(tag)
 *         v = bam_aux_get(self._delegate, btag)             # <<<<<<<<<<<<<<
 *         if v == NULL:
 *             raise KeyError("tag '%s' not present" % tag)
 */
  __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_7);

  /* "pysam/calignedsegment.pyx":1850
 *         btag = force_bytes(tag)
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL:             # <<<<<<<<<<<<<<
 *             raise KeyError("tag '%s' not present" % tag)
 *         if chr(v[0]) == "B":
 */
  __pyx_t_8 = ((__pyx_v_v == NULL) != 0);
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1851
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL:
 *             raise KeyError("tag '%s' not present" % tag)             # <<<<<<<<<<<<<<
 *         if chr(v[0]) == "B":
 *             auxtype = chr(v[0]) + chr(v[1])
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_tag_s_not_present, __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":1850
 *         btag = force_bytes(tag)
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL:             # <<<<<<<<<<<<<<
 *             raise KeyError("tag '%s' not present" % tag)
 *         if chr(v[0]) == "B":
 */
  }

  /* "pysam/calignedsegment.pyx":1852
 *         if v == NULL:
 *             raise KeyError("tag '%s' not present" % tag)
 *         if chr(v[0]) == "B":             # <<<<<<<<<<<<<<
 *             auxtype = chr(v[0]) + chr(v[1])
 *         else:
 */
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1853
 *             raise KeyError("tag '%s' not present" % tag)
 *         if chr(v[0]) == "B":
 *             auxtype = chr(v[0]) + chr(v[1])             # <<<<<<<<<<<<<<
 *         else:
 *             auxtype = chr(v[0])
 */
    __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[1])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1853; __pyx_clineno = __LINE__; goto __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_v_auxtype = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":1852
 *         if v == NULL:
 *             raise KeyError("tag '%s' not present" % tag)
 *         if chr(v[0]) == "B":             # <<<<<<<<<<<<<<
 *             auxtype = chr(v[0]) + chr(v[1])
 *         else:
 */
    goto __pyx_L4;
  }

  /* "pysam/calignedsegment.pyx":1855
 *             auxtype = chr(v[0]) + chr(v[1])
 *         else:
 *             auxtype = chr(v[0])             # <<<<<<<<<<<<<<
 * 
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 */
  /*else*/ {
    __pyx_t_3 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_auxtype = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L4:;

  /* "pysam/calignedsegment.pyx":1857
 *             auxtype = chr(v[0])
 * 
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':             # <<<<<<<<<<<<<<
 *             value = <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':
 */
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_C, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_s, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L6_bool_binop_done;
  }
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_S, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = __pyx_t_9;
  __pyx_L6_bool_binop_done:;
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1858
 * 
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             value = <int>bam_aux2i(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'i' or auxtype == 'I':
 *             value = <int32_t>bam_aux2i(v)
 */
    __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_value = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":1857
 *             auxtype = chr(v[0])
 * 
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':             # <<<<<<<<<<<<<<
 *             value = <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':
 */
    goto __pyx_L5;
  }

  /* "pysam/calignedsegment.pyx":1859
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             value = <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':             # <<<<<<<<<<<<<<
 *             value = <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':
 */
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_i, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L10_bool_binop_done;
  }
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_I, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = __pyx_t_9;
  __pyx_L10_bool_binop_done:;
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1860
 *             value = <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':
 *             value = <int32_t>bam_aux2i(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'f' or auxtype == 'F':
 *             value = <float>bam_aux2f(v)
 */
    __pyx_t_3 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_value = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":1859
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             value = <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':             # <<<<<<<<<<<<<<
 *             value = <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':
 */
    goto __pyx_L5;
  }

  /* "pysam/calignedsegment.pyx":1861
 *         elif auxtype == 'i' or auxtype == 'I':
 *             value = <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':             # <<<<<<<<<<<<<<
 *             value = <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':
 */
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L12_bool_binop_done;
  }
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_F, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = __pyx_t_9;
  __pyx_L12_bool_binop_done:;
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1862
 *             value = <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':
 *             value = <float>bam_aux2f(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'd' or auxtype == 'D':
 *             value = <double>bam_aux2f(v)
 */
    __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_value = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":1861
 *         elif auxtype == 'i' or auxtype == 'I':
 *             value = <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':             # <<<<<<<<<<<<<<
 *             value = <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':
 */
    goto __pyx_L5;
  }

  /* "pysam/calignedsegment.pyx":1863
 *         elif auxtype == 'f' or auxtype == 'F':
 *             value = <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':             # <<<<<<<<<<<<<<
 *             value = <double>bam_aux2f(v)
 *         elif auxtype == 'A':
 */
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_d, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_9) {
  } else {
    __pyx_t_8 = __pyx_t_9;
    goto __pyx_L14_bool_binop_done;
  }
  __pyx_t_9 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_D, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = __pyx_t_9;
  __pyx_L14_bool_binop_done:;
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1864
 *             value = <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':
 *             value = <double>bam_aux2f(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'A':
 *             # there might a more efficient way
 */
    __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_value = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysam/calignedsegment.pyx":1863
 *         elif auxtype == 'f' or auxtype == 'F':
 *             value = <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':             # <<<<<<<<<<<<<<
 *             value = <double>bam_aux2f(v)
 *         elif auxtype == 'A':
 */
    goto __pyx_L5;
  }

  /* "pysam/calignedsegment.pyx":1865
 *         elif auxtype == 'd' or auxtype == 'D':
 *             value = <double>bam_aux2f(v)
 *         elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *             # there might a more efficient way
 *             # to convert a char into a string
 */
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1865; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1868
 *             # there might a more efficient way
 *             # to convert a char into a string
 *             value = '%c' % <char>bam_aux2A(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'Z':
 *             value = charptr_to_str(<char*>bam_aux2Z(v))
 */
    __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_value = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysam/calignedsegment.pyx":1865
 *         elif auxtype == 'd' or auxtype == 'D':
 *             value = <double>bam_aux2f(v)
 *         elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *             # there might a more efficient way
 *             # to convert a char into a string
 */
    goto __pyx_L5;
  }

  /* "pysam/calignedsegment.pyx":1869
 *             # to convert a char into a string
 *             value = '%c' % <char>bam_aux2A(v)
 *         elif auxtype == 'Z':             # <<<<<<<<<<<<<<
 *             value = charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype[0] == 'B':
 */
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_Z, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1870
 *             value = '%c' % <char>bam_aux2A(v)
 *         elif auxtype == 'Z':
 *             value = charptr_to_str(<char*>bam_aux2Z(v))             # <<<<<<<<<<<<<<
 *         elif auxtype[0] == 'B':
 *             bytesize, nvalues, values = convert_binary_tag(v + 1)
 */
    __pyx_t_2 = __pyx_f_5pysam_6cutils_charptr_to_str(((char *)bam_aux2Z(__pyx_v_v)), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_value = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysam/calignedsegment.pyx":1869
 *             # to convert a char into a string
 *             value = '%c' % <char>bam_aux2A(v)
 *         elif auxtype == 'Z':             # <<<<<<<<<<<<<<
 *             value = charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype[0] == 'B':
 */
    goto __pyx_L5;
  }

  /* "pysam/calignedsegment.pyx":1871
 *         elif auxtype == 'Z':
 *             value = charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype[0] == 'B':             # <<<<<<<<<<<<<<
 *             bytesize, nvalues, values = convert_binary_tag(v + 1)
 *             value = values
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_auxtype, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1871; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1872
 *             value = charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype[0] == 'B':
 *             bytesize, nvalues, values = convert_binary_tag(v + 1)             # <<<<<<<<<<<<<<
 *             value = values
 *         else:
 */
    __pyx_t_2 = __pyx_f_5pysam_15calignedsegment_convert_binary_tag((__pyx_v_v + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_6 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_6);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_6 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_10 = Py_TYPE(__pyx_t_4)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_1 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 2; __pyx_t_6 = __pyx_t_10(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_4), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = NULL;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L17_unpacking_done;
      __pyx_L16_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_10 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L17_unpacking_done:;
    }
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_bytesize = __pyx_t_3;
    __pyx_t_3 = 0;
    __pyx_v_nvalues = __pyx_t_11;
    __pyx_v_values = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "pysam/calignedsegment.pyx":1873
 *         elif auxtype[0] == 'B':
 *             bytesize, nvalues, values = convert_binary_tag(v + 1)
 *             value = values             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("unknown auxiliary type '%s'" % auxtype)
 */
    __Pyx_INCREF(__pyx_v_values);
    __pyx_v_value = __pyx_v_values;

    /* "pysam/calignedsegment.pyx":1871
 *         elif auxtype == 'Z':
 *             value = charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype[0] == 'B':             # <<<<<<<<<<<<<<
 *             bytesize, nvalues, values = convert_binary_tag(v + 1)
 *             value = values
 */
    goto __pyx_L5;
  }

  /* "pysam/calignedsegment.pyx":1875
 *             value = values
 *         else:
 *             raise ValueError("unknown auxiliary type '%s'" % auxtype)             # <<<<<<<<<<<<<<
 * 
 *         if with_value_type:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_unknown_auxiliary_type_s, __pyx_v_auxtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L5:;

  /* "pysam/calignedsegment.pyx":1877
 *             raise ValueError("unknown auxiliary type '%s'" % auxtype)
 * 
 *         if with_value_type:             # <<<<<<<<<<<<<<
 *             return (value, auxtype)
 *         else:
 */
  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_with_value_type); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_8) {

    /* "pysam/calignedsegment.pyx":1878
 * 
 *         if with_value_type:
 *             return (value, auxtype)             # <<<<<<<<<<<<<<
 *         else:
 *             return value
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_value);
    __Pyx_INCREF(__pyx_v_auxtype);
    __Pyx_GIVEREF(__pyx_v_auxtype);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_auxtype);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1877
 *             raise ValueError("unknown auxiliary type '%s'" % auxtype)
 * 
 *         if with_value_type:             # <<<<<<<<<<<<<<
 *             return (value, auxtype)
 *         else:
 */
  }

  /* "pysam/calignedsegment.pyx":1880
 *             return (value, auxtype)
 *         else:
 *             return value             # <<<<<<<<<<<<<<
 * 
 *     def get_tags(self, with_value_type=False):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_value);
    __pyx_r = __pyx_v_value;
    goto __pyx_L0;
  }

  /* "pysam/calignedsegment.pyx":1813
 *         return v != NULL
 * 
 *     cpdef get_tag(self, tag, with_value_type=False):             # <<<<<<<<<<<<<<
 *         """
 *         retrieves data from the optional alignment section
 */

  /* 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_6);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_btag);
  __Pyx_XDECREF(__pyx_v_auxtype);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_bytesize);
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_35get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_34get_tag[] = "AlignedSegment.get_tag(self, tag, with_value_type=False)\n\n        retrieves data from the optional alignment section\n        given a two-letter *tag* denoting the field.\n\n        The returned value is cast into an appropriate python type.\n\n        This method is the fastest way to access the optional\n        alignment section if only few tags need to be retrieved.\n\n        Parameters\n        ----------\n\n        tag :\n            data tag.\n\n        with_value_type : Optional[bool]\n            if set to True, the return value is a tuple of (tag value, type code).\n            (default False)\n\n        Returns\n        -------\n\n        A python object with the value of the `tag`. The type of the\n        object depends on the data type in the data record.\n\n        Raises\n        ------\n\n        KeyError\n            If `tag` is not present, a KeyError is raised.\n\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_35get_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tag = 0;
  PyObject *__pyx_v_with_value_type = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tag (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_with_value_type,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_with_value_type);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_tag") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tag = values[0];
    __pyx_v_with_value_type = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_tag", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_34get_tag(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_with_value_type);

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_34get_tag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_with_value_type) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_get_tag __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_tag", 0);
  __Pyx_TraceCall("get_tag", __pyx_f[0], 1813, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.with_value_type = __pyx_v_with_value_type;
  __pyx_t_1 = __pyx_vtabptr_5pysam_15calignedsegment_AlignedSegment->get_tag(__pyx_v_self, __pyx_v_tag, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1813; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.get_tag", __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/calignedsegment.pyx":1882
 *             return value
 * 
 *     def get_tags(self, with_value_type=False):             # <<<<<<<<<<<<<<
 *         """the fields in the optional aligment section.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_37get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_36get_tags[] = "AlignedSegment.get_tags(self, with_value_type=False)\nthe fields in the optional aligment section.\n\n        Returns a list of all fields in the optional\n        alignment section. Values are converted to appropriate python\n        values. For example:\n\n        [(NM, 2), (RG, \"GJP00TM04\")]\n\n        If *with_value_type* is set, the value type as encode in\n        the AlignedSegment record will be returned as well:\n\n        [(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n        This method will convert all values in the optional alignment\n        section. When getting only one or few tags, please see\n        :meth:`get_tag` for a quicker way to achieve this.\n\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_37get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_with_value_type = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tags (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_with_value_type,0};
    PyObject* values[1] = {0};
    values[0] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_with_value_type);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_tags") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_with_value_type = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_tags", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_36get_tags(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_with_value_type);

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_36get_tags(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_with_value_type) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char __pyx_v_auxtag[3];
  char __pyx_v_auxtype;
  uint8_t __pyx_v_byte_size;
  int32_t __pyx_v_nvalues;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  uint8_t __pyx_t_10;
  int32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_tags", 0);
  __Pyx_TraceCall("get_tags", __pyx_f[0], 1882, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1910
 *         cdef int32_t nvalues
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if src.l_data == 0:
 *             return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1911
 * 
 *         src = self._delegate
 *         if src.l_data == 0:             # <<<<<<<<<<<<<<
 *             return []
 *         s = pysam_bam_get_aux(src)
 */
  __pyx_t_2 = ((__pyx_v_src->l_data == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1912
 *         src = self._delegate
 *         if src.l_data == 0:
 *             return []             # <<<<<<<<<<<<<<
 *         s = pysam_bam_get_aux(src)
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":1911
 * 
 *         src = self._delegate
 *         if src.l_data == 0:             # <<<<<<<<<<<<<<
 *             return []
 *         s = pysam_bam_get_aux(src)
 */
  }

  /* "pysam/calignedsegment.pyx":1913
 *         if src.l_data == 0:
 *             return []
 *         s = pysam_bam_get_aux(src)             # <<<<<<<<<<<<<<
 *         result = []
 *         auxtag[2] = 0
 */
  __pyx_v_s = pysam_bam_get_aux(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1914
 *             return []
 *         s = pysam_bam_get_aux(src)
 *         result = []             # <<<<<<<<<<<<<<
 *         auxtag[2] = 0
 *         while s < (src.data + src.l_data):
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1914; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":1915
 *         s = pysam_bam_get_aux(src)
 *         result = []
 *         auxtag[2] = 0             # <<<<<<<<<<<<<<
 *         while s < (src.data + src.l_data):
 *             # get tag
 */
  (__pyx_v_auxtag[2]) = 0;

  /* "pysam/calignedsegment.pyx":1916
 *         result = []
 *         auxtag[2] = 0
 *         while s < (src.data + src.l_data):             # <<<<<<<<<<<<<<
 *             # get tag
 *             auxtag[0] = s[0]
 */
  while (1) {
    __pyx_t_2 = ((__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->l_data)) != 0);
    if (!__pyx_t_2) break;

    /* "pysam/calignedsegment.pyx":1918
 *         while s < (src.data + src.l_data):
 *             # get tag
 *             auxtag[0] = s[0]             # <<<<<<<<<<<<<<
 *             auxtag[1] = s[1]
 *             s += 2
 */
    (__pyx_v_auxtag[0]) = (__pyx_v_s[0]);

    /* "pysam/calignedsegment.pyx":1919
 *             # get tag
 *             auxtag[0] = s[0]
 *             auxtag[1] = s[1]             # <<<<<<<<<<<<<<
 *             s += 2
 *             auxtype = s[0]
 */
    (__pyx_v_auxtag[1]) = (__pyx_v_s[1]);

    /* "pysam/calignedsegment.pyx":1920
 *             auxtag[0] = s[0]
 *             auxtag[1] = s[1]
 *             s += 2             # <<<<<<<<<<<<<<
 *             auxtype = s[0]
 *             if auxtype in ('c', 'C'):
 */
    __pyx_v_s = (__pyx_v_s + 2);

    /* "pysam/calignedsegment.pyx":1921
 *             auxtag[1] = s[1]
 *             s += 2
 *             auxtype = s[0]             # <<<<<<<<<<<<<<
 *             if auxtype in ('c', 'C'):
 *                 value = <int>bam_aux2i(s)
 */
    __pyx_v_auxtype = (__pyx_v_s[0]);

    /* "pysam/calignedsegment.pyx":1922
 *             s += 2
 *             auxtype = s[0]
 *             if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
 *                 value = <int>bam_aux2i(s)
 *                 s += 1
 */
    switch (__pyx_v_auxtype) {
      case 'c':
      case 'C':

      /* "pysam/calignedsegment.pyx":1923
 *             auxtype = s[0]
 *             if auxtype in ('c', 'C'):
 *                 value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                 s += 1
 *             elif auxtype in ('s', 'S'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignedsegment.pyx":1924
 *             if auxtype in ('c', 'C'):
 *                 value = <int>bam_aux2i(s)
 *                 s += 1             # <<<<<<<<<<<<<<
 *             elif auxtype in ('s', 'S'):
 *                 value = <int>bam_aux2i(s)
 */
      __pyx_v_s = (__pyx_v_s + 1);

      /* "pysam/calignedsegment.pyx":1922
 *             s += 2
 *             auxtype = s[0]
 *             if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
 *                 value = <int>bam_aux2i(s)
 *                 s += 1
 */
      break;

      /* "pysam/calignedsegment.pyx":1925
 *                 value = <int>bam_aux2i(s)
 *                 s += 1
 *             elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
 *                 value = <int>bam_aux2i(s)
 *                 s += 2
 */
      case 's':
      case 'S':

      /* "pysam/calignedsegment.pyx":1926
 *                 s += 1
 *             elif auxtype in ('s', 'S'):
 *                 value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                 s += 2
 *             elif auxtype in ('i', 'I'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignedsegment.pyx":1927
 *             elif auxtype in ('s', 'S'):
 *                 value = <int>bam_aux2i(s)
 *                 s += 2             # <<<<<<<<<<<<<<
 *             elif auxtype in ('i', 'I'):
 *                 value = <int32_t>bam_aux2i(s)
 */
      __pyx_v_s = (__pyx_v_s + 2);

      /* "pysam/calignedsegment.pyx":1925
 *                 value = <int>bam_aux2i(s)
 *                 s += 1
 *             elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
 *                 value = <int>bam_aux2i(s)
 *                 s += 2
 */
      break;

      /* "pysam/calignedsegment.pyx":1928
 *                 value = <int>bam_aux2i(s)
 *                 s += 2
 *             elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4
 */
      case 'i':
      case 'I':

      /* "pysam/calignedsegment.pyx":1929
 *                 s += 2
 *             elif auxtype in ('i', 'I'):
 *                 value = <int32_t>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                 s += 4
 *             elif auxtype == 'f':
 */
      __pyx_t_3 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignedsegment.pyx":1930
 *             elif auxtype in ('i', 'I'):
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4             # <<<<<<<<<<<<<<
 *             elif auxtype == 'f':
 *                 value = <float>bam_aux2f(s)
 */
      __pyx_v_s = (__pyx_v_s + 4);

      /* "pysam/calignedsegment.pyx":1928
 *                 value = <int>bam_aux2i(s)
 *                 s += 2
 *             elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4
 */
      break;

      /* "pysam/calignedsegment.pyx":1931
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4
 *             elif auxtype == 'f':             # <<<<<<<<<<<<<<
 *                 value = <float>bam_aux2f(s)
 *                 s += 4
 */
      case 'f':

      /* "pysam/calignedsegment.pyx":1932
 *                 s += 4
 *             elif auxtype == 'f':
 *                 value = <float>bam_aux2f(s)             # <<<<<<<<<<<<<<
 *                 s += 4
 *             elif auxtype == 'd':
 */
      __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignedsegment.pyx":1933
 *             elif auxtype == 'f':
 *                 value = <float>bam_aux2f(s)
 *                 s += 4             # <<<<<<<<<<<<<<
 *             elif auxtype == 'd':
 *                 value = <double>bam_aux2f(s)
 */
      __pyx_v_s = (__pyx_v_s + 4);

      /* "pysam/calignedsegment.pyx":1931
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4
 *             elif auxtype == 'f':             # <<<<<<<<<<<<<<
 *                 value = <float>bam_aux2f(s)
 *                 s += 4
 */
      break;

      /* "pysam/calignedsegment.pyx":1934
 *                 value = <float>bam_aux2f(s)
 *                 s += 4
 *             elif auxtype == 'd':             # <<<<<<<<<<<<<<
 *                 value = <double>bam_aux2f(s)
 *                 s += 8
 */
      case 'd':

      /* "pysam/calignedsegment.pyx":1935
 *                 s += 4
 *             elif auxtype == 'd':
 *                 value = <double>bam_aux2f(s)             # <<<<<<<<<<<<<<
 *                 s += 8
 *             elif auxtype == 'A':
 */
      __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignedsegment.pyx":1936
 *             elif auxtype == 'd':
 *                 value = <double>bam_aux2f(s)
 *                 s += 8             # <<<<<<<<<<<<<<
 *             elif auxtype == 'A':
 *                 value = "%c" % <char>bam_aux2A(s)
 */
      __pyx_v_s = (__pyx_v_s + 8);

      /* "pysam/calignedsegment.pyx":1934
 *                 value = <float>bam_aux2f(s)
 *                 s += 4
 *             elif auxtype == 'd':             # <<<<<<<<<<<<<<
 *                 value = <double>bam_aux2f(s)
 *                 s += 8
 */
      break;

      /* "pysam/calignedsegment.pyx":1937
 *                 value = <double>bam_aux2f(s)
 *                 s += 8
 *             elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1
 */
      case 'A':

      /* "pysam/calignedsegment.pyx":1938
 *                 s += 8
 *             elif auxtype == 'A':
 *                 value = "%c" % <char>bam_aux2A(s)             # <<<<<<<<<<<<<<
 *                 s += 1
 *             elif auxtype in ('Z', 'H'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysam/calignedsegment.pyx":1939
 *             elif auxtype == 'A':
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1             # <<<<<<<<<<<<<<
 *             elif auxtype in ('Z', 'H'):
 *                 value = charptr_to_str(<char*>bam_aux2Z(s))
 */
      __pyx_v_s = (__pyx_v_s + 1);

      /* "pysam/calignedsegment.pyx":1937
 *                 value = <double>bam_aux2f(s)
 *                 s += 8
 *             elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1
 */
      break;

      /* "pysam/calignedsegment.pyx":1940
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1
 *             elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
 *                 value = charptr_to_str(<char*>bam_aux2Z(s))
 *                 # +1 for NULL terminated string
 */
      case 'Z':
      case 'H':

      /* "pysam/calignedsegment.pyx":1941
 *                 s += 1
 *             elif auxtype in ('Z', 'H'):
 *                 value = charptr_to_str(<char*>bam_aux2Z(s))             # <<<<<<<<<<<<<<
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1
 */
      __pyx_t_4 = __pyx_f_5pysam_6cutils_charptr_to_str(((char *)bam_aux2Z(__pyx_v_s)), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysam/calignedsegment.pyx":1943
 *                 value = charptr_to_str(<char*>bam_aux2Z(s))
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1             # <<<<<<<<<<<<<<
 *             elif auxtype == 'B':
 *                 s += 1
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_s = (__pyx_v_s + (__pyx_t_5 + 1));

      /* "pysam/calignedsegment.pyx":1940
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1
 *             elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
 *                 value = charptr_to_str(<char*>bam_aux2Z(s))
 *                 # +1 for NULL terminated string
 */
      break;

      /* "pysam/calignedsegment.pyx":1944
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1
 *             elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *                 s += 1
 *                 byte_size, nvalues, value = convert_binary_tag(s)
 */
      case 'B':

      /* "pysam/calignedsegment.pyx":1945
 *                 s += len(value) + 1
 *             elif auxtype == 'B':
 *                 s += 1             # <<<<<<<<<<<<<<
 *                 byte_size, nvalues, value = convert_binary_tag(s)
 *                 # 5 for 1 char and 1 int
 */
      __pyx_v_s = (__pyx_v_s + 1);

      /* "pysam/calignedsegment.pyx":1946
 *             elif auxtype == 'B':
 *                 s += 1
 *                 byte_size, nvalues, value = convert_binary_tag(s)             # <<<<<<<<<<<<<<
 *                 # 5 for 1 char and 1 int
 *                 s += 5 + (nvalues * byte_size) - 1
 */
      __pyx_t_4 = __pyx_f_5pysam_15calignedsegment_convert_binary_tag(__pyx_v_s); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
        PyObject* sequence = __pyx_t_4;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 3)) {
          if (size > 3) __Pyx_RaiseTooManyValuesError(3);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 2); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        #endif
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 2; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __pyx_t_10 = __Pyx_PyInt_As_uint8_t(__pyx_t_3); if (unlikely((__pyx_t_10 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_6); if (unlikely((__pyx_t_11 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_byte_size = __pyx_t_10;
      __pyx_v_nvalues = __pyx_t_11;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/calignedsegment.pyx":1948
 *                 byte_size, nvalues, value = convert_binary_tag(s)
 *                 # 5 for 1 char and 1 int
 *                 s += 5 + (nvalues * byte_size) - 1             # <<<<<<<<<<<<<<
 *             else:
 *                 raise KeyError("unknown type '%s'" % auxtype)
 */
      __pyx_v_s = (__pyx_v_s + ((5 + (__pyx_v_nvalues * __pyx_v_byte_size)) - 1));

      /* "pysam/calignedsegment.pyx":1944
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1
 *             elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *                 s += 1
 *                 byte_size, nvalues, value = convert_binary_tag(s)
 */
      break;
      default:

      /* "pysam/calignedsegment.pyx":1950
 *                 s += 5 + (nvalues * byte_size) - 1
 *             else:
 *                 raise KeyError("unknown type '%s'" % auxtype)             # <<<<<<<<<<<<<<
 * 
 *             s += 1
 */
      __pyx_t_4 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_unknown_type_s, __pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;
    }

    /* "pysam/calignedsegment.pyx":1952
 *                 raise KeyError("unknown type '%s'" % auxtype)
 * 
 *             s += 1             # <<<<<<<<<<<<<<
 * 
 *             if with_value_type:
 */
    __pyx_v_s = (__pyx_v_s + 1);

    /* "pysam/calignedsegment.pyx":1954
 *             s += 1
 * 
 *             if with_value_type:             # <<<<<<<<<<<<<<
 *                 result.append((charptr_to_str(auxtag), value, chr(auxtype)))
 *             else:
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_with_value_type); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_2) {

      /* "pysam/calignedsegment.pyx":1955
 * 
 *             if with_value_type:
 *                 result.append((charptr_to_str(auxtag), value, chr(auxtype)))             # <<<<<<<<<<<<<<
 *             else:
 *                 result.append((charptr_to_str(auxtag), value))
 */
      __pyx_t_7 = __pyx_f_5pysam_6cutils_charptr_to_str(__pyx_v_auxtag, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_4 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_4);
      __pyx_t_7 = 0;
      __pyx_t_4 = 0;
      __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysam/calignedsegment.pyx":1954
 *             s += 1
 * 
 *             if with_value_type:             # <<<<<<<<<<<<<<
 *                 result.append((charptr_to_str(auxtag), value, chr(auxtype)))
 *             else:
 */
      goto __pyx_L8;
    }

    /* "pysam/calignedsegment.pyx":1957
 *                 result.append((charptr_to_str(auxtag), value, chr(auxtype)))
 *             else:
 *                 result.append((charptr_to_str(auxtag), value))             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
    /*else*/ {
      __pyx_t_6 = __pyx_f_5pysam_6cutils_charptr_to_str(__pyx_v_auxtag, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6);
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_value);
      __pyx_t_6 = 0;
      __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1957; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_L8:;
  }

  /* "pysam/calignedsegment.pyx":1959
 *                 result.append((charptr_to_str(auxtag), value))
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def set_tags(self, tags):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":1882
 *             return value
 * 
 *     def get_tags(self, with_value_type=False):             # <<<<<<<<<<<<<<
 *         """the fields in the optional aligment section.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":1961
 *         return result
 * 
 *     def set_tags(self, tags):             # <<<<<<<<<<<<<<
 *         """sets the fields in the optional alignmest section with
 *         a list of (tag, value) tuples.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_39set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_38set_tags[] = "AlignedSegment.set_tags(self, tags)\nsets the fields in the optional alignmest section with\n        a list of (tag, value) tuples.\n\n        The :term:`value type` of the values is determined from the\n        python type. Optionally, a type may be given explicitly as\n        a third value in the tuple, For example:\n\n        x.set_tags([(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n        This method will not enforce the rule that the same tag may appear\n        only once in the optional alignment section.\n        ";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_39set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_tags (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_38set_tags(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_38set_tags(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char *__pyx_v_temp;
  int __pyx_v_new_size;
  int __pyx_v_old_size;
  PyObject *__pyx_v_fmt = NULL;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_v_buffer = NULL;
  PyObject *__pyx_v_p = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  char *__pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("set_tags", 0);
  __Pyx_TraceCall("set_tags", __pyx_f[0], 1961, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1961; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":1978
 *         cdef uint8_t * s
 *         cdef char * temp
 *         cdef int new_size = 0             # <<<<<<<<<<<<<<
 *         cdef int old_size
 *         src = self._delegate
 */
  __pyx_v_new_size = 0;

  /* "pysam/calignedsegment.pyx":1980
 *         cdef int new_size = 0
 *         cdef int old_size
 *         src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *         # convert and pack the data
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":1983
 * 
 *         # convert and pack the data
 *         if tags is not None and len(tags) > 0:             # <<<<<<<<<<<<<<
 *             fmt, args = packTags(tags)
 *             new_size = struct.calcsize(fmt)
 */
  __pyx_t_3 = (__pyx_v_tags != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = PyObject_Length(__pyx_v_tags); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((__pyx_t_5 > 0) != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":1984
 *         # convert and pack the data
 *         if tags is not None and len(tags) > 0:
 *             fmt, args = packTags(tags)             # <<<<<<<<<<<<<<
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)
 */
    __pyx_t_6 = __pyx_f_5pysam_15calignedsegment_packTags(__pyx_v_tags); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
      PyObject* sequence = __pyx_t_6;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      #else
      __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      #endif
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext;
      index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = NULL;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L7_unpacking_done:;
    }
    __pyx_v_fmt = __pyx_t_7;
    __pyx_t_7 = 0;
    __pyx_v_args = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "pysam/calignedsegment.pyx":1985
 *         if tags is not None and len(tags) > 0:
 *             fmt, args = packTags(tags)
 *             new_size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,
 */
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_fmt); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
      __Pyx_INCREF(__pyx_v_fmt);
      __Pyx_GIVEREF(__pyx_v_fmt);
      PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_fmt);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_new_size = __pyx_t_11;

    /* "pysam/calignedsegment.pyx":1986
 *             fmt, args = packTags(tags)
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)             # <<<<<<<<<<<<<<
 *             struct.pack_into(fmt,
 *                              buffer,
 */
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_new_size); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL;
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_buffer = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "pysam/calignedsegment.pyx":1987
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,             # <<<<<<<<<<<<<<
 *                              buffer,
 *                              0,
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/calignedsegment.pyx":1988
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,
 *                              buffer,             # <<<<<<<<<<<<<<
 *                              0,
 *                              *args)
 */
    __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_fmt);
    __Pyx_GIVEREF(__pyx_v_fmt);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fmt);
    __Pyx_INCREF(__pyx_v_buffer);
    __Pyx_GIVEREF(__pyx_v_buffer);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_buffer);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_int_0);

    /* "pysam/calignedsegment.pyx":1987
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,             # <<<<<<<<<<<<<<
 *                              buffer,
 *                              0,
 */
    __pyx_t_12 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

    /* "pysam/calignedsegment.pyx":1983
 * 
 *         # convert and pack the data
 *         if tags is not None and len(tags) > 0:             # <<<<<<<<<<<<<<
 *             fmt, args = packTags(tags)
 *             new_size = struct.calcsize(fmt)
 */
  }

  /* "pysam/calignedsegment.pyx":1995
 *         # If total_size == 0, the aux field will be
 *         # empty
 *         old_size = pysam_bam_get_l_aux(src)             # <<<<<<<<<<<<<<
 *         pysam_bam_update(src,
 *                          old_size,
 */
  __pyx_v_old_size = pysam_bam_get_l_aux(__pyx_v_src);

  /* "pysam/calignedsegment.pyx":1996
 *         # empty
 *         old_size = pysam_bam_get_l_aux(src)
 *         pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                          old_size,
 *                          new_size,
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_old_size, __pyx_v_new_size, pysam_bam_get_aux(__pyx_v_src));

  /* "pysam/calignedsegment.pyx":2002
 * 
 *         # copy data only if there is any
 *         if new_size > 0:             # <<<<<<<<<<<<<<
 * 
 *             # get location of new data
 */
  __pyx_t_2 = ((__pyx_v_new_size > 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":2005
 * 
 *             # get location of new data
 *             s = pysam_bam_get_aux(src)             # <<<<<<<<<<<<<<
 * 
 *             # check if there is direct path from buffer.raw to tmp
 */
    __pyx_v_s = pysam_bam_get_aux(__pyx_v_src);

    /* "pysam/calignedsegment.pyx":2008
 * 
 *             # check if there is direct path from buffer.raw to tmp
 *             p = buffer.raw             # <<<<<<<<<<<<<<
 *             # create handle to make sure buffer stays alive long
 *             # enough for memcpy, see issue 129
 */
    if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_v_p = __pyx_t_12;
    __pyx_t_12 = 0;

    /* "pysam/calignedsegment.pyx":2011
 *             # create handle to make sure buffer stays alive long
 *             # enough for memcpy, see issue 129
 *             temp = p             # <<<<<<<<<<<<<<
 *             memcpy(s, temp, new_size)
 * 
 */
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_p); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_temp = __pyx_t_13;

    /* "pysam/calignedsegment.pyx":2012
 *             # enough for memcpy, see issue 129
 *             temp = p
 *             memcpy(s, temp, new_size)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    memcpy(__pyx_v_s, __pyx_v_temp, __pyx_v_new_size);

    /* "pysam/calignedsegment.pyx":2002
 * 
 *         # copy data only if there is any
 *         if new_size > 0:             # <<<<<<<<<<<<<<
 * 
 *             # get location of new data
 */
  }

  /* "pysam/calignedsegment.pyx":1961
 *         return result
 * 
 *     def set_tags(self, tags):             # <<<<<<<<<<<<<<
 *         """sets the fields in the optional alignmest section with
 *         a list of (tag, value) tuples.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.set_tags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fmt);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_buffer);
  __Pyx_XDECREF(__pyx_v_p);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":2030
 *     property qname:
 *         """deprecated, use query_name instead"""
 *         def __get__(self): return self.query_name             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.query_name = v
 *     property tid:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qname___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qname___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2030, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.qname.__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/calignedsegment.pyx":2031
 *         """deprecated, use query_name instead"""
 *         def __get__(self): return self.query_name
 *         def __set__(self, v): self.query_name = v             # <<<<<<<<<<<<<<
 *     property tid:
 *         """deprecated, use reference_id instead"""
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qname_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qname_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2031, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignedsegment.pyx":2034
 *     property tid:
 *         """deprecated, use reference_id instead"""
 *         def __get__(self): return self.reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.reference_id = v
 *     property pos:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3tid___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3tid___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2034, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.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/calignedsegment.pyx":2035
 *         """deprecated, use reference_id instead"""
 *         def __get__(self): return self.reference_id
 *         def __set__(self, v): self.reference_id = v             # <<<<<<<<<<<<<<
 *     property pos:
 *         """deprecated, use reference_start instead"""
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3tid_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3tid_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2035, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignedsegment.pyx":2038
 *     property pos:
 *         """deprecated, use reference_start instead"""
 *         def __get__(self): return self.reference_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.reference_start = v
 *     property mapq:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3pos___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3pos___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2038, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.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/calignedsegment.pyx":2039
 *         """deprecated, use reference_start instead"""
 *         def __get__(self): return self.reference_start
 *         def __set__(self, v): self.reference_start = v             # <<<<<<<<<<<<<<
 *     property mapq:
 *         """deprecated, use mapping_quality instead"""
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3pos_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3pos_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2039, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignedsegment.pyx":2042
 *     property mapq:
 *         """deprecated, use mapping_quality instead"""
 *         def __get__(self): return self.mapping_quality             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.mapping_quality = v
 *     property rnext:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mapq___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mapq___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2042, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.mapq.__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/calignedsegment.pyx":2043
 *         """deprecated, use mapping_quality instead"""
 *         def __get__(self): return self.mapping_quality
 *         def __set__(self, v): self.mapping_quality = v             # <<<<<<<<<<<<<<
 *     property rnext:
 *         """deprecated, use next_reference_id instead"""
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mapq_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mapq_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2043, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignedsegment.pyx":2046
 *     property rnext:
 *         """deprecated, use next_reference_id instead"""
 *         def __get__(self): return self.next_reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.next_reference_id = v
 *     property pnext:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rnext___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rnext___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2046, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __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.calignedsegment.AlignedSegment.rnext.__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/calignedsegment.pyx":2047
 *         """deprecated, use next_reference_id instead"""
 *         def __get__(self): return self.next_reference_id
 *         def __set__(self, v): self.next_reference_id = v             # <<<<<<<<<<<<<<
 *     property pnext:
 *         """deprecated, use next_reference_start instead"""
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rnext_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rnext_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2047, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignedsegment.pyx":2050
 *     property pnext:
 *         """deprecated, use next_reference_start instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5pnext___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5pnext___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2050, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2051
 *         """deprecated, use next_reference_start instead"""
 *         def __get__(self):
 *             return self.next_reference_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.next_reference_start = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2050
 *     property pnext:
 *         """deprecated, use next_reference_start instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.pnext.__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/calignedsegment.pyx":2052
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property cigar:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5pnext_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5pnext_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2052, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2053
 *             return self.next_reference_start
 *         def __set__(self, v):
 *             self.next_reference_start = v             # <<<<<<<<<<<<<<
 *     property cigar:
 *         """deprecated, use cigartuples instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2052
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property cigar:
 */

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

/* "pysam/calignedsegment.pyx":2056
 *     property cigar:
 *         """deprecated, use cigartuples instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             r = self.cigartuples
 *             if r is None:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5cigar___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5cigar___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_v_r = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2056, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2057
 *         """deprecated, use cigartuples instead"""
 *         def __get__(self):
 *             r = self.cigartuples             # <<<<<<<<<<<<<<
 *             if r is None:
 *                 r = []
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_r = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":2058
 *         def __get__(self):
 *             r = self.cigartuples
 *             if r is None:             # <<<<<<<<<<<<<<
 *                 r = []
 *             return r
 */
  __pyx_t_2 = (__pyx_v_r == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/calignedsegment.pyx":2059
 *             r = self.cigartuples
 *             if r is None:
 *                 r = []             # <<<<<<<<<<<<<<
 *             return r
 *         def __set__(self, v): self.cigartuples = v
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_r, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/calignedsegment.pyx":2058
 *         def __get__(self):
 *             r = self.cigartuples
 *             if r is None:             # <<<<<<<<<<<<<<
 *                 r = []
 *             return r
 */
  }

  /* "pysam/calignedsegment.pyx":2060
 *             if r is None:
 *                 r = []
 *             return r             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.cigartuples = v
 *     property tlen:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_r);
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2056
 *     property cigar:
 *         """deprecated, use cigartuples instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             r = self.cigartuples
 *             if r is None:
 */

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

/* "pysam/calignedsegment.pyx":2061
 *                 r = []
 *             return r
 *         def __set__(self, v): self.cigartuples = v             # <<<<<<<<<<<<<<
 *     property tlen:
 *         """deprecated, use template_length instead"""
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5cigar_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5cigar_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2061, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2061; __pyx_clineno = __LINE__; goto __pyx_L1_error;});
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignedsegment.pyx":2064
 *     property tlen:
 *         """deprecated, use template_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tlen___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tlen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2064, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2064; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2065
 *         """deprecated, use template_length instead"""
 *         def __get__(self):
 *             return self.template_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.template_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2064
 *     property tlen:
 *         """deprecated, use template_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.tlen.__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/calignedsegment.pyx":2066
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property seq:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tlen_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tlen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2066, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2066; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2067
 *             return self.template_length
 *         def __set__(self, v):
 *             self.template_length = v             # <<<<<<<<<<<<<<
 *     property seq:
 *         """deprecated, use query_sequence instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2066
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property seq:
 */

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

/* "pysam/calignedsegment.pyx":2070
 *     property seq:
 *         """deprecated, use query_sequence instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_sequence
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3seq___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3seq___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2070, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2070; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2071
 *         """deprecated, use query_sequence instead"""
 *         def __get__(self):
 *             return self.query_sequence             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_sequence = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2070
 *     property seq:
 *         """deprecated, use query_sequence instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_sequence
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.seq.__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/calignedsegment.pyx":2072
 *         def __get__(self):
 *             return self.query_sequence
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_sequence = v
 *     property qual:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3seq_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_3seq_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2072, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2072; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2073
 *             return self.query_sequence
 *         def __set__(self, v):
 *             self.query_sequence = v             # <<<<<<<<<<<<<<
 *     property qual:
 *         """deprecated, query_qualities instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2072
 *         def __get__(self):
 *             return self.query_sequence
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_sequence = v
 *     property qual:
 */

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

/* "pysam/calignedsegment.pyx":2076
 *     property qual:
 *         """deprecated, query_qualities instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return array_to_qualitystring(self.query_qualities)
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qual___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qual___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2076, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2076; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2077
 *         """deprecated, query_qualities instead"""
 *         def __get__(self):
 *             return array_to_qualitystring(self.query_qualities)             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_qualities = qualitystring_to_array(v)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2077; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_f_5pysam_6cutils_array_to_qualitystring(((arrayobject *)__pyx_t_1), 0, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2076
 *     property qual:
 *         """deprecated, query_qualities instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return array_to_qualitystring(self.query_qualities)
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.qual.__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/calignedsegment.pyx":2078
 *         def __get__(self):
 *             return array_to_qualitystring(self.query_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_qualities = qualitystring_to_array(v)
 *     property alen:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qual_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qual_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  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("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2078, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2078; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2079
 *             return array_to_qualitystring(self.query_qualities)
 *         def __set__(self, v):
 *             self.query_qualities = qualitystring_to_array(v)             # <<<<<<<<<<<<<<
 *     property alen:
 *         """deprecated, reference_length instead"""
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_6cutils_qualitystring_to_array(__pyx_v_v, 0, NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":2078
 *         def __get__(self):
 *             return array_to_qualitystring(self.query_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_qualities = qualitystring_to_array(v)
 *     property alen:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.qual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":2082
 *     property alen:
 *         """deprecated, reference_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4alen___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4alen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2082, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2082; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2083
 *         """deprecated, reference_length instead"""
 *         def __get__(self):
 *             return self.reference_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2082
 *     property alen:
 *         """deprecated, reference_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_length
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.alen.__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/calignedsegment.pyx":2084
 *         def __get__(self):
 *             return self.reference_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_length = v
 *     property aend:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4alen_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4alen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2084, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2084; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2085
 *             return self.reference_length
 *         def __set__(self, v):
 *             self.reference_length = v             # <<<<<<<<<<<<<<
 *     property aend:
 *         """deprecated, reference_end instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2084
 *         def __get__(self):
 *             return self.reference_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_length = v
 *     property aend:
 */

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

/* "pysam/calignedsegment.pyx":2088
 *     property aend:
 *         """deprecated, reference_end instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_end
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4aend___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4aend___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2088, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2088; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2089
 *         """deprecated, reference_end instead"""
 *         def __get__(self):
 *             return self.reference_end             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_end = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2089; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2088
 *     property aend:
 *         """deprecated, reference_end instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_end
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.aend.__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/calignedsegment.pyx":2090
 *         def __get__(self):
 *             return self.reference_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_end = v
 *     property rlen:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4aend_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4aend_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2090, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2091
 *             return self.reference_end
 *         def __set__(self, v):
 *             self.reference_end = v             # <<<<<<<<<<<<<<
 *     property rlen:
 *         """deprecated, query_length instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2090
 *         def __get__(self):
 *             return self.reference_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_end = v
 *     property rlen:
 */

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

/* "pysam/calignedsegment.pyx":2094
 *     property rlen:
 *         """deprecated, query_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4rlen___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4rlen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2094, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2094; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2095
 *         """deprecated, query_length instead"""
 *         def __get__(self):
 *             return self.query_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2095; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2094
 *     property rlen:
 *         """deprecated, query_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_length
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.rlen.__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/calignedsegment.pyx":2096
 *         def __get__(self):
 *             return self.query_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_length = v
 *     property query:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4rlen_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4rlen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2096, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2096; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2097
 *             return self.query_length
 *         def __set__(self, v):
 *             self.query_length = v             # <<<<<<<<<<<<<<
 *     property query:
 *         """deprecated, query_alignment_sequence instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2096
 *         def __get__(self):
 *             return self.query_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_length = v
 *     property query:
 */

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

/* "pysam/calignedsegment.pyx":2100
 *     property query:
 *         """deprecated, query_alignment_sequence instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_sequence
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5query___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5query___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2100, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2101
 *         """deprecated, query_alignment_sequence instead"""
 *         def __get__(self):
 *             return self.query_alignment_sequence             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_sequence = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2100
 *     property query:
 *         """deprecated, query_alignment_sequence instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_sequence
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.query.__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/calignedsegment.pyx":2102
 *         def __get__(self):
 *             return self.query_alignment_sequence
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_sequence = v
 *     property qqual:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5query_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5query_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2102, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2102; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2103
 *             return self.query_alignment_sequence
 *         def __set__(self, v):
 *             self.query_alignment_sequence = v             # <<<<<<<<<<<<<<
 *     property qqual:
 *         """deprecated, query_alignment_qualities instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2102
 *         def __get__(self):
 *             return self.query_alignment_sequence
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_sequence = v
 *     property qqual:
 */

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

/* "pysam/calignedsegment.pyx":2106
 *     property qqual:
 *         """deprecated, query_alignment_qualities instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return array_to_qualitystring(self.query_alignment_qualities)
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qqual___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qqual___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __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("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2106, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2106; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2107
 *         """deprecated, query_alignment_qualities instead"""
 *         def __get__(self):
 *             return array_to_qualitystring(self.query_alignment_qualities)             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_qualities = qualitystring_to_array(v)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_f_5pysam_6cutils_array_to_qualitystring(((arrayobject *)__pyx_t_1), 0, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2106
 *     property qqual:
 *         """deprecated, query_alignment_qualities instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return array_to_qualitystring(self.query_alignment_qualities)
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.qqual.__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/calignedsegment.pyx":2108
 *         def __get__(self):
 *             return array_to_qualitystring(self.query_alignment_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_qualities = qualitystring_to_array(v)
 *     property qstart:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qqual_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5qqual_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  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("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2108, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2109
 *             return array_to_qualitystring(self.query_alignment_qualities)
 *         def __set__(self, v):
 *             self.query_alignment_qualities = qualitystring_to_array(v)             # <<<<<<<<<<<<<<
 *     property qstart:
 *         """deprecated, use query_alignment_start instead"""
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_5pysam_6cutils_qualitystring_to_array(__pyx_v_v, 0, NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":2108
 *         def __get__(self):
 *             return array_to_qualitystring(self.query_alignment_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_qualities = qualitystring_to_array(v)
 *     property qstart:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.qqual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":2112
 *     property qstart:
 *         """deprecated, use query_alignment_start instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_start
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6qstart___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6qstart___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2112, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2113
 *         """deprecated, use query_alignment_start instead"""
 *         def __get__(self):
 *             return self.query_alignment_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_start = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2112
 *     property qstart:
 *         """deprecated, use query_alignment_start instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_start
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.qstart.__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/calignedsegment.pyx":2114
 *         def __get__(self):
 *             return self.query_alignment_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_start = v
 *     property qend:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6qstart_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6qstart_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2114, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2115
 *             return self.query_alignment_start
 *         def __set__(self, v):
 *             self.query_alignment_start = v             # <<<<<<<<<<<<<<
 *     property qend:
 *         """deprecated, use query_alignment_end instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2114
 *         def __get__(self):
 *             return self.query_alignment_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_start = v
 *     property qend:
 */

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

/* "pysam/calignedsegment.pyx":2118
 *     property qend:
 *         """deprecated, use query_alignment_end instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_end
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qend___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qend___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2118, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2118; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2119
 *         """deprecated, use query_alignment_end instead"""
 *         def __get__(self):
 *             return self.query_alignment_end             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_end = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2118
 *     property qend:
 *         """deprecated, use query_alignment_end instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_end
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.qend.__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/calignedsegment.pyx":2120
 *         def __get__(self):
 *             return self.query_alignment_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_end = v
 *     property qlen:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qend_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qend_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2120, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2120; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2121
 *             return self.query_alignment_end
 *         def __set__(self, v):
 *             self.query_alignment_end = v             # <<<<<<<<<<<<<<
 *     property qlen:
 *         """deprecated, use query_alignment_length instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2120
 *         def __get__(self):
 *             return self.query_alignment_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_end = v
 *     property qlen:
 */

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

/* "pysam/calignedsegment.pyx":2124
 *     property qlen:
 *         """deprecated, use query_alignment_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qlen___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qlen___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2124, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2124; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2125
 *         """deprecated, use query_alignment_length instead"""
 *         def __get__(self):
 *             return self.query_alignment_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2124
 *     property qlen:
 *         """deprecated, use query_alignment_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_length
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.qlen.__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/calignedsegment.pyx":2126
 *         def __get__(self):
 *             return self.query_alignment_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_length = v
 *     property mrnm:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qlen_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4qlen_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2126, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2126; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2127
 *             return self.query_alignment_length
 *         def __set__(self, v):
 *             self.query_alignment_length = v             # <<<<<<<<<<<<<<
 *     property mrnm:
 *         """deprecated, use next_reference_id instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2127; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2126
 *         def __get__(self):
 *             return self.query_alignment_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_length = v
 *     property mrnm:
 */

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

/* "pysam/calignedsegment.pyx":2130
 *     property mrnm:
 *         """deprecated, use next_reference_id instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_id
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mrnm___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mrnm___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2130, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2130; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2131
 *         """deprecated, use next_reference_id instead"""
 *         def __get__(self):
 *             return self.next_reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.next_reference_id = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2130
 *     property mrnm:
 *         """deprecated, use next_reference_id instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_id
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.mrnm.__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/calignedsegment.pyx":2132
 *         def __get__(self):
 *             return self.next_reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_id = v
 *     property mpos:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mrnm_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mrnm_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2132, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2132; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2133
 *             return self.next_reference_id
 *         def __set__(self, v):
 *             self.next_reference_id = v             # <<<<<<<<<<<<<<
 *     property mpos:
 *         """deprecated, use next_reference_start instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2133; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2132
 *         def __get__(self):
 *             return self.next_reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_id = v
 *     property mpos:
 */

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

/* "pysam/calignedsegment.pyx":2136
 *     property mpos:
 *         """deprecated, use next_reference_start instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mpos___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mpos___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2136, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2136; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2137
 *         """deprecated, use next_reference_start instead"""
 *         def __get__(self):
 *             return self.next_reference_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.next_reference_start = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2136
 *     property mpos:
 *         """deprecated, use next_reference_start instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.mpos.__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/calignedsegment.pyx":2138
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property rname:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mpos_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4mpos_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2138, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2138; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2139
 *             return self.next_reference_start
 *         def __set__(self, v):
 *             self.next_reference_start = v             # <<<<<<<<<<<<<<
 *     property rname:
 *         """deprecated, use reference_id instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2138
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property rname:
 */

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

/* "pysam/calignedsegment.pyx":2142
 *     property rname:
 *         """deprecated, use reference_id instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rname___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rname___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2142, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2142; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2143
 *         """deprecated, use reference_id instead"""
 *         def __get__(self):
 *             return self.reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_id = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2142
 *     property rname:
 *         """deprecated, use reference_id instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.rname.__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/calignedsegment.pyx":2144
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 *     property isize:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rname_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5rname_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2144, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2144; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2145
 *             return self.reference_id
 *         def __set__(self, v):
 *             self.reference_id = v             # <<<<<<<<<<<<<<
 *     property isize:
 *         """deprecated, use template_length instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2144
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 *     property isize:
 */

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

/* "pysam/calignedsegment.pyx":2148
 *     property isize:
 *         """deprecated, use template_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5isize___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5isize___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2148, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2148; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2149
 *         """deprecated, use template_length instead"""
 *         def __get__(self):
 *             return self.template_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.template_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2148
 *     property isize:
 *         """deprecated, use template_length instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.isize.__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/calignedsegment.pyx":2150
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property blocks:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5isize_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_5isize_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2150, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2150; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2151
 *             return self.template_length
 *         def __set__(self, v):
 *             self.template_length = v             # <<<<<<<<<<<<<<
 *     property blocks:
 *         """deprecated, use get_blocks() instead"""
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2150
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property blocks:
 */

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

/* "pysam/calignedsegment.pyx":2154
 *     property blocks:
 *         """deprecated, use get_blocks() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_blocks()
 *     property aligned_pairs:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6blocks___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_6blocks___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2154, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2154; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2155
 *         """deprecated, use get_blocks() instead"""
 *         def __get__(self):
 *             return self.get_blocks()             # <<<<<<<<<<<<<<
 *     property aligned_pairs:
 *         """deprecated, use get_aligned_pairs() instead"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_blocks); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2155; __pyx_clineno = __LINE__; goto __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/calignedsegment.pyx":2154
 *     property blocks:
 *         """deprecated, use get_blocks() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_blocks()
 *     property aligned_pairs:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.blocks.__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/calignedsegment.pyx":2158
 *     property aligned_pairs:
 *         """deprecated, use get_aligned_pairs() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_aligned_pairs()
 *     property inferred_length:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_13aligned_pairs___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_13aligned_pairs___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2158, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2158; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2159
 *         """deprecated, use get_aligned_pairs() instead"""
 *         def __get__(self):
 *             return self.get_aligned_pairs()             # <<<<<<<<<<<<<<
 *     property inferred_length:
 *         """deprecated, use infer_query_length() instead"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2159; __pyx_clineno = __LINE__; goto __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/calignedsegment.pyx":2158
 *     property aligned_pairs:
 *         """deprecated, use get_aligned_pairs() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_aligned_pairs()
 *     property inferred_length:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.aligned_pairs.__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/calignedsegment.pyx":2162
 *     property inferred_length:
 *         """deprecated, use infer_query_length() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.infer_query_length()
 *     property positions:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15inferred_length___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_15inferred_length___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2162, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2162; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2163
 *         """deprecated, use infer_query_length() instead"""
 *         def __get__(self):
 *             return self.infer_query_length()             # <<<<<<<<<<<<<<
 *     property positions:
 *         """deprecated, use get_reference_positions() instead"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_infer_query_length); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2163; __pyx_clineno = __LINE__; goto __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/calignedsegment.pyx":2162
 *     property inferred_length:
 *         """deprecated, use infer_query_length() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.infer_query_length()
 *     property positions:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.inferred_length.__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/calignedsegment.pyx":2166
 *     property positions:
 *         """deprecated, use get_reference_positions() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_reference_positions()
 *     property tags:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9positions___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_9positions___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2166, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2166; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2167
 *         """deprecated, use get_reference_positions() instead"""
 *         def __get__(self):
 *             return self.get_reference_positions()             # <<<<<<<<<<<<<<
 *     property tags:
 *         """deprecated, use get_tags() instead"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_positions); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2167; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2167; __pyx_clineno = __LINE__; goto __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/calignedsegment.pyx":2166
 *     property positions:
 *         """deprecated, use get_reference_positions() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_reference_positions()
 *     property tags:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.positions.__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/calignedsegment.pyx":2170
 *     property tags:
 *         """deprecated, use get_tags() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_tags()
 *         def __set__(self, tags):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tags___get__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tags___get__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2170, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2170; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2171
 *         """deprecated, use get_tags() instead"""
 *         def __get__(self):
 *             return self.get_tags()             # <<<<<<<<<<<<<<
 *         def __set__(self, tags):
 *             self.set_tags(tags)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __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/calignedsegment.pyx":2170
 *     property tags:
 *         """deprecated, use get_tags() instead"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_tags()
 *         def __set__(self, tags):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.tags.__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/calignedsegment.pyx":2172
 *         def __get__(self):
 *             return self.get_tags()
 *         def __set__(self, tags):             # <<<<<<<<<<<<<<
 *             self.set_tags(tags)
 *     def overlap(self):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tags_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags));

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

static int __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_4tags_2__set__(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) {
  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("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2172, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2172; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2173
 *             return self.get_tags()
 *         def __set__(self, tags):
 *             self.set_tags(tags)             # <<<<<<<<<<<<<<
 *     def overlap(self):
 *         """deprecated, use get_overlap() instead"""
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_v_tags);
    __Pyx_GIVEREF(__pyx_v_tags);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_tags);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":2172
 *         def __get__(self):
 *             return self.get_tags()
 *         def __set__(self, tags):             # <<<<<<<<<<<<<<
 *             self.set_tags(tags)
 *     def overlap(self):
 */

  /* 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.calignedsegment.AlignedSegment.tags.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":2174
 *         def __set__(self, tags):
 *             self.set_tags(tags)
 *     def overlap(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use get_overlap() instead"""
 *         return self.get_overlap()
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_41overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_40overlap[] = "AlignedSegment.overlap(self)\ndeprecated, use get_overlap() instead";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_41overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("overlap (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_40overlap(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_40overlap(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("overlap", 0);
  __Pyx_TraceCall("overlap", __pyx_f[0], 2174, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2174; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2176
 *     def overlap(self):
 *         """deprecated, use get_overlap() instead"""
 *         return self.get_overlap()             # <<<<<<<<<<<<<<
 *     def opt(self, tag):
 *         """deprecated, use get_tag() instead"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_overlap); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2176; __pyx_clineno = __LINE__; goto __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/calignedsegment.pyx":2174
 *         def __set__(self, tags):
 *             self.set_tags(tags)
 *     def overlap(self):             # <<<<<<<<<<<<<<
 *         """deprecated, use get_overlap() instead"""
 *         return self.get_overlap()
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.overlap", __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/calignedsegment.pyx":2177
 *         """deprecated, use get_overlap() instead"""
 *         return self.get_overlap()
 *     def opt(self, tag):             # <<<<<<<<<<<<<<
 *         """deprecated, use get_tag() instead"""
 *         return self.get_tag(tag)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_43opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_42opt[] = "AlignedSegment.opt(self, tag)\ndeprecated, use get_tag() instead";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_43opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("opt (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_42opt(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_42opt(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) {
  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("opt", 0);
  __Pyx_TraceCall("opt", __pyx_f[0], 2177, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2177; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2179
 *     def opt(self, tag):
 *         """deprecated, use get_tag() instead"""
 *         return self.get_tag(tag)             # <<<<<<<<<<<<<<
 *     def setTag(self, tag, value, value_type=None, replace=True):
 *         """deprecated, use set_tag() instead"""
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->get_tag(__pyx_v_self, __pyx_v_tag, 0, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2177
 *         """deprecated, use get_overlap() instead"""
 *         return self.get_overlap()
 *     def opt(self, tag):             # <<<<<<<<<<<<<<
 *         """deprecated, use get_tag() instead"""
 *         return self.get_tag(tag)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.opt", __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/calignedsegment.pyx":2180
 *         """deprecated, use get_tag() instead"""
 *         return self.get_tag(tag)
 *     def setTag(self, tag, value, value_type=None, replace=True):             # <<<<<<<<<<<<<<
 *         """deprecated, use set_tag() instead"""
 *         return self.set_tag(tag, value, value_type, replace)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_45setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_44setTag[] = "AlignedSegment.setTag(self, tag, value, value_type=None, replace=True)\ndeprecated, use set_tag() instead";
static PyObject *__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_45setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tag = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_v_value_type = 0;
  PyObject *__pyx_v_replace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("setTag (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value_type);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_replace);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setTag") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tag = values[0];
    __pyx_v_value = values[1];
    __pyx_v_value_type = values[2];
    __pyx_v_replace = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2180; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_14AlignedSegment_44setTag(((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace);

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_14AlignedSegment_44setTag(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("setTag", 0);
  __Pyx_TraceCall("setTag", __pyx_f[0], 2180, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2180; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2182
 *     def setTag(self, tag, value, value_type=None, replace=True):
 *         """deprecated, use set_tag() instead"""
 *         return self.set_tag(tag, value, value_type, replace)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.value_type = __pyx_v_value_type;
  __pyx_t_2.replace = __pyx_v_replace;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_15calignedsegment_AlignedSegment *)__pyx_v_self->__pyx_vtab)->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2180
 *         """deprecated, use get_tag() instead"""
 *         return self.get_tag(tag)
 *     def setTag(self, tag, value, value_type=None, replace=True):             # <<<<<<<<<<<<<<
 *         """deprecated, use set_tag() instead"""
 *         return self.set_tag(tag, value, value_type, replace)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.AlignedSegment.setTag", __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/calignedsegment.pyx":2195
 * 
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn___init__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self) {
  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("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2195, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2196
 *     '''
 *     def __init__(self):
 *         raise TypeError("this class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2195
 * 
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 */

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

/* "pysam/calignedsegment.pyx":2198
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join(map(str,
 *                               (self.reference_id,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_3__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_3__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_2__str__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_2__str__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 2198, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2198; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2199
 * 
 *     def __str__(self):
 *         return "\t".join(map(str,             # <<<<<<<<<<<<<<
 *                               (self.reference_id,
 *                                self.reference_pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/calignedsegment.pyx":2200
 *     def __str__(self):
 *         return "\t".join(map(str,
 *                               (self.reference_id,             # <<<<<<<<<<<<<<
 *                                self.reference_pos,
 *                                self.nsegments))) +\
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/calignedsegment.pyx":2201
 *         return "\t".join(map(str,
 *                               (self.reference_id,
 *                                self.reference_pos,             # <<<<<<<<<<<<<<
 *                                self.nsegments))) +\
 *             "\n" +\
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2201; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignedsegment.pyx":2202
 *                               (self.reference_id,
 *                                self.reference_pos,
 *                                self.nsegments))) +\             # <<<<<<<<<<<<<<
 *             "\n" +\
 *             "\n".join(map(str, self.pileups))
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignedsegment.pyx":2200
 *     def __str__(self):
 *         return "\t".join(map(str,
 *                               (self.reference_id,             # <<<<<<<<<<<<<<
 *                                self.reference_pos,
 *                                self.nsegments))) +\
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2200; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":2199
 * 
 *     def __str__(self):
 *         return "\t".join(map(str,             # <<<<<<<<<<<<<<
 *                               (self.reference_id,
 *                                self.reference_pos,
 */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__19, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2199; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignedsegment.pyx":2202
 *                               (self.reference_id,
 *                                self.reference_pos,
 *                                self.nsegments))) +\             # <<<<<<<<<<<<<<
 *             "\n" +\
 *             "\n".join(map(str, self.pileups))
 */
  __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__30); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2202; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":2204
 *                                self.nsegments))) +\
 *             "\n" +\
 *             "\n".join(map(str, self.pileups))             # <<<<<<<<<<<<<<
 * 
 *     property reference_id:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pileups); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__30, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/calignedsegment.pyx":2203
 *                                self.reference_pos,
 *                                self.nsegments))) +\
 *             "\n" +\             # <<<<<<<<<<<<<<
 *             "\n".join(map(str, self.pileups))
 * 
 */
  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2198
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join(map(str,
 *                               (self.reference_id,
 */

  /* 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.calignedsegment.PileupColumn.__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;
}

/* "pysam/calignedsegment.pyx":2208
 *     property reference_id:
 *         '''the reference sequence number as defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_12reference_id___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_12reference_id___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2208, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2208; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2209
 *         '''the reference sequence number as defined in the header'''
 *         def __get__(self):
 *             return self.tid             # <<<<<<<<<<<<<<
 * 
 *     property reference_name:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2208
 *     property reference_id:
 *         '''the reference sequence number as defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.tid
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.reference_id.__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/calignedsegment.pyx":2213
 *     property reference_name:
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self.tid)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_14reference_name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_14reference_name_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_14reference_name___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_14reference_name___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __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;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2213, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2213; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2214
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):
 *             if self._alignment_file is not None:             # <<<<<<<<<<<<<<
 *                 return self._alignment_file.getrname(self.tid)
 *             return None
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_self->_alignment_file) != Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":2215
 *         def __get__(self):
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self.tid)             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->_alignment_file), __pyx_n_s_getrname); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":2214
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):
 *             if self._alignment_file is not None:             # <<<<<<<<<<<<<<
 *                 return self._alignment_file.getrname(self.tid)
 *             return None
 */
  }

  /* "pysam/calignedsegment.pyx":2216
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self.tid)
 *             return None             # <<<<<<<<<<<<<<
 * 
 *     property nsegments:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2213
 *     property reference_name:
 *         """:term:`reference` name (None if no AlignmentFile is associated)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self._alignment_file is not None:
 *                 return self._alignment_file.getrname(self.tid)
 */

  /* 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_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.reference_name.__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/calignedsegment.pyx":2220
 *     property nsegments:
 *         '''number of reads mapping to this column.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.n_pu
 *         def __set__(self, n):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_9nsegments___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_9nsegments___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2220, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2220; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2221
 *         '''number of reads mapping to this column.'''
 *         def __get__(self):
 *             return self.n_pu             # <<<<<<<<<<<<<<
 *         def __set__(self, n):
 *             self.n_pu = n
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2220
 *     property nsegments:
 *         '''number of reads mapping to this column.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.n_pu
 *         def __set__(self, n):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.nsegments.__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/calignedsegment.pyx":2222
 *         def __get__(self):
 *             return self.n_pu
 *         def __set__(self, n):             # <<<<<<<<<<<<<<
 *             self.n_pu = n
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_9nsegments_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_n));

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

static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_9nsegments_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_n) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2222, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2222; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2223
 *             return self.n_pu
 *         def __set__(self, n):
 *             self.n_pu = n             # <<<<<<<<<<<<<<
 * 
 *     property reference_pos:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2223; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->n_pu = __pyx_t_1;

  /* "pysam/calignedsegment.pyx":2222
 *         def __get__(self):
 *             return self.n_pu
 *         def __set__(self, n):             # <<<<<<<<<<<<<<
 *             self.n_pu = n
 * 
 */

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

/* "pysam/calignedsegment.pyx":2227
 *     property reference_pos:
 *         '''the position in the reference sequence (0-based).'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.pos
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_13reference_pos___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_13reference_pos___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2227, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2227; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2228
 *         '''the position in the reference sequence (0-based).'''
 *         def __get__(self):
 *             return self.pos             # <<<<<<<<<<<<<<
 * 
 *     property pileups:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2227
 *     property reference_pos:
 *         '''the position in the reference sequence (0-based).'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.pos
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.reference_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/calignedsegment.pyx":2232
 *     property pileups:
 *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int x
 *             pileups = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_7pileups___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_7pileups___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self) {
  int __pyx_v_x;
  PyObject *__pyx_v_pileups = NULL;
  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;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2232, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2232; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2234
 *         def __get__(self):
 *             cdef int x
 *             pileups = []             # <<<<<<<<<<<<<<
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_pileups = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignedsegment.pyx":2236
 *             pileups = []
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError("PileupColumn accessed after iterator finished")
 * 
 */
  __pyx_t_3 = ((__pyx_v_self->plp == NULL) != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (((__pyx_v_self->plp[0]) == NULL) != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignedsegment.pyx":2237
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 *                 raise ValueError("PileupColumn accessed after iterator finished")             # <<<<<<<<<<<<<<
 * 
 *             # warning: there could be problems if self.n and self.buf are
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2237; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignedsegment.pyx":2236
 *             pileups = []
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError("PileupColumn accessed after iterator finished")
 * 
 */
  }

  /* "pysam/calignedsegment.pyx":2241
 *             # warning: there could be problems if self.n and self.buf are
 *             # out of sync.
 *             for x from 0 <= x < self.n_pu:             # <<<<<<<<<<<<<<
 *                 pileups.append(makePileupRead(&(self.plp[0][x]),
 *                                               self._alignment_file))
 */
  __pyx_t_4 = __pyx_v_self->n_pu;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_4; __pyx_v_x++) {

    /* "pysam/calignedsegment.pyx":2243
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append(makePileupRead(&(self.plp[0][x]),
 *                                               self._alignment_file))             # <<<<<<<<<<<<<<
 *             return pileups
 * 
 */
    __pyx_t_1 = ((PyObject *)__pyx_v_self->_alignment_file);
    __Pyx_INCREF(__pyx_t_1);

    /* "pysam/calignedsegment.pyx":2242
 *             # out of sync.
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append(makePileupRead(&(self.plp[0][x]),             # <<<<<<<<<<<<<<
 *                                               self._alignment_file))
 *             return pileups
 */
    __pyx_t_5 = __pyx_f_5pysam_15calignedsegment_makePileupRead((&((__pyx_v_self->plp[0])[__pyx_v_x])), ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_t_1)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_pileups, __pyx_t_5); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }

  /* "pysam/calignedsegment.pyx":2244
 *                 pileups.append(makePileupRead(&(self.plp[0][x]),
 *                                               self._alignment_file))
 *             return pileups             # <<<<<<<<<<<<<<
 * 
 *     ########################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_pileups);
  __pyx_r = __pyx_v_pileups;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2232
 *     property pileups:
 *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int x
 *             pileups = []
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.pileups.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pileups);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignedsegment.pyx":2251
 *     ########################################################
 *     property pos:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_pos
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3pos___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_3pos___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2251, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2251; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2252
 *     property pos:
 *         def __get__(self):
 *             return self.reference_pos             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_pos = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2251
 *     ########################################################
 *     property pos:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_pos
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.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/calignedsegment.pyx":2253
 *         def __get__(self):
 *             return self.reference_pos
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_pos = v
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3pos_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3pos_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2253, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2253; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2254
 *             return self.reference_pos
 *         def __set__(self, v):
 *             self.reference_pos = v             # <<<<<<<<<<<<<<
 * 
 *     property tid:
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2254; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2253
 *         def __get__(self):
 *             return self.reference_pos
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_pos = v
 * 
 */

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

/* "pysam/calignedsegment.pyx":2257
 * 
 *     property tid:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3tid___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_3tid___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2257, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2257; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2258
 *     property tid:
 *         def __get__(self):
 *             return self.reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_id = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2257
 * 
 *     property tid:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.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/calignedsegment.pyx":2259
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3tid_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_3tid_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2259, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2259; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2260
 *             return self.reference_id
 *         def __set__(self, v):
 *             self.reference_id = v             # <<<<<<<<<<<<<<
 * 
 *     property n:
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2259
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 * 
 */

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

/* "pysam/calignedsegment.pyx":2263
 * 
 *     property n:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.nsegments
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_1n___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_12PileupColumn_1n___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2263, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2263; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2264
 *     property n:
 *         def __get__(self):
 *             return self.nsegments             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.nsegments = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2263
 * 
 *     property n:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.nsegments
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupColumn.n.__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/calignedsegment.pyx":2265
 *         def __get__(self):
 *             return self.nsegments
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.nsegments = v
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_12PileupColumn_1n_2__set__(((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_15calignedsegment_12PileupColumn_1n_2__set__(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2265, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2265; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2266
 *             return self.nsegments
 *         def __set__(self, v):
 *             self.nsegments = v             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2265
 *         def __get__(self):
 *             return self.nsegments
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.nsegments = v
 * 
 */

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

/* "pysam/calignedsegment.pyx":2275
 *     '''
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError(
 *             "this class cannot be instantiated from Python")
 */

/* Python wrapper */
static int __pyx_pw_5pysam_15calignedsegment_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_15calignedsegment_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead___init__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static int __pyx_pf_5pysam_15calignedsegment_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self) {
  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("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2275, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2275; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2276
 * 
 *     def __init__(self):
 *         raise TypeError(             # <<<<<<<<<<<<<<
 *             "this class cannot be instantiated from Python")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2276; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 2276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignedsegment.pyx":2275
 *     '''
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError(
 *             "this class cannot be instantiated from Python")
 */

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

/* "pysam/calignedsegment.pyx":2279
 *             "this class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join(
 *             map(str,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_3__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_3__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_2__str__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_2__str__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 2279, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2279; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2280
 * 
 *     def __str__(self):
 *         return "\t".join(             # <<<<<<<<<<<<<<
 *             map(str,
 *                 (self.alignment, self.query_position,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/calignedsegment.pyx":2282
 *         return "\t".join(
 *             map(str,
 *                 (self.alignment, self.query_position,             # <<<<<<<<<<<<<<
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_position); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignedsegment.pyx":2283
 *             map(str,
 *                 (self.alignment, self.query_position,
 *                  self.indel, self.level,             # <<<<<<<<<<<<<<
 *                  self.is_del, self.is_head,
 *                  self.is_tail, self.is_refskip)))
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_indel); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_level); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignedsegment.pyx":2284
 *                 (self.alignment, self.query_position,
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,             # <<<<<<<<<<<<<<
 *                  self.is_tail, self.is_refskip)))
 * 
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_head); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/calignedsegment.pyx":2285
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,
 *                  self.is_tail, self.is_refskip)))             # <<<<<<<<<<<<<<
 * 
 *     property alignment:
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_tail); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/calignedsegment.pyx":2282
 *         return "\t".join(
 *             map(str,
 *                 (self.alignment, self.query_position,             # <<<<<<<<<<<<<<
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,
 */
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8);
  __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/calignedsegment.pyx":2281
 *     def __str__(self):
 *         return "\t".join(
 *             map(str,             # <<<<<<<<<<<<<<
 *                 (self.alignment, self.query_position,
 *                  self.indel, self.level,
 */
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(((PyObject *)(&PyString_Type)));
  PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)(&PyString_Type)));
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pysam/calignedsegment.pyx":2280
 * 
 *     def __str__(self):
 *         return "\t".join(             # <<<<<<<<<<<<<<
 *             map(str,
 *                 (self.alignment, self.query_position,
 */
  __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__19, __pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __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/calignedsegment.pyx":2279
 *             "this class cannot be instantiated from Python")
 * 
 *     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.calignedsegment.PileupRead.__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;
}

/* "pysam/calignedsegment.pyx":2289
 *     property alignment:
 *         """a :class:`pysam.AlignedSegment` object of the aligned read"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._alignment
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_9alignment___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2289, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2289; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2290
 *         """a :class:`pysam.AlignedSegment` object of the aligned read"""
 *         def __get__(self):
 *             return self._alignment             # <<<<<<<<<<<<<<
 * 
 *     property query_position:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->_alignment));
  __pyx_r = ((PyObject *)__pyx_v_self->_alignment);
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2289
 *     property alignment:
 *         """a :class:`pysam.AlignedSegment` object of the aligned read"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._alignment
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.alignment.__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/calignedsegment.pyx":2297
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.is_del or self.is_refskip:
 *                 return None
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_14query_position___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_14query_position___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2297, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2297; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2298
 *         """
 *         def __get__(self):
 *             if self.is_del or self.is_refskip:             # <<<<<<<<<<<<<<
 *                 return None
 *             else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2298; __pyx_clineno = __LINE__; goto __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_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/calignedsegment.pyx":2299
 *         def __get__(self):
 *             if self.is_del or self.is_refskip:
 *                 return None             # <<<<<<<<<<<<<<
 *             else:
 *                 return self._qpos
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "pysam/calignedsegment.pyx":2298
 *         """
 *         def __get__(self):
 *             if self.is_del or self.is_refskip:             # <<<<<<<<<<<<<<
 *                 return None
 *             else:
 */
  }

  /* "pysam/calignedsegment.pyx":2301
 *                 return None
 *             else:
 *                 return self._qpos             # <<<<<<<<<<<<<<
 * 
 *     property query_position_or_next:
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2301; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignedsegment.pyx":2297
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.is_del or self.is_refskip:
 *                 return None
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.query_position.__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/calignedsegment.pyx":2310
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._qpos
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_22query_position_or_next_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_22query_position_or_next_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_22query_position_or_next___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_22query_position_or_next___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2310, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2311
 *         """
 *         def __get__(self):
 *             return self._qpos             # <<<<<<<<<<<<<<
 * 
 *     property indel:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2310
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._qpos
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.query_position_or_next.__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/calignedsegment.pyx":2322
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._indel
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_5indel___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2322, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2322; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2323
 *         """
 *         def __get__(self):
 *             return self._indel             # <<<<<<<<<<<<<<
 * 
 *     property level:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2322
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._indel
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.indel.__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/calignedsegment.pyx":2327
 *     property level:
 *         """the level of the read in the "viewer" mode"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._level
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_5level_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_5level_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_5level___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_5level___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2327, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2327; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2328
 *         """the level of the read in the "viewer" mode"""
 *         def __get__(self):
 *             return self._level             # <<<<<<<<<<<<<<
 * 
 *     property is_del:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2328; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2327
 *     property level:
 *         """the level of the read in the "viewer" mode"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._level
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.level.__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/calignedsegment.pyx":2332
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_del
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_6is_del___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2332, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2332; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2333
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):
 *             return self._is_del             # <<<<<<<<<<<<<<
 * 
 *     property is_head:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2332
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_del
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.is_del.__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/calignedsegment.pyx":2337
 *     property is_head:
 *         """1 iff the base on the padded read is the left-most base."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_head
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_7is_head___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2337, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2337; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2338
 *         """1 iff the base on the padded read is the left-most base."""
 *         def __get__(self):
 *             return self._is_head             # <<<<<<<<<<<<<<
 * 
 *     property is_tail:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2337
 *     property is_head:
 *         """1 iff the base on the padded read is the left-most base."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_head
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.is_head.__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/calignedsegment.pyx":2342
 *     property is_tail:
 *         """1 iff the base on the padded read is the right-most base."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_tail
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_7is_tail___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2342, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2343
 *         """1 iff the base on the padded read is the right-most base."""
 *         def __get__(self):
 *             return self._is_tail             # <<<<<<<<<<<<<<
 * 
 *     property is_refskip:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2342
 *     property is_tail:
 *         """1 iff the base on the padded read is the right-most base."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_tail
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.is_tail.__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/calignedsegment.pyx":2346
 * 
 *     property is_refskip:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_refskip
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_15calignedsegment_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_15calignedsegment_10PileupRead_10is_refskip___get__(((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_15calignedsegment_10PileupRead_10is_refskip___get__(struct __pyx_obj_5pysam_15calignedsegment_PileupRead *__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__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2346, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2346; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":2347
 *     property is_refskip:
 *         def __get__(self):
 *             return self._is_refskip             # <<<<<<<<<<<<<<
 * 
 * __all__ = [
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_refskip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignedsegment.pyx":2346
 * 
 *     property is_refskip:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_refskip
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignedsegment.PileupRead.is_refskip.__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;
}

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

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __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_TraceDeclarations
  __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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  if (__pyx_v_info != NULL) {
    __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(__pyx_v_info->obj);
  }
  __Pyx_TraceCall("__getbuffer__", __pyx_f[1], 91, 0, {__pyx_filename = __pyx_f[1]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "array.pxd":96
 *             # 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_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_item_count = __pyx_t_1;
  __pyx_t_1 = 0;

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

  /* "array.pxd":99
 * 
 *             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":100
 *             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":101
 *             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":102
 *             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":103
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count             # <<<<<<<<<<<<<<
 * 
 *             info.shape = <Py_ssize_t*> PyMem_Malloc(sizeof(Py_ssize_t) + 2)
 */
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_info->len = __pyx_t_5;

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

  /* "array.pxd":106
 * 
 *             info.shape = <Py_ssize_t*> PyMem_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)) != 0);
  if (__pyx_t_6) {

    /* "array.pxd":107
 *             info.shape = <Py_ssize_t*> PyMem_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_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

  /* "array.pxd":108
 *             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_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  (__pyx_v_info->shape[0]) = __pyx_t_5;

  /* "array.pxd":109
 *                 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":111
 *             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":112
 * 
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode             # <<<<<<<<<<<<<<
 *             info.format[1] = 0
 *             info.obj = self
 */
  __pyx_t_3 = __pyx_v_self->ob_descr->typecode;
  (__pyx_v_info->format[0]) = __pyx_t_3;

  /* "array.pxd":113
 *             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":114
 *             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":91
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill 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 != NULL && __pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(Py_None);
    __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL;
  }
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_item_count);
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __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) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);
  __Pyx_TraceCall("__releasebuffer__", __pyx_f[1], 116, 0, {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

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

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

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("cpython.array.array.__releasebuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}

/* "array.pxd":128
 * 
 * 
 * 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 = NULL;
  arrayobject *__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("clone", 0);
  __Pyx_TraceCall("clone", __pyx_f[1], 128, 0, {__pyx_filename = __pyx_f[1]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "array.pxd":132
 *     type will be same as template.
 *     if zero is true, new array will be initialized with zeroes."""
 *     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_filename = __pyx_f[1]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":133
 *     if zero is true, new array will be initialized with zeroes."""
 *     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
 */
  __pyx_t_3 = (__pyx_v_zero != 0);
  if (__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "array.pxd":134
 *     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
 * 
 */
    memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize));

    /* "array.pxd":133
 *     if zero is true, new array will be initialized with zeroes."""
 *     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":135
 *     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":128
 * 
 * 
 * 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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":137
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an 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 = NULL;
  arrayobject *__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("copy", 0);
  __Pyx_TraceCall("copy", __pyx_f[1], 137, 0, {__pyx_filename = __pyx_f[1]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "array.pxd":139
 * cdef inline array copy(array self):
 *     """ make a copy of an 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_filename = __pyx_f[1]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":140
 *     """ make a copy of an 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
 * 
 */
  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":141
 *     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":137
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an 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_TraceReturn(__pyx_r, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":143
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficent 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;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend_buffer", 0);
  __Pyx_TraceCall("extend_buffer", __pyx_f[1], 143, 0, {__pyx_filename = __pyx_f[1]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "array.pxd":147
 *     (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":148
 *     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":149
 *     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 == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "array.pxd":150
 *     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
 * 
 */
  memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize));

  /* "array.pxd":151
 *     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":143
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficent 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:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":153
 *     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;
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("extend", 0);
  __Pyx_TraceCall("extend", __pyx_f[1], 153, 0, {__pyx_filename = __pyx_f[1]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "array.pxd":155
 * 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) != 0);
  if (__pyx_t_1) {

    /* "array.pxd":156
 *     """ 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 == 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "array.pxd":155
 * 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":157
 *     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):
 */
  __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 == -1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_2;
  goto __pyx_L0;

  /* "array.pxd":153
 *     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:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":159
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ 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) {
  __Pyx_TraceDeclarations
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("zero", 0);
  __Pyx_TraceCall("zero", __pyx_f[1], 159, 0, {__pyx_filename = __pyx_f[1]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

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

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

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("cpython.array.zero", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None, 0);
  __Pyx_RefNannyFinishContext();
}
static struct __pyx_vtabstruct_5pysam_15calignedsegment_AlignedSegment __pyx_vtable_5pysam_15calignedsegment_AlignedSegment;

static PyObject *__pyx_tp_new_5pysam_15calignedsegment_AlignedSegment(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_15calignedsegment_AlignedSegment;
  p->_alignment_file = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->cache_query_qualities = Py_None; Py_INCREF(Py_None);
  p->cache_query_alignment_qualities = Py_None; Py_INCREF(Py_None);
  p->cache_query_sequence = Py_None; Py_INCREF(Py_None);
  p->cache_query_alignment_sequence = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_15calignedsegment_AlignedSegment(PyObject *o) {
  struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->_alignment_file);
  Py_CLEAR(p->cache_query_qualities);
  Py_CLEAR(p->cache_query_alignment_qualities);
  Py_CLEAR(p->cache_query_sequence);
  Py_CLEAR(p->cache_query_alignment_sequence);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_15calignedsegment_AlignedSegment(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)o;
  if (p->_alignment_file) {
    e = (*v)(((PyObject*)p->_alignment_file), a); if (e) return e;
  }
  if (p->cache_query_qualities) {
    e = (*v)(p->cache_query_qualities, a); if (e) return e;
  }
  if (p->cache_query_alignment_qualities) {
    e = (*v)(p->cache_query_alignment_qualities, a); if (e) return e;
  }
  if (p->cache_query_sequence) {
    e = (*v)(p->cache_query_sequence, a); if (e) return e;
  }
  if (p->cache_query_alignment_sequence) {
    e = (*v)(p->cache_query_alignment_sequence, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_15calignedsegment_AlignedSegment(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *p = (struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)o;
  tmp = ((PyObject*)p->_alignment_file);
  p->_alignment_file = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cache_query_qualities);
  p->cache_query_qualities = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cache_query_alignment_qualities);
  p->cache_query_alignment_qualities = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cache_query_sequence);
  p->cache_query_sequence = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->cache_query_alignment_sequence);
  p->cache_query_alignment_sequence = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_name(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10query_name_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10query_name_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_flag(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4flag_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_flag(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4flag_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_name(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14reference_name_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_id(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12reference_id_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12reference_id_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15reference_start_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15reference_start_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mapping_quality(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mapping_quality_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_cigarstring(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_cigarstring(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigarstring_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_id(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17next_reference_id_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_name(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19next_reference_name_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_20next_reference_start_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12query_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_template_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15template_length_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_template_length(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15template_length_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_sequence(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query_sequence(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14query_sequence_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_qualities(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query_qualities(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15query_qualities_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_bin(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3bin_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_bin(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3bin_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_paired(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_paired_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_paired(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_paired_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_proper_pair(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_proper_pair(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_14is_proper_pair_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11is_unmapped_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16mate_is_unmapped_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_reverse(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_10is_reverse_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_reverse(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15mate_is_reverse_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_read1(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read1_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_read1(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read1_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_read2(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read2_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_read2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_8is_read2_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_secondary(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_secondary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_secondary_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_qcfail(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_qcfail(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9is_qcfail_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_duplicate(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_duplicate(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_12is_duplicate_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_supplementary(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_supplementary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16is_supplementary_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_end(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13reference_end_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_16reference_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_sequence(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_24query_alignment_sequence_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_qualities(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_25query_alignment_qualities_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_21query_alignment_start_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_end(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19query_alignment_end_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_22query_alignment_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_cigartuples(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_cigartuples(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11cigartuples_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qname_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qname_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3tid_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3tid_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3pos_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3pos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mapq(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mapq_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mapq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mapq_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_rnext(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rnext_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_rnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rnext_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_pnext(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5pnext_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_pnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5pnext_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_cigar(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5cigar_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_cigar(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5cigar_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_tlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tlen_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_tlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tlen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_seq(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3seq_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_seq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_3seq_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qual(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qual_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qual_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_alen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4alen_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_alen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4alen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_aend(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4aend_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_aend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4aend_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_rlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4rlen_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_rlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4rlen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5query_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5query_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qqual(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qqual_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qqual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5qqual_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qstart(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6qstart_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qstart(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6qstart_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qend(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qend_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qend_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qlen_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4qlen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mrnm(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mrnm_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mrnm(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mrnm_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mpos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mpos_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mpos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4mpos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_rname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rname_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_rname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5rname_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_isize(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5isize_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_isize(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5isize_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_blocks(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_6blocks_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_aligned_pairs(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13aligned_pairs_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_inferred_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15inferred_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_positions(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9positions_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_tags(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tags_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_tags(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_4tags_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_5pysam_15calignedsegment_AlignedSegment[] = {
  {"__copy__", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_7__copy__, METH_NOARGS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_6__copy__},
  {"__deepcopy__", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_9__deepcopy__, METH_O, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_8__deepcopy__},
  {"compare", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_11compare, METH_O, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_10compare},
  {"tostring", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_17tostring, METH_O, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_16tostring},
  {"get_reference_positions", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_19get_reference_positions, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_18get_reference_positions},
  {"infer_query_length", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_21infer_query_length, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_20infer_query_length},
  {"get_reference_sequence", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_23get_reference_sequence, METH_NOARGS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_22get_reference_sequence},
  {"get_aligned_pairs", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_25get_aligned_pairs, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_24get_aligned_pairs},
  {"get_blocks", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_27get_blocks, METH_NOARGS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_26get_blocks},
  {"get_overlap", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_29get_overlap, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_28get_overlap},
  {"set_tag", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_31set_tag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_30set_tag},
  {"has_tag", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_33has_tag, METH_O, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_32has_tag},
  {"get_tag", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_35get_tag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_34get_tag},
  {"get_tags", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_37get_tags, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_36get_tags},
  {"set_tags", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_39set_tags, METH_O, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_38set_tags},
  {"overlap", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_41overlap, METH_NOARGS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_40overlap},
  {"opt", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_43opt, METH_O, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_42opt},
  {"setTag", (PyCFunction)__pyx_pw_5pysam_15calignedsegment_14AlignedSegment_45setTag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_44setTag},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_15calignedsegment_AlignedSegment[] = {
  {(char *)"query_name", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_name, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query_name, __pyx_k_the_query_template_name_None_if, 0},
  {(char *)"flag", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_flag, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_flag, __pyx_k_properties_flag, 0},
  {(char *)"reference_name", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_name, 0, __pyx_k_term_reference_name_None_if_no, 0},
  {(char *)"reference_id", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_id, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_reference_id, __pyx_k_term_reference_ID_note_This_fie, 0},
  {(char *)"reference_start", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_start, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_reference_start, __pyx_k_0_based_leftmost_coordinate, 0},
  {(char *)"mapping_quality", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mapping_quality, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mapping_quality, __pyx_k_mapping_quality_2, 0},
  {(char *)"cigarstring", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_cigarstring, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_cigarstring, __pyx_k_the_term_cigar_alignment_as_a_st, 0},
  {(char *)"next_reference_id", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_id, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_id, __pyx_k_the_term_reference_id_of_the_mat, 0},
  {(char *)"next_reference_name", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_name, 0, __pyx_k_term_reference_name_of_the_mate, 0},
  {(char *)"next_reference_start", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_start, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_next_reference_start, __pyx_k_the_position_of_the_mate_next_re, 0},
  {(char *)"query_length", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_length, 0, __pyx_k_the_length_of_the_query_read_Thi, 0},
  {(char *)"template_length", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_template_length, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_template_length, __pyx_k_the_observed_query_template_leng, 0},
  {(char *)"query_sequence", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_sequence, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query_sequence, __pyx_k_read_sequence_bases_including_te, 0},
  {(char *)"query_qualities", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_qualities, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query_qualities, __pyx_k_read_sequence_base_qualities_inc, 0},
  {(char *)"bin", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_bin, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_bin, __pyx_k_properties_bin, 0},
  {(char *)"is_paired", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_paired, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_paired, __pyx_k_true_if_read_is_paired_in_sequen, 0},
  {(char *)"is_proper_pair", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_proper_pair, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_proper_pair, __pyx_k_true_if_read_is_mapped_in_a_prop, 0},
  {(char *)"is_unmapped", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_unmapped, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_unmapped, __pyx_k_true_if_read_itself_is_unmapped, 0},
  {(char *)"mate_is_unmapped", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_unmapped, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_unmapped, __pyx_k_true_if_the_mate_is_unmapped, 0},
  {(char *)"is_reverse", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_reverse, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_reverse, __pyx_k_true_if_read_is_mapped_to_revers, 0},
  {(char *)"mate_is_reverse", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_reverse, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mate_is_reverse, __pyx_k_true_is_read_is_mapped_to_revers, 0},
  {(char *)"is_read1", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_read1, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_read1, __pyx_k_true_if_this_is_read1, 0},
  {(char *)"is_read2", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_read2, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_read2, __pyx_k_true_if_this_is_read2, 0},
  {(char *)"is_secondary", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_secondary, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_secondary, __pyx_k_true_if_not_primary_alignment, 0},
  {(char *)"is_qcfail", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_qcfail, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_qcfail, __pyx_k_true_if_QC_failure, 0},
  {(char *)"is_duplicate", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_duplicate, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_duplicate, __pyx_k_true_if_optical_or_PCR_duplicate, 0},
  {(char *)"is_supplementary", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_is_supplementary, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_is_supplementary, __pyx_k_true_if_this_is_a_supplementary, 0},
  {(char *)"reference_end", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_end, 0, __pyx_k_aligned_reference_position_of_th, 0},
  {(char *)"reference_length", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_reference_length, 0, __pyx_k_aligned_length_of_the_read_on_th, 0},
  {(char *)"query_alignment_sequence", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_sequence, 0, __pyx_k_aligned_portion_of_the_read_This, 0},
  {(char *)"query_alignment_qualities", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_qualities, 0, __pyx_k_aligned_query_sequence_quality_v, 0},
  {(char *)"query_alignment_start", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_start, 0, __pyx_k_start_index_of_the_aligned_query, 0},
  {(char *)"query_alignment_end", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_end, 0, __pyx_k_end_index_of_the_aligned_query_p, 0},
  {(char *)"query_alignment_length", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query_alignment_length, 0, __pyx_k_length_of_the_aligned_query_sequ, 0},
  {(char *)"cigartuples", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_cigartuples, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_cigartuples, __pyx_k_the_term_cigar_alignment_The_ali, 0},
  {(char *)"qname", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qname, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qname, __pyx_k_deprecated_use_query_name_instea, 0},
  {(char *)"tid", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_tid, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_tid, __pyx_k_deprecated_use_reference_id_inst, 0},
  {(char *)"pos", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_pos, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_pos, __pyx_k_deprecated_use_reference_start_i, 0},
  {(char *)"mapq", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mapq, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mapq, __pyx_k_deprecated_use_mapping_quality_i, 0},
  {(char *)"rnext", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_rnext, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_rnext, __pyx_k_deprecated_use_next_reference_id, 0},
  {(char *)"pnext", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_pnext, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_pnext, __pyx_k_deprecated_use_next_reference_st, 0},
  {(char *)"cigar", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_cigar, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_cigar, __pyx_k_deprecated_use_cigartuples_inste, 0},
  {(char *)"tlen", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_tlen, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_tlen, __pyx_k_deprecated_use_template_length_i, 0},
  {(char *)"seq", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_seq, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_seq, __pyx_k_deprecated_use_query_sequence_in, 0},
  {(char *)"qual", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qual, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qual, __pyx_k_deprecated_query_qualities_inste, 0},
  {(char *)"alen", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_alen, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_alen, __pyx_k_deprecated_reference_length_inst, 0},
  {(char *)"aend", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_aend, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_aend, __pyx_k_deprecated_reference_end_instead, 0},
  {(char *)"rlen", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_rlen, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_rlen, __pyx_k_deprecated_query_length_instead, 0},
  {(char *)"query", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_query, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_query, __pyx_k_deprecated_query_alignment_seque, 0},
  {(char *)"qqual", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qqual, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qqual, __pyx_k_deprecated_query_alignment_quali, 0},
  {(char *)"qstart", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qstart, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qstart, __pyx_k_deprecated_use_query_alignment_s, 0},
  {(char *)"qend", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qend, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qend, __pyx_k_deprecated_use_query_alignment_e, 0},
  {(char *)"qlen", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_qlen, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_qlen, __pyx_k_deprecated_use_query_alignment_l, 0},
  {(char *)"mrnm", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mrnm, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mrnm, __pyx_k_deprecated_use_next_reference_id, 0},
  {(char *)"mpos", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_mpos, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_mpos, __pyx_k_deprecated_use_next_reference_st, 0},
  {(char *)"rname", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_rname, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_rname, __pyx_k_deprecated_use_reference_id_inst, 0},
  {(char *)"isize", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_isize, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_isize, __pyx_k_deprecated_use_template_length_i, 0},
  {(char *)"blocks", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_blocks, 0, __pyx_k_deprecated_use_get_blocks_instea, 0},
  {(char *)"aligned_pairs", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_aligned_pairs, 0, __pyx_k_deprecated_use_get_aligned_pairs, 0},
  {(char *)"inferred_length", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_inferred_length, 0, __pyx_k_deprecated_use_infer_query_lengt, 0},
  {(char *)"positions", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_positions, 0, __pyx_k_deprecated_use_get_reference_pos, 0},
  {(char *)"tags", __pyx_getprop_5pysam_15calignedsegment_14AlignedSegment_tags, __pyx_setprop_5pysam_15calignedsegment_14AlignedSegment_tags, __pyx_k_deprecated_use_get_tags_instead, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_15calignedsegment_AlignedSegment = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignedsegment.AlignedSegment", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_15calignedsegment_AlignedSegment, /*tp_dealloc*/
  0, /*tp_print*/
  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*/
  __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_15__hash__, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_5__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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "AlignedSegment()\nClass representing an aligned segment.\n\n    This class stores a handle to the samtools C-structure representing\n    an aligned read. Member read access is forwarded to the C-structure\n    and converted into python objects. This implementation should be fast,\n    as only the data needed is converted.\n\n    For write access, the C-structure is updated in-place. This is\n    not the most efficient way to build BAM entries, as the variable\n    length data is concatenated and thus needs to be resized if\n    a field is updated. Furthermore, the BAM entry might be\n    in an inconsistent state.\n\n    One issue to look out for is that the sequence should always\n    be set *before* the quality scores. Setting the sequence will\n    also erase any quality scores that were set previously.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_15calignedsegment_AlignedSegment, /*tp_traverse*/
  __pyx_tp_clear_5pysam_15calignedsegment_AlignedSegment, /*tp_clear*/
  __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_13__richcmp__, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_15calignedsegment_AlignedSegment, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_15calignedsegment_AlignedSegment, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_15calignedsegment_14AlignedSegment_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_15calignedsegment_AlignedSegment, /*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
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_15calignedsegment_PileupColumn(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)o);
  p->_alignment_file = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_15calignedsegment_PileupColumn(PyObject *o) {
  struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->_alignment_file);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_15calignedsegment_PileupColumn(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)o;
  if (p->_alignment_file) {
    e = (*v)(((PyObject*)p->_alignment_file), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_15calignedsegment_PileupColumn(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *p = (struct __pyx_obj_5pysam_15calignedsegment_PileupColumn *)o;
  tmp = ((PyObject*)p->_alignment_file);
  p->_alignment_file = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_reference_id(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_12reference_id_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_reference_name(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_14reference_name_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_nsegments(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_9nsegments_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_nsegments(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_9nsegments_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_reference_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_13reference_pos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_pileups(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_7pileups_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3pos_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3pos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3tid_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_3tid_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_12PileupColumn_n(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_1n_1__get__(o);
}

static int __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_n(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_15calignedsegment_12PileupColumn_1n_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_5pysam_15calignedsegment_PileupColumn[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_15calignedsegment_PileupColumn[] = {
  {(char *)"reference_id", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_reference_id, 0, __pyx_k_the_reference_sequence_number_as, 0},
  {(char *)"reference_name", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_reference_name, 0, __pyx_k_term_reference_name_None_if_no, 0},
  {(char *)"nsegments", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_nsegments, __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_nsegments, __pyx_k_number_of_reads_mapping_to_this, 0},
  {(char *)"reference_pos", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_reference_pos, 0, __pyx_k_the_position_in_the_reference_se, 0},
  {(char *)"pileups", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_pileups, 0, __pyx_k_list_of_reads_class_pysam_Pileup, 0},
  {(char *)"pos", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_pos, __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_pos, 0, 0},
  {(char *)"tid", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_tid, __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_tid, 0, 0},
  {(char *)"n", __pyx_getprop_5pysam_15calignedsegment_12PileupColumn_n, __pyx_setprop_5pysam_15calignedsegment_12PileupColumn_n, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_15calignedsegment_PileupColumn = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignedsegment.PileupColumn", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_15calignedsegment_PileupColumn), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_15calignedsegment_PileupColumn, /*tp_dealloc*/
  0, /*tp_print*/
  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_15calignedsegment_12PileupColumn_3__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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "PileupColumn()\nA pileup of reads at a particular reference sequence postion\n    (:term:`column`). A pileup column contains all the reads that map\n    to a certain target base.\n\n    This class is a proxy for results returned by the samtools pileup\n    engine.  If the underlying engine iterator advances, the results\n    of this column will change.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_15calignedsegment_PileupColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_15calignedsegment_PileupColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_15calignedsegment_PileupColumn, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_15calignedsegment_PileupColumn, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_15calignedsegment_12PileupColumn_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_15calignedsegment_PileupColumn, /*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
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_15calignedsegment_PileupRead(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_15calignedsegment_PileupRead *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)o);
  p->_alignment = ((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_15calignedsegment_PileupRead(PyObject *o) {
  struct __pyx_obj_5pysam_15calignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->_alignment);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_15calignedsegment_PileupRead(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_15calignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)o;
  if (p->_alignment) {
    e = (*v)(((PyObject*)p->_alignment), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_15calignedsegment_PileupRead(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_15calignedsegment_PileupRead *p = (struct __pyx_obj_5pysam_15calignedsegment_PileupRead *)o;
  tmp = ((PyObject*)p->_alignment);
  p->_alignment = ((struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_alignment(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_9alignment_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_query_position(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_14query_position_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_query_position_or_next(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_22query_position_or_next_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_indel(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_5indel_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_level(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_5level_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_del(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_6is_del_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_head(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_7is_head_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_tail(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_7is_tail_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_refskip(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_15calignedsegment_10PileupRead_10is_refskip_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_15calignedsegment_PileupRead[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_15calignedsegment_PileupRead[] = {
  {(char *)"alignment", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_alignment, 0, __pyx_k_a_class_pysam_AlignedSegment_obj, 0},
  {(char *)"query_position", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_query_position, 0, __pyx_k_position_of_the_read_base_at_the, 0},
  {(char *)"query_position_or_next", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_query_position_or_next, 0, __pyx_k_position_of_the_read_base_at_the_2, 0},
  {(char *)"indel", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_indel, 0, __pyx_k_indel_length_for_the_position_fo, 0},
  {(char *)"level", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_level, 0, __pyx_k_the_level_of_the_read_in_the_vie, 0},
  {(char *)"is_del", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_del, 0, __pyx_k_1_iff_the_base_on_the_padded_rea, 0},
  {(char *)"is_head", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_head, 0, __pyx_k_1_iff_the_base_on_the_padded_rea_2, 0},
  {(char *)"is_tail", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_tail, 0, __pyx_k_1_iff_the_base_on_the_padded_rea_3, 0},
  {(char *)"is_refskip", __pyx_getprop_5pysam_15calignedsegment_10PileupRead_is_refskip, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_15calignedsegment_PileupRead = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignedsegment.PileupRead", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_15calignedsegment_PileupRead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_15calignedsegment_PileupRead, /*tp_dealloc*/
  0, /*tp_print*/
  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_15calignedsegment_10PileupRead_3__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|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "PileupRead()\nRepresentation of a read aligned to a particular position in the\n    reference sequence.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_15calignedsegment_PileupRead, /*tp_traverse*/
  __pyx_tp_clear_5pysam_15calignedsegment_PileupRead, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_15calignedsegment_PileupRead, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_15calignedsegment_PileupRead, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_15calignedsegment_10PileupRead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_15calignedsegment_PileupRead, /*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
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *__pyx_freelist_5pysam_15calignedsegment___pyx_scope_struct__genexpr[8];
static int __pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct__genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct__genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct__genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_15calignedsegment___pyx_scope_struct__genexpr[--__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct__genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_15calignedsegment___pyx_scope_struct__genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_v_y);
  Py_CLEAR(p->__pyx_t_0);
  Py_CLEAR(p->__pyx_t_1);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct__genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr)))) {
    __pyx_freelist_5pysam_15calignedsegment___pyx_scope_struct__genexpr[__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct__genexpr++] = ((struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_15calignedsegment___pyx_scope_struct__genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *)o;
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, a); if (e) return e;
  }
  if (p->__pyx_v_y) {
    e = (*v)(p->__pyx_v_y, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  if (p->__pyx_t_1) {
    e = (*v)(p->__pyx_t_1, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_15calignedsegment___pyx_scope_struct__genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr *)o;
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_y);
  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_0);
  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_1);
  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5pysam_15calignedsegment___pyx_scope_struct__genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignedsegment.__pyx_scope_struct__genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct__genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_15calignedsegment___pyx_scope_struct__genexpr, /*tp_dealloc*/
  0, /*tp_print*/
  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_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_15calignedsegment___pyx_scope_struct__genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_15calignedsegment___pyx_scope_struct__genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct__genexpr, /*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
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr[8];
static int __pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_v_y);
  Py_CLEAR(p->__pyx_t_0);
  Py_CLEAR(p->__pyx_t_1);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr)))) {
    __pyx_freelist_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *)o;
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, a); if (e) return e;
  }
  if (p->__pyx_v_y) {
    e = (*v)(p->__pyx_v_y, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  if (p->__pyx_t_1) {
    e = (*v)(p->__pyx_t_1, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr *)o;
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_y);
  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_0);
  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_1);
  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignedsegment.__pyx_scope_struct_1_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
  0, /*tp_print*/
  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_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr, /*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
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "calignedsegment",
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_2sc_is, __pyx_k_2sc_is, sizeof(__pyx_k_2sc_is), 0, 0, 1, 0},
  {&__pyx_kp_s_2sc_s, __pyx_k_2sc_s, sizeof(__pyx_k_2sc_s), 0, 0, 1, 0},
  {&__pyx_kp_s_2sccI_i_s, __pyx_k_2sccI_i_s, sizeof(__pyx_k_2sccI_i_s), 0, 0, 1, 0},
  {&__pyx_kp_s_2sccI_is, __pyx_k_2sccI_is, sizeof(__pyx_k_2sccI_is), 0, 0, 1, 0},
  {&__pyx_n_b_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 0, 1},
  {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1},
  {&__pyx_n_b_AZ, __pyx_k_AZ, sizeof(__pyx_k_AZ), 0, 0, 0, 1},
  {&__pyx_n_s_AlignedSegment, __pyx_k_AlignedSegment, sizeof(__pyx_k_AlignedSegment), 0, 0, 1, 1},
  {&__pyx_n_b_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 0, 1},
  {&__pyx_n_s_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 1, 1},
  {&__pyx_n_b_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 0, 1},
  {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1},
  {&__pyx_n_s_CIGAR2CODE, __pyx_k_CIGAR2CODE, sizeof(__pyx_k_CIGAR2CODE), 0, 0, 1, 1},
  {&__pyx_n_s_CIGAR_REGEX, __pyx_k_CIGAR_REGEX, sizeof(__pyx_k_CIGAR_REGEX), 0, 0, 1, 1},
  {&__pyx_n_s_D, __pyx_k_D, sizeof(__pyx_k_D), 0, 0, 1, 1},
  {&__pyx_n_s_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 0, 1, 1},
  {&__pyx_n_s_H, __pyx_k_H, sizeof(__pyx_k_H), 0, 0, 1, 1},
  {&__pyx_n_b_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 0, 1},
  {&__pyx_n_s_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 1, 1},
  {&__pyx_kp_s_Invalid_tag_s, __pyx_k_Invalid_tag_s, sizeof(__pyx_k_Invalid_tag_s), 0, 0, 1, 0},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_kp_s_MD_tag_not_present, __pyx_k_MD_tag_not_present, sizeof(__pyx_k_MD_tag_not_present), 0, 0, 1, 0},
  {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
  {&__pyx_n_s_NotImplemented, __pyx_k_NotImplemented, sizeof(__pyx_k_NotImplemented), 0, 0, 1, 1},
  {&__pyx_n_s_NotImplementedError, __pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 0, 1, 1},
  {&__pyx_kp_s_Padding_BAM_CPAD_6_is_currently, __pyx_k_Padding_BAM_CPAD_6_is_currently, sizeof(__pyx_k_Padding_BAM_CPAD_6_is_currently), 0, 0, 1, 0},
  {&__pyx_n_s_PileupColumn, __pyx_k_PileupColumn, sizeof(__pyx_k_PileupColumn), 0, 0, 1, 1},
  {&__pyx_kp_s_PileupColumn_accessed_after_iter, __pyx_k_PileupColumn_accessed_after_iter, sizeof(__pyx_k_PileupColumn_accessed_after_iter), 0, 0, 1, 0},
  {&__pyx_n_s_PileupRead, __pyx_k_PileupRead, sizeof(__pyx_k_PileupRead), 0, 0, 1, 1},
  {&__pyx_n_b_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 0, 1},
  {&__pyx_n_s_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 1, 1},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_n_b_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 0, 1},
  {&__pyx_n_s_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 1, 1},
  {&__pyx_n_s_Zidf, __pyx_k_Zidf, sizeof(__pyx_k_Zidf), 0, 0, 1, 1},
  {&__pyx_kp_s__16, __pyx_k__16, sizeof(__pyx_k__16), 0, 0, 1, 0},
  {&__pyx_kp_s__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 0, 1, 0},
  {&__pyx_kp_s__30, __pyx_k__30, sizeof(__pyx_k__30), 0, 0, 1, 0},
  {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0},
  {&__pyx_n_s_alignment, __pyx_k_alignment, sizeof(__pyx_k_alignment), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_always, __pyx_k_always, sizeof(__pyx_k_always), 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_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1},
  {&__pyx_kp_s_at_least_one_integer_out_of_rang, __pyx_k_at_least_one_integer_out_of_rang, sizeof(__pyx_k_at_least_one_integer_out_of_rang), 0, 0, 1, 0},
  {&__pyx_kp_s_at_least_one_signed_integer_out, __pyx_k_at_least_one_signed_integer_out, sizeof(__pyx_k_at_least_one_signed_integer_out), 0, 0, 1, 0},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_n_b_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 0, 1},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__pyx_kp_s_c_2, __pyx_k_c_2, sizeof(__pyx_k_c_2), 0, 0, 1, 0},
  {&__pyx_n_s_calcsize, __pyx_k_calcsize, sizeof(__pyx_k_calcsize), 0, 0, 1, 1},
  {&__pyx_kp_s_can_t_guess_type_or_invalid_type, __pyx_k_can_t_guess_type_or_invalid_type, sizeof(__pyx_k_can_t_guess_type_or_invalid_type), 0, 0, 1, 0},
  {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 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_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_compare, __pyx_k_compare, sizeof(__pyx_k_compare), 0, 0, 1, 1},
  {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1},
  {&__pyx_kp_s_could_not_allocated_sequence_of, __pyx_k_could_not_allocated_sequence_of, sizeof(__pyx_k_could_not_allocated_sequence_of), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_determine_alignment_le, __pyx_k_could_not_determine_alignment_le, sizeof(__pyx_k_could_not_determine_alignment_le), 0, 0, 1, 0},
  {&__pyx_n_s_create_string_buffer, __pyx_k_create_string_buffer, sizeof(__pyx_k_create_string_buffer), 0, 0, 1, 1},
  {&__pyx_n_s_ctypes, __pyx_k_ctypes, sizeof(__pyx_k_ctypes), 0, 0, 1, 1},
  {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1},
  {&__pyx_kp_s_d_MIDNSHP_X, __pyx_k_d_MIDNSHP_X, sizeof(__pyx_k_d_MIDNSHP_X), 0, 0, 1, 0},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_b_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 0, 1},
  {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1},
  {&__pyx_n_s_findall, __pyx_k_findall, sizeof(__pyx_k_findall), 0, 0, 1, 1},
  {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1},
  {&__pyx_n_s_full_length, __pyx_k_full_length, sizeof(__pyx_k_full_length), 0, 0, 1, 1},
  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 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_blocks, __pyx_k_get_blocks, sizeof(__pyx_k_get_blocks), 0, 0, 1, 1},
  {&__pyx_n_s_get_overlap, __pyx_k_get_overlap, sizeof(__pyx_k_get_overlap), 0, 0, 1, 1},
  {&__pyx_n_s_get_reference_positions, __pyx_k_get_reference_positions, sizeof(__pyx_k_get_reference_positions), 0, 0, 1, 1},
  {&__pyx_n_s_get_reference_sequence, __pyx_k_get_reference_sequence, sizeof(__pyx_k_get_reference_sequence), 0, 0, 1, 1},
  {&__pyx_n_s_get_tag, __pyx_k_get_tag, sizeof(__pyx_k_get_tag), 0, 0, 1, 1},
  {&__pyx_n_s_get_tags, __pyx_k_get_tags, sizeof(__pyx_k_get_tags), 0, 0, 1, 1},
  {&__pyx_n_s_getrname, __pyx_k_getrname, sizeof(__pyx_k_getrname), 0, 0, 1, 1},
  {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1},
  {&__pyx_n_s_has_tag, __pyx_k_has_tag, sizeof(__pyx_k_has_tag), 0, 0, 1, 1},
  {&__pyx_n_b_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 0, 1},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_kp_s_i_c, __pyx_k_i_c, sizeof(__pyx_k_i_c), 0, 0, 1, 0},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_indel, __pyx_k_indel, sizeof(__pyx_k_indel), 0, 0, 1, 1},
  {&__pyx_n_s_infer_query_length, __pyx_k_infer_query_length, sizeof(__pyx_k_infer_query_length), 0, 0, 1, 1},
  {&__pyx_kp_s_invalid_value_type_s, __pyx_k_invalid_value_type_s, sizeof(__pyx_k_invalid_value_type_s), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_value_type_s_s, __pyx_k_invalid_value_type_s_s, sizeof(__pyx_k_invalid_value_type_s_s), 0, 0, 1, 0},
  {&__pyx_n_s_is_del, __pyx_k_is_del, sizeof(__pyx_k_is_del), 0, 0, 1, 1},
  {&__pyx_n_s_is_head, __pyx_k_is_head, sizeof(__pyx_k_is_head), 0, 0, 1, 1},
  {&__pyx_n_s_is_refskip, __pyx_k_is_refskip, sizeof(__pyx_k_is_refskip), 0, 0, 1, 1},
  {&__pyx_n_s_is_tail, __pyx_k_is_tail, sizeof(__pyx_k_is_tail), 0, 0, 1, 1},
  {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1},
  {&__pyx_n_s_level, __pyx_k_level, sizeof(__pyx_k_level), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_kp_s_malformatted_tag_s, __pyx_k_malformatted_tag_s, sizeof(__pyx_k_malformatted_tag_s), 0, 0, 1, 0},
  {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1},
  {&__pyx_n_s_mapping_quality, __pyx_k_mapping_quality, sizeof(__pyx_k_mapping_quality), 0, 0, 1, 1},
  {&__pyx_n_s_matches_only, __pyx_k_matches_only, sizeof(__pyx_k_matches_only), 0, 0, 1, 1},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
  {&__pyx_n_s_next_reference_id, __pyx_k_next_reference_id, sizeof(__pyx_k_next_reference_id), 0, 0, 1, 1},
  {&__pyx_n_s_next_reference_start, __pyx_k_next_reference_start, sizeof(__pyx_k_next_reference_start), 0, 0, 1, 1},
  {&__pyx_n_s_nsegments, __pyx_k_nsegments, sizeof(__pyx_k_nsegments), 0, 0, 1, 1},
  {&__pyx_n_s_pack_into, __pyx_k_pack_into, sizeof(__pyx_k_pack_into), 0, 0, 1, 1},
  {&__pyx_n_s_pileups, __pyx_k_pileups, sizeof(__pyx_k_pileups), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_k_quality_and_sequence_mismatch_i, sizeof(__pyx_k_quality_and_sequence_mismatch_i), 0, 0, 1, 0},
  {&__pyx_n_s_query_alignment_end, __pyx_k_query_alignment_end, sizeof(__pyx_k_query_alignment_end), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_length, __pyx_k_query_alignment_length, sizeof(__pyx_k_query_alignment_length), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_qualities, __pyx_k_query_alignment_qualities, sizeof(__pyx_k_query_alignment_qualities), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_sequence, __pyx_k_query_alignment_sequence, sizeof(__pyx_k_query_alignment_sequence), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_start, __pyx_k_query_alignment_start, sizeof(__pyx_k_query_alignment_start), 0, 0, 1, 1},
  {&__pyx_n_s_query_length, __pyx_k_query_length, sizeof(__pyx_k_query_length), 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_position, __pyx_k_query_position, sizeof(__pyx_k_query_position), 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_query_sequence, __pyx_k_query_sequence, sizeof(__pyx_k_query_sequence), 0, 0, 1, 1},
  {&__pyx_n_s_raw, __pyx_k_raw, sizeof(__pyx_k_raw), 0, 0, 1, 1},
  {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1},
  {&__pyx_n_s_reference_end, __pyx_k_reference_end, sizeof(__pyx_k_reference_end), 0, 0, 1, 1},
  {&__pyx_n_s_reference_id, __pyx_k_reference_id, sizeof(__pyx_k_reference_id), 0, 0, 1, 1},
  {&__pyx_n_s_reference_length, __pyx_k_reference_length, sizeof(__pyx_k_reference_length), 0, 0, 1, 1},
  {&__pyx_n_s_reference_pos, __pyx_k_reference_pos, sizeof(__pyx_k_reference_pos), 0, 0, 1, 1},
  {&__pyx_n_s_reference_start, __pyx_k_reference_start, sizeof(__pyx_k_reference_start), 0, 0, 1, 1},
  {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1},
  {&__pyx_n_b_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 0, 1},
  {&__pyx_n_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 1},
  {&__pyx_kp_s_sam_format_failed, __pyx_k_sam_format_failed, sizeof(__pyx_k_sam_format_failed), 0, 0, 1, 0},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_n_s_set_tag, __pyx_k_set_tag, sizeof(__pyx_k_set_tag), 0, 0, 1, 1},
  {&__pyx_n_s_set_tags, __pyx_k_set_tags, sizeof(__pyx_k_set_tags), 0, 0, 1, 1},
  {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1},
  {&__pyx_n_s_tag, __pyx_k_tag, sizeof(__pyx_k_tag), 0, 0, 1, 1},
  {&__pyx_kp_s_tag_s_not_present, __pyx_k_tag_s_not_present, sizeof(__pyx_k_tag_s_not_present), 0, 0, 1, 0},
  {&__pyx_n_s_tags, __pyx_k_tags, sizeof(__pyx_k_tags), 0, 0, 1, 1},
  {&__pyx_n_s_template_length, __pyx_k_template_length, sizeof(__pyx_k_template_length), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_kp_s_this_class_cannot_be_instantiate, __pyx_k_this_class_cannot_be_instantiate, sizeof(__pyx_k_this_class_cannot_be_instantiate), 0, 0, 1, 0},
  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
  {&__pyx_n_s_tostring, __pyx_k_tostring, sizeof(__pyx_k_tostring), 0, 0, 1, 1},
  {&__pyx_n_s_typecode, __pyx_k_typecode, sizeof(__pyx_k_typecode), 0, 0, 1, 1},
  {&__pyx_kp_s_unknown_auxiliary_type_s, __pyx_k_unknown_auxiliary_type_s, sizeof(__pyx_k_unknown_auxiliary_type_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_conversion_for_array_typ, __pyx_k_unknown_conversion_for_array_typ, sizeof(__pyx_k_unknown_conversion_for_array_typ), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_htslib_tag_typecode_s, __pyx_k_unknown_htslib_tag_typecode_s, sizeof(__pyx_k_unknown_htslib_tag_typecode_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_type_s, __pyx_k_unknown_type_s, sizeof(__pyx_k_unknown_type_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unsupported_value_type_in_set_op, __pyx_k_unsupported_value_type_in_set_op, sizeof(__pyx_k_unsupported_value_type_in_set_op), 0, 0, 1, 0},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_n_s_value_type, __pyx_k_value_type, sizeof(__pyx_k_value_type), 0, 0, 1, 1},
  {&__pyx_n_s_with_seq, __pyx_k_with_seq, sizeof(__pyx_k_with_seq), 0, 0, 1, 1},
  {&__pyx_n_s_with_value_type, __pyx_k_with_value_type, sizeof(__pyx_k_with_value_type), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_NotImplemented = __Pyx_GetBuiltinName(__pyx_n_s_NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pysam/calignedsegment.pyx":193
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one signed integer out of range of "
 *                     "BAM/SAM specification")
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_at_least_one_signed_integer_out); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "pysam/calignedsegment.pyx":205
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one integer out of range of BAM/SAM specification")
 *             else:
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_at_least_one_integer_out_of_rang); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "pysam/calignedsegment.pyx":212
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:
 *             value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *         if len(value) == 1:
 *             valuetype = b'A'
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "pysam/calignedsegment.pyx":233
 * 
 *     datatype2format = {
 *         b'c': ('b', 1),             # <<<<<<<<<<<<<<
 *         b'C': ('B', 1),
 *         b's': ('h', 2),
 */
  __pyx_tuple__5 = PyTuple_Pack(2, __pyx_n_s_b, __pyx_int_1); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 233; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "pysam/calignedsegment.pyx":234
 *     datatype2format = {
 *         b'c': ('b', 1),
 *         b'C': ('B', 1),             # <<<<<<<<<<<<<<
 *         b's': ('h', 2),
 *         b'S': ('H', 2),
 */
  __pyx_tuple__6 = PyTuple_Pack(2, __pyx_n_s_B, __pyx_int_1); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "pysam/calignedsegment.pyx":235
 *         b'c': ('b', 1),
 *         b'C': ('B', 1),
 *         b's': ('h', 2),             # <<<<<<<<<<<<<<
 *         b'S': ('H', 2),
 *         b'i': ('i', 4),
 */
  __pyx_tuple__7 = PyTuple_Pack(2, __pyx_n_s_h, __pyx_int_2); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 235; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);

  /* "pysam/calignedsegment.pyx":236
 *         b'C': ('B', 1),
 *         b's': ('h', 2),
 *         b'S': ('H', 2),             # <<<<<<<<<<<<<<
 *         b'i': ('i', 4),
 *         b'I': ('I', 4),
 */
  __pyx_tuple__8 = PyTuple_Pack(2, __pyx_n_s_H, __pyx_int_2); if (unlikely(!__pyx_tuple__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "pysam/calignedsegment.pyx":237
 *         b's': ('h', 2),
 *         b'S': ('H', 2),
 *         b'i': ('i', 4),             # <<<<<<<<<<<<<<
 *         b'I': ('I', 4),
 *         b'f': ('f', 4),
 */
  __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_i, __pyx_int_4); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "pysam/calignedsegment.pyx":238
 *         b'S': ('H', 2),
 *         b'i': ('i', 4),
 *         b'I': ('I', 4),             # <<<<<<<<<<<<<<
 *         b'f': ('f', 4),
 *         b'A': ('c', 1)}
 */
  __pyx_tuple__10 = PyTuple_Pack(2, __pyx_n_s_I, __pyx_int_4); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pysam/calignedsegment.pyx":239
 *         b'i': ('i', 4),
 *         b'I': ('I', 4),
 *         b'f': ('f', 4),             # <<<<<<<<<<<<<<
 *         b'A': ('c', 1)}
 * 
 */
  __pyx_tuple__11 = PyTuple_Pack(2, __pyx_n_s_f, __pyx_int_4); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "pysam/calignedsegment.pyx":240
 *         b'I': ('I', 4),
 *         b'f': ('f', 4),
 *         b'A': ('c', 1)}             # <<<<<<<<<<<<<<
 * 
 *     for tag in tags:
 */
  __pyx_tuple__12 = PyTuple_Pack(2, __pyx_n_s_c, __pyx_int_1); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "pysam/calignedsegment.pyx":268
 * 
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype][0])
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
  __pyx_slice__13 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__13);
  __Pyx_GIVEREF(__pyx_slice__13);

  /* "pysam/calignedsegment.pyx":286
 *             # save as bytes
 *             datafmt = "2sccI%is" % (len(value) * datatype2format[valuetype][1])
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
  __pyx_slice__14 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__14);
  __Pyx_GIVEREF(__pyx_slice__14);

  /* "pysam/calignedsegment.pyx":304
 *                 datafmt = "2sc%s" % datatype2format[valuetype][0]
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          valuetype,
 *                          value])
 */
  __pyx_slice__15 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__15);
  __Pyx_GIVEREF(__pyx_slice__15);

  /* "pysam/calignedsegment.pyx":530
 *     cdef uint32_t max_len = get_alignment_length(src)
 *     if max_len == 0:
 *         raise ValueError("could not determine alignment length")             # <<<<<<<<<<<<<<
 * 
 *     cdef char * s = <char*>calloc(max_len + 1, sizeof(char))
 */
  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_could_not_determine_alignment_le); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "pysam/calignedsegment.pyx":560
 *             pass # advances neither
 *         elif op == BAM_CPAD:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "Padding (BAM_CPAD, 6) is currently not supported. "
 *                 "Please implement. Sorry about that.")
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "pysam/calignedsegment.pyx":770
 *             if line.m:
 *                 free(line.s)
 *             raise ValueError('sam_format failed')             # <<<<<<<<<<<<<<
 * 
 *         ret = force_str(line.s[:line.l])
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_sam_format_failed); if (unlikely(!__pyx_tuple__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "pysam/calignedsegment.pyx":1400
 *         ref_seq = force_str(build_alignment_sequence(src))
 *         if ref_seq is None:
 *             raise ValueError("MD tag not present")             # <<<<<<<<<<<<<<
 * 
 *         cdef uint32_t * cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_MD_tag_not_present); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "pysam/calignedsegment.pyx":1423
 *                 pass # advances neither
 *             elif op == BAM_CPAD:
 *                 raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 *                     "Please implement. Sorry about that.")
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "pysam/calignedsegment.pyx":1468
 *             ref_seq = force_str(self.get_reference_sequence())
 *             if ref_seq is None:
 *                 raise ValueError("MD tag not present")             # <<<<<<<<<<<<<<
 * 
 *         r_idx = 0
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_MD_tag_not_present); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "pysam/calignedsegment.pyx":1523
 * 
 *             elif op == BAM_CPAD:
 *                 raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                     "Padding (BAM_CPAD, 6) is currently not supported. "
 *                     "Please implement. Sorry about that.")
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1523; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "pysam/calignedsegment.pyx":1752
 *         typecode = get_value_code(value, value_type)
 *         if typecode == 0:
 *             raise ValueError("can't guess type or invalid type code specified")             # <<<<<<<<<<<<<<
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_can_t_guess_type_or_invalid_type); if (unlikely(!__pyx_tuple__25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1752; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "pysam/calignedsegment.pyx":1781
 *             # remove tag and type code as set by bam_aux_append
 *             # first four chars of format (<2sc)
 *             fmt = '<' + fmt[4:]             # <<<<<<<<<<<<<<
 *             # first two values to pack
 *             args = args[2:]
 */
  __pyx_slice__26 = PySlice_New(__pyx_int_4, Py_None, Py_None); if (unlikely(!__pyx_slice__26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__26);
  __Pyx_GIVEREF(__pyx_slice__26);

  /* "pysam/calignedsegment.pyx":1783
 *             fmt = '<' + fmt[4:]
 *             # first two values to pack
 *             args = args[2:]             # <<<<<<<<<<<<<<
 *             value_size = struct.calcsize(fmt)
 *             # buffer will be freed when object goes out of scope
 */
  __pyx_slice__27 = PySlice_New(__pyx_int_2, Py_None, Py_None); if (unlikely(!__pyx_slice__27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__27);
  __Pyx_GIVEREF(__pyx_slice__27);

  /* "pysam/calignedsegment.pyx":1796
 *             return
 *         else:
 *             raise ValueError('unsupported value_type in set_option')             # <<<<<<<<<<<<<<
 * 
 *         bam_aux_append(src,
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_unsupported_value_type_in_set_op); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "pysam/calignedsegment.pyx":2196
 *     '''
 *     def __init__(self):
 *         raise TypeError("this class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "pysam/calignedsegment.pyx":2237
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 *                 raise ValueError("PileupColumn accessed after iterator finished")             # <<<<<<<<<<<<<<
 * 
 *             # warning: there could be problems if self.n and self.buf are
 */
  __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s_PileupColumn_accessed_after_iter); if (unlikely(!__pyx_tuple__31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "pysam/calignedsegment.pyx":2276
 * 
 *     def __init__(self):
 *         raise TypeError(             # <<<<<<<<<<<<<<
 *             "this class cannot be instantiated from Python")
 * 
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "pysam/calignedsegment.pyx":86
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))
 * 
 * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=X])")             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_d_MIDNSHP_X); if (unlikely(!__pyx_tuple__33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_4 = PyInt_FromLong(4); if (unlikely(!__pyx_int_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_128 = PyInt_FromLong(128); if (unlikely(!__pyx_int_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_256 = PyInt_FromLong(256); if (unlikely(!__pyx_int_256)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_32768 = PyInt_FromLong(32768L); if (unlikely(!__pyx_int_32768)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_65536 = PyInt_FromLong(65536L); if (unlikely(!__pyx_int_65536)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_2147483648 = PyInt_FromString((char *)"2147483648", 0, 0); if (unlikely(!__pyx_int_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_4294967296 = PyInt_FromString((char *)"4294967296", 0, 0); if (unlikely(!__pyx_int_4294967296)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_128 = PyInt_FromLong(-128); if (unlikely(!__pyx_int_neg_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_32768 = PyInt_FromLong(-32768L); if (unlikely(!__pyx_int_neg_32768)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_2147483648 = PyInt_FromLong(-2147483648L); if (unlikely(!__pyx_int_neg_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initcalignedsegment(void); /*proto*/
PyMODINIT_FUNC initcalignedsegment(void)
#else
PyMODINIT_FUNC PyInit_calignedsegment(void); /*proto*/
PyMODINIT_FUNC PyInit_calignedsegment(void)
#endif
{
  __Pyx_TraceDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #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("PyMODINIT_FUNC PyInit_calignedsegment(void)", 0);
  if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("calignedsegment", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_pysam__calignedsegment) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "pysam.calignedsegment")) {
      if (unlikely(PyDict_SetItemString(modules, "pysam.calignedsegment", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  if (__Pyx_ExportFunction("makeAlignedSegment", (void (*)(void))__pyx_f_5pysam_15calignedsegment_makeAlignedSegment, "PyObject *(bam1_t *, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ExportFunction("makePileupColumn", (void (*)(void))__pyx_f_5pysam_15calignedsegment_makePileupColumn, "PyObject *(bam_pileup1_t **, int, int, int, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ExportFunction("makePileupRead", (void (*)(void))__pyx_f_5pysam_15calignedsegment_makePileupRead, "PyObject *(bam_pileup1_t *, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ExportFunction("get_alignment_length", (void (*)(void))__pyx_f_5pysam_15calignedsegment_get_alignment_length, "uint32_t (bam1_t *)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Type init code ---*/
  __pyx_vtabptr_5pysam_15calignedsegment_AlignedSegment = &__pyx_vtable_5pysam_15calignedsegment_AlignedSegment;
  __pyx_vtable_5pysam_15calignedsegment_AlignedSegment.set_tag = (PyObject *(*)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_set_tag *__pyx_optional_args))__pyx_f_5pysam_15calignedsegment_14AlignedSegment_set_tag;
  __pyx_vtable_5pysam_15calignedsegment_AlignedSegment.get_tag = (PyObject *(*)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_15calignedsegment_14AlignedSegment_get_tag *__pyx_optional_args))__pyx_f_5pysam_15calignedsegment_14AlignedSegment_get_tag;
  __pyx_vtable_5pysam_15calignedsegment_AlignedSegment.has_tag = (PyObject *(*)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, PyObject *, int __pyx_skip_dispatch))__pyx_f_5pysam_15calignedsegment_14AlignedSegment_has_tag;
  __pyx_vtable_5pysam_15calignedsegment_AlignedSegment.tostring = (PyObject *(*)(struct __pyx_obj_5pysam_15calignedsegment_AlignedSegment *, __pyx_t_5pysam_15calignedsegment_AlignmentFile_t, int __pyx_skip_dispatch))__pyx_f_5pysam_15calignedsegment_14AlignedSegment_tostring;
  if (PyType_Ready(&__pyx_type_5pysam_15calignedsegment_AlignedSegment) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_15calignedsegment_AlignedSegment.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_15calignedsegment_AlignedSegment, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_15calignedsegment_14AlignedSegment_4__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_15calignedsegment_14AlignedSegment_4__str__.doc = __pyx_doc_5pysam_15calignedsegment_14AlignedSegment_4__str__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_15calignedsegment_14AlignedSegment_4__str__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_15calignedsegment_AlignedSegment.tp_dict, __pyx_vtabptr_5pysam_15calignedsegment_AlignedSegment) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "AlignedSegment", (PyObject *)&__pyx_type_5pysam_15calignedsegment_AlignedSegment) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_15calignedsegment_AlignedSegment = &__pyx_type_5pysam_15calignedsegment_AlignedSegment;
  if (PyType_Ready(&__pyx_type_5pysam_15calignedsegment_PileupColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_15calignedsegment_PileupColumn.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "PileupColumn", (PyObject *)&__pyx_type_5pysam_15calignedsegment_PileupColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_15calignedsegment_PileupColumn = &__pyx_type_5pysam_15calignedsegment_PileupColumn;
  if (PyType_Ready(&__pyx_type_5pysam_15calignedsegment_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_15calignedsegment_PileupRead.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_15calignedsegment_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_15calignedsegment_PileupRead = &__pyx_type_5pysam_15calignedsegment_PileupRead;
  if (PyType_Ready(&__pyx_type_5pysam_15calignedsegment___pyx_scope_struct__genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_15calignedsegment___pyx_scope_struct__genexpr.tp_print = 0;
  __pyx_ptype_5pysam_15calignedsegment___pyx_scope_struct__genexpr = &__pyx_type_5pysam_15calignedsegment___pyx_scope_struct__genexpr;
  if (PyType_Ready(&__pyx_type_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr.tp_print = 0;
  __pyx_ptype_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_15calignedsegment___pyx_scope_struct_1_genexpr;
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastaFile = __Pyx_ImportType("pysam.cfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastaFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastaFile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastaFile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqProxy = __Pyx_ImportType("pysam.cfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastqProxy)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastqProxy = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastqProxy)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_PersistentFastqProxy = __Pyx_ImportType("pysam.cfaidx", "PersistentFastqProxy", sizeof(struct __pyx_obj_5pysam_6cfaidx_PersistentFastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_PersistentFastqProxy)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_PersistentFastqProxy = (struct __pyx_vtabstruct_5pysam_6cfaidx_PersistentFastqProxy*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_PersistentFastqProxy->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_PersistentFastqProxy)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastxFile = __Pyx_ImportType("pysam.cfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastxFile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastxFile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqFile = __Pyx_ImportType("pysam.cfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastqFile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastqFile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastafile = __Pyx_ImportType("pysam.cfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_AlignmentFile = __Pyx_ImportType("pysam.calignmentfile", "AlignmentFile", sizeof(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_AlignmentFile)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile = (struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_AlignmentFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_PileupColumn = __Pyx_ImportType("pysam.calignmentfile", "PileupColumn", sizeof(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_PileupColumn)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_PileupRead = __Pyx_ImportType("pysam.calignmentfile", "PileupRead", sizeof(struct __pyx_obj_5pysam_14calignmentfile_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_PileupRead)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRow = __Pyx_ImportType("pysam.calignmentfile", "IteratorRow", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRow), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRow)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowRegion", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowHead = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowHead", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowAll = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowAll", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowAllRefs", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection = __Pyx_ImportType("pysam.calignmentfile", "IteratorRowSelection", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumn = __Pyx_ImportType("pysam.calignmentfile", "IteratorColumn", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorColumn)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorColumn->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion = __Pyx_ImportType("pysam.calignmentfile", "IteratorColumnRegion", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs = __Pyx_ImportType("pysam.calignmentfile", "IteratorColumnAllRefs", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs*)__Pyx_GetVtable(__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IndexedReads = __Pyx_ImportType("pysam.calignmentfile", "IndexedReads", sizeof(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads), 1); if (unlikely(!__pyx_ptype_5pysam_14calignmentfile_IndexedReads)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  __pyx_t_1 = __Pyx_ImportModule("pysam.cutils"); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ImportFunction(__pyx_t_1, "qualitystring_to_array", (void (**)(void))&__pyx_f_5pysam_6cutils_qualitystring_to_array, "arrayobject *(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cutils_qualitystring_to_array *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ImportFunction(__pyx_t_1, "array_to_qualitystring", (void (**)(void))&__pyx_f_5pysam_6cutils_array_to_qualitystring, "PyObject *(arrayobject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cutils_array_to_qualitystring *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ImportFunction(__pyx_t_1, "qualities_to_qualitystring", (void (**)(void))&__pyx_f_5pysam_6cutils_qualities_to_qualitystring, "PyObject *(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_6cutils_qualities_to_qualitystring *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_str", (void (**)(void))&__pyx_f_5pysam_6cutils_charptr_to_str, "PyObject *(char const *, struct __pyx_opt_args_5pysam_6cutils_charptr_to_str *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ImportFunction(__pyx_t_1, "charptr_to_bytes", (void (**)(void))&__pyx_f_5pysam_6cutils_charptr_to_bytes, "PyObject *(char const *, struct __pyx_opt_args_5pysam_6cutils_charptr_to_bytes *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ImportFunction(__pyx_t_1, "force_str", (void (**)(void))&__pyx_f_5pysam_6cutils_force_str, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_6cutils_force_str *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__Pyx_ImportFunction(__pyx_t_1, "force_bytes", (void (**)(void))&__pyx_f_5pysam_6cutils_force_bytes, "PyObject *(PyObject *, struct __pyx_opt_args_5pysam_6cutils_force_bytes *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  __Pyx_TraceCall("PyMODINIT_FUNC PyInit_calignedsegment(void)", __pyx_f[0], 1, 0, {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;});

  /* "pysam/calignedsegment.pyx":56
 * #
 * ###############################################################################
 * import re             # <<<<<<<<<<<<<<
 * import array
 * import ctypes
 */
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":57
 * ###############################################################################
 * import re
 * import array             # <<<<<<<<<<<<<<
 * import ctypes
 * import struct
 */
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_array, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":58
 * import re
 * import array
 * import ctypes             # <<<<<<<<<<<<<<
 * import struct
 * 
 */
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_ctypes, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctypes, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":59
 * import array
 * import ctypes
 * import struct             # <<<<<<<<<<<<<<
 * 
 * cimport cython
 */
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_struct, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_struct, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":73
 * 
 * # Constants for binary tag conversion
 * cdef char * htslib_types = 'cCsSiIf'             # <<<<<<<<<<<<<<
 * cdef char * parray_types = 'bBhHiIf'
 * 
 */
  __pyx_v_5pysam_15calignedsegment_htslib_types = __pyx_k_cCsSiIf;

  /* "pysam/calignedsegment.pyx":74
 * # Constants for binary tag conversion
 * cdef char * htslib_types = 'cCsSiIf'
 * cdef char * parray_types = 'bBhHiIf'             # <<<<<<<<<<<<<<
 * 
 * # translation tables
 */
  __pyx_v_5pysam_15calignedsegment_parray_types = __pyx_k_bBhHiIf;

  /* "pysam/calignedsegment.pyx":79
 * 
 * # cigar code to character and vice versa
 * cdef char* CODE2CIGAR= "MIDNSHP=X"             # <<<<<<<<<<<<<<
 * 
 * if PY_MAJOR_VERSION >= 3:
 */
  __pyx_v_5pysam_15calignedsegment_CODE2CIGAR = __pyx_k_MIDNSHP_X;

  /* "pysam/calignedsegment.pyx":81
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * 
 * if PY_MAJOR_VERSION >= 3:             # <<<<<<<<<<<<<<
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))
 * else:
 */
  __pyx_t_3 = ((PY_MAJOR_VERSION >= 3) != 0);
  if (__pyx_t_3) {

    /* "pysam/calignedsegment.pyx":82
 * 
 * if PY_MAJOR_VERSION >= 3:
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))
 */
    __pyx_t_2 = __pyx_pf_5pysam_15calignedsegment_genexpr(NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyDict_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "pysam/calignedsegment.pyx":81
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * 
 * if PY_MAJOR_VERSION >= 3:             # <<<<<<<<<<<<<<
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))
 * else:
 */
    goto __pyx_L2;
  }

  /* "pysam/calignedsegment.pyx":84
 *     CIGAR2CODE = dict([y, x] for x, y in enumerate(CODE2CIGAR))
 * else:
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))             # <<<<<<<<<<<<<<
 * 
 * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=X])")
 */
  /*else*/ {
    __pyx_t_2 = __pyx_pf_5pysam_15calignedsegment_3genexpr(NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)(&PyDict_Type)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_L2:;

  /* "pysam/calignedsegment.pyx":86
 *     CIGAR2CODE = dict([ord(y), x] for x, y in enumerate(CODE2CIGAR))
 * 
 * CIGAR_REGEX = re.compile("(\d+)([MIDNSHP=X])")             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_compile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR_REGEX, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":2349
 *             return self._is_refskip
 * 
 * __all__ = [             # <<<<<<<<<<<<<<
 *     "AlignedSegment",
 *     "PileupColumn",
 */
  __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_AlignedSegment);
  __Pyx_GIVEREF(__pyx_n_s_AlignedSegment);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_AlignedSegment);
  __Pyx_INCREF(__pyx_n_s_PileupColumn);
  __Pyx_GIVEREF(__pyx_n_s_PileupColumn);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_PileupColumn);
  __Pyx_INCREF(__pyx_n_s_PileupRead);
  __Pyx_GIVEREF(__pyx_n_s_PileupRead);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_PileupRead);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignedsegment.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * # cython: profile=True
 * ###############################################################################
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

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

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init pysam.calignedsegment", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pysam.calignedsegment");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        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;
}

#if CYTHON_PROFILE
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    PyObject *type, *value, *traceback;
    int retval;
    PyThreadState* tstate = PyThreadState_GET();
    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
    }
    (*frame)->f_lineno = firstlineno;
    retval = 1;
    tstate->tracing++;
    tstate->use_tracing = 0;
    PyErr_Fetch(&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;
    tstate->use_tracing = (tstate->c_profilefunc ||
                           (CYTHON_TRACE && tstate->c_tracefunc));
    tstate->tracing--;
    if (retval) {
        PyErr_Restore(type, value, traceback);
        return tstate->use_tracing && 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) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyCodeObject *py_code = 0;
    #if PY_MAJOR_VERSION < 3
    py_funcname = PyString_FromString(funcname);
    py_srcfile = PyString_FromString(srcfile);
    #else
    py_funcname = PyUnicode_FromString(funcname);
    py_srcfile = PyUnicode_FromString(srcfile);
    #endif
    if (!py_funcname | !py_srcfile) goto bad;
    py_code = PyCode_New(
        0,
        #if PY_MAJOR_VERSION >= 3
        0,
        #endif
        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,*/
        firstlineno,
        __pyx_empty_bytes      /*PyObject *lnotab*/
    );
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return py_code;
}
#endif

#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #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 + 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 && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            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;
                    } 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;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                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;
                    } 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;
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            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

static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
   Py_ssize_t length;
   #if CYTHON_PEP393_ENABLED
   length = PyUnicode_GET_LENGTH(x);
   if (likely(length == 1)) {
       return PyUnicode_READ_CHAR(x, 0);
   }
   #else
   length = PyUnicode_GET_SIZE(x);
   if (likely(length == 1)) {
       return PyUnicode_AS_UNICODE(x)[0];
   }
   #if Py_UNICODE_SIZE == 2
   else if (PyUnicode_GET_SIZE(x) == 2) {
       Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
       if (high_val >= 0xD800 && high_val <= 0xDBFF) {
           Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
           if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
               return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
           }
       }
   }
   #endif
   #endif
   PyErr_Format(PyExc_ValueError,
                "only single character unicode strings can be converted to Py_UCS4, "
                "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
   return (Py_UCS4)-1;
}

static long __Pyx__PyObject_Ord(PyObject* c) {
    Py_ssize_t size;
    if (PyBytes_Check(c)) {
        size = PyBytes_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyBytes_AS_STRING(c)[0];
        }
#if PY_MAJOR_VERSION < 3
    } else if (PyUnicode_Check(c)) {
        return (long)__Pyx_PyUnicode_AsPy_UCS4(c);
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    } else if (PyByteArray_Check(c)) {
        size = PyByteArray_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyByteArray_AS_STRING(c)[0];
        }
#endif
    } else {
        PyErr_Format(PyExc_TypeError,
            "ord() expected string of length 1, but %.200s found", c->ob_type->tp_name);
        return (long)(Py_UCS4)-1;
    }
    PyErr_Format(PyExc_TypeError,
        "ord() expected a character, but string of length %zd found", size);
    return (long)(Py_UCS4)-1;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    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

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    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);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *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_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 PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        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 CYTHON_COMPILING_IN_PYPY
        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);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#endif
    __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(1);
    }
    #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
}

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    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

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

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);
}

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");
}

static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!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_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, 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_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, 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_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (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((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

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, CYTHON_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_CPYTHON
    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))
                    PyErr_Clear();
                else
                    goto bad;
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#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_COMPILING_IN_CPYTHON
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    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 = 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
}

#if !CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
    return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL);
}
#endif

static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
    long r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

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);
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    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(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && 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:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) {
            Py_RETURN_TRUE;
        } else {
            Py_RETURN_FALSE;
        }
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            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;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                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;
                    }
                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;
                    }
                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;
                    }
                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;
                    }
                #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
                default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ);
                #else
                default: Py_RETURN_FALSE;
                #endif
            }
        }
            if (a == b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            if ((double)a == (double)b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    return PyObject_RichCompare(op1, op2, Py_EQ);
}
#endif

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
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    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;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || 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;
                    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 = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    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
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(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;
        }
    }
    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:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    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;
        }
        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_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
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    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;
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

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);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        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);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    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;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

#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;\
    }

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    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;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                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
            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))
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                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))
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        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;
}

static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) {
    const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0;
    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;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint32_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint32_t, digit, digits[0])
                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
            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))
            } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint32_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(uint32_t, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(uint32_t,  digit, +digits[0])
                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))
            } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint32_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (uint32_t) -1;
        }
    } else {
        uint32_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint32_t) -1;
        val = __Pyx_PyInt_As_uint32_t(tmp);
        Py_DECREF(tmp);
        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;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    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);
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value) {
    const uint8_t neg_one = (uint8_t) -1, const_zero = (uint8_t) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint8_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint8_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint8_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(uint8_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint8_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint8_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
    const char neg_one = (char) -1, const_zero = (char) 0;
    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);
        } else if (sizeof(char) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(char) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(char) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(char),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
    const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0;
    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);
        } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(int32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int32_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
    const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0;
    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);
        } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(uint32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint32_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    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);
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) {
    const uint16_t neg_one = (uint16_t) -1, const_zero = (uint16_t) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint16_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(uint16_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint16_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *x) {
    const uint16_t neg_one = (uint16_t) -1, const_zero = (uint16_t) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint16_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint16_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint16_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint16_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint16_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(uint16_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint16_t) >= 2 * PyLong_SHIFT) {
                            return (uint16_t) (((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint16_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint16_t) >= 3 * PyLong_SHIFT) {
                            return (uint16_t) (((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint16_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_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(uint16_t) >= 4 * PyLong_SHIFT) {
                            return (uint16_t) (((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            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 (uint16_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(uint16_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint16_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(uint16_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint16_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint16_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(uint16_t, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(uint16_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(uint16_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint16_t) (((uint16_t)-1)*(((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(uint16_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint16_t) ((((((uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(uint16_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint16_t) (((uint16_t)-1)*(((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint16_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint16_t) ((((((((uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(uint16_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_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(uint16_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint16_t) (((uint16_t)-1)*(((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint16_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint16_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(uint16_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint16_t) ((((((((((uint16_t)digits[3]) << PyLong_SHIFT) | (uint16_t)digits[2]) << PyLong_SHIFT) | (uint16_t)digits[1]) << PyLong_SHIFT) | (uint16_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(uint16_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint16_t, long, PyLong_AsLong(x))
            } else if (sizeof(uint16_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint16_t, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint16_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (uint16_t) -1;
        }
    } else {
        uint16_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint16_t) -1;
        val = __Pyx_PyInt_As_uint16_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint16_t");
    return (uint16_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint16_t");
    return (uint16_t) -1;
}

static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
    const int32_t neg_one = (int32_t) -1, const_zero = (int32_t) 0;
    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;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int32_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int32_t, digit, digits[0])
                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
            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))
            } else if (sizeof(int32_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int32_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int32_t, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(int32_t,  digit, +digits[0])
                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))
            } else if (sizeof(int32_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int32_t, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int32_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int32_t) -1;
        }
    } else {
        int32_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int32_t) -1;
        val = __Pyx_PyInt_As_int32_t(tmp);
        Py_DECREF(tmp);
        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;
}

static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *x) {
    const uint8_t neg_one = (uint8_t) -1, const_zero = (uint8_t) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint8_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint8_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint8_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint8_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint8_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(uint8_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint8_t) >= 2 * PyLong_SHIFT) {
                            return (uint8_t) (((((uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint8_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint8_t) >= 3 * PyLong_SHIFT) {
                            return (uint8_t) (((((((uint8_t)digits[2]) << PyLong_SHIFT) | (uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint8_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_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(uint8_t) >= 4 * PyLong_SHIFT) {
                            return (uint8_t) (((((((((uint8_t)digits[3]) << PyLong_SHIFT) | (uint8_t)digits[2]) << PyLong_SHIFT) | (uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            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 (uint8_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(uint8_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint8_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(uint8_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint8_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (uint8_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(uint8_t, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(uint8_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(uint8_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint8_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint8_t) (((uint8_t)-1)*(((((uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(uint8_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint8_t) - 1 > 2 * PyLong_SHIFT) {
                            return (uint8_t) ((((((uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(uint8_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint8_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint8_t) (((uint8_t)-1)*(((((((uint8_t)digits[2]) << PyLong_SHIFT) | (uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(uint8_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(uint8_t) - 1 > 3 * PyLong_SHIFT) {
                            return (uint8_t) ((((((((uint8_t)digits[2]) << PyLong_SHIFT) | (uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(uint8_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_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(uint8_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint8_t) (((uint8_t)-1)*(((((((((uint8_t)digits[3]) << PyLong_SHIFT) | (uint8_t)digits[2]) << PyLong_SHIFT) | (uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(uint8_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(uint8_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(uint8_t) - 1 > 4 * PyLong_SHIFT) {
                            return (uint8_t) ((((((((((uint8_t)digits[3]) << PyLong_SHIFT) | (uint8_t)digits[2]) << PyLong_SHIFT) | (uint8_t)digits[1]) << PyLong_SHIFT) | (uint8_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(uint8_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint8_t, long, PyLong_AsLong(x))
            } else if (sizeof(uint8_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(uint8_t, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint8_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (uint8_t) -1;
        }
    } else {
        uint8_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint8_t) -1;
        val = __Pyx_PyInt_As_uint8_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint8_t");
    return (uint8_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint8_t");
    return (uint8_t) -1;
}

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    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;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                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
            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))
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                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))
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        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;
}

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    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;
#else
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
#endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            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);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
bad:
    Py_XDECREF(method);
    return result;
}

#include <structmember.h>
#include <frameobject.h>
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value);
static PyObject *__Pyx_Coroutine_Close(PyObject *self);
static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args);
#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
    PyObject *et, *ev, *tb;
    PyObject *value = NULL;
    __Pyx_ErrFetch(&et, &ev, &tb);
    if (!et) {
        Py_XDECREF(tb);
        Py_XDECREF(ev);
        Py_INCREF(Py_None);
        *pvalue = Py_None;
        return 0;
    }
    if (likely(et == PyExc_StopIteration)) {
#if PY_VERSION_HEX >= 0x030300A0
        if (ev && Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
            value = ((PyStopIterationObject *)ev)->value;
            Py_INCREF(value);
            Py_DECREF(ev);
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = value;
            return 0;
        }
#endif
        if (!ev || !PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
            if (!ev) {
                Py_INCREF(Py_None);
                ev = Py_None;
            } else if (PyTuple_Check(ev)) {
                if (PyTuple_GET_SIZE(ev) >= 1) {
                    PyObject *value;
#if CYTHON_COMPILING_IN_CPYTHON
                    value = PySequence_ITEM(ev, 0);
#else
                    value = PyTuple_GET_ITEM(ev, 0);
                    Py_INCREF(value);
#endif
                    Py_DECREF(ev);
                    ev = value;
                } else {
                    Py_INCREF(Py_None);
                    Py_DECREF(ev);
                    ev = Py_None;
                }
            }
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = ev;
            return 0;
        }
    } else if (!PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    PyErr_NormalizeException(&et, &ev, &tb);
    if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    Py_XDECREF(tb);
    Py_DECREF(et);
#if PY_VERSION_HEX >= 0x030300A0
    value = ((PyStopIterationObject *)ev)->value;
    Py_INCREF(value);
    Py_DECREF(ev);
#else
    {
        PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args);
        Py_DECREF(ev);
        if (likely(args)) {
            value = PySequence_GetItem(args, 0);
            Py_DECREF(args);
        }
        if (unlikely(!value)) {
            __Pyx_ErrRestore(NULL, NULL, NULL);
            Py_INCREF(Py_None);
            value = Py_None;
        }
    }
#endif
    *pvalue = value;
    return 0;
}
#endif
static CYTHON_INLINE
void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) {
    PyObject *exc_type = self->exc_type;
    PyObject *exc_value = self->exc_value;
    PyObject *exc_traceback = self->exc_traceback;
    self->exc_type = NULL;
    self->exc_value = NULL;
    self->exc_traceback = NULL;
    Py_XDECREF(exc_type);
    Py_XDECREF(exc_value);
    Py_XDECREF(exc_traceback);
}
static CYTHON_INLINE
int __Pyx_Coroutine_CheckRunning(__pyx_CoroutineObject *gen) {
    if (unlikely(gen->is_running)) {
        PyErr_SetString(PyExc_ValueError,
                        "generator already executing");
        return 1;
    }
    return 0;
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
    PyObject *retval;
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            PyErr_SetString(PyExc_TypeError,
                            "can't send non-None value to a "
                            "just-started generator");
            return NULL;
        }
    }
    if (unlikely(self->resume_label == -1)) {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    if (value) {
#if CYTHON_COMPILING_IN_PYPY
#else
        if (self->exc_traceback) {
            PyThreadState *tstate = PyThreadState_GET();
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_XINCREF(tstate->frame);
            assert(f->f_back == NULL);
            f->f_back = tstate->frame;
        }
#endif
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
    } else {
        __Pyx_Coroutine_ExceptionClear(self);
    }
    self->is_running = 1;
    retval = self->body((PyObject *) self, value);
    self->is_running = 0;
    if (retval) {
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
#if CYTHON_COMPILING_IN_PYPY
#else
        if (self->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_CLEAR(f->f_back);
        }
#endif
    } else {
        __Pyx_Coroutine_ExceptionClear(self);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_MethodReturn(PyObject *retval) {
    if (unlikely(!retval && !PyErr_Occurred())) {
        PyErr_SetNone(PyExc_StopIteration);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Coroutine_Undelegate(gen);
    __Pyx_PyGen_FetchStopIterationValue(&val);
    ret = __Pyx_Coroutine_SendEx(gen, val);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
    PyObject *retval;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        {
            if (value == Py_None)
                ret = PyIter_Next(yf);
            else
                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
        }
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        retval = __Pyx_Coroutine_FinishDelegation(gen);
    } else {
        retval = __Pyx_Coroutine_SendEx(gen, value);
    }
    return __Pyx_Coroutine_MethodReturn(retval);
}
static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
    PyObject *retval = NULL;
    int err = 0;
    #ifdef __Pyx_Generator_USED
    if (__Pyx_Generator_CheckExact(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    #endif
    #ifdef __Pyx_Coroutine_USED
    if (__Pyx_Coroutine_CheckExact(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    #endif
    {
        PyObject *meth;
        gen->is_running = 1;
        meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close);
        if (unlikely(!meth)) {
            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                PyErr_WriteUnraisable(yf);
            }
            PyErr_Clear();
        } else {
            retval = PyObject_CallFunction(meth, NULL);
            Py_DECREF(meth);
            if (!retval)
                err = -1;
        }
        gen->is_running = 0;
    }
    Py_XDECREF(retval);
    return err;
}
static PyObject *__Pyx_Generator_Next(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Coroutine_FinishDelegation(gen);
    }
    return __Pyx_Coroutine_SendEx(gen, Py_None);
}
static PyObject *__Pyx_Coroutine_Close(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Coroutine_CloseIter(gen, yf);
        __Pyx_Coroutine_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
        PyErr_SetNone(PyExc_GeneratorExit);
    retval = __Pyx_Coroutine_SendEx(gen, NULL);
    if (retval) {
        Py_DECREF(retval);
        PyErr_SetString(PyExc_RuntimeError,
                        "generator ignored GeneratorExit");
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (!raised_exception
        || raised_exception == PyExc_StopIteration
        || raised_exception == PyExc_GeneratorExit
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
    {
        if (raised_exception) PyErr_Clear();
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *typ;
    PyObject *tb = NULL;
    PyObject *val = NULL;
    PyObject *yf = gen->yieldfrom;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
            int err = __Pyx_Coroutine_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Coroutine_Undelegate(gen);
            if (err < 0)
                return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
            goto throw_here;
        }
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Throw(yf, args);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Throw(yf, args);
        } else
        #endif
        {
            PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw);
            if (unlikely(!meth)) {
                Py_DECREF(yf);
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                    gen->is_running = 0;
                    return NULL;
                }
                PyErr_Clear();
                __Pyx_Coroutine_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            ret = PyObject_CallObject(meth, args);
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Coroutine_FinishDelegation(gen);
        }
        return __Pyx_Coroutine_MethodReturn(ret);
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
}
static int __Pyx_Coroutine_traverse(PyObject *self, visitproc visit, void *arg) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    Py_VISIT(gen->exc_type);
    Py_VISIT(gen->exc_value);
    Py_VISIT(gen->exc_traceback);
    return 0;
}
static int __Pyx_Coroutine_clear(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    Py_CLEAR(gen->exc_type);
    Py_CLEAR(gen->exc_value);
    Py_CLEAR(gen->exc_traceback);
    Py_CLEAR(gen->gi_name);
    Py_CLEAR(gen->gi_qualname);
    return 0;
}
static void __Pyx_Coroutine_dealloc(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject_GC_UnTrack(gen);
    if (gen->gi_weakreflist != NULL)
        PyObject_ClearWeakRefs(self);
    if (gen->resume_label > 0) {
        PyObject_GC_Track(self);
#if PY_VERSION_HEX >= 0x030400a1
        if (PyObject_CallFinalizerFromDealloc(self))
#else
        Py_TYPE(gen)->tp_del(self);
        if (self->ob_refcnt > 0)
#endif
        {
            return;
        }
        PyObject_GC_UnTrack(self);
    }
    __Pyx_Coroutine_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Coroutine_del(PyObject *self) {
    PyObject *res;
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    if (gen->resume_label <= 0)
        return ;
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt == 0);
    self->ob_refcnt = 1;
#endif
    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
    res = __Pyx_Coroutine_Close(self);
    if (res == NULL)
        PyErr_WriteUnraisable(self);
    else
        Py_DECREF(res);
    __Pyx_ErrRestore(error_type, error_value, error_traceback);
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt > 0);
    if (--self->ob_refcnt == 0) {
        return;
    }
    {
        Py_ssize_t refcnt = self->ob_refcnt;
        _Py_NewReference(self);
        self->ob_refcnt = refcnt;
    }
#if CYTHON_COMPILING_IN_CPYTHON
    assert(PyType_IS_GC(self->ob_type) &&
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    _Py_DEC_REFTOTAL;
#endif
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
#endif
}
static PyObject *
__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self)
{
    Py_INCREF(self->gi_name);
    return self->gi_name;
}
static int
__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value)
{
    PyObject *tmp;
#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;
    }
    tmp = self->gi_name;
    Py_INCREF(value);
    self->gi_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
{
    Py_INCREF(self->gi_qualname);
    return self->gi_qualname;
}
static int
__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value)
{
    PyObject *tmp;
#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;
    }
    tmp = self->gi_qualname;
    Py_INCREF(value);
    self->gi_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static __pyx_CoroutineObject *__Pyx__Coroutine_New(PyTypeObject* type, __pyx_coroutine_body_t body,
                                                   PyObject *closure, PyObject *name, PyObject *qualname) {
    __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
    if (gen == NULL)
        return NULL;
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->exc_type = NULL;
    gen->exc_value = NULL;
    gen->exc_traceback = NULL;
    gen->gi_weakreflist = NULL;
    Py_XINCREF(qualname);
    gen->gi_qualname = qualname;
    Py_XINCREF(name);
    gen->gi_name = name;
    PyObject_GC_Track(gen);
    return gen;
}

static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    int result;
    PyObject *globals, *result_obj;
    globals = PyDict_New();  if (unlikely(!globals)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_coroutine_type",
    #ifdef __Pyx_Coroutine_USED
        (PyObject*)__pyx_CoroutineType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_generator_type",
    #ifdef __Pyx_Generator_USED
        (PyObject*)__pyx_GeneratorType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore;
    result_obj = PyRun_String(py_code, Py_file_input, globals, globals);
    if (unlikely(!result_obj)) goto ignore;
    Py_DECREF(result_obj);
    Py_DECREF(globals);
    return module;
ignore:
    Py_XDECREF(globals);
    PyErr_WriteUnraisable(module);
    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) {
        Py_DECREF(module);
        module = NULL;
    }
#else
    py_code++;
#endif
    return module;
}

#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
static PyObject* __Pyx_patch_abc_module(PyObject *module);
static PyObject* __Pyx_patch_abc_module(PyObject *module) {
    module = __Pyx_Coroutine_patch_module(
        module, ""
"if _cython_generator_type is not None:\n"
"    try: Generator = _module.Generator\n"
"    except AttributeError: pass\n"
"    else: Generator.register(_cython_generator_type)\n"
"if _cython_coroutine_type is not None:\n"
"    try: Coroutine = _module.Coroutine\n"
"    except AttributeError: pass\n"
"    else: Coroutine.register(_cython_coroutine_type)\n"
    );
    return module;
}
#endif
static int __Pyx_patch_abc(void) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    static int abc_patched = 0;
    if (!abc_patched) {
        PyObject *module;
        module = PyImport_ImportModule((PY_VERSION_HEX >= 0x03030000) ? "collections.abc" : "collections");
        if (!module) {
            PyErr_WriteUnraisable(NULL);
            if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning,
                    ((PY_VERSION_HEX >= 0x03030000) ?
                        "Cython module failed to register with collections.abc module" :
                        "Cython module failed to register with collections module"), 1) < 0)) {
                return -1;
            }
        } else {
            module = __Pyx_patch_abc_module(module);
            abc_patched = 1;
            if (unlikely(!module))
                return -1;
            Py_DECREF(module);
        }
        module = PyImport_ImportModule("backports_abc");
        if (module) {
            module = __Pyx_patch_abc_module(module);
            Py_XDECREF(module);
        }
        if (!module) {
            PyErr_Clear();
        }
    }
#else
    if (0) __Pyx_Coroutine_patch_module(NULL, NULL);
#endif
    return 0;
}

static PyMethodDef __pyx_Generator_methods[] = {
    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
     (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
    {"close", (PyCFunction) __Pyx_Coroutine_Close, METH_NOARGS,
     (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
    {0, 0, 0, 0}
};
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
    {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
     (char*) PyDoc_STR("object being iterated by 'yield from', or None")},
    {0, 0, 0, 0, 0}
};
static PyGetSetDef __pyx_Generator_getsets[] = {
    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
     (char*) PyDoc_STR("name of the generator"), 0},
    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
     (char*) PyDoc_STR("qualified name of the generator"), 0},
    {0, 0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "generator",
    sizeof(__pyx_CoroutineObject),
    0,
    (destructor) __Pyx_Coroutine_dealloc,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
    0,
    (traverseproc) __Pyx_Coroutine_traverse,
    0,
    0,
    offsetof(__pyx_CoroutineObject, gi_weakreflist),
    0,
    (iternextfunc) __Pyx_Generator_Next,
    __pyx_Generator_methods,
    __pyx_Generator_memberlist,
    __pyx_Generator_getsets,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#else
    __Pyx_Coroutine_del,
#endif
    0,
#if PY_VERSION_HEX >= 0x030400a1
    __Pyx_Coroutine_del,
#endif
};
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
    if (unlikely(!__pyx_GeneratorType)) {
        return -1;
    }
    return 0;
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
    if (!d) {
        PyErr_Clear();
        d = PyDict_New();
        if (!d)
            goto bad;
        Py_INCREF(d);
        if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
            goto bad;
    }
    tmp.fp = f;
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(tmp.p, sig, 0);
#else
    cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#endif
    if (!cobj)
        goto bad;
    if (PyDict_SetItemString(d, name, cobj) < 0)
        goto bad;
    Py_DECREF(cobj);
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(cobj);
    Py_XDECREF(d);
    return -1;
}

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    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;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#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;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility",
            module_name, class_name);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(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 PY_VERSION_HEX >= 0x02070000
    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);
#else
    {const char *desc, *s1, *s2;
    desc = (const char *)PyCObject_GetDesc(cobj);
    if (!desc)
        goto bad;
    s1 = desc; s2 = sig;
    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
    if (*s1 != *s2) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, desc);
        goto bad;
    }
    tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
    *f = tmp.fp;
    if (!(*f))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        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);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__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)) {
#if PY_VERSION_HEX < 0x03030000
        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
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (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
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (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 PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  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(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      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 PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
