// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_data_validation_range
lxw_error
worksheet_data_validation_range(lxw_worksheet *self, lxw_row_t first_row,
                                lxw_col_t first_col,
                                lxw_row_t last_row,
                                lxw_col_t last_col,
                                lxw_data_validation *validation)
{
    lxw_data_val_obj *copy;
    uint8_t is_between = LXW_FALSE;
    uint8_t is_formula = LXW_FALSE;
    uint8_t has_criteria = LXW_TRUE;
    lxw_error err;
    lxw_row_t tmp_row;
    lxw_col_t tmp_col;
    size_t length;

    /* No action is required for validation type 'any' unless there are
     * input messages to display.*/
    if (validation->validate == LXW_VALIDATION_TYPE_ANY
        && !(validation->input_title || validation->input_message)) {

        return LXW_NO_ERROR;
    }

    /* Check for formula types. */
    switch (validation->validate) {
        case LXW_VALIDATION_TYPE_INTEGER_FORMULA:
        case LXW_VALIDATION_TYPE_DECIMAL_FORMULA:
        case LXW_VALIDATION_TYPE_LIST_FORMULA:
        case LXW_VALIDATION_TYPE_LENGTH_FORMULA:
        case LXW_VALIDATION_TYPE_DATE_FORMULA:
        case LXW_VALIDATION_TYPE_TIME_FORMULA:
        case LXW_VALIDATION_TYPE_CUSTOM_FORMULA:
            is_formula = LXW_TRUE;
            break;
    }

    /* Check for types without a criteria. */
    switch (validation->validate) {
        case LXW_VALIDATION_TYPE_LIST:
        case LXW_VALIDATION_TYPE_LIST_FORMULA:
        case LXW_VALIDATION_TYPE_ANY:
        case LXW_VALIDATION_TYPE_CUSTOM_FORMULA:
            has_criteria = LXW_FALSE;
            break;
    }

    /* Check that a validation parameter has been specified
     * except for 'list', 'any' and 'custom'. */
    if (has_criteria && validation->criteria == LXW_VALIDATION_CRITERIA_NONE) {

        LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                        "criteria parameter must be specified.");
        return LXW_ERROR_PARAMETER_VALIDATION;
    }

    /* Check for "between" criteria so we can do additional checks. */
    if (has_criteria
        && (validation->criteria == LXW_VALIDATION_CRITERIA_BETWEEN
            || validation->criteria == LXW_VALIDATION_CRITERIA_NOT_BETWEEN)) {

        is_between = LXW_TRUE;
    }

    /* Check that formula values are non NULL. */
    if (is_formula) {
        if (is_between) {
            if (!validation->minimum_formula) {
                LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                                "minimum_formula parameter cannot be NULL.");
                return LXW_ERROR_PARAMETER_VALIDATION;
            }
            if (!validation->maximum_formula) {
                LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                                "maximum_formula parameter cannot be NULL.");
                return LXW_ERROR_PARAMETER_VALIDATION;
            }
        }
        else {
            if (!validation->value_formula) {
                LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                                "formula parameter cannot be NULL.");
                return LXW_ERROR_PARAMETER_VALIDATION;
            }
        }
    }

    /* Check Excel limitations on input strings. */
    if (validation->input_title) {
        length = lxw_utf8_strlen(validation->input_title);
        if (length > LXW_VALIDATION_MAX_TITLE_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "input_title length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_TITLE_LENGTH);
            return LXW_ERROR_32_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->error_title) {
        length = lxw_utf8_strlen(validation->error_title);
        if (length > LXW_VALIDATION_MAX_TITLE_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "error_title length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_TITLE_LENGTH);
            return LXW_ERROR_32_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->input_message) {
        length = lxw_utf8_strlen(validation->input_message);
        if (length > LXW_VALIDATION_MAX_STRING_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "input_message length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_STRING_LENGTH);
            return LXW_ERROR_255_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->error_message) {
        length = lxw_utf8_strlen(validation->error_message);
        if (length > LXW_VALIDATION_MAX_STRING_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "error_message length > Excel limit of %d.",
                             LXW_VALIDATION_MAX_STRING_LENGTH);
            return LXW_ERROR_255_STRING_LENGTH_EXCEEDED;
        }
    }

    if (validation->validate == LXW_VALIDATION_TYPE_LIST) {
        length = _validation_list_length(validation->value_list);

        if (length == 0) {
            LXW_WARN_FORMAT("worksheet_data_validation_cell()/_range(): "
                            "list parameters cannot be zero.");
            return LXW_ERROR_PARAMETER_VALIDATION;
        }

        if (length > LXW_VALIDATION_MAX_STRING_LENGTH) {
            LXW_WARN_FORMAT1("worksheet_data_validation_cell()/_range(): "
                             "list length with commas > Excel limit of %d.",
                             LXW_VALIDATION_MAX_STRING_LENGTH);
            return LXW_ERROR_255_STRING_LENGTH_EXCEEDED;
        }
    }

    /* Swap last row/col with first row/col as necessary */
    if (first_row > last_row) {
        tmp_row = last_row;
        last_row = first_row;
        first_row = tmp_row;
    }
    if (first_col > last_col) {
        tmp_col = last_col;
        last_col = first_col;
        first_col = tmp_col;
    }

    /* Check that dimensions are valid but don't store them. */
    err = _check_dimensions(self, last_row, last_col, LXW_TRUE, LXW_TRUE);
    if (err)
        return err;

    /* Create a copy of the parameters from the user data validation. */
    copy = calloc(1, sizeof(lxw_data_val_obj));
    GOTO_LABEL_ON_MEM_ERROR(copy, mem_error);

    /* Create the data validation range. */
    if (first_row == last_row && first_col == last_col)
        lxw_rowcol_to_cell(copy->sqref, first_row, first_col);
    else
        lxw_rowcol_to_range(copy->sqref, first_row, first_col, last_row,
                            last_col);

    /* Copy the parameters from the user data validation. */
    copy->validate = validation->validate;
    copy->value_number = validation->value_number;
    copy->error_type = validation->error_type;
    copy->dropdown = validation->dropdown;

    if (has_criteria)
        copy->criteria = validation->criteria;

    if (is_between) {
        copy->value_number = validation->minimum_number;
        copy->maximum_number = validation->maximum_number;
    }

    /* Copy the input/error titles and messages. */
    if (validation->input_title) {
        copy->input_title = lxw_strdup_formula(validation->input_title);
        GOTO_LABEL_ON_MEM_ERROR(copy->input_title, mem_error);
    }

    if (validation->input_message) {
        copy->input_message = lxw_strdup_formula(validation->input_message);
        GOTO_LABEL_ON_MEM_ERROR(copy->input_message, mem_error);
    }

    if (validation->error_title) {
        copy->error_title = lxw_strdup_formula(validation->error_title);
        GOTO_LABEL_ON_MEM_ERROR(copy->error_title, mem_error);
    }

    if (validation->error_message) {
        copy->error_message = lxw_strdup_formula(validation->error_message);
        GOTO_LABEL_ON_MEM_ERROR(copy->error_message, mem_error);
    }

    /* Copy the formula strings. */
    if (is_formula) {
        if (is_between) {
            copy->value_formula =
                lxw_strdup_formula(validation->minimum_formula);
            GOTO_LABEL_ON_MEM_ERROR(copy->value_formula, mem_error);
            copy->maximum_formula =
                lxw_strdup_formula(validation->maximum_formula);
            GOTO_LABEL_ON_MEM_ERROR(copy->maximum_formula, mem_error);
        }
        else {
            copy->value_formula =
                lxw_strdup_formula(validation->value_formula);
            GOTO_LABEL_ON_MEM_ERROR(copy->value_formula, mem_error);
        }
    }

    /* Copy the validation list as a csv string. */
    if (validation->validate == LXW_VALIDATION_TYPE_LIST) {
        copy->value_formula = _validation_list_to_csv(validation->value_list);
        GOTO_LABEL_ON_MEM_ERROR(copy->value_formula, mem_error);
    }

    if (validation->validate == LXW_VALIDATION_TYPE_DATE
        || validation->validate == LXW_VALIDATION_TYPE_TIME) {
        if (is_between) {
            copy->value_number =
                lxw_datetime_to_excel_date_epoch
                (&validation->minimum_datetime, LXW_EPOCH_1900);
            copy->maximum_number =
                lxw_datetime_to_excel_date_epoch
                (&validation->maximum_datetime, LXW_EPOCH_1900);
        }
        else {
            copy->value_number =
                lxw_datetime_to_excel_date_epoch(&validation->value_datetime,
                                                 LXW_EPOCH_1900);
        }
    }

    /* These options are on by default so we can't take plain booleans. */
    copy->ignore_blank = validation->ignore_blank ^ 1;
    copy->show_input = validation->show_input ^ 1;
    copy->show_error = validation->show_error ^ 1;

    STAILQ_INSERT_TAIL(self->data_validations, copy, list_pointers);

    self->num_validations++;

    return LXW_NO_ERROR;

mem_error:
    _free_data_validation(copy);
    return LXW_ERROR_MEMORY_MALLOC_FAILED;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movl %r8d, %r12d
movl %ecx, %r13d
movl %edx, %r15d
movl %esi, 0x10(%rsp)
movzbl (%r9), %ecx
movb $0x1, %al
cmpl $0x10, %ecx
ja 0x3a159
movl $0xc954, %edx           # imm = 0xC954
btl %ecx, %edx
jae 0x3a19f
xorl %eax, %eax
cmpl $0xf, %ecx
ja 0x3a184
movl $0x8060, %edx           # imm = 0x8060
btl %ecx, %edx
jae 0x3a184
movb $0x1, %cl
movb $0x1, %bl
movb $0x1, %bpl
testb %al, %al
jne 0x3a1e0
cmpq $0x0, 0x10(%r14)
je 0x3a597
movb $0x1, %bl
xorl %ebp, %ebp
jmp 0x3a1e0
movb 0x1(%r14), %cl
testb %cl, %cl
je 0x3a5e4
cmpb $0x3, %cl
setae %bl
testb %al, %al
je 0x3a1bb
movb $0x1, %bpl
jmp 0x3a1de
cmpl $0x10, %ecx
jne 0x3a159
movb $0x1, %bl
cmpq $0x0, 0xa0(%r14)
je 0x3a50f
movb $0x1, %bpl
movb $0x1, %cl
jmp 0x3a1e0
cmpb $0x2, %cl
jbe 0x3a1c4
xorl %ecx, %ecx
jmp 0x3a173
cmpq $0x0, 0x48(%r14)
je 0x3a64f
cmpq $0x0, 0x78(%r14)
je 0x3a662
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %ecx, %ecx
movl %ecx, 0x1c(%rsp)
movq %rdi, 0x20(%rsp)
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x3a204
callq 0xd150
cmpq $0x21, %rax
jae 0x3a524
movq 0xb0(%r14), %rdi
testq %rdi, %rdi
je 0x3a21f
callq 0xd150
cmpq $0x21, %rax
jae 0x3a537
movq 0xa8(%r14), %rdi
testq %rdi, %rdi
je 0x3a23c
callq 0xd150
cmpq $0x100, %rax            # imm = 0x100
jae 0x3a559
movq 0xb8(%r14), %rdi
testq %rdi, %rdi
je 0x3a259
callq 0xd150
cmpq $0x100, %rax            # imm = 0x100
jae 0x3a56c
cmpb $0x5, (%r14)
jne 0x3a27d
movq 0x18(%r14), %rdi
callq 0xc6a0
testq %rax, %rax
je 0x3a57f
cmpq $0x100, %rax            # imm = 0x100
jae 0x3a5b9
movl %ebp, 0x8(%rsp)
movl %ebx, 0xc(%rsp)
movl 0x10(%rsp), %eax
cmpl %r13d, %eax
movl %r13d, %ebp
cmoval %eax, %ebp
movl %r13d, 0x14(%rsp)
cmovbl %eax, %r13d
cmpw %r12w, %r15w
movl %r12d, %ebx
cmoval %r15d, %r12d
movl %ebx, 0x18(%rsp)
cmovbl %r15d, %ebx
cmpl $0x100000, %ebp         # imm = 0x100000
setae %al
cmpw $0x4000, %r12w          # imm = 0x4000
setae %cl
orb %al, %cl
je 0x3a2cc
pushq $0x17
popq %rax
jmp 0x3a500
pushq $0x1
popq %rdi
movl $0xc8, %esi
callq 0xc850
testq %rax, %rax
je 0x3a5af
movl 0x10(%rsp), %ecx
cmpl %ecx, 0x14(%rsp)
setne %dl
cmpw %r15w, 0x18(%rsp)
setne %cl
leaq 0xa0(%rax), %rdi
orb %dl, %cl
movq %rax, %r15
movzwl %bx, %edx
jne 0x3a311
movl %r13d, %esi
callq 0xca60
jmp 0x3a31f
movzwl %r12w, %r8d
movl %r13d, %esi
movl %ebp, %ecx
callq 0xcd90
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %ebp
movb (%r14), %al
movb %al, (%r15)
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
movb 0x5(%r14), %al
movb %al, 0x5(%r15)
movb 0x6(%r14), %al
movb %al, 0x6(%r15)
cmpb $0x0, 0x1c(%rsp)
jne 0x3a358
movb 0x1(%r14), %al
movb %al, 0x1(%r15)
testb %bl, %bl
jne 0x3a374
movsd 0x40(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
movsd 0x70(%r14), %xmm0
movsd %xmm0, 0x50(%r15)
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x3a395
callq 0xc0f0
movq %rax, 0x80(%r15)
testq %rax, %rax
je 0x3a5dd
movq 0xa8(%r14), %rdi
testq %rdi, %rdi
je 0x3a3b6
callq 0xc0f0
movq %rax, 0x88(%r15)
testq %rax, %rax
je 0x3a5f9
movq 0xb0(%r14), %rdi
testq %rdi, %rdi
je 0x3a3d7
callq 0xc0f0
movq %rax, 0x90(%r15)
testq %rax, %rax
je 0x3a600
movq 0xb8(%r14), %rdi
testq %rdi, %rdi
je 0x3a3f8
callq 0xc0f0
movq %rax, 0x98(%r15)
testq %rax, %rax
je 0x3a607
testb %bpl, %bpl
jne 0x3a449
testb %bl, %bl
je 0x3a41d
movq 0x10(%r14), %rdi
callq 0xc0f0
movq %rax, 0x10(%r15)
testq %rax, %rax
jne 0x3a449
movl $0x2a9e, %ecx           # imm = 0x2A9E
jmp 0x3a621
movq 0x48(%r14), %rdi
callq 0xc0f0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x3a615
movq 0x78(%r14), %rdi
callq 0xc0f0
movq %rax, 0x58(%r15)
testq %rax, %rax
je 0x3a61c
movb (%r14), %al
cmpb $0x5, %al
jne 0x3a469
movq 0x18(%r14), %rdi
callq 0xc730
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x3a60e
movb (%r14), %al
cmpb $0xa, %al
je 0x3a475
movzbl %al, %eax
cmpl $0x7, %eax
jne 0x3a4b1
testb %bl, %bl
je 0x3a48c
leaq 0x20(%r14), %rdi
xorl %esi, %esi
callq 0xccb0
movsd %xmm0, 0x8(%r15)
jmp 0x3a4b1
leaq 0x50(%r14), %rdi
xorl %esi, %esi
callq 0xccb0
movsd %xmm0, 0x8(%r15)
leaq 0x80(%r14), %rdi
xorl %esi, %esi
callq 0xccb0
movsd %xmm0, 0x50(%r15)
movb 0x2(%r14), %al
xorb $0x1, %al
movb %al, 0x2(%r15)
movb 0x3(%r14), %al
xorb $0x1, %al
movb %al, 0x3(%r15)
movb 0x4(%r14), %al
xorb $0x1, %al
movb %al, 0x4(%r15)
movq %r15, %rax
addq $0xc0, %rax
andq $0x0, 0xc0(%r15)
movq 0x20(%rsp), %rdx
movq 0x50(%rdx), %rcx
movq 0x8(%rcx), %rcx
movq %r15, (%rcx)
movq 0x50(%rdx), %rcx
movq %rax, 0x8(%rcx)
incb 0x150(%rdx)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0xa8(%r14)
movb $0x1, %bpl
movb $0x1, %cl
jne 0x3a1e0
jmp 0x3a4fe
movq 0x18acd(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xac3b(%rip), %rsi      # 0x45170
jmp 0x3a548
movq 0x18aba(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xac87(%rip), %rsi      # 0x451cf
pushq $0x20
popq %rdx
xorl %eax, %eax
callq 0xc8d0
pushq $0x12
jmp 0x3a2c6
movq 0x18a98(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xacc4(%rip), %rsi      # 0x4522e
jmp 0x3a5ca
movq 0x18a85(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xad12(%rip), %rsi      # 0x4528f
jmp 0x3a5ca
movq 0x18a72(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xad60(%rip), %rdi      # 0x452f0
pushq $0x56
jmp 0x3a675
movq 0x18a5a(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xab6f(%rip), %rdi      # 0x45117
pushq $0x58
jmp 0x3a675
movl $0x2a65, %ecx           # imm = 0x2A65
movq %rax, %r15
jmp 0x3a621
movq 0x18a38(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xad7d(%rip), %rsi      # 0x45347
movl $0xff, %edx
xorl %eax, %eax
callq 0xc8d0
pushq $0x14
jmp 0x3a2c6
movl $0x2a7f, %ecx           # imm = 0x2A7F
jmp 0x3a621
movq 0x18a0d(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xaa03(%rip), %rdi      # 0x44ff8
pushq $0x5c
jmp 0x3a675
movl $0x2a84, %ecx           # imm = 0x2A84
jmp 0x3a621
movl $0x2a89, %ecx           # imm = 0x2A89
jmp 0x3a621
movl $0x2a8e, %ecx           # imm = 0x2A8E
jmp 0x3a621
movl $0x2aa5, %ecx           # imm = 0x2AA5
jmp 0x3a621
movl $0x2a96, %ecx           # imm = 0x2A96
jmp 0x3a621
movl $0x2a99, %ecx           # imm = 0x2A99
movq 0x189d0(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x2aae(%rip), %rsi      # 0x3d0e0
leaq 0x93a7(%rip), %rdx      # 0x439e0
xorl %eax, %eax
callq 0xc8d0
movq %r15, %rdi
callq 0x2c98c
pushq $0x1
jmp 0x3a2c6
movq 0x189a2(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xa9f5(%rip), %rdi      # 0x45055
jmp 0x3a673
movq 0x1898f(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xaa43(%rip), %rdi      # 0x450b6
pushq $0x60
popq %rsi
pushq $0x1
popq %rdx
callq 0xd000
pushq $0xd
jmp 0x3a2c6