# 1 "hg_main.c"
# 1 "/root/mountpoint-genprog/genprog-many-bugs/valgrind-bug-11623-11624/valgrind/helgrind//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "hg_main.c"
# 39 "hg_main.c"
# 1 "../include/pub_tool_basics.h" 1
# 47 "../include/pub_tool_basics.h"
# 1 "../VEX/pub/libvex_basictypes.h" 1
# 44 "../VEX/pub/libvex_basictypes.h"
typedef unsigned char UChar;
typedef signed char Char;
typedef char HChar;




typedef unsigned short UShort;
typedef signed short Short;


typedef unsigned int UInt;
typedef signed int Int;


typedef unsigned long long int ULong;
typedef signed long long int Long;


typedef UInt U128[4];


typedef
   union {
      UChar w8[16];
      UShort w16[8];
      UInt w32[4];
      ULong w64[2];
   }
   V128;


typedef float Float;
typedef double Double;


typedef unsigned char Bool;






static inline Bool toBool ( Int x ) {
   Int r = (x == 0) ? ((Bool)0) : ((Bool)1);
   return (Bool)r;
}
static inline UChar toUChar ( Int x ) {
   x &= 0xFF;
   return (UChar)x;
}
static inline HChar toHChar ( Int x ) {
   x &= 0xFF;
   return (HChar)x;
}
static inline UShort toUShort ( Int x ) {
   x &= 0xFFFF;
   return (UShort)x;
}
static inline Short toShort ( Int x ) {
   x &= 0xFFFF;
   return (Short)x;
}
static inline UInt toUInt ( Long x ) {
   x &= 0xFFFFFFFFLL;
   return (UInt)x;
}


typedef UInt Addr32;
typedef ULong Addr64;





typedef unsigned long HWord;
# 170 "../VEX/pub/libvex_basictypes.h"
   static inline ULong Ptr_to_ULong ( void* p ) {
      UInt w = (UInt)p;
      return (ULong)w;
   }
   static inline void* ULong_to_Ptr ( ULong n ) {
      UInt w = (UInt)n;
      return (void*)w;
   }
# 48 "../include/pub_tool_basics.h" 2


# 1 "/usr/lib/gcc/i686-redhat-linux/4.4.5/include/stdarg.h" 1 3 4
# 40 "/usr/lib/gcc/i686-redhat-linux/4.4.5/include/stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 102 "/usr/lib/gcc/i686-redhat-linux/4.4.5/include/stdarg.h" 3 4
typedef __gnuc_va_list va_list;
# 51 "../include/pub_tool_basics.h" 2
# 86 "../include/pub_tool_basics.h"
typedef unsigned long UWord;
typedef signed long Word;





typedef UWord Addr;
typedef UWord AddrH;




typedef UWord SizeT;
typedef Word SSizeT;





typedef Word PtrdiffT;
# 115 "../include/pub_tool_basics.h"
typedef Word OffT;





typedef Long Off64T;






typedef struct { UWord uw1; UWord uw2; } UWordPair;
# 139 "../include/pub_tool_basics.h"
typedef UInt ThreadId;
# 177 "../include/pub_tool_basics.h"
typedef
   struct {
      UWord _val;
      Bool _isError;
   }
   SysRes;
# 216 "../include/pub_tool_basics.h"
static inline Bool sr_isError ( SysRes sr ) {
   return sr._isError;
}
static inline UWord sr_Res ( SysRes sr ) {
   return sr._isError ? 0 : sr._val;
}
static inline UWord sr_ResHI ( SysRes sr ) {
   return 0;
}
static inline UWord sr_Err ( SysRes sr ) {
   return sr._isError ? sr._val : 0;
}
static inline Bool sr_EQ ( SysRes sr1, SysRes sr2 ) {
   return sr1._val == sr2._val
          && ((sr1._isError && sr2._isError)
              || (!sr1._isError && !sr2._isError));
}
# 40 "hg_main.c" 2
# 1 "../include/pub_tool_libcassert.h" 1
# 50 "../include/pub_tool_libcassert.h"
__attribute__ ((__noreturn__))
extern void vgPlain_exit( Int status );


__attribute__ ((__noreturn__))
extern void vgPlain_tool_panic ( Char* str );

__attribute__ ((__noreturn__))
extern void vgPlain_assert_fail ( Bool isCore, const Char* expr, const Char* file,
                               Int line, const Char* fn,
                               const HChar* format, ... );
# 41 "hg_main.c" 2
# 1 "../include/pub_tool_libcbase.h" 1
# 38 "../include/pub_tool_libcbase.h"
extern Bool vgPlain_isspace ( Char c );
extern Bool vgPlain_isdigit ( Char c );
extern Char vgPlain_tolower ( Char c );
# 64 "../include/pub_tool_libcbase.h"
extern Long vgPlain_strtoll10 ( Char* str, Char** endptr );
extern Long vgPlain_strtoll16 ( Char* str, Char** endptr );





extern double vgPlain_strtod ( Char* str, Char** endptr );
# 83 "../include/pub_tool_libcbase.h"
extern SizeT vgPlain_strlen ( const Char* str );
extern Char* vgPlain_strcat ( Char* dest, const Char* src );
extern Char* vgPlain_strncat ( Char* dest, const Char* src, SizeT n );
extern Char* vgPlain_strpbrk ( const Char* s, const Char* accpt );
extern Char* vgPlain_strcpy ( Char* dest, const Char* src );
extern Char* vgPlain_strncpy ( Char* dest, const Char* src, SizeT ndest );
extern Int vgPlain_strcmp ( const Char* s1, const Char* s2 );
extern Int vgPlain_strcasecmp ( const Char* s1, const Char* s2 );
extern Int vgPlain_strncmp ( const Char* s1, const Char* s2, SizeT nmax );
extern Int vgPlain_strncasecmp ( const Char* s1, const Char* s2, SizeT nmax );
extern Char* vgPlain_strstr ( const Char* haystack, Char* needle );
extern Char* vgPlain_strcasestr ( const Char* haystack, Char* needle );
extern Char* vgPlain_strchr ( const Char* s, Char c );
extern Char* vgPlain_strrchr ( const Char* s, Char c );
extern SizeT vgPlain_strspn ( const Char* s, const Char* accpt );
extern SizeT vgPlain_strcspn ( const Char* s, const char* reject );



extern void vgPlain_strncpy_safely ( Char* dest, const Char* src, SizeT ndest );





extern void* vgPlain_memcpy ( void *d, const void *s, SizeT sz );
extern void* vgPlain_memmove( void *d, const void *s, SizeT sz );
extern void* vgPlain_memset ( void *s, Int c, SizeT sz );
extern Int vgPlain_memcmp ( const void* s1, const void* s2, SizeT n );





inline __attribute__((always_inline))
static void vgPlain_bzero_inline ( void* s, SizeT sz )
{
   if (__builtin_expect(!!(0 == (((Addr)sz) & (Addr)(sizeof(UWord)-1))), 1)
       && __builtin_expect(!!(0 == (((Addr)s) & (Addr)(sizeof(UWord)-1))), 1)) {
      UWord* p = (UWord*)s;
      switch (sz / (SizeT)sizeof(UWord)) {
          case 8: p[0] = p[1] = p[2] = p[3]
                  = p[4] = p[5] = p[6] = p[7] = 0UL; return;
          case 7: p[0] = p[1] = p[2] = p[3]
                  = p[4] = p[5] = p[6] = 0UL; return;
          case 6: p[0] = p[1] = p[2] = p[3]
                  = p[4] = p[5] = 0UL; return;
          case 5: p[0] = p[1] = p[2] = p[3] = p[4] = 0UL; return;
          case 4: p[0] = p[1] = p[2] = p[3] = 0UL; return;
          case 3: p[0] = p[1] = p[2] = 0UL; return;
          case 2: p[0] = p[1] = 0UL; return;
          case 1: p[0] = 0UL; return;
          case 0: return;
          default: break;
      }
   }
   vgPlain_memset(s, 0, sz);
}
# 169 "../include/pub_tool_libcbase.h"
extern void vgPlain_ssort( void* base, SizeT nmemb, SizeT size,
                        Int (*compar)(void*, void*) );



extern Int vgPlain_log2 ( UInt x );




extern UInt vgPlain_random ( UInt* pSeed );
# 42 "hg_main.c" 2
# 1 "../include/pub_tool_libcprint.h" 1
# 38 "../include/pub_tool_libcprint.h"
extern UInt vgPlain_sprintf ( Char* buf, const HChar* format, ... )
                          __attribute__((format(__printf__, 2, 3)));

extern UInt vgPlain_vsprintf ( Char* buf, const HChar* format, va_list vargs )
                          __attribute__((format(__printf__, 2, 0)));

extern UInt vgPlain_snprintf ( Char* buf, Int size,
                                       const HChar *format, ... )
                          __attribute__((format(__printf__, 3, 4)));

extern UInt vgPlain_vsnprintf( Char* buf, Int size,
                                       const HChar *format, va_list vargs )
                          __attribute__((format(__printf__, 3, 0)));



extern void vgPlain_percentify(ULong n, ULong m, UInt d, Int n_buf, char buf[]);
# 73 "../include/pub_tool_libcprint.h"
typedef
   enum {
      Vg_FailMsg,
      Vg_UserMsg,
      Vg_DebugMsg,
      Vg_ClientMsg
   }
   VgMsgKind;



extern UInt vgPlain_printf ( const HChar *format, ... )
                          __attribute__((format(__printf__, 1, 2)));
extern UInt vgPlain_vprintf ( const HChar *format, va_list vargs )
                          __attribute__((format(__printf__, 1, 0)));
# 96 "../include/pub_tool_libcprint.h"
extern UInt vgPlain_printf_xml ( const HChar *format, ... )
                             __attribute__((format(__printf__, 1, 2)));

extern UInt vgPlain_vprintf_xml ( const HChar *format, va_list vargs )
                             __attribute__((format(__printf__, 1, 0)));

extern UInt vgPlain_printf_xml_no_f_c ( const HChar *format, ... );



extern void vgPlain_vcbprintf( void(*char_sink)(HChar, void* opaque),
                            void* opaque,
                            const HChar* format, va_list vargs );

extern UInt vgPlain_message_no_f_c( VgMsgKind kind, const HChar* format, ... );
extern UInt vgPlain_message( VgMsgKind kind, const HChar* format, ... )
   __attribute__((format(__printf__, 2, 3)));

extern UInt vgPlain_vmessage( VgMsgKind kind, const HChar* format, va_list vargs )
   __attribute__((format(__printf__, 2, 0)));





extern UInt vgPlain_fmsg( const HChar* format, ... ) __attribute__((format(__printf__, 1, 2)));






__attribute__((noreturn))
extern void vgPlain_fmsg_bad_option ( HChar* opt, const HChar* format, ... )
   __attribute__((format(__printf__, 2, 3)));




extern UInt vgPlain_umsg( const HChar* format, ... ) __attribute__((format(__printf__, 1, 2)));


extern UInt vgPlain_dmsg( const HChar* format, ... ) __attribute__((format(__printf__, 1, 2)));


extern void vgPlain_message_flush ( void );
# 43 "hg_main.c" 2
# 1 "../include/pub_tool_threadstate.h" 1
# 47 "../include/pub_tool_threadstate.h"
extern ThreadId vgPlain_get_running_tid ( void );
# 44 "hg_main.c" 2
# 1 "../include/pub_tool_tooliface.h" 1
# 34 "../include/pub_tool_tooliface.h"
# 1 "../include/pub_tool_errormgr.h" 1
# 34 "../include/pub_tool_errormgr.h"
# 1 "../include/pub_tool_execontext.h" 1
# 34 "../include/pub_tool_execontext.h"
typedef
   struct _ExeContext
   ExeContext;



typedef
   enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
   VgRes;
# 60 "../include/pub_tool_execontext.h"
extern
ExeContext* vgPlain_record_ExeContext ( ThreadId tid, Word first_ip_delta );







extern
ExeContext* vgPlain_record_depth_1_ExeContext( ThreadId tid );




extern void vgPlain_apply_ExeContext( void(*action)(UInt n, Addr ip),
                                   ExeContext* ec, UInt n_ips );





extern Bool vgPlain_eq_ExeContext ( VgRes res, ExeContext* e1, ExeContext* e2 );


extern void vgPlain_pp_ExeContext ( ExeContext* ec );





extern UInt vgPlain_get_ECU_from_ExeContext( ExeContext* e );


extern Int vgPlain_get_ExeContext_n_ips( ExeContext* e );



extern ExeContext* vgPlain_get_ExeContext_from_ECU( UInt uniq );


ExeContext* vgPlain_make_depth_1_ExeContext_from_Addr( Addr a );




static inline Bool vgPlain_is_plausible_ECU( UInt ecu ) {
   return (ecu > 0) && ((ecu & 3) == 0);
}


ExeContext* vgPlain_make_ExeContext_from_StackTrace( Addr* ips, UInt n_ips );
# 35 "../include/pub_tool_errormgr.h" 2
# 43 "../include/pub_tool_errormgr.h"
typedef
   Int
   ErrorKind;







typedef
   struct _Error
   Error;



ExeContext* vgPlain_get_error_where ( Error* err );
ErrorKind vgPlain_get_error_kind ( Error* err );
Addr vgPlain_get_error_address ( Error* err );
Char* vgPlain_get_error_string ( Error* err );
void* vgPlain_get_error_extra ( Error* err );
# 75 "../include/pub_tool_errormgr.h"
extern void vgPlain_maybe_record_error ( ThreadId tid, ErrorKind ekind,
                                      Addr a, Char* s, void* extra );
# 85 "../include/pub_tool_errormgr.h"
extern Bool vgPlain_unique_error ( ThreadId tid, ErrorKind ekind,
                                Addr a, Char* s, void* extra,
                                ExeContext* where, Bool print_error,
                                Bool allow_GDB_attach, Bool count_error );
# 97 "../include/pub_tool_errormgr.h"
extern Bool vgPlain_get_line ( Int fd, Char** bufpp, SizeT* nBufp, Int* lineno );
# 107 "../include/pub_tool_errormgr.h"
typedef
   Int
   SuppKind;






typedef
   struct _Supp
   Supp;


SuppKind vgPlain_get_supp_kind ( Supp* su );
Char* vgPlain_get_supp_string ( Supp* su );
void* vgPlain_get_supp_extra ( Supp* su );


void vgPlain_set_supp_kind ( Supp* su, SuppKind suppkind );

void vgPlain_set_supp_string ( Supp* su, Char* string );
void vgPlain_set_supp_extra ( Supp* su, void* extra );
# 35 "../include/pub_tool_tooliface.h" 2
# 1 "../VEX/pub/libvex.h" 1
# 40 "../VEX/pub/libvex.h"
# 1 "../VEX/pub/libvex_basictypes.h" 1
# 41 "../VEX/pub/libvex.h" 2
# 1 "../VEX/pub/libvex_ir.h" 1
# 219 "../VEX/pub/libvex_ir.h"
typedef
   enum {
      Ity_INVALID=0x11000,
      Ity_I1,
      Ity_I8,
      Ity_I16,
      Ity_I32,
      Ity_I64,
      Ity_I128,
      Ity_F32,
      Ity_F64,
      Ity_F128,
      Ity_V128
   }
   IRType;


extern void ppIRType ( IRType );


extern Int sizeofIRType ( IRType );





typedef
   enum {
      Iend_LE=0x12000,
      Iend_BE
   }
   IREndness;







typedef
   enum {
      Ico_U1=0x13000,
      Ico_U8,
      Ico_U16,
      Ico_U32,
      Ico_U64,
      Ico_F32,
      Ico_F32i,

      Ico_F64,
      Ico_F64i,

      Ico_V128

   }
   IRConstTag;





typedef
   struct _IRConst {
      IRConstTag tag;
      union {
         Bool U1;
         UChar U8;
         UShort U16;
         UInt U32;
         ULong U64;
         Float F32;
         UInt F32i;
         Double F64;
         ULong F64i;
         UShort V128;
      } Ico;
   }
   IRConst;


extern IRConst* IRConst_U1 ( Bool );
extern IRConst* IRConst_U8 ( UChar );
extern IRConst* IRConst_U16 ( UShort );
extern IRConst* IRConst_U32 ( UInt );
extern IRConst* IRConst_U64 ( ULong );
extern IRConst* IRConst_F32 ( Float );
extern IRConst* IRConst_F32i ( UInt );
extern IRConst* IRConst_F64 ( Double );
extern IRConst* IRConst_F64i ( ULong );
extern IRConst* IRConst_V128 ( UShort );


extern IRConst* deepCopyIRConst ( IRConst* );


extern void ppIRConst ( IRConst* );


extern Bool eqIRConst ( IRConst*, IRConst* );
# 336 "../VEX/pub/libvex_ir.h"
typedef
   struct {
      Int regparms;
      HChar* name;
      void* addr;
      UInt mcx_mask;
   }
   IRCallee;


extern IRCallee* mkIRCallee ( Int regparms, HChar* name, void* addr );


extern IRCallee* deepCopyIRCallee ( IRCallee* );


extern void ppIRCallee ( IRCallee* );







typedef
   struct {
      Int base;
      IRType elemTy;
      Int nElems;
   }
   IRRegArray;

extern IRRegArray* mkIRRegArray ( Int, IRType, Int );

extern IRRegArray* deepCopyIRRegArray ( IRRegArray* );

extern void ppIRRegArray ( IRRegArray* );
extern Bool eqIRRegArray ( IRRegArray*, IRRegArray* );







typedef UInt IRTemp;


extern void ppIRTemp ( IRTemp );
# 401 "../VEX/pub/libvex_ir.h"
typedef
   enum {



      Iop_INVALID=0x14000,
      Iop_Add8, Iop_Add16, Iop_Add32, Iop_Add64,
      Iop_Sub8, Iop_Sub16, Iop_Sub32, Iop_Sub64,

      Iop_Mul8, Iop_Mul16, Iop_Mul32, Iop_Mul64,
      Iop_Or8, Iop_Or16, Iop_Or32, Iop_Or64,
      Iop_And8, Iop_And16, Iop_And32, Iop_And64,
      Iop_Xor8, Iop_Xor16, Iop_Xor32, Iop_Xor64,
      Iop_Shl8, Iop_Shl16, Iop_Shl32, Iop_Shl64,
      Iop_Shr8, Iop_Shr16, Iop_Shr32, Iop_Shr64,
      Iop_Sar8, Iop_Sar16, Iop_Sar32, Iop_Sar64,

      Iop_CmpEQ8, Iop_CmpEQ16, Iop_CmpEQ32, Iop_CmpEQ64,
      Iop_CmpNE8, Iop_CmpNE16, Iop_CmpNE32, Iop_CmpNE64,

      Iop_Not8, Iop_Not16, Iop_Not32, Iop_Not64,






      Iop_CasCmpEQ8, Iop_CasCmpEQ16, Iop_CasCmpEQ32, Iop_CasCmpEQ64,
      Iop_CasCmpNE8, Iop_CasCmpNE16, Iop_CasCmpNE32, Iop_CasCmpNE64,




      Iop_MullS8, Iop_MullS16, Iop_MullS32, Iop_MullS64,
      Iop_MullU8, Iop_MullU16, Iop_MullU32, Iop_MullU64,


      Iop_Clz64, Iop_Clz32,
      Iop_Ctz64, Iop_Ctz32,





      Iop_CmpLT32S, Iop_CmpLT64S,
      Iop_CmpLE32S, Iop_CmpLE64S,
      Iop_CmpLT32U, Iop_CmpLT64U,
      Iop_CmpLE32U, Iop_CmpLE64U,


      Iop_CmpNEZ8, Iop_CmpNEZ16, Iop_CmpNEZ32, Iop_CmpNEZ64,
      Iop_CmpwNEZ32, Iop_CmpwNEZ64,
      Iop_Left8, Iop_Left16, Iop_Left32, Iop_Left64,
      Iop_Max32U,







      Iop_CmpORD32U, Iop_CmpORD64U,
      Iop_CmpORD32S, Iop_CmpORD64S,



      Iop_DivU32,
      Iop_DivS32,
      Iop_DivU64,
      Iop_DivS64,

      Iop_DivModU64to32,

      Iop_DivModS64to32,

      Iop_DivModU128to64,

      Iop_DivModS128to64,

      Iop_DivModS64to64,
# 489 "../VEX/pub/libvex_ir.h"
      Iop_8Uto16, Iop_8Uto32, Iop_8Uto64,
                  Iop_16Uto32, Iop_16Uto64,
                               Iop_32Uto64,
      Iop_8Sto16, Iop_8Sto32, Iop_8Sto64,
                  Iop_16Sto32, Iop_16Sto64,
                               Iop_32Sto64,


      Iop_64to8, Iop_32to8, Iop_64to16,

      Iop_16to8,
      Iop_16HIto8,
      Iop_8HLto16,

      Iop_32to16,
      Iop_32HIto16,
      Iop_16HLto32,

      Iop_64to32,
      Iop_64HIto32,
      Iop_32HLto64,

      Iop_128to64,
      Iop_128HIto64,
      Iop_64HLto128,

      Iop_Not1,
      Iop_32to1,
      Iop_64to1,
      Iop_1Uto8,
      Iop_1Uto32,
      Iop_1Uto64,
      Iop_1Sto8,
      Iop_1Sto16,
      Iop_1Sto32,
      Iop_1Sto64,







      Iop_AddF64, Iop_SubF64, Iop_MulF64, Iop_DivF64,


      Iop_AddF32, Iop_SubF32, Iop_MulF32, Iop_DivF32,




      Iop_AddF64r32, Iop_SubF64r32, Iop_MulF64r32, Iop_DivF64r32,



      Iop_NegF64, Iop_AbsF64,


      Iop_NegF32, Iop_AbsF32,



      Iop_SqrtF64, Iop_SqrtF64r32,


      Iop_SqrtF32,
# 565 "../VEX/pub/libvex_ir.h"
      Iop_CmpF64,
      Iop_CmpF32,
      Iop_CmpF128,
# 610 "../VEX/pub/libvex_ir.h"
      Iop_F64toI16S,
      Iop_F64toI32S,
      Iop_F64toI64S,

      Iop_F64toI32U,

      Iop_I16StoF64,
      Iop_I32StoF64,
      Iop_I64StoF64,

      Iop_I32UtoF64,

      Iop_F32toI16S,
      Iop_F32toI32S,
      Iop_F32toI64S,

      Iop_I16StoF32,
      Iop_I32StoF32,
      Iop_I64StoF32,


      Iop_F32toF64,
      Iop_F64toF32,



      Iop_ReinterpF64asI64, Iop_ReinterpI64asF64,
      Iop_ReinterpF32asI32, Iop_ReinterpI32asF32,


      Iop_F64HLtoF128,
      Iop_F128HItoF64,
      Iop_F128LOtoF64,


      Iop_AddF128, Iop_SubF128, Iop_MulF128, Iop_DivF128,


      Iop_NegF128, Iop_AbsF128,


      Iop_SqrtF128,

      Iop_I32StoF128,
      Iop_I64StoF128,
      Iop_F32toF128,
      Iop_F64toF128,

      Iop_F128toI32S,
      Iop_F128toI64S,
      Iop_F128toF64,
      Iop_F128toF32,





      Iop_AtanF64,
      Iop_Yl2xF64,
      Iop_Yl2xp1F64,
      Iop_PRemF64,
      Iop_PRemC3210F64,
      Iop_PRem1F64,
      Iop_PRem1C3210F64,
      Iop_ScaleF64,






      Iop_SinF64,
      Iop_CosF64,
      Iop_TanF64,
      Iop_2xm1F64,
      Iop_RoundF64toInt,

      Iop_RoundF32toInt,







      Iop_MAddF32, Iop_MSubF32,
# 705 "../VEX/pub/libvex_ir.h"
      Iop_MAddF64, Iop_MSubF64,




      Iop_MAddF64r32, Iop_MSubF64r32,


      Iop_Est5FRSqrt,
      Iop_RoundF64toF64_NEAREST,
      Iop_RoundF64toF64_NegINF,
      Iop_RoundF64toF64_PosINF,
      Iop_RoundF64toF64_ZERO,


      Iop_TruncF64asF32,


      Iop_RoundF64toF32,




      Iop_CalcFPRF,





      Iop_Add16x2, Iop_Sub16x2,
      Iop_QAdd16Sx2, Iop_QAdd16Ux2,
      Iop_QSub16Sx2, Iop_QSub16Ux2,




      Iop_HAdd16Ux2, Iop_HAdd16Sx2,
      Iop_HSub16Ux2, Iop_HSub16Sx2,


      Iop_Add8x4, Iop_Sub8x4,
      Iop_QAdd8Sx4, Iop_QAdd8Ux4,
      Iop_QSub8Sx4, Iop_QSub8Ux4,




      Iop_HAdd8Ux4, Iop_HAdd8Sx4,
      Iop_HSub8Ux4, Iop_HSub8Sx4,


      Iop_Sad8Ux4,


      Iop_CmpNEZ16x2, Iop_CmpNEZ8x4,




      Iop_I32UtoFx2, Iop_I32StoFx2,
      Iop_FtoI32Ux2_RZ, Iop_FtoI32Sx2_RZ,



      Iop_F32ToFixed32Ux2_RZ, Iop_F32ToFixed32Sx2_RZ,
      Iop_Fixed32UToF32x2_RN, Iop_Fixed32SToF32x2_RN,


      Iop_Max32Fx2, Iop_Min32Fx2,


      Iop_PwMax32Fx2, Iop_PwMin32Fx2,


      Iop_CmpEQ32Fx2, Iop_CmpGT32Fx2, Iop_CmpGE32Fx2,




      Iop_Recip32Fx2,




      Iop_Recps32Fx2,



      Iop_Rsqrte32Fx2,




      Iop_Rsqrts32Fx2,


      Iop_Neg32Fx2, Iop_Abs32Fx2,




      Iop_CmpNEZ8x8, Iop_CmpNEZ16x4, Iop_CmpNEZ32x2,


      Iop_Add8x8, Iop_Add16x4, Iop_Add32x2,
      Iop_QAdd8Ux8, Iop_QAdd16Ux4, Iop_QAdd32Ux2, Iop_QAdd64Ux1,
      Iop_QAdd8Sx8, Iop_QAdd16Sx4, Iop_QAdd32Sx2, Iop_QAdd64Sx1,




      Iop_PwAdd8x8, Iop_PwAdd16x4, Iop_PwAdd32x2,
      Iop_PwMax8Sx8, Iop_PwMax16Sx4, Iop_PwMax32Sx2,
      Iop_PwMax8Ux8, Iop_PwMax16Ux4, Iop_PwMax32Ux2,
      Iop_PwMin8Sx8, Iop_PwMin16Sx4, Iop_PwMin32Sx2,
      Iop_PwMin8Ux8, Iop_PwMin16Ux4, Iop_PwMin32Ux2,





      Iop_PwAddL8Ux8, Iop_PwAddL16Ux4, Iop_PwAddL32Ux2,
      Iop_PwAddL8Sx8, Iop_PwAddL16Sx4, Iop_PwAddL32Sx2,


      Iop_Sub8x8, Iop_Sub16x4, Iop_Sub32x2,
      Iop_QSub8Ux8, Iop_QSub16Ux4, Iop_QSub32Ux2, Iop_QSub64Ux1,
      Iop_QSub8Sx8, Iop_QSub16Sx4, Iop_QSub32Sx2, Iop_QSub64Sx1,


      Iop_Abs8x8, Iop_Abs16x4, Iop_Abs32x2,


      Iop_Mul8x8, Iop_Mul16x4, Iop_Mul32x2,
      Iop_Mul32Fx2,
      Iop_MulHi16Ux4,
      Iop_MulHi16Sx4,


      Iop_PolynomialMul8x8,







      Iop_QDMulHi16Sx4, Iop_QDMulHi32Sx2,
      Iop_QRDMulHi16Sx4, Iop_QRDMulHi32Sx2,


      Iop_Avg8Ux8,
      Iop_Avg16Ux4,


      Iop_Max8Sx8, Iop_Max16Sx4, Iop_Max32Sx2,
      Iop_Max8Ux8, Iop_Max16Ux4, Iop_Max32Ux2,
      Iop_Min8Sx8, Iop_Min16Sx4, Iop_Min32Sx2,
      Iop_Min8Ux8, Iop_Min16Ux4, Iop_Min32Ux2,


      Iop_CmpEQ8x8, Iop_CmpEQ16x4, Iop_CmpEQ32x2,
      Iop_CmpGT8Ux8, Iop_CmpGT16Ux4, Iop_CmpGT32Ux2,
      Iop_CmpGT8Sx8, Iop_CmpGT16Sx4, Iop_CmpGT32Sx2,



      Iop_Cnt8x8,
      Iop_Clz8Sx8, Iop_Clz16Sx4, Iop_Clz32Sx2,
      Iop_Cls8Sx8, Iop_Cls16Sx4, Iop_Cls32Sx2,


      Iop_Shl8x8, Iop_Shl16x4, Iop_Shl32x2,
      Iop_Shr8x8, Iop_Shr16x4, Iop_Shr32x2,
      Iop_Sar8x8, Iop_Sar16x4, Iop_Sar32x2,
      Iop_Sal8x8, Iop_Sal16x4, Iop_Sal32x2, Iop_Sal64x1,


      Iop_ShlN8x8, Iop_ShlN16x4, Iop_ShlN32x2,
      Iop_ShrN8x8, Iop_ShrN16x4, Iop_ShrN32x2,
      Iop_SarN8x8, Iop_SarN16x4, Iop_SarN32x2,


      Iop_QShl8x8, Iop_QShl16x4, Iop_QShl32x2, Iop_QShl64x1,
      Iop_QSal8x8, Iop_QSal16x4, Iop_QSal32x2, Iop_QSal64x1,

      Iop_QShlN8Sx8, Iop_QShlN16Sx4, Iop_QShlN32Sx2, Iop_QShlN64Sx1,
      Iop_QShlN8x8, Iop_QShlN16x4, Iop_QShlN32x2, Iop_QShlN64x1,
      Iop_QSalN8x8, Iop_QSalN16x4, Iop_QSalN32x2, Iop_QSalN64x1,


      Iop_QNarrow16Ux4,
      Iop_QNarrow16Sx4,
      Iop_QNarrow32Sx2,





      Iop_InterleaveHI8x8, Iop_InterleaveHI16x4, Iop_InterleaveHI32x2,
      Iop_InterleaveLO8x8, Iop_InterleaveLO16x4, Iop_InterleaveLO32x2,



      Iop_InterleaveOddLanes8x8, Iop_InterleaveEvenLanes8x8,
      Iop_InterleaveOddLanes16x4, Iop_InterleaveEvenLanes16x4,






      Iop_CatOddLanes8x8, Iop_CatOddLanes16x4,
      Iop_CatEvenLanes8x8, Iop_CatEvenLanes16x4,





      Iop_GetElem8x8, Iop_GetElem16x4, Iop_GetElem32x2,
      Iop_SetElem8x8, Iop_SetElem16x4, Iop_SetElem32x2,


      Iop_Dup8x8, Iop_Dup16x4, Iop_Dup32x2,






      Iop_Extract64,







      Iop_Reverse16_8x8,
      Iop_Reverse32_8x8, Iop_Reverse32_16x4,
      Iop_Reverse64_8x8, Iop_Reverse64_16x4, Iop_Reverse64_32x2,






      Iop_Perm8x8,



      Iop_Recip32x2, Iop_Rsqrte32x2,






      Iop_Add32Fx4, Iop_Sub32Fx4, Iop_Mul32Fx4, Iop_Div32Fx4,
      Iop_Max32Fx4, Iop_Min32Fx4,
      Iop_Add32Fx2, Iop_Sub32Fx2,


      Iop_CmpEQ32Fx4, Iop_CmpLT32Fx4, Iop_CmpLE32Fx4, Iop_CmpUN32Fx4,
      Iop_CmpGT32Fx4, Iop_CmpGE32Fx4,


      Iop_Abs32Fx4,


      Iop_PwMax32Fx4, Iop_PwMin32Fx4,


      Iop_Sqrt32Fx4, Iop_RSqrt32Fx4,
      Iop_Neg32Fx4,




      Iop_Recip32Fx4,




      Iop_Recps32Fx4,



      Iop_Rsqrte32Fx4,




      Iop_Rsqrts32Fx4,






      Iop_I32UtoFx4, Iop_I32StoFx4,
      Iop_FtoI32Ux4_RZ, Iop_FtoI32Sx4_RZ,
      Iop_QFtoI32Ux4_RZ, Iop_QFtoI32Sx4_RZ,
      Iop_RoundF32x4_RM, Iop_RoundF32x4_RP,
      Iop_RoundF32x4_RN, Iop_RoundF32x4_RZ,



      Iop_F32ToFixed32Ux4_RZ, Iop_F32ToFixed32Sx4_RZ,
      Iop_Fixed32UToF32x4_RN, Iop_Fixed32SToF32x4_RN,


      Iop_F32toF16x4, Iop_F16toF32x4,







      Iop_Add32F0x4, Iop_Sub32F0x4, Iop_Mul32F0x4, Iop_Div32F0x4,
      Iop_Max32F0x4, Iop_Min32F0x4,
      Iop_CmpEQ32F0x4, Iop_CmpLT32F0x4, Iop_CmpLE32F0x4, Iop_CmpUN32F0x4,


      Iop_Recip32F0x4, Iop_Sqrt32F0x4, Iop_RSqrt32F0x4,




      Iop_Add64Fx2, Iop_Sub64Fx2, Iop_Mul64Fx2, Iop_Div64Fx2,
      Iop_Max64Fx2, Iop_Min64Fx2,
      Iop_CmpEQ64Fx2, Iop_CmpLT64Fx2, Iop_CmpLE64Fx2, Iop_CmpUN64Fx2,


      Iop_Recip64Fx2, Iop_Sqrt64Fx2, Iop_RSqrt64Fx2,







      Iop_Add64F0x2, Iop_Sub64F0x2, Iop_Mul64F0x2, Iop_Div64F0x2,
      Iop_Max64F0x2, Iop_Min64F0x2,
      Iop_CmpEQ64F0x2, Iop_CmpLT64F0x2, Iop_CmpLE64F0x2, Iop_CmpUN64F0x2,


      Iop_Recip64F0x2, Iop_Sqrt64F0x2, Iop_RSqrt64F0x2,




      Iop_V128to64,
      Iop_V128HIto64,
      Iop_64HLtoV128,

      Iop_64UtoV128,
      Iop_SetV128lo64,


      Iop_32UtoV128,
      Iop_V128to32,
      Iop_SetV128lo32,




      Iop_NotV128,
      Iop_AndV128, Iop_OrV128, Iop_XorV128,


      Iop_ShlV128, Iop_ShrV128,


      Iop_CmpNEZ8x16, Iop_CmpNEZ16x8, Iop_CmpNEZ32x4, Iop_CmpNEZ64x2,


      Iop_Add8x16, Iop_Add16x8, Iop_Add32x4, Iop_Add64x2,
      Iop_QAdd8Ux16, Iop_QAdd16Ux8, Iop_QAdd32Ux4, Iop_QAdd64Ux2,
      Iop_QAdd8Sx16, Iop_QAdd16Sx8, Iop_QAdd32Sx4, Iop_QAdd64Sx2,


      Iop_Sub8x16, Iop_Sub16x8, Iop_Sub32x4, Iop_Sub64x2,
      Iop_QSub8Ux16, Iop_QSub16Ux8, Iop_QSub32Ux4, Iop_QSub64Ux2,
      Iop_QSub8Sx16, Iop_QSub16Sx8, Iop_QSub32Sx4, Iop_QSub64Sx2,


      Iop_Mul8x16, Iop_Mul16x8, Iop_Mul32x4,
                    Iop_MulHi16Ux8, Iop_MulHi32Ux4,
                    Iop_MulHi16Sx8, Iop_MulHi32Sx4,

      Iop_MullEven8Ux16, Iop_MullEven16Ux8,
      Iop_MullEven8Sx16, Iop_MullEven16Sx8,

      Iop_Mull8Ux8, Iop_Mull8Sx8,
      Iop_Mull16Ux4, Iop_Mull16Sx4,
      Iop_Mull32Ux2, Iop_Mull32Sx2,






      Iop_QDMulHi16Sx8, Iop_QDMulHi32Sx4,
      Iop_QRDMulHi16Sx8, Iop_QRDMulHi32Sx4,

      Iop_QDMulLong16Sx4, Iop_QDMulLong32Sx2,


      Iop_PolynomialMul8x16,
      Iop_PolynomialMull8x8,




      Iop_PwAdd8x16, Iop_PwAdd16x8, Iop_PwAdd32x4,
      Iop_PwAdd32Fx2,





      Iop_PwAddL8Ux16, Iop_PwAddL16Ux8, Iop_PwAddL32Ux4,
      Iop_PwAddL8Sx16, Iop_PwAddL16Sx8, Iop_PwAddL32Sx4,


      Iop_Abs8x16, Iop_Abs16x8, Iop_Abs32x4,


      Iop_Avg8Ux16, Iop_Avg16Ux8, Iop_Avg32Ux4,
      Iop_Avg8Sx16, Iop_Avg16Sx8, Iop_Avg32Sx4,


      Iop_Max8Sx16, Iop_Max16Sx8, Iop_Max32Sx4,
      Iop_Max8Ux16, Iop_Max16Ux8, Iop_Max32Ux4,
      Iop_Min8Sx16, Iop_Min16Sx8, Iop_Min32Sx4,
      Iop_Min8Ux16, Iop_Min16Ux8, Iop_Min32Ux4,


      Iop_CmpEQ8x16, Iop_CmpEQ16x8, Iop_CmpEQ32x4,
      Iop_CmpGT8Sx16, Iop_CmpGT16Sx8, Iop_CmpGT32Sx4, Iop_CmpGT64Sx2,
      Iop_CmpGT8Ux16, Iop_CmpGT16Ux8, Iop_CmpGT32Ux4,



      Iop_Cnt8x16,
      Iop_Clz8Sx16, Iop_Clz16Sx8, Iop_Clz32Sx4,
      Iop_Cls8Sx16, Iop_Cls16Sx8, Iop_Cls32Sx4,


      Iop_ShlN8x16, Iop_ShlN16x8, Iop_ShlN32x4, Iop_ShlN64x2,
      Iop_ShrN8x16, Iop_ShrN16x8, Iop_ShrN32x4, Iop_ShrN64x2,
      Iop_SarN8x16, Iop_SarN16x8, Iop_SarN32x4, Iop_SarN64x2,


      Iop_Shl8x16, Iop_Shl16x8, Iop_Shl32x4, Iop_Shl64x2,
      Iop_Shr8x16, Iop_Shr16x8, Iop_Shr32x4, Iop_Shr64x2,
      Iop_Sar8x16, Iop_Sar16x8, Iop_Sar32x4, Iop_Sar64x2,
      Iop_Sal8x16, Iop_Sal16x8, Iop_Sal32x4, Iop_Sal64x2,
      Iop_Rol8x16, Iop_Rol16x8, Iop_Rol32x4,


      Iop_QShl8x16, Iop_QShl16x8, Iop_QShl32x4, Iop_QShl64x2,
      Iop_QSal8x16, Iop_QSal16x8, Iop_QSal32x4, Iop_QSal64x2,

      Iop_QShlN8Sx16, Iop_QShlN16Sx8, Iop_QShlN32Sx4, Iop_QShlN64Sx2,
      Iop_QShlN8x16, Iop_QShlN16x8, Iop_QShlN32x4, Iop_QShlN64x2,
      Iop_QSalN8x16, Iop_QSalN16x8, Iop_QSalN32x4, Iop_QSalN64x2,



      Iop_QNarrow16Ux8, Iop_QNarrow32Ux4,
      Iop_QNarrow16Sx8, Iop_QNarrow32Sx4,
      Iop_Narrow16x8, Iop_Narrow32x4,

      Iop_Shorten16x8, Iop_Shorten32x4, Iop_Shorten64x2,

      Iop_QShortenS16Sx8, Iop_QShortenS32Sx4, Iop_QShortenS64Sx2,
      Iop_QShortenU16Sx8, Iop_QShortenU32Sx4, Iop_QShortenU64Sx2,

      Iop_QShortenU16Ux8, Iop_QShortenU32Ux4, Iop_QShortenU64Ux2,
# 1197 "../VEX/pub/libvex_ir.h"
      Iop_Longen8Ux8, Iop_Longen16Ux4, Iop_Longen32Ux2,
      Iop_Longen8Sx8, Iop_Longen16Sx4, Iop_Longen32Sx2,





      Iop_InterleaveHI8x16, Iop_InterleaveHI16x8,
      Iop_InterleaveHI32x4, Iop_InterleaveHI64x2,
      Iop_InterleaveLO8x16, Iop_InterleaveLO16x8,
      Iop_InterleaveLO32x4, Iop_InterleaveLO64x2,


      Iop_InterleaveOddLanes8x16, Iop_InterleaveEvenLanes8x16,
      Iop_InterleaveOddLanes16x8, Iop_InterleaveEvenLanes16x8,
      Iop_InterleaveOddLanes32x4, Iop_InterleaveEvenLanes32x4,



      Iop_CatOddLanes8x16, Iop_CatOddLanes16x8, Iop_CatOddLanes32x4,
      Iop_CatEvenLanes8x16, Iop_CatEvenLanes16x8, Iop_CatEvenLanes32x4,




      Iop_GetElem8x16, Iop_GetElem16x8, Iop_GetElem32x4, Iop_GetElem64x2,


      Iop_Dup8x16, Iop_Dup16x8, Iop_Dup32x4,






      Iop_ExtractV128,






      Iop_Reverse16_8x16,
      Iop_Reverse32_8x16, Iop_Reverse32_16x8,
      Iop_Reverse64_8x16, Iop_Reverse64_16x8, Iop_Reverse64_32x4,






      Iop_Perm8x16,



      Iop_Recip32x4, Iop_Rsqrte32x4
   }
   IROp;


extern void ppIROp ( IROp );






typedef
   enum {
      Irrm_NEAREST = 0,
      Irrm_NegINF = 1,
      Irrm_PosINF = 2,
      Irrm_ZERO = 3
   }
   IRRoundingMode;



typedef
   enum {
      Ircr_UN = 0x45,
      Ircr_LT = 0x01,
      Ircr_GT = 0x00,
      Ircr_EQ = 0x40
   }
   IRCmpF64Result;

typedef IRCmpF64Result IRCmpF32Result;
typedef IRCmpF64Result IRCmpF128Result;





typedef
   enum {
      Iex_Binder=0x15000,
      Iex_Get,
      Iex_GetI,
      Iex_RdTmp,
      Iex_Qop,
      Iex_Triop,
      Iex_Binop,
      Iex_Unop,
      Iex_Load,
      Iex_Const,
      Iex_Mux0X,
      Iex_CCall
   }
   IRExprTag;
# 1317 "../VEX/pub/libvex_ir.h"
typedef
   struct _IRExpr
   IRExpr;

struct _IRExpr {
   IRExprTag tag;
   union {


      struct {
         Int binder;
      } Binder;




      struct {
         Int offset;
         IRType ty;
      } Get;
# 1374 "../VEX/pub/libvex_ir.h"
      struct {
         IRRegArray* descr;
         IRExpr* ix;
         Int bias;
      } GetI;




      struct {
         IRTemp tmp;
      } RdTmp;





      struct {
         IROp op;
         IRExpr* arg1;
         IRExpr* arg2;
         IRExpr* arg3;
         IRExpr* arg4;
      } Qop;





      struct {
         IROp op;
         IRExpr* arg1;
         IRExpr* arg2;
         IRExpr* arg3;
      } Triop;




      struct {
         IROp op;
         IRExpr* arg1;
         IRExpr* arg2;
      } Binop;




      struct {
         IROp op;
         IRExpr* arg;
      } Unop;







      struct {
         IREndness end;
         IRType ty;
         IRExpr* addr;
      } Load;




      struct {
         IRConst* con;
      } Const;
# 1485 "../VEX/pub/libvex_ir.h"
      struct {
         IRCallee* cee;
         IRType retty;
         IRExpr** args;
      } CCall;
# 1498 "../VEX/pub/libvex_ir.h"
      struct {
         IRExpr* cond;
         IRExpr* expr0;
         IRExpr* exprX;
      } Mux0X;
   } Iex;
};


extern IRExpr* IRExpr_Binder ( Int binder );
extern IRExpr* IRExpr_Get ( Int off, IRType ty );
extern IRExpr* IRExpr_GetI ( IRRegArray* descr, IRExpr* ix, Int bias );
extern IRExpr* IRExpr_RdTmp ( IRTemp tmp );
extern IRExpr* IRExpr_Qop ( IROp op, IRExpr* arg1, IRExpr* arg2,
                                        IRExpr* arg3, IRExpr* arg4 );
extern IRExpr* IRExpr_Triop ( IROp op, IRExpr* arg1,
                                        IRExpr* arg2, IRExpr* arg3 );
extern IRExpr* IRExpr_Binop ( IROp op, IRExpr* arg1, IRExpr* arg2 );
extern IRExpr* IRExpr_Unop ( IROp op, IRExpr* arg );
extern IRExpr* IRExpr_Load ( IREndness end, IRType ty, IRExpr* addr );
extern IRExpr* IRExpr_Const ( IRConst* con );
extern IRExpr* IRExpr_CCall ( IRCallee* cee, IRType retty, IRExpr** args );
extern IRExpr* IRExpr_Mux0X ( IRExpr* cond, IRExpr* expr0, IRExpr* exprX );


extern IRExpr* deepCopyIRExpr ( IRExpr* );


extern void ppIRExpr ( IRExpr* );



extern IRExpr** mkIRExprVec_0 ( void );
extern IRExpr** mkIRExprVec_1 ( IRExpr* );
extern IRExpr** mkIRExprVec_2 ( IRExpr*, IRExpr* );
extern IRExpr** mkIRExprVec_3 ( IRExpr*, IRExpr*, IRExpr* );
extern IRExpr** mkIRExprVec_4 ( IRExpr*, IRExpr*, IRExpr*, IRExpr* );
extern IRExpr** mkIRExprVec_5 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
                                IRExpr* );
extern IRExpr** mkIRExprVec_6 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
                                IRExpr*, IRExpr* );
extern IRExpr** mkIRExprVec_7 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
                                IRExpr*, IRExpr*, IRExpr* );
extern IRExpr** mkIRExprVec_8 ( IRExpr*, IRExpr*, IRExpr*, IRExpr*,
                                IRExpr*, IRExpr*, IRExpr*, IRExpr*);





extern IRExpr** shallowCopyIRExprVec ( IRExpr** );
extern IRExpr** deepCopyIRExprVec ( IRExpr** );



extern IRExpr* mkIRExpr_HWord ( HWord );


extern
IRExpr* mkIRExprCCall ( IRType retty,
                        Int regparms, HChar* name, void* addr,
                        IRExpr** args );




static inline Bool isIRAtom ( IRExpr* e ) {
   return toBool(e->tag == Iex_RdTmp || e->tag == Iex_Const);
}



extern Bool eqIRAtom ( IRExpr*, IRExpr* );
# 1600 "../VEX/pub/libvex_ir.h"
typedef
   enum {
      Ijk_Boring=0x16000,
      Ijk_Call,
      Ijk_Ret,
      Ijk_ClientReq,
      Ijk_Yield,
      Ijk_EmWarn,
      Ijk_EmFail,
      Ijk_NoDecode,
      Ijk_MapFail,
      Ijk_TInval,
      Ijk_NoRedir,
      Ijk_SigTRAP,
      Ijk_SigSEGV,
      Ijk_SigBUS,


      Ijk_Sys_syscall,
      Ijk_Sys_int32,
      Ijk_Sys_int128,
      Ijk_Sys_int129,
      Ijk_Sys_int130,
      Ijk_Sys_sysenter

   }
   IRJumpKind;

extern void ppIRJumpKind ( IRJumpKind );
# 1676 "../VEX/pub/libvex_ir.h"
typedef
   enum {
      Ifx_None = 0x17000,
      Ifx_Read,
      Ifx_Write,
      Ifx_Modify,
   }
   IREffect;


extern void ppIREffect ( IREffect );


typedef
   struct {

      IRCallee* cee;
      IRExpr* guard;
      IRExpr** args;
      IRTemp tmp;


      IREffect mFx;
      IRExpr* mAddr;
      Int mSize;


      Bool needsBBP;
      Int nFxState;
      struct {
         IREffect fx;
         Int offset;
         Int size;
      } fxState[7];
   }
   IRDirty;


extern void ppIRDirty ( IRDirty* );


extern IRDirty* emptyIRDirty ( void );


extern IRDirty* deepCopyIRDirty ( IRDirty* );







extern
IRDirty* unsafeIRDirty_0_N ( Int regparms, HChar* name, void* addr,
                             IRExpr** args );



extern
IRDirty* unsafeIRDirty_1_N ( IRTemp dst,
                             Int regparms, HChar* name, void* addr,
                             IRExpr** args );




typedef
   enum {
      Imbe_Fence=0x18000,
   }
   IRMBusEvent;

extern void ppIRMBusEvent ( IRMBusEvent );
# 1816 "../VEX/pub/libvex_ir.h"
typedef
   struct {
      IRTemp oldHi;
      IRTemp oldLo;
      IREndness end;
      IRExpr* addr;
      IRExpr* expdHi;
      IRExpr* expdLo;
      IRExpr* dataHi;
      IRExpr* dataLo;
   }
   IRCAS;

extern void ppIRCAS ( IRCAS* cas );

extern IRCAS* mkIRCAS ( IRTemp oldHi, IRTemp oldLo,
                        IREndness end, IRExpr* addr,
                        IRExpr* expdHi, IRExpr* expdLo,
                        IRExpr* dataHi, IRExpr* dataLo );

extern IRCAS* deepCopyIRCAS ( IRCAS* );
# 1850 "../VEX/pub/libvex_ir.h"
typedef
   enum {
      Ist_NoOp=0x19000,
      Ist_IMark,
      Ist_AbiHint,
      Ist_Put,
      Ist_PutI,
      Ist_WrTmp,
      Ist_Store,
      Ist_CAS,
      Ist_LLSC,
      Ist_Dirty,
      Ist_MBE,
      Ist_Exit
   }
   IRStmtTag;
# 1876 "../VEX/pub/libvex_ir.h"
typedef
   struct _IRStmt {
      IRStmtTag tag;
      union {





         struct {
  } NoOp;
# 1897 "../VEX/pub/libvex_ir.h"
         struct {
            Addr64 addr;
            Int len;
         } IMark;
# 1916 "../VEX/pub/libvex_ir.h"
         struct {
            IRExpr* base;
            Int len;
            IRExpr* nia;
         } AbiHint;




         struct {
            Int offset;
            IRExpr* data;
         } Put;
# 1937 "../VEX/pub/libvex_ir.h"
         struct {
            IRRegArray* descr;
            IRExpr* ix;
            Int bias;
            IRExpr* data;
         } PutI;
# 1951 "../VEX/pub/libvex_ir.h"
         struct {
            IRTemp tmp;
            IRExpr* data;
         } WrTmp;






         struct {
            IREndness end;
            IRExpr* addr;
            IRExpr* data;
         } Store;
# 1981 "../VEX/pub/libvex_ir.h"
         struct {
            IRCAS* details;
         } CAS;
# 2029 "../VEX/pub/libvex_ir.h"
         struct {
            IREndness end;
            IRTemp result;
            IRExpr* addr;
            IRExpr* storedata;
         } LLSC;
# 2047 "../VEX/pub/libvex_ir.h"
         struct {
            IRDirty* details;
         } Dirty;







         struct {
            IRMBusEvent event;
         } MBE;





         struct {
            IRExpr* guard;
            IRJumpKind jk;
            IRConst* dst;
         } Exit;
      } Ist;
   }
   IRStmt;


extern IRStmt* IRStmt_NoOp ( void );
extern IRStmt* IRStmt_IMark ( Addr64 addr, Int len );
extern IRStmt* IRStmt_AbiHint ( IRExpr* base, Int len, IRExpr* nia );
extern IRStmt* IRStmt_Put ( Int off, IRExpr* data );
extern IRStmt* IRStmt_PutI ( IRRegArray* descr, IRExpr* ix, Int bias,
                                IRExpr* data );
extern IRStmt* IRStmt_WrTmp ( IRTemp tmp, IRExpr* data );
extern IRStmt* IRStmt_Store ( IREndness end, IRExpr* addr, IRExpr* data );
extern IRStmt* IRStmt_CAS ( IRCAS* details );
extern IRStmt* IRStmt_LLSC ( IREndness end, IRTemp result,
                                IRExpr* addr, IRExpr* storedata );
extern IRStmt* IRStmt_Dirty ( IRDirty* details );
extern IRStmt* IRStmt_MBE ( IRMBusEvent event );
extern IRStmt* IRStmt_Exit ( IRExpr* guard, IRJumpKind jk, IRConst* dst );


extern IRStmt* deepCopyIRStmt ( IRStmt* );


extern void ppIRStmt ( IRStmt* );
# 2105 "../VEX/pub/libvex_ir.h"
typedef
   struct {
      IRType* types;
      Int types_size;
      Int types_used;
   }
   IRTypeEnv;


extern IRTemp newIRTemp ( IRTypeEnv*, IRType );


extern IRTypeEnv* deepCopyIRTypeEnv ( IRTypeEnv* );


extern void ppIRTypeEnv ( IRTypeEnv* );
# 2136 "../VEX/pub/libvex_ir.h"
typedef
   struct {
      IRTypeEnv* tyenv;
      IRStmt** stmts;
      Int stmts_size;
      Int stmts_used;
      IRExpr* next;
      IRJumpKind jumpkind;
   }
   IRSB;


extern IRSB* emptyIRSB ( void );


extern IRSB* deepCopyIRSB ( IRSB* );



extern IRSB* deepCopyIRSBExceptStmts ( IRSB* );


extern void ppIRSB ( IRSB* );


extern void addStmtToIRSB ( IRSB*, IRStmt* );







extern IRTypeEnv* emptyIRTypeEnv ( void );


extern IRType typeOfIRConst ( IRConst* );
extern IRType typeOfIRTemp ( IRTypeEnv*, IRTemp );
extern IRType typeOfIRExpr ( IRTypeEnv*, IRExpr* );


extern void sanityCheckIRSB ( IRSB* bb,
                              HChar* caller,
                              Bool require_flatness,
                              IRType guest_word_size );
extern Bool isFlatIRStmt ( IRStmt* );


extern Bool isPlausibleIRType ( IRType ty );
# 42 "../VEX/pub/libvex.h" 2
# 52 "../VEX/pub/libvex.h"
typedef
   enum {
      VexArch_INVALID,
      VexArchX86,
      VexArchAMD64,
      VexArchARM,
      VexArchPPC32,
      VexArchPPC64,
      VexArchS390X
   }
   VexArch;
# 122 "../VEX/pub/libvex.h"
extern const HChar* LibVEX_ppVexArch ( VexArch );
extern const HChar* LibVEX_ppVexHwCaps ( VexArch, UInt );






typedef
   struct {

      UInt hwcaps;

      Int ppc_cache_line_szB;


      UInt ppc_dcbz_szB;
      UInt ppc_dcbzl_szB;
   }
   VexArchInfo;


extern
void LibVEX_default_VexArchInfo ( VexArchInfo* vai );
# 204 "../VEX/pub/libvex.h"
typedef
   struct {


      Int guest_stack_redzone_size;




      Bool guest_amd64_assume_fs_is_zero;




      Bool guest_amd64_assume_gs_is_0x60;



      Bool guest_ppc_zap_RZ_at_blr;





      Bool (*guest_ppc_zap_RZ_at_bl)(Addr64);




      Bool guest_ppc_sc_continues_at_LR;




      Bool host_ppc_calls_use_fndescrs;




      Bool host_ppc32_regalign_int64_args;
   }
   VexAbiInfo;


extern
void LibVEX_default_VexAbiInfo ( VexAbiInfo* vbi );
# 258 "../VEX/pub/libvex.h"
typedef
   struct {

      Int iropt_verbosity;


      Int iropt_level;



      Bool iropt_precise_memory_exns;



      Int iropt_unroll_thresh;



      Int guest_max_insns;





      Int guest_chase_thresh;


      Bool guest_chase_cond;
   }
   VexControl;




extern
void LibVEX_default_VexControl ( VexControl* vcon );
# 306 "../VEX/pub/libvex.h"
extern HChar* private_LibVEX_alloc_first;
extern HChar* private_LibVEX_alloc_curr;
extern HChar* private_LibVEX_alloc_last;
extern void private_LibVEX_alloc_OOM(void) __attribute__((noreturn));

static inline void* LibVEX_Alloc ( Int nbytes )
{




   HChar* curr;
   HChar* next;
   Int ALIGN;
   ALIGN = sizeof(void*)-1;
   nbytes = (nbytes + ALIGN) & ~ALIGN;
   curr = private_LibVEX_alloc_curr;
   next = curr + nbytes;
   if (next >= private_LibVEX_alloc_last)
      private_LibVEX_alloc_OOM();
   private_LibVEX_alloc_curr = next;
   return curr;

}


extern void LibVEX_ShowAllocStats ( void );
# 346 "../VEX/pub/libvex.h"
typedef
   struct {


      Int total_sizeB;

      Int offset_SP;
      Int sizeof_SP;

      Int offset_FP;
      Int sizeof_FP;

      Int offset_IP;
      Int sizeof_IP;


      Int n_alwaysDefd;
      struct {
         Int offset;
         Int size;
      } alwaysDefd[24];
   }
   VexGuestLayout;
# 396 "../VEX/pub/libvex.h"
extern void LibVEX_Init (

   __attribute__ ((noreturn))
   void (*failure_exit) ( void ),

   void (*log_bytes) ( HChar*, Int nbytes ),

   Int debuglevel,

   Bool valgrind_support,

               VexControl* vcon
);







typedef
   enum {
      VexTransOK,
      VexTransAccessFail,
      VexTransOutputFull
   }
   VexTranslateResult;
# 433 "../VEX/pub/libvex.h"
typedef
   struct {
      Addr64 base[3];
      UShort len[3];
      UShort n_used;
   }
   VexGuestExtents;




typedef
   struct {


      VexArch arch_guest;
      VexArchInfo archinfo_guest;
      VexArch arch_host;
      VexArchInfo archinfo_host;
      VexAbiInfo abiinfo_both;




      void* callback_opaque;



      UChar* guest_bytes;




      Addr64 guest_bytes_addr;



      Bool (*chase_into_ok) ( void*, Addr64 );


      VexGuestExtents* guest_extents;


      UChar* host_bytes;
      Int host_bytes_size;

      Int* host_bytes_used;



      IRSB* (*instrument1) ( void*,
                               IRSB*,
                               VexGuestLayout*,
                               VexGuestExtents*,
                               IRType gWordTy, IRType hWordTy );
      IRSB* (*instrument2) ( void*,
                               IRSB*,
                               VexGuestLayout*,
                               VexGuestExtents*,
                               IRType gWordTy, IRType hWordTy );

      IRSB* (*finaltidy) ( IRSB* );


      Bool do_self_check;
# 508 "../VEX/pub/libvex.h"
      Bool (*preamble_function)( void*, IRSB*);


      Int traceflags;
# 540 "../VEX/pub/libvex.h"
      void* dispatch;
   }
   VexTranslateArgs;


extern
VexTranslateResult LibVEX_Translate ( VexTranslateArgs* );
# 565 "../VEX/pub/libvex.h"
extern void LibVEX_ShowStats ( void );
# 36 "../include/pub_tool_tooliface.h" 2
# 48 "../include/pub_tool_tooliface.h"
extern void (*vgPlain_tl_pre_clo_init) ( void );
# 65 "../include/pub_tool_tooliface.h"
typedef
   struct {
      Addr64 nraddr;
      Addr64 readdr;
      ThreadId tid;
   }
   VgCallbackClosure;

extern void vgPlain_basic_tool_funcs(


   void (*post_clo_init)(void),
# 219 "../include/pub_tool_tooliface.h"
   IRSB*(*instrument)(VgCallbackClosure* closure,
                      IRSB* sb_in,
                      VexGuestLayout* layout,
                      VexGuestExtents* vge,
                      IRType gWordTy,
                      IRType hWordTy),



   void (*fini)(Int)
);
# 245 "../include/pub_tool_tooliface.h"
extern void vgPlain_details_name ( Char* name );
extern void vgPlain_details_version ( Char* version );
extern void vgPlain_details_description ( Char* description );
extern void vgPlain_details_copyright_author ( Char* copyright_author );




extern void vgPlain_details_avg_translation_sizeB ( UInt size );



extern void vgPlain_details_bug_reports_to ( Char* bug_reports_to );





extern void vgPlain_needs_libc_freeres ( void );







extern void vgPlain_needs_core_errors ( void );






extern void vgPlain_needs_tool_errors (







   Bool (*eq_Error)(VgRes res, Error* e1, Error* e2),
# 296 "../include/pub_tool_tooliface.h"
   void (*before_pp_Error)(Error* err),


   void (*pp_Error)(Error* err),


   Bool show_ThreadIDs_for_errors,
# 311 "../include/pub_tool_tooliface.h"
   UInt (*update_extra)(Error* err),



   Bool (*recognised_suppression)(Char* name, Supp* su),






   Bool (*read_extra_suppression_info)(Int fd, Char** bufpp, SizeT* nBufp,
                                       Supp* su),




   Bool (*error_matches_suppression)(Error* err, Supp* su),




   Char* (*get_error_name)(Error* err),
# 344 "../include/pub_tool_tooliface.h"
   Bool (*print_extra_suppression_info)(Error* err,
                                               Char* buf, Int nBuf)
);
# 355 "../include/pub_tool_tooliface.h"
extern void vgPlain_needs_superblock_discards (
# 372 "../include/pub_tool_tooliface.h"
   void (*discard_superblock_info)(Addr64 orig_addr, VexGuestExtents extents)
);


extern void vgPlain_needs_command_line_options (
# 388 "../include/pub_tool_tooliface.h"
   Bool (*process_cmd_line_option)(Char* argv),


   void (*print_usage)(void),


   void (*print_debug_usage)(void)
);


extern void vgPlain_needs_client_requests (
# 410 "../include/pub_tool_tooliface.h"
   Bool (*handle_client_request)(ThreadId tid, UWord* arg_block, UWord* ret)
);
# 424 "../include/pub_tool_tooliface.h"
extern void vgPlain_needs_syscall_wrapper (
               void (* pre_syscall)(ThreadId tid, UInt syscallno,
                                    UWord* args, UInt nArgs),
               void (*post_syscall)(ThreadId tid, UInt syscallno,
                                    UWord* args, UInt nArgs, SysRes res)
);





extern void vgPlain_needs_sanity_checks (
   Bool(*cheap_sanity_check)(void),
   Bool(*expensive_sanity_check)(void)
);


extern void vgPlain_needs_var_info ( void );





extern void vgPlain_needs_malloc_replacement(
   void* (*pmalloc) ( ThreadId tid, SizeT n ),
   void* (*p__builtin_new) ( ThreadId tid, SizeT n ),
   void* (*p__builtin_vec_new) ( ThreadId tid, SizeT n ),
   void* (*pmemalign) ( ThreadId tid, SizeT align, SizeT n ),
   void* (*pcalloc) ( ThreadId tid, SizeT nmemb, SizeT size1 ),
   void (*pfree) ( ThreadId tid, void* p ),
   void (*p__builtin_delete) ( ThreadId tid, void* p ),
   void (*p__builtin_vec_delete) ( ThreadId tid, void* p ),
   void* (*prealloc) ( ThreadId tid, void* p, SizeT new_size ),
   SizeT (*pmalloc_usable_size) ( ThreadId tid, void* p),
   SizeT client_malloc_redzone_szB
);




extern void vgPlain_needs_xml_output ( void );




extern void vgPlain_needs_final_IR_tidy_pass ( IRSB*(*final_tidy)(IRSB*) );







typedef
   enum { Vg_CoreStartup=1, Vg_CoreSignal, Vg_CoreSysCall,





          Vg_CoreSysCallArgInMem,
          Vg_CoreTranslate, Vg_CoreClientReq
   } CorePart;
# 512 "../include/pub_tool_tooliface.h"
void vgPlain_track_new_mem_startup (void(*f)(Addr a, SizeT len,
                                              Bool rr, Bool ww, Bool xx,
                                              ULong di_handle));
void vgPlain_track_new_mem_stack_signal(void(*f)(Addr a, SizeT len, ThreadId tid));
void vgPlain_track_new_mem_brk (void(*f)(Addr a, SizeT len, ThreadId tid));
void vgPlain_track_new_mem_mmap (void(*f)(Addr a, SizeT len,
                                              Bool rr, Bool ww, Bool xx,
                                              ULong di_handle));

void vgPlain_track_copy_mem_remap (void(*f)(Addr from, Addr to, SizeT len));
void vgPlain_track_change_mem_mprotect (void(*f)(Addr a, SizeT len,
                                              Bool rr, Bool ww, Bool xx));
void vgPlain_track_die_mem_stack_signal(void(*f)(Addr a, SizeT len));
void vgPlain_track_die_mem_brk (void(*f)(Addr a, SizeT len));
void vgPlain_track_die_mem_munmap (void(*f)(Addr a, SizeT len));
# 548 "../include/pub_tool_tooliface.h"
void vgPlain_track_new_mem_stack_4_w_ECU (__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_8_w_ECU (__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_12_w_ECU (__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_16_w_ECU (__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_32_w_ECU (__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_112_w_ECU(__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_128_w_ECU(__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_144_w_ECU(__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_160_w_ECU(__attribute__((regparm(2))) void(*f)(Addr new_ESP, UInt ecu));
void vgPlain_track_new_mem_stack_w_ECU (void(*f)(Addr a, SizeT len,
                                                                       UInt ecu));

void vgPlain_track_new_mem_stack_4 (__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_8 (__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_12 (__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_16 (__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_32 (__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_112(__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_128(__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_144(__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack_160(__attribute__((regparm(1))) void(*f)(Addr new_ESP));
void vgPlain_track_new_mem_stack (void(*f)(Addr a, SizeT len));

void vgPlain_track_die_mem_stack_4 (__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_8 (__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_12 (__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_16 (__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_32 (__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_112(__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_128(__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_144(__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack_160(__attribute__((regparm(1))) void(*f)(Addr die_ESP));
void vgPlain_track_die_mem_stack (void(*f)(Addr a, SizeT len));


void vgPlain_track_ban_mem_stack (void(*f)(Addr a, SizeT len));


void vgPlain_track_pre_mem_read (void(*f)(CorePart part, ThreadId tid,
                                             Char* s, Addr a, SizeT size));
void vgPlain_track_pre_mem_read_asciiz(void(*f)(CorePart part, ThreadId tid,
                                             Char* s, Addr a));
void vgPlain_track_pre_mem_write (void(*f)(CorePart part, ThreadId tid,
                                             Char* s, Addr a, SizeT size));
void vgPlain_track_post_mem_write (void(*f)(CorePart part, ThreadId tid,
                                             Addr a, SizeT size));



void vgPlain_track_pre_reg_read (void(*f)(CorePart part, ThreadId tid,
                                        Char* s, PtrdiffT guest_state_offset,
                                        SizeT size));
void vgPlain_track_post_reg_write(void(*f)(CorePart part, ThreadId tid,
                                        PtrdiffT guest_state_offset,
                                        SizeT size));


void vgPlain_track_post_reg_write_clientcall_return(
      void(*f)(ThreadId tid, PtrdiffT guest_state_offset, SizeT size, Addr f));
# 621 "../include/pub_tool_tooliface.h"
void vgPlain_track_start_client_code(
        void(*f)(ThreadId tid, ULong blocks_dispatched)
     );
void vgPlain_track_stop_client_code(
        void(*f)(ThreadId tid, ULong blocks_dispatched)
     );
# 665 "../include/pub_tool_tooliface.h"
void vgPlain_track_pre_thread_ll_create (void(*f)(ThreadId tid, ThreadId child));
void vgPlain_track_pre_thread_first_insn(void(*f)(ThreadId tid));
void vgPlain_track_pre_thread_ll_exit (void(*f)(ThreadId tid));
# 676 "../include/pub_tool_tooliface.h"
void vgPlain_track_pre_deliver_signal (void(*f)(ThreadId tid, Int sigNo,
                                             Bool alt_stack));


void vgPlain_track_post_deliver_signal(void(*f)(ThreadId tid, Int sigNo));
# 45 "hg_main.c" 2
# 1 "../include/pub_tool_hashtable.h" 1
# 43 "../include/pub_tool_hashtable.h"
typedef
   struct _VgHashNode {
      struct _VgHashNode * next;
      UWord key;
   }
   VgHashNode;

typedef struct _VgHashTable * VgHashTable;





extern VgHashTable vgPlain_HT_construct ( HChar* name );


extern Int vgPlain_HT_count_nodes ( VgHashTable table );


extern void vgPlain_HT_add_node ( VgHashTable t, void* node );




extern void* vgPlain_HT_lookup ( VgHashTable table, UWord key );


extern void* vgPlain_HT_remove ( VgHashTable table, UWord key );




extern VgHashNode** vgPlain_HT_to_array ( VgHashTable t, UInt* n_elems );


extern void vgPlain_HT_ResetIter ( VgHashTable table );
# 91 "../include/pub_tool_hashtable.h"
extern void* vgPlain_HT_Next ( VgHashTable table );


extern void vgPlain_HT_destruct ( VgHashTable t );
# 46 "hg_main.c" 2
# 1 "../include/pub_tool_replacemalloc.h" 1
# 41 "../include/pub_tool_replacemalloc.h"
extern void* vgPlain_cli_malloc ( SizeT align, SizeT nbytes );
extern void vgPlain_cli_free ( void* p );





extern Long vgPlain_free_queue_volume;
extern Long vgPlain_free_queue_length;


extern Bool vgPlain_addr_is_in_block( Addr a, Addr start,
                                   SizeT size, SizeT rz_szB );







extern Bool vgPlain_clo_trace_malloc;


extern UInt vgPlain_clo_alignment;

extern Bool vgPlain_replacement_malloc_process_cmd_line_option ( Char* arg );
# 47 "hg_main.c" 2
# 1 "../include/pub_tool_machine.h" 1
# 110 "../include/pub_tool_machine.h"
Addr vgPlain_get_IP ( ThreadId tid );
Addr vgPlain_get_SP ( ThreadId tid );
# 120 "../include/pub_tool_machine.h"
void
vgPlain_get_shadow_regs_area ( ThreadId tid,
                                   UChar* dst,
                                   Int shadowNo, PtrdiffT offset, SizeT size );
void
vgPlain_set_shadow_regs_area ( ThreadId tid,
                                   Int shadowNo, PtrdiffT offset, SizeT size,
                                   const UChar* src );



void vgPlain_set_syscall_return_shadows ( ThreadId tid,

                                       UWord s1res, UWord s2res,

                                       UWord s1err, UWord s2err );





extern void vgPlain_apply_to_GP_regs(void (*f)(UWord val));




extern void vgPlain_thread_stack_reset_iter ( ThreadId* tid );
extern Bool vgPlain_thread_stack_next ( ThreadId* tid,
                                                  Addr* stack_min,
                                                  Addr* stack_max );


extern Addr vgPlain_thread_get_stack_max ( ThreadId tid );


extern SizeT vgPlain_thread_get_stack_size ( ThreadId tid );



extern Addr vgPlain_thread_get_altstack_min ( ThreadId tid );



extern SizeT vgPlain_thread_get_altstack_size ( ThreadId tid );





extern void* vgPlain_fnptr_to_fnentry( void* );
# 48 "hg_main.c" 2
# 1 "../include/pub_tool_options.h" 1
# 144 "../include/pub_tool_options.h"
extern Int vgPlain_clo_verbosity;


extern Bool vgPlain_clo_stats;




extern Bool vgPlain_clo_xml;



extern HChar* vgPlain_clo_xml_user_comment;



extern VexControl vgPlain_clo_vex_control;


extern Int vgPlain_clo_backtrace_size;


extern Bool vgPlain_clo_show_below_main;
# 187 "../include/pub_tool_options.h"
extern Char* vgPlain_expand_file_name(Char* option_name, Char* format);
# 49 "hg_main.c" 2
# 1 "../include/pub_tool_xarray.h" 1
# 47 "../include/pub_tool_xarray.h"
typedef struct _XArray XArray;




extern XArray* vgPlain_newXA ( void*(*alloc_fn)(HChar*,SizeT),
                            HChar* cc,
                            void(*free_fn)(void*),
                            Word elemSzB );


extern void vgPlain_deleteXA ( XArray* );




extern void vgPlain_setCmpFnXA ( XArray*, Int (*compar)(void*,void*) );




extern Word vgPlain_addToXA ( XArray*, void* elem );




extern Word vgPlain_addBytesToXA ( XArray* xao, void* bytesV, Word nbytes );



extern void vgPlain_sortXA ( XArray* );






extern Bool vgPlain_lookupXA ( XArray*, void* key,
                                   Word* first, Word* last );
# 95 "../include/pub_tool_xarray.h"
extern Bool vgPlain_lookupXA_UNSAFE ( XArray* xao, void* key,
                                          Word* first, Word* last,
                                   Int(*cmpFn)(void*,void*) );


extern Word vgPlain_sizeXA ( XArray* );
# 109 "../include/pub_tool_xarray.h"
extern void* vgPlain_indexXA ( XArray*, Word );



extern void vgPlain_dropTailXA ( XArray*, Word );




extern void vgPlain_dropHeadXA ( XArray*, Word );







extern XArray* vgPlain_cloneXA( HChar* cc, XArray* xa );







extern void vgPlain_getContentsXA_UNSAFE( XArray* sr,
                                              void** ctsP,
                                              Word* usedP );







extern void vgPlain_xaprintf( XArray* dst, const HChar* format, ... )
                         __attribute__((format(__printf__, 2, 3)));

extern void vgPlain_xaprintf_no_f_c
                         ( XArray* dst, const HChar* format, ... );
# 50 "hg_main.c" 2
# 1 "../include/pub_tool_stacktrace.h" 1
# 35 "../include/pub_tool_stacktrace.h"
typedef Addr* StackTrace;
# 59 "../include/pub_tool_stacktrace.h"
extern UInt vgPlain_get_StackTrace ( ThreadId tid,
                                         StackTrace ips, UInt n_ips,
                                         StackTrace sps,
                                         StackTrace fps,
                                  Word first_ip_delta );






extern void vgPlain_apply_StackTrace(
               void(*action)(UInt n, Addr ip, void* opaque),
               void* opaque,
               StackTrace ips, UInt n_ips
            );


extern void vgPlain_pp_StackTrace ( StackTrace ips, UInt n_ips );



extern void vgPlain_get_and_pp_StackTrace ( ThreadId tid, UInt n_ips );
# 51 "hg_main.c" 2
# 1 "../include/pub_tool_wordfm.h" 1
# 70 "../include/pub_tool_wordfm.h"
typedef struct _WordFM WordFM;
# 79 "../include/pub_tool_wordfm.h"
WordFM* vgPlain_newFM ( void* (*alloc_nofail)( HChar* cc, SizeT ),
                     HChar* cc,
                     void (*dealloc)(void*),
                     Word (*kCmp)(UWord,UWord) );



void vgPlain_deleteFM ( WordFM*, void(*kFin)(UWord), void(*vFin)(UWord) );





Bool vgPlain_addToFM ( WordFM* fm, UWord k, UWord v );


Bool vgPlain_delFromFM ( WordFM* fm,
                             UWord* oldK, UWord* oldV, UWord key );


Bool vgPlain_lookupFM ( WordFM* fm,
                            UWord* keyP, UWord* valP, UWord key );
# 118 "../include/pub_tool_wordfm.h"
Bool vgPlain_findBoundsFM( WordFM* fm,
                               UWord* kMinP, UWord* vMinP,
                               UWord* kMaxP, UWord* vMaxP,
                        UWord minKey, UWord minVal,
                        UWord maxKey, UWord maxVal,
                        UWord key );




UWord vgPlain_sizeFM ( WordFM* fm );







void vgPlain_initIterFM ( WordFM* fm );





void vgPlain_initIterAtFM ( WordFM* fm, UWord start_at );



Bool vgPlain_nextIterFM ( WordFM* fm,
                              UWord* pKey, UWord* pVal );


void vgPlain_doneIterFM ( WordFM* fm );







WordFM* vgPlain_dopyFM ( WordFM* fm,
                      UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) );


SizeT vgPlain_getNodeSizeFM( void );
# 174 "../include/pub_tool_wordfm.h"
typedef struct _WordBag WordBag;


WordBag* vgPlain_newBag ( void* (*alloc_nofail)( HChar* cc, SizeT ),
                       HChar* cc,
                       void (*dealloc)(void*) );


void vgPlain_deleteBag ( WordBag* );


void vgPlain_addToBag( WordBag*, UWord );


UWord vgPlain_elemBag ( WordBag*, UWord );


Bool vgPlain_delFromBag( WordBag*, UWord );


Bool vgPlain_isEmptyBag( WordBag* );


Bool vgPlain_isSingletonTotalBag( WordBag* );


UWord vgPlain_anyElementOfBag( WordBag* );


UWord vgPlain_sizeUniqueBag( WordBag* );
UWord vgPlain_sizeTotalBag( WordBag* );


void vgPlain_initIterBag( WordBag* );
Bool vgPlain_nextIterBag( WordBag*, UWord* pVal, UWord* pCount );
void vgPlain_doneIterBag( WordBag* );
# 52 "hg_main.c" 2
# 1 "../include/pub_tool_debuginfo.h" 1
# 44 "../include/pub_tool_debuginfo.h"
extern Bool vgPlain_get_filename ( Addr a, Char* filename, Int n_filename );
extern Bool vgPlain_get_fnname ( Addr a, Char* fnname, Int n_fnname );
extern Bool vgPlain_get_linenum ( Addr a, UInt* linenum );
extern Bool vgPlain_get_fnname_w_offset
                              ( Addr a, Char* fnname, Int n_fnname );
# 61 "../include/pub_tool_debuginfo.h"
extern Bool vgPlain_get_filename_linenum
                              ( Addr a,
                                       Char* filename, Int n_filename,
                                       Char* dirname, Int n_dirname,
                                       Bool* dirname_available,
                                       UInt* linenum );
# 75 "../include/pub_tool_debuginfo.h"
extern Bool vgPlain_get_fnname_if_entry ( Addr a, Char* fnname, Int n_fnname );

typedef
   enum {
      Vg_FnNameNormal,
      Vg_FnNameMain,
      Vg_FnNameBelowMain
   } Vg_FnNameKind;


extern Vg_FnNameKind vgPlain_get_fnname_kind ( Char* name );


extern Vg_FnNameKind vgPlain_get_fnname_kind_from_IP ( Addr ip );





extern Bool vgPlain_get_datasym_and_offset( Addr data_addr,
                                                Char* dname, Int n_dname,
                                                PtrdiffT* offset );
# 111 "../include/pub_tool_debuginfo.h"
Bool vgPlain_get_data_description(
                void* dname1v,
                void* dname2v,
        Addr data_addr
     );



extern Bool vgPlain_get_objname ( Addr a, Char* objname, Int n_objname );
# 128 "../include/pub_tool_debuginfo.h"
extern Char* vgPlain_describe_IP(Addr eip, Char* buf, Int n_buf);







typedef
   struct {
      PtrdiffT base;
      SizeT szB;
      Bool spRel;
      Bool isVec;
      HChar name[16];
   }
   StackBlock;

extern void*
             vgPlain_di_get_stack_blocks_at_ip( Addr ip, Bool arrays_only );
# 157 "../include/pub_tool_debuginfo.h"
typedef
   struct {
      Addr addr;
      SizeT szB;
      Bool isVec;
      HChar name[16];
      HChar soname[16];
   }
   GlobalBlock;

extern void*
vgPlain_di_get_global_blocks_from_dihandle ( ULong di_handle,
                                          Bool arrays_only );
# 178 "../include/pub_tool_debuginfo.h"
typedef struct _DebugInfo DebugInfo;



DebugInfo* vgPlain_find_DebugInfo ( Addr a );


Addr vgPlain_DebugInfo_get_text_avma ( const DebugInfo *di );
SizeT vgPlain_DebugInfo_get_text_size ( const DebugInfo *di );
Addr vgPlain_DebugInfo_get_plt_avma ( const DebugInfo *di );
SizeT vgPlain_DebugInfo_get_plt_size ( const DebugInfo *di );
Addr vgPlain_DebugInfo_get_gotplt_avma ( const DebugInfo *di );
SizeT vgPlain_DebugInfo_get_gotplt_size ( const DebugInfo *di );
const UChar* vgPlain_DebugInfo_get_soname ( const DebugInfo *di );
const UChar* vgPlain_DebugInfo_get_filename ( const DebugInfo *di );
PtrdiffT vgPlain_DebugInfo_get_text_bias ( const DebugInfo *di );
# 202 "../include/pub_tool_debuginfo.h"
const DebugInfo* vgPlain_next_DebugInfo ( const DebugInfo *di );





Int vgPlain_DebugInfo_syms_howmany ( const DebugInfo *di );
void vgPlain_DebugInfo_syms_getidx ( const DebugInfo *di,
                                   Int idx,
                                          Addr* avma,
                                          Addr* tocptr,
                                          UInt* size,
                                          HChar** name,
                                          Bool* isText,
                                          Bool* isIFunc );



typedef
   enum {
      Vg_SectUnknown,
      Vg_SectText,
      Vg_SectData,
      Vg_SectBSS,
      Vg_SectGOT,
      Vg_SectPLT,
      Vg_SectGOTPLT,
      Vg_SectOPD
   }
   VgSectKind;



const HChar* vgPlain_pp_SectKind( VgSectKind kind );





VgSectKind vgPlain_DebugInfo_sect_kind( UChar* name, SizeT n_name,
                                     Addr a);
# 53 "hg_main.c" 2
# 1 "../include/pub_tool_redir.h" 1
# 54 "hg_main.c" 2
# 1 "../include/pub_tool_vki.h" 1
# 49 "../include/pub_tool_vki.h"
# 1 "../include/vki/vki-linux.h" 1
# 83 "../include/vki/vki-linux.h"
# 1 "../include/vki/vki-posixtypes-x86-linux.h" 1
# 39 "../include/vki/vki-posixtypes-x86-linux.h"
typedef unsigned short __vki_kernel_mode_t;
typedef long __vki_kernel_off_t;
typedef int __vki_kernel_pid_t;
typedef unsigned short __vki_kernel_ipc_pid_t;
typedef unsigned short __vki_kernel_uid_t;
typedef unsigned short __vki_kernel_gid_t;
typedef unsigned int __vki_kernel_size_t;
typedef long __vki_kernel_time_t;
typedef long __vki_kernel_suseconds_t;
typedef long __vki_kernel_clock_t;
typedef int __vki_kernel_timer_t;
typedef int __vki_kernel_clockid_t;
typedef char * __vki_kernel_caddr_t;
typedef unsigned int __vki_kernel_uid32_t;
typedef unsigned int __vki_kernel_gid32_t;

typedef unsigned short __vki_kernel_old_uid_t;
typedef unsigned short __vki_kernel_old_gid_t;

typedef long long __vki_kernel_loff_t;

typedef struct {
 int val[2];
} __vki_kernel_fsid_t;
# 84 "../include/vki/vki-linux.h" 2
# 153 "../include/vki/vki-linux.h"
typedef struct {
 unsigned long fds_bits [(1024/(8 * sizeof(unsigned long)))];
} __vki_kernel_fd_set;

typedef int __vki_kernel_key_t;
typedef int __vki_kernel_mqd_t;





typedef __vki_kernel_fd_set vki_fd_set;
typedef __vki_kernel_mode_t vki_mode_t;
typedef __vki_kernel_off_t vki_off_t;
typedef __vki_kernel_pid_t vki_pid_t;
typedef __vki_kernel_key_t vki_key_t;
typedef __vki_kernel_suseconds_t vki_suseconds_t;
typedef __vki_kernel_timer_t vki_timer_t;
typedef __vki_kernel_clockid_t vki_clockid_t;
typedef __vki_kernel_mqd_t vki_mqd_t;


typedef __vki_kernel_uid32_t vki_uid_t;
typedef __vki_kernel_gid32_t vki_gid_t;

typedef __vki_kernel_old_uid_t vki_old_uid_t;
typedef __vki_kernel_old_gid_t vki_old_gid_t;

typedef __vki_kernel_loff_t vki_loff_t;

typedef __vki_kernel_size_t vki_size_t;
typedef __vki_kernel_time_t vki_time_t;
typedef __vki_kernel_clock_t vki_clock_t;
typedef __vki_kernel_caddr_t vki_caddr_t;

typedef unsigned long vki_u_long;

typedef unsigned int vki_uint;






# 1 "../include/vki/vki-x86-linux.h" 1
# 41 "../include/vki/vki-x86-linux.h"
typedef unsigned char __vki_u8;

typedef __signed__ short __vki_s16;
typedef unsigned short __vki_u16;

typedef __signed__ int __vki_s32;
typedef unsigned int __vki_u32;

typedef __signed__ long long __vki_s64;
typedef unsigned long long __vki_u64;

typedef unsigned short vki_u16;

typedef unsigned int vki_u32;
# 83 "../include/vki/vki-x86-linux.h"
typedef void __vki_signalfn_t(int);
typedef __vki_signalfn_t *__vki_sighandler_t;

typedef void __vki_restorefn_t(void);
typedef __vki_restorefn_t *__vki_sigrestore_t;
# 96 "../include/vki/vki-x86-linux.h"
typedef unsigned long vki_old_sigset_t;

typedef struct {
 unsigned long sig[(64 / 32)];
} vki_sigset_t;
# 162 "../include/vki/vki-x86-linux.h"
struct vki_old_sigaction {




        __vki_sighandler_t ksa_handler;
        vki_old_sigset_t sa_mask;
        unsigned long sa_flags;
        __vki_sigrestore_t sa_restorer;
};

struct vki_sigaction_base {

 __vki_sighandler_t ksa_handler;
 unsigned long sa_flags;
 __vki_sigrestore_t sa_restorer;
 vki_sigset_t sa_mask;
};



typedef struct vki_sigaction_base vki_sigaction_toK_t;
typedef struct vki_sigaction_base vki_sigaction_fromK_t;


typedef struct vki_sigaltstack {
 void *ss_sp;
 int ss_flags;
 vki_size_t ss_size;
} vki_stack_t;





struct _vki_fpreg {
 unsigned short significand[4];
 unsigned short exponent;
};

struct _vki_fpxreg {
 unsigned short significand[4];
 unsigned short exponent;
 unsigned short padding[3];
};

struct _vki_xmmreg {
 unsigned long element[4];
};

struct _vki_fpstate {

 unsigned long cw;
 unsigned long sw;
 unsigned long tag;
 unsigned long ipoff;
 unsigned long cssel;
 unsigned long dataoff;
 unsigned long datasel;
 struct _vki_fpreg _st[8];
 unsigned short status;
 unsigned short magic;


 unsigned long _fxsr_env[6];
 unsigned long mxcsr;
 unsigned long reserved;
 struct _vki_fpxreg _fxsr_st[8];
 struct _vki_xmmreg _xmm[8];
 unsigned long padding[56];
};

struct vki_sigcontext {
 unsigned short gs, __gsh;
 unsigned short fs, __fsh;
 unsigned short es, __esh;
 unsigned short ds, __dsh;
 unsigned long edi;
 unsigned long esi;
 unsigned long ebp;
 unsigned long esp;
 unsigned long ebx;
 unsigned long edx;
 unsigned long ecx;
 unsigned long eax;
 unsigned long trapno;
 unsigned long err;
 unsigned long eip;
 unsigned short cs, __csh;
 unsigned long eflags;
 unsigned long esp_at_signal;
 unsigned short ss, __ssh;
 struct _vki_fpstate * fpstate;
 unsigned long oldmask;
 unsigned long cr2;
};
# 346 "../include/vki/vki-x86-linux.h"
struct vki_stat {
 unsigned long st_dev;
 unsigned long st_ino;
 unsigned short st_mode;
 unsigned short st_nlink;
 unsigned short st_uid;
 unsigned short st_gid;
 unsigned long st_rdev;
 unsigned long st_size;
 unsigned long st_blksize;
 unsigned long st_blocks;
 unsigned long st_atime;
 unsigned long st_atime_nsec;
 unsigned long st_mtime;
 unsigned long st_mtime_nsec;
 unsigned long st_ctime;
 unsigned long st_ctime_nsec;
 unsigned long __unused4;
 unsigned long __unused5;
};

struct vki_stat64 {
 unsigned long long st_dev;
 unsigned char __pad0[4];


 unsigned long __st_ino;

 unsigned int st_mode;
 unsigned int st_nlink;

 unsigned long st_uid;
 unsigned long st_gid;

 unsigned long long st_rdev;
 unsigned char __pad3[4];

 long long st_size;
 unsigned long st_blksize;

 unsigned long st_blocks;
 unsigned long __pad4;

 unsigned long st_atime;
 unsigned long st_atime_nsec;

 unsigned long st_mtime;
 unsigned int st_mtime_nsec;

 unsigned long st_ctime;
 unsigned long st_ctime_nsec;

 unsigned long long st_ino;
};






struct vki_statfs {
 __vki_u32 f_type;
 __vki_u32 f_bsize;
 __vki_u32 f_blocks;
 __vki_u32 f_bfree;
 __vki_u32 f_bavail;
 __vki_u32 f_files;
 __vki_u32 f_ffree;
 __vki_kernel_fsid_t f_fsid;
 __vki_u32 f_namelen;
 __vki_u32 f_frsize;
 __vki_u32 f_spare[5];
};





struct vki_winsize {
 unsigned short ws_row;
 unsigned short ws_col;
 unsigned short ws_xpixel;
 unsigned short ws_ypixel;
};


struct vki_termio {
 unsigned short c_iflag;
 unsigned short c_oflag;
 unsigned short c_cflag;
 unsigned short c_lflag;
 unsigned char c_line;
 unsigned char c_cc[8];
};






typedef unsigned char vki_cc_t;
typedef unsigned int vki_tcflag_t;


struct vki_termios {
 vki_tcflag_t c_iflag;
 vki_tcflag_t c_oflag;
 vki_tcflag_t c_cflag;
 vki_tcflag_t c_lflag;
 vki_cc_t c_line;
 vki_cc_t c_cc[19];
};
# 544 "../include/vki/vki-x86-linux.h"
struct vki_pollfd {
 int fd;
 short events;
 short revents;
};





struct vki_user_i387_struct {
 long cwd;
 long swd;
 long twd;
 long fip;
 long fcs;
 long foo;
 long fos;
 long st_space[20];
};

struct vki_user_fxsr_struct {
 unsigned short cwd;
 unsigned short swd;
 unsigned short twd;
 unsigned short fop;
 long fip;
 long fcs;
 long foo;
 long fos;
 long mxcsr;
 long reserved;
 long st_space[32];
 long xmm_space[32];
 long padding[56];
};







struct vki_user_regs_struct {
 long ebx, ecx, edx, esi, edi, ebp, eax;
 unsigned short ds, __ds, es, __es;
 unsigned short fs, __fs, gs, __gs;
 long orig_eax, eip;
 unsigned short cs, __cs;
 long eflags, esp;
 unsigned short ss, __ss;
};





typedef unsigned long vki_elf_greg_t;


typedef vki_elf_greg_t vki_elf_gregset_t[(sizeof (struct vki_user_regs_struct) / sizeof(vki_elf_greg_t))];

typedef struct vki_user_i387_struct vki_elf_fpregset_t;
typedef struct vki_user_fxsr_struct vki_elf_fpxregset_t;







struct vki_ucontext {
 unsigned long uc_flags;
 struct vki_ucontext *uc_link;
 vki_stack_t uc_stack;
 struct vki_sigcontext uc_mcontext;
 vki_sigset_t uc_sigmask;
};
# 639 "../include/vki/vki-x86-linux.h"
struct vki_user_desc {
 unsigned int entry_number;
 unsigned long base_addr;
 unsigned int limit;
 unsigned int seg_32bit:1;
 unsigned int contents:2;
 unsigned int read_exec_only:1;
 unsigned int limit_in_pages:1;
 unsigned int seg_not_present:1;
 unsigned int useable:1;





 unsigned int reserved:25;
};


typedef struct vki_user_desc vki_modify_ldt_t;





struct vki_ipc64_perm
{
 __vki_kernel_key_t key;
 __vki_kernel_uid32_t uid;
 __vki_kernel_gid32_t gid;
 __vki_kernel_uid32_t cuid;
 __vki_kernel_gid32_t cgid;
 __vki_kernel_mode_t mode;
 unsigned short __pad1;
 unsigned short seq;
 unsigned short __pad2;
 unsigned long __unused1;
 unsigned long __unused2;
};





struct vki_semid64_ds {
 struct vki_ipc64_perm sem_perm;
 __vki_kernel_time_t sem_otime;
 unsigned long __unused1;
 __vki_kernel_time_t sem_ctime;
 unsigned long __unused2;
 unsigned long sem_nsems;
 unsigned long __unused3;
 unsigned long __unused4;
};





struct vki_msqid64_ds {
 struct vki_ipc64_perm msg_perm;
 __vki_kernel_time_t msg_stime;
 unsigned long __unused1;
 __vki_kernel_time_t msg_rtime;
 unsigned long __unused2;
 __vki_kernel_time_t msg_ctime;
 unsigned long __unused3;
 unsigned long msg_cbytes;
 unsigned long msg_qnum;
 unsigned long msg_qbytes;
 __vki_kernel_pid_t msg_lspid;
 __vki_kernel_pid_t msg_lrpid;
 unsigned long __unused4;
 unsigned long __unused5;
};





struct vki_ipc_kludge {
 struct vki_msgbuf *msgp;
 long msgtyp;
};
# 742 "../include/vki/vki-x86-linux.h"
struct vki_shmid64_ds {
 struct vki_ipc64_perm shm_perm;
 vki_size_t shm_segsz;
 __vki_kernel_time_t shm_atime;
 unsigned long __unused1;
 __vki_kernel_time_t shm_dtime;
 unsigned long __unused2;
 __vki_kernel_time_t shm_ctime;
 unsigned long __unused3;
 __vki_kernel_pid_t shm_cpid;
 __vki_kernel_pid_t shm_lpid;
 unsigned long shm_nattch;
 unsigned long __unused4;
 unsigned long __unused5;
};

struct vki_shminfo64 {
 unsigned long shmmax;
 unsigned long shmmin;
 unsigned long shmmni;
 unsigned long shmseg;
 unsigned long shmall;
 unsigned long __unused1;
 unsigned long __unused2;
 unsigned long __unused3;
 unsigned long __unused4;
};
# 815 "../include/vki/vki-x86-linux.h"
struct vki_vm86_regs {



 long ebx;
 long ecx;
 long edx;
 long esi;
 long edi;
 long ebp;
 long eax;
 long __null_ds;
 long __null_es;
 long __null_fs;
 long __null_gs;
 long orig_eax;
 long eip;
 unsigned short cs, __csh;
 long eflags;
 long esp;
 unsigned short ss, __ssh;



 unsigned short es, __esh;
 unsigned short ds, __dsh;
 unsigned short fs, __fsh;
 unsigned short gs, __gsh;
};

struct vki_revectored_struct {
 unsigned long __map[8];
};

struct vki_vm86_struct {
 struct vki_vm86_regs regs;
 unsigned long flags;
 unsigned long screen_bitmap;
 unsigned long cpu_type;
 struct vki_revectored_struct int_revectored;
 struct vki_revectored_struct int21_revectored;
};

struct vki_vm86plus_info_struct {
 unsigned long force_return_for_pic:1;
 unsigned long vm86dbg_active:1;
 unsigned long vm86dbg_TFpendig:1;
 unsigned long unused:28;
 unsigned long is_vm86pus:1;
 unsigned char vm86dbg_intxxtab[32];
};

struct vki_vm86plus_struct {
 struct vki_vm86_regs regs;
 unsigned long flags;
 unsigned long screen_bitmap;
 unsigned long cpu_type;
 struct vki_revectored_struct int_revectored;
 struct vki_revectored_struct int21_revectored;
 struct vki_vm86plus_info_struct vm86plus;
};
# 198 "../include/vki/vki-linux.h" 2
# 216 "../include/vki/vki-linux.h"
typedef __vki_s32 vki_int32_t;

typedef __vki_u8 vki_uint8_t;
typedef __vki_u16 vki_uint16_t;
typedef __vki_u32 vki_uint32_t;
# 232 "../include/vki/vki-linux.h"
struct vki_sysinfo {
 long uptime;
 unsigned long loads[3];
 unsigned long totalram;
 unsigned long freeram;
 unsigned long sharedram;
 unsigned long bufferram;
 unsigned long totalswap;
 unsigned long freeswap;
 unsigned short procs;
 unsigned short pad;
 unsigned long totalhigh;
 unsigned long freehigh;
 unsigned int mem_unit;
 char _f[20-2*sizeof(long)-sizeof(int)];
};
# 258 "../include/vki/vki-linux.h"
struct vki_timespec {
 vki_time_t tv_sec;
 long tv_nsec;
};

struct vki_timeval {
 vki_time_t tv_sec;
 vki_suseconds_t tv_usec;
};

struct vki_timezone {
 int tz_minuteswest;
 int tz_dsttime;
};

struct vki_itimerspec {
        struct vki_timespec it_interval;
        struct vki_timespec it_value;
};

struct vki_itimerval {
 struct vki_timeval it_interval;
 struct vki_timeval it_value;
};





struct vki_timex {
 unsigned int modes;
 long offset;
 long freq;
 long maxerror;
 long esterror;
 int status;
 long constant;
 long precision;
 long tolerance;


 struct vki_timeval time;
 long tick;

 long ppsfreq;
 long jitter;
 int shift;
 long stabil;
 long jitcnt;
 long calcnt;
 long errcnt;
 long stbcnt;

 int :32; int :32; int :32; int :32;
 int :32; int :32; int :32; int :32;
 int :32; int :32; int :32; int :32;
};
# 332 "../include/vki/vki-linux.h"
struct vki_tms {
 vki_clock_t tms_utime;
 vki_clock_t tms_stime;
 vki_clock_t tms_cutime;
 vki_clock_t tms_cstime;
};





struct vki_utimbuf {
 vki_time_t actime;
 vki_time_t modtime;
};
# 367 "../include/vki/vki-linux.h"
struct vki_sched_param {
 int sched_priority;
};







typedef union vki_sigval {
 int sival_int;
 void *sival_ptr;
} vki_sigval_t;
# 402 "../include/vki/vki-linux.h"
typedef struct vki_siginfo {
 int si_signo;
 int si_errno;
 int si_code;

 union {
  int _pad[((128 - (3 * sizeof(int))) / sizeof(int))];


  struct {
   vki_pid_t _pid;
   vki_uid_t _uid;
  } _kill;


  struct {
   vki_timer_t _tid;
   int _overrun;
   char _pad[sizeof( vki_uid_t) - sizeof(int)];
   vki_sigval_t _sigval;
   int _sys_private;
  } _timer;


  struct {
   vki_pid_t _pid;
   vki_uid_t _uid;
   vki_sigval_t _sigval;
  } _rt;


  struct {
   vki_pid_t _pid;
   vki_uid_t _uid;
   int _status;
   vki_clock_t _utime;
   vki_clock_t _stime;
  } _sigchld;


  struct {
   void *_addr;



  } _sigfault;


  struct {
   long _band;
   int _fd;
  } _sigpoll;
 } _sifields;
} vki_siginfo_t;
# 521 "../include/vki/vki-linux.h"
typedef struct vki_sigevent {
 vki_sigval_t sigev_value;
 int sigev_signo;
 int sigev_notify;
 union {
  int _pad[((64 - (sizeof(int) * 2 + sizeof(vki_sigval_t))) / sizeof(int))];
   int _tid;

  struct {
   void (*_function)(vki_sigval_t);
   void *_attribute;
  } _sigev_thread;
 } _sigev_un;
} vki_sigevent_t;
# 569 "../include/vki/vki-linux.h"
enum vki_sock_type {
 VKI_SOCK_STREAM = 1,

};





struct vki_iovec
{
 void *iov_base;
 __vki_kernel_size_t iov_len;
};
# 592 "../include/vki/vki-linux.h"
typedef unsigned short vki_sa_family_t;

struct vki_sockaddr {
 vki_sa_family_t sa_family;
 char sa_data[14];
};

struct vki_msghdr {
 void * msg_name;
 int msg_namelen;
 struct vki_iovec * msg_iov;
 __vki_kernel_size_t msg_iovlen;
 void * msg_control;
 __vki_kernel_size_t msg_controllen;
 unsigned msg_flags;
};

struct vki_cmsghdr {
 __vki_kernel_size_t cmsg_len;
        int cmsg_level;
        int cmsg_type;
};
# 628 "../include/vki/vki-linux.h"
static __inline__ struct vki_cmsghdr * __vki_cmsg_nxthdr(void *__ctl, __vki_kernel_size_t __size,
            struct vki_cmsghdr *__cmsg)
{
 struct vki_cmsghdr * __ptr;

 __ptr = (struct vki_cmsghdr*)(((unsigned char *) __cmsg) + ( ((__cmsg->cmsg_len)+sizeof(long)-1) & ~(sizeof(long)-1) ));
 if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
  return (struct vki_cmsghdr *)0;

 return __ptr;
}

static __inline__ struct vki_cmsghdr * vki_cmsg_nxthdr (struct vki_msghdr *__msg, struct vki_cmsghdr *__cmsg)
{
 return __vki_cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
}
# 659 "../include/vki/vki-linux.h"
struct vki_in_addr {
 __vki_u32 s_addr;
};



struct vki_sockaddr_in {
  vki_sa_family_t sin_family;
  unsigned short int sin_port;
  struct vki_in_addr sin_addr;


  unsigned char __pad[16 - sizeof(short int) -
   sizeof(unsigned short int) - sizeof(struct vki_in_addr)];
};





struct vki_in6_addr
{
 union
 {
  __vki_u8 u6_addr8[16];
  __vki_u16 u6_addr16[8];
  __vki_u32 u6_addr32[4];
 } vki_in6_u;



};

struct vki_sockaddr_in6 {
 unsigned short int sin6_family;
 __vki_u16 sin6_port;
 __vki_u32 sin6_flowinfo;
 struct vki_in6_addr sin6_addr;
 __vki_u32 sin6_scope_id;
};







struct vki_sockaddr_un {
 vki_sa_family_t sun_family;
 char sun_path[108];
};







struct vki_ifmap
{
 unsigned long mem_start;
 unsigned long mem_end;
 unsigned short base_addr;
 unsigned char irq;
 unsigned char dma;
 unsigned char port;

};

struct vki_if_settings
{
 unsigned int type;
 unsigned int size;
 union {



  void *raw_hdlc;
  void *cisco;
  void *fr;
  void *fr_pvc;
  void *fr_pvc_info;


  void *sync;
  void *te1;
 } ifs_ifsu;
};

struct vki_ifreq
{

 union
 {
  char ifrn_name[16];
 } ifr_ifrn;

 union {
  struct vki_sockaddr ifru_addr;
  struct vki_sockaddr ifru_dstaddr;
  struct vki_sockaddr ifru_broadaddr;
  struct vki_sockaddr ifru_netmask;
  struct vki_sockaddr ifru_hwaddr;
  short ifru_flags;
  int ifru_ivalue;
  int ifru_mtu;
  struct vki_ifmap ifru_map;
  char ifru_slave[16];
  char ifru_newname[16];
  void * ifru_data;
  struct vki_if_settings ifru_settings;
 } ifr_ifru;
};
# 791 "../include/vki/vki-linux.h"
struct vki_ifconf
{
 int ifc_len;
 union
 {
  char *ifcu_buf;
  struct vki_ifreq *ifcu_req;
 } ifc_ifcu;
};






struct vki_arpreq {
  struct vki_sockaddr arp_pa;
  struct vki_sockaddr arp_ha;
  int arp_flags;
  struct vki_sockaddr arp_netmask;
  char arp_dev[16];
};





struct vki_rtentry
{
 unsigned long rt_pad1;
 struct vki_sockaddr rt_dst;
 struct vki_sockaddr rt_gateway;
 struct vki_sockaddr rt_genmask;
 unsigned short rt_flags;
 short rt_pad2;
 unsigned long rt_pad3;
 void *rt_pad4;
 short rt_metric;
 char *rt_dev;
 unsigned long rt_mtu;




 unsigned long rt_window;
 unsigned short rt_irtt;
};





typedef __vki_s32 vki_sctp_assoc_t;

enum vki_sctp_optname {
 VKI_SCTP_RTOINFO,

 VKI_SCTP_ASSOCINFO,

 VKI_SCTP_INITMSG,

 VKI_SCTP_NODELAY,

 VKI_SCTP_AUTOCLOSE,

 VKI_SCTP_SET_PEER_PRIMARY_ADDR,

 VKI_SCTP_PRIMARY_ADDR,

 VKI_SCTP_ADAPTION_LAYER,

 VKI_SCTP_DISABLE_FRAGMENTS,

 VKI_SCTP_PEER_ADDR_PARAMS,

 VKI_SCTP_DEFAULT_SEND_PARAM,

 VKI_SCTP_EVENTS,

 VKI_SCTP_I_WANT_MAPPED_V4_ADDR,

 VKI_SCTP_MAXSEG,

 VKI_SCTP_STATUS,

 VKI_SCTP_GET_PEER_ADDR_INFO,





 VKI_SCTP_SOCKOPT_BINDX_ADD = 100,

 VKI_SCTP_SOCKOPT_BINDX_REM,

 VKI_SCTP_SOCKOPT_PEELOFF,

 VKI_SCTP_GET_PEER_ADDRS_NUM,

 VKI_SCTP_GET_PEER_ADDRS,

 VKI_SCTP_GET_LOCAL_ADDRS_NUM,

 VKI_SCTP_GET_LOCAL_ADDRS,

 VKI_SCTP_SOCKOPT_CONNECTX,

};

struct vki_sctp_getaddrs {
 vki_sctp_assoc_t assoc_id;
 int addr_num;
 struct vki_sockaddr *addrs;
};





struct vki_rusage {
 struct vki_timeval ru_utime;
 struct vki_timeval ru_stime;
 long ru_maxrss;
 long ru_ixrss;
 long ru_idrss;
 long ru_isrss;
 long ru_minflt;
 long ru_majflt;
 long ru_nswap;
 long ru_inblock;
 long ru_oublock;
 long ru_msgsnd;
 long ru_msgrcv;
 long ru_nsignals;
 long ru_nvcsw;
 long ru_nivcsw;
};

struct vki_rlimit {
 unsigned long rlim_cur;
 unsigned long rlim_max;
};





struct vki_elf_siginfo
{
 int si_signo;
 int si_code;
 int si_errno;
};


struct vki_elf_prstatus
{
 struct vki_elf_siginfo pr_info;
 short pr_cursig;
 unsigned long pr_sigpend;
 unsigned long pr_sighold;
 vki_pid_t pr_pid;
 vki_pid_t pr_ppid;
 vki_pid_t pr_pgrp;
 vki_pid_t pr_sid;
 struct vki_timeval pr_utime;
 struct vki_timeval pr_stime;
 struct vki_timeval pr_cutime;
 struct vki_timeval pr_cstime;
 vki_elf_gregset_t pr_reg;
 int pr_fpvalid;
};



struct vki_elf_prpsinfo
{
 char pr_state;
 char pr_sname;
 char pr_zomb;
 char pr_nice;
 unsigned long pr_flag;
 __vki_kernel_uid_t pr_uid;
 __vki_kernel_gid_t pr_gid;
 vki_pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;

 char pr_fname[16];
 char pr_psargs[(80)];
};
# 996 "../include/vki/vki-linux.h"
struct vki_epoll_event {
 __vki_u32 events;
 __vki_u64 data;
} ;






struct vki_mq_attr {
 long mq_flags;
 long mq_maxmsg;
 long mq_msgsize;
 long mq_curmsgs;
 long __reserved[4];
};





struct vki_new_utsname {
 char sysname[65];
 char nodename[65];
 char release[65];
 char version[65];
 char machine[65];
 char domainname[65];
};






struct vki_mii_ioctl_data {
 vki_u16 phy_id;
 vki_u16 reg_num;
 vki_u16 val_in;
 vki_u16 val_out;
};
# 1051 "../include/vki/vki-linux.h"
typedef struct __vki_user_cap_header_struct {
 __vki_u32 version;
 int pid;
} *vki_cap_user_header_t;

typedef struct __vki_user_cap_data_struct {
        __vki_u32 effective;
        __vki_u32 permitted;
        __vki_u32 inheritable;
} *vki_cap_user_data_t;
# 1075 "../include/vki/vki-linux.h"
struct vki_ipc_perm
{
 __vki_kernel_key_t key;
 __vki_kernel_uid_t uid;
 __vki_kernel_gid_t gid;
 __vki_kernel_uid_t cuid;
 __vki_kernel_gid_t cgid;
 __vki_kernel_mode_t mode;
 unsigned short seq;
};
# 1110 "../include/vki/vki-linux.h"
struct vki_semid_ds {
 struct vki_ipc_perm sem_perm;
 __vki_kernel_time_t sem_otime;
 __vki_kernel_time_t sem_ctime;

 void *sem_base;
 void *sem_pending;
 void **sem_pending_last;
 void *undo;
 unsigned short sem_nsems;
};

struct vki_sembuf {
 unsigned short sem_num;
 short sem_op;
 short sem_flg;
};

union vki_semun {
 int val;
 struct vki_semid_ds *buf;
 unsigned short *array;
 struct vki_seminfo *__buf;
 void *__pad;
};

struct vki_seminfo {
 int semmap;
 int semmni;
 int semmns;
 int semmnu;
 int semmsl;
 int semopm;
 int semume;
 int semusz;
 int semvmx;
 int semaem;
};
# 1212 "../include/vki/vki-linux.h"
struct vki_robust_list {
 struct vki_robust_list *next;
};

struct vki_robust_list_head {



 struct vki_robust_list list;







 long futex_offset;
# 1240 "../include/vki/vki-linux.h"
 struct vki_robust_list *list_op_pending;
};
# 1292 "../include/vki/vki-linux.h"
struct vki_dirent {
 long d_ino;
 __vki_kernel_off_t d_off;
 unsigned short d_reclen;
 char d_name[256];
};
# 1319 "../include/vki/vki-linux.h"
struct __vki_sysctl_args {
 int *name;
 int nlen;
 void *oldval;
 vki_size_t *oldlenp;
 void *newval;
 vki_size_t newlen;
 unsigned long __unused[4];
};





typedef unsigned long vki_aio_context_t;

enum {
 VKI_IOCB_CMD_PREAD = 0,
 VKI_IOCB_CMD_PWRITE = 1,
 VKI_IOCB_CMD_FSYNC = 2,
 VKI_IOCB_CMD_FDSYNC = 3,
 VKI_IOCB_CMD_PREADV = 7,
 VKI_IOCB_CMD_PWRITEV = 8,
};


struct vki_io_event {
 __vki_u64 data;
 __vki_u64 obj;


 __vki_s64 result;
 __vki_s64 result2;
};
# 1362 "../include/vki/vki-linux.h"
struct vki_iocb {

 __vki_u64 aio_data;
 __vki_u32 aio_key, aio_reserved1;



 __vki_u16 aio_lio_opcode;
 __vki_s16 aio_reqprio;
 __vki_u32 aio_fildes;

 __vki_u64 aio_buf;
 __vki_u64 aio_nbytes;
 __vki_s64 aio_offset;


 __vki_u64 aio_reserved2;
 __vki_u64 aio_reserved3;
};





struct vki_aio_ring {
 unsigned id;
 unsigned nr;
 unsigned head;
 unsigned tail;

 unsigned magic;
 unsigned compat_features;
 unsigned incompat_features;
 unsigned header_length;

 struct vki_io_event io_events[0];
};
# 1407 "../include/vki/vki-linux.h"
struct vki_msqid_ds {
 struct vki_ipc_perm msg_perm;
 struct vki_msg *msg_first;
 struct vki_msg *msg_last;
 __vki_kernel_time_t msg_stime;
 __vki_kernel_time_t msg_rtime;
 __vki_kernel_time_t msg_ctime;
 unsigned long msg_lcbytes;
 unsigned long msg_lqbytes;
 unsigned short msg_cbytes;
 unsigned short msg_qnum;
 unsigned short msg_qbytes;
 __vki_kernel_ipc_pid_t msg_lspid;
 __vki_kernel_ipc_pid_t msg_lrpid;
};

struct vki_msgbuf {
 long mtype;
 char mtext[1];
};

struct vki_msginfo {
 int msgpool;
 int msgmap;
 int msgmax;
 int msgmnb;
 int msgmni;
 int msgssz;
 int msgtql;
 unsigned short msgseg;
};





struct vki_shmid_ds {
 struct vki_ipc_perm shm_perm;
 int shm_segsz;
 __vki_kernel_time_t shm_atime;
 __vki_kernel_time_t shm_dtime;
 __vki_kernel_time_t shm_ctime;
 __vki_kernel_ipc_pid_t shm_cpid;
 __vki_kernel_ipc_pid_t shm_lpid;
 unsigned short shm_nattch;
 unsigned short shm_unused;
 void *shm_unused2;
 void *shm_unused3;
};
# 1464 "../include/vki/vki-linux.h"
struct vki_shminfo {
 int shmmax;
 int shmmin;
 int shmmni;
 int shmseg;
 int shmall;
};

struct vki_shm_info {
 int used_ids;
 unsigned long shm_tot;
 unsigned long shm_rss;
 unsigned long shm_swp;
 unsigned long swap_attempts;
 unsigned long swap_successes;
};





struct vki_rtc_time {
 int tm_sec;
 int tm_min;
 int tm_hour;
 int tm_mday;
 int tm_mon;
 int tm_year;
 int tm_wday;
 int tm_yday;
 int tm_isdst;
};
# 1525 "../include/vki/vki-linux.h"
typedef struct {
  char name[10];
  char phone[32];
  int outgoing;
} vki_isdn_net_ioctl_phone;
# 1597 "../include/vki/vki-linux.h"
struct vki_ppdev_frob_struct {
 unsigned char mask;
 unsigned char val;
};
# 1671 "../include/vki/vki-linux.h"
typedef struct vki_sg_io_hdr
{
    int interface_id;
    int dxfer_direction;
    unsigned char cmd_len;
    unsigned char mx_sb_len;
    unsigned short iovec_count;
    unsigned int dxfer_len;
    void *dxferp;

    unsigned char *cmdp;
    void *sbp;
    unsigned int timeout;
    unsigned int flags;
    int pack_id;
    void * usr_ptr;
    unsigned char status;
    unsigned char masked_status;
    unsigned char msg_status;
    unsigned char sb_len_wr;
    unsigned short host_status;
    unsigned short driver_status;
    int resid;
    unsigned int duration;
    unsigned int info;
} vki_sg_io_hdr_t;

typedef struct vki_sg_scsi_id {
    int host_no;
    int channel;
    int scsi_id;
    int lun;
    int scsi_type;
    short h_cmd_per_lun;
    short d_queue_depth;
    int unused[2];
} vki_sg_scsi_id_t;
# 1756 "../include/vki/vki-linux.h"
struct vki_cdrom_msf0
{
 __vki_u8 minute;
 __vki_u8 second;
 __vki_u8 frame;
};

union vki_cdrom_addr
{
 struct vki_cdrom_msf0 msf;
 int lba;
};

struct vki_cdrom_msf
{
 __vki_u8 cdmsf_min0;
 __vki_u8 cdmsf_sec0;
 __vki_u8 cdmsf_frame0;
 __vki_u8 cdmsf_min1;
 __vki_u8 cdmsf_sec1;
 __vki_u8 cdmsf_frame1;
};

struct vki_cdrom_tochdr
{
 __vki_u8 cdth_trk0;
 __vki_u8 cdth_trk1;
};

struct vki_cdrom_volctrl
{
 __vki_u8 channel0;
 __vki_u8 channel1;
 __vki_u8 channel2;
 __vki_u8 channel3;
};

struct vki_cdrom_subchnl
{
 __vki_u8 cdsc_format;
 __vki_u8 cdsc_audiostatus;
 __vki_u8 cdsc_adr: 4;
 __vki_u8 cdsc_ctrl: 4;
 __vki_u8 cdsc_trk;
 __vki_u8 cdsc_ind;
 union vki_cdrom_addr cdsc_absaddr;
 union vki_cdrom_addr cdsc_reladdr;
};

struct vki_cdrom_tocentry
{
 __vki_u8 cdte_track;
 __vki_u8 cdte_adr :4;
 __vki_u8 cdte_ctrl :4;
 __vki_u8 cdte_format;
 union vki_cdrom_addr cdte_addr;
 __vki_u8 cdte_datamode;
};

struct vki_cdrom_read
{
 int cdread_lba;
 char *cdread_bufaddr;
 int cdread_buflen;
};

struct vki_cdrom_read_audio
{
 union vki_cdrom_addr addr;
 __vki_u8 addr_format;
 int nframes;
 __vki_u8 *buf;
};

struct vki_cdrom_multisession
{
 union vki_cdrom_addr addr;


 __vki_u8 xa_flag;
 __vki_u8 addr_format;
};

struct vki_cdrom_mcn
{
  __vki_u8 medium_catalog_number[14];
};



struct vki_cdrom_generic_command
{
 unsigned char cmd[12];
 unsigned char *buffer;
 unsigned int buflen;
 int stat;

 void *sense;
 unsigned char data_direction;
 int quiet;
 int timeout;
 void *reserved[1];
};
# 1913 "../include/vki/vki-linux.h"
typedef struct vki_audio_buf_info {
   int fragments;
   int fragstotal;
   int fragsize;

   int bytes;

  } vki_audio_buf_info;
# 1950 "../include/vki/vki-linux.h"
struct vki_hd_geometry {
      unsigned char heads;
      unsigned char sectors;
      unsigned short cylinders;
      unsigned long start;
};
# 1972 "../include/vki/vki-linux.h"
struct vki_fb_fix_screeninfo {
 char id[16];
 unsigned long smem_start;

 __vki_u32 smem_len;
 __vki_u32 type;
 __vki_u32 type_aux;
 __vki_u32 visual;
 __vki_u16 xpanstep;
 __vki_u16 ypanstep;
 __vki_u16 ywrapstep;
 __vki_u32 line_length;
 unsigned long mmio_start;

 __vki_u32 mmio_len;
 __vki_u32 accel;

 __vki_u16 reserved[3];
};

struct vki_fb_bitfield {
 __vki_u32 offset;
 __vki_u32 length;
 __vki_u32 msb_right;

};

struct vki_fb_var_screeninfo {
 __vki_u32 xres;
 __vki_u32 yres;
 __vki_u32 xres_virtual;
 __vki_u32 yres_virtual;
 __vki_u32 xoffset;
 __vki_u32 yoffset;

 __vki_u32 bits_per_pixel;
 __vki_u32 grayscale;

 struct vki_fb_bitfield red;
 struct vki_fb_bitfield green;
 struct vki_fb_bitfield blue;
 struct vki_fb_bitfield transp;

 __vki_u32 nonstd;

 __vki_u32 activate;

 __vki_u32 height;
 __vki_u32 width;

 __vki_u32 accel_flags;


 __vki_u32 pixclock;
 __vki_u32 left_margin;
 __vki_u32 right_margin;
 __vki_u32 upper_margin;
 __vki_u32 lower_margin;
 __vki_u32 hsync_len;
 __vki_u32 vsync_len;
 __vki_u32 sync;
 __vki_u32 vmode;
 __vki_u32 rotate;
 __vki_u32 reserved[5];
};
# 2047 "../include/vki/vki-linux.h"
struct vki_consolefontdesc {
 unsigned short charcount;
 unsigned short charheight;
 char *chardata;
};
# 2084 "../include/vki/vki-linux.h"
struct vki_unipair {
 unsigned short unicode;
 unsigned short fontpos;
};
struct vki_unimapdesc {
 unsigned short entry_ct;
 struct vki_unipair *entries;
};


struct vki_unimapinit {
 unsigned short advised_hashsize;
 unsigned short advised_hashstep;
 unsigned short advised_hashlevel;
};
# 2109 "../include/vki/vki-linux.h"
struct vki_kbentry {
 unsigned char kb_table;
 unsigned char kb_index;
 unsigned short kb_value;
};



struct vki_kbsentry {
 unsigned char kb_func;
 unsigned char kb_string[512];
};



struct vki_kbdiacr {
        unsigned char diacr, base, result;
};
struct vki_kbdiacrs {
        unsigned int kb_cnt;
 struct vki_kbdiacr kbdiacr[256];
};



struct vki_kbkeycode {
 unsigned int scancode, keycode;
};





struct vki_kbd_repeat {
 int delay;
 int period;

};





struct vki_console_font_op {
 unsigned int op;
 unsigned int flags;
 unsigned int width, height;
 unsigned int charcount;
 unsigned char *data;
};
# 2169 "../include/vki/vki-linux.h"
typedef __vki_kernel_uid32_t vki_qid_t;
# 2191 "../include/vki/vki-linux.h"
enum {
 VKI_SNDRV_PCM_IOCTL_HW_FREE = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x12)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_HWSYNC = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x22)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_PREPARE = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x40)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_RESET = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x41)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_START = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x42)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_DROP = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x43)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_DRAIN = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x44)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_PAUSE = (((1U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x45)) << 0) | (((((sizeof(struct { int:-!((sizeof(int) == sizeof(int[1]) && sizeof(int) < (1 << 14))); })) + sizeof(int)))) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_RESUME = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x47)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_XRUN = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x48)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_LINK = (((1U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x60)) << 0) | (((((sizeof(struct { int:-!((sizeof(int) == sizeof(int[1]) && sizeof(int) < (1 << 14))); })) + sizeof(int)))) << ((0 +8)+8))),
 VKI_SNDRV_PCM_IOCTL_UNLINK = (((0U) << (((0 +8)+8)+14)) | ((('A')) << (0 +8)) | (((0x61)) << 0) | ((0) << ((0 +8)+8))),
};

enum {
 VKI_SNDRV_TIMER_IOCTL_START = (((0U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((0xa0)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_TIMER_IOCTL_STOP = (((0U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((0xa1)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_TIMER_IOCTL_CONTINUE = (((0U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((0xa2)) << 0) | ((0) << ((0 +8)+8))),
 VKI_SNDRV_TIMER_IOCTL_PAUSE = (((0U) << (((0 +8)+8)+14)) | ((('T')) << (0 +8)) | (((0xa3)) << 0) | ((0) << ((0 +8)+8))),
};





struct vki_serial_icounter_struct {
 int cts, dsr, rng, dcd;
 int rx, tx;
 int frame, overrun, parity, brk;
 int buf_overrun;
 int reserved[9];
};







struct vki_vt_mode {
 char mode;
 char waitv;
 short relsig;
 short acqsig;
 short frsig;
};



struct vki_vt_stat {
 unsigned short v_active;
 unsigned short v_signal;
 unsigned short v_state;
};
# 2255 "../include/vki/vki-linux.h"
struct vki_vt_sizes {
 unsigned short v_rows;
 unsigned short v_cols;
 unsigned short v_scrollsize;
};


struct vki_vt_consize {
 unsigned short v_rows;
 unsigned short v_cols;
 unsigned short v_vlin;
 unsigned short v_clin;
 unsigned short v_vcol;
 unsigned short v_ccol;
};
# 2330 "../include/vki/vki-linux.h"
struct vki_usbdevfs_ctrltransfer {
 __vki_u8 bRequestType;
 __vki_u8 bRequest;
 __vki_u16 wValue;
 __vki_u16 wIndex;
 __vki_u16 wLength;
 __vki_u32 timeout;
  void *data;
};

struct vki_usbdevfs_bulktransfer {
 unsigned int ep;
 unsigned int len;
 unsigned int timeout;
 void *data;
};



struct vki_usbdevfs_getdriver {
 unsigned int interface;
 char driver[255 + 1];
};

struct vki_usbdevfs_connectinfo {
 unsigned int devnum;
 unsigned char slow;
};

struct vki_usbdevfs_iso_packet_desc {
 unsigned int length;
 unsigned int actual_length;
 unsigned int status;
};

struct vki_usbdevfs_urb {
 unsigned char type;
 unsigned char endpoint;
 int status;
 unsigned int flags;
 void *buffer;
 int buffer_length;
 int actual_length;
 int start_frame;
 int number_of_packets;
 int error_count;
 unsigned int signr;
 void *usercontext;
 struct vki_usbdevfs_iso_packet_desc iso_frame_desc[0];
};

struct vki_usbdevfs_ioctl {
 int ifno;
 int ioctl_code;

 void *data;
};
# 2404 "../include/vki/vki-linux.h"
struct vki_usbdevfs_setuppacket {
       __vki_u8 bRequestType;
       __vki_u8 bRequest;
       __vki_u16 wValue;
       __vki_u16 wIndex;
       __vki_u16 wLength;
};
# 2454 "../include/vki/vki-linux.h"
typedef vki_int32_t vki_key_serial_t;


typedef vki_uint32_t vki_key_perm_t;
# 2551 "../include/vki/vki-linux.h"
struct vki_iw_param
{
  __vki_s32 value;
  __vki_u8 fixed;
  __vki_u8 disabled;
  __vki_u16 flags;
};

struct vki_iw_point
{
  void *pointer;
  __vki_u16 length;
  __vki_u16 flags;
};

struct vki_iw_freq
{
 __vki_s32 m;
 __vki_s16 e;
 __vki_u8 i;
 __vki_u8 flags;
};

struct vki_iw_quality
{
 __vki_u8 qual;

 __vki_u8 level;
 __vki_u8 noise;
 __vki_u8 updated;
};

union vki_iwreq_data
{

 char name[16];



 struct vki_iw_point essid;
 struct vki_iw_param nwid;
 struct vki_iw_freq freq;



 struct vki_iw_param sens;
 struct vki_iw_param bitrate;
 struct vki_iw_param txpower;
 struct vki_iw_param rts;
 struct vki_iw_param frag;
 __vki_u32 mode;
 struct vki_iw_param retry;

 struct vki_iw_point encoding;
 struct vki_iw_param power;
 struct vki_iw_quality qual;

 struct vki_sockaddr ap_addr;
 struct vki_sockaddr addr;

 struct vki_iw_param param;
 struct vki_iw_point data;
};

struct vki_iwreq
{
 union
 {
  char ifrn_name[16];
 } ifr_ifrn;


 union vki_iwreq_data u;
};





struct vki_perf_counter_attr {




 __vki_u32 type;




 __vki_u32 size;




 __vki_u64 config;

 union {
  __vki_u64 sample_period;
  __vki_u64 sample_freq;
 };

 __vki_u64 sample_type;
 __vki_u64 read_format;

 __vki_u64 disabled : 1,
     inherit : 1,
     pinned : 1,
     exclusive : 1,
     exclude_user : 1,
     exclude_kernel : 1,
     exclude_hv : 1,
     exclude_idle : 1,
     mmap : 1,
     comm : 1,
     freq : 1,
     inherit_stat : 1,
     enable_on_exec : 1,
     task : 1,

     __reserved_1 : 50;

 __vki_u32 wakeup_events;
 __vki_u32 __reserved_2;

 __vki_u64 __reserved_3;
};





struct vki_getcpu_cache {
 unsigned long blob[128 / sizeof(long)];
};
# 50 "../include/pub_tool_vki.h" 2
# 55 "hg_main.c" 2
# 1 "../include/pub_tool_libcproc.h" 1
# 39 "../include/pub_tool_libcproc.h"
extern Char** vgPlain_client_envp;


extern Char* vgPlain_getenv ( Char* name );


extern const Char *vgPlain_libdir;



extern const Char* vgPlain_LD_PRELOAD_var_name;





extern Int vgPlain_waitpid( Int pid, Int *status, Int options );
extern Int vgPlain_system ( Char* cmd );
extern Int vgPlain_fork ( void);
extern void vgPlain_execv ( Char* filename, Char** argv );





extern Int vgPlain_getrlimit ( Int resource, struct vki_rlimit *rlim );
extern Int vgPlain_setrlimit ( Int resource, const struct vki_rlimit *rlim );





extern Int vgPlain_gettid ( void );
extern Int vgPlain_getpid ( void );
extern Int vgPlain_getppid ( void );
extern Int vgPlain_getpgrp ( void );
extern Int vgPlain_geteuid ( void );
extern Int vgPlain_getegid ( void );
# 85 "../include/pub_tool_libcproc.h"
extern UInt vgPlain_read_millisecond_timer ( void );





typedef void (*vg_atfork_t)(ThreadId);
extern void vgPlain_atfork(vg_atfork_t pre, vg_atfork_t parent, vg_atfork_t child);
# 56 "hg_main.c" 2
# 1 "../include/pub_tool_aspacemgr.h" 1
# 39 "../include/pub_tool_aspacemgr.h"
typedef
   enum {
      SkFree,
      SkAnonC,
      SkAnonV,
      SkFileC,
      SkFileV,
      SkShmC,
      SkResvn
   }
   SegKind;


typedef
   enum {
      SmLower,
      SmFixed,
      SmUpper
   }
   ShrinkMode;
# 93 "../include/pub_tool_aspacemgr.h"
typedef
   struct {
      SegKind kind;

      Addr start;
      Addr end;

      ShrinkMode smode;

      ULong dev;
      ULong ino;
      Off64T offset;
      UInt mode;
      Int fnIdx;

      Bool hasR;
      Bool hasW;
      Bool hasX;
      Bool hasT;

      Bool isCH;

      Bool mark;
   }
   NSegment;
# 133 "../include/pub_tool_aspacemgr.h"
extern Int vgPlain_am_get_segment_starts( Addr* starts, Int nStarts );



extern NSegment const * vgPlain_am_find_nsegment ( Addr a );


extern HChar* vgPlain_am_get_filename( NSegment const * );


extern Bool vgPlain_am_is_valid_for_client ( Addr start, SizeT len,
                                          UInt prot );



extern void* vgPlain_am_shadow_alloc(SizeT size);



extern SysRes vgPlain_am_munmap_valgrind( Addr start, SizeT length );
# 57 "hg_main.c" 2

# 1 "hg_basics.h" 1
# 42 "hg_basics.h"
void* vgHelgrind_zalloc ( HChar* cc, SizeT n );
void vgHelgrind_free ( void* p );
Char* vgHelgrind_strdup ( HChar* cc, const Char* s );

static inline Bool vgHelgrind_is_sane_ThreadId ( ThreadId coretid ) {
   return coretid >= 0 && coretid < 500;
}
# 68 "hg_basics.h"
extern Bool vgHelgrind_clo_track_lockorders;




extern Bool vgHelgrind_clo_cmp_race_err_addrs;
# 94 "hg_basics.h"
extern UWord vgHelgrind_clo_history_level;





extern UWord vgHelgrind_clo_conflict_cache_size;



extern Word vgHelgrind_clo_sanity_flags;
# 59 "hg_main.c" 2
# 1 "hg_wordset.h" 1
# 45 "hg_wordset.h"
typedef struct _WordSetU WordSetU;

typedef UInt WordSet;


WordSetU* vgHelgrind_newWordSetU ( void* (*alloc_nofail)( HChar*, SizeT ),
                             HChar* cc,
                             void (*dealloc)(void*),
                             Word cacheSize );


void vgHelgrind_deleteWordSetU ( WordSetU* );


UWord vgHelgrind_cardinalityWSU ( WordSetU* );


void vgHelgrind_ppWSUstats ( WordSetU* wsu, HChar* name );






WordSet vgHelgrind_emptyWS ( WordSetU* );
WordSet vgHelgrind_addToWS ( WordSetU*, WordSet, UWord );
WordSet vgHelgrind_delFromWS ( WordSetU*, WordSet, UWord );
WordSet vgHelgrind_unionWS ( WordSetU*, WordSet, WordSet );
WordSet vgHelgrind_intersectWS ( WordSetU*, WordSet, WordSet );
WordSet vgHelgrind_minusWS ( WordSetU*, WordSet, WordSet );
Bool vgHelgrind_isEmptyWS ( WordSetU*, WordSet );
Bool vgHelgrind_isSingletonWS ( WordSetU*, WordSet, UWord );
UWord vgHelgrind_anyElementOfWS ( WordSetU*, WordSet );
UWord vgHelgrind_cardinalityWS ( WordSetU*, WordSet );
Bool vgHelgrind_elemWS ( WordSetU*, WordSet, UWord );
WordSet vgHelgrind_doubletonWS ( WordSetU*, UWord, UWord );
WordSet vgHelgrind_singletonWS ( WordSetU*, UWord );
WordSet vgHelgrind_isSubsetOf ( WordSetU*, WordSet, WordSet );

Bool vgHelgrind_plausibleWS ( WordSetU*, WordSet );
Bool vgHelgrind_saneWS_SLOW ( WordSetU*, WordSet );

void vgHelgrind_ppWS ( WordSetU*, WordSet );
void vgHelgrind_getPayloadWS ( UWord** words, UWord* nWords,
                             WordSetU*, WordSet );
# 60 "hg_main.c" 2
# 1 "hg_lock_n_thread.h" 1
# 51 "hg_lock_n_thread.h"
typedef WordSet WordSetID;



typedef struct _SO SO;






typedef struct _Thr Thr;
typedef UInt ThrID;
# 81 "hg_lock_n_thread.h"
typedef
   struct _Thread {

      struct _Thread* admin;
      UInt magic;
      Thr* hbthr;
      ThreadId coretid;

      WordSetID locksetA;
      WordSetID locksetW;


      ExeContext* created_at;
      Bool announced;

      Int errmsg_index;
   }
   Thread;
# 111 "hg_lock_n_thread.h"
typedef
   enum {
      LK_mbRec=1001,
      LK_nonRec,
      LK_rdwr
   }
   LockKind;

typedef
   struct _Lock {

      struct _Lock* admin_next;
      struct _Lock* admin_prev;
      ULong unique;
      UInt magic;


      ExeContext* appeared_at;



      ExeContext* acquired_at;

      SO* hbso;
      Addr guestaddr;
      LockKind kind;

      Bool heldW;
      WordBag* heldBy;
# 154 "hg_lock_n_thread.h"
   }
   Lock;





Bool vgHelgrind_is_sane_Thread ( Thread* thr );
Bool vgHelgrind_is_sane_LockP ( Lock* lock );
Bool vgHelgrind_is_sane_LockN ( Lock* lock );
Bool vgHelgrind_is_sane_LockNorP ( Lock* lock );
# 61 "hg_main.c" 2
# 1 "hg_errors.h" 1
# 38 "hg_errors.h"
Bool vgHelgrind_eq_Error ( VgRes not_used, Error* e1, Error* e2 );
void vgHelgrind_before_pp_Error ( Error* err );
void vgHelgrind_pp_Error ( Error* err );
UInt vgHelgrind_update_extra ( Error* err );
Bool vgHelgrind_recognised_suppression ( Char* name, Supp *su );
Bool vgHelgrind_read_extra_suppression_info ( Int fd, Char** bufpp, SizeT* nBufp,
                                         Supp* su );
Bool vgHelgrind_error_matches_suppression ( Error* err, Supp* su );
Char* vgHelgrind_get_error_name ( Error* err );
Bool vgHelgrind_get_extra_suppression_info ( Error* err,
                                               Char* buf, Int nBuf );


void vgHelgrind_record_error_Race ( Thread* thr,
                              Addr data_addr, Int szB, Bool isWrite,
                              Thread* h1_confthr,
                              ExeContext* h1_ct_segstart,
                              ExeContext* h1_ct_mbsegend );
void vgHelgrind_record_error_UnlockUnlocked ( Thread*, Lock* );
void vgHelgrind_record_error_UnlockForeign ( Thread*, Thread*, Lock* );
void vgHelgrind_record_error_UnlockBogus ( Thread*, Addr );
void vgHelgrind_record_error_PthAPIerror ( Thread*, HChar*, Word, HChar* );
void vgHelgrind_record_error_LockOrder ( Thread*, Addr, Addr,
                                        ExeContext*, ExeContext* );
void vgHelgrind_record_error_Misc_w_aux ( Thread*, HChar* errstr,
                                        HChar* auxstr, ExeContext* auxctx );
void vgHelgrind_record_error_Misc ( Thread* thr, HChar* errstr );



extern ULong vgHelgrind_stats__LockN_to_P_queries;
extern ULong vgHelgrind_stats__LockN_to_P_get_map_size ( void );
extern ULong vgHelgrind_stats__string_table_queries;
extern ULong vgHelgrind_stats__string_table_get_map_size ( void );
# 80 "hg_errors.h"
Bool vgHelgrind_mm_find_containing_block( ExeContext** where,
                                           Addr* payload,
                                           SizeT* szB,
                                    Addr data_addr );
# 62 "hg_main.c" 2

# 1 "libhb.h" 1
# 45 "libhb.h"
Thr* libhb_init (
        void (*get_stacktrace)( Thr*, Addr*, UWord ),
        ExeContext* (*get_EC)( Thr* )
     );



void libhb_shutdown ( Bool show_stats );


Thr* libhb_create ( Thr* parent );


void libhb_async_exit ( Thr* exitter );




SO* libhb_so_alloc ( void );


void libhb_so_dealloc ( SO* so );
# 83 "libhb.h"
void libhb_so_send ( Thr* thr, SO* so, Bool strong_send );
# 93 "libhb.h"
void libhb_so_recv ( Thr* thr, SO* so, Bool strong_recv );


Bool libhb_so_everSent ( SO* so );
# 112 "libhb.h"
void zsm_sapply08_f__msmcwrite ( Thr* thr, Addr a );
void zsm_sapply16_f__msmcwrite ( Thr* thr, Addr a );
void zsm_sapply32_f__msmcwrite ( Thr* thr, Addr a );
void zsm_sapply64_f__msmcwrite ( Thr* thr, Addr a );
void zsm_sapplyNN_f__msmcwrite ( Thr* thr, Addr a, SizeT len );

void zsm_sapply08_f__msmcread ( Thr* thr, Addr a );
void zsm_sapply16_f__msmcread ( Thr* thr, Addr a );
void zsm_sapply32_f__msmcread ( Thr* thr, Addr a );
void zsm_sapply64_f__msmcread ( Thr* thr, Addr a );
void zsm_sapplyNN_f__msmcread ( Thr* thr, Addr a, SizeT len );

void libhb_Thr_resumes ( Thr* thr );



void libhb_srange_new ( Thr*, Addr, SizeT );
void libhb_srange_noaccess ( Thr*, Addr, SizeT );
void libhb_srange_untrack ( Thr*, Addr, SizeT );



Thread* libhb_get_Thr_hgthread ( Thr* );
void libhb_set_Thr_hgthread ( Thr*, Thread* );



void libhb_copy_shadow_state ( Thr* thr, Addr src, Addr dst, SizeT len );



void libhb_maybe_GC ( void );


Bool libhb_event_map_lookup ( ExeContext** resEC,
                                     Thr** resThr,
                                     SizeT* resSzB,
                                     Bool* resIsW,
                              Thr* thr, Addr a, SizeT szB, Bool isW );
# 64 "hg_main.c" 2

# 1 "helgrind.h" 1
# 61 "helgrind.h"
# 1 "../include/valgrind.h" 1
# 214 "../include/valgrind.h"
typedef
   struct {
      unsigned int nraddr;
   }
   OrigFn;
# 4827 "../include/valgrind.h"
typedef
   enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001,
          VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002,






          VG_USERREQ__CLIENT_CALL0 = 0x1101,
          VG_USERREQ__CLIENT_CALL1 = 0x1102,
          VG_USERREQ__CLIENT_CALL2 = 0x1103,
          VG_USERREQ__CLIENT_CALL3 = 0x1104,




          VG_USERREQ__COUNT_ERRORS = 0x1201,



          VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301,
          VG_USERREQ__FREELIKE_BLOCK = 0x1302,

          VG_USERREQ__CREATE_MEMPOOL = 0x1303,
          VG_USERREQ__DESTROY_MEMPOOL = 0x1304,
          VG_USERREQ__MEMPOOL_ALLOC = 0x1305,
          VG_USERREQ__MEMPOOL_FREE = 0x1306,
          VG_USERREQ__MEMPOOL_TRIM = 0x1307,
          VG_USERREQ__MOVE_MEMPOOL = 0x1308,
          VG_USERREQ__MEMPOOL_CHANGE = 0x1309,
          VG_USERREQ__MEMPOOL_EXISTS = 0x130a,
# 4867 "../include/valgrind.h"
          VG_USERREQ__PRINTF = 0x1401,
          VG_USERREQ__PRINTF_BACKTRACE = 0x1402,

          VG_USERREQ__PRINTF_VALIST_BY_REF = 0x1403,
          VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF = 0x1404,


          VG_USERREQ__STACK_REGISTER = 0x1501,
          VG_USERREQ__STACK_DEREGISTER = 0x1502,
          VG_USERREQ__STACK_CHANGE = 0x1503,


          VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601,


          VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701
   } Vg_ClientRequest;
# 4972 "../include/valgrind.h"
static int VALGRIND_PRINTF(const char *format, ...)
   __attribute__((format(__printf__, 1, 2), __unused__));

static int



VALGRIND_PRINTF(const char *format, ...)
{



   unsigned long _qzz_res;
   va_list vargs;
   __builtin_va_start(vargs,format);







   { volatile unsigned int _zzq_args[6]; volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned int)(VG_USERREQ__PRINTF_VALIST_BY_REF); _zzq_args[1] = (unsigned int)((unsigned long)format); _zzq_args[2] = (unsigned int)((unsigned long)&vargs); _zzq_args[3] = (unsigned int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = (unsigned int)(0); __asm__ volatile("roll $3,  %%edi ; roll $13, %%edi\n\t" "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", "memory" ); _qzz_res = _zzq_result; }



                                      ;

   __builtin_va_end(vargs);
   return (int)_qzz_res;

}


static int VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
   __attribute__((format(__printf__, 1, 2), __unused__));

static int



VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
{



   unsigned long _qzz_res;
   va_list vargs;
   __builtin_va_start(vargs,format);







   { volatile unsigned int _zzq_args[6]; volatile unsigned int _zzq_result; _zzq_args[0] = (unsigned int)(VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF); _zzq_args[1] = (unsigned int)((unsigned long)format); _zzq_args[2] = (unsigned int)((unsigned long)&vargs); _zzq_args[3] = (unsigned int)(0); _zzq_args[4] = (unsigned int)(0); _zzq_args[5] = (unsigned int)(0); __asm__ volatile("roll $3,  %%edi ; roll $13, %%edi\n\t" "roll $29, %%edi ; roll $19, %%edi\n\t" "xchgl %%ebx,%%ebx" : "=d" (_zzq_result) : "a" (&_zzq_args[0]), "0" (0) : "cc", "memory" ); _qzz_res = _zzq_result; }



                                      ;

   __builtin_va_end(vargs);
   return (int)_qzz_res;

}
# 62 "helgrind.h" 2





typedef
   enum {
      VG_USERREQ__HG_CLEAN_MEMORY = ((unsigned int)((('H')&0xff) << 24 | (('G')&0xff) << 16)),





      _VG_USERREQ__HG_SET_MY_PTHREAD_T = ((unsigned int)((('H')&0xff) << 24 | (('G')&0xff) << 16))
                                         + 256,
      _VG_USERREQ__HG_PTH_API_ERROR,
      _VG_USERREQ__HG_PTHREAD_JOIN_POST,
      _VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST,
      _VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE,
      _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE,
      _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST,
      _VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE,
      _VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST,
      _VG_USERREQ__HG_PTHREAD_COND_SIGNAL_PRE,
      _VG_USERREQ__HG_PTHREAD_COND_BROADCAST_PRE,
      _VG_USERREQ__HG_PTHREAD_COND_WAIT_PRE,
      _VG_USERREQ__HG_PTHREAD_COND_WAIT_POST,
      _VG_USERREQ__HG_PTHREAD_COND_DESTROY_PRE,
      _VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST,
      _VG_USERREQ__HG_PTHREAD_RWLOCK_DESTROY_PRE,
      _VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE,
      _VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST,
      _VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_PRE,
      _VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_POST,
      _VG_USERREQ__HG_POSIX_SEM_INIT_POST,
      _VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE,
      _VG_USERREQ__HG_POSIX_SEM_POST_PRE,
      _VG_USERREQ__HG_POSIX_SEM_WAIT_POST,
      _VG_USERREQ__HG_PTHREAD_BARRIER_INIT_PRE,
      _VG_USERREQ__HG_PTHREAD_BARRIER_WAIT_PRE,
      _VG_USERREQ__HG_PTHREAD_BARRIER_DESTROY_PRE,
      _VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE,
      _VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST,
      _VG_USERREQ__HG_PTHREAD_SPIN_LOCK_PRE,
      _VG_USERREQ__HG_PTHREAD_SPIN_LOCK_POST,
      _VG_USERREQ__HG_PTHREAD_SPIN_DESTROY_PRE,
      _VG_USERREQ__HG_CLIENTREQ_UNIMP,
      _VG_USERREQ__HG_USERSO_SEND_PRE,
      _VG_USERREQ__HG_USERSO_RECV_POST,
      _VG_USERREQ__HG_RESERVED1,
      _VG_USERREQ__HG_RESERVED2,
      _VG_USERREQ__HG_RESERVED3,
      _VG_USERREQ__HG_RESERVED4,
      _VG_USERREQ__HG_ARANGE_MAKE_UNTRACKED,
      _VG_USERREQ__HG_ARANGE_MAKE_TRACKED,
      _VG_USERREQ__HG_PTHREAD_BARRIER_RESIZE_PRE,
      _VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK

   } Vg_TCheckClientRequest;
# 66 "hg_main.c" 2
# 103 "hg_main.c"
static void all__sanity_check ( Char* who );
# 122 "hg_main.c"
static Thread* admin_threads = ((void*)0);




static Lock* admin_locks = ((void*)0);


static Thread** map_threads = ((void*)0);


static WordFM* map_locks = ((void*)0);


static WordSetU* univ_lsets = ((void*)0);
static WordSetU* univ_laog = ((void*)0);






static UWord stats__lockN_acquires = 0;
static UWord stats__lockN_releases = 0;

static
ThreadId map_threads_maybe_reverse_lookup_SLOW ( Thread* thr );



static Thread* mk_Thread ( Thr* hbthr ) {
   static Int indx = 1;
   Thread* thread = vgHelgrind_zalloc( "hg.mk_Thread.1", sizeof(Thread) );
   thread->locksetA = vgHelgrind_emptyWS( univ_lsets );
   thread->locksetW = vgHelgrind_emptyWS( univ_lsets );
   thread->magic = 0x504fc5e5;
   thread->hbthr = hbthr;
   thread->coretid = ((ThreadId)(0));
   thread->created_at = ((void*)0);
   thread->announced = ((Bool)0);
   thread->errmsg_index = indx++;
   thread->admin = admin_threads;
   admin_threads = thread;
   return thread;
}



static Lock* mk_LockN ( LockKind kind, Addr guestaddr ) {
   static ULong unique = 0;
   Lock* lock = vgHelgrind_zalloc( "hg.mk_Lock.1", sizeof(Lock) );

   if (admin_locks)
      admin_locks->admin_prev = lock;
   lock->admin_next = admin_locks;
   lock->admin_prev = ((void*)0);
   admin_locks = lock;

   lock->unique = unique++;
   lock->magic = 0x6545b557;
   lock->appeared_at = ((void*)0);
   lock->acquired_at = ((void*)0);
   lock->hbso = libhb_so_alloc();
   lock->guestaddr = guestaddr;
   lock->kind = kind;
   lock->heldW = ((Bool)0);
   lock->heldBy = ((void*)0);
   ((void) ((vgHelgrind_is_sane_LockN(lock)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lock)", (const Char*)"hg_main.c", 189, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   return lock;
}



static void del_LockN ( Lock* lk )
{
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 197, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((lk->hbso) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->hbso", (const Char*)"hg_main.c", 198, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   libhb_so_dealloc(lk->hbso);
   if (lk->heldBy)
      vgPlain_deleteBag( lk->heldBy );

   if (lk == admin_locks) {
      ((void) ((lk->admin_prev == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->admin_prev == NULL", (const Char*)"hg_main.c", 204, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (lk->admin_next)
         lk->admin_next->admin_prev = ((void*)0);
      admin_locks = lk->admin_next;
   }
   else {
      ((void) ((lk->admin_prev != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->admin_prev != NULL", (const Char*)"hg_main.c", 210, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      lk->admin_prev->admin_next = lk->admin_next;
      if (lk->admin_next)
         lk->admin_next->admin_prev = lk->admin_prev;
   }

   vgPlain_memset(lk, 0xAA, sizeof(*lk));
   vgHelgrind_free(lk);
}




static void lockN_acquire_writer ( Lock* lk, Thread* thr )
{
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 225, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 226, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   stats__lockN_acquires++;




   if (lk->acquired_at == ((void*)0)) {
      ThreadId tid;
      ((void) ((lk->heldBy == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy == NULL", (const Char*)"hg_main.c", 235, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      tid = map_threads_maybe_reverse_lookup_SLOW(thr);
      lk->acquired_at
         = vgPlain_record_ExeContext(tid, 0 );
   } else {
      ((void) ((lk->heldBy != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy != NULL", (const Char*)"hg_main.c", 240, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }


   switch (lk->kind) {
      case LK_nonRec:
      case_LK_nonRec:
         ((void) ((lk->heldBy == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy == NULL", (const Char*)"hg_main.c", 247, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((!lk->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lk->heldW", (const Char*)"hg_main.c", 248, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         lk->heldW = ((Bool)1);
         lk->heldBy = vgPlain_newBag( vgHelgrind_zalloc, "hg.lNaw.1", vgHelgrind_free );
         vgPlain_addToBag( lk->heldBy, (Word)thr );
         break;
      case LK_mbRec:
         if (lk->heldBy == ((void*)0))
            goto case_LK_nonRec;

         ((void) ((lk->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldW", (const Char*)"hg_main.c", 257, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

         ((void) ((vgPlain_sizeUniqueBag(lk->heldBy) == 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_(sizeUniqueBag(lk->heldBy)) == 1", (const Char*)"hg_main.c", 259, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

         ((void) ((vgPlain_elemBag(lk->heldBy, (Word)thr) == vgPlain_sizeTotalBag(lk->heldBy)) ? 0 : (
 vgPlain_assert_fail
# 261 "hg_main.c"
         ( ((Bool)0), (const Char*)"VG_(elemBag)(lk->heldBy, (Word)thr) == VG_(sizeTotalBag)(lk->heldBy)", (const Char*)
 "hg_main.c"
# 261 "hg_main.c"
         ,
 262
# 261 "hg_main.c"
         , (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)))
                                                    ;
         vgPlain_addToBag(lk->heldBy, (Word)thr);
         break;
      case LK_rdwr:
         ((void) ((lk->heldBy == ((void*)0) && !lk->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy == NULL && !lk->heldW", (const Char*)"hg_main.c", 266, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         goto case_LK_nonRec;
      default:
         ((void) ((0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"0", (const Char*)"hg_main.c", 269, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
  }
  ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 271, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}

static void lockN_acquire_reader ( Lock* lk, Thread* thr )
{
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 276, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 277, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((lk->kind == LK_rdwr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->kind == LK_rdwr", (const Char*)"hg_main.c", 279, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((lk->heldBy == ((void*)0) || (lk->heldBy != ((void*)0) && !lk->heldW)) ? 0 : (
 vgPlain_assert_fail
# 281 "hg_main.c"
   ( ((Bool)0), (const Char*)"lk->heldBy == NULL || (lk->heldBy != NULL && !lk->heldW)", (const Char*)
 "hg_main.c"
# 281 "hg_main.c"
   ,
 282
# 281 "hg_main.c"
   , (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)))
                                                   ;

   stats__lockN_acquires++;




   if (lk->acquired_at == ((void*)0)) {
      ThreadId tid;
      ((void) ((lk->heldBy == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy == NULL", (const Char*)"hg_main.c", 291, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      tid = map_threads_maybe_reverse_lookup_SLOW(thr);
      lk->acquired_at
         = vgPlain_record_ExeContext(tid, 0 );
   } else {
      ((void) ((lk->heldBy != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy != NULL", (const Char*)"hg_main.c", 296, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }


   if (lk->heldBy) {
      vgPlain_addToBag(lk->heldBy, (Word)thr);
   } else {
      lk->heldW = ((Bool)0);
      lk->heldBy = vgPlain_newBag( vgHelgrind_zalloc, "hg.lNar.1", vgHelgrind_free );
      vgPlain_addToBag( lk->heldBy, (Word)thr );
   }
   ((void) ((!lk->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lk->heldW", (const Char*)"hg_main.c", 307, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 308, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}





static void lockN_release ( Lock* lk, Thread* thr )
{
   Bool b;
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 318, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 319, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((lk->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy", (const Char*)"hg_main.c", 321, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   stats__lockN_releases++;

   b = vgPlain_delFromBag(lk->heldBy, (Word)thr);

   ((void) ((b) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"b", (const Char*)"hg_main.c", 326, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((lk->acquired_at) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->acquired_at", (const Char*)"hg_main.c", 328, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (vgPlain_isEmptyBag(lk->heldBy)) {
      vgPlain_deleteBag(lk->heldBy);
      lk->heldBy = ((void*)0);
      lk->heldW = ((Bool)0);
      lk->acquired_at = ((void*)0);
   }
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 335, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}

static void remove_Lock_from_locksets_of_all_owning_Threads( Lock* lk )
{
   Thread* thr;
   if (!lk->heldBy) {
      ((void) ((!lk->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lk->heldW", (const Char*)"hg_main.c", 342, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return;
   }

   vgPlain_initIterBag( lk->heldBy );
   while (vgPlain_nextIterBag( lk->heldBy, (Word*)&thr, ((void*)0) )) {
      ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 348, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((vgHelgrind_elemWS( univ_lsets, thr->locksetA, (Word)lk )) ? 0 : (
 vgPlain_assert_fail
# 349 "hg_main.c"
      ( ((Bool)0), (const Char*)"HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lk )", (const Char*)
 "hg_main.c"
# 349 "hg_main.c"
      ,
 350
# 349 "hg_main.c"
      , (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)))
                                                       ;
      thr->locksetA
         = vgHelgrind_delFromWS( univ_lsets, thr->locksetA, (Word)lk );

      if (lk->heldW) {
         ((void) ((vgHelgrind_elemWS( univ_lsets, thr->locksetW, (Word)lk )) ? 0 : (
 vgPlain_assert_fail
# 355 "hg_main.c"
         ( ((Bool)0), (const Char*)"HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lk )", (const Char*)
 "hg_main.c"
# 355 "hg_main.c"
         ,
 356
# 355 "hg_main.c"
         , (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)))
                                                          ;
         thr->locksetW
            = vgHelgrind_delFromWS( univ_lsets, thr->locksetW, (Word)lk );
      }
   }
   vgPlain_doneIterBag( lk->heldBy );
}
# 374 "hg_main.c"
static const Int sHOW_ADMIN = 0;

static void space ( Int n )
{
   Int i;
   Char spaces[128+1];
   ((void) ((n >= 0 && n < 128) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"n >= 0 && n < 128", (const Char*)"hg_main.c", 380, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (n == 0)
      return;
   for (i = 0; i < n; i++)
      spaces[i] = ' ';
   spaces[i] = 0;
   ((void) ((i < 128+1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"i < 128+1", (const Char*)"hg_main.c", 386, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   vgPlain_printf("%s", spaces);
}

static void pp_Thread ( Int d, Thread* t )
{
   space(d+0); vgPlain_printf("Thread %p {\n", t);
   if (sHOW_ADMIN) {
   space(d+3); vgPlain_printf("admin    %p\n", t->admin);
   space(d+3); vgPlain_printf("magic    0x%x\n", (UInt)t->magic);
   }
   space(d+3); vgPlain_printf("locksetA %d\n", (Int)t->locksetA);
   space(d+3); vgPlain_printf("locksetW %d\n", (Int)t->locksetW);
   space(d+0); vgPlain_printf("}\n");
}

static void pp_admin_threads ( Int d )
{
   Int i, n;
   Thread* t;
   for (n = 0, t = admin_threads; t; n++, t = t->admin) {

   }
   space(d); vgPlain_printf("admin_threads (%d records) {\n", n);
   for (i = 0, t = admin_threads; t; i++, t = t->admin) {
      if (0) {
         space(n);
         vgPlain_printf("admin_threads record %d of %d:\n", i, n);
      }
      pp_Thread(d+3, t);
   }
   space(d); vgPlain_printf("}\n");
}

static void pp_map_threads ( Int d )
{
   Int i, n = 0;
   space(d); vgPlain_printf("map_threads ");
   for (i = 0; i < 500; i++) {
      if (map_threads[i] != ((void*)0))
         n++;
   }
   vgPlain_printf("(%d entries) {\n", n);
   for (i = 0; i < 500; i++) {
      if (map_threads[i] == ((void*)0))
         continue;
      space(d+3);
      vgPlain_printf("coretid %d -> Thread %p\n", i, map_threads[i]);
   }
   space(d); vgPlain_printf("}\n");
}

static const HChar* show_LockKind ( LockKind lkk ) {
   switch (lkk) {
      case LK_mbRec: return "mbRec";
      case LK_nonRec: return "nonRec";
      case LK_rdwr: return "rdwr";
      default: ((void) ((0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"0", (const Char*)"hg_main.c", 443, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }
}

static void pp_Lock ( Int d, Lock* lk )
{
   space(d+0); vgPlain_printf("Lock %p (ga %#lx) {\n", lk, lk->guestaddr);
   if (sHOW_ADMIN) {
      space(d+3); vgPlain_printf("admin_n  %p\n", lk->admin_next);
      space(d+3); vgPlain_printf("admin_p  %p\n", lk->admin_prev);
      space(d+3); vgPlain_printf("magic    0x%x\n", (UInt)lk->magic);
   }
   space(d+3); vgPlain_printf("unique %llu\n", lk->unique);
   space(d+3); vgPlain_printf("kind   %s\n", show_LockKind(lk->kind));
   space(d+3); vgPlain_printf("heldW  %s\n", lk->heldW ? "yes" : "no");
   space(d+3); vgPlain_printf("heldBy %p", lk->heldBy);
   if (lk->heldBy) {
      Thread* thr;
      Word count;
      vgPlain_printf(" { ");
      vgPlain_initIterBag( lk->heldBy );
      while (vgPlain_nextIterBag( lk->heldBy, (Word*)&thr, &count ))
         vgPlain_printf("%lu:%p ", count, thr);
      vgPlain_doneIterBag( lk->heldBy );
      vgPlain_printf("}");
   }
   vgPlain_printf("\n");
   space(d+0); vgPlain_printf("}\n");
}

static void pp_admin_locks ( Int d )
{
   Int i, n;
   Lock* lk;
   for (n = 0, lk = admin_locks; lk; n++, lk = lk->admin_next) {

   }
   space(d); vgPlain_printf("admin_locks (%d records) {\n", n);
   for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin_next) {
      if (0) {
         space(n);
         vgPlain_printf("admin_locks record %d of %d:\n", i, n);
      }
      pp_Lock(d+3, lk);
   }
   space(d); vgPlain_printf("}\n");
}

static void pp_map_locks ( Int d )
{
   void* gla;
   Lock* lk;
   space(d); vgPlain_printf("map_locks (%d entries) {\n",
                         (Int)vgPlain_sizeFM( map_locks ));
   vgPlain_initIterFM( map_locks );
   while (vgPlain_nextIterFM( map_locks, (Word*)&gla,
                                      (Word*)&lk )) {
      space(d+3);
      vgPlain_printf("guest %p -> Lock %p\n", gla, lk);
   }
   vgPlain_doneIterFM( map_locks );
   space(d); vgPlain_printf("}\n");
}

static void pp_everything ( Int flags, Char* caller )
{
   Int d = 0;
   vgPlain_printf("\n");
   vgPlain_printf("All_Data_Structures (caller = \"%s\") {\n", caller);
   if (flags & (1<<1)) {
      vgPlain_printf("\n");
      pp_admin_threads(d+3);
      vgPlain_printf("\n");
      pp_map_threads(d+3);
   }
   if (flags & (1<<2)) {
      vgPlain_printf("\n");
      pp_admin_locks(d+3);
      vgPlain_printf("\n");
      pp_map_locks(d+3);
   }

   vgPlain_printf("\n");
   vgPlain_printf("}\n");
   vgPlain_printf("\n");
}
# 537 "hg_main.c"
static void initialise_data_structures ( Thr* hbthr_root )
{
   Thread* thr;


   ((void) ((admin_threads == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"admin_threads == NULL", (const Char*)"hg_main.c", 542, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((admin_locks == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"admin_locks == NULL", (const Char*)"hg_main.c", 543, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((sizeof(Addr) == sizeof(Word)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"sizeof(Addr) == sizeof(Word)", (const Char*)"hg_main.c", 545, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((map_threads == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_threads == NULL", (const Char*)"hg_main.c", 547, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   map_threads = vgHelgrind_zalloc( "hg.ids.1", 500 * sizeof(Thread*) );
   ((void) ((map_threads != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_threads != NULL", (const Char*)"hg_main.c", 549, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((sizeof(Addr) == sizeof(Word)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"sizeof(Addr) == sizeof(Word)", (const Char*)"hg_main.c", 551, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((map_locks == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_locks == NULL", (const Char*)"hg_main.c", 552, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   map_locks = vgPlain_newFM( vgHelgrind_zalloc, "hg.ids.2", vgHelgrind_free,
                           ((void*)0) );
   ((void) ((map_locks != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_locks != NULL", (const Char*)"hg_main.c", 555, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((univ_lsets == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"univ_lsets == NULL", (const Char*)"hg_main.c", 557, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   univ_lsets = vgHelgrind_newWordSetU( vgHelgrind_zalloc, "hg.ids.4", vgHelgrind_free,
                                  8 );
   ((void) ((univ_lsets != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"univ_lsets != NULL", (const Char*)"hg_main.c", 560, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((univ_laog == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"univ_laog == NULL", (const Char*)"hg_main.c", 562, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (vgHelgrind_clo_track_lockorders) {
      univ_laog = vgHelgrind_newWordSetU( vgHelgrind_zalloc, "hg.ids.5 (univ_laog)",
                                    vgHelgrind_free, 24 );
      ((void) ((univ_laog != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"univ_laog != NULL", (const Char*)"hg_main.c", 566, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }





   thr = mk_Thread(hbthr_root);
   thr->coretid = 1;

   ((void) ((libhb_get_Thr_hgthread(hbthr_root) == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"libhb_get_Thr_hgthread(hbthr_root) == NULL", (const Char*)"hg_main.c", 576, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   libhb_set_Thr_hgthread(hbthr_root, thr);


   ((void) ((vgHelgrind_is_sane_ThreadId(thr->coretid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(thr->coretid)", (const Char*)"hg_main.c", 580, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((thr->coretid != ((ThreadId)(0))) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr->coretid != VG_INVALID_THREADID", (const Char*)"hg_main.c", 581, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   map_threads[thr->coretid] = thr;

   ((void) ((((ThreadId)(0)) == 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_INVALID_THREADID == 0", (const Char*)"hg_main.c", 585, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   all__sanity_check("initialise_data_structures");
}







static Thread* map_threads_maybe_lookup ( ThreadId coretid )
{
   Thread* thr;
   ((void) ((vgHelgrind_is_sane_ThreadId(coretid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(coretid)", (const Char*)"hg_main.c", 599, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = map_threads[coretid];
   return thr;
}


static inline Thread* map_threads_lookup ( ThreadId coretid )
{
   Thread* thr;
   ((void) ((vgHelgrind_is_sane_ThreadId(coretid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(coretid)", (const Char*)"hg_main.c", 608, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = map_threads[coretid];
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 610, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   return thr;
}



static ThreadId map_threads_maybe_reverse_lookup_SLOW ( Thread* thr )
{
   ThreadId tid;
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 619, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((((ThreadId)(0)) >= 0 && ((ThreadId)(0)) < 500) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_INVALID_THREADID >= 0 && VG_INVALID_THREADID < VG_N_THREADS", (const Char*)"hg_main.c", 621, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((map_threads[((ThreadId)(0))] == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_threads[VG_INVALID_THREADID] == NULL", (const Char*)"hg_main.c", 622, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   tid = thr->coretid;
   ((void) ((vgHelgrind_is_sane_ThreadId(tid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(tid)", (const Char*)"hg_main.c", 624, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   return tid;
}



static ThreadId map_threads_reverse_lookup_SLOW ( Thread* thr )
{
   ThreadId tid = map_threads_maybe_reverse_lookup_SLOW( thr );
   ((void) ((tid != ((ThreadId)(0))) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"tid != VG_INVALID_THREADID", (const Char*)"hg_main.c", 633, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((map_threads[tid]) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_threads[tid]", (const Char*)"hg_main.c", 634, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((map_threads[tid]->coretid == tid) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_threads[tid]->coretid == tid", (const Char*)"hg_main.c", 635, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   return tid;
}

static void map_threads_delete ( ThreadId coretid )
{
   Thread* thr;
   ((void) ((coretid != 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"coretid != 0", (const Char*)"hg_main.c", 642, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgHelgrind_is_sane_ThreadId(coretid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(coretid)", (const Char*)"hg_main.c", 643, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = map_threads[coretid];
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 645, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   map_threads[coretid] = ((void*)0);
}
# 657 "hg_main.c"
static
Lock* map_locks_lookup_or_create ( LockKind lkk, Addr ga, ThreadId tid )
{
   Bool found;
   Lock* oldlock = ((void*)0);
   ((void) ((vgHelgrind_is_sane_ThreadId(tid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(tid)", (const Char*)"hg_main.c", 662, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   found = vgPlain_lookupFM( map_locks,
                          ((void*)0), (Word*)&oldlock, (Word)ga );
   if (!found) {
      Lock* lock = mk_LockN(lkk, ga);
      lock->appeared_at = vgPlain_record_ExeContext( tid, 0 );
      ((void) ((vgHelgrind_is_sane_LockN(lock)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lock)", (const Char*)"hg_main.c", 668, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgPlain_addToFM( map_locks, (Word)ga, (Word)lock );
      ((void) ((oldlock == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"oldlock == NULL", (const Char*)"hg_main.c", 670, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return lock;
   } else {
      ((void) ((oldlock != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"oldlock != NULL", (const Char*)"hg_main.c", 673, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((vgHelgrind_is_sane_LockN(oldlock)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(oldlock)", (const Char*)"hg_main.c", 674, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((oldlock->guestaddr == ga) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"oldlock->guestaddr == ga", (const Char*)"hg_main.c", 675, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return oldlock;
   }
}

static Lock* map_locks_maybe_lookup ( Addr ga )
{
   Bool found;
   Lock* lk = ((void*)0);
   found = vgPlain_lookupFM( map_locks, ((void*)0), (Word*)&lk, (Word)ga );
   ((void) ((found ? lk != ((void*)0) : lk == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"found ? lk != NULL : lk == NULL", (const Char*)"hg_main.c", 685, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   return lk;
}

static void map_locks_delete ( Addr ga )
{
   Addr ga2 = 0;
   Lock* lk = ((void*)0);
   vgPlain_delFromFM( map_locks,
                   (Word*)&ga2, (Word*)&lk, (Word)ga );



   ((void) ((lk != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk != NULL", (const Char*)"hg_main.c", 698, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((ga2 == ga) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"ga2 == ga", (const Char*)"hg_main.c", 699, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}







static UWord stats__sanity_checks = 0;

static void laog__sanity_check ( Char* who );
# 783 "hg_main.c"
static Bool thread_is_a_holder_of_Lock ( Thread* thr, Lock* lk )
{
   if (lk->heldBy)
      return vgPlain_elemBag( lk->heldBy, (Word)thr ) > 0;
   else
      return ((Bool)0);
}


__attribute__((noinline))
static void threads__sanity_check ( Char* who )
{

   Char* how = "no error";
   Thread* thr;
   WordSetID wsA, wsW;
   UWord* ls_words;
   Word ls_size, i;
   Lock* lk;
   for (thr = admin_threads; thr; thr = thr->admin) {
      if (!vgHelgrind_is_sane_Thread(thr)) do { how = ("1"); goto bad; } while (0);
      wsA = thr->locksetA;
      wsW = thr->locksetW;

      if (!vgHelgrind_isSubsetOf( univ_lsets, wsW, wsA )) do { how = ("7"); goto bad; } while (0);
      vgHelgrind_getPayloadWS( &ls_words, &ls_size, univ_lsets, wsA );
      for (i = 0; i < ls_size; i++) {
         lk = (Lock*)ls_words[i];

         if (!vgHelgrind_is_sane_LockN(lk)) do { how = ("2"); goto bad; } while (0);


         if (!thread_is_a_holder_of_Lock(thr,lk)) do { how = ("3"); goto bad; } while (0);
      }
   }
   return;
  bad:
   vgPlain_printf("threads__sanity_check: who=\"%s\", bad=\"%s\"\n", who, how);
   ((void) ((0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"0", (const Char*)"hg_main.c", 821, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

}



__attribute__((noinline))
static void locks__sanity_check ( Char* who )
{

   Char* how = "no error";
   Addr gla;
   Lock* lk;
   Int i;

   for (i = 0, lk = admin_locks; lk; i++, lk = lk->admin_next)
      ;
   if (i != vgPlain_sizeFM(map_locks)) do { how = ("1"); goto bad; } while (0);


   vgPlain_initIterFM( map_locks );
   while (vgPlain_nextIterFM( map_locks,
                           (Word*)&gla, (Word*)&lk )) {
      if (lk->guestaddr != gla) do { how = ("2"); goto bad; } while (0);
   }
   vgPlain_doneIterFM( map_locks );

   for (lk = admin_locks; lk; lk = lk->admin_next) {


      if (!vgHelgrind_is_sane_LockN(lk)) do { how = ("3"); goto bad; } while (0);

      if (lk != map_locks_maybe_lookup(lk->guestaddr)) do { how = ("4"); goto bad; } while (0);


      if (lk->heldBy) {
         Thread* thr;
         Word count;
         vgPlain_initIterBag( lk->heldBy );
         while (vgPlain_nextIterBag( lk->heldBy,
                                  (Word*)&thr, &count )) {

            ((void) ((count >= 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"count >= 1", (const Char*)"hg_main.c", 863, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
            ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 864, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
            if (!vgHelgrind_elemWS(univ_lsets, thr->locksetA, (Word)lk))
               do { how = ("6"); goto bad; } while (0);

            if (lk->heldW
                && !vgHelgrind_elemWS(univ_lsets, thr->locksetW, (Word)lk))
               do { how = ("7"); goto bad; } while (0);
            if ((!lk->heldW)
                && vgHelgrind_elemWS(univ_lsets, thr->locksetW, (Word)lk))
               do { how = ("8"); goto bad; } while (0);
         }
         vgPlain_doneIterBag( lk->heldBy );
      } else {

         if (lk->heldW) do { how = ("9"); goto bad; } while (0);


      }
   }

   return;
  bad:
   vgPlain_printf("locks__sanity_check: who=\"%s\", bad=\"%s\"\n", who, how);
   ((void) ((0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"0", (const Char*)"hg_main.c", 887, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

}


static void all_except_Locks__sanity_check ( Char* who ) {
   stats__sanity_checks++;
   if (0) vgPlain_printf("all_except_Locks__sanity_check(%s)\n", who);
   threads__sanity_check(who);
   if (vgHelgrind_clo_track_lockorders)
      laog__sanity_check(who);
}
static void all__sanity_check ( Char* who ) {
   all_except_Locks__sanity_check(who);
   locks__sanity_check(who);
}






static void laog__pre_thread_acquires_lock ( Thread*, Lock* );

static inline Thread* get_current_Thread ( void );
__attribute__((noinline))
static void laog__handle_one_lock_deletion ( Lock* lk );





static void shadow_mem_scopy_range ( Thread* thr,
                                     Addr src, Addr dst, SizeT len )
{
   Thr* hbthr = thr->hbthr;
   ((void) ((hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr", (const Char*)"hg_main.c", 923, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   libhb_copy_shadow_state( hbthr, src, dst, len );
}

static void shadow_mem_cread_range ( Thread* thr, Addr a, SizeT len )
{
   Thr* hbthr = thr->hbthr;
   ((void) ((hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr", (const Char*)"hg_main.c", 930, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   zsm_sapplyNN_f__msmcread((hbthr),(a),(len));
}

static void shadow_mem_cwrite_range ( Thread* thr, Addr a, SizeT len ) {
   Thr* hbthr = thr->hbthr;
   ((void) ((hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr", (const Char*)"hg_main.c", 936, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   zsm_sapplyNN_f__msmcwrite((hbthr),(a),(len));
}

static void shadow_mem_make_New ( Thread* thr, Addr a, SizeT len )
{
   libhb_srange_new( thr->hbthr, a, len );
}

static void shadow_mem_make_NoAccess ( Thread* thr, Addr aIN, SizeT len )
{
   if (0 && len > 500)
      vgPlain_printf("make NoAccess ( %#lx, %ld )\n", aIN, len );
   libhb_srange_noaccess( thr->hbthr, aIN, len );
}

static void shadow_mem_make_Untracked ( Thread* thr, Addr aIN, SizeT len )
{
   if (0 && len > 500)
      vgPlain_printf("make Untracked ( %#lx, %ld )\n", aIN, len );
   libhb_srange_untrack( thr->hbthr, aIN, len );
}
# 993 "hg_main.c"
static
void evhH__post_thread_w_acquires_lock ( Thread* thr,
                                         LockKind lkk, Addr lock_ga )
{
   Lock* lk;
# 1010 "hg_main.c"
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 1010, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


   lk = map_locks_lookup_or_create(
           lkk, lock_ga, map_threads_reverse_lookup_SLOW(thr) );
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 1015, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


   ((void) ((thr->hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr->hbthr", (const Char*)"hg_main.c", 1018, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((lk->hbso) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->hbso", (const Char*)"hg_main.c", 1019, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (lk->heldBy == ((void*)0)) {

      ((void) ((!lk->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lk->heldW", (const Char*)"hg_main.c", 1023, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      lockN_acquire_writer( lk, thr );

      libhb_so_recv( thr->hbthr, lk->hbso, ((Bool)1) );
      goto noerror;
   }



   ((void) ((lk->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy", (const Char*)"hg_main.c", 1032, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (!lk->heldW) {
      vgHelgrind_record_error_Misc(
         thr, "Bug in libpthread: write lock "
              "granted on rwlock which is currently rd-held");
      goto error;
   }



   ((void) ((vgPlain_sizeUniqueBag(lk->heldBy) == 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_(sizeUniqueBag)(lk->heldBy) == 1", (const Char*)"hg_main.c", 1042, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (thr != (Thread*)vgPlain_anyElementOfBag(lk->heldBy)) {
      vgHelgrind_record_error_Misc(
         thr, "Bug in libpthread: write lock "
              "granted on mutex/rwlock which is currently "
              "wr-held by a different thread");
      goto error;
   }






   if (lk->kind != LK_mbRec) {
      vgHelgrind_record_error_Misc(
         thr, "Bug in libpthread: recursive write lock "
              "granted on mutex/wrlock which does not "
              "support recursion");
      goto error;
   }


   lockN_acquire_writer( lk, thr );


   libhb_so_recv( thr->hbthr, lk->hbso, ((Bool)1) );
   goto noerror;

  noerror:
   if (vgHelgrind_clo_track_lockorders) {


      laog__pre_thread_acquires_lock( thr, lk );
   }

   thr->locksetA = vgHelgrind_addToWS( univ_lsets, thr->locksetA, (Word)lk );
   thr->locksetW = vgHelgrind_addToWS( univ_lsets, thr->locksetW, (Word)lk );


  error:
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 1084, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}




static
void evhH__post_thread_r_acquires_lock ( Thread* thr,
                                         LockKind lkk, Addr lock_ga )
{
   Lock* lk;
# 1107 "hg_main.c"
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 1107, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));



   ((void) ((lkk == LK_rdwr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lkk == LK_rdwr", (const Char*)"hg_main.c", 1111, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   lk = map_locks_lookup_or_create(
           lkk, lock_ga, map_threads_reverse_lookup_SLOW(thr) );
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 1114, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


   ((void) ((thr->hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr->hbthr", (const Char*)"hg_main.c", 1117, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((lk->hbso) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->hbso", (const Char*)"hg_main.c", 1118, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (lk->heldBy == ((void*)0)) {

      ((void) ((!lk->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lk->heldW", (const Char*)"hg_main.c", 1122, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      lockN_acquire_reader( lk, thr );

      libhb_so_recv( thr->hbthr, lk->hbso, ((Bool)0) );
      goto noerror;
   }



   ((void) ((lk->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->heldBy", (const Char*)"hg_main.c", 1131, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (lk->heldW) {
      vgHelgrind_record_error_Misc( thr, "Bug in libpthread: read lock "
                                   "granted on rwlock which is "
                                   "currently wr-held");
      goto error;
   }



   lockN_acquire_reader( lk, thr );


   libhb_so_recv( thr->hbthr, lk->hbso, ((Bool)0) );
   goto noerror;

  noerror:
   if (vgHelgrind_clo_track_lockorders) {


      laog__pre_thread_acquires_lock( thr, lk );
   }

   thr->locksetA = vgHelgrind_addToWS( univ_lsets, thr->locksetA, (Word)lk );



  error:
   ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 1159, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}




static
void evhH__pre_thread_releases_lock ( Thread* thr,
                                      Addr lock_ga, Bool isRDWR )
{
   Lock* lock;
   Word n;
   Bool was_heldW;
# 1182 "hg_main.c"
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 1182, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   lock = map_locks_maybe_lookup( lock_ga );

   if (!lock) {



      vgHelgrind_record_error_UnlockBogus( thr, lock_ga );
      return;
   }

   ((void) ((lock->guestaddr == lock_ga) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lock->guestaddr == lock_ga", (const Char*)"hg_main.c", 1193, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgHelgrind_is_sane_LockN(lock)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lock)", (const Char*)"hg_main.c", 1194, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (isRDWR && lock->kind != LK_rdwr) {
      vgHelgrind_record_error_Misc( thr, "pthread_rwlock_unlock with a "
                                   "pthread_mutex_t* argument " );
   }
   if ((!isRDWR) && lock->kind == LK_rdwr) {
      vgHelgrind_record_error_Misc( thr, "pthread_mutex_unlock with a "
                                   "pthread_rwlock_t* argument " );
   }

   if (!lock->heldBy) {


      ((void) ((!lock->heldW) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lock->heldW", (const Char*)"hg_main.c", 1208, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgHelgrind_record_error_UnlockUnlocked( thr, lock );
      ((void) ((!vgHelgrind_elemWS( univ_lsets, thr->locksetA, (Word)lock )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock )", (const Char*)"hg_main.c", 1210, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((!vgHelgrind_elemWS( univ_lsets, thr->locksetW, (Word)lock )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock )", (const Char*)"hg_main.c", 1211, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      goto error;
   }


   ((void) ((lock->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lock->heldBy", (const Char*)"hg_main.c", 1216, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   was_heldW = lock->heldW;



   n = vgPlain_elemBag( lock->heldBy, (Word)thr );
   ((void) ((n >= 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"n >= 0", (const Char*)"hg_main.c", 1222, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (n == 0) {




      Thread* realOwner = (Thread*)vgPlain_anyElementOfBag( lock->heldBy );
      ((void) ((vgHelgrind_is_sane_Thread(realOwner)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(realOwner)", (const Char*)"hg_main.c", 1229, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((realOwner != thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"realOwner != thr", (const Char*)"hg_main.c", 1230, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((!vgHelgrind_elemWS( univ_lsets, thr->locksetA, (Word)lock )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock )", (const Char*)"hg_main.c", 1231, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((!vgHelgrind_elemWS( univ_lsets, thr->locksetW, (Word)lock )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock )", (const Char*)"hg_main.c", 1232, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgHelgrind_record_error_UnlockForeign( thr, realOwner, lock );
      goto error;
   }


   ((void) ((n >= 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"n >= 1", (const Char*)"hg_main.c", 1238, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   lockN_release( lock, thr );

   n--;
   ((void) ((n >= 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"n >= 0", (const Char*)"hg_main.c", 1243, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (n > 0) {
      ((void) ((lock->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lock->heldBy", (const Char*)"hg_main.c", 1246, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((n == vgPlain_elemBag( lock->heldBy, (Word)thr )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"n == VG_(elemBag)( lock->heldBy, (Word)thr )", (const Char*)"hg_main.c", 1247, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


      ((void) ((lock->kind == LK_mbRec || (lock->kind == LK_rdwr && !lock->heldW)) ? 0 : (
 vgPlain_assert_fail
# 1250 "hg_main.c"
      ( ((Bool)0), (const Char*)"lock->kind == LK_mbRec || (lock->kind == LK_rdwr && !lock->heldW)", (const Char*)
 "hg_main.c"
# 1250 "hg_main.c"
      ,
 1251
# 1250 "hg_main.c"
      , (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)))
                                                           ;
      ((void) ((vgHelgrind_elemWS( univ_lsets, thr->locksetA, (Word)lock )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(elemWS)( univ_lsets, thr->locksetA, (Word)lock )", (const Char*)"hg_main.c", 1252, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (lock->heldW)
         ((void) ((vgHelgrind_elemWS( univ_lsets, thr->locksetW, (Word)lock )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock )", (const Char*)"hg_main.c", 1254, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      else
         ((void) ((!vgHelgrind_elemWS( univ_lsets, thr->locksetW, (Word)lock )) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!HG_(elemWS)( univ_lsets, thr->locksetW, (Word)lock )", (const Char*)"hg_main.c", 1256, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   } else {



      if (lock->kind == LK_rdwr && lock->heldBy) {







         ((void) ((lock->heldW == ((Bool)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lock->heldW == False", (const Char*)"hg_main.c", 1269, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      } else {







         ((void) ((!lock->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lock->heldBy", (const Char*)"hg_main.c", 1278, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((lock->heldW == ((Bool)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lock->heldW == False", (const Char*)"hg_main.c", 1279, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      }




      thr->locksetA
         = vgHelgrind_delFromWS( univ_lsets, thr->locksetA, (Word)lock );
      thr->locksetW
         = vgHelgrind_delFromWS( univ_lsets, thr->locksetW, (Word)lock );

      ((void) ((thr->hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr->hbthr", (const Char*)"hg_main.c", 1290, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((lock->hbso) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lock->hbso", (const Char*)"hg_main.c", 1291, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


      libhb_so_send( thr->hbthr, lock->hbso, was_heldW );
   }


  error:
   ((void) ((vgHelgrind_is_sane_LockN(lock)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lock)", (const Char*)"hg_main.c", 1299, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}
# 1323 "hg_main.c"
static Thread *current_Thread = ((void*)0),
              *current_Thread_prev = ((void*)0);

static void evh__start_client_code ( ThreadId tid, ULong nDisp ) {
   if (0) vgPlain_printf("start %d %llu\n", (Int)tid, nDisp);
   ((void) ((current_Thread == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"current_Thread == NULL", (const Char*)"hg_main.c", 1328, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   current_Thread = map_threads_lookup( tid );
   ((void) ((current_Thread != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"current_Thread != NULL", (const Char*)"hg_main.c", 1330, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (current_Thread != current_Thread_prev) {
      libhb_Thr_resumes( current_Thread->hbthr );
      current_Thread_prev = current_Thread;
   }
}
static void evh__stop_client_code ( ThreadId tid, ULong nDisp ) {
   if (0) vgPlain_printf(" stop %d %llu\n", (Int)tid, nDisp);
   ((void) ((current_Thread != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"current_Thread != NULL", (const Char*)"hg_main.c", 1338, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   current_Thread = ((void*)0);
   libhb_maybe_GC();
}
static inline Thread* get_current_Thread_in_C_C ( void ) {
   return current_Thread;
}
static inline Thread* get_current_Thread ( void ) {
   ThreadId coretid;
   Thread* thr;
   thr = get_current_Thread_in_C_C();
   if (__builtin_expect(!!(thr), 1))
      return thr;

   coretid = vgPlain_get_running_tid();




   if (coretid == ((ThreadId)(0)))
      coretid = 1;
   thr = map_threads_lookup( coretid );
   return thr;
}

static
void evh__new_mem ( Addr a, SizeT len ) {
   if (0 >= 2)
      vgPlain_printf("evh__new_mem(%p, %lu)\n", (void*)a, len );
   shadow_mem_make_New( get_current_Thread(), a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__new_mem-post");
}

static
void evh__new_mem_stack ( Addr a, SizeT len ) {
   if (0 >= 2)
      vgPlain_printf("evh__new_mem_stack(%p, %lu)\n", (void*)a, len );
   shadow_mem_make_New( get_current_Thread(),
                        -0 + a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__new_mem_stack-post");
}

static
void evh__new_mem_w_tid ( Addr a, SizeT len, ThreadId tid ) {
   if (0 >= 2)
      vgPlain_printf("evh__new_mem_w_tid(%p, %lu)\n", (void*)a, len );
   shadow_mem_make_New( get_current_Thread(), a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__new_mem_w_tid-post");
}

static
void evh__new_mem_w_perms ( Addr a, SizeT len,
                            Bool rr, Bool ww, Bool xx, ULong di_handle ) {
   if (0 >= 1)
      vgPlain_printf("evh__new_mem_w_perms(%p, %lu, %d,%d,%d)\n",
                  (void*)a, len, (Int)rr, (Int)ww, (Int)xx );
   if (rr || ww || xx)
      shadow_mem_make_New( get_current_Thread(), a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__new_mem_w_perms-post");
}

static
void evh__set_perms ( Addr a, SizeT len,
                      Bool rr, Bool ww, Bool xx ) {
   if (0 >= 1)
      vgPlain_printf("evh__set_perms(%p, %lu, %d,%d,%d)\n",
                  (void*)a, len, (Int)rr, (Int)ww, (Int)xx );



   if (!(rr || ww))
      shadow_mem_make_NoAccess( get_current_Thread(), a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__set_perms-post");
}

static
void evh__die_mem ( Addr a, SizeT len ) {

   if (0 >= 2)
      vgPlain_printf("evh__die_mem(%p, %lu)\n", (void*)a, len );
   shadow_mem_make_NoAccess( get_current_Thread(), a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__die_mem-post");
}

static
void evh__untrack_mem ( Addr a, SizeT len ) {

   if (0 >= 2)
      vgPlain_printf("evh__untrack_mem(%p, %lu)\n", (void*)a, len );
   shadow_mem_make_Untracked( get_current_Thread(), a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__untrack_mem-post");
}

static
void evh__copy_mem ( Addr src, Addr dst, SizeT len ) {
   if (0 >= 2)
      vgPlain_printf("evh__copy_mem(%p, %p, %lu)\n", (void*)src, (void*)dst, len );
   shadow_mem_scopy_range( get_current_Thread(), src, dst, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__copy_mem-post");
}

static
void evh__pre_thread_ll_create ( ThreadId parent, ThreadId child )
{
   if (0 >= 1)
      vgPlain_printf("evh__pre_thread_ll_create(p=%d, c=%d)\n",
                  (Int)parent, (Int)child );

   if (parent != ((ThreadId)(0))) {
      Thread* thr_p;
      Thread* thr_c;
      Thr* hbthr_p;
      Thr* hbthr_c;

      ((void) ((vgHelgrind_is_sane_ThreadId(parent)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(parent)", (const Char*)"hg_main.c", 1460, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((vgHelgrind_is_sane_ThreadId(child)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(child)", (const Char*)"hg_main.c", 1461, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((parent != child) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"parent != child", (const Char*)"hg_main.c", 1462, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      thr_p = map_threads_maybe_lookup( parent );
      thr_c = map_threads_maybe_lookup( child );

      ((void) ((thr_p != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_p != NULL", (const Char*)"hg_main.c", 1467, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((thr_c == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_c == NULL", (const Char*)"hg_main.c", 1468, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      hbthr_p = thr_p->hbthr;
      ((void) ((hbthr_p != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr_p != NULL", (const Char*)"hg_main.c", 1471, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((libhb_get_Thr_hgthread(hbthr_p) == thr_p) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"libhb_get_Thr_hgthread(hbthr_p) == thr_p", (const Char*)"hg_main.c", 1472, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      hbthr_c = libhb_create ( hbthr_p );



      thr_c = mk_Thread( hbthr_c );
      ((void) ((libhb_get_Thr_hgthread(hbthr_c) == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"libhb_get_Thr_hgthread(hbthr_c) == NULL", (const Char*)"hg_main.c", 1479, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      libhb_set_Thr_hgthread(hbthr_c, thr_c);


      map_threads[child] = thr_c;
      ((void) ((thr_c->coretid == ((ThreadId)(0))) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_c->coretid == VG_INVALID_THREADID", (const Char*)"hg_main.c", 1484, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      thr_c->coretid = child;
# 1498 "hg_main.c"
      { Word first_ip_delta = 0;



        thr_c->created_at = vgPlain_record_ExeContext(parent, first_ip_delta);
      }
   }

   if (vgHelgrind_clo_sanity_flags & (1<<0))
      all__sanity_check("evh__pre_thread_create-post");
}

static
void evh__pre_thread_ll_exit ( ThreadId quit_tid )
{
   Int nHeld;
   Thread* thr_q;
   if (0 >= 1)
      vgPlain_printf("evh__pre_thread_ll_exit(thr=%d)\n",
                  (Int)quit_tid );
# 1533 "hg_main.c"
   ((void) ((vgHelgrind_is_sane_ThreadId(quit_tid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(quit_tid)", (const Char*)"hg_main.c", 1533, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr_q = map_threads_maybe_lookup( quit_tid );
   ((void) ((thr_q != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_q != NULL", (const Char*)"hg_main.c", 1535, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


   nHeld = vgHelgrind_cardinalityWS( univ_lsets, thr_q->locksetA );
   ((void) ((nHeld >= 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"nHeld >= 0", (const Char*)"hg_main.c", 1539, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (nHeld > 0) {
      HChar buf[80];
      vgPlain_sprintf(buf, "Exiting thread still holds %d lock%s",
                        nHeld, nHeld > 1 ? "s" : "");
      vgHelgrind_record_error_Misc( thr_q, buf );
   }







   ((void) ((thr_q->hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_q->hbthr", (const Char*)"hg_main.c", 1553, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   libhb_async_exit(thr_q->hbthr);
   ((void) ((thr_q->coretid == quit_tid) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_q->coretid == quit_tid", (const Char*)"hg_main.c", 1555, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr_q->coretid = ((ThreadId)(0));
   map_threads_delete( quit_tid );

   if (vgHelgrind_clo_sanity_flags & (1<<0))
      all__sanity_check("evh__pre_thread_ll_exit-post");
}





static
void evh__atfork_child ( ThreadId tid )
{
   UInt i;
   Thread* thr;

   thr = map_threads_maybe_lookup( 0 );
   ((void) ((!thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!thr", (const Char*)"hg_main.c", 1574, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   for (i = 1; i < 500; i++) {
      if (i == tid)
         continue;
      thr = map_threads_maybe_lookup(i);
      if (!thr)
         continue;


      ((void) ((thr->hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr->hbthr", (const Char*)"hg_main.c", 1584, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      libhb_async_exit(thr->hbthr);
      ((void) ((thr->coretid == i) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr->coretid == i", (const Char*)"hg_main.c", 1586, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      thr->coretid = ((ThreadId)(0));
      map_threads_delete(i);
   }
}


static
void evh__HG_PTHREAD_JOIN_POST ( ThreadId stay_tid, Thread* quit_thr )
{
   Thread* thr_s;
   Thread* thr_q;
   Thr* hbthr_s;
   Thr* hbthr_q;
   SO* so;

   if (0 >= 1)
      vgPlain_printf("evh__post_thread_join(stayer=%d, quitter=%p)\n",
                  (Int)stay_tid, quit_thr );

   ((void) ((vgHelgrind_is_sane_ThreadId(stay_tid)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_ThreadId)(stay_tid)", (const Char*)"hg_main.c", 1606, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   thr_s = map_threads_maybe_lookup( stay_tid );
   thr_q = quit_thr;
   ((void) ((thr_s != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_s != NULL", (const Char*)"hg_main.c", 1610, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((thr_q != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_q != NULL", (const Char*)"hg_main.c", 1611, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((thr_s != thr_q) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr_s != thr_q", (const Char*)"hg_main.c", 1612, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   hbthr_s = thr_s->hbthr;
   hbthr_q = thr_q->hbthr;
   ((void) ((hbthr_s != hbthr_q) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr_s != hbthr_q", (const Char*)"hg_main.c", 1616, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((libhb_get_Thr_hgthread(hbthr_s) == thr_s) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"libhb_get_Thr_hgthread(hbthr_s) == thr_s", (const Char*)"hg_main.c", 1617, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((libhb_get_Thr_hgthread(hbthr_q) == thr_q) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"libhb_get_Thr_hgthread(hbthr_q) == thr_q", (const Char*)"hg_main.c", 1618, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));





   so = libhb_so_alloc();
   ((void) ((so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"so", (const Char*)"hg_main.c", 1625, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));



   libhb_so_send(hbthr_q, so, ((Bool)1) );
   libhb_so_recv(hbthr_s, so, ((Bool)1) );
   libhb_so_dealloc(so);
# 1642 "hg_main.c"
   ((void) ((map_threads_maybe_reverse_lookup_SLOW(thr_q) == ((ThreadId)(0))) ? 0 : (
 vgPlain_assert_fail
# 1642 "hg_main.c"
   ( ((Bool)0), (const Char*)"map_threads_maybe_reverse_lookup_SLOW(thr_q) == VG_INVALID_THREADID", (const Char*)
 "hg_main.c"
# 1642 "hg_main.c"
   ,
 1643
# 1642 "hg_main.c"
   , (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)))
                                     ;

   if (vgHelgrind_clo_sanity_flags & (1<<0))
      all__sanity_check("evh__post_thread_join-post");
}

static
void evh__pre_mem_read ( CorePart part, ThreadId tid, Char* s,
                         Addr a, SizeT size) {
   if (0 >= 2
       || (0 >= 1 && size != 1))
      vgPlain_printf("evh__pre_mem_read(ctid=%d, \"%s\", %p, %lu)\n",
                  (Int)tid, s, (void*)a, size );
   shadow_mem_cread_range( map_threads_lookup(tid), a, size);
   if (size >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__pre_mem_read-post");
}

static
void evh__pre_mem_read_asciiz ( CorePart part, ThreadId tid,
                                Char* s, Addr a ) {
   Int len;
   if (0 >= 1)
      vgPlain_printf("evh__pre_mem_asciiz(ctid=%d, \"%s\", %p)\n",
                  (Int)tid, s, (void*)a );




   if (!vgPlain_am_is_valid_for_client (a, 1, 0x1))
      return;
   len = vgPlain_strlen( (Char*) a );
   shadow_mem_cread_range( map_threads_lookup(tid), a, len+1 );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__pre_mem_read_asciiz-post");
}

static
void evh__pre_mem_write ( CorePart part, ThreadId tid, Char* s,
                          Addr a, SizeT size ) {
   if (0 >= 1)
      vgPlain_printf("evh__pre_mem_write(ctid=%d, \"%s\", %p, %lu)\n",
                  (Int)tid, s, (void*)a, size );
   shadow_mem_cwrite_range( map_threads_lookup(tid), a, size);
   if (size >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__pre_mem_write-post");
}

static
void evh__new_mem_heap ( Addr a, SizeT len, Bool is_inited ) {
   if (0 >= 1)
      vgPlain_printf("evh__new_mem_heap(%p, %lu, inited=%d)\n",
                  (void*)a, len, (Int)is_inited );

   if (is_inited) {
      shadow_mem_make_New(get_current_Thread(), a, len);
   } else {
      shadow_mem_make_New(get_current_Thread(), a, len);
   }
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__pre_mem_read-post");
}

static
void evh__die_mem_heap ( Addr a, SizeT len ) {
   if (0 >= 1)
      vgPlain_printf("evh__die_mem_heap(%p, %lu)\n", (void*)a, len );
   shadow_mem_make_NoAccess( get_current_Thread(), a, len );
   if (len >= 256 && (vgHelgrind_clo_sanity_flags & (1<<2)))
      all__sanity_check("evh__pre_mem_read-post");
}



static __attribute__((regparm(1)))
void evh__mem_help_cread_1(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply08_f__msmcread((hbthr),(a));
}

static __attribute__((regparm(1)))
void evh__mem_help_cread_2(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply16_f__msmcread((hbthr),(a));
}

static __attribute__((regparm(1)))
void evh__mem_help_cread_4(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply32_f__msmcread((hbthr),(a));
}

static __attribute__((regparm(1)))
void evh__mem_help_cread_8(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply64_f__msmcread((hbthr),(a));
}

static __attribute__((regparm(2)))
void evh__mem_help_cread_N(Addr a, SizeT size) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapplyNN_f__msmcread((hbthr),(a),(size));
}

static __attribute__((regparm(1)))
void evh__mem_help_cwrite_1(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply08_f__msmcwrite((hbthr),(a));
}

static __attribute__((regparm(1)))
void evh__mem_help_cwrite_2(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply16_f__msmcwrite((hbthr),(a));
}

static __attribute__((regparm(1)))
void evh__mem_help_cwrite_4(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply32_f__msmcwrite((hbthr),(a));
}

static __attribute__((regparm(1)))
void evh__mem_help_cwrite_8(Addr a) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapply64_f__msmcwrite((hbthr),(a));
}

static __attribute__((regparm(2)))
void evh__mem_help_cwrite_N(Addr a, SizeT size) {
   Thread* thr = get_current_Thread_in_C_C();
   Thr* hbthr = thr->hbthr;
   zsm_sapplyNN_f__msmcwrite((hbthr),(a),(size));
}
# 1796 "hg_main.c"
static
void evh__HG_PTHREAD_MUTEX_INIT_POST( ThreadId tid,
                                      void* mutex, Word mbRec )
{
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_MUTEX_INIT_POST(ctid=%d, mbRec=%ld, %p)\n",
                  (Int)tid, mbRec, (void*)mutex );
   ((void) ((mbRec == 0 || mbRec == 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"mbRec == 0 || mbRec == 1", (const Char*)"hg_main.c", 1803, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   map_locks_lookup_or_create( mbRec ? LK_mbRec : LK_nonRec,
                               (Addr)mutex, tid );
   if (vgHelgrind_clo_sanity_flags & (1<<1))
      all__sanity_check("evh__hg_PTHREAD_MUTEX_INIT_POST");
}

static
void evh__HG_PTHREAD_MUTEX_DESTROY_PRE( ThreadId tid, void* mutex )
{
   Thread* thr;
   Lock* lk;
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_MUTEX_DESTROY_PRE(ctid=%d, %p)\n",
                  (Int)tid, (void*)mutex );

   thr = map_threads_maybe_lookup( tid );

   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 1821, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   lk = map_locks_maybe_lookup( (Addr)mutex );

   if (lk == ((void*)0) || (lk->kind != LK_nonRec && lk->kind != LK_mbRec)) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_mutex_destroy with invalid argument" );
   }

   if (lk) {
      ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 1831, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((lk->guestaddr == (Addr)mutex) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->guestaddr == (Addr)mutex", (const Char*)"hg_main.c", 1832, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (lk->heldBy) {

         vgHelgrind_record_error_Misc(
            thr, "pthread_mutex_destroy of a locked mutex" );

         remove_Lock_from_locksets_of_all_owning_Threads( lk );
         vgPlain_deleteBag( lk->heldBy );
         lk->heldBy = ((void*)0);
         lk->heldW = ((Bool)0);
         lk->acquired_at = ((void*)0);
      }
      ((void) ((!lk->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lk->heldBy", (const Char*)"hg_main.c", 1844, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 1845, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      if (vgHelgrind_clo_track_lockorders)
         laog__handle_one_lock_deletion(lk);
      map_locks_delete( lk->guestaddr );
      del_LockN( lk );
   }

   if (vgHelgrind_clo_sanity_flags & (1<<1))
      all__sanity_check("evh__hg_PTHREAD_MUTEX_DESTROY_PRE");
}

static void evh__HG_PTHREAD_MUTEX_LOCK_PRE ( ThreadId tid,
                                             void* mutex, Word isTryLock )
{


   Thread* thr;
   Lock* lk;
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_MUTEX_LOCK_PRE(ctid=%d, mutex=%p)\n",
                  (Int)tid, (void*)mutex );

   ((void) ((isTryLock == 0 || isTryLock == 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"isTryLock == 0 || isTryLock == 1", (const Char*)"hg_main.c", 1868, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 1870, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   lk = map_locks_maybe_lookup( (Addr)mutex );

   if (lk && (lk->kind == LK_rdwr)) {
      vgHelgrind_record_error_Misc( thr, "pthread_mutex_lock with a "
                                   "pthread_rwlock_t* argument " );
   }

   if ( lk
        && isTryLock == 0
        && (lk->kind == LK_nonRec || lk->kind == LK_rdwr)
        && lk->heldBy
        && lk->heldW
        && vgPlain_elemBag( lk->heldBy, (Word)thr ) > 0 ) {




      HChar* errstr = "Attempt to re-lock a "
                      "non-recursive lock I already hold";
      HChar* auxstr = "Lock was previously acquired";
      if (lk->acquired_at) {
         vgHelgrind_record_error_Misc_w_aux( thr, errstr, auxstr, lk->acquired_at );
      } else {
         vgHelgrind_record_error_Misc( thr, errstr );
      }
   }
}

static void evh__HG_PTHREAD_MUTEX_LOCK_POST ( ThreadId tid, void* mutex )
{

   Thread* thr;
   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_MUTEX_LOCK_POST(ctid=%d, mutex=%p)\n",
                  (Int)tid, (void*)mutex );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 1909, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   evhH__post_thread_w_acquires_lock(
      thr,
      LK_mbRec,
      (Addr)mutex
   );
}

static void evh__HG_PTHREAD_MUTEX_UNLOCK_PRE ( ThreadId tid, void* mutex )
{

   Thread* thr;
   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_MUTEX_UNLOCK_PRE(ctid=%d, mutex=%p)\n",
                  (Int)tid, (void*)mutex );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 1927, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   evhH__pre_thread_releases_lock( thr, (Addr)mutex, ((Bool)0) );
}

static void evh__HG_PTHREAD_MUTEX_UNLOCK_POST ( ThreadId tid, void* mutex )
{

   Thread* thr;
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_MUTEX_UNLOCK_POST(ctid=%d, mutex=%p)\n",
                  (Int)tid, (void*)mutex );
   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 1940, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


}
# 1953 "hg_main.c"
static void evh__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE( ThreadId tid,
                                                     void* slock )
{
   Thread* thr;
   Lock* lk;




   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE"
                  "(ctid=%d, slock=%p)\n",
                  (Int)tid, (void*)slock );

   thr = map_threads_maybe_lookup( tid );
                                                 ;
   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 1969, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   lk = map_locks_maybe_lookup( (Addr)slock );
   if (lk && lk->heldBy) {



      evhH__pre_thread_releases_lock( thr, (Addr)slock,
                                           ((Bool)0) );
   }
}

static void evh__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST( ThreadId tid,
                                                      void* slock )
{
   Lock* lk;




   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_SPIN_INIT_OR_UNLOCK_POST"
                  "(ctid=%d, slock=%p)\n",
                  (Int)tid, (void*)slock );

   lk = map_locks_maybe_lookup( (Addr)slock );
   if (!lk) {
      map_locks_lookup_or_create( LK_nonRec, (Addr)slock, tid );
   }
}

static void evh__HG_PTHREAD_SPIN_LOCK_PRE( ThreadId tid,
                                           void* slock, Word isTryLock )
{
   evh__HG_PTHREAD_MUTEX_LOCK_PRE( tid, slock, isTryLock );
}

static void evh__HG_PTHREAD_SPIN_LOCK_POST( ThreadId tid,
                                            void* slock )
{
   evh__HG_PTHREAD_MUTEX_LOCK_POST( tid, slock );
}

static void evh__HG_PTHREAD_SPIN_DESTROY_PRE( ThreadId tid,
                                              void* slock )
{
   evh__HG_PTHREAD_MUTEX_DESTROY_PRE( tid, slock );
}
# 2039 "hg_main.c"
typedef
   struct {
      SO* so;
      void* mx_ga;
      UWord nWaiters;
   }
   CVInfo;



static WordFM* map_cond_to_CVInfo = ((void*)0);

static void map_cond_to_CVInfo_INIT ( void ) {
   if (__builtin_expect((map_cond_to_CVInfo == ((void*)0)), 0)) {
      map_cond_to_CVInfo = vgPlain_newFM( vgHelgrind_zalloc,
                                       "hg.mctCI.1", vgHelgrind_free, ((void*)0) );
      ((void) ((map_cond_to_CVInfo != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_cond_to_CVInfo != NULL", (const Char*)"hg_main.c", 2055, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }
}

static CVInfo* map_cond_to_CVInfo_lookup_or_alloc ( void* cond ) {
   UWord key, val;
   map_cond_to_CVInfo_INIT();
   if (vgPlain_lookupFM( map_cond_to_CVInfo, &key, &val, (UWord)cond )) {
      ((void) ((key == (UWord)cond) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"key == (UWord)cond", (const Char*)"hg_main.c", 2063, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return (CVInfo*)val;
   } else {
      SO* so = libhb_so_alloc();
      CVInfo* cvi = vgHelgrind_zalloc("hg.mctCloa.1", sizeof(CVInfo));
      cvi->so = so;
      cvi->mx_ga = 0;
      vgPlain_addToFM( map_cond_to_CVInfo, (UWord)cond, (UWord)cvi );
      return cvi;
   }
}

static void map_cond_to_CVInfo_delete ( void* cond ) {
   UWord keyW, valW;
   map_cond_to_CVInfo_INIT();
   if (vgPlain_delFromFM( map_cond_to_CVInfo, &keyW, &valW, (UWord)cond )) {
      CVInfo* cvi = (CVInfo*)valW;
      ((void) ((keyW == (UWord)cond) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (UWord)cond", (const Char*)"hg_main.c", 2080, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((cvi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi", (const Char*)"hg_main.c", 2081, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((cvi->so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi->so", (const Char*)"hg_main.c", 2082, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      libhb_so_dealloc(cvi->so);
      cvi->mx_ga = 0;
      vgHelgrind_free(cvi);
   }
}

static void evh__HG_PTHREAD_COND_SIGNAL_PRE ( ThreadId tid, void* cond )
{






   Thread* thr;
   CVInfo* cvi;


   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_COND_SIGNAL_PRE(ctid=%d, cond=%p)\n",
                  (Int)tid, (void*)cond );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2106, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   cvi = map_cond_to_CVInfo_lookup_or_alloc( cond );
   ((void) ((cvi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi", (const Char*)"hg_main.c", 2109, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((cvi->so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi->so", (const Char*)"hg_main.c", 2110, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
# 2144 "hg_main.c"
   libhb_so_send( thr->hbthr, cvi->so, ((Bool)1) );
}



static Bool evh__HG_PTHREAD_COND_WAIT_PRE ( ThreadId tid,
                                            void* cond, void* mutex )
{
   Thread* thr;
   Lock* lk;
   Bool lk_valid = ((Bool)1);
   CVInfo* cvi;

   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_COND_WAIT_PRE"
                  "(ctid=%d, cond=%p, mutex=%p)\n",
                  (Int)tid, (void*)cond, (void*)mutex );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2163, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   lk = map_locks_maybe_lookup( (Addr)mutex );




   if (lk == ((void*)0)) {
      lk_valid = ((Bool)0);
      vgHelgrind_record_error_Misc(
         thr,
         "pthread_cond_{timed}wait called with invalid mutex" );
   } else {
      ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 2176, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (lk->kind == LK_rdwr) {
         lk_valid = ((Bool)0);
         vgHelgrind_record_error_Misc(
            thr, "pthread_cond_{timed}wait called with mutex "
                 "of type pthread_rwlock_t*" );
      } else
         if (lk->heldBy == ((void*)0)) {
         lk_valid = ((Bool)0);
         vgHelgrind_record_error_Misc(
            thr, "pthread_cond_{timed}wait called with un-held mutex");
      } else
      if (lk->heldBy != ((void*)0)
          && vgPlain_elemBag( lk->heldBy, (Word)thr ) == 0) {
         lk_valid = ((Bool)0);
         vgHelgrind_record_error_Misc(
            thr, "pthread_cond_{timed}wait called with mutex "
                 "held by a different thread" );
      }
   }


   cvi = map_cond_to_CVInfo_lookup_or_alloc(cond);
   ((void) ((cvi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi", (const Char*)"hg_main.c", 2199, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((cvi->so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi->so", (const Char*)"hg_main.c", 2200, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (cvi->nWaiters == 0) {

      cvi->mx_ga = mutex;
   }
   else
   if (cvi->mx_ga != mutex) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_cond_{timed}wait: cond is associated "
              "with a different mutex");
   }
   cvi->nWaiters++;

   return lk_valid;
}

static void evh__HG_PTHREAD_COND_WAIT_POST ( ThreadId tid,
                                             void* cond, void* mutex )
{



   Thread* thr;
   CVInfo* cvi;

   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_COND_WAIT_POST"
                  "(ctid=%d, cond=%p, mutex=%p)\n",
                  (Int)tid, (void*)cond, (void*)mutex );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2231, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));



   cvi = map_cond_to_CVInfo_lookup_or_alloc( cond );
   ((void) ((cvi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi", (const Char*)"hg_main.c", 2236, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((cvi->so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi->so", (const Char*)"hg_main.c", 2237, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((cvi->nWaiters > 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cvi->nWaiters > 0", (const Char*)"hg_main.c", 2238, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (!libhb_so_everSent(cvi->so)) {



      vgHelgrind_record_error_Misc( thr, "Bug in libpthread: pthread_cond_wait "
                                   "succeeded on"
                                   " without prior pthread_cond_post");
   }


   libhb_so_recv( thr->hbthr, cvi->so, ((Bool)1) );

   cvi->nWaiters--;
}

static void evh__HG_PTHREAD_COND_DESTROY_PRE ( ThreadId tid,
                                               void* cond )
{



   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_COND_DESTROY_PRE"
                  "(ctid=%d, cond=%p)\n",
                  (Int)tid, (void*)cond );

   map_cond_to_CVInfo_delete( cond );
}







static
void evh__HG_PTHREAD_RWLOCK_INIT_POST( ThreadId tid, void* rwl )
{
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_RWLOCK_INIT_POST(ctid=%d, %p)\n",
                  (Int)tid, (void*)rwl );
   map_locks_lookup_or_create( LK_rdwr, (Addr)rwl, tid );
   if (vgHelgrind_clo_sanity_flags & (1<<1))
      all__sanity_check("evh__hg_PTHREAD_RWLOCK_INIT_POST");
}

static
void evh__HG_PTHREAD_RWLOCK_DESTROY_PRE( ThreadId tid, void* rwl )
{
   Thread* thr;
   Lock* lk;
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_RWLOCK_DESTROY_PRE(ctid=%d, %p)\n",
                  (Int)tid, (void*)rwl );

   thr = map_threads_maybe_lookup( tid );

   ((void) ((vgHelgrind_is_sane_Thread(thr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_Thread)(thr)", (const Char*)"hg_main.c", 2297, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   lk = map_locks_maybe_lookup( (Addr)rwl );

   if (lk == ((void*)0) || lk->kind != LK_rdwr) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_rwlock_destroy with invalid argument" );
   }

   if (lk) {
      ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 2307, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((lk->guestaddr == (Addr)rwl) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->guestaddr == (Addr)rwl", (const Char*)"hg_main.c", 2308, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (lk->heldBy) {

         vgHelgrind_record_error_Misc(
            thr, "pthread_rwlock_destroy of a locked mutex" );

         remove_Lock_from_locksets_of_all_owning_Threads( lk );
         vgPlain_deleteBag( lk->heldBy );
         lk->heldBy = ((void*)0);
         lk->heldW = ((Bool)0);
         lk->acquired_at = ((void*)0);
      }
      ((void) ((!lk->heldBy) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!lk->heldBy", (const Char*)"hg_main.c", 2320, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((vgHelgrind_is_sane_LockN(lk)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(is_sane_LockN)(lk)", (const Char*)"hg_main.c", 2321, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      if (vgHelgrind_clo_track_lockorders)
         laog__handle_one_lock_deletion(lk);
      map_locks_delete( lk->guestaddr );
      del_LockN( lk );
   }

   if (vgHelgrind_clo_sanity_flags & (1<<1))
      all__sanity_check("evh__hg_PTHREAD_RWLOCK_DESTROY_PRE");
}

static
void evh__HG_PTHREAD_RWLOCK_LOCK_PRE ( ThreadId tid,
                                       void* rwl,
                                       Word isW, Word isTryLock )
{


   Thread* thr;
   Lock* lk;
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_RWLOCK_LOCK_PRE(ctid=%d, isW=%d, %p)\n",
                  (Int)tid, (Int)isW, (void*)rwl );

   ((void) ((isW == 0 || isW == 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"isW == 0 || isW == 1", (const Char*)"hg_main.c", 2346, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((isTryLock == 0 || isTryLock == 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"isTryLock == 0 || isTryLock == 1", (const Char*)"hg_main.c", 2347, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2349, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   lk = map_locks_maybe_lookup( (Addr)rwl );
   if ( lk
        && (lk->kind == LK_nonRec || lk->kind == LK_mbRec) ) {

      vgHelgrind_record_error_Misc(
         thr, "pthread_rwlock_{rd,rw}lock with a "
              "pthread_mutex_t* argument " );
   }
}

static
void evh__HG_PTHREAD_RWLOCK_LOCK_POST ( ThreadId tid, void* rwl, Word isW )
{

   Thread* thr;
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_RWLOCK_LOCK_POST(ctid=%d, isW=%d, %p)\n",
                  (Int)tid, (Int)isW, (void*)rwl );

   ((void) ((isW == 0 || isW == 1) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"isW == 0 || isW == 1", (const Char*)"hg_main.c", 2370, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2372, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   (isW ? evhH__post_thread_w_acquires_lock
        : evhH__post_thread_r_acquires_lock)(
      thr,
      LK_rdwr,
      (Addr)rwl
   );
}

static void evh__HG_PTHREAD_RWLOCK_UNLOCK_PRE ( ThreadId tid, void* rwl )
{

   Thread* thr;
   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_RWLOCK_UNLOCK_PRE(ctid=%d, rwl=%p)\n",
                  (Int)tid, (void*)rwl );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2391, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   evhH__pre_thread_releases_lock( thr, (Addr)rwl, ((Bool)1) );
}

static void evh__HG_PTHREAD_RWLOCK_UNLOCK_POST ( ThreadId tid, void* rwl )
{

   Thread* thr;
   if (0 >= 1)
      vgPlain_printf("evh__hg_PTHREAD_RWLOCK_UNLOCK_POST(ctid=%d, rwl=%p)\n",
                  (Int)tid, (void*)rwl );
   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2404, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


}
# 2448 "hg_main.c"
static WordFM* map_sem_to_SO_stack = ((void*)0);

static void map_sem_to_SO_stack_INIT ( void ) {
   if (map_sem_to_SO_stack == ((void*)0)) {
      map_sem_to_SO_stack = vgPlain_newFM( vgHelgrind_zalloc, "hg.mstSs.1",
                                        vgHelgrind_free, ((void*)0) );
      ((void) ((map_sem_to_SO_stack != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_sem_to_SO_stack != NULL", (const Char*)"hg_main.c", 2454, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }
}

static void push_SO_for_sem ( void* sem, SO* so ) {
   UWord keyW;
   XArray* xa;
   ((void) ((so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"so", (const Char*)"hg_main.c", 2461, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   map_sem_to_SO_stack_INIT();
   if (vgPlain_lookupFM( map_sem_to_SO_stack,
                      &keyW, (UWord*)&xa, (UWord)sem )) {
      ((void) ((keyW == (UWord)sem) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (UWord)sem", (const Char*)"hg_main.c", 2465, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((xa) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"xa", (const Char*)"hg_main.c", 2466, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgPlain_addToXA( xa, &so );
   } else {
     xa = vgPlain_newXA( vgHelgrind_zalloc, "hg.pSfs.1", vgHelgrind_free, sizeof(SO*) );
      vgPlain_addToXA( xa, &so );
      vgPlain_addToFM( map_sem_to_SO_stack, (Word)sem, (Word)xa );
   }
}

static SO* mb_pop_SO_for_sem ( void* sem ) {
   UWord keyW;
   XArray* xa;
   SO* so;
   map_sem_to_SO_stack_INIT();
   if (vgPlain_lookupFM( map_sem_to_SO_stack,
                      &keyW, (UWord*)&xa, (UWord)sem )) {

      Word sz;
      ((void) ((keyW == (UWord)sem) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (UWord)sem", (const Char*)"hg_main.c", 2484, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      sz = vgPlain_sizeXA( xa );
      ((void) ((sz >= 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"sz >= 0", (const Char*)"hg_main.c", 2486, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (sz == 0)
         return ((void*)0);
      so = *(SO**)vgPlain_indexXA( xa, sz-1 );
      ((void) ((so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"so", (const Char*)"hg_main.c", 2490, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgPlain_dropTailXA( xa, 1 );
      return so;
   } else {

      return ((void*)0);
   }
}

static void evh__HG_POSIX_SEM_DESTROY_PRE ( ThreadId tid, void* sem )
{
   UWord keyW, valW;
   SO* so;

   if (0 >= 1)
      vgPlain_printf("evh__HG_POSIX_SEM_DESTROY_PRE(ctid=%d, sem=%p)\n",
                  (Int)tid, (void*)sem );

   map_sem_to_SO_stack_INIT();



   while (1) {
      so = mb_pop_SO_for_sem( sem );
      if (!so) break;
      libhb_so_dealloc(so);
   }

   if (vgPlain_delFromFM( map_sem_to_SO_stack, &keyW, &valW, (UWord)sem )) {
      XArray* xa = (XArray*)valW;
      ((void) ((keyW == (UWord)sem) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (UWord)sem", (const Char*)"hg_main.c", 2520, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((xa) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"xa", (const Char*)"hg_main.c", 2521, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((vgPlain_sizeXA(xa) == 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_(sizeXA)(xa) == 0", (const Char*)"hg_main.c", 2522, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgPlain_deleteXA(xa);
   }
}

static
void evh__HG_POSIX_SEM_INIT_POST ( ThreadId tid, void* sem, UWord value )
{
   SO* so;
   Thread* thr;

   if (0 >= 1)
      vgPlain_printf("evh__HG_POSIX_SEM_INIT_POST(ctid=%d, sem=%p, value=%lu)\n",
                  (Int)tid, (void*)sem, value );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2538, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));



   while (1) {
      so = mb_pop_SO_for_sem( sem );
      if (!so) break;
      libhb_so_dealloc(so);
   }



   if (value > 10000) {
      vgHelgrind_record_error_Misc(
         thr, "sem_init: initial value exceeds 10000; using 10000" );
      value = 10000;
   }



   for (; value > 0; value--) {
      Thr* hbthr = thr->hbthr;
      ((void) ((hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr", (const Char*)"hg_main.c", 2560, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      so = libhb_so_alloc();
      libhb_so_send( hbthr, so, ((Bool)1) );
      push_SO_for_sem( sem, so );
   }
}

static void evh__HG_POSIX_SEM_POST_PRE ( ThreadId tid, void* sem )
{
# 2578 "hg_main.c"
   Thread* thr;
   SO* so;
   Thr* hbthr;

   if (0 >= 1)
      vgPlain_printf("evh__HG_POSIX_SEM_POST_PRE(ctid=%d, sem=%p)\n",
                  (Int)tid, (void*)sem );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2587, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));



   hbthr = thr->hbthr;
   ((void) ((hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr", (const Char*)"hg_main.c", 2592, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   so = libhb_so_alloc();
   libhb_so_send( hbthr, so, ((Bool)1) );
   push_SO_for_sem( sem, so );
}

static void evh__HG_POSIX_SEM_WAIT_POST ( ThreadId tid, void* sem )
{





   Thread* thr;
   SO* so;
   Thr* hbthr;

   if (0 >= 1)
      vgPlain_printf("evh__HG_POSIX_SEM_WAIT_POST(ctid=%d, sem=%p)\n",
                  (Int)tid, (void*)sem );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2615, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));



   so = mb_pop_SO_for_sem( sem );

   if (so) {
      hbthr = thr->hbthr;
      ((void) ((hbthr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbthr", (const Char*)"hg_main.c", 2623, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      libhb_so_recv( hbthr, so, ((Bool)1) );
      libhb_so_dealloc(so);
   } else {



      vgHelgrind_record_error_Misc(
         thr, "Bug in libpthread: sem_wait succeeded on"
              " semaphore without prior sem_post");
   }
}






typedef
   struct {
      Bool initted;
      Bool resizable;
      UWord size;
      XArray* waiting;
   }
   Bar;

static Bar* new_Bar ( void ) {
   Bar* bar = vgHelgrind_zalloc( "hg.nB.1 (new_Bar)", sizeof(Bar) );
   ((void) ((bar) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar", (const Char*)"hg_main.c", 2653, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((bar->initted == ((Bool)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->initted == False", (const Char*)"hg_main.c", 2655, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   return bar;
}

static void delete_Bar ( Bar* bar ) {
   ((void) ((bar) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar", (const Char*)"hg_main.c", 2660, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (bar->waiting)
      vgPlain_deleteXA(bar->waiting);
   vgHelgrind_free(bar);
}




static WordFM* map_barrier_to_Bar = ((void*)0);

static void map_barrier_to_Bar_INIT ( void ) {
   if (__builtin_expect((map_barrier_to_Bar == ((void*)0)), 0)) {
      map_barrier_to_Bar = vgPlain_newFM( vgHelgrind_zalloc,
                                       "hg.mbtBI.1", vgHelgrind_free, ((void*)0) );
      ((void) ((map_barrier_to_Bar != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_barrier_to_Bar != NULL", (const Char*)"hg_main.c", 2675, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }
}

static Bar* map_barrier_to_Bar_lookup_or_alloc ( void* barrier ) {
   UWord key, val;
   map_barrier_to_Bar_INIT();
   if (vgPlain_lookupFM( map_barrier_to_Bar, &key, &val, (UWord)barrier )) {
      ((void) ((key == (UWord)barrier) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"key == (UWord)barrier", (const Char*)"hg_main.c", 2683, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return (Bar*)val;
   } else {
      Bar* bar = new_Bar();
      vgPlain_addToFM( map_barrier_to_Bar, (UWord)barrier, (UWord)bar );
      return bar;
   }
}

static void map_barrier_to_Bar_delete ( void* barrier ) {
   UWord keyW, valW;
   map_barrier_to_Bar_INIT();
   if (vgPlain_delFromFM( map_barrier_to_Bar, &keyW, &valW, (UWord)barrier )) {
      Bar* bar = (Bar*)valW;
      ((void) ((keyW == (UWord)barrier) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (UWord)barrier", (const Char*)"hg_main.c", 2697, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      delete_Bar(bar);
   }
}


static void evh__HG_PTHREAD_BARRIER_INIT_PRE ( ThreadId tid,
                                               void* barrier,
                                               UWord count,
                                               UWord resizable )
{
   Thread* thr;
   Bar* bar;

   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_BARRIER_INIT_PRE"
                  "(tid=%d, barrier=%p, count=%lu, resizable=%lu)\n",
                  (Int)tid, (void*)barrier, count, resizable );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2717, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (count == 0) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_init: 'count' argument is zero"
      );
   }

   if (resizable != 0 && resizable != 1) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_init: invalid 'resizable' argument"
      );
   }

   bar = map_barrier_to_Bar_lookup_or_alloc(barrier);
   ((void) ((bar) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar", (const Char*)"hg_main.c", 2732, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (bar->initted) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_init: barrier is already initialised"
      );
   }

   if (bar->waiting && vgPlain_sizeXA(bar->waiting) > 0) {
      ((void) ((bar->initted) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->initted", (const Char*)"hg_main.c", 2741, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_init: threads are waiting at barrier"
      );
      vgPlain_dropTailXA(bar->waiting, vgPlain_sizeXA(bar->waiting));
   }
   if (!bar->waiting) {
      bar->waiting = vgPlain_newXA( vgHelgrind_zalloc, "hg.eHPBIP.1", vgHelgrind_free,
                                 sizeof(Thread*) );
   }

   ((void) ((bar->waiting) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->waiting", (const Char*)"hg_main.c", 2752, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgPlain_sizeXA(bar->waiting) == 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_(sizeXA)(bar->waiting) == 0", (const Char*)"hg_main.c", 2753, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   bar->initted = ((Bool)1);
   bar->resizable = resizable == 1 ? ((Bool)1) : ((Bool)0);
   bar->size = count;
}


static void evh__HG_PTHREAD_BARRIER_DESTROY_PRE ( ThreadId tid,
                                                  void* barrier )
{
   Thread* thr;
   Bar* bar;




   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_BARRIER_DESTROY_PRE"
                  "(tid=%d, barrier=%p)\n",
                  (Int)tid, (void*)barrier );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2775, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   bar = map_barrier_to_Bar_lookup_or_alloc(barrier);
   ((void) ((bar) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar", (const Char*)"hg_main.c", 2778, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (!bar->initted) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_destroy: barrier was never initialised"
      );
   }

   if (bar->initted && bar->waiting && vgPlain_sizeXA(bar->waiting) > 0) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_destroy: threads are waiting at barrier"
      );
   }
# 2800 "hg_main.c"
   map_barrier_to_Bar_delete( barrier );
}
# 2810 "hg_main.c"
static void do_barrier_cross_sync_and_empty ( Bar* bar )
{

   UWord i;
   SO* so = libhb_so_alloc();

   ((void) ((bar->waiting) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->waiting", (const Char*)"hg_main.c", 2816, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgPlain_sizeXA(bar->waiting) == bar->size) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_(sizeXA)(bar->waiting) == bar->size", (const Char*)"hg_main.c", 2817, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


   for (i = 0; i < bar->size; i++) {
      Thread* t = *(Thread**)vgPlain_indexXA(bar->waiting, i);
      Thr* hbthr = t->hbthr;
      libhb_so_send( hbthr, so, ((Bool)0) );
   }

   for (i = 0; i < bar->size; i++) {
      Thread* t = *(Thread**)vgPlain_indexXA(bar->waiting, i);
      Thr* hbthr = t->hbthr;
      libhb_so_recv( hbthr, so, ((Bool)1) );
   }


   vgPlain_dropTailXA(bar->waiting, vgPlain_sizeXA(bar->waiting));



   libhb_so_dealloc(so);
}


static void evh__HG_PTHREAD_BARRIER_WAIT_PRE ( ThreadId tid,
                                               void* barrier )
{
# 2884 "hg_main.c"
   Thread* thr;
   Bar* bar;
   UWord present;

   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_BARRIER_WAIT_PRE"
                  "(tid=%d, barrier=%p)\n",
                  (Int)tid, (void*)barrier );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2894, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   bar = map_barrier_to_Bar_lookup_or_alloc(barrier);
   ((void) ((bar) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar", (const Char*)"hg_main.c", 2897, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (!bar->initted) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_wait: barrier is uninitialised"
      );
      return;
   }


   ((void) ((bar->size > 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->size > 0", (const Char*)"hg_main.c", 2907, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((bar->waiting) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->waiting", (const Char*)"hg_main.c", 2908, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   vgPlain_addToXA( bar->waiting, &thr );


   present = vgPlain_sizeXA(bar->waiting);
   ((void) ((present > 0 && present <= bar->size) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"present > 0 && present <= bar->size", (const Char*)"hg_main.c", 2914, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (present < bar->size)
      return;

   do_barrier_cross_sync_and_empty(bar);
}


static void evh__HG_PTHREAD_BARRIER_RESIZE_PRE ( ThreadId tid,
                                                 void* barrier,
                                                 UWord newcount )
{
   Thread* thr;
   Bar* bar;
   UWord present;

   if (0 >= 1)
      vgPlain_printf("evh__HG_PTHREAD_BARRIER_RESIZE_PRE"
                  "(tid=%d, barrier=%p, newcount=%lu)\n",
                  (Int)tid, (void*)barrier, newcount );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 2937, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   bar = map_barrier_to_Bar_lookup_or_alloc(barrier);
   ((void) ((bar) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar", (const Char*)"hg_main.c", 2940, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (!bar->initted) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_resize: barrier is uninitialised"
      );
      return;
   }

   if (!bar->resizable) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_resize: barrier is may not be resized"
      );
      return;
   }

   if (newcount == 0) {
      vgHelgrind_record_error_Misc(
         thr, "pthread_barrier_resize: 'newcount' argument is zero"
      );
      return;
   }


   ((void) ((bar->size > 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->size > 0", (const Char*)"hg_main.c", 2964, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((bar->waiting) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bar->waiting", (const Char*)"hg_main.c", 2965, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   ((void) ((newcount > 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"newcount > 0", (const Char*)"hg_main.c", 2967, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (newcount >= bar->size) {



      bar->size = newcount;
   } else {




      present = vgPlain_sizeXA(bar->waiting);
      ((void) ((present >= 0 && present <= bar->size) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"present >= 0 && present <= bar->size", (const Char*)"hg_main.c", 2980, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (newcount <= present) {
         bar->size = present;
         do_barrier_cross_sync_and_empty(bar);
      }
      bar->size = newcount;
   }
}
# 3001 "hg_main.c"
static WordFM* map_usertag_to_SO = ((void*)0);

static void map_usertag_to_SO_INIT ( void ) {
   if (__builtin_expect((map_usertag_to_SO == ((void*)0)), 0)) {
      map_usertag_to_SO = vgPlain_newFM( vgHelgrind_zalloc,
                                      "hg.mutS.1", vgHelgrind_free, ((void*)0) );
      ((void) ((map_usertag_to_SO != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_usertag_to_SO != NULL", (const Char*)"hg_main.c", 3007, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }
}

static SO* map_usertag_to_SO_lookup_or_alloc ( UWord usertag ) {
   UWord key, val;
   map_usertag_to_SO_INIT();
   if (vgPlain_lookupFM( map_usertag_to_SO, &key, &val, usertag )) {
      ((void) ((key == (UWord)usertag) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"key == (UWord)usertag", (const Char*)"hg_main.c", 3015, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return (SO*)val;
   } else {
      SO* so = libhb_so_alloc();
      vgPlain_addToFM( map_usertag_to_SO, usertag, (UWord)so );
      return so;
   }
}
# 3037 "hg_main.c"
static
void evh__HG_USERSO_SEND_PRE ( ThreadId tid, UWord usertag )
{






   Thread* thr;
   SO* so;

   if (0 >= 1)
      vgPlain_printf("evh__HG_USERSO_SEND_PRE(ctid=%d, usertag=%#lx)\n",
                  (Int)tid, usertag );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 3054, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   so = map_usertag_to_SO_lookup_or_alloc( usertag );
   ((void) ((so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"so", (const Char*)"hg_main.c", 3057, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   libhb_so_send( thr->hbthr, so, ((Bool)1) );
}

static
void evh__HG_USERSO_RECV_POST ( ThreadId tid, UWord usertag )
{






   Thread* thr;
   SO* so;

   if (0 >= 1)
      vgPlain_printf("evh__HG_USERSO_RECV_POST(ctid=%d, usertag=%#lx)\n",
                  (Int)tid, usertag );

   thr = map_threads_maybe_lookup( tid );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 3079, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   so = map_usertag_to_SO_lookup_or_alloc( usertag );
   ((void) ((so) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"so", (const Char*)"hg_main.c", 3082, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));




   libhb_so_recv( thr->hbthr, so, ((Bool)1) );
}
# 3121 "hg_main.c"
typedef
   struct {
      WordSetID inns;
      WordSetID outs;
   }
   LAOGLinks;


static WordFM* laog = ((void*)0);




typedef
   struct {
      Addr src_ga;
      Addr dst_ga;
      ExeContext* src_ec;
      ExeContext* dst_ec;
   }
   LAOGLinkExposition;

static Word cmp_LAOGLinkExposition ( UWord llx1W, UWord llx2W ) {

   LAOGLinkExposition* llx1 = (LAOGLinkExposition*)llx1W;
   LAOGLinkExposition* llx2 = (LAOGLinkExposition*)llx2W;
   if (llx1->src_ga < llx2->src_ga) return -1;
   if (llx1->src_ga > llx2->src_ga) return 1;
   if (llx1->dst_ga < llx2->dst_ga) return -1;
   if (llx1->dst_ga > llx2->dst_ga) return 1;
   return 0;
}

static WordFM* laog_exposition = ((void*)0);



__attribute__((noinline))
static void laog__init ( void )
{
   ((void) ((!laog) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!laog", (const Char*)"hg_main.c", 3161, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((!laog_exposition) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!laog_exposition", (const Char*)"hg_main.c", 3162, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((vgHelgrind_clo_track_lockorders) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"HG_(clo_track_lockorders)", (const Char*)"hg_main.c", 3163, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   laog = vgPlain_newFM( vgHelgrind_zalloc, "hg.laog__init.1",
                      vgHelgrind_free, ((void*)0) );

   laog_exposition = vgPlain_newFM( vgHelgrind_zalloc, "hg.laog__init.2", vgHelgrind_free,
                                 cmp_LAOGLinkExposition );
   ((void) ((laog) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"laog", (const Char*)"hg_main.c", 3170, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((laog_exposition) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"laog_exposition", (const Char*)"hg_main.c", 3171, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}

static void laog__show ( Char* who ) {
   Word i, ws_size;
   UWord* ws_words;
   Lock* me;
   LAOGLinks* links;
   vgPlain_printf("laog (requested by %s) {\n", who);
   vgPlain_initIterFM( laog );
   me = ((void*)0);
   links = ((void*)0);
   while (vgPlain_nextIterFM( laog, (Word*)&me,
                                 (Word*)&links )) {
      ((void) ((me) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"me", (const Char*)"hg_main.c", 3185, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3186, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgPlain_printf("   node %p:\n", me);
      vgHelgrind_getPayloadWS( &ws_words, &ws_size, univ_laog, links->inns );
      for (i = 0; i < ws_size; i++)
         vgPlain_printf("      inn %#lx\n", ws_words[i] );
      vgHelgrind_getPayloadWS( &ws_words, &ws_size, univ_laog, links->outs );
      for (i = 0; i < ws_size; i++)
         vgPlain_printf("      out %#lx\n", ws_words[i] );
      me = ((void*)0);
      links = ((void*)0);
   }
   vgPlain_doneIterFM( laog );
   vgPlain_printf("}\n");
}

__attribute__((noinline))
static void laog__add_edge ( Lock* src, Lock* dst ) {
   Word keyW;
   LAOGLinks* links;
   Bool presentF, presentR;
   if (0) vgPlain_printf("laog__add_edge %p %p\n", src, dst);
# 3216 "hg_main.c"
   presentF = presentR = ((Bool)0);


   keyW = 0;
   links = ((void*)0);
   if (vgPlain_lookupFM( laog, &keyW, (Word*)&links, (Word)src )) {
      WordSetID outs_new;
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3223, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((keyW == (Word)src) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (Word)src", (const Char*)"hg_main.c", 3224, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      outs_new = vgHelgrind_addToWS( univ_laog, links->outs, (Word)dst );
      presentF = outs_new == links->outs;
      links->outs = outs_new;
   } else {
      links = vgHelgrind_zalloc("hg.lae.1", sizeof(LAOGLinks));
      links->inns = vgHelgrind_emptyWS( univ_laog );
      links->outs = vgHelgrind_singletonWS( univ_laog, (Word)dst );
      vgPlain_addToFM( laog, (Word)src, (Word)links );
   }

   keyW = 0;
   links = ((void*)0);
   if (vgPlain_lookupFM( laog, &keyW, (Word*)&links, (Word)dst )) {
      WordSetID inns_new;
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3239, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((keyW == (Word)dst) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (Word)dst", (const Char*)"hg_main.c", 3240, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      inns_new = vgHelgrind_addToWS( univ_laog, links->inns, (Word)src );
      presentR = inns_new == links->inns;
      links->inns = inns_new;
   } else {
      links = vgHelgrind_zalloc("hg.lae.2", sizeof(LAOGLinks));
      links->inns = vgHelgrind_singletonWS( univ_laog, (Word)src );
      links->outs = vgHelgrind_emptyWS( univ_laog );
      vgPlain_addToFM( laog, (Word)dst, (Word)links );
   }

   ((void) (((presentF && presentR) || (!presentF && !presentR)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"(presentF && presentR) || (!presentF && !presentR)", (const Char*)"hg_main.c", 3251, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (!presentF && src->acquired_at && dst->acquired_at) {
      LAOGLinkExposition expo;





      if (0) vgPlain_printf("acquire edge %#lx %#lx\n",
                         src->guestaddr, dst->guestaddr);
      expo.src_ga = src->guestaddr;
      expo.dst_ga = dst->guestaddr;
      expo.src_ec = ((void*)0);
      expo.dst_ec = ((void*)0);
      ((void) ((laog_exposition) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"laog_exposition", (const Char*)"hg_main.c", 3266, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      if (vgPlain_lookupFM( laog_exposition, ((void*)0), ((void*)0), (Word)&expo )) {

      } else {
         LAOGLinkExposition* expo2 = vgHelgrind_zalloc("hg.lae.3",
                                               sizeof(LAOGLinkExposition));
         expo2->src_ga = src->guestaddr;
         expo2->dst_ga = dst->guestaddr;
         expo2->src_ec = src->acquired_at;
         expo2->dst_ec = dst->acquired_at;
         vgPlain_addToFM( laog_exposition, (Word)expo2, (Word)((void*)0) );
      }
   }
}

__attribute__((noinline))
static void laog__del_edge ( Lock* src, Lock* dst ) {
   Word keyW;
   LAOGLinks* links;
   if (0) vgPlain_printf("laog__del_edge %p %p\n", src, dst);

   keyW = 0;
   links = ((void*)0);
   if (vgPlain_lookupFM( laog, &keyW, (Word*)&links, (Word)src )) {
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3290, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((keyW == (Word)src) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (Word)src", (const Char*)"hg_main.c", 3291, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      links->outs = vgHelgrind_delFromWS( univ_laog, links->outs, (Word)dst );
   }

   keyW = 0;
   links = ((void*)0);
   if (vgPlain_lookupFM( laog, &keyW, (Word*)&links, (Word)dst )) {
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3298, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((keyW == (Word)dst) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (Word)dst", (const Char*)"hg_main.c", 3299, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      links->inns = vgHelgrind_delFromWS( univ_laog, links->inns, (Word)src );
   }
}

__attribute__((noinline))
static WordSetID laog__succs ( Lock* lk ) {
   Word keyW;
   LAOGLinks* links;
   keyW = 0;
   links = ((void*)0);
   if (vgPlain_lookupFM( laog, &keyW, (Word*)&links, (Word)lk )) {
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3311, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((keyW == (Word)lk) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (Word)lk", (const Char*)"hg_main.c", 3312, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return links->outs;
   } else {
      return vgHelgrind_emptyWS( univ_laog );
   }
}

__attribute__((noinline))
static WordSetID laog__preds ( Lock* lk ) {
   Word keyW;
   LAOGLinks* links;
   keyW = 0;
   links = ((void*)0);
   if (vgPlain_lookupFM( laog, &keyW, (Word*)&links, (Word)lk )) {
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3326, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((keyW == (Word)lk) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"keyW == (Word)lk", (const Char*)"hg_main.c", 3327, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      return links->inns;
   } else {
      return vgHelgrind_emptyWS( univ_laog );
   }
}

__attribute__((noinline))
static void laog__sanity_check ( Char* who ) {
   Word i, ws_size;
   UWord* ws_words;
   Lock* me;
   LAOGLinks* links;
   vgPlain_initIterFM( laog );
   me = ((void*)0);
   links = ((void*)0);
   if (0) vgPlain_printf("laog sanity check\n");
   while (vgPlain_nextIterFM( laog, (Word*)&me,
                                 (Word*)&links )) {
      ((void) ((me) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"me", (const Char*)"hg_main.c", 3346, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((links) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"links", (const Char*)"hg_main.c", 3347, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      vgHelgrind_getPayloadWS( &ws_words, &ws_size, univ_laog, links->inns );
      for (i = 0; i < ws_size; i++) {
         if ( ! vgHelgrind_elemWS( univ_laog,
                             laog__succs( (Lock*)ws_words[i] ),
                             (Word)me ))
            goto bad;
      }
      vgHelgrind_getPayloadWS( &ws_words, &ws_size, univ_laog, links->outs );
      for (i = 0; i < ws_size; i++) {
         if ( ! vgHelgrind_elemWS( univ_laog,
                             laog__preds( (Lock*)ws_words[i] ),
                             (Word)me ))
            goto bad;
      }
      me = ((void*)0);
      links = ((void*)0);
   }
   vgPlain_doneIterFM( laog );
   return;

  bad:
   vgPlain_printf("laog__sanity_check(%s) FAILED\n", who);
   laog__show(who);
   ((void) ((0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"0", (const Char*)"hg_main.c", 3371, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
}





__attribute__((noinline))
static
Lock* laog__do_dfs_from_to ( Lock* src, WordSetID dsts )
{
   Lock* ret;
   Word i, ssz;
   XArray* stack;
   WordFM* visited;
   Lock* here;
   WordSetID succs;
   Word succs_size;
   UWord* succs_words;




   if (vgHelgrind_isEmptyWS( univ_lsets, dsts ))
      return ((void*)0);

   ret = ((void*)0);
   stack = vgPlain_newXA( vgHelgrind_zalloc, "hg.lddft.1", vgHelgrind_free, sizeof(Lock*) );
   visited = vgPlain_newFM( vgHelgrind_zalloc, "hg.lddft.2", vgHelgrind_free, ((void*)0) );

   (void) vgPlain_addToXA( stack, &src );

   while (((Bool)1)) {

      ssz = vgPlain_sizeXA( stack );

      if (ssz == 0) { ret = ((void*)0); break; }

      here = *(Lock**) vgPlain_indexXA( stack, ssz-1 );
      vgPlain_dropTailXA( stack, 1 );

      if (vgHelgrind_elemWS( univ_lsets, dsts, (Word)here )) { ret = here; break; }

      if (vgPlain_lookupFM( visited, ((void*)0), ((void*)0), (Word)here ))
         continue;

      vgPlain_addToFM( visited, (Word)here, 0 );

      succs = laog__succs( here );
      vgHelgrind_getPayloadWS( &succs_words, &succs_size, univ_laog, succs );
      for (i = 0; i < succs_size; i++)
         (void) vgPlain_addToXA( stack, &succs_words[i] );
   }

   vgPlain_deleteFM( visited, ((void*)0), ((void*)0) );
   vgPlain_deleteXA( stack );
   return ret;
}






__attribute__((noinline))
static void laog__pre_thread_acquires_lock (
               Thread* thr,
               Lock* lk
            )
{
   UWord* ls_words;
   Word ls_size, i;
   Lock* other;




   if (vgHelgrind_elemWS( univ_lsets, thr->locksetA, (Word)lk ))
      return;







   other = laog__do_dfs_from_to(lk, thr->locksetA);
   if (other) {
      LAOGLinkExposition key, *found;







      key.src_ga = lk->guestaddr;
      key.dst_ga = other->guestaddr;
      key.src_ec = ((void*)0);
      key.dst_ec = ((void*)0);
      found = ((void*)0);
      if (vgPlain_lookupFM( laog_exposition,
                         (Word*)&found, ((void*)0), (Word)&key )) {
         ((void) ((found != &key) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"found != &key", (const Char*)"hg_main.c", 3474, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((found->src_ga == key.src_ga) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"found->src_ga == key.src_ga", (const Char*)"hg_main.c", 3475, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((found->dst_ga == key.dst_ga) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"found->dst_ga == key.dst_ga", (const Char*)"hg_main.c", 3476, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((found->src_ec) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"found->src_ec", (const Char*)"hg_main.c", 3477, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((found->dst_ec) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"found->dst_ec", (const Char*)"hg_main.c", 3478, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         vgHelgrind_record_error_LockOrder(
            thr, lk->guestaddr, other->guestaddr,
                 found->src_ec, found->dst_ec );
      } else {

         vgHelgrind_record_error_LockOrder(
            thr, lk->guestaddr, other->guestaddr,
                 ((void*)0), ((void*)0) );
      }
   }






   ((void) ((lk->acquired_at) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"lk->acquired_at", (const Char*)"hg_main.c", 3495, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   vgHelgrind_getPayloadWS( &ls_words, &ls_size, univ_lsets, thr->locksetA );
   for (i = 0; i < ls_size; i++) {
      Lock* old = (Lock*)ls_words[i];
      ((void) ((old->acquired_at) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"old->acquired_at", (const Char*)"hg_main.c", 3499, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      laog__add_edge( old, lk );
   }






   if (vgHelgrind_clo_sanity_flags & (1<<4))
      all_except_Locks__sanity_check("laog__pre_thread_acquires_lock-post");
}




__attribute__((noinline))
static void laog__handle_one_lock_deletion ( Lock* lk )
{
   WordSetID preds, succs;
   Word preds_size, succs_size, i, j;
   UWord *preds_words, *succs_words;

   preds = laog__preds( lk );
   succs = laog__succs( lk );

   vgHelgrind_getPayloadWS( &preds_words, &preds_size, univ_laog, preds );
   for (i = 0; i < preds_size; i++)
      laog__del_edge( (Lock*)preds_words[i], lk );

   vgHelgrind_getPayloadWS( &succs_words, &succs_size, univ_laog, succs );
   for (j = 0; j < succs_size; j++)
      laog__del_edge( lk, (Lock*)succs_words[j] );

   for (i = 0; i < preds_size; i++) {
      for (j = 0; j < succs_size; j++) {
         if (preds_words[i] != succs_words[j]) {



            laog__add_edge( (Lock*)preds_words[i], (Lock*)succs_words[j] );
         }
      }
   }
}
# 3567 "hg_main.c"
typedef
   struct {
      void* next;
      Addr payload;
      SizeT szB;
      ExeContext* where;
      Thread* thr;
   }
   MallocMeta;



static VgHashTable hg_mallocmeta_table = ((void*)0);


static MallocMeta* new_MallocMeta ( void ) {
   MallocMeta* md = vgHelgrind_zalloc( "hg.new_MallocMeta.1", sizeof(MallocMeta) );
   ((void) ((md) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"md", (const Char*)"hg_main.c", 3584, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   return md;
}
static void delete_MallocMeta ( MallocMeta* md ) {
   vgHelgrind_free(md);
}




static
void* handle_alloc ( ThreadId tid,
                     SizeT szB, SizeT alignB, Bool is_zeroed )
{
   Addr p;
   MallocMeta* md;

   ((void) ((((SSizeT)szB) >= 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"((SSizeT)szB) >= 0", (const Char*)"hg_main.c", 3601, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   p = (Addr)vgPlain_cli_malloc(alignB, szB);
   if (!p) {
      return ((void*)0);
   }
   if (is_zeroed)
      vgPlain_memset((void*)p, 0, szB);




   md = new_MallocMeta();
   md->payload = p;
   md->szB = szB;
   md->where = vgPlain_record_ExeContext( tid, 0 );
   md->thr = map_threads_lookup( tid );

   vgPlain_HT_add_node( hg_mallocmeta_table, (VgHashNode*)md );


   evh__new_mem_heap( p, szB, is_zeroed );

   return (void*)p;
}






static void* hg_cli__malloc ( ThreadId tid, SizeT n ) {
   if (((SSizeT)n) < 0) return ((void*)0);
   return handle_alloc ( tid, n, vgPlain_clo_alignment,
                                      ((Bool)0) );
}
static void* hg_cli____builtin_new ( ThreadId tid, SizeT n ) {
   if (((SSizeT)n) < 0) return ((void*)0);
   return handle_alloc ( tid, n, vgPlain_clo_alignment,
                                      ((Bool)0) );
}
static void* hg_cli____builtin_vec_new ( ThreadId tid, SizeT n ) {
   if (((SSizeT)n) < 0) return ((void*)0);
   return handle_alloc ( tid, n, vgPlain_clo_alignment,
                                      ((Bool)0) );
}
static void* hg_cli__memalign ( ThreadId tid, SizeT align, SizeT n ) {
   if (((SSizeT)n) < 0) return ((void*)0);
   return handle_alloc ( tid, n, align,
                                      ((Bool)0) );
}
static void* hg_cli__calloc ( ThreadId tid, SizeT nmemb, SizeT size1 ) {
   if ( ((SSizeT)nmemb) < 0 || ((SSizeT)size1) < 0 ) return ((void*)0);
   return handle_alloc ( tid, nmemb*size1, vgPlain_clo_alignment,
                                      ((Bool)1) );
}





static void handle_free ( ThreadId tid, void* p )
{
   MallocMeta *md, *old_md;
   SizeT szB;


   md = (MallocMeta*) vgPlain_HT_lookup( hg_mallocmeta_table, (UWord)p );
   if (!md)
      return;

   ((void) ((md->payload == (Addr)p) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"md->payload == (Addr)p", (const Char*)"hg_main.c", 3671, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   szB = md->szB;


   old_md = (MallocMeta*)
            vgPlain_HT_remove( hg_mallocmeta_table, (UWord)p );
   ((void) ((old_md) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"old_md", (const Char*)"hg_main.c", 3677, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((old_md == md) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"old_md == md", (const Char*)"hg_main.c", 3678, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((old_md->payload == (Addr)p) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"old_md->payload == (Addr)p", (const Char*)"hg_main.c", 3679, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   vgPlain_cli_free((void*)old_md->payload);
   delete_MallocMeta(old_md);


   evh__die_mem_heap( (Addr)p, szB );
}

static void hg_cli__free ( ThreadId tid, void* p ) {
   handle_free(tid, p);
}
static void hg_cli____builtin_delete ( ThreadId tid, void* p ) {
   handle_free(tid, p);
}
static void hg_cli____builtin_vec_delete ( ThreadId tid, void* p ) {
   handle_free(tid, p);
}


static void* hg_cli__realloc ( ThreadId tid, void* payloadV, SizeT new_size )
{
   MallocMeta *md, *md_new, *md_tmp;
   SizeT i;

   Addr payload = (Addr)payloadV;

   if (((SSizeT)new_size) < 0) return ((void*)0);

   md = (MallocMeta*) vgPlain_HT_lookup( hg_mallocmeta_table, (UWord)payload );
   if (!md)
      return ((void*)0);

   ((void) ((md->payload == payload) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"md->payload == payload", (const Char*)"hg_main.c", 3712, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   if (md->szB == new_size) {

      md->where = vgPlain_record_ExeContext(tid, 0);
      return payloadV;
   }

   if (md->szB > new_size) {

      md->szB = new_size;
      md->where = vgPlain_record_ExeContext(tid, 0);
      evh__die_mem_heap( md->payload + new_size, md->szB - new_size );
      return payloadV;
   }

              {

      Addr p_new = (Addr)vgPlain_cli_malloc(vgPlain_clo_alignment, new_size);




      evh__copy_mem( payload, p_new, md->szB );
      evh__new_mem_heap ( p_new + md->szB, new_size - md->szB,
                                    ((Bool)0) );



      evh__die_mem_heap( payload, md->szB );


      for (i = 0; i < md->szB; i++)
         ((UChar*)p_new)[i] = ((UChar*)payload)[i];






      md_new = new_MallocMeta();
      *md_new = *md;

      md_tmp = vgPlain_HT_remove( hg_mallocmeta_table, payload );
      ((void) ((md_tmp) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"md_tmp", (const Char*)"hg_main.c", 3756, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((md_tmp == md) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"md_tmp == md", (const Char*)"hg_main.c", 3757, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      vgPlain_cli_free((void*)md->payload);
      delete_MallocMeta(md);


      md_new->where = vgPlain_record_ExeContext( tid, 0 );
      md_new->szB = new_size;
      md_new->payload = p_new;
      md_new->thr = map_threads_lookup( tid );


      vgPlain_HT_add_node( hg_mallocmeta_table, (VgHashNode*)md_new );

      return (void*)p_new;
   }
}

static SizeT hg_cli_malloc_usable_size ( ThreadId tid, void* p )
{
   MallocMeta *md = vgPlain_HT_lookup( hg_mallocmeta_table, (UWord)p );



   return ( md ? md->szB : 0 );
}







static inline Bool addr_is_in_MM_Chunk( MallocMeta* mm, Addr a )
{


  if (__builtin_expect((mm->szB == 0 && a == mm->payload), 0))
     return ((Bool)1);

  if (__builtin_expect(!!(a < mm->payload), 1)) return ((Bool)0);
  if (__builtin_expect(!!(a >= mm->payload + mm->szB), 1)) return ((Bool)0);
  return ((Bool)1);
}

Bool vgHelgrind_mm_find_containing_block( ExeContext** where,
                                           Addr* payload,
                                           SizeT* szB,
                                    Addr data_addr )
{
   MallocMeta* mm;
   Int i;
   const Int n_fast_check_words = 16;





   for (i = 0; i < n_fast_check_words; i++) {
      mm = vgPlain_HT_lookup( hg_mallocmeta_table,
                           data_addr - (UWord)(UInt)i * sizeof(UWord) );
      if (__builtin_expect((mm && addr_is_in_MM_Chunk(mm, data_addr)), 0))
         goto found;
   }




   vgPlain_HT_ResetIter(hg_mallocmeta_table);
   while ( (mm = vgPlain_HT_Next(hg_mallocmeta_table)) ) {
      if (__builtin_expect((addr_is_in_MM_Chunk(mm, data_addr)), 0))
         goto found;
   }


   return ((Bool)0);


  found:
   ((void) ((mm) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"mm", (const Char*)"hg_main.c", 3836, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((addr_is_in_MM_Chunk(mm, data_addr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"addr_is_in_MM_Chunk(mm, data_addr)", (const Char*)"hg_main.c", 3837, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (where) *where = mm->where;
   if (payload) *payload = mm->payload;
   if (szB) *szB = mm->szB;
   return ((Bool)1);
}






static void instrument_mem_access ( IRSB* bbOut,
                                    IRExpr* addr,
                                    Int szB,
                                    Bool isStore,
                                    Int hWordTy_szB )
{
   IRType tyAddr = Ity_INVALID;
   HChar* hName = ((void*)0);
   void* hAddr = ((void*)0);
   Int regparms = 0;
   IRExpr** argv = ((void*)0);
   IRDirty* di = ((void*)0);

   ((void) ((isIRAtom(addr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"isIRAtom(addr)", (const Char*)"hg_main.c", 3862, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((hWordTy_szB == 4 || hWordTy_szB == 8) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hWordTy_szB == 4 || hWordTy_szB == 8", (const Char*)"hg_main.c", 3863, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

   tyAddr = typeOfIRExpr( bbOut->tyenv, addr );
   ((void) ((tyAddr == Ity_I32 || tyAddr == Ity_I64) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"tyAddr == Ity_I32 || tyAddr == Ity_I64", (const Char*)"hg_main.c", 3866, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


   regparms = 1;
   if (isStore) {
      switch (szB) {
         case 1:
            hName = "evh__mem_help_cwrite_1";
            hAddr = &evh__mem_help_cwrite_1;
            argv = mkIRExprVec_1( addr );
            break;
         case 2:
            hName = "evh__mem_help_cwrite_2";
            hAddr = &evh__mem_help_cwrite_2;
            argv = mkIRExprVec_1( addr );
            break;
         case 4:
            hName = "evh__mem_help_cwrite_4";
            hAddr = &evh__mem_help_cwrite_4;
            argv = mkIRExprVec_1( addr );
            break;
         case 8:
            hName = "evh__mem_help_cwrite_8";
            hAddr = &evh__mem_help_cwrite_8;
            argv = mkIRExprVec_1( addr );
            break;
         default:
            ((void) ((szB > 8 && szB <= 512) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"szB > 8 && szB <= 512", (const Char*)"hg_main.c", 3893, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
            regparms = 2;
            hName = "evh__mem_help_cwrite_N";
            hAddr = &evh__mem_help_cwrite_N;
            argv = mkIRExprVec_2( addr, mkIRExpr_HWord( szB ));
            break;
      }
   } else {
      switch (szB) {
         case 1:
            hName = "evh__mem_help_cread_1";
            hAddr = &evh__mem_help_cread_1;
            argv = mkIRExprVec_1( addr );
            break;
         case 2:
            hName = "evh__mem_help_cread_2";
            hAddr = &evh__mem_help_cread_2;
            argv = mkIRExprVec_1( addr );
            break;
         case 4:
            hName = "evh__mem_help_cread_4";
            hAddr = &evh__mem_help_cread_4;
            argv = mkIRExprVec_1( addr );
            break;
         case 8:
            hName = "evh__mem_help_cread_8";
            hAddr = &evh__mem_help_cread_8;
            argv = mkIRExprVec_1( addr );
            break;
         default:
            ((void) ((szB > 8 && szB <= 512) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"szB > 8 && szB <= 512", (const Char*)"hg_main.c", 3923, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
            regparms = 2;
            hName = "evh__mem_help_cread_N";
            hAddr = &evh__mem_help_cread_N;
            argv = mkIRExprVec_2( addr, mkIRExpr_HWord( szB ));
            break;
      }
   }


   ((void) ((hName) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hName", (const Char*)"hg_main.c", 3933, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((hAddr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hAddr", (const Char*)"hg_main.c", 3934, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((argv) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"argv", (const Char*)"hg_main.c", 3935, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   di = unsafeIRDirty_0_N( regparms,
                           hName, vgPlain_fnptr_to_fnentry( hAddr ),
                           argv );
   addStmtToIRSB( bbOut, IRStmt_Dirty(di) );
}





static Bool is_in_dynamic_linker_shared_object( Addr64 ga )
{
   DebugInfo* dinfo;
   const UChar* soname;
   if (0) return ((Bool)0);

   dinfo = vgPlain_find_DebugInfo( (Addr)ga );
   if (!dinfo) return ((Bool)0);

   soname = vgPlain_DebugInfo_get_soname(dinfo);
   ((void) ((soname) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"soname", (const Char*)"hg_main.c", 3956, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   if (0) vgPlain_printf("%s\n", soname);


   if (( (soname != ((void*)0) && "ld-linux.so.3" != ((void*)0) && vgPlain_strcmp((soname),("ld-linux.so.3"))==0) ? ((Bool)1) : ((Bool)0) )) return ((Bool)1);
   if (( (soname != ((void*)0) && "ld-linux.so.2" != ((void*)0) && vgPlain_strcmp((soname),("ld-linux.so.2"))==0) ? ((Bool)1) : ((Bool)0) )) return ((Bool)1);
   if (( (soname != ((void*)0) && "ld-linux-x86-64.so.2" != ((void*)0) && vgPlain_strcmp((soname),("ld-linux-x86-64.so.2"))==0) ? ((Bool)1) : ((Bool)0) )) return ((Bool)1);
   if (( (soname != ((void*)0) && "ld64.so.1" != ((void*)0) && vgPlain_strcmp((soname),("ld64.so.1"))==0) ? ((Bool)1) : ((Bool)0) )) return ((Bool)1);
   if (( (soname != ((void*)0) && "ld.so.1" != ((void*)0) && vgPlain_strcmp((soname),("ld.so.1"))==0) ? ((Bool)1) : ((Bool)0) )) return ((Bool)1);





   return ((Bool)0);
}

static
IRSB* hg_instrument ( VgCallbackClosure* closure,
                      IRSB* bbIn,
                      VexGuestLayout* layout,
                      VexGuestExtents* vge,
                      IRType gWordTy, IRType hWordTy )
{
   Int i;
   IRSB* bbOut;
   Addr64 cia;
   IRStmt* st;
   Bool inLDSO = ((Bool)0);
   Addr64 inLDSOmask4K = 1;

   if (gWordTy != hWordTy) {

      vgPlain_tool_panic("host/guest word size mismatch");
   }

   if ((1UL << 12) < 4096 || vgPlain_log2((1UL << 12)) == -1) {
      vgPlain_tool_panic("implausible or too-small VKI_PAGE_SIZE");
   }


   bbOut = emptyIRSB();
   bbOut->tyenv = deepCopyIRTypeEnv(bbIn->tyenv);
   bbOut->next = deepCopyIRExpr(bbIn->next);
   bbOut->jumpkind = bbIn->jumpkind;


   i = 0;
   while (i < bbIn->stmts_used && bbIn->stmts[i]->tag != Ist_IMark) {
      addStmtToIRSB( bbOut, bbIn->stmts[i] );
      i++;
   }


   ((void) ((bbIn->stmts_used > 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"bbIn->stmts_used > 0", (const Char*)"hg_main.c", 4010, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((i < bbIn->stmts_used) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"i < bbIn->stmts_used", (const Char*)"hg_main.c", 4011, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   st = bbIn->stmts[i];
   ((void) ((Ist_IMark == st->tag) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"Ist_IMark == st->tag", (const Char*)"hg_main.c", 4013, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   cia = st->Ist.IMark.addr;
   st = ((void*)0);

   for ( ; i < bbIn->stmts_used; i++) {
      st = bbIn->stmts[i];
      ((void) ((st) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"st", (const Char*)"hg_main.c", 4019, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      ((void) ((isFlatIRStmt(st)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"isFlatIRStmt(st)", (const Char*)"hg_main.c", 4020, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
      switch (st->tag) {
         case Ist_NoOp:
         case Ist_AbiHint:
         case Ist_Put:
         case Ist_PutI:
         case Ist_Exit:

            break;

         case Ist_IMark:

            cia = st->Ist.IMark.addr;







            if ((cia & ~(Addr64)0xFFF) != inLDSOmask4K) {
               if (0) vgPlain_printf("NEW %#lx\n", (Addr)cia);
               inLDSOmask4K = cia & ~(Addr64)0xFFF;
               inLDSO = is_in_dynamic_linker_shared_object(cia);
            } else {
               if (0) vgPlain_printf("old %#lx\n", (Addr)cia);
            }
            break;

         case Ist_MBE:
            switch (st->Ist.MBE.event) {
               case Imbe_Fence:
                  break;
               default:
                  goto unhandled;
            }
            break;

         case Ist_CAS: {


            IRCAS* cas = st->Ist.CAS.details;
            Bool isDCAS = cas->oldHi != ((IRTemp)0xFFFFFFFF);
            if (isDCAS) {
               ((void) ((cas->expdHi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cas->expdHi", (const Char*)"hg_main.c", 4064, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
               ((void) ((cas->dataHi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"cas->dataHi", (const Char*)"hg_main.c", 4065, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
            } else {
               ((void) ((!cas->expdHi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!cas->expdHi", (const Char*)"hg_main.c", 4067, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
               ((void) ((!cas->dataHi) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"!cas->dataHi", (const Char*)"hg_main.c", 4068, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
            }

            if (!inLDSO) {
               instrument_mem_access(
                  bbOut,
                  cas->addr,
                  (isDCAS ? 2 : 1)
                     * sizeofIRType(typeOfIRExpr(bbIn->tyenv, cas->dataLo)),
                  ((Bool)0) ,
                  sizeofIRType(hWordTy)
               );
            }
            break;
         }

         case Ist_LLSC: {



            IRType dataTy;
            if (st->Ist.LLSC.storedata == ((void*)0)) {

               dataTy = typeOfIRTemp(bbIn->tyenv, st->Ist.LLSC.result);
               if (!inLDSO) {
                  instrument_mem_access(
                     bbOut,
                     st->Ist.LLSC.addr,
                     sizeofIRType(dataTy),
                     ((Bool)0) ,
                     sizeofIRType(hWordTy)
                  );
               }
            } else {


            }
            break;
         }

         case Ist_Store:


            if (!inLDSO) {
               instrument_mem_access(
                  bbOut,
                  st->Ist.Store.addr,
                  sizeofIRType(typeOfIRExpr(bbIn->tyenv, st->Ist.Store.data)),
                  ((Bool)1) ,
                  sizeofIRType(hWordTy)
               );
            }
            break;

         case Ist_WrTmp: {


            IRExpr* data = st->Ist.WrTmp.data;
            if (data->tag == Iex_Load) {
               if (!inLDSO) {
                  instrument_mem_access(
                     bbOut,
                     data->Iex.Load.addr,
                     sizeofIRType(data->Iex.Load.ty),
                     ((Bool)0) ,
                     sizeofIRType(hWordTy)
                  );
               }
            }
            break;
         }

         case Ist_Dirty: {
            Int dataSize;
            IRDirty* d = st->Ist.Dirty.details;
            if (d->mFx != Ifx_None) {


               ((void) ((d->mAddr != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"d->mAddr != NULL", (const Char*)"hg_main.c", 4146, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
               ((void) ((d->mSize != 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"d->mSize != 0", (const Char*)"hg_main.c", 4147, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
               dataSize = d->mSize;
               if (d->mFx == Ifx_Read || d->mFx == Ifx_Modify) {
                  if (!inLDSO) {
                     instrument_mem_access(
                        bbOut, d->mAddr, dataSize, ((Bool)0) ,
                        sizeofIRType(hWordTy)
                     );
                  }
               }
               if (d->mFx == Ifx_Write || d->mFx == Ifx_Modify) {
                  if (!inLDSO) {
                     instrument_mem_access(
                        bbOut, d->mAddr, dataSize, ((Bool)1) ,
                        sizeofIRType(hWordTy)
                     );
                  }
               }
            } else {
               ((void) ((d->mAddr == ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"d->mAddr == NULL", (const Char*)"hg_main.c", 4166, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
               ((void) ((d->mSize == 0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"d->mSize == 0", (const Char*)"hg_main.c", 4167, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
            }
            break;
         }

         default:
         unhandled:
            ppIRStmt(st);
            ((void) ((0) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"0", (const Char*)"hg_main.c", 4175, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));

      }

      addStmtToIRSB( bbOut, st );
   }

   return bbOut;
}







static WordFM* map_pthread_t_to_Thread = ((void*)0);

static void map_pthread_t_to_Thread_INIT ( void ) {
   if (__builtin_expect((map_pthread_t_to_Thread == ((void*)0)), 0)) {
      map_pthread_t_to_Thread = vgPlain_newFM( vgHelgrind_zalloc, "hg.mpttT.1",
                                            vgHelgrind_free, ((void*)0) );
      ((void) ((map_pthread_t_to_Thread != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"map_pthread_t_to_Thread != NULL", (const Char*)"hg_main.c", 4197, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   }
}


static
Bool hg_handle_client_request ( ThreadId tid, UWord* args, UWord* ret)
{
   if (!(((unsigned int)((('H')&0xff) << 24 | (('G')&0xff) << 16)) == ((args[0]) & 0xffff0000)))
      return ((Bool)0);





   *ret = 0;

   switch (args[0]) {



      case VG_USERREQ__HG_CLEAN_MEMORY:
         if (0) vgPlain_printf("VG_USERREQ__HG_CLEAN_MEMORY(%#lx,%ld)\n",
                            args[1], args[2]);




         if (args[2] > 0) {
            evh__die_mem(args[1], args[2]);

            evh__new_mem(args[1], args[2]);
         }
         break;

      case _VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK: {
         Addr payload = 0;
         SizeT pszB = 0;
         if (0) vgPlain_printf("VG_USERREQ__HG_CLEAN_MEMORY_HEAPBLOCK(%#lx)\n",
                            args[1]);
         if (vgHelgrind_mm_find_containing_block(((void*)0), &payload, &pszB, args[1])) {
            if (pszB > 0) {
               evh__die_mem(payload, pszB);
               evh__new_mem(payload, pszB);
            }
            *ret = pszB;
         } else {
            *ret = (UWord)-1;
         }
         break;
      }

      case _VG_USERREQ__HG_ARANGE_MAKE_UNTRACKED:
         if (0) vgPlain_printf("HG_ARANGE_MAKE_UNTRACKED(%#lx,%ld)\n",
                            args[1], args[2]);
         if (args[2] > 0) {
            evh__untrack_mem(args[1], args[2]);
         }
         break;

      case _VG_USERREQ__HG_ARANGE_MAKE_TRACKED:
         if (0) vgPlain_printf("HG_ARANGE_MAKE_TRACKED(%#lx,%ld)\n",
                            args[1], args[2]);
         if (args[2] > 0) {
            evh__new_mem(args[1], args[2]);
         }
         break;







      case _VG_USERREQ__HG_SET_MY_PTHREAD_T: {
         Thread* my_thr = ((void*)0);
         if (0)
         vgPlain_printf("SET_MY_PTHREAD_T (tid %d): pthread_t = %p\n", (Int)tid,
                     (void*)args[1]);
         map_pthread_t_to_Thread_INIT();
         my_thr = map_threads_maybe_lookup( tid );







         ((void) ((my_thr != ((void*)0)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"my_thr != NULL", (const Char*)"hg_main.c", 4285, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));


         if (0)
         vgPlain_printf("XXXX: bind pthread_t %p to Thread* %p\n",
                     (void*)args[1], (void*)my_thr );
         vgPlain_addToFM( map_pthread_t_to_Thread, (Word)args[1], (Word)my_thr );
         break;
      }

      case _VG_USERREQ__HG_PTH_API_ERROR: {
         Thread* my_thr = ((void*)0);
         map_pthread_t_to_Thread_INIT();
         my_thr = map_threads_maybe_lookup( tid );
         ((void) ((my_thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"my_thr", (const Char*)"hg_main.c", 4299, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         vgHelgrind_record_error_PthAPIerror(
            my_thr, (HChar*)args[1], (Word)args[2], (HChar*)args[3] );
         break;
      }



      case _VG_USERREQ__HG_PTHREAD_JOIN_POST: {
         Thread* thr_q = ((void*)0);
         Bool found = ((Bool)0);
         if (0)
         vgPlain_printf("NOTIFY_JOIN_COMPLETE (tid %d): quitter = %p\n", (Int)tid,
                     (void*)args[1]);
         map_pthread_t_to_Thread_INIT();
         found = vgPlain_lookupFM( map_pthread_t_to_Thread,
                                ((void*)0), (Word*)&thr_q, (Word)args[1] );






         ((void) ((found) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"found", (const Char*)"hg_main.c", 4322, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         if (found) {
            if (0)
            vgPlain_printf(".................... quitter Thread* = %p\n",
                        thr_q);
            evh__HG_PTHREAD_JOIN_POST( tid, thr_q );
         }
         break;
      }






      case _VG_USERREQ__HG_PTHREAD_MUTEX_INIT_POST:
         evh__HG_PTHREAD_MUTEX_INIT_POST( tid, (void*)args[1], args[2] );
         break;

      case _VG_USERREQ__HG_PTHREAD_MUTEX_DESTROY_PRE:
         evh__HG_PTHREAD_MUTEX_DESTROY_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE:
         evh__HG_PTHREAD_MUTEX_UNLOCK_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_POST:
         evh__HG_PTHREAD_MUTEX_UNLOCK_POST( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_PRE:
         evh__HG_PTHREAD_MUTEX_LOCK_PRE( tid, (void*)args[1], args[2] );
         break;

      case _VG_USERREQ__HG_PTHREAD_MUTEX_LOCK_POST:
         evh__HG_PTHREAD_MUTEX_LOCK_POST( tid, (void*)args[1] );
         break;



      case _VG_USERREQ__HG_PTHREAD_COND_SIGNAL_PRE:
      case _VG_USERREQ__HG_PTHREAD_COND_BROADCAST_PRE:
         evh__HG_PTHREAD_COND_SIGNAL_PRE( tid, (void*)args[1] );
         break;




      case _VG_USERREQ__HG_PTHREAD_COND_WAIT_PRE: {
         Bool mutex_is_valid
            = evh__HG_PTHREAD_COND_WAIT_PRE( tid, (void*)args[1],
                                                  (void*)args[2] );
         *ret = mutex_is_valid ? 1 : 0;
         break;
      }


      case _VG_USERREQ__HG_PTHREAD_COND_DESTROY_PRE:
         evh__HG_PTHREAD_COND_DESTROY_PRE( tid, (void*)args[1] );
         break;



      case _VG_USERREQ__HG_PTHREAD_COND_WAIT_POST:
         evh__HG_PTHREAD_COND_WAIT_POST( tid,
                                         (void*)args[1], (void*)args[2] );
         break;

      case _VG_USERREQ__HG_PTHREAD_RWLOCK_INIT_POST:
         evh__HG_PTHREAD_RWLOCK_INIT_POST( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_RWLOCK_DESTROY_PRE:
         evh__HG_PTHREAD_RWLOCK_DESTROY_PRE( tid, (void*)args[1] );
         break;


      case _VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_PRE:
         evh__HG_PTHREAD_RWLOCK_LOCK_PRE( tid, (void*)args[1],
                                               args[2], args[3] );
         break;


      case _VG_USERREQ__HG_PTHREAD_RWLOCK_LOCK_POST:
         evh__HG_PTHREAD_RWLOCK_LOCK_POST( tid, (void*)args[1], args[2] );
         break;

      case _VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_PRE:
         evh__HG_PTHREAD_RWLOCK_UNLOCK_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_RWLOCK_UNLOCK_POST:
         evh__HG_PTHREAD_RWLOCK_UNLOCK_POST( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_POSIX_SEM_INIT_POST:
         evh__HG_POSIX_SEM_INIT_POST( tid, (void*)args[1], args[2] );
         break;

      case _VG_USERREQ__HG_POSIX_SEM_DESTROY_PRE:
         evh__HG_POSIX_SEM_DESTROY_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_POSIX_SEM_POST_PRE:
         evh__HG_POSIX_SEM_POST_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_POSIX_SEM_WAIT_POST:
         evh__HG_POSIX_SEM_WAIT_POST( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_BARRIER_INIT_PRE:

         evh__HG_PTHREAD_BARRIER_INIT_PRE( tid, (void*)args[1],
                                                args[2], args[3] );
         break;

      case _VG_USERREQ__HG_PTHREAD_BARRIER_RESIZE_PRE:

         evh__HG_PTHREAD_BARRIER_RESIZE_PRE ( tid, (void*)args[1],
                                              args[2] );
         break;

      case _VG_USERREQ__HG_PTHREAD_BARRIER_WAIT_PRE:

         evh__HG_PTHREAD_BARRIER_WAIT_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_BARRIER_DESTROY_PRE:

         evh__HG_PTHREAD_BARRIER_DESTROY_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE:

         evh__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST:

         evh__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_SPIN_LOCK_PRE:

         evh__HG_PTHREAD_SPIN_LOCK_PRE( tid, (void*)args[1], args[2] );
         break;

      case _VG_USERREQ__HG_PTHREAD_SPIN_LOCK_POST:

         evh__HG_PTHREAD_SPIN_LOCK_POST( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_PTHREAD_SPIN_DESTROY_PRE:

         evh__HG_PTHREAD_SPIN_DESTROY_PRE( tid, (void*)args[1] );
         break;

      case _VG_USERREQ__HG_CLIENTREQ_UNIMP: {

         HChar* who = (HChar*)args[1];
         HChar buf[50 + 50];
         Thread* thr = map_threads_maybe_lookup( tid );
         ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 4486, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((who) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"who", (const Char*)"hg_main.c", 4487, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         ((void) ((vgPlain_strlen(who) <= 50) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"VG_(strlen)(who) <= 50", (const Char*)"hg_main.c", 4488, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
         vgPlain_sprintf(buf, "Unimplemented client request macro \"%s\"", who );

         vgHelgrind_record_error_Misc( thr, buf );
         break;
      }

      case _VG_USERREQ__HG_USERSO_SEND_PRE:

         evh__HG_USERSO_SEND_PRE( tid, args[1] );
         break;

      case _VG_USERREQ__HG_USERSO_RECV_POST:

         evh__HG_USERSO_RECV_POST( tid, args[1] );
         break;

      default:

         ((void) ((0) ? 0 : (
 vgPlain_assert_fail
# 4507 "hg_main.c"
         ( ((Bool)0), (const Char*)"0", (const Char*)
 "hg_main.c"
# 4507 "hg_main.c"
         ,
 4508
# 4507 "hg_main.c"
         , (const Char*)__PRETTY_FUNCTION__, "unhandled Helgrind client request 0x%lx", args[0]), 0)))
                               ;
   }

   return ((Bool)1);
}






static Bool hg_process_cmd_line_option ( Char* arg )
{
   Char* tmp_str;

   if (( (arg != ((void*)0) && "--track-lockorders""=" != ((void*)0) &&
 vgPlain_strncmp
# 4523 "hg_main.c"
           ((arg),("--track-lockorders""="),(vgPlain_strlen("--track-lockorders")+1))==0) ? ((Bool)1) : ((Bool)0) ) && ({ Char* val = &(arg)[
 vgPlain_strlen
# 4523 "hg_main.c"
           ("--track-lockorders")+1 ]; if ( (val != ((void*)0) && "yes" != ((void*)0) &&
 vgPlain_strcmp
# 4523 "hg_main.c"
           ((val),("yes"))==0) ? ((Bool)1) : ((Bool)0) ) (vgHelgrind_clo_track_lockorders) = ((Bool)1); else if ( (val != ((void*)0) && "no" != ((void*)0) &&
 vgPlain_strcmp
# 4523 "hg_main.c"
           ((val),("no"))==0) ? ((Bool)1) : ((Bool)0) ) (vgHelgrind_clo_track_lockorders) = ((Bool)0); ((Bool)1); }) )
                                                       {}
   else if (( (arg != ((void*)0) && "--cmp-race-err-addrs""=" != ((void*)0) &&
 vgPlain_strncmp
# 4525 "hg_main.c"
           ((arg),("--cmp-race-err-addrs""="),(vgPlain_strlen("--cmp-race-err-addrs")+1))==0) ? ((Bool)1) : ((Bool)0) ) && ({ Char* val = &(arg)[
 vgPlain_strlen
# 4525 "hg_main.c"
           ("--cmp-race-err-addrs")+1 ]; if ( (val != ((void*)0) && "yes" != ((void*)0) &&
 vgPlain_strcmp
# 4525 "hg_main.c"
           ((val),("yes"))==0) ? ((Bool)1) : ((Bool)0) ) (vgHelgrind_clo_cmp_race_err_addrs) = ((Bool)1); else if ( (val != ((void*)0) && "no" != ((void*)0) &&
 vgPlain_strcmp
# 4525 "hg_main.c"
           ((val),("no"))==0) ? ((Bool)1) : ((Bool)0) ) (vgHelgrind_clo_cmp_race_err_addrs) = ((Bool)0); ((Bool)1); }) )
                                                         {}

   else if (( ((arg) != ((void*)0) && ("--history-level=none") != ((void*)0) &&
 vgPlain_strcmp
# 4528 "hg_main.c"
           (((arg)),(("--history-level=none")))==0) ? ((Bool)1) : ((Bool)0) ) && ({ (vgHelgrind_clo_history_level) = (0); ((Bool)1); }) )
                                                      ;
   else if (( ((arg) != ((void*)0) && ("--history-level=approx") != ((void*)0) &&
 vgPlain_strcmp
# 4530 "hg_main.c"
           (((arg)),(("--history-level=approx")))==0) ? ((Bool)1) : ((Bool)0) ) && ({ (vgHelgrind_clo_history_level) = (1); ((Bool)1); }) )
                                                      ;
   else if (( ((arg) != ((void*)0) && ("--history-level=full") != ((void*)0) &&
 vgPlain_strcmp
# 4532 "hg_main.c"
           (((arg)),(("--history-level=full")))==0) ? ((Bool)1) : ((Bool)0) ) && ({ (vgHelgrind_clo_history_level) = (2); ((Bool)1); }) )
                                                      ;



   else if (( ((arg) != ((void*)0) && "--conflict-cache-size""=" != ((void*)0) &&
 vgPlain_strncmp
# 4537 "hg_main.c"
           (((arg)),("--conflict-cache-size""="),(vgPlain_strlen("--conflict-cache-size")+1))==0) ? ((Bool)1) : ((Bool)0) ) && ({ Char* val = &((arg))[
 vgPlain_strlen
# 4537 "hg_main.c"
           ("--conflict-cache-size")+1 ]; Char* s; Long n =
 vgPlain_strtoll10
# 4537 "hg_main.c"
           ( val, &s ); ((vgHelgrind_clo_conflict_cache_size)) = n; if ('\0' != s[0] || ((vgHelgrind_clo_conflict_cache_size)) != n)
 vgPlain_fmsg_bad_option
# 4537 "hg_main.c"
           ((arg), ""); if (((vgHelgrind_clo_conflict_cache_size)) < ((10*1000)) || ((vgHelgrind_clo_conflict_cache_size)) > ((30*1000*1000))) {
 vgPlain_fmsg_bad_option
# 4537 "hg_main.c"
           ((arg), "'%s' argument must be between %lld and %lld\n", ("--conflict-cache-size"), (Long)((10*1000)), (Long)((30*1000*1000))); } ((Bool)1); }) )
                                                                            {}


   else if (( (arg != ((void*)0) && "--hg-sanity-flags""=" != ((void*)0) && vgPlain_strncmp((arg),("--hg-sanity-flags""="),(vgPlain_strlen("--hg-sanity-flags")+1))==0) ? ((Bool)1) : ((Bool)0) ) && ({ Char* val = &(arg)[ vgPlain_strlen("--hg-sanity-flags")+1 ]; (tmp_str) = val; ((Bool)1); }) ) {
      Int j;

      if (6 != vgPlain_strlen(tmp_str)) {
         vgPlain_message(Vg_UserMsg,
                      "--hg-sanity-flags argument must have 6 digits\n");
         return ((Bool)0);
      }
      for (j = 0; j < 6; j++) {
         if ('0' == tmp_str[j]) { }
         else if ('1' == tmp_str[j]) vgHelgrind_clo_sanity_flags |= (1 << (6-1-j));
         else {
            vgPlain_message(Vg_UserMsg, "--hg-sanity-flags argument can "
                                     "only contain 0s and 1s\n");
            return ((Bool)0);
         }
      }
      if (0) vgPlain_printf("XXX sanity flags: 0x%lx\n", vgHelgrind_clo_sanity_flags);
   }

   else
      return vgPlain_replacement_malloc_process_cmd_line_option(arg);

   return ((Bool)1);
}

static void hg_print_usage ( void )
{
   vgPlain_printf(
"    --track-lockorders=no|yes show lock ordering errors? [yes]\n"
"    --history-level=none|approx|full [full]\n"
"       full:   show both stack traces for a data race (can be very slow)\n"
"       approx: full trace for one thread, approx for the other (faster)\n"
"       none:   only show trace for one thread in a race (fastest)\n"
"    --conflict-cache-size=N   size of 'full' history cache [1000000]\n"
   );
}

static void hg_print_debug_usage ( void )
{
   vgPlain_printf("    --cmp-race-err-addrs=no|yes  are data addresses in "
               "race errors significant? [no]\n");
   vgPlain_printf("    --hg-sanity-flags=<XXXXXX>   sanity check "
               "  at events (X = 0|1) [000000]\n");
   vgPlain_printf("    --hg-sanity-flags values:\n");
   vgPlain_printf("       010000   after changes to "
               "lock-order-acquisition-graph\n");
   vgPlain_printf("       001000   at memory accesses (NB: not currently used)\n");
   vgPlain_printf("       000100   at mem permission setting for "
               "ranges >= %d bytes\n", 256);
   vgPlain_printf("       000010   at lock/unlock events\n");
   vgPlain_printf("       000001   at thread create/join events\n");
}

static void hg_fini ( Int exitcode )
{
   if (vgPlain_clo_verbosity == 1 && !vgPlain_clo_xml) {
      vgPlain_message(Vg_UserMsg,
                   "For counts of detected and suppressed errors, "
                   "rerun with: -v\n");
   }

   if (vgPlain_clo_verbosity == 1 && !vgPlain_clo_xml
       && vgHelgrind_clo_history_level >= 2) {
      vgPlain_umsg(
         "Use --history-level=approx or =none to gain increased speed, at\n" );
      vgPlain_umsg(
         "the cost of reduced accuracy of conflicting-access information\n");
   }

   if (0)
      pp_everything( ((1<<1) | (1<<2)), "SK_(fini)" );
   if (vgHelgrind_clo_sanity_flags)
      all__sanity_check("SK_(fini)");

   if (vgPlain_clo_stats) {

      if (1) {
         vgPlain_printf("\n");
         vgHelgrind_ppWSUstats( univ_lsets, "univ_lsets" );
         if (vgHelgrind_clo_track_lockorders) {
            vgPlain_printf("\n");
            vgHelgrind_ppWSUstats( univ_laog, "univ_laog" );
         }
      }
# 4639 "hg_main.c"
      vgPlain_printf("\n");
      vgPlain_printf("        locksets: %'8d unique lock sets\n",
                  (Int)vgHelgrind_cardinalityWSU( univ_lsets ));
      if (vgHelgrind_clo_track_lockorders) {
         vgPlain_printf("       univ_laog: %'8d unique lock sets\n",
                     (Int)vgHelgrind_cardinalityWSU( univ_laog ));
      }





      vgPlain_printf("  LockN-to-P map: %'8llu queries (%llu map size)\n",
                  vgHelgrind_stats__LockN_to_P_queries,
                  vgHelgrind_stats__LockN_to_P_get_map_size() );

      vgPlain_printf("string table map: %'8llu queries (%llu map size)\n",
                  vgHelgrind_stats__string_table_queries,
                  vgHelgrind_stats__string_table_get_map_size() );
      if (vgHelgrind_clo_track_lockorders) {
         vgPlain_printf("            LAOG: %'8d map size\n",
                     (Int)(laog ? vgPlain_sizeFM( laog ) : 0));
         vgPlain_printf(" LAOG exposition: %'8d map size\n",
                     (Int)(laog_exposition ? vgPlain_sizeFM( laog_exposition ) : 0));
      }

      vgPlain_printf("           locks: %'8lu acquires, "
                  "%'lu releases\n",
                  stats__lockN_acquires,
                  stats__lockN_releases
                 );
      vgPlain_printf("   sanity checks: %'8lu\n", stats__sanity_checks);

      vgPlain_printf("\n");
      libhb_shutdown(((Bool)1));
   }
}



static
void for_libhb__get_stacktrace ( Thr* hbt, Addr* frames, UWord nRequest )
{
   Thread* thr;
   ThreadId tid;
   UWord nActual;
   ((void) ((hbt) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbt", (const Char*)"hg_main.c", 4685, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = libhb_get_Thr_hgthread( hbt );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 4687, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   tid = map_threads_maybe_reverse_lookup_SLOW(thr);
   nActual = (UWord)vgPlain_get_StackTrace( tid, frames, (UInt)nRequest,
                                         ((void*)0), ((void*)0), 0 );
   ((void) ((nActual <= nRequest) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"nActual <= nRequest", (const Char*)"hg_main.c", 4691, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   for (; nActual < nRequest; nActual++)
      frames[nActual] = 0;
}

static
ExeContext* for_libhb__get_EC ( Thr* hbt )
{
   Thread* thr;
   ThreadId tid;
   ExeContext* ec;
   ((void) ((hbt) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"hbt", (const Char*)"hg_main.c", 4702, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   thr = libhb_get_Thr_hgthread( hbt );
   ((void) ((thr) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"thr", (const Char*)"hg_main.c", 4704, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   tid = map_threads_maybe_reverse_lookup_SLOW(thr);

   ec = vgPlain_record_ExeContext( tid, 0 );
   return ec;
}


static void hg_post_clo_init ( void )
{
   Thr* hbthr_root;


   hbthr_root = libhb_init( for_libhb__get_stacktrace,
                            for_libhb__get_EC );



   if (vgHelgrind_clo_track_lockorders)
      laog__init();

   initialise_data_structures(hbthr_root);
}

static void hg_pre_clo_init ( void )
{
   vgPlain_details_name ("Helgrind");
   vgPlain_details_version (((void*)0));
   vgPlain_details_description ("a thread error detector");
   vgPlain_details_copyright_author(
      "Copyright (C) 2007-2010, and GNU GPL'd, by OpenWorks LLP et al.");
   vgPlain_details_bug_reports_to ("www.valgrind.org");
   vgPlain_details_avg_translation_sizeB ( 320 );

   vgPlain_basic_tool_funcs (hg_post_clo_init,
                                   hg_instrument,
                                   hg_fini);

   vgPlain_needs_core_errors ();
   vgPlain_needs_tool_errors (vgHelgrind_eq_Error,
                                   vgHelgrind_before_pp_Error,
                                   vgHelgrind_pp_Error,
                                   ((Bool)0),
                                   vgHelgrind_update_extra,
                                   vgHelgrind_recognised_suppression,
                                   vgHelgrind_read_extra_suppression_info,
                                   vgHelgrind_error_matches_suppression,
                                   vgHelgrind_get_error_name,
                                   vgHelgrind_get_extra_suppression_info);

   vgPlain_needs_xml_output ();

   vgPlain_needs_command_line_options(hg_process_cmd_line_option,
                                   hg_print_usage,
                                   hg_print_debug_usage);
   vgPlain_needs_client_requests (hg_handle_client_request);





   vgPlain_needs_malloc_replacement (hg_cli__malloc,
                                   hg_cli____builtin_new,
                                   hg_cli____builtin_vec_new,
                                   hg_cli__memalign,
                                   hg_cli__calloc,
                                   hg_cli__free,
                                   hg_cli____builtin_delete,
                                   hg_cli____builtin_vec_delete,
                                   hg_cli__realloc,
                                   hg_cli_malloc_usable_size,
                                   16 );





   if (0) vgPlain_needs_var_info();

   vgPlain_track_new_mem_startup ( evh__new_mem_w_perms );
   vgPlain_track_new_mem_stack_signal( evh__new_mem_w_tid );
   vgPlain_track_new_mem_brk ( evh__new_mem_w_tid );
   vgPlain_track_new_mem_mmap ( evh__new_mem_w_perms );
   vgPlain_track_new_mem_stack ( evh__new_mem_stack );


   vgPlain_track_copy_mem_remap ( evh__copy_mem );

   vgPlain_track_change_mem_mprotect ( evh__set_perms );

   vgPlain_track_die_mem_stack_signal( evh__die_mem );
   vgPlain_track_die_mem_brk ( evh__die_mem );
   vgPlain_track_die_mem_munmap ( evh__die_mem );
   vgPlain_track_die_mem_stack ( evh__die_mem );


   vgPlain_track_ban_mem_stack (((void*)0));

   vgPlain_track_pre_mem_read ( evh__pre_mem_read );
   vgPlain_track_pre_mem_read_asciiz ( evh__pre_mem_read_asciiz );
   vgPlain_track_pre_mem_write ( evh__pre_mem_write );
   vgPlain_track_post_mem_write (((void*)0));



   vgPlain_track_pre_thread_ll_create( evh__pre_thread_ll_create );
   vgPlain_track_pre_thread_ll_exit ( evh__pre_thread_ll_exit );

   vgPlain_track_start_client_code( evh__start_client_code );
   vgPlain_track_stop_client_code( evh__stop_client_code );




   ((void) ((sizeof(void*) == sizeof(struct _MallocMeta*)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"sizeof(void*) == sizeof(struct _MallocMeta*)", (const Char*)"hg_main.c", 4818, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   ((void) ((sizeof(UWord) == sizeof(Addr)) ? 0 : (vgPlain_assert_fail ( ((Bool)0), (const Char*)"sizeof(UWord) == sizeof(Addr)", (const Char*)"hg_main.c", 4819, (const Char*)__PRETTY_FUNCTION__, (const HChar*)""), 0)));
   hg_mallocmeta_table
      = vgPlain_HT_construct( "hg_malloc_metadata_table" );


   vgPlain_atfork(((void*)0) , ((void*)0) , evh__atfork_child );
}

void (*vgPlain_tl_pre_clo_init) ( void ) = hg_pre_clo_init;
