// File: /workspace/github_c_makefile_star2_O2/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 0x38ebf
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 0x38ebf
movq %rdi, %rbx
pushq $0x1
popq %rdi
pushq $0x50
popq %rsi
callq 0xc850
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x38ece
movzwl %r13w, %r14d
leaq 0x30(%rsp), %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0xca60
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 0x38e3f
movzwl %ax, %edx
leaq 0x10(%rsp), %rdi
callq 0xca60
jmp 0x38e61
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 0xcd90
movq 0x8(%rsp), %r12
leaq 0xc(%r12), %rdi
leaq 0xb01e(%rip), %r14      # 0x43e90
pushq $0x1c
popq %r15
leaq 0x30(%rsp), %rcx
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0xc5b0
leaq 0x28(%r12), %rdi
leaq 0x10(%rsp), %rcx
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0xc5b0
movq %r12, %rax
addq $0x48, %rax
andq $0x0, 0x48(%r12)
movq 0x48(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq %r12, (%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
movq 0x1a123(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x4201(%rip), %rsi      # 0x3d0e0
leaq 0xaafa(%rip), %rdx      # 0x439e0
movl $0x24f0, %ecx           # imm = 0x24F0
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc8d0