// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rcx, -0xc(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
cmpl $0x3, -0x30(%rbp)
jle 0xa5f0
cmpl $0x1, -0x2c(%rbp)
jne 0xa5d4
movl $0x0, -0x4(%rbp)
jmp 0xa86b
movq -0x18(%rbp), %rdi
callq 0x31d0
cmpl $0x0, %eax
jne 0xa5ee
movl $0x0, -0x4(%rbp)
jmp 0xa86b
jmp 0xa5f0
cmpl $0x1, -0x2c(%rbp)
jne 0xa5fc
movb $0x3, -0x31(%rbp)
jmp 0xa64f
movl -0x30(%rbp), %eax
movq %rax, -0x58(%rbp)
subq $0x5, %rax
ja 0xa641
movq -0x58(%rbp), %rax
leaq 0x22ac(%rip), %rcx      # 0xc8c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, -0x31(%rbp)
jmp 0xa64d
movb $0x1, -0x31(%rbp)
jmp 0xa64d
movb $0x2, -0x31(%rbp)
jmp 0xa64d
movb $0x40, -0x31(%rbp)
jmp 0xa64d
movb $0x41, -0x31(%rbp)
jmp 0xa64d
movb $0x3, -0x31(%rbp)
jmp 0xa64d
movl $0x0, -0x4(%rbp)
jmp 0xa86b
jmp 0xa64f
movq -0x18(%rbp), %rdi
callq 0x31d0
cmpl $0x0, %eax
je 0xa68f
cmpl $0x0, 0x10(%rbp)
je 0xa66d
movzbl -0x31(%rbp), %eax
orl $0x4, %eax
movb %al, -0x31(%rbp)
cmpl $0x0, 0x18(%rbp)
je 0xa67d
movzbl -0x31(%rbp), %eax
orl $0x8, %eax
movb %al, -0x31(%rbp)
cmpl $0x0, 0x20(%rbp)
je 0xa68d
movzbl -0x31(%rbp), %eax
orl $0x10, %eax
movb %al, -0x31(%rbp)
jmp 0xa68f
cmpl $0x2, -0x2c(%rbp)
jne 0xa69f
movzbl -0x31(%rbp), %eax
addl $0x20, %eax
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
addb $0x20, %al
movb %al, -0x31(%rbp)
movl -0x8(%rbp), %eax
addl $0x21, %eax
movl %eax, -0x38(%rbp)
movl -0xc(%rbp), %eax
addl $0x21, %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x48(%rax), %eax
movl %eax, -0x5c(%rbp)
testl %eax, %eax
je 0xa6e5
jmp 0xa6ca
movl -0x5c(%rbp), %eax
subl $0x1, %eax
je 0xa72d
jmp 0xa6d4
movl -0x5c(%rbp), %eax
subl $0x2, %eax
je 0xa81a
jmp 0xa864
cmpl $0xff, -0x38(%rbp)
jg 0xa6f7
cmpl $0xff, -0x3c(%rbp)
jle 0xa703
movl $0x0, -0x4(%rbp)
jmp 0xa86b
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movzbl -0x31(%rbp), %ecx
movl -0x38(%rbp), %r8d
movl -0x3c(%rbp), %r9d
leaq 0x220f(%rip), %rdx      # 0xc92d
movb $0x0, %al
callq 0x32a0
movl %eax, -0x4(%rbp)
jmp 0xa86b
movzbl -0x31(%rbp), %eax
cmpl $0x7f, %eax
jle 0xa75d
movzbl -0x31(%rbp), %eax
sarl $0x3, %eax
orl $0xc0, %eax
movb %al, -0x3e(%rbp)
movzbl -0x31(%rbp), %eax
andl $0x6f, %eax
orl $0x80, %eax
movb %al, -0x3d(%rbp)
movl $0x2, -0x48(%rbp)
jmp 0xa76a
movb -0x31(%rbp), %al
movb %al, -0x3e(%rbp)
movl $0x1, -0x48(%rbp)
cmpl $0x7f, -0x38(%rbp)
jle 0xa795
movl -0x38(%rbp), %eax
sarl $0x6, %eax
orl $0xc0, %eax
movb %al, -0x40(%rbp)
movl -0x38(%rbp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, -0x3f(%rbp)
movl $0x2, -0x4c(%rbp)
jmp 0xa7a2
movl -0x38(%rbp), %eax
movb %al, -0x40(%rbp)
movl $0x1, -0x4c(%rbp)
cmpl $0x7f, -0x3c(%rbp)
jle 0xa7cd
movl -0x3c(%rbp), %eax
sarl $0x6, %eax
orl $0xc0, %eax
movb %al, -0x42(%rbp)
movl -0x3c(%rbp), %eax
andl $0x3f, %eax
orl $0x80, %eax
movb %al, -0x41(%rbp)
movl $0x2, -0x50(%rbp)
jmp 0xa7da
movl -0x3c(%rbp), %eax
movb %al, -0x42(%rbp)
movl $0x1, -0x50(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x48(%rbp), %ecx
leaq -0x3e(%rbp), %r8
movl -0x4c(%rbp), %r9d
leaq -0x40(%rbp), %r11
movl -0x50(%rbp), %r10d
leaq -0x42(%rbp), %rax
leaq 0x2137(%rip), %rdx      # 0xc937
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x32a0
movl %eax, -0x4(%rbp)
jmp 0xa86b
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movzbl -0x31(%rbp), %ecx
subl $0x20, %ecx
movl -0x38(%rbp), %r8d
subl $0x20, %r8d
movl -0x3c(%rbp), %r9d
subl $0x20, %r9d
movl -0x2c(%rbp), %r10d
movl $0x4d, %eax
movl $0x6d, %edx
cmpl $0x1, %r10d
cmovel %edx, %eax
leaq 0x20f2(%rip), %rdx      # 0xc947
movl %eax, (%rsp)
movb $0x0, %al
callq 0x32a0
movl %eax, -0x4(%rbp)
jmp 0xa86b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)