text:
__author__ = 'Lothilius'
# coding: utf-8
from sqlalchemy import BigInteger, Column, Date, DateTime, Enum, Float, Index, Integer, Numeric, SmallInteger, String, Text, VARBINARY, text
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime, timedelta

Base = declarative_base()
metadata = Base.metadata

current_time = datetime.now()

class HitTypeSetting(Base):
    __tablename__ = u'HitTypeSettings'

    id = Column(Integer, primary_key=True)
    Title = Column(String(255), nullable=False)
    Description = Column(Text, nullable=False)
    Keywords = Column(String(255))
    Price = Column(Numeric(4, 3), nullable=False)
    Bonus_Price = Column(Numeric(4, 3), nullable=False)
    Question = Column(Text, nullable=False)
    AwsId = Column(String(255), nullable=False)
    AwsKey = Column(String(255), nullable=False)
    Sandbox = Column(Integer, nullable=False)
    HitTypeId = Column(String(255), nullable=False)
    debug = Column(Integer, nullable=False)
    formUrl = Column(String(255), nullable=False)
    AssignmentDuration = Column(Integer, nullable=False)
    RepostDays = Column(Integer, nullable=False)
    notification_url = Column(String(255), nullable=False)

class Hit(Base):
    __tablename__ = u'Hits'

    mtid = Column(Integer, primary_key=True)
    hitid = Column(String(200), nullable=False)
    mtvenueid = Column(Integer, nullable=False)
    date_published = Column(DateTime)
    last_published = Column(DateTime)
    next_publishdate = Column(DateTime)
    mt_status = Column(Enum(u'0', u'1', u'2'), nullable=False, server_default=text("'0'"))

class AdminLog(Base):
    __tablename__ = u'admin_log'

    id = Column(Integer, primary_key=True)
    admin_id = Column(Integer, nullable=False)
    role_name = Column(String(255, u'utf8_unicode_ci'), nullable=False)
    requested_resource = Column(String(255, u'utf8_unicode_ci'), nullable=False)
    permission_granted = Column(String(255, u'utf8_unicode_ci'), nullable=False)
    ip_address = Column(String(255, u'utf8_unicode_ci'), nullable=False)
    request_date = Column(DateTime, nullable=False)

class AdminResource(Base):
    __tablename__ = u'admin_resource'

    resource_id = Column(Integer, primary_key=True)
    resource_name = Column(String(255), nullable=False)

class AdminRole(Base):
    __tablename__ = u'admin_role'

    id = Column(Integer, primary_key=True)
    role_name = Column(String(128), nullable=False)

class AdminRule(Base):
    __tablename__ = u'admin_rule'

    rule_id = Column(Integer, primary_key=True)
    role_id = Column(Integer, nullable=False)
    resource_id = Column(Integer, nullable=False)
    access_permission = Column(String(255), nullable=False)

class AdminSetting(Base):
    __tablename__ = u'admin_settings'

    id = Column(Integer, primary_key=True)
    single_column_list_no = Column(Integer, nullable=False)
    total_events_at_eventslist = Column(Integer, nullable=False, server_default=text("'50'"))
    display_at_todayspic = Column(Enum(u'e', u'a'), nullable=False, server_default=text("'e'"))
    datp_event_id = Column(Integer, server_default=text("'0'"))
    max_shared_advt = Column(Integer, nullable=False, server_default=text("'15'"))
    dasv_venue_id = Column(String(255))
    placement_position_1 = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    placement_position_2 = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    placement_position_3 = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    placement_position_4 = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    placement_position_5 = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    placement_position_1_advt_details_id = Column(Integer, nullable=False, server_default=text("'0'"))
    placement_position_2_advt_details_id = Column(Integer, nullable=False, server_default=text("'0'"))
    placement_position_3_advt_details_id = Column(Integer, nullable=False, server_default=text("'0'"))
    placement_position_4_advt_details_id = Column(Integer, nullable=False, server_default=text("'0'"))
    placement_position_5_advt_details_id = Column(Integer, nullable=False, server_default=text("'0'"))
    tweet_userid = Column(String(255), nullable=False)
    tweet_count = Column(Integer, nullable=False, server_default=text("'5'"))
    facebook_page_username = Column(String(255), nullable=False)
    fb_category = Column(Integer)
    fb_subcategory = Column(Integer)
    total_pending_events_for_admin_mail_trigger = Column(Integer, nullable=False, server_default=text("'15'"))
    admin_fb_uid = Column(String(255))
    admin_fb_access_token = Column(Text)
    admin_fb_email = Column(String(255))
    admin_fb_first_name = Column(String(255))
    admin_fb_last_name = Column(String(255))

class AdminUser(Base):
    __tablename__ = u'admin_user'

    id = Column(Integer, primary_key=True)
    role_id = Column(Integer, nullable=False)
    username = Column(String(40), nullable=False)
    password = Column(String(32), nullable=False)
    created = Column(DateTime, nullable=False)
    lastlogin = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    pending_list_subscribe = Column(Enum(u'0', u'1'), nullable=False, server_default=text("'0'"))
    status = Column(Enum(u'0', u'1'), nullable=False, server_default=text("'1'"))

class AdvtCurrent(Base):
    __tablename__ = u'advt_current'

    id = Column(Integer, primary_key=True)
    space_type = Column(String(1), nullable=False)
    advt_details_id = Column(Integer, nullable=False)
    placement_position_id = Column(Integer, nullable=False)

class AdvtDetail(Base):
    __tablename__ = u'advt_details'

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, nullable=False)
    refund_at_this_email = Column(String(255))
    desc = Column(Text, nullable=False)
    purpose = Column(Text, nullable=False)
    space_type = Column(String(1), nullable=False)
    placement_position_id = Column(Integer, nullable=False)
    advt_type = Column(String(1), nullable=False)
    total_duration = Column(Float, nullable=False)
    total_impression = Column(BigInteger, nullable=False)
    total_cost = Column(Float, nullable=False)
    url_link = Column(String(255), nullable=False)
    advt_file = Column(Text)
    upload_later = Column(Integer)
    want_a_design = Column(Integer, nullable=False)
    date_added = Column(DateTime, nullable=False)
    url_encrypt = Column(Text)
    paid = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    advt_details_status = Column(Enum(u'0', u'1', u'2'), nullable=False, server_default=text("'0'"))
    is_expired = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    godrt = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))

class AdvtPrice(Base):
    __tablename__ = u'advt_prices'

    id = Column(Integer, primary_key=True)
    placement_position_id = Column(Integer, nullable=False)
    premium_price = Column(Float, nullable=False)
    monthly_price = Column(Float, nullable=False)
    weekly_price = Column(Float, nullable=False)
    daily_price = Column(Float, nullable=False)
    per_impression_price = Column(Float, nullable=False)
    max_advts = Column(Integer, nullable=False, server_default=text("'50'"))

class AdvtRestricted(Base):
    __tablename__ = u'advt_restricted'

    id = Column(Integer, primary_key=True)
    advt_details_id = Column(Integer, nullable=False)
    useridd = Column(Integer, nullable=False)
    placement_position_id = Column(Integer, nullable=False)
    url_link = Column(String(255), nullable=False)
    advt_file = Column(Text, nullable=False)
    total_duration = Column(Float, nullable=False)
    total_impression = Column(BigInteger, nullable=False)
    remaining_duration = Column(Float, nullable=False)
    remaining_impression = Column(BigInteger, nullable=False)
    date_added = Column(DateTime, nullable=False)
    date_activated = Column(DateTime)
    status = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    is_expired = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))

class AdvtShared(Base):
    __tablename__ = u'advt_shared'

    id = Column(Integer, primary_key=True)
    advt_details_id = Column(Integer, nullable=False)
    useridd = Column(Integer, nullable=False)
    placement_position_id = Column(Integer, nullable=False)
    url_link = Column(String(255), nullable=False)
    advt_file = Column(Text)
    total_duration = Column(Float, nullable=False)
    total_impression = Column(BigInteger, nullable=False)
    remaining_duration = Column(Float, nullable=False)
    remaining_impression = Column(BigInteger, nullable=False)
    date_added = Column(DateTime, nullable=False)
    date_activated = Column(DateTime)
    status = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    is_expired = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))

class Category(Base):
    __tablename__ = u'category'

    id = Column(Integer, primary_key=True)
    category_name = Column(String(40), nullable=False)
    icon = Column(String(100, u'utf8_unicode_ci'), nullable=False, server_default=text("'oi915_iphone.png'"))
    category_desc = Column(String(128), nullable=False)
    meta_keywords = Column(String(128))
    meta_title = Column(String(40))
    meta_desc = Column(String(128))
    category_pagetitle = Column(String(128), nullable=False)
    category_order = Column(Integer, nullable=False)
    category_status = Column(Enum(u'0', u'1'), nullable=False, server_default=text("'1'"))
    color = Column(String(100), nullable=False, server_default=text("'blue'"))

class Comment(Base):
    __tablename__ = u'comment'

    id = Column(Integer, primary_key=True)
    event_id = Column(Integer, nullable=False)
    user_id = Column(Integer, nullable=False)
    comment = Column(Text, nullable=False)
    comment_start = Column(DateTime, nullable=False)

class Corepage(Base):
    __tablename__ = u'corepages'

    id = Column(Integer, primary_key=True)
    about = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    contact = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    faq = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    promos = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    freebies = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    giveaways = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    hosted = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    emails = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    friendemail = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    register = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    want_a_design = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)
    privacy_policy = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)

class Event(Base):
    __tablename__ = u'event'

    id = Column(Integer, primary_key=True)
    fb_eventid = Column(String(255))
    group_id = Column(String(20))
    category_id = Column(VARBINARY(255), nullable=False)
    subcat_id = Column(String(255), nullable=False)
    user_id = Column(Integer)
    event_name = Column(String(255), nullable=False)
    event_desc = Column(Text, nullable=False)
    is_venue_name_filled = Column(Enum(u'0', u'1'), nullable=False, server_default=text("'1'"))
    venue_id = Column(Integer, nullable=False)
    event_start = Column(DateTime, nullable=False)
    event_end = Column(DateTime, nullable=False)
    event_repeat = Column(String(255), nullable=False, server_default=text("'o'"))
    event_repeat_end = Column(DateTime)
    event_source = Column(String(255))
    event_source_title = Column(String(255))
    address = Column(String(255))
    city = Column(String(255))
    state = Column(String(255))
    zipcode = Column(String(255))
    image = Column(String(255), nullable=False, server_default=text("'oi915_fillerpic.png'"))
    status = Column(Enum(u'1', u'0', u'2'), nullable=False, server_default=text("'2'"))
    how = Column(Text)
    sftp = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    asedrt = Column(String(255))
    event_added = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
    who = Column(Text, nullable=False)
    week = Column(Integer, nullable=False)
    type = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    hit_id = Column(String(255))
    assignment_id = Column(String(255))
    worker_id = Column(String(200))
    pstart = Column(DateTime)
    pend = Column(DateTime)
    wall_post_title = Column(Text)
    event_post_to_facebook = Column(Integer, nullable=False, server_default=text("'0'"))
    block_post = Column(Integer, nullable=False, server_default=text("'0'"))

    def __init__(self, event, category_id='1', subcat_id='8', user_id='6', is_venue_name_filled='1',
                 event_end='', event_repeat='o', sftp='0',
                 event_added=current_time.strftime('%Y-%m-%d %H:%M:%S'), who='', week='0', type_col='0',
                 event_post_to_facebook='0', block_post='0'):

        if event_end == '':
            event_end = datetime.strptime(event[5], '%Y-%m-%d %H:%M:%S')
            event_end += timedelta(hours=3)

        self.fb_eventid = event[0]
        self.event_name = event[1]
        self.event_desc = event[2]
        self.venue_id = event[3]
        self.event_start = event[5]
        self.event_source = event[6]
        self.event_source_title = event[7]
        self.image = event[8]
        self.how = event[9]
        self.status = event[10]
        self.category_id = category_id
        self.subcat_id = subcat_id
        self.user_id = user_id
        self.is_venue_name_filled = is_venue_name_filled
        self.event_end = event_end
        self.event_repeat = event_repeat
        self.sftp = sftp
        self.event_added = event_added
        self.who = who
        self.week = week
        self.type = type_col
        self.event_post_to_facebook = event_post_to_facebook
        self.block_post = block_post

class EventBackup05082012(Base):
    __tablename__ = u'event_backup_05_08_2012'

    id = Column(Integer, primary_key=True)
    fb_eventid = Column(String(255))
    group_id = Column(String(20))
    category_id = Column(VARBINARY(255), nullable=False)
    subcat_id = Column(String(255), nullable=False)
    user_id = Column(Integer)
    event_name = Column(String(255), nullable=False)
    event_desc = Column(Text, nullable=False)
    is_venue_name_filled = Column(Enum(u'0', u'1'), nullable=False, server_default=text("'1'"))
    venue_id = Column(Integer, nullable=False)
    event_start = Column(DateTime, nullable=False)
    event_end = Column(DateTime, nullable=False)
    event_repeat = Column(String(255), nullable=False, server_default=text("'o'"))
    event_repeat_end = Column(DateTime)
    event_source = Column(String(255))
    event_source_title = Column(String(255))
    address = Column(String(255))
    city = Column(String(255))
    state = Column(String(255))
    zipcode = Column(String(255))
    image = Column(String(255), nullable=False, server_default=text("'oi915_fillerpic.png'"))
    status = Column(Enum(u'1', u'0', u'2'), nullable=False, server_default=text("'2'"))
    how = Column(Text)
    sftp = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    asedrt = Column(String(255))
    event_added = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
    who = Column(Text, nullable=False)
    week = Column(Integer, nullable=False)
    type = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    hit_id = Column(String(255))
    assignment_id = Column(String(255))
    worker_id = Column(String(200))

class Eventcounter(Base):
    __tablename__ = u'eventcounter'

    id = Column(Integer, primary_key=True)
    counter = Column(Integer, nullable=False, server_default=text("'0'"))
    mailevent = Column(String(255), nullable=False)

class FbEventTempStorage(Base):
    __tablename__ = u'fb_event_temp_storage'

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, nullable=False)
    event_data = Column(Text(collation=u'utf8_unicode_ci'), nullable=False)

class FbEventToken(Base):
    __tablename__ = u'fb_event_token'

    pkid = Column(Integer, primary_key=True)
    token_id = Column(Text, nullable=False)
    stag = Column(String)

class FbWallPost(Base):
    __tablename__ = u'fb_wall_posts'

    fb_wall_post_id = Column(Integer, primary_key=True)
    fb_message = Column(Text)
    fb_title = Column(Text)
    fb_posting_time = Column(DateTime)
    fb_creation_time = Column(DateTime)

class FrontUser(Base):
    __tablename__ = u'front_user'

    id = Column(Integer, primary_key=True)
    fb_uid = Column(String(255))
    fb_access_token = Column(Text)
    email = Column(String(100), nullable=False)
    password = Column(String(32), nullable=False)
    created = Column(DateTime, nullable=False)
    lastlogin = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    firstname = Column(String(100), nullable=False)
    lastname = Column(String(100), nullable=False)
    address = Column(Text, nullable=False)
    city = Column(String(50), nullable=False, server_default=text("'.....'"))
    country = Column(String(50), nullable=False, server_default=text("'.....'"))
    dob = Column(Date, nullable=False)
    image = Column(String(255), nullable=False, server_default=text("'oi915_fillerpic.png'"))
    edit_rights = Column(String(255))
    verified = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    varify_url = Column(String(255))
    amount = Column(Float, nullable=False, server_default=text("'0'"))
    fb_eventid_uploaded = Column(Text)

class GoogleAdsense(Base):
    __tablename__ = u'google_adsense'

    id = Column(Integer, primary_key=True)
    placement_position_id = Column(Integer)
    google_adsense_code = Column(Text)

class LastCheckedEvent(Base):
    __tablename__ = u'last_checked_event'

    id = Column(Integer, primary_key=True)
    event_id = Column(Integer, nullable=False, server_default=text("'0'"))
    to_delete_event_ids = Column(String(255), nullable=False)

class Like(Base):
    __tablename__ = u'like'

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, nullable=False)
    event_id = Column(Integer, nullable=False)
    like_start = Column(DateTime, nullable=False)
    like_count = Column(Integer, nullable=False)

    def __init__(self, user_id, event_id, like_start, like_count=0):

        self.user_id = user_id
        self.event_id = event_id
        self.like_start = like_start
        self.like_count = like_count

class Likecount(Base):
    __tablename__ = u'likecount'

    id = Column(Integer, primary_key=True)
    event_id = Column(Integer, nullable=False)
    like_count = Column(Integer, nullable=False)

    def __init__(self, event_id, like_count=1):

        self.event_id = event_id
        self.like_count = like_count

class Location(Base):
    __tablename__ = u'location'

    id = Column(Integer, primary_key=True)
    location_name = Column(String(255), nullable=False)
    location_status = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'1'"))

class MtLog(Base):
    __tablename__ = u'mt_log'

    id = Column(Integer, primary_key=True)
    lvl = Column(Integer, nullable=False)
    msg = Column(Text, nullable=False)
    timestamp = Column(DateTime, nullable=False, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))

class PaymentPaypalOrder(Base):
    __tablename__ = u'payment_paypal_order'

    id = Column(Integer, primary_key=True)
    advt_details_id = Column(Integer, nullable=False)
    trans_id = Column(String(128))
    card_type = Column(String(32))
    card_number = Column(String(64))
    card_expires = Column(String(16))
    token = Column(String(255))
    correlationid = Column(String(255))

class Resetpas(Base):
    __tablename__ = u'resetpass'

    id = Column(Integer, primary_key=True)
    uid = Column(Integer)
    link = Column(String(255, u'utf8_unicode_ci'))
    status = Column(Enum(u'1', u'0'), server_default=text("'1'"))

class Shbptc(Base):
    __tablename__ = u'shbptc'

    id = Column(Integer, primary_key=True)
    shbptc_image = Column(String(255), nullable=False)
    shbptc_desc = Column(Text, nullable=False)
    artist_name = Column(Text, nullable=False)
    artist_page = Column(Text)

class ShbptcVote(Base):
    __tablename__ = u'shbptc_votes'

    id = Column(Integer, primary_key=True)
    uid = Column(Integer, nullable=False)
    image_id = Column(Integer, nullable=False)
    date = Column(DateTime, nullable=False)
    source = Column(Text)

class Subcategory(Base):
    __tablename__ = u'subcategory'

    id = Column(Integer, primary_key=True)
    parent_catid = Column(Integer, nullable=False)
    subcategory_name = Column(String(255), nullable=False)
    subcategory_status = Column(Integer, nullable=False, server_default=text("'1'"))

class Venue(Base):
    __tablename__ = u'venue'

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer)
    name = Column(String(128), nullable=False)
    location_id = Column(Integer, nullable=False, server_default=text("'0'"))
    addline1 = Column(String(255), nullable=False)
    addline2 = Column(String(255))
    city = Column(String(255), nullable=False)
    state = Column(String(255), nullable=False)
    country = Column(String(255), nullable=False)
    zip = Column(Integer, nullable=False)
    website = Column(String(255), nullable=False)
    image = Column(String(255), server_default=text("'oi915_fillerpic.png'"))
    phone = Column(BigInteger, nullable=False)
    lat = Column(Float(10), nullable=False, server_default=text("'0.000000'"))
    lng = Column(Float(10), nullable=False, server_default=text("'0.000000'"))
    timezone = Column(String(10), nullable=False, server_default=text("'+00'"))
    sizzvenue = Column(Enum(u'1', u'0'), nullable=False, server_default=text("'0'"))
    status = Column(Enum(u'0', u'1'), nullable=False, server_default=text("'1'"))
    desc = Column(Text, nullable=False)
    fb_venueid = Column(Integer)

class WpCommentmeta(Base):
    __tablename__ = u'wp_commentmeta'

    meta_id = Column(BigInteger, primary_key=True)
    comment_id = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    meta_key = Column(String(255), index=True)
    meta_value = Column(String)

class WpComment(Base):
    __tablename__ = u'wp_comments'
    __table_args__ = (
        Index(u'comment_approved_date_gmt', u'comment_approved', u'comment_date_gmt'),
    )

    comment_ID = Column(BigInteger, primary_key=True)
    comment_post_ID = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    comment_author = Column(String, nullable=False)
    comment_author_email = Column(String(100), nullable=False, server_default=text("''"))
    comment_author_url = Column(String(200), nullable=False, server_default=text("''"))
    comment_author_IP = Column(String(100), nullable=False, server_default=text("''"))
    comment_date = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    comment_date_gmt = Column(DateTime, nullable=False, index=True, server_default=text("'0000-00-00 00:00:00'"))
    comment_content = Column(Text, nullable=False)
    comment_karma = Column(Integer, nullable=False, server_default=text("'0'"))
    comment_approved = Column(String(20), nullable=False, server_default=text("'1'"))
    comment_agent = Column(String(255), nullable=False, server_default=text("''"))
    comment_type = Column(String(20), nullable=False, server_default=text("''"))
    comment_parent = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    user_id = Column(BigInteger, nullable=False, server_default=text("'0'"))

class WpEshopBaseProduct(Base):
    __tablename__ = u'wp_eshop_base_products'

    post_id = Column(BigInteger, primary_key=True, server_default=text("'0'"))
    img = Column(Text, nullable=False)
    brand = Column(String(255), nullable=False, server_default=text("''"))
    ptype = Column(String(255), nullable=False, server_default=text("''"))
    thecondition = Column(String(255), nullable=False, server_default=text("''"))
    expiry = Column(Date, nullable=False, server_default=text("'0000-00-00'"))
    ean = Column(String(255), nullable=False, server_default=text("''"))
    isbn = Column(String(255), nullable=False, server_default=text("''"))
    mpn = Column(String(255), nullable=False, server_default=text("''"))
    qty = Column(Integer, nullable=False, server_default=text("'0'"))
    xtra = Column(Text, nullable=False)

class WpEshopCountry(Base):
    __tablename__ = u'wp_eshop_countries'

    code = Column(String(2), primary_key=True, server_default=text("''"))
    country = Column(String(50), nullable=False, server_default=text("''"))
    zone = Column(Integer, nullable=False, index=True, server_default=text("'0'"))
    list = Column(Integer, nullable=False, server_default=text("'1'"))

class WpEshopDiscountCode(Base):
    __tablename__ = u'wp_eshop_discount_codes'

    id = Column(Integer, primary_key=True)
    dtype = Column(Integer, nullable=False, server_default=text("'0'"))
    disccode = Column(String(255), nullable=False, unique=True, server_default=text("''"))
    percent = Column(Float(5), nullable=False, server_default=text("'0.00'"))
    remain = Column(String(11), nullable=False, server_default=text("''"))
    used = Column(Integer, nullable=False, server_default=text("'0'"))
    enddate = Column(Date, nullable=False, server_default=text("'0000-00-00'"))
    live = Column(String(3), nullable=False, server_default=text("'no'"))

class WpEshopDownloadOrder(Base):
    __tablename__ = u'wp_eshop_download_orders'
    __table_args__ = (
        Index(u'code', u'code', u'email'),
    )

    id = Column(Integer, primary_key=True)
    checkid = Column(String(255), nullable=False, server_default=text("''"))
    title = Column(String(255), nullable=False, server_default=text("''"))
    purchased = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    files = Column(String(255), nullable=False, server_default=text("''"))
    downloads = Column(SmallInteger, nullable=False, server_default=text("'3'"))
    code = Column(String(20), nullable=False, server_default=text("''"))
    email = Column(String(255), nullable=False, server_default=text("''"))

class WpEshopDownload(Base):
    __tablename__ = u'wp_eshop_downloads'

    id = Column(Integer, primary_key=True)
    title = Column(String(255), nullable=False, server_default=text("''"))
    added = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    files = Column(String(255), nullable=False, server_default=text("''"))
    downloads = Column(Integer, nullable=False, server_default=text("'0'"))
    purchases = Column(Integer, nullable=False, server_default=text("'0'"))

class WpEshopEmail(Base):
    __tablename__ = u'wp_eshop_emails'

    id = Column(Integer, primary_key=True)
    emailUse = Column(Integer, nullable=False, server_default=text("'0'"))
    emailType = Column(String(50), nullable=False, server_default=text("''"))
    emailSubject = Column(String(255), nullable=False, server_default=text("''"))
    emailContent = Column(Text, nullable=False)

class WpEshopOptionName(Base):
    __tablename__ = u'wp_eshop_option_names'

    optid = Column(Integer, primary_key=True)
    name = Column(String(255), nullable=False, server_default=text("''"))
    admin_name = Column(String(255), nullable=False, server_default=text("''"))
    type = Column(Integer, nullable=False, server_default=text("'0'"))
    description = Column(String(255), nullable=False, server_default=text("''"))

class WpEshopOptionSet(Base):
    __tablename__ = u'wp_eshop_option_sets'

    id = Column(Integer, primary_key=True)
    optid = Column(Integer, nullable=False, server_default=text("'0'"))
    name = Column(String(255), nullable=False, server_default=text("''"))
    price = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    weight = Column(Float(8), nullable=False, server_default=text("'0.00'"))

class WpEshopOrderItem(Base):
    __tablename__ = u'wp_eshop_order_items'

    id = Column(Integer, primary_key=True)
    checkid = Column(String(255), nullable=False, index=True, server_default=text("''"))
    item_id = Column(String(255), nullable=False, server_default=text("'0'"))
    item_qty = Column(Integer, nullable=False, server_default=text("'0'"))
    item_amt = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    tax_rate = Column(String(255), nullable=False, server_default=text("''"))
    tax_amt = Column(String(255), nullable=False, server_default=text("''"))
    optname = Column(String(255), nullable=False, server_default=text("''"))
    optsets = Column(Text, nullable=False)
    post_id = Column(Integer, nullable=False, server_default=text("'0'"))
    option_id = Column(Integer, nullable=False, server_default=text("'0'"))
    down_id = Column(Integer, nullable=False, server_default=text("'0'"))
    weight = Column(Float(16), nullable=False, server_default=text("'0.00'"))

class WpEshopOrder(Base):
    __tablename__ = u'wp_eshop_orders'

    id = Column(Integer, primary_key=True)
    checkid = Column(String(255), nullable=False, index=True, server_default=text("''"))
    status = Column(String(9), nullable=False, index=True, server_default=text("'Pending'"))
    first_name = Column(String(50), nullable=False, server_default=text("''"))
    last_name = Column(String(50), nullable=False, server_default=text("''"))
    company = Column(String(255), nullable=False, server_default=text("''"))
    email = Column(String(100), nullable=False, server_default=text("''"))
    phone = Column(String(30), nullable=False, server_default=text("''"))
    address1 = Column(String(255), nullable=False, server_default=text("''"))
    address2 = Column(String(255), nullable=False, server_default=text("''"))
    city = Column(String(100), nullable=False, server_default=text("''"))
    state = Column(String(100), nullable=False, server_default=text("''"))
    zip = Column(String(20), nullable=False, server_default=text("''"))
    country = Column(String(3), nullable=False, server_default=text("''"))
    reference = Column(String(255), nullable=False, server_default=text("''"))
    ship_name = Column(String(100), nullable=False, server_default=text("''"))
    ship_company = Column(String(255), nullable=False, server_default=text("''"))
    ship_phone = Column(String(30), nullable=False, server_default=text("''"))
    ship_address = Column(String(255), nullable=False, server_default=text("''"))
    ship_city = Column(String(100), nullable=False, server_default=text("''"))
    ship_state = Column(String(100), nullable=False, server_default=text("''"))
    ship_postcode = Column(String(20), nullable=False, server_default=text("''"))
    ship_country = Column(String(3), nullable=False, server_default=text("''"))
    custom_field = Column(String(15), nullable=False, server_default=text("''"))
    transid = Column(String(255), nullable=False, server_default=text("''"))
    comments = Column(Text, nullable=False)
    thememo = Column(Text, nullable=False)
    edited = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    downloads = Column(String(3), nullable=False, server_default=text("'no'"))
    admin_note = Column(Text, nullable=False)
    paidvia = Column(String(255), nullable=False, server_default=text("''"))
    affiliate = Column(String(255), nullable=False, server_default=text("''"))
    user_id = Column(Integer, nullable=False)
    user_notes = Column(Text, nullable=False)

class WpEshopRate(Base):
    __tablename__ = u'wp_eshop_rates'

    id = Column(Integer, primary_key=True)
    _class = Column(u'class', String(3), nullable=False, server_default=text("''"))
    items = Column(SmallInteger, nullable=False, server_default=text("'0'"))
    zone1 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone2 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone3 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone4 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone5 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone6 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone7 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone8 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    zone9 = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    weight = Column(Float(16), nullable=False, server_default=text("'0.00'"))
    maxweight = Column(String(16), nullable=False, server_default=text("''"))
    area = Column(String(50), nullable=False, server_default=text("''"))
    rate_type = Column(String(255), nullable=False, server_default=text("'shipping'"))

class WpEshopState(Base):
    __tablename__ = u'wp_eshop_states'

    id = Column(Integer, primary_key=True)
    code = Column(String(4), nullable=False, server_default=text("''"))
    stateName = Column(String(30), nullable=False, server_default=text("''"))
    zone = Column(Integer, nullable=False, index=True, server_default=text("'0'"))
    list = Column(String(2), nullable=False, server_default=text("''"))

class WpEshopStock(Base):
    __tablename__ = u'wp_eshop_stock'
    __table_args__ = (
        Index(u'post_id', u'post_id', u'available', u'purchases'),
    )

    id = Column(Integer, primary_key=True)
    post_id = Column(Integer, nullable=False, server_default=text("'0'"))
    option_id = Column(Integer, nullable=False, server_default=text("'0'"))
    available = Column(Integer, nullable=False, server_default=text("'0'"))
    purchases = Column(Integer, nullable=False, server_default=text("'0'"))

class WpHlTwitterReply(Base):
    __tablename__ = u'wp_hl_twitter_replies'

    id = Column(Integer, primary_key=True)
    twitter_tweet_id = Column(BigInteger, unique=True)
    twitter_user_id = Column(Integer)
    twitter_user_name = Column(String(40, u'utf8_unicode_ci'))
    twitter_user_screen_name = Column(String(40, u'utf8_unicode_ci'))
    twitter_user_url = Column(String(255, u'utf8_unicode_ci'))
    twitter_user_avatar = Column(String(255, u'utf8_unicode_ci'))
    tweet = Column(String(160, u'utf8_unicode_ci'), index=True)
    lat = Column(Float(asdecimal=True))
    lon = Column(Float(asdecimal=True))
    created = Column(DateTime)
    reply_tweet_id = Column(BigInteger)
    reply_user_id = Column(Integer)
    reply_screen_name = Column(String(40, u'utf8_unicode_ci'))
    source = Column(String(40, u'utf8_unicode_ci'))

class WpHlTwitterTweet(Base):
    __tablename__ = u'wp_hl_twitter_tweets'

    id = Column(Integer, primary_key=True)
    twitter_tweet_id = Column(BigInteger, unique=True)
    twitter_user_id = Column(Integer, index=True)
    tweet = Column(String(160, u'utf8_unicode_ci'), index=True)
    lat = Column(Float(asdecimal=True))
    lon = Column(Float(asdecimal=True))
    created = Column(DateTime)
    reply_tweet_id = Column(BigInteger)
    reply_user_id = Column(Integer)
    reply_screen_name = Column(String(40, u'utf8_unicode_ci'))
    source = Column(String(40, u'utf8_unicode_ci'))

class WpHlTwitterUser(Base):
    __tablename__ = u'wp_hl_twitter_users'

    id = Column(Integer, primary_key=True)
    twitter_user_id = Column(Integer, index=True)
    screen_name = Column(String(40, u'utf8_unicode_ci'))
    name = Column(String(40, u'utf8_unicode_ci'))
    num_friends = Column(Integer)
    num_followers = Column(Integer)
    num_tweets = Column(Integer)
    registered = Column(DateTime)
    url = Column(String(255, u'utf8_unicode_ci'))
    description = Column(String(255, u'utf8_unicode_ci'))
    location = Column(String(40, u'utf8_unicode_ci'))
    avatar = Column(String(255, u'utf8_unicode_ci'))
    created = Column(DateTime)
    last_updated = Column(DateTime)
    pull_in_replies = Column(Integer, server_default=text("'0'"))

class WpInstagram(Base):
    __tablename__ = u'wp_instagram'

    access_token = Column(String(150, u'utf8_unicode_ci'), nullable=False)
    user_id = Column(String(50, u'utf8_unicode_ci'), nullable=False)
    ID = Column(Integer, primary_key=True)

class WpLink(Base):
    __tablename__ = u'wp_links'

    link_id = Column(BigInteger, primary_key=True)
    link_url = Column(String(255), nullable=False, server_default=text("''"))
    link_name = Column(String(255), nullable=False, server_default=text("''"))
    link_image = Column(String(255), nullable=False, server_default=text("''"))
    link_target = Column(String(25), nullable=False, server_default=text("''"))
    link_description = Column(String(255), nullable=False, server_default=text("''"))
    link_visible = Column(String(20), nullable=False, index=True, server_default=text("'Y'"))
    link_owner = Column(BigInteger, nullable=False, server_default=text("'1'"))
    link_rating = Column(Integer, nullable=False, server_default=text("'0'"))
    link_updated = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    link_rel = Column(String(255), nullable=False, server_default=text("''"))
    link_notes = Column(String, nullable=False)
    link_rss = Column(String(255), nullable=False, server_default=text("''"))

class WpNggAlbum(Base):
    __tablename__ = u'wp_ngg_album'

    id = Column(BigInteger, primary_key=True)
    name = Column(String(255), nullable=False)
    slug = Column(String(255), nullable=False)
    previewpic = Column(BigInteger, nullable=False, server_default=text("'0'"))
    albumdesc = Column(String)
    sortorder = Column(String, nullable=False)
    pageid = Column(BigInteger, nullable=False, server_default=text("'0'"))

class WpNggGallery(Base):
    __tablename__ = u'wp_ngg_gallery'

    gid = Column(BigInteger, primary_key=True)
    name = Column(String(255), nullable=False)
    slug = Column(String(255), nullable=False)
    path = Column(String)
    title = Column(String)
    galdesc = Column(String)
    pageid = Column(BigInteger, nullable=False, server_default=text("'0'"))
    previewpic = Column(BigInteger, nullable=False, server_default=text("'0'"))
    author = Column(BigInteger, nullable=False, server_default=text("'0'"))

class WpNggPicture(Base):
    __tablename__ = u'wp_ngg_pictures'

    pid = Column(BigInteger, primary_key=True)
    image_slug = Column(String(255), nullable=False)
    post_id = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    galleryid = Column(BigInteger, nullable=False, server_default=text("'0'"))
    filename = Column(String(255), nullable=False)
    description = Column(String)
    alttext = Column(String)
    imagedate = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    exclude = Column(Integer, server_default=text("'0'"))
    sortorder = Column(BigInteger, nullable=False, server_default=text("'0'"))
    meta_data = Column(String)

class WpOption(Base):
    __tablename__ = u'wp_options'

    option_id = Column(BigInteger, primary_key=True)
    option_name = Column(String(64), nullable=False, unique=True, server_default=text("''"))
    option_value = Column(String, nullable=False)
    autoload = Column(String(20), nullable=False, server_default=text("'yes'"))

class WpPostmeta(Base):
    __tablename__ = u'wp_postmeta'

    meta_id = Column(BigInteger, primary_key=True)
    post_id = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    meta_key = Column(String(255), index=True)
    meta_value = Column(String)

class WpPost(Base):
    __tablename__ = u'wp_posts'
    __table_args__ = (
        Index(u'type_status_date', u'post_type', u'post_status', u'post_date', u'ID'),
    )

    ID = Column(BigInteger, primary_key=True)
    post_author = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    post_date = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    post_date_gmt = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    post_content = Column(String, nullable=False)
    post_title = Column(Text, nullable=False)
    post_excerpt = Column(Text, nullable=False)
    post_status = Column(String(20), nullable=False, server_default=text("'publish'"))
    comment_status = Column(String(20), nullable=False, server_default=text("'open'"))
    ping_status = Column(String(20), nullable=False, server_default=text("'open'"))
    post_password = Column(String(20), nullable=False, server_default=text("''"))
    post_name = Column(String(200), nullable=False, index=True, server_default=text("''"))
    to_ping = Column(Text, nullable=False)
    pinged = Column(Text, nullable=False)
    post_modified = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    post_modified_gmt = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    post_content_filtered = Column(String, nullable=False)
    post_parent = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    guid = Column(String(255), nullable=False, server_default=text("''"))
    menu_order = Column(Integer, nullable=False, server_default=text("'0'"))
    post_type = Column(String(20), nullable=False, server_default=text("'post'"))
    post_mime_type = Column(String(100), nullable=False, server_default=text("''"))
    comment_count = Column(BigInteger, nullable=False, server_default=text("'0'"))

class WpTermRelationship(Base):
    __tablename__ = u'wp_term_relationships'

    object_id = Column(BigInteger, primary_key=True, nullable=False, server_default=text("'0'"))
    term_taxonomy_id = Column(BigInteger, primary_key=True, nullable=False, index=True, server_default=text("'0'"))
    term_order = Column(Integer, nullable=False, server_default=text("'0'"))

class WpTermTaxonomy(Base):
    __tablename__ = u'wp_term_taxonomy'
    __table_args__ = (
        Index(u'term_id_taxonomy', u'term_id', u'taxonomy', unique=True),
    )

    term_taxonomy_id = Column(BigInteger, primary_key=True)
    term_id = Column(BigInteger, nullable=False, server_default=text("'0'"))
    taxonomy = Column(String(32), nullable=False, index=True, server_default=text("''"))
    description = Column(String, nullable=False)
    parent = Column(BigInteger, nullable=False, server_default=text("'0'"))
    count = Column(BigInteger, nullable=False, server_default=text("'0'"))

class WpTerm(Base):
    __tablename__ = u'wp_terms'

    term_id = Column(BigInteger, primary_key=True)
    name = Column(String(200), nullable=False, index=True, server_default=text("''"))
    slug = Column(String(200), nullable=False, unique=True, server_default=text("''"))
    term_group = Column(BigInteger, nullable=False, server_default=text("'0'"))

class WpUsermeta(Base):
    __tablename__ = u'wp_usermeta'

    umeta_id = Column(BigInteger, primary_key=True)
    user_id = Column(BigInteger, nullable=False, index=True, server_default=text("'0'"))
    meta_key = Column(String(255), index=True)
    meta_value = Column(String)

class WpUser(Base):
    __tablename__ = u'wp_users'

    ID = Column(BigInteger, primary_key=True)
    user_login = Column(String(60), nullable=False, index=True, server_default=text("''"))
    user_pass = Column(String(64), nullable=False, server_default=text("''"))
    user_nicename = Column(String(50), nullable=False, index=True, server_default=text("''"))
    user_email = Column(String(100), nullable=False, server_default=text("''"))
    user_url = Column(String(100), nullable=False, server_default=text("''"))
    user_registered = Column(DateTime, nullable=False, server_default=text("'0000-00-00 00:00:00'"))
    user_activation_key = Column(String(60), nullable=False, server_default=text("''"))
    user_status = Column(Integer, nullable=False, server_default=text("'0'"))
    display_name = Column(String(250), nullable=False, server_default=text("''"))


text:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Author: Jose Santos <jcas81@gmail.com>
% Date: 2009-08-13
%
%    This file contains predicates to compute the symmetric relative minimal generalization
%  of two clauses.
%
%
%  There's a linear algorithm to determine if an srmg bottom subsumes another.
%  An srmg can be viewed as a two list of integers (indexs) over each bottom clause used
%  to construct it. An srmg, srmg1, subsumes another srmg, srmg2, with respect to one example E,
%  if its list of integers (for bottom E) is a subset of the list of integers for srmg2 AND
%  at those positions, it unifies!
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

:- module(srmg,
            [
              create_srmg_heuristic_term/2,
              srmg/7, % srmg between 2 clauses (requires their signatures)
              srmg/6, % srmg between one clause and one example
              srmg/5  % srmg between two examples (constructs their bottom clauses)
            ]
         ).

% GILPS modules
:- use_module('../clause evaluation/common_clause_evaluation', [clause_examples_coverage/6]).
:- use_module('../utils/clause', [buildPredCall/4, skolemize/2]).
:- use_module('../settings/settings', [setting/2]).%because of 'srmg_heuristic'
:- use_module('bottom_clause', [sat/3]).

% YAP modules
:- use_module(library(lists), [nth/4, reverse/2]).
:- use_module(library(rbtrees), [rb_new/1, rb_lookup/3, rb_insert/4]).
:- use_module(library(apply_macros), [maplist/3]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% create_srmg_heuristic_term(+NegativeExampleIDs, -SRMG_Heuristic),
%
% Given:
%  NegativeExampleIDs: ordered list of negative example ids
%
% Returns:
%  SRMG_Heuristic: the heuristic term to use when computing srmgs
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

create_srmg_heuristic_term(_, heuristic(first_match)):-
  setting(srmg_heuristic, first_match),!.

create_srmg_heuristic_term(NEIDs, heuristic(minimize_negative, NEIDs)):-
  setting(srmg_heuristic, minimize_negative),!.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Type of important datastructures for constructing the lgg
%
%    Mapping: an rb_tree where the key is a triple (Type, Term1, Term2) and value is the variable
%             associated with this pair (Type is Term1 and Term2 type)
%             Term1 and Term2 are skolemized variables
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% initial_mapping(-Mapping)
%
% Returns:
%   Mapping: initial Mapping
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

initial_mapping(Mapping):-
  rb_new(Mapping).

%get_existing_mapping(+Mapping, +(Type, Term1, Term2), -Value)
get_existing_mapping(Mapping, (Type, Term1, Term2), Value):-
  rb_lookup(k(Type, Term1, Term2), Value, Mapping).

%create_new_mapping(+Mapping, +(Type, Term1, Term2), -Value, -NewMapping)
create_new_mapping(Mapping, (Type, Term1, Term2), Value, NewMapping):-
  rb_insert(Mapping, k(Type, Term1, Term2), Value, NewMapping).

/*
%Alternative mapping implementation with lists, the above is more efficient
initial_mapping([]).

get_existing_mapping([(Type, Term1A, Term2A, Value)|_], (Type, Term1B, Term2B), Value):-
  Term1A==Term1B,
  Term2A==Term2B,!.
get_existing_mapping([_|Map], (Type, Term1, Term2), Value):-
  get_existing_mapping(Map, (Type, Term1, Term2), Value).

create_new_mapping(Map, (Type, Term1, Term2), Value, [(Type, Term1, Term2, Value)|Map]).
*/

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% srmg(+Clause1, +ClauseSig1, +Clause2, +ClauseSig2, +Heuristic, -lgg, -lggSig)
%
% Given:
%   Clause1: a clause as a list of literals
%   Clause1Sig: Clause1 signature
%   Clause2: a clause as a list of literals
%   Clause2Sig: Clause2 signature
%   Heuristic: a term that can either be: heuristic(first_match) or
%                heuristic(minimize_negative, OrderedListOfNegativeExamples)
%
% Returns:
%   lgg: least general generalization of Clause1 and Clause2
%   lggSig: lgg signature
%
% Examples:
%
% srmg([a(5)],[a(#i)],[a(5)],[a(#i)], C, S).
%   C= [a(5)], S = [a(#i)] ? ;
%
% srmg([a(A),b(A,5)],[a(+i),b(+i,#i)],[a(B),b(B,5)],[a(+i),b(+i,#i)], C, S).
%   C = [a(_A),b(_A,5)],
%   S = [a(+i),b(+i,#i)] ?
%
% sat(p(d0),_C1,_S1),sat(p(d1),_C2,_S2),srmg(_C1,_C1,_C2,_S2,LGU,LGUS).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

srmg(Clause1, [HeadSig|Body1Sig], Clause2, [HeadSig|Body2Sig], Heuristic,
     [LGU_Head|LGU_Body], [HeadSig|LGU_BodySig]):-
  skolemize(Clause1, [Head1|Body1]),
  skolemize(Clause2, [Head2|Body2]),
  initial_mapping(Map0),
  lgu(Head1, Head2, HeadSig, head, Map0, LGU_Head, Map1),
  srmg_body(Body1, Body1Sig, Body2, Body2Sig, Map1, Heuristic, [LGU_Head], [HeadSig], LGU_Body, LGU_BodySig).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  srmg_body(+Body1, +Body1Sig, +Body2, +Body2Sig, +Map1, +Heuristic, +CurLGU, +CurLGUSig,
%            -LGU_Body, -LGU_BodySig)
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

srmg_body([], [], _, _, _, _, _, _, [], []).
srmg_body([Atom|Atoms], [ASig|ASigs], Body, BodySig, CurMap, Heuristic, CL, CLS, [LGUB|Ls], [ASig|LBs]):-
  lgusForBodyAtom(Body, BodySig, Atom, ASig, CurMap, AllAtomLGUs),
  select_best_matching_lgu(Heuristic, AllAtomLGUs, ASig, CL, CLS, BestLGU, UHeuristic),!,
%  length(Atoms, StillToGo), format("Still ~w atoms to compute this srmg~n", [StillToGo]),
  BestLGU=(LGUB,Pos,NCurMap),
  nth(Pos, Body, _BodyAtom, NBody),
  nth(Pos, BodySig, _, NBodySig),
  %format("Atom ~w (pos: ~w) selected to match ~w~n", [_BodyAtom, Pos, Atom]),
  srmg_body(Atoms, ASigs, NBody, NBodySig, NCurMap, UHeuristic, [LGUB|CL], [ASig|CLS], Ls, LBs).
srmg_body([_|Atoms], [_|ASigs], Body, BodySig, CurMap, Heuristic, CL, CLS, LGU_Body, LGU_BodySig):-
  %Atom has no lgu in the other body
  srmg_body(Atoms, ASigs, Body, BodySig, CurMap, Heuristic, CL, CLS, LGU_Body, LGU_BodySig).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% select_best_matching_lgu(+Heuristic, +AllPossibleLGUs, +AllLGUSig, +CurLGU, +CurLGUSig,
%                         -BestMatchingLGU, -UpdatedHeuristic)
%
% Given:
%  Heuristic: see above srmg/6
%  AllPossibleLGUs: a list of all possible lgus where each element is a tuple:
%    (LeastGeneralUnifier, Position in BodyAtoms, UpdatedMapping)
%  AllLGUSig: signature common to all LeastGeneralUnifiers in AllPossibleLGUs
%  CurLGU: a list of literals representing the current lgu (in reversed form!)
%  CurLGUSig: CurLGU signature  (in reversed form!)
%  NegativeExampleIDs: ordered list of negative example ids
%
% Returns:
%  BestMatchingLGU: the best matching lgu is a tuple: (LeastGeneralUnifier, Position in BodyAtoms, UpdatedMapping)
%    LeastGeneralUnifier is an atom
%  UpdatedHeuristic: the heuristic to use next turn (it's the same heuristic, this parameter is only
%                    needed because we want to pass an ordered list of the CoveredNegativeExamples,
%                    so that in the next turns, if heuristic is minimize_negative, we can do it more efficiently)
%
% Notes:
%  The best matching lgu is obtained by, from all the matching lgu, choosing the one that, when added
%  to the current lgu, covers the fewest negative examples weights.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%select_best_matching_lgu(+Heuristic, +AllPossibleLGUs, +CommonSig, +CurLGU, +CurLGUSig, -BMLGU, -UHeuristic):-
select_best_matching_lgu(heuristic(first_match), [BMLGU|_], _CSig, _C, _S, BMLGU, heuristic(first_match)).
select_best_matching_lgu(heuristic(minimize_negative, NEIDs), AllPLgus, ASig, CL, SL,%note that CL and SL are reversed
                         BMLGU, heuristic(minimize_negative, NNEIDs)):-
  length(AllPLgus, NumAllPLgus),
  NumAllPLgus>0,
  (NumAllPLgus=1 -> % there's only one choice, select it without computing negative coverage
     AllPLgus=[BMLGU],
     NNEIDs=NEIDs
   ;%NumAllPLgus>1
     reverse([ASig|SL], CSig), %C sig is now in proper format
    %CL still needs to have the head appended and reversed
     select_best_matching_lgu_mn(AllPLgus, NEIDs, CL, CSig, inf, _, _, NNEIDs, BMLGU)
  ).

%select_best_matching_lgu_mn(+AllPLgus, +NegativeEIDs, +CL, +ClauseSig, +CurBestNegWeightsCovered,
%                            +CurNegEIDsCovered, +CurBestMLGU, -FinalNegEIDsCovered, -FinalBestMLGU)

select_best_matching_lgu_mn([], _, _, _, _, NEIDs, BMLGU, NEIDs, BMLGU).
select_best_matching_lgu_mn([(LGUB,Pos,Map)|RL], NEIDs, CL, ClauseSig, CurBNWC,
                            _CurNegEIDsCovered, _CurBMLGU, FinalNegEIDsCov, BMLGU):-
  reverse([LGUB|CL], Clause), %ClauseSig has the signature for Clause
  clause_examples_coverage(NEIDs, Clause, ClauseSig, CurBNWC, NCurBNWC, NCurNegEIDsCovered),
  NCurBNWC<CurBNWC,!,% NCurBNWC may be equal to CurBNWC, in which case we prefer the former
  %format("Weight covered by atom pos ~w:~w~n", [Pos, NCurBNWC]),
  select_best_matching_lgu_mn(RL, NEIDs, CL, ClauseSig, NCurBNWC,
                              NCurNegEIDsCovered, (LGUB,Pos,Map), FinalNegEIDsCov, BMLGU).

select_best_matching_lgu_mn([_|RL], NEIDs, CL, ClauseSig, CurBNWC,
                            CurNegEIDsCovered, CurBMLGU, FinalNegEIDsCov, BMLGU):-
  % current LGU tuple is no better than the best so far
  select_best_matching_lgu_mn(RL, NEIDs, CL, ClauseSig, CurBNWC,
                              CurNegEIDsCovered, CurBMLGU, FinalNegEIDsCov, BMLGU).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% lgusForBodyAtom(+BodyAtoms, +BodyAtomsSig, +Atom, +AtomSig, +CurMapping, -LGUs)
%
% Given:
%  BodyAtoms: a list of atoms
%  BodyAtomsSig: signatures for each of BodyAtoms
%  Atom: an atom we want to compute its lgu
%  AtomSig: Atom signature
%  CurMapping: the current mapping of terms to variables
%
% Returns:
%  LGUs: a list where each element is a tuple: (LeastGeneralUnifier, Position in BodyAtoms, UpdatedMapping)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

lgusForBodyAtom(BodyAtoms, BodyAtomsSig, Atom, AtomSig, CurMapping, LGUs):-
  lgusForBodyAtom(BodyAtoms, BodyAtomsSig, 1, Atom, AtomSig, CurMapping, LGUs).

lgusForBodyAtom([], [], _, _, _, _, []).
lgusForBodyAtom([A|As], [AtomSig|ASs], N, Atom, AtomSig, CM, [(LGU,N,FM)|LGUs]):-
  lgu(A, Atom, AtomSig, body, CM, LGU, FM),!,
  N1 is N+1,
  lgusForBodyAtom(As, ASs, N1, Atom, AtomSig, CM, LGUs).
lgusForBodyAtom([_|As], [_|ASs], N, Atom, AtomSig, CM, LGUs):-
  N1 is N+1,
  lgusForBodyAtom(As, ASs, N1, Atom, AtomSig, CM, LGUs).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% lgu(+Atom1, +Atom2, +AtomSig, +LiteralFrom, +CurMapping, -LGU, -FinalMapping)
%
% Given:
%  Atom1: an atom
%  Atom2: another atom
%  AtomSig: signature that is shared by Atom1 and Atom2
%  LiteralFrom: where Atom1 and Atom2 comes from either 'head' or 'body'
%
% Returns:
%  lgu: least general unifier of Atom1 with Atom2
%       (it's signature is AtomSig)
%
% Notes:
%  The least general unifier must be mode compatible (that is, it's input variable must
%  already exist, except in the case of the head)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

lgu(Atom1, Atom2, AtomSig, LiteralFrom, CurMap, LGU, FinalMap):-
  buildPredCall(AtomSig, Atom1Args, AtomIOTypes, Atom1),
  buildPredCall(AtomSig, Atom2Args, AtomIOTypes, Atom2),
  maplist(updateIO(LiteralFrom), AtomIOTypes, NAtomIOTypes),
  matchArgs(Atom1Args, Atom2Args, NAtomIOTypes, CurMap, ArgsUnifier, FinalMap),
  buildPredCall(AtomSig, ArgsUnifier, AtomIOTypes, LGU).

%updateIO(+LiteralFrom, +AtomIOType, -NewAtomIOType)
% head input atoms (+) are replaced by output (-) because otherwise matchArgs would fail to
% find an existing unifier as the mapping is empty before processing head
updateIO(head, +T, -T):-!.
updateIO(_, IOT, IOT).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% matchArgs(+AA1, +AA2, +AIOT, +MappingDS, -ArgsGeneralizer, -NewMappingDS)
%
% Given:
%   AtomArgs1: atom1's terms (some/all may be variables). E.g. [A,5,B]
%   AtomArgs2: atom2's terms (some/all may be variables).
%   AtomIOTypes: atom1's and atom2's io types. E.g. [+t,#i,-p]
%   MappingDS: mapping datastructure
%
% Returns:
%   ArgGeneralizer: a list of terms (variables or values) that generalize ATT1 with ATT2
%   NewMappingDS: new mapping datastructure
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%matchArgs(+AA1, +AA2, +AIOT, +MappingDS, -ArgsGeneralizer, -NewMappingDS):-
matchArgs([], [], [], Map, [], Map).
matchArgs([A1|A1s], [A2|A2s], [IOType|IOTs], CurMap, [AG|AGs], FMap):-
  matchTerm(IOType, A1, A2, CurMap, AG, NCurMap),
  matchArgs(A1s, A2s, IOTs, NCurMap, AGs, FMap).

%matchTerm(+IOType, +A1, +A2, +CurMapping, -Generalizer, -NewMapping)
matchTerm(+Type, A1, A2, CurMapping, Generalizer, CurMapping):-
  !, % if the IO Mode is + then the variable to add must already exist
  get_existing_mapping(CurMapping, (Type, A1, A2), Generalizer). % unifier already exists

matchTerm(#_, A1, A2, Mapping, A1, Mapping):-
  !, % if the IO Mode is # the constants must be the same, otherwise the unifier signature
     % wouldn't be equal
  A1=A2. % we don't need to update the mapping

matchTerm(-Type, A1, A2, CurMapping, Generalizer, CurMapping):-
  get_existing_mapping(CurMapping, (Type, A1, A2), Generalizer),!. % unifier already exists

% unifier does not exist, create it
matchTerm(-Type, A1, A2, Mapping, Generalizer, NewMapping):-
  %case where the terms are two distinct constants or variables (no matter if equal)
  create_new_mapping(Mapping, (Type, A1, A2), Generalizer, NewMapping).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% srmg(+Example1, +Example2, +Heuristic, -lgg, -lggSig)
% srmg(+Clause, +ClauseSig, +Example, +Heuristic, -SRMG, -SRMGSig)
%
% Given:
%
%  Heuristic: either heuristic(first_match) or heuristic(minimize_negative, NegEIDs)
%
% These are variations from the above srmg/6
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

srmg(Example1, Example2, Heuristic, SRMG, SRMGSig):-
  sat(Example1, Bottom_Example1, Bottom_Example1Sig),
  srmg(Bottom_Example1, Bottom_Example1Sig, Example2, Heuristic, SRMG, SRMGSig).

srmg(Clause, ClauseSig, Example, Heuristic, SRMG, SRMGSig):-
  sat(Example, Bottom_Example, Bottom_ExampleSig),
  srmg(Clause, ClauseSig, Bottom_Example, Bottom_ExampleSig, Heuristic, SRMG, SRMGSig).

redpajama_set_name: RedPajamaGithub


text:
import { Injectable } from '@angular/core';
import { Effect, Actions } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { CandidateActions } from './candidate.actions';
import { CandidateService } from './candidate.service';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';

@Injectable()
export class CandidateEffects {
    @Effect() public loadCandidates$ = this.update$
        .ofType(CandidateActions.LOAD_CANDIDATES)
        .switchMap(() => this.svc.getCandidates())
        .map( (candidates) => this.candidateActions.loadCandidatesSuccess(candidates));

    @Effect() public getCandidate$ = this.update$
        .ofType(CandidateActions.GET_CANDIDATE)
        .map( (action) => action.payload)
        .switchMap( (id) => this.svc.getCandidate(id))
        .map( (candidate) => this.candidateActions.getCandidateSuccess(candidate));

    @Effect() public addCandidate$ = this.update$
        .ofType(CandidateActions.ADD_CANDIDATE)
        .map( (action) => action.payload)
        .switchMap( (candidate) => this.svc.addCandidate(candidate))
        .map( (candidate) => this.candidateActions.addCandidateSuccess(candidate));

    @Effect() public updateCandidate$ = this.update$
        .ofType(CandidateActions.UPDATE_CANDIDATE)
        .map( (action) => action.payload)
        .switchMap( (candidate) => this.svc.updateCandidate(candidate))
        .map( (candidate) => this.candidateActions.updateCandidateSuccess(candidate));

    constructor(
        private update$: Actions,
        private candidateActions: CandidateActions,
        private svc: CandidateService
    ) { }
}


text:
#ifndef LIBDISASM_H
#define LIBDISASM_H

#ifdef WIN32
#include <windows.h>
#endif

#include <stdint.h>

/* 'NEW" types
 * __________________________________________________________________________*/
#ifndef LIBDISASM_QWORD_H       /* do not interfere with qword.h */
        #define LIBDISASM_QWORD_H
        #ifdef _MSC_VER
                typedef __int64         qword_t;
        #else
                typedef int64_t         qword_t;
        #endif
#endif

#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/* 'NEW" x86 API
 * __________________________________________________________________________*/

/* ========================================= Error Reporting */
/* REPORT CODES
 *      These are passed to a reporter function passed at initialization.
 *      Each code determines the type of the argument passed to the reporter;
 *      this allows the report to recover from errors, or just log them.
 */
enum x86_report_codes {
        report_disasm_bounds,   /* RVA OUT OF BOUNDS : The disassembler could
                                   not disassemble the supplied RVA as it is
                                   out of the range of the buffer. The
                                   application should store the address and
                                   attempt to determine what section of the
                                   binary it is in, then disassemble the
                                   address from the bytes in that section.
                                        data: uint32_t rva */
        report_insn_bounds,     /* INSTRUCTION OUT OF BOUNDS: The disassembler
                                   could not disassemble the instruction as
                                   the instruction would require bytes beyond
                                   the end of the current buffer. This usually
                                   indicated garbage bytes at the end of a
                                   buffer, or an incorrectly-sized buffer.
                                        data: uint32_t rva */
        report_invalid_insn,    /* INVALID INSTRUCTION: The disassembler could
                                   not disassemble the instruction as it has an
                                   invalid combination of opcodes and operands.
                                   This will stop automated disassembly; the
                                   application can restart the disassembly
                                   after the invalid instruction.
                                        data: uint32_t rva */
        report_unknown
};

/* 'arg' is optional arbitrary data provided by the code passing the
 *       callback -- for example, it could be 'this' or 'self' in OOP code.
 * 'code' is provided by libdisasm, it is one of the above
 * 'data' is provided by libdisasm and is context-specific, per the enums */
typedef void (*DISASM_REPORTER)( enum x86_report_codes code,
				 void *data, void *arg );

/* x86_report_error : Call the register reporter to report an error */
void x86_report_error( enum x86_report_codes code, void *data );

/* ========================================= Libdisasm Management Routines */
enum x86_options {		/* these can be ORed together */
        opt_none= 0,
        opt_ignore_nulls=1,     /* ignore sequences of > 4 NULL bytes */
        opt_16_bit=2,           /* 16-bit/DOS disassembly */
        opt_att_mnemonics=4,    /* use AT&T syntax names for alternate opcode mnemonics */
};

/* management routines */
/* 'arg' is caller-specific data which is passed as the first argument
 * to the reporter callback routine */
int x86_init( enum x86_options options, DISASM_REPORTER reporter, void *arg);
void x86_set_reporter( DISASM_REPORTER reporter, void *arg);
void x86_set_options( enum x86_options options );
enum x86_options x86_get_options( void );
int x86_cleanup(void);

/* ========================================= Instruction Representation */
/* these defines are only intended for use in the array decl's */
#define MAX_REGNAME 8

#define MAX_PREFIX_STR 32
#define MAX_MNEM_STR 16
#define MAX_INSN_SIZE 20        /* same as in i386.h */
#define MAX_OP_STRING 256       /* max possible operand size in string form */
#define MAX_OP_RAW_STRING 64    /* max possible operand size in raw form */
#define MAX_OP_XML_STRING 256   /* max possible operand size in xml form */
#define MAX_NUM_OPERANDS 8	/* max # implicit and explicit operands */
/* in these, the '2 *' is arbitrary: the max # of operands should require
 * more space than the rest of the insn */
#define MAX_INSN_STRING 512        /* 2 * 8 * MAX_OP_STRING */
#define MAX_INSN_RAW_STRING 1024   /* 2 * 8 * MAX_OP_RAW_STRING */
#define MAX_INSN_XML_STRING 4096   /* 2 * 8 * MAX_OP_XML_STRING */

enum x86_reg_type {     /* NOTE: these may be ORed together */
        reg_gen         = 0x00001,      /* general purpose */
        reg_in          = 0x00002,      /* incoming args, ala RISC */
        reg_out         = 0x00004,      /* args to calls, ala RISC */
        reg_local       = 0x00008,      /* local vars, ala RISC */
        reg_fpu         = 0x00010,      /* FPU data register */
        reg_seg         = 0x00020,      /* segment register */
        reg_simd        = 0x00040,      /* SIMD/MMX reg */
        reg_sys         = 0x00080,      /* restricted/system register */
        reg_sp          = 0x00100,      /* stack pointer */
        reg_fp          = 0x00200,      /* frame pointer */
        reg_pc          = 0x00400,      /* program counter */
        reg_retaddr     = 0x00800,      /* return addr for func */
        reg_cond        = 0x01000,      /* condition code / flags */
        reg_zero        = 0x02000,      /* zero register, ala RISC */
        reg_ret         = 0x04000,      /* return value */
        reg_src         = 0x10000,      /* array/rep source */
        reg_dest        = 0x20000,      /* array/rep destination */
        reg_count       = 0x40000       /* array/rep/loop counter */
};

/* x86_reg_t : an X86 CPU register */
typedef struct {
        char name[MAX_REGNAME];
        enum x86_reg_type type;         /* what register is used for */
        unsigned int size;              /* size of register in bytes */
        unsigned int id;                /* register ID #, for quick compares */
	unsigned int alias;		/* ID of reg this is an alias for */
	unsigned int shift;		/* amount to shift aliased reg by */
} x86_reg_t;

/* x86_ea_t : an X86 effective address (address expression) */
typedef struct {
        unsigned int     scale;         /* scale factor */
        x86_reg_t        index, base;   /* index, base registers */
        int32_t          disp;          /* displacement */
        char             disp_sign;     /* is negative? 1/0 */
        char             disp_size;     /* 0, 1, 2, 4 */
} x86_ea_t;

/* x86_absolute_t : an X86 segment:offset address (descriptor) */
typedef struct {
	unsigned short	segment;	/* loaded directly into CS */
	union {
		unsigned short	off16;	/* loaded directly into IP */
		uint32_t		off32;	/* loaded directly into EIP */
	} offset;
} x86_absolute_t;

enum x86_op_type {      /* mutually exclusive */
        op_unused = 0,          /* empty/unused operand: should never occur */
        op_register = 1,        /* CPU register */
        op_immediate = 2,       /* Immediate Value */
        op_relative_near = 3,   /* Relative offset from IP */
        op_relative_far = 4,    /* Relative offset from IP */
        op_absolute = 5,        /* Absolute address (ptr16:32) */
        op_expression = 6,      /* Address expression (scale/index/base/disp) */
        op_offset = 7,          /* Offset from start of segment (m32) */
        op_unknown
};

#define x86_optype_is_address( optype ) \
	( optype == op_absolute || optype == op_offset )
#define x86_optype_is_relative( optype ) \
	( optype == op_relative_near || optype == op_relative_far )
#define x86_optype_is_memory( optype ) \
	( optype > op_immediate && optype < op_unknown )

enum x86_op_datatype {          /* these use Intel's lame terminology */
        op_byte = 1,            /* 1 byte integer */
        op_word = 2,            /* 2 byte integer */
        op_dword = 3,           /* 4 byte integer */
        op_qword = 4,           /* 8 byte integer */
        op_dqword = 5,          /* 16 byte integer */
        op_sreal = 6,           /* 4 byte real (single real) */
        op_dreal = 7,           /* 8 byte real (double real) */
        op_extreal = 8,         /* 10 byte real (extended real) */
        op_bcd = 9,             /* 10 byte binary-coded decimal */
        op_ssimd = 10,          /* 16 byte : 4 packed single FP (SIMD, MMX) */
        op_dsimd = 11,          /* 16 byte : 2 packed double FP (SIMD, MMX) */
        op_sssimd = 12,         /* 4 byte : scalar single FP (SIMD, MMX) */
        op_sdsimd = 13,         /* 8 byte : scalar double FP (SIMD, MMX) */
	op_descr32 = 14,	/* 6 byte Intel descriptor 2:4 */
	op_descr16 = 15,	/* 4 byte Intel descriptor 2:2 */
	op_pdescr32 = 16,	/* 6 byte Intel pseudo-descriptor 32:16 */
	op_pdescr16 = 17,	/* 6 byte Intel pseudo-descriptor 8:24:16 */
	op_bounds16 = 18,	/* signed 16:16 lower:upper bounds */
	op_bounds32 = 19,	/* signed 32:32 lower:upper bounds */
        op_fpuenv16 = 20,	/* 14 byte FPU control/environment data */
        op_fpuenv32 = 21,	/* 28 byte FPU control/environment data */
	op_fpustate16 = 22,	/* 94 byte FPU state (env & reg stack) */
	op_fpustate32 = 23,	/* 108 byte FPU state (env & reg stack) */
	op_fpregset = 24,	/* 512 bytes: register set */
	op_fpreg = 25,		/* FPU register */
    op_none = 0xFF,     /* operand without a datatype (INVLPG) */
};

enum x86_op_access {    /* ORed together */
        op_read = 1,
        op_write = 2,
        op_execute = 4
};

enum x86_op_flags {     /* ORed together, but segs are mutually exclusive */
        op_signed = 1,          /* signed integer */
        op_string = 2,          /* possible string or array */
        op_constant = 4,        /* symbolic constant */
        op_pointer = 8,         /* operand points to a memory address */
	op_sysref = 0x010,	/* operand is a syscall number */
	op_implied = 0x020,	/* operand is implicit in the insn */
	op_hardcode = 0x40,	/* operand is hardcoded in insn definition */
	/* NOTE: an 'implied' operand is one which can be considered a side
	 * effect of the insn, e.g. %esp being modified by PUSH or POP. A
	 * 'hard-coded' operand is one which is specified in the instruction
	 * definition, e.g. %es:%edi in MOVSB or 1 in ROL Eb, 1. The difference
	 * is that hard-coded operands are printed by disassemblers and are
	 * required to re-assemble, while implicit operands are invisible. */
        op_es_seg = 0x100,      /* ES segment override */
        op_cs_seg = 0x200,      /* CS segment override */
        op_ss_seg = 0x300,      /* SS segment override */
        op_ds_seg = 0x400,      /* DS segment override */
        op_fs_seg = 0x500,      /* FS segment override */
        op_gs_seg = 0x600       /* GS segment override */
};

/* x86_op_t : an X86 instruction operand */
typedef struct {
        enum x86_op_type        type;           /* operand type */
        enum x86_op_datatype    datatype;       /* operand size */
        enum x86_op_access      access;         /* operand access [RWX] */
        enum x86_op_flags       flags;          /* misc flags */
        union {
		/* sizeof will have to work on these union members! */
                /* immediate values */
                char            sbyte;
                short           sword;
                int32_t         sdword;
                qword_t         sqword;
                unsigned char   byte;
                unsigned short  word;
                uint32_t        dword;
                qword_t         qword;
                float           sreal;
                double          dreal;
                /* misc large/non-native types */
                unsigned char   extreal[10];
                unsigned char   bcd[10];
                qword_t         dqword[2];
                unsigned char   simd[16];
                unsigned char   fpuenv[28];
                /* offset from segment */
                uint32_t        offset;
                /* ID of CPU register */
                x86_reg_t       reg;
                /* offsets from current insn */
                char            relative_near;
                int32_t         relative_far;
		/* segment:offset */
		x86_absolute_t	absolute;
                /* effective address [expression] */
                x86_ea_t        expression;
        } data;
	/* this is needed to make formatting operands more sane */
	void * insn;		/* pointer to x86_insn_t owning operand */
} x86_op_t;

/* Linked list of x86_op_t; provided for manual traversal of the operand
 * list in an insn. Users wishing to add operands to this list, e.g. to add
 * implicit operands, should use x86_operand_new in x86_operand_list.h */
typedef struct x86_operand_list {
	x86_op_t op;
	struct x86_operand_list *next;
} x86_oplist_t;

enum x86_insn_group {
	insn_none = 0,		/* invalid instruction */
        insn_controlflow = 1,
        insn_arithmetic = 2,
        insn_logic = 3,
        insn_stack = 4,
        insn_comparison = 5,
        insn_move = 6,
        insn_string = 7,
        insn_bit_manip = 8,
        insn_flag_manip = 9,
        insn_fpu = 10,
        insn_interrupt = 13,
        insn_system = 14,
        insn_other = 15
};

enum x86_insn_type {
	insn_invalid = 0,	/* invalid instruction */
        /* insn_controlflow */
        insn_jmp = 0x1001,
        insn_jcc = 0x1002,
        insn_call = 0x1003,
        insn_callcc = 0x1004,
        insn_return = 0x1005,
        /* insn_arithmetic */
        insn_add = 0x2001,
        insn_sub = 0x2002,
        insn_mul = 0x2003,
        insn_div = 0x2004,
        insn_inc = 0x2005,
        insn_dec = 0x2006,
        insn_shl = 0x2007,
        insn_shr = 0x2008,
        insn_rol = 0x2009,
        insn_ror = 0x200A,
        /* insn_logic */
        insn_and = 0x3001,
        insn_or = 0x3002,
        insn_xor = 0x3003,
        insn_not = 0x3004,
        insn_neg = 0x3005,
        /* insn_stack */
        insn_push = 0x4001,
        insn_pop = 0x4002,
        insn_pushregs = 0x4003,
        insn_popregs = 0x4004,
        insn_pushflags = 0x4005,
        insn_popflags = 0x4006,
        insn_enter = 0x4007,
        insn_leave = 0x4008,
        /* insn_comparison */
        insn_test = 0x5001,
        insn_cmp = 0x5002,
        /* insn_move */
        insn_mov = 0x6001,      /* move */
        insn_movcc = 0x6002,    /* conditional move */
        insn_xchg = 0x6003,     /* exchange */
        insn_xchgcc = 0x6004,   /* conditional exchange */
        /* insn_string */
        insn_strcmp = 0x7001,
        insn_strload = 0x7002,
        insn_strmov = 0x7003,
        insn_strstore = 0x7004,
        insn_translate = 0x7005,        /* xlat */
        /* insn_bit_manip */
        insn_bittest = 0x8001,
        insn_bitset = 0x8002,
        insn_bitclear = 0x8003,
        /* insn_flag_manip */
        insn_clear_carry = 0x9001,
        insn_clear_zero = 0x9002,
        insn_clear_oflow = 0x9003,
        insn_clear_dir = 0x9004,
        insn_clear_sign = 0x9005,
        insn_clear_parity = 0x9006,
        insn_set_carry = 0x9007,
        insn_set_zero = 0x9008,
        insn_set_oflow = 0x9009,
        insn_set_dir = 0x900A,
        insn_set_sign = 0x900B,
        insn_set_parity = 0x900C,
        insn_tog_carry = 0x9010,
        insn_tog_zero = 0x9020,
        insn_tog_oflow = 0x9030,
        insn_tog_dir = 0x9040,
        insn_tog_sign = 0x9050,
        insn_tog_parity = 0x9060,
        /* insn_fpu */
        insn_fmov = 0xA001,
        insn_fmovcc = 0xA002,
        insn_fneg = 0xA003,
        insn_fabs = 0xA004,
        insn_fadd = 0xA005,
        insn_fsub = 0xA006,
        insn_fmul = 0xA007,
        insn_fdiv = 0xA008,
        insn_fsqrt = 0xA009,
        insn_fcmp = 0xA00A,
        insn_fcos = 0xA00C,
        insn_fldpi = 0xA00D,
        insn_fldz = 0xA00E,
        insn_ftan = 0xA00F,
        insn_fsine = 0xA010,
        insn_fsys = 0xA020,
        /* insn_interrupt */
        insn_int = 0xD001,
        insn_intcc = 0xD002,    /* not present in x86 ISA */
        insn_iret = 0xD003,
        insn_bound = 0xD004,
        insn_debug = 0xD005,
        insn_trace = 0xD006,
        insn_invalid_op = 0xD007,
        insn_oflow = 0xD008,
        /* insn_system */
        insn_halt = 0xE001,
        insn_in = 0xE002,       /* input from port/bus */
        insn_out = 0xE003,      /* output to port/bus */
        insn_cpuid = 0xE004,
        /* insn_other */
        insn_nop = 0xF001,
        insn_bcdconv = 0xF002,  /* convert to or from BCD */
        insn_szconv = 0xF003    /* change size of operand */
};

/* These flags specify special characteristics of the instruction, such as
 * whether the inatruction is privileged or whether it serializes the
 * pipeline.
 * NOTE : These may not be accurate for all instructions; updates to the
 * opcode tables have not been completed. */
enum x86_insn_note {
	insn_note_ring0		= 1,	/* Only available in ring 0 */
	insn_note_smm		= 2,	/* "" in System Management Mode */
	insn_note_serial	= 4,	/* Serializing instruction */
	insn_note_nonswap	= 8,	/* Does not swap arguments in att-style formatting */
	insn_note_nosuffix  = 16,	/* Does not have size suffix in att-style formatting */
};

/* This specifies what effects the instruction has on the %eflags register */
enum x86_flag_status {
        insn_carry_set = 0x1,			/* CF */
        insn_zero_set = 0x2,			/* ZF */
        insn_oflow_set = 0x4,			/* OF */
        insn_dir_set = 0x8,			/* DF */
        insn_sign_set = 0x10,			/* SF */
        insn_parity_set = 0x20,			/* PF */
        insn_carry_or_zero_set = 0x40,
        insn_zero_set_or_sign_ne_oflow = 0x80,
        insn_carry_clear = 0x100,
        insn_zero_clear = 0x200,
        insn_oflow_clear = 0x400,
        insn_dir_clear = 0x800,
        insn_sign_clear = 0x1000,
        insn_parity_clear = 0x2000,
        insn_sign_eq_oflow = 0x4000,
        insn_sign_ne_oflow = 0x8000
};

/* The CPU model in which the insturction first appeared; this can be used
 * to mask out instructions appearing in earlier or later models or to
 * check the portability of a binary.
 * NOTE : These may not be accurate for all instructions; updates to the
 * opcode tables have not been completed. */
enum x86_insn_cpu {
	cpu_8086 	= 1,	/* Intel */
	cpu_80286	= 2,
	cpu_80386	= 3,
	cpu_80387	= 4,
	cpu_80486	= 5,
	cpu_pentium	= 6,
	cpu_pentiumpro	= 7,
	cpu_pentium2	= 8,
	cpu_pentium3	= 9,
	cpu_pentium4	= 10,
	cpu_k6		= 16,	/* AMD */
	cpu_k7		= 32,
	cpu_athlon	= 48
};

/* CPU ISA subsets: These are derived from the Instruction Groups in
 * Intel Vol 1 Chapter 5; they represent subsets of the IA32 ISA but
 * do not reflect the 'type' of the instruction in the same way that
 * x86_insn_group does. In short, these are AMD/Intel's somewhat useless
 * designations.
 * NOTE : These may not be accurate for all instructions; updates to the
 * opcode tables have not been completed. */
enum x86_insn_isa {
	isa_gp		= 1,	/* general purpose */
	isa_fp		= 2,	/* floating point */
	isa_fpumgt	= 3,	/* FPU/SIMD management */
	isa_mmx		= 4,	/* Intel MMX */
	isa_sse1	= 5,	/* Intel SSE SIMD */
	isa_sse2	= 6,	/* Intel SSE2 SIMD */
	isa_sse3	= 7,	/* Intel SSE3 SIMD */
	isa_3dnow	= 8,	/* AMD 3DNow! SIMD */
	isa_sys		= 9	/* system instructions */
};

enum x86_insn_prefix {
        insn_no_prefix = 0,
        insn_rep_zero = 1,	/* REPZ and REPE */
        insn_rep_notzero = 2,	/* REPNZ and REPNZ */
        insn_lock = 4		/* LOCK: */
};

/* TODO: maybe provide insn_new/free(), and have disasm return new insn_t */
/* x86_insn_t : an X86 instruction */
typedef struct {
        /* information about the instruction */
        uint32_t addr;             /* load address */
        uint32_t offset;           /* offset into file/buffer */
        enum x86_insn_group group;      /* meta-type, e.g. INS_EXEC */
        enum x86_insn_type type;        /* type, e.g. INS_BRANCH */
	enum x86_insn_note note;	/* note, e.g. RING0 */
        unsigned char bytes[MAX_INSN_SIZE];
        unsigned char size;             /* size of insn in bytes */
	/* 16/32-bit mode settings */
	unsigned char addr_size;	/* default address size : 2 or 4 */
	unsigned char op_size;		/* default operand size : 2 or 4 */
	/* CPU/instruction set */
	enum x86_insn_cpu cpu;
	enum x86_insn_isa isa;
	/* flags */
        enum x86_flag_status flags_set; /* flags set or tested by insn */
        enum x86_flag_status flags_tested;
	/* stack */
	unsigned char stack_mod;	/* 0 or 1 : is the stack modified? */
	int32_t stack_mod_val;		/* val stack is modified by if known */

        /* the instruction proper */
        enum x86_insn_prefix prefix;	/* prefixes ORed together */
        char prefix_string[MAX_PREFIX_STR]; /* prefixes [might be truncated] */
        char mnemonic[MAX_MNEM_STR];
        x86_oplist_t *operands;		/* list of explicit/implicit operands */
	size_t operand_count;		/* total number of operands */
	size_t explicit_count;		/* number of explicit operands */
        /* convenience fields for user */
        void *block;                    /* code block containing this insn */
        void *function;                 /* function containing this insn */
        int tag;			/* tag the insn as seen/processed */
} x86_insn_t;

/* returns 0 if an instruction is invalid, 1 if valid */
int x86_insn_is_valid( x86_insn_t *insn );

/* DISASSEMBLY ROUTINES
 *      Canonical order of arguments is
 *        (buf, buf_len, buf_rva, offset, len, insn, func, arg, resolve_func)
 *      ...but of course all of these are not used at the same time.
 */

/* Function prototype for caller-supplied callback routine
 *      These callbacks are intended to process 'insn' further, e.g. by
 *      adding it to a linked list, database, etc */
typedef void (*DISASM_CALLBACK)( x86_insn_t *insn, void * arg );

/* Function prototype for caller-supplied address resolver.
 *      This routine is used to determine the rva to disassemble next, given
 *      the 'dest' operand of a jump/call. This allows the caller to resolve
 *      jump/call targets stored in a register or on the stack, and also allows
 *      the caller to prevent endless loops by checking if an address has
 *      already been disassembled. If an address cannot be resolved from the
 *      operand, or if the address has already been disassembled, this routine
 *      should return -1; in all other cases the RVA to be disassembled next
 *      should be returned. */
typedef int32_t (*DISASM_RESOLVER)( x86_op_t *op, x86_insn_t * current_insn,
				 void *arg );

/* x86_disasm: Disassemble a single instruction from a buffer of bytes.
 *             Returns size of instruction in bytes.
 *             Caller is responsible for calling x86_oplist_free() on
 *             a reused "insn" to avoid leaking memory when calling this
 *             function repeatedly.
 *      buf     : Buffer of bytes to disassemble
 *      buf_len : Length of the buffer
 *      buf_rva : Load address of the start of the buffer
 *      offset  : Offset in buffer to disassemble
 *      insn    : Structure to fill with disassembled instruction
 */
unsigned int x86_disasm( unsigned char *buf, unsigned int buf_len,
                	 uint32_t buf_rva, unsigned int offset,
                	 x86_insn_t * insn );

/* x86_disasm_range: Sequential disassembly of a range of bytes in a buffer,
 *                   invoking a callback function each time an instruction
 *                   is successfully disassembled. The 'range' refers to the
 *                   bytes between 'offset' and 'offset + len' in the buffer;
 *                   'len' is assumed to be less than the length of the buffer.
 *                   Returns number of instructions processed.
 *      buf     : Buffer of bytes to disassemble (e.g. .text section)
 *      buf_rva : Load address of buffer (e.g. ELF Virtual Address)
 *      offset  : Offset in buffer to start disassembly at
 *      len     : Number of bytes to disassemble
 *      func    : Callback function to invoke (may be NULL)
 *      arg     : Arbitrary data to pass to callback (may be NULL)
 */
unsigned int x86_disasm_range( unsigned char *buf, uint32_t buf_rva,
	                       unsigned int offset, unsigned int len,
	                       DISASM_CALLBACK func, void *arg );

/* x86_disasm_forward: Flow-of-execution disassembly of the bytes in a buffer,
 *                     invoking a callback function each time an instruction
 *                     is successfully disassembled.
 *      buf     : Buffer to disassemble (e.g. .text section)
 *      buf_len : Number of bytes in buffer
 *      buf_rva : Load address of buffer (e.g. ELF Virtual Address)
 *      offset  : Offset in buffer to start disassembly at (e.g. entry point)
 *      func    : Callback function to invoke (may be NULL)
 *      arg     : Arbitrary data to pass to callback (may be NULL)
 *      resolver: Caller-supplied address resolver. If no resolver is
 *                supplied, a default internal one is used -- however the
 *                internal resolver does NOT catch loops and could end up
 *                disassembling forever..
 *      r_arg	: Arbitrary data to pass to resolver (may be NULL)
 */
unsigned int x86_disasm_forward( unsigned char *buf, unsigned int buf_len,
	                         uint32_t buf_rva, unsigned int offset,
	                         DISASM_CALLBACK func, void *arg,
	                         DISASM_RESOLVER resolver, void *r_arg );

/* Instruction operands: these are stored as a list of explicit and
 * implicit operands. It is recommended that the 'foreach' routines
 * be used to when examining operands for purposes of data flow analysis */

/* Operand FOREACH callback: 'arg' is an abritrary parameter passed to the
 * foreach routine, 'insn' is the x86_insn_t whose operands are being
 * iterated over, and 'op' is the current x86_op_t */
typedef void (*x86_operand_fn)(x86_op_t *op, x86_insn_t *insn, void *arg);

/* FOREACH types: these are used to limit the foreach results to
 * operands which match a certain "type" (implicit or explicit)
 * or which are accessed in certain ways (e.g. read or write). Note
 * that this operates on the operand list of single instruction, so
 * specifying the 'real' operand type (register, memory, etc) is not
 * useful. Note also that by definition Execute Access implies Read
 * Access and implies Not Write Access.
 * The "type" (implicit or explicit) and the access method can
 * be ORed together, e.g. op_wo | op_explicit */
enum x86_op_foreach_type {
	op_any 	= 0,		/* ALL operands (explicit, implicit, rwx) */
	op_dest = 1,		/* operands with Write access */
	op_src 	= 2,		/* operands with Read access */
	op_ro 	= 3,		/* operands with Read but not Write access */
	op_wo 	= 4,		/* operands with Write but not Read access */
	op_xo 	= 5,		/* operands with Execute access */
	op_rw 	= 6,		/* operands with Read AND Write access */
	op_implicit = 0x10,	/* operands that are implied by the opcode */
	op_explicit = 0x20	/* operands that are not side-effects */
};

/* free the operand list associated with an instruction -- useful for
 * preventing memory leaks when free()ing an x86_insn_t */
void x86_oplist_free( x86_insn_t *insn );

/* Operand foreach: invokes 'func' with 'insn' and 'arg' as arguments. The
 * 'type' parameter is used to select only operands matching specific
 * criteria. */
int x86_operand_foreach( x86_insn_t *insn, x86_operand_fn func, void *arg,
	       	  	 enum x86_op_foreach_type type);

/* convenience routine: returns count of operands matching 'type' */
size_t x86_operand_count( x86_insn_t *insn, enum x86_op_foreach_type type );

/* accessor functions for the operands */
x86_op_t * x86_operand_1st( x86_insn_t *insn );
x86_op_t * x86_operand_2nd( x86_insn_t *insn );
x86_op_t * x86_operand_3rd( x86_insn_t *insn );

/* these allow libdisasm 2.0 accessor functions to still be used */
#define x86_get_dest_operand( insn ) x86_operand_1st( insn )
#define x86_get_src_operand( insn ) x86_operand_2nd( insn )
#define x86_get_imm_operand( insn ) x86_operand_3rd( insn )

/* get size of operand data in bytes */
unsigned int x86_operand_size( x86_op_t *op );

/* Operand Convenience Routines: the following three routines are common
 * operations on operands, intended to ease the burden of the programmer. */

/* Get Address: return the value of an offset operand, or the offset of
 * a segment:offset absolute address */
uint32_t x86_get_address( x86_insn_t *insn );

/* Get Relative Offset: return as a sign-extended int32_t the near or far
 * relative offset operand, or 0 if there is none. There can be only one
 * relaive offset operand in an instruction. */
int32_t x86_get_rel_offset( x86_insn_t *insn );

/* Get Branch Target: return the x86_op_t containing the target of
 * a jump or call operand, or NULL if there is no branch target.
 * Internally, a 'branch target' is defined as any operand with
 * Execute Access set. There can be only one branch target per instruction. */
x86_op_t * x86_get_branch_target( x86_insn_t *insn );

/* Get Immediate: return the x86_op_t containing the immediate operand
 * for this instruction, or NULL if there is no immediate operand. There
 * can be only one immediate operand per instruction */
x86_op_t * x86_get_imm( x86_insn_t *insn );

/* Get Raw Immediate Data: returns a pointer to the immediate data encoded
 * in the instruction. This is useful for large data types [>32 bits] currently
 * not supported by libdisasm, or for determining if the disassembler
 * screwed up the conversion of the immediate data. Note that 'imm' in this
 * context refers to immediate data encoded at the end of an instruction as
 * detailed in the Intel Manual Vol II Chapter 2; it does not refer to the
 * 'op_imm' operand (the third operand in instructions like 'mul' */
unsigned char * x86_get_raw_imm( x86_insn_t *insn );

/* More accessor fuctions, this time for user-defined info... */
/* set the address (usually RVA) of the insn */
void x86_set_insn_addr( x86_insn_t *insn, uint32_t addr );

/* set the offset (usually offset into file) of the insn */
void x86_set_insn_offset( x86_insn_t *insn, unsigned int offset );

/* set a pointer to the function owning the instruction. The
 * type of 'func' is user-defined; libdisasm does not use the func field. */
void x86_set_insn_function( x86_insn_t *insn, void * func );

/* set a pointer to the block of code owning the instruction. The
 * type of 'block' is user-defined; libdisasm does not use the block field. */
void x86_set_insn_block( x86_insn_t *insn, void * block );

/* instruction tagging: these routines allow the programmer to mark
 * instructions as "seen" in a DFS, for example. libdisasm does not use
 * the tag field.*/
/* set insn->tag to 1 */
void x86_tag_insn( x86_insn_t *insn );
/* set insn->tag to 0 */
void x86_untag_insn( x86_insn_t *insn );
/* return insn->tag */
int x86_insn_is_tagged( x86_insn_t *insn );

/* Disassembly formats:
 *      AT&T is standard AS/GAS-style: "mnemonic\tsrc, dest, imm"
 *      Intel is standard MASM/NASM/TASM: "mnemonic\tdest,src, imm"
 *      Native is tab-delimited: "RVA\tbytes\tmnemonic\tdest\tsrc\timm"
 *      XML is your typical <insn> ... </insn>
 *      Raw is addr|offset|size|bytes|prefix... see libdisasm_formats.7
 */
enum x86_asm_format {
	unknown_syntax = 0,		/* never use! */
	native_syntax, 			/* header: 35 bytes */
	intel_syntax, 			/* header: 23 bytes */
	att_syntax,  			/* header: 23 bytes */
	xml_syntax,			/* header: 679 bytes */
	raw_syntax			/* header: 172 bytes */
};

/* format (sprintf) an operand into 'buf' using specified syntax */
int x86_format_operand(x86_op_t *op, char *buf, int len,
                  enum x86_asm_format format);

/* format (sprintf) an instruction mnemonic into 'buf' using specified syntax */
int x86_format_mnemonic(x86_insn_t *insn, char *buf, int len,
                        enum x86_asm_format format);

/* format (sprintf) an instruction into 'buf' using specified syntax;
 * this includes formatting all operands */
int x86_format_insn(x86_insn_t *insn, char *buf, int len, enum x86_asm_format);

/* fill 'buf' with a description of the format's syntax */
int x86_format_header( char *buf, int len, enum x86_asm_format format);

/* Endianness of an x86 CPU : 0 is big, 1 is little; always returns 1 */
unsigned int x86_endian(void);

/* Default address and operand size in bytes */
unsigned int x86_addr_size(void);
unsigned int x86_op_size(void);

/* Size of a machine word in bytes */
unsigned int x86_word_size(void);

/* maximum size of a code instruction */
#define x86_max_inst_size(x) x86_max_insn_size(x)
unsigned int x86_max_insn_size(void);

/* register IDs of Stack, Frame, Instruction pointer and Flags register */
unsigned int x86_sp_reg(void);
unsigned int x86_fp_reg(void);
unsigned int x86_ip_reg(void);
unsigned int x86_flag_reg(void);

/* fill 'reg' struct with details of register 'id' */
void x86_reg_from_id( unsigned int id, x86_reg_t * reg );

/* convenience macro demonstrating how to get an aliased register; proto is
 *   void x86_get_aliased_reg( x86_reg_t *alias_reg, x86_reg_t *output_reg )
 * where 'alias_reg' is a reg operand and 'output_reg' is filled with the
 * register that the operand is an alias for */
#define x86_get_aliased_reg( alias_reg, output_reg )			\
	x86_reg_from_id( alias_reg->alias, output_reg )

/* ================================== Invariant Instruction Representation */
/* Invariant instructions are used for generating binary signatures;
 * the instruction is modified so that all variant bytes in an instruction
 * are replaced with a wildcard byte.
 *
 * A 'variant byte' is one that is expected to be modified by either the
 * static or the dynamic linker: for example, an address encoded in an
 * instruction.
 *
 * By comparing the invariant representation of one instruction [or of a
 * sequence of instructions] with the invariant representation of another,
 * one determine whether the two invariant representations are from the same
 * relocatable object [.o] file. Thus one can use binary signatures [which
 * are just sequences of invariant instruction representations] to look for
 * library routines which have been statically-linked into a binary.
 *
 * The invariant routines are faster and smaller than the disassembly
 * routines; they can be used to determine the size of an instruction
 * without all of the overhead of a full instruction disassembly.
 */

/* This byte is used to replace variant bytes */
#define X86_WILDCARD_BYTE 0xF4

typedef struct {
        enum x86_op_type        type;           /* operand type */
        enum x86_op_datatype    datatype;       /* operand size */
        enum x86_op_access      access;         /* operand access [RWX] */
        enum x86_op_flags       flags;          /* misc flags */
} x86_invariant_op_t;

typedef struct {
	unsigned char bytes[64];	/* invariant representation */
	unsigned int  size;		/* number of bytes in insn */
        enum x86_insn_group group;      /* meta-type, e.g. INS_EXEC */
        enum x86_insn_type type;        /* type, e.g. INS_BRANCH */
	x86_invariant_op_t operands[3];	/* operands: dest, src, imm */
} x86_invariant_t;

/* return a version of the instruction with the variant bytes masked out */
size_t x86_invariant_disasm( unsigned char *buf, int buf_len,
			  x86_invariant_t *inv );
/* return the size in bytes of the intruction pointed to by 'buf';
 * this used x86_invariant_disasm since it faster than x86_disasm */
size_t x86_size_disasm( unsigned char *buf, unsigned int buf_len );

/* added by Alex Reimann Cunha Lima */
void x86_reloc_reset(void);
void x86_reloc_send(unsigned int x, const char *name);
int x86_reloc_check(void);

#ifdef __cplusplus
}
#endif

#endif


text:
This example shows using data from redux state to be used in queries. A good example of this is querying based on the current user's UID.

## Auth Wrapping
By wrapping component in connect function, you bring `auth` from redux state into a prop name "auth":

```js
const authWrappedComponent = connect(
  ({ firebase }) => ({
    auth: pathToJS(firebase, 'auth')
  })
)(App)
```