// File: /workspace/github_c_makefile_star2_O1/doy[P]libvt100/src/screen.c
// Function: vt100_screen_format_mouse_reporting_response
int vt100_screen_format_mouse_reporting_response(
    VT100Screen *vt, char *buf, size_t len, struct vt100_loc loc,
    int event_type, int button, int shift, int alt, int ctrl)
{
    unsigned char status;
    int x, y;

    if (button > VT100_BUTTON_RIGHT) {
        /* don't care about button release events for scroll wheel */
        if (event_type == VT100_BUTTONEVENT_RELEASE) {
            return 0;
        }

        /* don't care about scroll wheel events for x10 mode */
        if (!vt100_screen_mouse_reporting_wants_button_release(vt)) {
            return 0;
        }
    }

    if (event_type == VT100_BUTTONEVENT_RELEASE) {
        status = 3;
    }
    else {
        switch (button) {
        case VT100_BUTTON_LEFT:
            status = 0;
            break;
        case VT100_BUTTON_MIDDLE:
            status = 1;
            break;
        case VT100_BUTTON_RIGHT:
            status = 2;
            break;
        case VT100_BUTTON_SCROLL_UP:
            status = 64;
            break;
        case VT100_BUTTON_SCROLL_DOWN:
            status = 65;
            break;
        case VT100_BUTTON_NONE:
            status = 3;
            break;
        default:
            return 0;
        }
    }

    /* don't care about modifier keys in x10 mode */
    if (vt100_screen_mouse_reporting_wants_button_release(vt)) {
        if (shift) {
            status |= 4;
        }
        if (alt) {
            status |= 8;
        }
        if (ctrl) {
            status |= 16;
        }
    }

    if (event_type == VT100_BUTTONEVENT_MOTION) {
        status += 32;
    }

    status += 32;
    x = loc.col + 1 + 32;
    y = loc.row + 1 + 32;

    switch (vt->mouse_reporting_mode) {
    case VT100_MOUSEREPORTING_NORMAL:
        if (x > 255 || y > 255) {
            return 0;
        }

        return snprintf(buf, len, "\033[M%c%c%c", status, x, y);
    case VT100_MOUSEREPORTING_UTF8: {
        char status_bytes[2], x_bytes[2], y_bytes[2];
        int status_len, x_len, y_len;

        if (status > 0x7F) {
            status_bytes[0] = 0xC0 | (status >> 3);
            status_bytes[1] = 0x80 | (status & 0x6F);
            status_len = 2;
        }
        else {
            status_bytes[0] = status;
            status_len = 1;
        }

        if (x > 0x7F) {
            x_bytes[0] = 0xC0 | (x >> 6);
            x_bytes[1] = 0x80 | (x & 0x3F);
            x_len = 2;
        }
        else {
            x_bytes[0] = x;
            x_len = 1;
        }

        if (y > 0x7F) {
            y_bytes[0] = 0xC0 | (y >> 6);
            y_bytes[1] = 0x80 | (y & 0x3F);
            y_len = 2;
        }
        else {
            y_bytes[0] = y;
            y_len = 1;
        }

        return snprintf(
            buf, len, "\033[M%.*s%.*s%.*s", status_len, status_bytes, x_len,
            x_bytes, y_len, y_bytes);
    }
    case VT100_MOUSEREPORTING_SGR:
        return snprintf(
            buf, len, "\033[<%d;%d;%d%c", status - 32, x - 32, y - 32,
            event_type == VT100_BUTTONEVENT_RELEASE ? 'm' : 'M');
    default:
        return 0;
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %r8d, %r11d
movq %rcx, %r10
movl 0x40(%rsp), %ebx
movl 0x38(%rsp), %ebp
movl 0x30(%rsp), %r14d
cmpl $0x4, %r9d
jl 0x7523
xorl %eax, %eax
cmpl $0x1, %r11d
je 0x76f4
testb $0x70, 0x49(%rdi)
je 0x76f4
movb $0x3, %al
cmpl $0x1, %r11d
je 0x754b
xorl %eax, %eax
cmpl $0x5, %r9d
ja 0x76f4
shll $0x3, %r9d
movabsq $0x414002010003, %rax   # imm = 0x414002010003
movl %r9d, %ecx
shrq %cl, %rax
movq %r10, %r8
shrq $0x20, %r8
testb $0x70, 0x49(%rdi)
je 0x757f
movzbl %al, %ecx
orb $0x4, %al
testl %r14d, %r14d
movzbl %al, %eax
cmovel %ecx, %eax
movl %eax, %ecx
orb $0x8, %cl
testl %ebp, %ebp
movzbl %cl, %ecx
cmovel %eax, %ecx
movl %ecx, %eax
orb $0x10, %al
testl %ebx, %ebx
movzbl %al, %eax
cmovel %ecx, %eax
leal 0x20(%rax), %ecx
cmpl $0x2, %r11d
movzbl %al, %eax
movzbl %cl, %ecx
cmovnel %eax, %ecx
movzbl 0x48(%rdi), %edi
cmpl $0x2, %edi
je 0x7602
addb $0x20, %cl
leal 0x21(%r8), %r11d
leal 0x21(%r10), %r9d
cmpl $0x1, %edi
je 0x75f3
xorl %eax, %eax
testl %edi, %edi
jne 0x76f4
movl $0xdf, %edi
cmpl %edi, %r8d
setge %r8b
cmpl %edi, %r10d
setge %dil
orb %r8b, %dil
jne 0x76f4
movzbl %cl, %ecx
leaq 0x2375(%rip), %rax      # 0x994d
movq %rsi, %rdi
movq %rdx, %rsi
movq %rax, %rdx
movl %r11d, %r8d
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x3270
testb %cl, %cl
js 0x7642
movb %cl, 0xe(%rsp)
movl $0x1, %ecx
jmp 0x7659
xorl %ebx, %ebx
cmpl $0x1, %r11d
sete %bl
incl %r10d
incl %r8d
movzbl %cl, %ecx
shll $0x5, %ebx
orl $0x4d, %ebx
subq $0x8, %rsp
leaq 0x2342(%rip), %rax      # 0x9967
movq %rsi, %rdi
movq %rdx, %rsi
movq %rax, %rdx
movl %r10d, %r9d
xorl %eax, %eax
pushq %rbx
callq 0x3270
addq $0x20, %rsp
jmp 0x76f8
movl %ecx, %eax
shrb $0x3, %al
orb $-0x40, %al
movb %al, 0xe(%rsp)
andb $-0x11, %cl
movb %cl, 0xf(%rsp)
movl $0x2, %ecx
cmpl $0x5f, %r8d
jl 0x767f
movl %r11d, %eax
shrl $0x6, %eax
orb $-0x40, %al
movb %al, 0xc(%rsp)
andb $0x3f, %r11b
orb $-0x80, %r11b
movb %r11b, 0xd(%rsp)
movl $0x2, %eax
jmp 0x7689
movb %r11b, 0xc(%rsp)
movl $0x1, %eax
cmpl $0x5f, %r10d
jl 0x76b3
movl %r9d, %edi
shrl $0x6, %edi
orb $-0x40, %dil
movb %dil, 0xa(%rsp)
andb $0x3f, %r9b
orb $-0x80, %r9b
movb %r9b, 0xb(%rsp)
movl $0x2, %r10d
jmp 0x76be
movb %r9b, 0xa(%rsp)
movl $0x1, %r10d
subq $0x8, %rsp
leaq 0x12(%rsp), %r11
leaq 0x14(%rsp), %rbx
leaq 0x2284(%rip), %r9       # 0x9957
leaq 0x16(%rsp), %r8
movq %rsi, %rdi
movq %rdx, %rsi
movq %r9, %rdx
movl %eax, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
pushq %rbx
callq 0x3270
addq $0x20, %rsp
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq