static void tcg_out_modrm_sib_offset(TCGContext *s, int opc, int r, int rm,

                                     int index, int shift, intptr_t offset)

{

    int mod, len;



    if (index < 0 && rm < 0) {

        if (TCG_TARGET_REG_BITS == 64) {

            /* Try for a rip-relative addressing mode.  This has replaced

               the 32-bit-mode absolute addressing encoding.  */

            intptr_t pc = (intptr_t)s->code_ptr + 5 + ~rm;

            intptr_t disp = offset - pc;

            if (disp == (int32_t)disp) {

                tcg_out_opc(s, opc, r, 0, 0);

                tcg_out8(s, (LOWREGMASK(r) << 3) | 5);

                tcg_out32(s, disp);

                return;

            }



            /* Try for an absolute address encoding.  This requires the

               use of the MODRM+SIB encoding and is therefore larger than

               rip-relative addressing.  */

            if (offset == (int32_t)offset) {

                tcg_out_opc(s, opc, r, 0, 0);

                tcg_out8(s, (LOWREGMASK(r) << 3) | 4);

                tcg_out8(s, (4 << 3) | 5);

                tcg_out32(s, offset);

                return;

            }



            /* ??? The memory isn't directly addressable.  */

            tcg_abort();

        } else {

            /* Absolute address.  */

            tcg_out_opc(s, opc, r, 0, 0);

            tcg_out8(s, (r << 3) | 5);

            tcg_out32(s, offset);

            return;

        }

    }



    /* Find the length of the immediate addend.  Note that the encoding

       that would be used for (%ebp) indicates absolute addressing.  */

    if (rm < 0) {

        mod = 0, len = 4, rm = 5;

    } else if (offset == 0 && LOWREGMASK(rm) != TCG_REG_EBP) {

        mod = 0, len = 0;

    } else if (offset == (int8_t)offset) {

        mod = 0x40, len = 1;

    } else {

        mod = 0x80, len = 4;

    }



    /* Use a single byte MODRM format if possible.  Note that the encoding

       that would be used for %esp is the escape to the two byte form.  */

    if (index < 0 && LOWREGMASK(rm) != TCG_REG_ESP) {

        /* Single byte MODRM format.  */

        tcg_out_opc(s, opc, r, rm, 0);

        tcg_out8(s, mod | (LOWREGMASK(r) << 3) | LOWREGMASK(rm));

    } else {

        /* Two byte MODRM+SIB format.  */



        /* Note that the encoding that would place %esp into the index

           field indicates no index register.  In 64-bit mode, the REX.X

           bit counts, so %r12 can be used as the index.  */

        if (index < 0) {

            index = 4;

        } else {

            assert(index != TCG_REG_ESP);

        }



        tcg_out_opc(s, opc, r, rm, index);

        tcg_out8(s, mod | (LOWREGMASK(r) << 3) | 4);

        tcg_out8(s, (shift << 6) | (LOWREGMASK(index) << 3) | LOWREGMASK(rm));

    }



    if (len == 1) {

        tcg_out8(s, offset);

    } else if (len == 4) {

        tcg_out32(s, offset);

    }

}

static void tcg_out_modrm_sib_offset(TCGContext *s, int opc, int r, int rm,

                                     int index, int shift, intptr_t offset)

{

    int mod, len;



    if (index < 0 && rm < 0) {

        if (TCG_TARGET_REG_BITS == 64) {

            



            intptr_t pc = (intptr_t)s->code_ptr + 5 + ~rm;

            intptr_t disp = offset - pc;

            if (disp == (int32_t)disp) {

                tcg_out_opc(s, opc, r, 0, 0);

                tcg_out8(s, (LOWREGMASK(r) << 3) | 5);

                tcg_out32(s, disp);

                return;

            }



            





            if (offset == (int32_t)offset) {

                tcg_out_opc(s, opc, r, 0, 0);

                tcg_out8(s, (LOWREGMASK(r) << 3) | 4);

                tcg_out8(s, (4 << 3) | 5);

                tcg_out32(s, offset);

                return;

            }



            

            tcg_abort();

        } else {

            

            tcg_out_opc(s, opc, r, 0, 0);

            tcg_out8(s, (r << 3) | 5);

            tcg_out32(s, offset);

            return;

        }

    }



    



    if (rm < 0) {

        mod = 0, len = 4, rm = 5;

    } else if (offset == 0 && LOWREGMASK(rm) != TCG_REG_EBP) {

        mod = 0, len = 0;

    } else if (offset == (int8_t)offset) {

        mod = 0x40, len = 1;

    } else {

        mod = 0x80, len = 4;

    }



    



    if (index < 0 && LOWREGMASK(rm) != TCG_REG_ESP) {

        

        tcg_out_opc(s, opc, r, rm, 0);

        tcg_out8(s, mod | (LOWREGMASK(r) << 3) | LOWREGMASK(rm));

    } else {

        



        





        if (index < 0) {

            index = 4;

        } else {

            assert(index != TCG_REG_ESP);

        }



        tcg_out_opc(s, opc, r, rm, index);

        tcg_out8(s, mod | (LOWREGMASK(r) << 3) | 4);

        tcg_out8(s, (shift << 6) | (LOWREGMASK(index) << 3) | LOWREGMASK(rm));

    }



    if (len == 1) {

        tcg_out8(s, offset);

    } else if (len == 4) {

        tcg_out32(s, offset);

    }

}

static void FUNC_0(TCGContext *VAR_0, int VAR_1, int VAR_2, int VAR_3,

                                     int VAR_4, int VAR_5, intptr_t VAR_6)

{

    int VAR_7, VAR_8;



    if (VAR_4 < 0 && VAR_3 < 0) {

        if (TCG_TARGET_REG_BITS == 64) {

            



            intptr_t pc = (intptr_t)VAR_0->code_ptr + 5 + ~VAR_3;

            intptr_t disp = VAR_6 - pc;

            if (disp == (int32_t)disp) {

                tcg_out_opc(VAR_0, VAR_1, VAR_2, 0, 0);

                tcg_out8(VAR_0, (LOWREGMASK(VAR_2) << 3) | 5);

                tcg_out32(VAR_0, disp);

                return;

            }



            





            if (VAR_6 == (int32_t)VAR_6) {

                tcg_out_opc(VAR_0, VAR_1, VAR_2, 0, 0);

                tcg_out8(VAR_0, (LOWREGMASK(VAR_2) << 3) | 4);

                tcg_out8(VAR_0, (4 << 3) | 5);

                tcg_out32(VAR_0, VAR_6);

                return;

            }



            

            tcg_abort();

        } else {

            

            tcg_out_opc(VAR_0, VAR_1, VAR_2, 0, 0);

            tcg_out8(VAR_0, (VAR_2 << 3) | 5);

            tcg_out32(VAR_0, VAR_6);

            return;

        }

    }



    



    if (VAR_3 < 0) {

        VAR_7 = 0, VAR_8 = 4, VAR_3 = 5;

    } else if (VAR_6 == 0 && LOWREGMASK(VAR_3) != TCG_REG_EBP) {

        VAR_7 = 0, VAR_8 = 0;

    } else if (VAR_6 == (int8_t)VAR_6) {

        VAR_7 = 0x40, VAR_8 = 1;

    } else {

        VAR_7 = 0x80, VAR_8 = 4;

    }



    



    if (VAR_4 < 0 && LOWREGMASK(VAR_3) != TCG_REG_ESP) {

        

        tcg_out_opc(VAR_0, VAR_1, VAR_2, VAR_3, 0);

        tcg_out8(VAR_0, VAR_7 | (LOWREGMASK(VAR_2) << 3) | LOWREGMASK(VAR_3));

    } else {

        



        





        if (VAR_4 < 0) {

            VAR_4 = 4;

        } else {

            assert(VAR_4 != TCG_REG_ESP);

        }



        tcg_out_opc(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4);

        tcg_out8(VAR_0, VAR_7 | (LOWREGMASK(VAR_2) << 3) | 4);

        tcg_out8(VAR_0, (VAR_5 << 6) | (LOWREGMASK(VAR_4) << 3) | LOWREGMASK(VAR_3));

    }



    if (VAR_8 == 1) {

        tcg_out8(VAR_0, VAR_6);

    } else if (VAR_8 == 4) {

        tcg_out32(VAR_0, VAR_6);

    }

}

static void FUNC_0(TCGContext *VAR_0, int VAR_1, int VAR_2, int VAR_3,
int VAR_4, int VAR_5, intptr_t VAR_6)
{ int VAR_7, VAR_8; if (VAR_4 < 0 && VAR_3 < 0) { if (TCG_TARGET_REG_BITS == 64) { intptr_t pc = (intptr_t)VAR_0->code_ptr + 5 + ~VAR_3; intptr_t disp = VAR_6 - pc; if (disp == (int32_t)disp) { tcg_out_opc(VAR_0, VAR_1, VAR_2, 0, 0); tcg_out8(VAR_0, (LOWREGMASK(VAR_2) << 3) | 5); tcg_out32(VAR_0, disp); return; } if (VAR_6 == (int32_t)VAR_6) { tcg_out_opc(VAR_0, VAR_1, VAR_2, 0, 0); tcg_out8(VAR_0, (LOWREGMASK(VAR_2) << 3) | 4); tcg_out8(VAR_0, (4 << 3) | 5); tcg_out32(VAR_0, VAR_6); return; } tcg_abort(); } else { tcg_out_opc(VAR_0, VAR_1, VAR_2, 0, 0); tcg_out8(VAR_0, (VAR_2 << 3) | 5); tcg_out32(VAR_0, VAR_6); return; } } if (VAR_3 < 0) { VAR_7 = 0, VAR_8 = 4, VAR_3 = 5; } else if (VAR_6 == 0 && LOWREGMASK(VAR_3) != TCG_REG_EBP) { VAR_7 = 0, VAR_8 = 0; } else if (VAR_6 == (int8_t)VAR_6) { VAR_7 = 0x40, VAR_8 = 1; } else { VAR_7 = 0x80, VAR_8 = 4; } if (VAR_4 < 0 && LOWREGMASK(VAR_3) != TCG_REG_ESP) { tcg_out_opc(VAR_0, VAR_1, VAR_2, VAR_3, 0); tcg_out8(VAR_0, VAR_7 | (LOWREGMASK(VAR_2) << 3) | LOWREGMASK(VAR_3)); } else { if (VAR_4 < 0) { VAR_4 = 4; } else { assert(VAR_4 != TCG_REG_ESP); } tcg_out_opc(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4); tcg_out8(VAR_0, VAR_7 | (LOWREGMASK(VAR_2) << 3) | 4); tcg_out8(VAR_0, (VAR_5 << 6) | (LOWREGMASK(VAR_4) << 3) | LOWREGMASK(VAR_3)); } if (VAR_8 == 1) { tcg_out8(VAR_0, VAR_6); } else if (VAR_8 == 4) { tcg_out32(VAR_0, VAR_6); } }