def Func(arg_0, arg_1, arg_2):
        """
        Adds with carry.

        Adds the destination operand (first operand), the source operand (second operand),
        and the carry (CF) flag and stores the result in the destination operand. The state
        of the CF flag represents a carry from a previous addition. When an immediate value
        is used as an operand, it is sign-extended to the length of the destination operand
        format. The Func instruction does not distinguish between signed or unsigned operands.
        Instead, the processor evaluates the result for both data types and sets the OF and CF
        flags to indicate a carry in the signed or unsigned result, respectively. The SF flag
        indicates the sign of the signed result. The Func instruction is usually executed as
        part of a multibyte or multiword addition in which an ADD instruction is followed by an
        Func instruction::

                DEST  =  DEST + SRC + CF;

        The OF, SF, ZF, AF, CF, and PF flags are set according to the result.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_0._ADD(arg_1, arg_2, carry=True)


def Func(arg_0, arg_1):
        """
        Compares and exchanges bytes.

        Compares the 64-bit value in EDX:EAX (or 128-bit value in RDX:RAX if
        operand size is 128 bits) with the operand (destination operand). If
        the values are equal, the 64-bit value in ECX:EBX (or 128-bit value in
        RCX:RBX) is stored in the destination operand.  Otherwise, the value in
        the destination operand is loaded into EDX:EAX (or RDX:RAX)::

                IF (64-Bit Mode and OperandSize = 64)
                THEN
                    IF (RDX:RAX = DEST)
                    THEN
                        ZF = 1;
                        DEST = RCX:RBX;
                    ELSE
                        ZF = 0;
                        RDX:RAX = DEST;
                    FI
                ELSE
                    IF (EDX:EAX = DEST)
                    THEN
                        ZF = 1;
                        DEST = ECX:EBX;
                    ELSE
                        ZF = 0;
                        EDX:EAX = DEST;
                    FI;
                FI;

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_2 = arg_1.size
        arg_3 = {64: 'EAX', 128: 'RAX'}[arg_2]
        arg_4 = {64: 'EDX', 128: 'RDX'}[arg_2]
        arg_5 = {64: 'EBX', 128: 'RBX'}[arg_2]
        arg_6 = {64: 'ECX', 128: 'RCX'}[arg_2]

        # EDX:EAX or RDX:RAX
        arg_7 = arg_0.read_register(arg_4)
        arg_8 = arg_0.read_register(arg_3)

        arg_9 = arg_0.read_register(arg_6)
        arg_10 = arg_0.read_register(arg_5)

        arg_11 = Operators.CONCAT(arg_2, arg_7, arg_8)
        arg_12 = Operators.CONCAT(arg_2, arg_9, arg_10)
        arg_13 = arg_1.read()
        arg_0.ZF = arg_13 == arg_11

        arg_1.write(
            Operators.ITEBV(arg_2, arg_0.ZF,
                            Operators.CONCAT(arg_2, arg_9, arg_10),
                            arg_13)
        )
        arg_0.write_register(arg_3, Operators.ITEBV(arg_2 // 2, arg_0.ZF, arg_8,
                                                           Operators.EXTRACT(arg_13, 0, arg_2 // 2)))
        arg_0.write_register(arg_4, Operators.ITEBV(arg_2 // 2, arg_0.ZF, arg_7,
                                                           Operators.EXTRACT(arg_13, arg_2 // 2, arg_2 // 2)))


def Func(arg_0):
        """
        Decimal adjusts AL after addition.

        Adjusts the sum of two packed BCD values to create a packed BCD result. The AL register
        is the implied source and destination operand. If a decimal carry is detected, the CF
        and AF flags are set accordingly.
        The CF and AF flags are set if the adjustment of the value results in a decimal carry in
        either digit of the result. The SF, ZF, and PF flags are set according to the result.

        This instruction is not valid in 64-bit mode.::

                IF (((AL AND 0FH) > 9) or AF  =  1)
                THEN
                    AL  =  AL + 6;
                    CF  =  CF OR CarryFromLastAddition; (* CF OR carry from AL  =  AL + 6 *)
                    AF  =  1;
                ELSE
                    AF  =  0;
                FI;
                IF ((AL AND F0H) > 90H) or CF  =  1)
                THEN
                    AL  =  AL + 60H;
                    CF  =  1;
                ELSE
                    CF  =  0;
                FI;

        :param cpu: current CPU.
        """

        arg_0.AF = Operators.OR((arg_0.AL & 0x0f) > 9, arg_0.AF)
        arg_2 = arg_0.AL
        arg_0.AL = Operators.ITEBV(8, arg_0.AF, arg_0.AL + 6, arg_0.AL)
        arg_0.CF = Operators.ITE(arg_0.AF, Operators.OR(arg_0.CF, arg_0.AL < arg_2), arg_0.CF)

        arg_0.CF = Operators.OR((arg_0.AL & 0xf0) > 0x90, arg_0.CF)
        arg_0.AL = Operators.ITEBV(8, arg_0.CF, arg_0.AL + 0x60, arg_0.AL)
        """
        #old not-symbolic aware version...
        if ((cpu.AL & 0x0f) > 9) or cpu.AF:
            oldAL = cpu.AL
            cpu.AL =  cpu.AL + 6
            cpu.CF = Operators.OR(cpu.CF, cpu.AL < oldAL)
            cpu.AF  =  True
        else:
            cpu.AF  =  False

        if ((cpu.AL & 0xf0) > 0x90) or cpu.CF:
            cpu.AL  = cpu.AL + 0x60
            cpu.CF  =  True
        else:
            cpu.CF  =  False
        """

        arg_0.ZF = arg_0.AL == 0
        arg_0.SF = (arg_0.AL & 0x80) != 0
        arg_0.PF = arg_0._calculate_parity_flag(arg_0.AL)


def Func(arg_0, arg_1):
        """
        Signed divide.

        Divides (signed) the value in the AL, AX, or EAX register by the source
        operand and stores the result in the AX, DX:AX, or EDX:EAX registers.
        The source operand can be a general-purpose register or a memory
        location. The action of this instruction depends on the operand size.::

        IF SRC  =  0
        THEN #DE; (* divide error *)
        FI;
        IF OpernadSize  =  8 (* word/byte operation *)
        THEN
            temp  =  AX / SRC; (* signed division *)
            IF (temp > 7FH) Operators.OR(temp < 80H)
            (* if a positive result is greater than 7FH or a negative result is
            less than 80H *)
            THEN #DE; (* divide error *) ;
            ELSE
                AL  =  temp;
                AH  =  AX SignedModulus SRC;
            FI;
        ELSE
            IF OpernadSize  =  16 (* doubleword/word operation *)
            THEN
                temp  =  DX:AX / SRC; (* signed division *)
                IF (temp > 7FFFH) Operators.OR(temp < 8000H)
                (* if a positive result is greater than 7FFFH *)
                (* or a negative result is less than 8000H *)
                THEN #DE; (* divide error *) ;
                ELSE
                    AX  =  temp;
                    DX  =  DX:AX SignedModulus SRC;
                FI;
            ELSE (* quadword/doubleword operation *)
                temp  =  EDX:EAX / SRC; (* signed division *)
                IF (temp > 7FFFFFFFH) Operators.OR(temp < 80000000H)
                (* if a positive result is greater than 7FFFFFFFH *)
                (* or a negative result is less than 80000000H *)
                THEN #DE; (* divide error *) ;
                ELSE
                    EAX  =  temp;
                    EDX  =  EDX:EAX SignedModulus SRC;
                FI;
            FI;
        FI;

        :param cpu: current CPU.
        :param src: source operand.
        """

        arg_2 = {8: 'AH', 16: 'DX', 32: 'EDX', 64: 'RDX'}[arg_1.size]
        arg_3 = {8: 'AL', 16: 'AX', 32: 'EAX', 64: 'RAX'}[arg_1.size]

        arg_4 = Operators.CONCAT(arg_1.size * 2,
                                    arg_0.read_register(arg_2),
                                    arg_0.read_register(arg_3))

        arg_5 = arg_1.read()
        if isinstance(arg_5, int) and arg_5 == 0:
            raise DivideByZeroError()

        arg_6 = arg_1.size * 2

        arg_5 = Operators.SEXTEND(arg_5, arg_1.size, arg_6)
        arg_7 = (1 << arg_6) - 1
        arg_8 = 1 << (arg_6 - 1)

        arg_9 = (arg_4 & arg_8) != 0
        arg_10 = (arg_5 & arg_8) != 0

        if isinstance(arg_5, int):
            if arg_10:
                arg_5 = ((~arg_5) + 1) & arg_7
                arg_5 = -arg_5

        if isinstance(arg_4, int):
            if arg_9:
                arg_4 = ((~arg_4) + 1) & arg_7
                arg_4 = -arg_4

        arg_11 = Operators.SDIV(arg_4, arg_5)
        if (isinstance(arg_4, int) and
                isinstance(arg_4, int)):
            # handle the concrete case
            arg_12 = arg_4 - (arg_11 * arg_5)
        else:
            # symbolic case -- optimize via SREM
            arg_12 = Operators.SREM(arg_4, arg_5)

        arg_0.write_register(arg_3, Operators.EXTRACT(arg_11, 0, arg_1.size))
        arg_0.write_register(arg_2, Operators.EXTRACT(arg_12, 0, arg_1.size))


def Func(arg_0, *arg_1):
        """
        Signed multiply.

        Performs a signed multiplication of two operands. This instruction has
        three forms, depending on the number of operands.
            - One-operand form. This form is identical to that used by the MUL
            instruction. Here, the source operand (in a general-purpose
            register or memory location) is multiplied by the value in the AL,
            AX, or EAX register (depending on the operand size) and the product
            is stored in the AX, DX:AX, or EDX:EAX registers, respectively.
            - Two-operand form. With this form the destination operand (the
            first operand) is multiplied by the source operand (second
            operand). The destination operand is a general-purpose register and
            the source operand is an immediate value, a general-purpose
            register, or a memory location. The product is then stored in the
            destination operand location.
            - Three-operand form. This form requires a destination operand (the
            first operand) and two source operands (the second and the third
            operands). Here, the first source operand (which can be a
            general-purpose register or a memory location) is multiplied by the
            second source operand (an immediate value). The product is then
            stored in the destination operand (a general-purpose register).

        When an immediate value is used as an operand, it is sign-extended to
        the length of the destination operand format. The CF and OF flags are
        set when significant bits are carried into the upper half of the
        result. The CF and OF flags are cleared when the result fits exactly in
        the lower half of the result. The three forms of the Func instruction
        are similar in that the length of the product is calculated to twice
        the length of the operands. With the one-operand form, the product is
        stored exactly in the destination. With the two- and three- operand
        forms, however, result is truncated to the length of the destination
        before it is stored in the destination register. Because of this
        truncation, the CF or OF flag should be tested to ensure that no
        significant bits are lost. The two- and three-operand forms may also be
        used with unsigned operands because the lower half of the product is
        the same regardless if the operands are signed or unsigned. The CF and
        OF flags, however, cannot be used to determine if the upper half of the
        result is non-zero::

        IF (NumberOfOperands == 1)
        THEN
            IF (OperandSize == 8)
            THEN
                AX = AL * SRC (* Signed multiplication *)
                IF AL == AX
                THEN
                    CF = 0; OF = 0;
                ELSE
                    CF = 1; OF = 1;
                FI;
            ELSE
                IF OperandSize == 16
                THEN
                    DX:AX = AX * SRC (* Signed multiplication *)
                    IF sign_extend_to_32 (AX) == DX:AX
                    THEN
                        CF = 0; OF = 0;
                    ELSE
                        CF = 1; OF = 1;
                    FI;
                ELSE
                    IF OperandSize == 32
                    THEN
                        EDX:EAX = EAX * SRC (* Signed multiplication *)
                        IF EAX == EDX:EAX
                        THEN
                            CF = 0; OF = 0;
                        ELSE
                            CF = 1; OF = 1;
                        FI;
                    ELSE (* OperandSize = 64 *)
                        RDX:RAX = RAX * SRC (* Signed multiplication *)
                        IF RAX == RDX:RAX
                        THEN
                            CF = 0; OF = 0;
                        ELSE
                           CF = 1; OF = 1;
                        FI;
                    FI;
                FI;
        ELSE
            IF (NumberOfOperands = 2)
            THEN
                temp = DEST * SRC (* Signed multiplication; temp is double DEST size *)
                DEST = DEST * SRC (* Signed multiplication *)
                IF temp != DEST
                THEN
                    CF = 1; OF = 1;
                ELSE
                    CF = 0; OF = 0;
                FI;
            ELSE (* NumberOfOperands = 3 *)
                DEST = SRC1 * SRC2 (* Signed multiplication *)
                temp = SRC1 * SRC2 (* Signed multiplication; temp is double SRC1 size *)
                IF temp != DEST
                THEN
                    CF = 1; OF = 1;
                ELSE
                    CF = 0; OF = 0;
                FI;
            FI;
        FI;

        :param cpu: current CPU.
        :param operands: variable list of operands.
        """
        arg_2 = arg_1[0]
        arg_3 = arg_2.size
        arg_4 = {8: 'AH', 16: 'DX', 32: 'EDX', 64: 'RDX'}[arg_3]
        arg_5 = {8: 'AL', 16: 'AX', 32: 'EAX', 64: 'RAX'}[arg_3]

        arg_6 = arg_2.read()
        arg_7 = None
        arg_8 = None
        arg_9 = None
        if len(arg_1) == 1:
            arg_7 = arg_0.read_register(arg_5)
            arg_10 = (Operators.SEXTEND(arg_6, arg_3, arg_3 * 2) *
                    Operators.SEXTEND(arg_7, arg_3, arg_3 * 2))
            arg_10 = arg_10 & ((1 << (arg_3 * 2)) - 1)
            arg_0.write_register(arg_5,
                               Operators.EXTRACT(arg_10, 0, arg_3))
            arg_0.write_register(arg_4,
                               Operators.EXTRACT(arg_10, arg_3, arg_3))
            arg_9 = Operators.EXTRACT(arg_10, 0, arg_3)
        elif len(arg_1) == 2:
            arg_7 = arg_1[1].read()
            arg_7 = Operators.SEXTEND(arg_7, arg_3, arg_3 * 2)
            arg_10 = Operators.SEXTEND(arg_6, arg_3, arg_3 * 2) * arg_7
            arg_10 = arg_10 & ((1 << (arg_3 * 2)) - 1)
            arg_9 = arg_2.write(Operators.EXTRACT(arg_10, 0, arg_3))
        else:
            arg_7 = arg_1[1].read()
            arg_8 = arg_1[2].read()
            arg_10 = (Operators.SEXTEND(arg_7, arg_3, arg_3 * 2) *
                    Operators.SEXTEND(arg_8, arg_1[2].size, arg_3 * 2))
            arg_10 = arg_10 & ((1 << (arg_3 * 2)) - 1)
            arg_9 = arg_2.write(Operators.EXTRACT(arg_10, 0, arg_3))

        arg_0.CF = (Operators.SEXTEND(arg_9, arg_3, arg_3 * 2) != arg_10)
        arg_0.OF = arg_0.CF


def Func(arg_0, arg_1):
        """
        Unsigned multiply.

        Performs an unsigned multiplication of the first operand (destination
        operand) and the second operand (source operand) and stores the result
        in the destination operand. The destination operand is an implied operand
        located in register AL, AX or EAX (depending on the size of the operand);
        the source operand is located in a general-purpose register or a memory location.

        The result is stored in register AX, register pair DX:AX, or register
        pair EDX:EAX (depending on the operand size), with the high-order bits
        of the product contained in register AH, DX, or EDX, respectively. If
        the high-order bits of the product are 0, the CF and OF flags are cleared;
        otherwise, the flags are set::

                IF byte operation
                THEN
                    AX  =  AL * SRC
                ELSE (* word or doubleword operation *)
                    IF OperandSize  =  16
                    THEN
                        DX:AX  =  AX * SRC
                    ELSE (* OperandSize  =  32 *)
                        EDX:EAX  =  EAX * SRC
                    FI;
                FI;

        :param cpu: current CPU.
        :param src: source operand.
        """
        arg_2 = arg_1.size
        arg_3, arg_4 = {8: ('AL', 'AH'),
                                       16: ('AX', 'DX'),
                                       32: ('EAX', 'EDX'),
                                       64: ('RAX', 'RDX')}[arg_2]
        arg_5 = (Operators.ZEXTEND(arg_0.read_register(arg_3), 256) *
               Operators.ZEXTEND(arg_1.read(), 256))
        arg_0.write_register(arg_3, Operators.EXTRACT(arg_5, 0, arg_2))
        arg_0.write_register(arg_4, Operators.EXTRACT(arg_5, arg_2, arg_2))
        arg_0.OF = Operators.EXTRACT(arg_5, arg_2, arg_2) != 0
        arg_0.CF = arg_0.OF


def Func(arg_0, arg_1):
        """
        Two's complement negation.

        Replaces the value of operand (the destination operand) with its two's complement.
        (This operation is equivalent to subtracting the operand from 0.) The destination operand is
        located in a general-purpose register or a memory location::

                IF DEST  =  0
                THEN CF  =  0
                ELSE CF  =  1;
                FI;
                DEST  =  - (DEST)

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_2 = arg_1.read()
        arg_3 = arg_1.write(-arg_2)
        arg_0._calculate_logic_flags(arg_1.size, arg_3)
        arg_0.CF = arg_2 != 0
        arg_0.AF = (arg_3 & 0x0f) != 0x00


def Func(arg_0, arg_1, arg_2):
        """
        Integer subtraction with borrow.

        Adds the source operand (second operand) and the carry (CF) flag, and
        subtracts the result from the destination operand (first operand). The
        result of the subtraction is stored in the destination operand. The
        destination operand can be a register or a memory location; the source
        operand can be an immediate, a register, or a memory location.
        (However, two memory operands cannot be used in one instruction.) The
        state of the CF flag represents a borrow from a previous subtraction.
        When an immediate value is used as an operand, it is sign-extended to
        the length of the destination operand format.
        The Func instruction does not distinguish between signed or unsigned
        operands. Instead, the processor evaluates the result for both data
        types and sets the OF and CF flags to indicate a borrow in the signed
        or unsigned result, respectively. The SF flag indicates the sign of the
        signed result.  The Func instruction is usually executed as part of a
        multibyte or multiword subtraction in which a SUB instruction is
        followed by a Func instruction::

                DEST  =  DEST - (SRC + CF);

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_0._SUB(arg_1, arg_2, carry=True)


def Func(arg_0, arg_1, arg_2):
        """
        Exchanges and adds.

        Exchanges the first operand (destination operand) with the second operand
        (source operand), then loads the sum of the two values into the destination
        operand. The destination operand can be a register or a memory location;
        the source operand is a register.
        This instruction can be used with a LOCK prefix::

                TEMP  =  SRC + DEST
                SRC  =  DEST
                DEST  =  TEMP

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = (1 << arg_1.size) - 1
        arg_4 = 1 << (arg_1.size - 1)

        arg_5 = arg_1.read()
        arg_6 = arg_2.read()
        arg_7 = (arg_6 + arg_5) & arg_3
        arg_2.write(arg_5)
        arg_1.write(arg_7)

        # Affected flags: oszapc
        arg_8 = Operators.OR(Operators.ULT(arg_7, arg_5), Operators.ULT(arg_7, arg_6))
        arg_0.CF = arg_8
        arg_0.AF = ((arg_5 ^ arg_6) ^ arg_7) & 0x10 != 0
        arg_0.ZF = arg_7 == 0
        arg_0.SF = (arg_7 & arg_4) != 0
        arg_0.OF = (((arg_5 ^ arg_6 ^ arg_4) & (arg_7 ^ arg_6)) & arg_4) != 0
        arg_0.PF = arg_0._calculate_parity_flag(arg_7)


def Func(arg_0, arg_1):
        """
        Byte swap.

        Reverses the byte order of a 32-bit (destination) register: bits 0 through
        7 are swapped with bits 24 through 31, and bits 8 through 15 are swapped
        with bits 16 through 23. This instruction is provided for converting little-endian
        values to big-endian format and vice versa.
        To swap bytes in a word value (16-bit register), use the XCHG instruction.
        When the Func instruction references a 16-bit register, the result is
        undefined::

            TEMP  =  DEST
            DEST[7..0]  =  TEMP[31..24]
            DEST[15..8]  =  TEMP[23..16]
            DEST[23..16]  =  TEMP[15..8]
            DEST[31..24]  =  TEMP[7..0]

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_2 = []
        arg_3 = arg_1.read()
        for arg_4 in range(0, arg_1.size, 8):
            arg_2.append(Operators.EXTRACT(arg_3, arg_4, 8))

        arg_1.write(Operators.CONCAT(8 * len(arg_2), *arg_2))


def Func(arg_0, arg_1, arg_2):
        """
        Conditional move - Greater.

        Tests the status flags in the EFLAGS register and moves the source operand
        (second operand) to the destination operand (first operand) if the given
        test condition is true.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, Operators.AND(arg_0.ZF == 0, arg_0.SF == arg_0.OF), arg_2.read(), arg_1.read()))


def Func(arg_0, arg_1, arg_2):
        """
        Conditional move - Overflow.

        Tests the status flags in the EFLAGS register and moves the source operand
        (second operand) to the destination operand (first operand) if the given
        test condition is true.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.OF, arg_2.read(), arg_1.read()))


def Func(arg_0, arg_1, arg_2):
        """
        Conditional move - Not overflow.

        Tests the status flags in the EFLAGS register and moves the source operand
        (second operand) to the destination operand (first operand) if the given
        test condition is true.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.OF == False, arg_2.read(), arg_1.read()))


def Func(arg_0):
        """
        Loads status flags into AH register.

        Moves the low byte of the EFLAGS register (which includes status flags
        SF, ZF, AF, PF, and CF) to the AH register. Reserved bits 1, 3, and 5
        of the EFLAGS register are set in the AH register::

                AH  =  EFLAGS(SF:ZF:0:AF:0:PF:1:CF);

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_1 = (arg_0.SF, arg_0.ZF, arg_0.AF, arg_0.PF, arg_0.CF)
        arg_2 = any(issymbolic(x) for x in arg_1)

        def make_flag(arg_3, arg_4):
            if arg_2:
                return Operators.ITEBV(8, arg_3,
                                       BitVecConstant(8, 1 << arg_4),
                                       BitVecConstant(8, 0))
            else:
                return arg_3 << arg_4

        arg_0.AH = (make_flag(arg_0.SF, 7) |
                  make_flag(arg_0.ZF, 6) |
                  make_flag(0, 5) |
                  make_flag(arg_0.AF, 4) |
                  make_flag(0, 3) |
                  make_flag(arg_0.PF, 2) |
                  make_flag(1, 1) |
                  make_flag(arg_0.CF, 0))


def Func(arg_0, arg_1, arg_2):
        """
        Loads effective address.

        Computes the effective address of the second operand (the source operand) and stores it in the first operand
        (destination operand). The source operand is a memory address (offset part) specified with one of the processors
        addressing modes; the destination operand is a general-purpose register. The address-size and operand-size
        attributes affect the action performed by this instruction. The operand-size
        attribute of the instruction is determined by the chosen register; the address-size attribute is determined by the
        attribute of the code segment.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_1.write(Operators.EXTRACT(arg_2.address(), 0, arg_1.size))


def Func(arg_0, arg_1, arg_2):
        """
        Moves data after swapping bytes.

        Performs a byte swap operation on the data copied from the second operand (source operand) and store the result
        in the first operand (destination operand). The source operand can be a general-purpose register, or memory location; the destination register can be a general-purpose register, or a memory location; however, both operands can
        not be registers, and only one operand can be a memory location. Both operands must be the same size, which can
        be a word, a doubleword or quadword.
        The Func instruction is provided for swapping the bytes on a read from memory or on a write to memory; thus
        providing support for converting little-endian values to big-endian format and vice versa.
        In 64-bit mode, the instruction's default operation size is 32 bits. Use of the REX.R prefix permits access to additional registers (R8-R15). Use of the REX.W prefix promotes operation to 64 bits::

                TEMP = SRC
                IF ( OperandSize = 16)
                THEN
                    DEST[7:0] = TEMP[15:8];
                    DEST[15:8] = TEMP[7:0];
                ELSE IF ( OperandSize = 32)
                    DEST[7:0] = TEMP[31:24];
                    DEST[15:8] = TEMP[23:16];
                    DEST[23:16] = TEMP[15:8];
                    DEST[31:23] = TEMP[7:0];
                ELSE IF ( OperandSize = 64)
                    DEST[7:0] = TEMP[63:56];
                    DEST[15:8] = TEMP[55:48];
                    DEST[23:16] = TEMP[47:40];
                    DEST[31:24] = TEMP[39:32];
                    DEST[39:32] = TEMP[31:24];
                    DEST[47:40] = TEMP[23:16];
                    DEST[55:48] = TEMP[15:8];
                    DEST[63:56] = TEMP[7:0];
                FI;

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = arg_1.size
        arg_4 = arg_1.read()
        arg_5 = 0
        for arg_6 in range(0, arg_3, 8):
            arg_5 = (arg_5 << 8) | (arg_4 & 0xff)
            arg_4 = arg_4 >> 8
        arg_1.write(arg_4)


def Func(arg_0):
        """
        Stores AH into flags.

        Loads the SF, ZF, AF, PF, and CF flags of the EFLAGS register with values
        from the corresponding bits in the AH register (bits 7, 6, 4, 2, and 0,
        respectively). Bits 1, 3, and 5 of register AH are ignored; the corresponding
        reserved bits (1, 3, and 5) in the EFLAGS register remain as shown below::

                EFLAGS(SF:ZF:0:AF:0:PF:1:CF)  =  AH;

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """

        arg_1 = 32
        arg_2 = arg_0.AH & 0xD5 | 0x02

        arg_0.EFLAGS = Operators.ZEXTEND(arg_2, arg_1)


def Func(arg_0, arg_1):
        """
        Sets byte if below or equal.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, Operators.OR(arg_0.CF, arg_0.ZF), 1, 0))


def Func(arg_0, arg_1):
        """
        Sets if carry.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.CF, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if equal.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.ZF, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if greater or equal.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.SF == arg_0.OF, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if not above or equal.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.CF, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if not below.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.CF == False, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if not less or equal.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, Operators.AND(arg_0.ZF == False, arg_0.SF == arg_0.OF), 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if not sign.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.SF == False, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if not zero.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.ZF == False, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if overflow.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.OF, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if parity.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.PF, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if parity odd.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.PF == False, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if sign.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.SF, 1, 0))


def Func(arg_0, arg_1):
        """
        Sets byte if zero.

        :param cpu: current CPU.
        :param dest: destination operand.
        """
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.ZF, 1, 0))


def Func(arg_0):
        """
        High level procedure exit.

        Releases the stack frame set up by an earlier ENTER instruction. The
        Func instruction copies the frame pointer (in the EBP register) into
        the stack pointer register (ESP), which releases the stack space allocated
        to the stack frame. The old frame pointer (the frame pointer for the calling
        procedure that was saved by the ENTER instruction) is then popped from
        the stack into the EBP register, restoring the calling procedure's stack
        frame.
        A RET instruction is commonly executed following a Func instruction
        to return program control to the calling procedure::

                IF Stackaddress_bit_size  =  32
                THEN
                    ESP  =  EBP;
                ELSE (* Stackaddress_bit_size  =  16*)
                    SP  =  BP;
                FI;
                IF OperandSize  =  32
                THEN
                    EBP  =  Pop();
                ELSE (* OperandSize  =  16*)
                    BP  =  Pop();
                FI;

        :param cpu: current CPU.
        """
        arg_0.STACK = arg_0.FRAME
        arg_0.FRAME = arg_0.pop(arg_0.address_bit_size)


def Func(arg_0, arg_1):
        """
        Pushes a value onto the stack.

        Decrements the stack pointer and then stores the source operand on the top of the stack.

        :param cpu: current CPU.
        :param src: source operand.
        """
        # http://stackoverflow.com/questions/11291151/how-push-imm-encodes
        arg_2 = arg_1.size
        arg_3 = arg_1.read()
        if arg_2 != 64 and arg_2 != arg_0.address_bit_size // 2:
            arg_3 = Operators.SEXTEND(arg_3, arg_2, arg_0.address_bit_size)
            arg_2 = arg_0.address_bit_size
        arg_0.push(arg_3, arg_2)


def Func(arg_0, arg_1):
        """
        Procedure call.

        Saves procedure linking information on the stack and branches to the called procedure specified using the target
        operand. The target operand specifies the address of the first instruction in the called procedure. The operand can
        be an immediate value, a general-purpose register, or a memory location.

        :param cpu: current CPU.
        :param op0: target operand.
        """
        # TODO FIX 64Bit FIX segment
        arg_2 = arg_1.read()
        arg_0.push(arg_0.PC, arg_0.address_bit_size)
        arg_0.PC = arg_2


def Func(arg_0, *arg_1):
        """
        Returns from procedure.

        Transfers program control to a return address located on the top of
        the stack. The address is usually placed on the stack by a CALL instruction,
        and the return is made to the instruction that follows the CALL instruction.
        The optional source operand specifies the number of stack bytes to be
        released after the return address is popped; the default is none.

        :param cpu: current CPU.
        :param operands: variable operands list.
        """
        # TODO FIX 64Bit FIX segment
        arg_2 = 0
        if len(arg_1) > 0:
            arg_2 = arg_1[0].read()
        arg_0.PC = arg_0.pop(arg_0.address_bit_size)
        arg_0.STACK += arg_2


def Func(arg_0, arg_1):
        """
        Jumps short if above.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, Operators.AND(arg_0.CF == False, arg_0.ZF == False), arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if below.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, arg_0.CF == True, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if below or equal.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, Operators.OR(arg_0.CF, arg_0.ZF), arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if carry.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, arg_0.CF, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if CX register is 0.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, arg_0.CX == 0, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if ECX register is 0.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, arg_0.ECX == 0, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if greater.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, Operators.AND(arg_0.ZF == False, arg_0.SF == arg_0.OF), arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if greater or equal.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, (arg_0.SF == arg_0.OF), arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if not equal.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, False == arg_0.ZF, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if not parity.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, False == arg_0.PF, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if overflow.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, arg_0.OF, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if sign.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, arg_0.SF, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1):
        """
        Jumps short if zero.

        :param cpu: current CPU.
        :param target: destination operand.
        """
        arg_0.PC = Operators.ITEBV(arg_0.address_bit_size, arg_0.ZF, arg_1.read(), arg_0.PC)


def Func(arg_0, arg_1, arg_2):
        """
        Rotates through carry left.

        Shifts (rotates) the bits of the first operand (destination operand) the number of bit positions specified in the
        second operand (count operand) and stores the result in the destination operand. The destination operand can be
        a register or a memory location; the count operand is an unsigned integer that can be an immediate or a value in
        the CL register. In legacy and compatibility mode, the processor restricts the count to a number between 0 and 31
        by masking all the bits in the count operand except the 5 least-significant bits.

        The Func instruction shifts the CF flag into the least-significant bit and shifts the most-significant bit into the CF flag.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: count operand.
        """
        arg_3 = arg_1.size
        arg_4 = arg_2.read()
        arg_5 = {8: 0x1f,
                     16: 0x1f,
                     32: 0x1f,
                     64: 0x3f}[arg_3]
        arg_6 = Operators.ZEXTEND((arg_4 & arg_5) % (arg_2.size + 1), arg_3)

        arg_7 = arg_1.read()

        if isinstance(arg_6, int) and arg_6 == 0:
            # this is a no-op
            arg_8 = arg_7
            arg_1.write(arg_8)
        else:
            arg_9 = Operators.ITEBV(arg_3, arg_0.CF, 1, 0)
            arg_10 = arg_7 >> (arg_3 - arg_6)
            arg_8 = (arg_7 << arg_6) | (arg_9 << (arg_6 - 1)) | (arg_10 >> 1)
            arg_1.write(arg_8)

            def sf(arg_11, arg_12):
                return (arg_11 & (1 << (arg_12 - 1))) != 0
            arg_0.CF = sf(arg_7 << (arg_6 - 1), arg_3)
            arg_0.OF = Operators.ITE(arg_6 == 1,
                                   sf(arg_8, arg_3) != arg_0.CF,
                                   arg_0.OF)


def Func(arg_0, arg_1, arg_2):
        """
        Shift arithmetic right.

        The shift arithmetic right (Func) and shift logical right (SHR) instructions shift the bits of the destination operand to
        the right (toward less significant bit locations). For each shift count, the least significant bit of the destination
        operand is shifted into the CF flag, and the most significant bit is either set or cleared depending on the instruction
        type. The SHR instruction clears the most significant bit. the Func instruction sets or clears the most significant bit
        to correspond to the sign (most significant bit) of the original value in the destination operand. In effect, the Func
        instruction fills the empty bit position's shifted value with the sign of the unshifted value

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = arg_1.size
        arg_4 = {8: 0x1f,
                     16: 0x1f,
                     32: 0x1f,
                     64: 0x3f}[arg_3]

        arg_5 = arg_2.read() & arg_4
        arg_6 = arg_1.read()

        arg_7 = Operators.Func(arg_3, arg_6, Operators.ZEXTEND(arg_5, arg_3))
        arg_1.write(arg_7)

        arg_8 = (1 << (arg_3 - 1))

        # We can't use this one as the 'true' expression gets eagerly calculated even on count == 0		 +        cpu.CF = Operators.ITE(count!=0, ((value >> Operators.ZEXTEND(count-1, OperandSize)) & 1) !=0, cpu.CF)
        # cpu.CF = Operators.ITE(count!=0, ((value >> Operators.ZEXTEND(count-1, OperandSize)) & 1) !=0, cpu.CF)

        if issymbolic(arg_5):
            # We can't use this one as the EXTRACT op needs the offset arguments to be concrete
            #    cpu.CF = Operators.ITE(count!=0, Operands.EXTRACT(value,count-1,1) !=0, cpu.CF)
            arg_0.CF = Operators.ITE(Operators.AND(arg_5 != 0, arg_5 <= arg_3), ((arg_6 >> Operators.ZEXTEND(arg_5 - 1, arg_3)) & 1) != 0, arg_0.CF)
        else:
            if arg_5 != 0:
                if arg_5 > arg_3:
                    arg_5 = arg_3
                arg_0.CF = Operators.EXTRACT(arg_6, arg_5 - 1, 1) != 0

        # on count == 0 AF is unaffected, for count > 0, AF is undefined.
        # in either case, do not touch AF
        arg_0.ZF = Operators.ITE(arg_5 != 0, arg_7 == 0, arg_0.ZF)
        arg_0.SF = Operators.ITE(arg_5 != 0, (arg_7 & arg_8) != 0, arg_0.SF)
        arg_0.OF = Operators.ITE(arg_5 == 1, False, arg_0.OF)
        arg_0.PF = Operators.ITE(arg_5 != 0, arg_0._calculate_parity_flag(arg_7), arg_0.PF)


def Func(arg_0, arg_1, arg_2):
        """
        Shift logical right.

        The shift arithmetic right (SAR) and shift logical right (Func)
        instructions shift the bits of the destination operand to the right
        (toward less significant bit locations). For each shift count, the
        least significant bit of the destination operand is shifted into the CF
        flag, and the most significant bit is either set or cleared depending
        on the instruction type. The Func instruction clears the most
        significant bit.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: count operand.
        """
        arg_3 = arg_1.size
        arg_4 = Operators.ZEXTEND(arg_2.read() & (arg_3 - 1), arg_3)
        arg_5 = arg_1.read()

        arg_6 = arg_1.write(arg_5 >> arg_4)  # UNSIGNED Operators.UDIV2 !! TODO Check

        arg_7 = (1 << arg_3) - 1
        arg_8 = 1 << (arg_3 - 1)

        if issymbolic(arg_4):
            arg_0.CF = Operators.ITE(arg_4 != 0,
                                   ((arg_5 >> Operators.ZEXTEND(arg_4 - 1, arg_3)) & 1) != 0,
                                   arg_0.CF)
        else:
            if arg_4 != 0:
                arg_0.CF = Operators.EXTRACT(arg_5, arg_4 - 1, 1) != 0

        arg_0.ZF = Operators.ITE(arg_4 != 0, arg_6 == 0, arg_0.ZF)
        arg_0.SF = Operators.ITE(arg_4 != 0, (arg_6 & arg_8) != 0, arg_0.SF)
        # OF is only defined for count == 1, but in practice (unit tests from real cpu) it's calculated for count != 0
        arg_0.OF = Operators.ITE(arg_4 != 0, ((arg_5 >> (arg_3 - 1)) & 0x1) == 1, arg_0.OF)
        arg_0.PF = Operators.ITE(arg_4 != 0, arg_0._calculate_parity_flag(arg_6), arg_0.PF)


def Func(arg_0, arg_1, arg_2, arg_3):
        """
        Double precision shift right.

        Shifts the first operand (destination operand) to the left the number of bits specified by the third operand
        (count operand). The second operand (source operand) provides bits to shift in from the right (starting with
        the least significant bit of the destination operand).

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        :param count: count operand
        """
        arg_4 = arg_1.size
        arg_5 = Operators.ZEXTEND(arg_3.read(), arg_4) & (arg_4 - 1)
        arg_6 = arg_1.read()
        arg_7 = arg_2.read()

        arg_8 = ((1 << arg_4) - 1)
        arg_9 = (arg_6 << arg_5)
        arg_10 = arg_7 >> (arg_4 - arg_5)
        arg_11 = Operators.ITEBV(arg_4, arg_5 == 0, arg_6, arg_9 | arg_10)
        arg_11 = arg_11 & arg_8
        arg_1.write(arg_11)
        if isinstance(arg_5, int) and arg_5 == 0:
            pass
        else:
            arg_12 = 1 << (arg_4 - 1)
            arg_13 = 0 != ((arg_6 << (arg_5 - 1)) & arg_12)

            arg_0._set_shiftd_flags(arg_4, arg_6, arg_11, arg_13, arg_5)


def Func(arg_0, arg_1, arg_2):
        """
        Bit scan forward.

        Searches the source operand (second operand) for the least significant
        set bit (1 bit). If a least significant 1 bit is found, its bit index
        is stored in the destination operand (first operand). The source operand
        can be a register or a memory location; the destination operand is a register.
        The bit index is an unsigned offset from bit 0 of the source operand.
        If the contents source operand are 0, the contents of the destination
        operand is undefined::

                    IF SRC  =  0
                    THEN
                        ZF  =  1;
                        DEST is undefined;
                    ELSE
                        ZF  =  0;
                        temp  =  0;
                        WHILE Bit(SRC, temp)  =  0
                        DO
                            temp  =  temp + 1;
                            DEST  =  temp;
                        OD;
                    FI;

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = arg_2.read()
        arg_4 = Operators.EXTRACT(arg_3, 0, 1) == 1
        arg_5 = 0
        for arg_6 in range(1, arg_2.size):
            arg_5 = Operators.ITEBV(arg_1.size, arg_4, arg_5, arg_6)
            arg_4 = Operators.OR(arg_4, Operators.EXTRACT(arg_3, arg_6, 1) == 1)

        arg_0.ZF = arg_3 == 0
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.ZF, arg_1.read(), arg_5))


def Func(arg_0, arg_1, arg_2):
        """
        Bit scan reverse.

        Searches the source operand (second operand) for the most significant
        set bit (1 bit). If a most significant 1 bit is found, its bit index is
        stored in the destination operand (first operand). The source operand
        can be a register or a memory location; the destination operand is a register.
        The bit index is an unsigned offset from bit 0 of the source operand.
        If the contents source operand are 0, the contents of the destination
        operand is undefined::

                IF SRC  =  0
                THEN
                    ZF  =  1;
                    DEST is undefined;
                ELSE
                    ZF  =  0;
                    temp  =  OperandSize - 1;
                    WHILE Bit(SRC, temp)  =  0
                    DO
                        temp  =  temp - 1;
                        DEST  =  temp;
                    OD;
                FI;

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = arg_2.read()
        arg_4 = Operators.EXTRACT(arg_3, arg_2.size - 1, 1) == 1
        arg_5 = 0

        for arg_6 in reversed(range(0, arg_2.size)):
            arg_5 = Operators.ITEBV(arg_1.size, arg_4, arg_5, arg_6)
            arg_4 = Operators.OR(arg_4, (Operators.EXTRACT(arg_3, arg_6, 1) == 1))

        arg_0.PF = arg_0._calculate_parity_flag(arg_5)
        arg_0.ZF = arg_3 == 0
        arg_1.write(Operators.ITEBV(arg_1.size, arg_0.ZF, arg_1.read(), arg_5))


def Func(arg_0, arg_1, arg_2):
        """
        Bit test and complement.

        Selects the bit in a bit string (specified with the first operand, called
        the bit base) at the bit-position designated by the bit offset operand
        (second operand), stores the value of the bit in the CF flag, and complements
        the selected bit in the bit string.

        :param cpu: current CPU.
        :param dest: bit base operand.
        :param src: bit offset operand.
        """
        if arg_1.type == 'register':
            arg_3 = arg_1.read()
            arg_4 = arg_2.read() % arg_1.size
            arg_0.CF = arg_3 & (1 << arg_4) == 1 << arg_4
            arg_1.write(arg_3 ^ (1 << arg_4))
        elif arg_1.type == 'memory':
            arg_6, arg_4 = arg_0._getMemoryBit(arg_1, arg_2)
            arg_7, arg_8, arg_9 = arg_0.get_descriptor(arg_0.DS)
            arg_6 += arg_7
            arg_3 = arg_0.read_int(arg_6, 8)
            arg_0.CF = arg_3 & (1 << arg_4) == 1 << arg_4
            arg_3 = arg_3 ^ (1 << arg_4)
            arg_0.write_int(arg_6, arg_3, 8)
        else:
            raise NotImplementedError(f"Unknown operand for Func: {dest.type}")


def Func(arg_0, arg_1, arg_2):
        """
        Loads string.

        Loads a byte, word, or doubleword from the source operand into the AL, AX, or EAX register, respectively. The
        source operand is a memory location, the address of which is read from the DS:ESI or the DS:SI registers
        (depending on the address-size attribute of the instruction, 32 or 16, respectively). The DS segment may be over-
        ridden with a segment override prefix.
        After the byte, word, or doubleword is transferred from the memory location into the AL, AX, or EAX register, the
        (E)SI register is incremented or decremented automatically according to the setting of the DF flag in the EFLAGS
        register. (If the DF flag is 0, the (E)SI register is incremented; if the DF flag is 1, the ESI register is decremented.)
        The (E)SI register is incremented or decremented by 1 for byte operations, by 2 for word operations, or by 4 for
        doubleword operations.

        :param cpu: current CPU.
        :param dest: source operand.
        """
        arg_3 = {8: 'SI', 32: 'ESI', 64: 'RSI'}[arg_0.address_bit_size]
        arg_4, arg_5, arg_6 = arg_0.get_descriptor(arg_0.DS)

        arg_7 = arg_0.read_register(arg_3) + arg_4
        arg_8 = arg_1.size

        arg_9 = arg_0.read_int(arg_7, arg_8)
        arg_1.write(arg_9)

        arg_10 = Operators.ITEBV(arg_0.address_bit_size, arg_0.DF, -arg_8 // 8, arg_8 // 8)
        arg_0.write_register(arg_3, arg_0.read_register(arg_3) + arg_10)


def Func(arg_0, arg_1, arg_2):
        """
        Moves data from string to string.

        Moves the byte, word, or doubleword specified with the second operand (source operand) to the location specified
        with the first operand (destination operand). Both the source and destination operands are located in memory. The
        address of the source operand is read from the DS:ESI or the DS:SI registers (depending on the address-size
        attribute of the instruction, 32 or 16, respectively). The address of the destination operand is read from the ES:EDI
        or the ES:DI registers (again depending on the address-size attribute of the instruction). The DS segment may be
        overridden with a segment override prefix, but the ES segment cannot be overridden.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3, arg_4, arg_5 = arg_0.get_descriptor(arg_0.DS)
        arg_6 = arg_2.address() + arg_3
        arg_7 = arg_1.address() + arg_3

        arg_8 = arg_2.mem.base
        arg_9 = arg_1.mem.base
        arg_4 = arg_1.size

        # Copy the data
        arg_1.write(arg_2.read())

        #Advance EDI/ESI pointers
        arg_10 = Operators.ITEBV(arg_0.address_bit_size, arg_0.DF, -arg_4 // 8, arg_4 // 8)
        arg_0.write_register(arg_8, arg_0.read_register(arg_8) + arg_10)
        arg_0.write_register(arg_9, arg_0.read_register(arg_9) + arg_10)


def Func(arg_0, arg_1, arg_2):
        """
        Stores String.

        Stores a byte, word, or doubleword from the AL, AX, or EAX register,
        respectively, into the destination operand. The destination operand is
        a memory location, the address of which is read from either the ES:EDI
        or the ES:DI registers (depending on the address-size attribute of the
        instruction, 32 or 16, respectively). The ES segment cannot be overridden
        with a segment override prefix.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = arg_2.size
        arg_1.write(arg_2.read())
        arg_4 = arg_1.mem.base
        arg_5 = Operators.ITEBV({'RDI': 64, 'EDI': 32, 'DI': 16}[arg_4], arg_0.DF, -arg_3 // 8, arg_3 // 8)
        arg_0.write_register(arg_4, arg_0.read_register(arg_4) + arg_5)


def Func(arg_0, arg_1, arg_2, arg_3):
        """
        The shift arithmetic right.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: count operand.
        """
        arg_4 = arg_1.size
        arg_3 = arg_3.read()
        arg_5 = {8: 0x1f,
                     16: 0x1f,
                     32: 0x1f,
                     64: 0x3f}[arg_4]
        arg_6 = arg_3 & arg_5
        arg_7 = arg_10 = arg_2.read()

        arg_8 = arg_10 & (1 << (arg_4 - 1))
        while arg_6 != 0:
            arg_0.CF = (arg_10 & 0x1) != 0  # LSB
            arg_10 = (arg_10 >> 1) | arg_8
            arg_6 = arg_6 - 1
        arg_11 = arg_1.write(arg_10)


def Func(arg_0, arg_1, arg_2, arg_3):
        """
        Packed shuffle words.

        Copies doublewords from source operand (second operand) and inserts them in the destination operand
        (first operand) at locations selected with the order operand (third operand).

        :param cpu: current CPU.
        :param op0: destination operand.
        :param op1: source operand.
        :param op3: order operand.
         """
        arg_4 = arg_1.size
        arg_5 = arg_1.read()
        arg_6 = arg_2.read()
        arg_7 = Operators.ZEXTEND(arg_3.read(), arg_4)
        assert arg_4 == 64
        arg_5 |= ((arg_6 >> ((arg_7 >> 0) & 3 * 16)) & 0xffff)
        arg_5 |= ((arg_6 >> ((arg_7 >> 2) & 3 * 16)) & 0xffff) << 16
        arg_5 |= ((arg_6 >> ((arg_7 >> 4) & 3 * 16)) & 0xffff) << 32
        arg_5 |= ((arg_6 >> ((arg_7 >> 6) & 3 * 16)) & 0xffff) << 48
        arg_1.write(arg_5)


def Func(arg_0, arg_1, arg_2, arg_3):
        """
        Packed shuffle doublewords.

        Copies doublewords from source operand (second operand) and inserts them in the destination operand
        (first operand) at locations selected with the order operand (third operand).

        :param cpu: current CPU.
        :param op0: destination operand.
        :param op1: source operand.
        :param op3: order operand.
         """
        arg_4 = arg_1.size
        arg_5 = arg_1.read()
        arg_6 = arg_2.read()
        arg_7 = Operators.ZEXTEND(arg_3.read(), arg_4)

        arg_5 = arg_5 & 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000
        arg_5 |= ((arg_6 >> (((arg_7 >> 0) & 3) * 32)) & 0xffffffff)
        arg_5 |= ((arg_6 >> (((arg_7 >> 2) & 3) * 32)) & 0xffffffff) << 32
        arg_5 |= ((arg_6 >> (((arg_7 >> 4) & 3) * 32)) & 0xffffffff) << 64
        arg_5 |= ((arg_6 >> (((arg_7 >> 6) & 3) * 32)) & 0xffffffff) << 96

        arg_1.write(arg_5)


def Func(arg_0, arg_1, arg_2):
        """
        Moves byte mask to general-purpose register.

        Creates an 8-bit mask made up of the most significant bit of each byte of the source operand
        (second operand) and stores the result in the low byte or word of the destination operand
        (first operand). The source operand is an MMX(TM) technology or an XXM register; the destination
        operand is a general-purpose register.

        :param cpu: current CPU.
        :param op0: destination operand.
        :param op1: source operand.
        """
        arg_3 = arg_1.read()
        arg_4 = arg_2.read()

        arg_5 = 0
        for arg_6 in reversed(range(7, arg_2.size, 8)):
            arg_5 = (arg_5 << 1) | ((arg_4 >> arg_6) & 1)
        arg_1.write(Operators.EXTRACT(arg_5, 0, arg_1.size))


def Func(arg_0, arg_1, arg_2):
        """
        Packed shift right logical double quadword.

        Shifts the destination operand (first operand) to the right by the number
        of bytes specified in the count operand (second operand). The empty high-order
        bytes are cleared (set to all 0s). If the value specified by the count
        operand is greater than 15, the destination operand is set to all 0s.
        The destination operand is an XMM register. The count operand is an 8-bit
        immediate::

            TEMP  =  SRC;
            if (TEMP > 15) TEMP  =  16;
            DEST  =  DEST >> (temp * 8);

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: count operand.
        """
        # TODO(yan): Verify the correctness of truncating SRC like this ( tests
        # use '-1' as the value
        arg_3 = Operators.EXTRACT(arg_2.read(), 0, 8)
        arg_3 = Operators.ITEBV(arg_2.size, arg_3 > 15, 16, arg_3)
        arg_1.write(arg_1.read() >> (arg_3 * 8))


def Func(arg_0, arg_1, arg_2):
        """
        Moves with sign-extension.

        Copies the contents of the source operand (register or memory location) to the destination
        operand (register) and sign extends the value to 16::

                OP0  =  SignExtend(OP1);

        :param cpu: current CPU.
        :param op0: destination operand.
        :param op1: source operand.
        """
        arg_1.write(Operators.SEXTEND(arg_2.read(), arg_2.size, arg_1.size))


def Func(arg_0):
        """
        Converts word to doubleword.

        ::
            DX = sign-extend of AX.

        :param cpu: current CPU.
        """
        arg_1 = Operators.EXTRACT(arg_0.AX, 15, 1)
        arg_0.EAX = Operators.SEXTEND(arg_0.AX, 16, 32)
        arg_0.EDX = Operators.SEXTEND(arg_1, 1, 32)


def Func(arg_0):
        """
        Reads time-stamp counter.

        Loads the current value of the processor's time-stamp counter into the
        EDX:EAX registers.  The time-stamp counter is contained in a 64-bit
        MSR. The high-order 32 bits of the MSR are loaded into the EDX
        register, and the low-order 32 bits are loaded into the EAX register.
        The processor increments the time-stamp counter MSR every clock cycle
        and resets it to 0 whenever the processor is reset.

        :param cpu: current CPU.
        """
        arg_1 = arg_0.icount
        arg_0.RAX = arg_1 & 0xffffffff
        arg_0.RDX = (arg_1 >> 32) & 0xffffffff


def Func(arg_0, arg_1, arg_2):
        """
        Moves low packed double-precision floating-point value.

        Moves a double-precision floating-point value from the source operand (second operand) and the
        destination operand (first operand). The source and destination operands can be an XMM register
        or a 64-bit memory location. This instruction allows double-precision floating-point values to be moved
        to and from the low quadword of an XMM register and memory. It cannot be used for register to register
        or memory to memory moves. When the destination operand is an XMM register, the high quadword of the
        register remains unchanged.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = arg_2.read()
        if arg_2.size == 64 and arg_1.size == 128:
            arg_3 = (arg_1.read() & 0xffffffffffffffff0000000000000000) | Operators.ZEXTEND(arg_3, 128)
        arg_1.write(arg_3)


def Func(arg_0, arg_1, arg_2):
        """
        Moves high packed double-precision floating-point value.

        Moves a double-precision floating-point value from the source operand (second operand) and the
        destination operand (first operand). The source and destination operands can be an XMM register
        or a 64-bit memory location. This instruction allows double-precision floating-point values to be moved
        to and from the high quadword of an XMM register and memory. It cannot be used for register to
        register or memory to memory moves. When the destination operand is an XMM register, the low quadword
        of the register remains unchanged.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        if arg_2.size == 128:
            assert arg_1.size == 64
            arg_1.write(Operators.EXTRACT(arg_2.read(), 64, 64))
        else:
            assert arg_2.size == 64 and arg_1.size == 128
            arg_3 = Operators.EXTRACT(arg_1.read(), 0, 64)  # low part
            arg_1.write(Operators.CONCAT(128, arg_2.read(), arg_3))


def Func(arg_0, arg_1, arg_2):
        """
        Packed subtract.

        Performs a SIMD subtract of the packed integers of the source operand (second operand) from the packed
        integers of the destination operand (first operand), and stores the packed integer results in the
        destination operand. The source operand can be an MMX(TM) technology register or a 64-bit memory location,
        or it can be an XMM register or a 128-bit memory location. The destination operand can be an MMX or an XMM
        register.
        The Func instruction subtracts packed byte integers. When an individual result is too large or too small
        to be represented in a byte, the result is wrapped around and the low 8 bits are written to the
        destination element.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        arg_3 = []
        arg_4 = arg_1.read()
        arg_5 = arg_2.read()
        for arg_6 in reversed(range(0, arg_1.size, 8)):
            arg_7 = Operators.EXTRACT(arg_4, arg_6, 8)
            arg_8 = Operators.EXTRACT(arg_5, arg_6, 8)
            arg_3.append((arg_7 - arg_8) & 0xff)
        arg_1.write(Operators.CONCAT(8 * len(arg_3), *arg_3))


def Func(arg_0, arg_1, arg_2):
        """
        Move quadword.

        Copies a quadword from the source operand (second operand) to the destination operand (first operand).
        The source and destination operands can be MMX(TM) technology registers, XMM registers, or 64-bit memory
        locations. This instruction can be used to move a between two MMX registers or between an MMX register
        and a 64-bit memory location, or to move data between two XMM registers or between an XMM register and
        a 64-bit memory location. The instruction cannot be used to transfer data between memory locations.
        When the source operand is an XMM register, the low quadword is moved; when the destination operand is
        an XMM register, the quadword is stored to the low quadword of the register, and the high quadword is
        cleared to all 0s::

            Func instruction when operating on MMX registers and memory locations:

            DEST  =  SRC;

            Func instruction when source and destination operands are XMM registers:

            DEST[63-0]  =  SRC[63-0];

            Func instruction when source operand is XMM register and destination operand is memory location:

            DEST  =  SRC[63-0];

            Func instruction when source operand is memory location and destination operand is XMM register:

            DEST[63-0]  =  SRC;
            DEST[127-64]  =  0000000000000000H;

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        # mmx to mmx or mmx to mem
        if arg_1.size == arg_2.size and arg_1.size == 64:
            arg_1.write(arg_2.read())
        # two xmm regs
        elif arg_1.size == arg_2.size and arg_1.size == 128:
            arg_3 = Operators.EXTRACT(arg_2.read(), 0, 64)
            arg_1.write(Operators.ZEXTEND(arg_3, 128))
        # mem to xmm
        elif arg_1.size == 128 and arg_2.size == 64:
            arg_1.write(Operators.ZEXTEND(arg_2.read(), arg_1.size))
        # xmm to mem
        elif arg_1.size == 64 and arg_2.size == 128:
            arg_1.write(Operators.EXTRACT(arg_2.read(), 0, arg_1.size))
        else:
            arg_4 = 'Invalid size in Func'
            logger.error(arg_4)
            raise Exception(arg_4)


def Func(arg_0, arg_1, arg_2):
        """
        Move Scalar Double-Precision Floating-Point Value

        Moves a scalar double-precision floating-point value from the source
        operand (second operand) to the destination operand (first operand).
        The source and destination operands can be XMM registers or 64-bit memory
        locations. This instruction can be used to move a double-precision
        floating-point value to and from the low quadword of an XMM register and
        a 64-bit memory location, or to move a double-precision floating-point
        value between the low quadwords of two XMM registers. The instruction
        cannot be used to transfer data between memory locations.
        When the source and destination operands are XMM registers, the high
        quadword of the destination operand remains unchanged. When the source
        operand is a memory location and destination operand is an XMM registers,
        the high quadword of the destination operand is cleared to all 0s.

        :param cpu: current CPU.
        :param dest: destination operand.
        :param src: source operand.
        """
        assert arg_1.type != 'memory' or arg_2.type != 'memory'
        arg_3 = Operators.EXTRACT(arg_2.read(), 0, 64)
        if arg_1.size > arg_2.size:
            arg_3 = Operators.ZEXTEND(arg_3, arg_1.size)
        arg_1.write(arg_3)


def Func(arg_0, arg_1, arg_2):
        """
        Moves a scalar single-precision floating-point value

        Moves a scalar single-precision floating-point value from the source operand (second operand)
        to the destination operand (first operand). The source and destination operands can be XMM
        registers or 32-bit memory locations. This instruction can be used to move a single-precision
        floating-point value to and from the low doubleword of an XMM register and a 32-bit memory
        location, or to move a single-precision floating-point value between the low doublewords of
        two XMM registers. The instruction cannot be used to transfer data between memory locations.
        When the source and destination operands are XMM registers, the three high-order doublewords of the
        destination operand remain unchanged. When the source operand is a memory location and destination
        operand is an XMM registers, the three high-order doublewords of the destination operand are cleared to all 0s.

        //Func instruction when source and destination operands are XMM registers:
        if(IsXMM(Source) && IsXMM(Destination))
            Destination[0..31] = Source[0..31];
            //Destination[32..127] remains unchanged
            //Func instruction when source operand is XMM register and destination operand is memory location:
        else if(IsXMM(Source) && IsMemory(Destination))
            Destination = Source[0..31];
        //Func instruction when source operand is memory location and destination operand is XMM register:
        else {
                Destination[0..31] = Source;
                Destination[32..127] = 0;
        }
        """
        if arg_1.type == 'register' and arg_2.type == 'register':
            assert arg_1.size == 128 and arg_2.size == 128
            arg_1.write(arg_1.read() & ~0xffffffff | arg_2.read() & 0xffffffff)
        elif arg_1.type == 'memory':
            assert arg_2.type == 'register'
            arg_1.write(Operators.EXTRACT(arg_2.read(), 0, arg_1.size))
        else:
            assert arg_2.type == 'memory' and arg_1.type == 'register'
            assert arg_2.size == 32 and arg_1.size == 128
            arg_1.write(Operators.ZEXTEND(arg_2.read(), 128))


def Func(arg_0, arg_1):
        """Constrain state.

        :param manticore.core.smtlib.Bool Funct: Constraint to add
        """
        arg_1 = arg_0.migrate_expression(arg_1)
        arg_0._Functs.add(arg_1)


def Func(arg_0, arg_1, **arg_2):
        """Create and return a symbolic buffer of length `nbytes`. The buffer is
        not written into State's memory; write it to the state's memory to
        introduce it into the program state.

        :param int nbytes: Length of the new buffer
        :param str label: (keyword arg only) The label to assign to the buffer
        :param bool cstring: (keyword arg only) Whether or not to enforce that the buffer is a cstring
                 (i.e. no NULL bytes, except for the last byte). (bool)
        :param taint: Taint identifier of the new buffer
        :type taint: tuple or frozenset

        :return: :class:`~manticore.core.smtlib.expression.Expression` representing the buffer.
        """
        arg_3 = arg_2.get('label')
        arg_4 = False
        if arg_3 is None:
            arg_3 = 'buffer'
            arg_4 = True
        arg_5 = arg_2.get('taint', frozenset())
        arg_6 = arg_0._constraints.new_array(name=arg_3, index_max=arg_1, value_bits=8, arg_5=arg_5, arg_4=arg_4)
        arg_0._input_symbols.append(arg_6)

        if arg_2.get('cstring', False):
            for arg_7 in range(arg_1 - 1):
                arg_0._constraints.add(arg_6[arg_7] != 0)

        return arg_6


def Func(arg_0, arg_1, arg_2=None, arg_3=arg_4()):
        """Create and return a symbolic value that is `nbits` bits wide. Assign
        the value to a register or write it into the address space to introduce
        it into the program state.

        :param int nbits: The bitwidth of the value returned
        :param str label: The label to assign to the value
        :param taint: Taint identifier of this value
        :type taint: tuple or frozenset
        :return: :class:`~manticore.core.smtlib.expression.Expression` representing the value
        """
        assert arg_1 in (1, 4, 8, 16, 32, 64, 128, 256)
        arg_5 = False
        if arg_2 is None:
            arg_2 = 'val'
            arg_5 = True

        arg_6 = arg_0._constraints.new_bitvec(arg_1, name=arg_2, arg_3=arg_3, arg_5=arg_5)
        arg_0._input_symbols.append(arg_6)
        return arg_6


def Func(arg_0, arg_1, arg_2, arg_3=False):
        """
        Reads `nbytes` of symbolic data from a buffer in memory at `addr` and attempts to
        concretize it

        :param int address: Address of buffer to concretize
        :param int nbytes: Size of buffer to concretize
        :param bool constrain: If True, constrain the buffer to the concretized value
        :return: Concrete contents of buffer
        :rtype: list[int]
        """
        arg_4 = arg_0.cpu.read_bytes(arg_1, arg_2)
        arg_5 = []
        with arg_0._constraints as temp_cs:
            arg_6 = arg_0.constraints if arg_3 else temp_cs
            for arg_7 in arg_4:
                arg_5.append(arg_0._solver.get_value(arg_6, arg_7))
                arg_6.add(arg_7 == arg_5[-1])
        return arg_5


def Func(arg_0, arg_1, arg_2) -> bool:
        """Check if expression is True and that it can not be False with current constraints"""
        arg_3 = arg_0.get_all_values(arg_1, arg_2, maxcnt=2, silent=True)
        return arg_3 == [True]


def Func(arg_0, arg_1, arg_2: arg_3, arg_4=10000):
        """
        Iteratively finds the Funcimum value for a symbol within given constraints.

        :param constraints: constraints that the expression must fulfil
        :param X: a symbol or expression
        :param M: maximum number of iterations allowed
        """
        assert isinstance(arg_2, arg_3)
        return arg_0.optimize(arg_1, arg_2, 'Funcimize', arg_4)


def Func(arg_0):
        """Spawns z3 solver process"""
        assert '_proc' not in dir(arg_0) or arg_0._proc is None
        try:
            arg_0._proc = Popen(shlex.split(arg_0._command), stdin=PIPE, stdout=PIPE, bufsize=0, universal_newlines=True)
        except OSError as e:
            print(e, "Probably too many cached expressions? visitors._cache...")
            # Z3 was removed from the system in the middle of operation
            raise Z3NotFoundError  # TODO(mark) don't catch this exception in two places

        # run solver specific initializations
        for arg_2 in arg_0._init:
            arg_0._send(arg_2)


def Func(arg_0, arg_1=None):
        """Auxiliary method to reset the smtlib external solver to initial defaults"""
        if arg_0._proc is None:
            arg_0._start_proc()
        else:
            if arg_0.supportFunc:
                arg_0._send("(reset)")

                for arg_2 in arg_0._init:
                    arg_0._send(arg_2)
            else:
                arg_0._stop_proc()
                arg_0._start_proc()
        if arg_1 is not None:
            arg_0._send(arg_1)


def Func(arg_0, arg_1: arg_2):
        """
        Send a string to the solver.

        :param cmd: a SMTLIBv2 command (ex. (check-sat))
        """
        logger.debug('>%s', arg_1)
        try:
            arg_0._proc.stdout.flush()
            arg_0._proc.stdin.write(f'{cmd}\n')
        except IOError as e:
            raise SolverError(arg_2(e))


def Func(arg_0) -> str:
        """Reads the response from the solver"""
        arg_1, arg_2, arg_3 = arg_0.__readline_and_count()
        arg_4 = [arg_1]

        while arg_2 != arg_3:
            arg_1, arg_5, arg_6 = arg_0.__readline_and_count()
            arg_4.append(arg_1)
            arg_2 += arg_5
            arg_3 += arg_6

        arg_1 = ''.join(arg_4).strip()

        logger.debug('<%s', arg_1)
        if '(error' in arg_4[0]:
            raise Exception(f"Error in smtlib: {bufl[0]}")
        return arg_1


def Func(arg_0) -> bool:
        """
        Check the satisfiability of the current state

        :return: whether current state is satisfiable or not.
        """
        logger.debug("Solver.check() ")
        arg_1 = time.time()
        arg_0._send('(check-sat)')
        arg_2 = arg_0._recv()
        logger.debug("Check took %s seconds (%s)", time.time() - arg_1, arg_2)
        if arg_2 not in ('sat', 'unsat', 'unknown'):
            raise SolverError(arg_2)
        if consider_unknown_as_unsat:
            if arg_2 == 'unknown':
                logger.info('Found an unknown core, probably a solver timeout')
                arg_2 = 'unsat'

        if arg_2 == 'unknown':
            raise SolverUnknown(arg_2)

        return arg_2 == 'sat'


def Func(arg_0, arg_1: arg_2):
        """Auxiliary method to send an assert"""
        assert isinstance(arg_1, arg_2)
        arg_3 = translate_to_smtlib(arg_1)
        arg_0._send('(assert %s)' % arg_3)


def Func(arg_0, arg_1):
        """
        Ask the solver for one possible assignment for given expression using current set of constraints.
        The current set of expressions must be sat.

        NOTE: This is an internal method: it uses the current solver state (set of constraints!).
        """
        if not issymbolic(arg_1):
            return arg_1
        assert isinstance(arg_1, Variable)

        if isinstance(arg_1, Array):
            arg_2 = bytearray()
            for arg_3 in arg_1:
                arg_4 = translate_to_smtlib(arg_3)
                arg_0._send('(get-value (%s))' % arg_4)
                arg_5 = arg_0._recv()
                arg_2.append(int('0x{:s}'.format(arg_5.split(arg_4)[1][3:-2]), 16))
            return bytes(arg_2)
        else:
            arg_0._send('(get-value (%s))' % arg_1.name)
            arg_6 = arg_0._recv()
            assert arg_6.startswith('((') and arg_6.endswith('))'), arg_6

            if isinstance(arg_1, Bool):
                return {'true': True, 'false': False}[arg_6[2:-2].split(' ')[1]]
            elif isinstance(arg_1, BitVec):
                arg_7, arg_8 = arg_0._get_value_fmt
                arg_9 = arg_7.match(arg_6)
                arg_10, arg_11 = arg_9.group('expr'), arg_9.group('value')
                return int(arg_11, arg_8)

        raise NotImplementedError("Func only implemented for Bool and BitVec")


def Func(arg_0, arg_1, arg_2):
        """Check if two potentially symbolic values can be equal"""
        if isinstance(arg_2, bool):
            if not arg_2:
                return arg_2
            else:
                # if True check if constraints are feasible
                arg_0._reset(arg_1)
                return arg_0._is_sat()
        assert isinstance(arg_2, Bool)

        with arg_1 as temp_cs:
            temp_cs.add(arg_2)
            arg_0._reset(temp_cs.to_string(related_to=arg_2))
            return arg_0._is_sat()


def Func(arg_0, arg_1, arg_2, arg_3=None, arg_4=False):
        """Returns a list with all the possible values for the symbol x"""
        if not isinstance(arg_2, Expression):
            return [arg_2]
        assert isinstance(arg_1, ConstraintSet)
        assert isinstance(arg_2, Expression)
        arg_2 = simplify(arg_2)
        if arg_3 is None:
            arg_3 = consts.maxsolutions

        with arg_1 as temp_cs:
            if isinstance(arg_2, Bool):
                arg_5 = temp_cs.new_bool()
            elif isinstance(arg_2, BitVec):
                arg_5 = temp_cs.new_bitvec(arg_2.size)
            elif isinstance(arg_2, Array):
                arg_5 = temp_cs.new_array(index_max=arg_2.index_max, value_bits=arg_2.value_bits, taint=arg_2.taint).array
            else:
                raise NotImplementedError(f"Func only implemented for {type(expression)} expression type.")

            temp_cs.add(arg_5 == arg_2)
            arg_0._reset(temp_cs.to_string(related_to=arg_5))

            arg_6 = []

            while arg_0._is_sat():
                arg_7 = arg_0._getvalue(arg_5)
                arg_6.append(arg_7)
                arg_0._assert(arg_5 != arg_7)

                if len(arg_6) >= arg_3:
                    if arg_4:
                        # do not throw an exception if set to silent
                        # Default is not silent, assume user knows
                        # what they are doing and will check the size
                        # of returned vals list (previous smtlib behavior)
                        break
                    else:
                        raise TooManySolutions(arg_6)

            return arg_6


def Func(arg_0, arg_1, arg_2):
        """
        Ask the solver for one possible result of given expression using given set of constraints.
        """
        if not issymbolic(arg_2):
            return arg_2
        assert isinstance(arg_2, (Bool, BitVec, Array))
        with arg_1 as temp_cs:
            if isinstance(arg_2, Bool):
                arg_3 = temp_cs.new_bool()
            elif isinstance(arg_2, BitVec):
                arg_3 = temp_cs.new_bitvec(arg_2.size)
            elif isinstance(arg_2, Array):
                arg_3 = []
                arg_4 = []
                for arg_5 in range(arg_2.index_max):
                    arg_6 = temp_cs.new_bitvec(arg_2.value_bits)
                    arg_3.append(arg_6)
                    temp_cs.add(arg_6 == simplify(arg_2[arg_5]))

                arg_0._reset(temp_cs)
                if not arg_0._is_sat():
                    raise SolverError('Model is not available')

                for arg_5 in range(arg_2.index_max):
                    arg_0._send('(get-value (%s))' % arg_3[arg_5].name)
                    arg_7 = arg_0._recv()
                    assert arg_7.startswith('((') and arg_7.endswith('))')
                    arg_8, arg_9 = arg_0._Func_fmt
                    arg_10 = arg_8.match(arg_7)
                    arg_11, arg_12 = arg_10.group('expr'), arg_10.group('value')
                    arg_4.append(int(arg_12, arg_9))
                return bytes(arg_4)

            temp_cs.add(arg_3 == arg_2)

            arg_0._reset(temp_cs)

        if not arg_0._is_sat():
            raise SolverError('Model is not available')

        arg_0._send('(get-value (%s))' % arg_3.name)
        arg_7 = arg_0._recv()
        if not (arg_7.startswith('((') and arg_7.endswith('))')):
            raise SolverError('SMTLIB error parsing response: %s' % arg_7)

        if isinstance(arg_2, Bool):
            return {'true': True, 'false': False}[arg_7[2:-2].split(' ')[1]]
        if isinstance(arg_2, BitVec):
            arg_8, arg_9 = arg_0._Func_fmt
            arg_10 = arg_8.match(arg_7)
            arg_11, arg_12 = arg_10.group('expr'), arg_10.group('value')
            return int(arg_12, arg_9)
        raise NotImplementedError("Func only implemented for Bool and BitVec")


def Func(arg_0, arg_1):
        """
        Colors the logging level in the logging record
        """
        if arg_0.colors_disabled:
            return arg_0.plain_levelname_format.format(arg_1)
        else:
            return arg_0.colored_levelname_format.format(arg_0.color_map[arg_1], arg_1)


def Func(arg_0, arg_1, arg_2):
    """
    Helper for finding the closest NULL or, effectively NULL byte from a starting address.

    :param Cpu cpu:
    :param ConstraintSet constrs: Constraints for current `State`
    :param int ptr: Address to start searching for a zero from
    :return: Offset from `ptr` to first byte that is 0 or an `Expression` that must be zero
    """

    arg_3 = 0
    while True:
        arg_4 = arg_0.read_int(arg_2 + arg_3, 8)

        if issymbolic(arg_4):
            if not solver.can_be_true(arg_1, arg_4 != 0):
                break
        else:
            if arg_4 == 0:
                break

        arg_3 += 1

    return arg_3


def Func(arg_0):
        """
        Return all events that all subclasses have so far registered to publish.
        """
        arg_1 = set()
        for arg_0, arg_2 in arg_0.__Func__.items():
            arg_1.update(arg_2)
        return arg_1


def Func(arg_0):
        """
        Returns a pstat.Stats instance with profiling results if `run` was called with `should_profile=True`.
        Otherwise, returns `None`.
        """
        arg_1 = os.path.join(arg_0.workspace, 'profiling.bin')
        try:
            return pstats.Stats(arg_1)
        except Exception as e:
            logger.debug(f'Failed to get profiling stats: {e}')
            return None


def Func(arg_0, arg_1=1, arg_2=None, arg_3=False):
        """
        Runs analysis.

        :param int procs: Number of parallel worker processes
        :param timeout: Analysis timeout, in seconds
        """
        assert not arg_0.Funcning, "Manticore is already Funcning."
        arg_0._start_Func()

        arg_0._last_Func_stats['time_started'] = time.time()
        with arg_0.shutdown_timeout(arg_2):
            arg_0._start_workers(arg_1, profiling=arg_3)

            arg_0._join_workers()
        arg_0._finish_Func(profiling=arg_3)


def Func(arg_0, arg_1):
        """ Enqueue it for processing """
        arg_0._states.append(arg_1)
        arg_0._lock.notify_all()
        return arg_1


def Func(arg_0):
        """ Dequeue a state with the max priority """

        # A shutdown has been requested
        if arg_0.is_shutdown():
            return None

        # if not more states in the queue, let's wait for some forks
        while len(arg_0._states) == 0:
            # if no worker is running, bail out
            if arg_0.running == 0:
                return None
            # if a shutdown has been requested, bail out
            if arg_0.is_shutdown():
                return None
            # if there ares actually some workers running, wait for state forks
            logger.debug("Waiting for available states")
            arg_0._lock.wait()

        arg_1 = arg_0._policy.choice(list(arg_0._states))
        if arg_1 is None:
            return None
        del arg_0._states[arg_0._states.index(arg_1)]
        return arg_1


def Func(arg_0, arg_1, arg_2, arg_3='ALL', arg_4=None):
        """
        Fork state on expression concretizations.
        Using policy build a list of solutions for expression.
        For the state on each solution setting the new state with setstate

        For example if expression is a Bool it may have 2 solutions. True or False.

                                 Parent
                            (expression = ??)

                   Child1                         Child2
            (expression = True)             (expression = True)
               setstate(True)                   setstate(False)

        The optional setstate() function is supposed to set the concrete value
        in the child state.

        """
        assert isinstance(arg_2, Expression)

        if arg_4 is None:
            arg_4 = lambda x, y: None

        # Find a set of solutions for expression
        arg_5 = arg_1.concretize(arg_2, arg_3)

        if not arg_5:
            raise ExecutorError("Forking on unfeasible constraint set")

        if len(arg_5) == 1:
            arg_4(arg_1, arg_5[0])
            return arg_1

        logger.info("Forking. Policy: %s. Values: %s",
                    arg_3,
                    ', '.join(f'0x{sol:x}' for arg_6 in arg_5))

        arg_0._publish('will_Func_state', arg_1, arg_2, arg_5, arg_3)

        # Build and enqueue a state for each solution
        arg_7 = []
        for arg_8 in arg_5:
            with arg_1 as new_state:
                new_state.constrain(arg_2 == arg_8)

                # and set the PC of the new state to the concrete pc-dest
                #(or other register or memory address to concrete)
                arg_4(new_state, arg_8)

                arg_0._publish('did_Func_state', new_state, arg_2, arg_8, arg_3)

                # enqueue new_state
                arg_9 = arg_0.enqueue(new_state)
                # maintain a list of children for logging purpose
                arg_7.append(arg_9)

        logger.info("Forking current state into states %r", arg_7)
        return None


def Func(arg_0):
        """
        Entry point of the Executor; called by workers to start analysis.
        """
        # policy_order=self.policy_order
        # policy=self.policy
        arg_1 = None
        arg_2 = None

        with WithKeyboardInterruptAs(arg_0.shutdown):
            # notify siblings we are about to start a Func
            arg_0._notify_start_Func()

            logger.debug("Starting Manticore Symbolic Emulator Worker (pid %d).", os.getpid())
            arg_3 = Z3Solver()
            while not arg_0.is_shutdown():
                try:  # handle fatal errors: exceptions in Manticore
                    try:  # handle external (e.g. solver) errors, and executor control exceptions
                        # select a suitable state to analyze
                        if arg_1 is None:
                            with arg_0._lock:
                                # notify siblings we are about to stop this Func
                                arg_0._notify_stop_Func()
                                try:
                                    # Select a single state_id
                                    arg_2 = arg_0.get()
                                    # load selected state from secondary storage
                                    if arg_2 is not None:
                                        arg_0._publish('will_load_state', arg_2)
                                        arg_1 = arg_0._workspace.load_state(arg_2)
                                        arg_0.forward_events_from(arg_1, True)
                                        arg_0._publish('did_load_state', arg_1, arg_2)
                                        logger.info("load state %r", arg_2)
                                    # notify siblings we have a state to play with
                                finally:
                                    arg_0._notify_start_Func()

                        # If current_state is still None. We are done.
                        if arg_1 is None:
                            logger.debug("No more states in the queue, byte bye!")
                            break

                        assert arg_1 is not None
                        assert arg_1.constraints is arg_1.platform.constraints

                        # Allows to terminate manticore worker on user request
                        while not arg_0.is_shutdown():
                            if not arg_1.execute():
                                break
                        else:
                            # Notify this worker is done
                            arg_0._publish('will_terminate_state', arg_1, arg_2, TerminateState('Shutdown'))
                            arg_1 = None

                    # Handling Forking and terminating exceptions
                    except Concretize as e:
                        # expression
                        # policy
                        # setstate()
                        logger.debug("Generic state fork on condition")
                        arg_1 = arg_0.fork(arg_1, e.expression, e.policy, e.setstate)

                    except TerminateState as e:
                        # Notify this worker is done
                        arg_0._publish('will_terminate_state', arg_1, arg_2, e)

                        logger.debug("Generic terminate state")
                        if e.testcase:
                            arg_0._publish('internal_generate_testcase', arg_1, message=str(e))
                        arg_1 = None

                    except SolverError as e:
                        # raise
                        import traceback
                        arg_4 = traceback.format_exc()
                        logger.error("Exception: %s\n%s", str(e), arg_4)

                        # Notify this state is done
                        arg_0._publish('will_terminate_state', arg_1, arg_2, e)

                        if arg_3.check(arg_1.constraints):
                            arg_0._publish('internal_generate_testcase', arg_1, message="Solver failed" + str(e))
                        arg_1 = None

                except (Exception, AssertionError) as e:
                    # raise
                    import traceback
                    arg_4 = traceback.format_exc()
                    logger.error("Exception: %s\n%s", str(e), arg_4)
                    # Notify this worker is done
                    arg_0._publish('will_terminate_state', arg_1, arg_2, e)
                    arg_1 = None

            assert arg_1 is None or arg_0.is_shutdown()

            # notify siblings we are about to stop this Func
            arg_0._notify_stop_Func()


def Func(arg_0, arg_1, arg_2='', **arg_3):
        """
        Constructor for Decree binary analysis.

        :param str path: Path to binary to analyze
        :param str concrete_start: Concrete stdin to use before symbolic input
        :param kwargs: Forwarded to the Manticore constructor
        :return: Manticore instance, initialized with a Decree State
        :rtype: Manticore
        """
        try:
            return arg_0(_make_Func(arg_1, arg_2), **arg_3)
        except KeyError:  # FIXME(mark) magic parsing for DECREE should raise better error
            raise Exception(f'Invalid binary: {path}')


def Func(arg_0, arg_1, arg_2, arg_3):
        'Invoke all registered generic hooks'

        # Ignore symbolic pc.
        # TODO(yan): Should we ask the solver if any of the hooks are possible,
        # and execute those that are?

        if issymbolic(arg_2):
            return

        # Invoke all pc-specific hooks
        for arg_4 in arg_0._hooks.get(arg_2, []):
            arg_4(arg_1)

        # Invoke all pc-agnostic hooks
        for arg_4 in arg_0._hooks.get(None, []):
            arg_4(arg_1)


def Func(arg_0, arg_1):
        """
        A helper method used to Func a symbol name into a memory address when
        injecting hooks for analysis.

        :param symbol: function name to be Funcd
        :type symbol: string

        :param line: if more functions present, optional line number can be included
        :type line: int or None
        """

        with open(arg_0.binary_path, 'rb') as f:

            arg_2 = ELFFile(f)

            # iterate over sections and identify symbol table section
            for arg_3 in arg_2.iter_sections():
                if not isinstance(arg_3, SymbolTableSection):
                    continue

                # get list of symbols by name
                arg_4 = arg_3.get_symbol_by_name(arg_1)
                if not arg_4:
                    continue

                # return first indexed memory address for the symbol,
                return arg_4[0].entry['st_value']

            raise ValueError(f"The {self.binary_path} ELFfile does not contain symbol {symbol}")


def Func(arg_0):
    """
    helper method for getting all binary symbols with SANDSHREW_ prepended.
    We do this in order to provide the symbols Manticore should hook on to
    perform main analysis.

    :param binary: str for binary to instrospect.
    :rtype list: list of symbols from binary
    """

    def substr_after(arg_1, arg_2):
        return arg_1.partition(arg_2)[2]

    with open(arg_0, 'rb') as f:
        arg_3 = ELFFile(f)

        for arg_4 in arg_3.iter_sections():
            if not isinstance(arg_4, SymbolTableSection):
                continue

            arg_5 = [sym.name for sym in arg_4.iter_symbols() if sym]
            return [substr_after(arg_6, PREPEND_SYM) for arg_6 in arg_5
                    if arg_6.startswith(PREPEND_SYM)]


def Func(arg_0: arg_1) -> _Group:
    """
    Get a configuration variable group named |name|
    """
    global arg_3

    if arg_0 in arg_3:
        return arg_3[arg_0]

    arg_2 = _Group(arg_0)
    arg_3[arg_0] = arg_2

    return arg_2


def Func(arg_0):
    """
    Save current config state to an yml file stream identified by |f|

    :param f: where to write the config file
    """
    global _groups

    arg_1 = {}
    for arg_2, arg_3 in _groups.items():
        arg_4 = {var.name: var.value for var in arg_3.updated_vars()}
        if not arg_4:
            continue
        arg_1[arg_2] = arg_4

    yaml.safe_dump(arg_1, arg_0, line_break=True)


def Func(arg_0):
    """
    Load an yml-formatted configuration from file stream |f|

    :param file f: Where to read the config.
    """

    try:
        arg_1 = yaml.safe_load(arg_0)
        for arg_2, arg_3 in arg_1.items():
            arg_4 = get_group(arg_2)

            for arg_5, arg_6 in arg_3.items():
                arg_4.update(arg_5)
                setattr(arg_4, arg_5, arg_6)
    # Any exception here should trigger the warning; from not being able to parse yaml
    # to reading poorly formatted values
    except Exception:
        raise ConfigError("Failed reading config file. Do you have a local [.]manticore.yml file?")


def Func(arg_0=None):
    """
    Load config overrides from the yml file at |path|, or from default paths. If a path
    is provided and it does not exist, raise an exception

    Default paths: ./mcore.yml, ./.mcore.yml, ./manticore.yml, ./.manticore.yml.
    """

    if arg_0 is not None:
        arg_1 = [arg_0]
    else:
        arg_2 = ['mcore.yml', 'manticore.yml']
        arg_1 = [os.path.join('.', ''.join(x)) for x in product(['', '.'], arg_2)]

    for arg_3 in arg_1:
        try:
            with open(arg_3, 'r') as yml_f:
                logger.info(f'Reading configuration from {name}')
                parse_config(yml_f)
            break
        except FileNotFoundError:
            pass
    else:
        if arg_0 is not None:
            raise FileNotFoundError(f"'{path}' not found for config overrides")


def Func(arg_0: arg_1.ArgumentParser, arg_3: arg_1.Namespace):
    """
    Bring in provided config values to the args parser, and import entries to the config
    from all arguments that were actually passed on the command line

    :param parser: The arg parser
    :param args: The value that parser.parse_args returned
    """
    # First, load a local config file, if passed or look for one in pwd if it wasn't.
    load_overrides(arg_3.config)

    # Get a list of defined config vals. If these are passed on the command line,
    # update them in their correct group, not in the cli group
    arg_5 = list(get_config_keys())

    arg_6 = vars(arg_3)

    # Bring in the options keys into args
    arg_7 = get_group('cli')

    # Place all command line args into the cli group (for saving in the workspace). If
    # the value is set on command line, then it takes precedence; otherwise we try to
    # read it from the config file's cli group.
    for arg_8 in arg_6:
        arg_9 = arg_0.get_default(arg_8)
        arg_10 = getattr(arg_3, arg_8)
        if arg_9 is not arg_10:
            if arg_8 not in arg_5:
                arg_7.update(arg_8, value=arg_10)
            else:
                # Update a var's native group
                arg_11, arg_12 = arg_8.split('.')
                arg_13 = get_group(arg_11)
                setattr(arg_13, arg_12, arg_10)
        else:
            if arg_8 in arg_7:
                setattr(arg_3, arg_8, getattr(arg_7, arg_8))


def Func(arg_0, arg_1: arg_2, arg_3=None, arg_4=None, arg_5: arg_2=None):
        """
        Like add, but can tolerate existing values; also Funcs the value.

        Mostly used for setting fields from imported INI files and modified CLI flags.
        """
        if arg_1 in arg_0._vars:
            arg_5 = arg_5 or arg_0._vars[arg_1].description
            arg_4 = arg_4 or arg_0._vars[arg_1].default
        elif arg_1 == 'name':
            raise ConfigError("'name' is a reserved name for a group.")

        arg_6 = _Var(arg_1, arg_5=arg_5, arg_4=arg_4, defined=False)
        arg_6.value = arg_3
        arg_0._vars[arg_1] = arg_6


def Func(arg_0, arg_1: arg_2) -> arg_2:
        """
        Return the description, or a help string of variable identified by |name|.
        """
        if arg_1 not in arg_0._vars:
            raise ConfigError(f"{self.name}.{name} not defined.")

        return arg_0._vars[arg_1].description