// File: /workspace/github_c_makefile_star2_O1/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_set_selection
void
worksheet_set_selection(lxw_worksheet *self,
                        lxw_row_t first_row, lxw_col_t first_col,
                        lxw_row_t last_row, lxw_col_t last_col)
{
    lxw_selection *selection;
    lxw_row_t tmp_row;
    lxw_col_t tmp_col;
    char active_cell[LXW_MAX_CELL_RANGE_LENGTH];
    char sqref[LXW_MAX_CELL_RANGE_LENGTH];

    /* Only allow selection to be set once to avoid freeing/re-creating it. */
    if (!STAILQ_EMPTY(self->selections))
        return;

    /* Excel doesn't set a selection for cell A1 since it is the default. */
    if (first_row == 0 && first_col == 0 && last_row == 0 && last_col == 0)
        return;

    selection = calloc(1, sizeof(lxw_selection));
    RETURN_VOID_ON_MEM_ERROR(selection);

    /* Set the cell range selection. Do this before swapping max/min to  */
    /* allow the selection direction to be reversed. */
    lxw_rowcol_to_cell(active_cell, first_row, first_col);

    /* Swap last row/col for first row/col if necessary. */
    if (first_row > last_row) {
        tmp_row = first_row;
        first_row = last_row;
        last_row = tmp_row;
    }

    if (first_col > last_col) {
        tmp_col = first_col;
        first_col = last_col;
        last_col = tmp_col;
    }

    /* If the first and last cell are the same write a single cell. */
    if ((first_row == last_row) && (first_col == last_col))
        lxw_rowcol_to_cell(sqref, first_row, first_col);
    else
        lxw_rowcol_to_range(sqref, first_row, first_col, last_row, last_col);

    lxw_strcpy(selection->pane, "");
    lxw_strcpy(selection->active_cell, active_cell);
    lxw_strcpy(selection->sqref, sqref);

    STAILQ_INSERT_TAIL(self->selections, selection, list_pointers);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq 0x48(%rdi), %rax
cmpq $0x0, (%rax)
jne 0x3bc05
movl %r8d, %r15d
movl %ecx, %ebp
movl %edx, %r13d
movl %esi, %r12d
movl %ecx, %eax
orl %esi, %eax
sete %al
movl %r15d, %ecx
orw %r13w, %cx
sete %cl
testb %cl, %al
jne 0x3bc05
movq %rdi, %rbx
movl $0x1, %edi
movl $0x50, %esi
callq 0xc7f0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x3bc14
movzwl %r13w, %r14d
leaq 0x30(%rsp), %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0xca00
cmpl %ebp, %r12d
movl %ebp, %esi
cmovbl %r12d, %esi
cmpw %r15w, %r14w
movl %r15d, %eax
cmovbl %r14d, %eax
cmpl %r12d, %ebp
setne %cl
cmpw %r14w, %r15w
setne %dl
orb %cl, %dl
jne 0x3bb81
movzwl %ax, %edx
leaq 0x10(%rsp), %rdi
callq 0xca00
jmp 0x3bba3
cmpw %r15w, %r13w
cmoval %r13d, %r15d
cmpl %ebp, %r12d
cmoval %r12d, %ebp
movzwl %r15w, %r8d
movzwl %ax, %edx
leaq 0x10(%rsp), %rdi
movl %ebp, %ecx
callq 0xcd10
movq 0x8(%rsp), %r15
movb $0x0, (%r15)
leaq 0xc(%r15), %rdi
leaq 0xb201(%rip), %r14      # 0x46db8
leaq 0x30(%rsp), %rcx
movl $0x1c, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xc570
leaq 0x28(%r15), %rdi
leaq 0x10(%rsp), %rcx
movl $0x1c, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xc570
movq %r15, %rax
addq $0x48, %rax
movq $0x0, 0x48(%r15)
movq 0x48(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %r15, (%rcx)
movq 0x48(%rbx), %rcx
movq %rax, 0x8(%rcx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xf44d
jmp 0x3bc05