// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq %rdi, %r15
movzbl (%r9), %ecx
movb $0x1, %al
cmpl $0x10, %ecx
ja 0x3d061
movl $0xc954, %edx           # imm = 0xC954
btl %ecx, %edx
jae 0x3d0a7
xorl %eax, %eax
cmpl $0xf, %ecx
ja 0x3d08c
movl $0x8060, %edx           # imm = 0x8060
btl %ecx, %edx
jae 0x3d08c
movb $0x1, %cl
movb $0x1, %bl
movb $0x1, %bpl
testb %al, %al
jne 0x3d0e8
cmpq $0x0, 0x10(%r14)
je 0x3d45a
movb $0x1, %bl
xorl %ebp, %ebp
jmp 0x3d0e8
movb 0x1(%r14), %cl
testb %cl, %cl
je 0x3d47b
cmpb $0x3, %cl
setae %bl
testb %al, %al
je 0x3d0c3
movb $0x1, %bpl
jmp 0x3d0e6
cmpl $0x10, %ecx
jne 0x3d061
movb $0x1, %bl
cmpq $0x0, 0xa0(%r14)
je 0x3d41d
movb $0x1, %bpl
movb $0x1, %cl
jmp 0x3d0e8
cmpb $0x2, %cl
jbe 0x3d0cc
xorl %ecx, %ecx
jmp 0x3d07b
cmpq $0x0, 0x48(%r14)
je 0x3d4cb
cmpq $0x0, 0x78(%r14)
je 0x3d4d2
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %ecx, %ecx
movl %ecx, 0x1c(%rsp)
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x3d107
callq 0xd0d0
cmpq $0x21, %rax
jae 0x3d432
movq 0xb0(%r14), %rdi
testq %rdi, %rdi
je 0x3d122
callq 0xd0d0
cmpq $0x21, %rax
jae 0x3d439
movq 0xa8(%r14), %rdi
testq %rdi, %rdi
je 0x3d13f
callq 0xd0d0
cmpq $0x100, %rax            # imm = 0x100
jae 0x3d445
movq 0xb8(%r14), %rdi
testq %rdi, %rdi
je 0x3d15c
callq 0xd0d0
cmpq $0x100, %rax            # imm = 0x100
jae 0x3d44c
cmpb $0x5, (%r14)
jne 0x3d180
movq 0x18(%r14), %rdi
callq 0xc650
testq %rax, %rax
je 0x3d453
cmpq $0x100, %rax            # imm = 0x100
jae 0x3d468
movl %ebp, 0x4(%rsp)
movl %ebx, 0x8(%rsp)
movl 0xc(%rsp), %eax
cmpl %r13d, %eax
movl %r13d, %ebp
cmoval %eax, %ebp
movl %r13d, 0x14(%rsp)
cmovbl %eax, %r13d
movl 0x10(%rsp), %ecx
cmpw %r12w, %cx
movl %r12d, %eax
cmoval %ecx, %eax
movl %r12d, 0x18(%rsp)
movl %r12d, %ebx
cmovbl %ecx, %ebx
cmpl $0x100000, %ebp         # imm = 0x100000
setae %cl
movzwl %ax, %r12d
cmpl $0x4000, %r12d          # imm = 0x4000
setae %al
orb %cl, %al
movl $0x17, %eax
jne 0x3d4bc
movq %r15, 0x20(%rsp)
movl $0x1, %edi
movl $0xc8, %esi
callq 0xc7f0
movq %rax, %r15
testq %rax, %rax
je 0x3d461
movl 0xc(%rsp), %eax
cmpl %eax, 0x14(%rsp)
setne %al
movl 0x10(%rsp), %ecx
cmpw %cx, 0x18(%rsp)
setne %cl
leaq 0xa0(%r15), %rdi
movzwl %bx, %edx
movl %r13d, %esi
orb %al, %cl
jne 0x3d22a
callq 0xca00
jmp 0x3d234
movl %ebp, %ecx
movl %r12d, %r8d
callq 0xcd10
movl 0x8(%rsp), %ebx
movl 0x4(%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 0x3d26d
movb 0x1(%r14), %al
movb %al, 0x1(%r15)
testb %bl, %bl
jne 0x3d289
movsd 0x40(%r14), %xmm0
movsd %xmm0, 0x8(%r15)
movsd 0x70(%r14), %xmm0
movsd %xmm0, 0x50(%r15)
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x3d2aa
callq 0xc0e0
movq %rax, 0x80(%r15)
testq %rax, %rax
je 0x3d474
movq 0xa8(%r14), %rdi
testq %rdi, %rdi
je 0x3d2cb
callq 0xc0e0
movq %rax, 0x88(%r15)
testq %rax, %rax
je 0x3d487
movq 0xb0(%r14), %rdi
testq %rdi, %rdi
je 0x3d2ec
callq 0xc0e0
movq %rax, 0x90(%r15)
testq %rax, %rax
je 0x3d48e
movq 0xb8(%r14), %rdi
testq %rdi, %rdi
je 0x3d30d
callq 0xc0e0
movq %rax, 0x98(%r15)
testq %rax, %rax
je 0x3d495
testb %bpl, %bpl
jne 0x3d35e
testb %bl, %bl
je 0x3d332
movq 0x10(%r14), %rdi
callq 0xc0e0
movq %rax, 0x10(%r15)
testq %rax, %rax
jne 0x3d35e
movl $0x2a9e, %edi           # imm = 0x2A9E
jmp 0x3d4af
movq 0x48(%r14), %rdi
callq 0xc0e0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x3d4a3
movq 0x78(%r14), %rdi
callq 0xc0e0
movq %rax, 0x58(%r15)
testq %rax, %rax
je 0x3d4aa
movb (%r14), %al
cmpb $0x5, %al
jne 0x3d37e
movq 0x18(%r14), %rdi
callq 0xc6d0
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x3d49c
movb (%r14), %al
cmpb $0xa, %al
je 0x3d38a
movzbl %al, %eax
cmpl $0x7, %eax
jne 0x3d3c6
testb %bl, %bl
je 0x3d3a1
leaq 0x20(%r14), %rdi
xorl %esi, %esi
callq 0xcc40
movsd %xmm0, 0x8(%r15)
jmp 0x3d3c6
leaq 0x50(%r14), %rdi
xorl %esi, %esi
callq 0xcc40
movsd %xmm0, 0x8(%r15)
leaq 0x80(%r14), %rdi
xorl %esi, %esi
callq 0xcc40
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
movq $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
jmp 0x3d4bc
cmpq $0x0, 0xa8(%r14)
movb $0x1, %bpl
movb $0x1, %cl
jne 0x3d0e8
jmp 0x3d416
callq 0xfac8
jmp 0x3d43e
callq 0xfae3
movl $0x12, %eax
jmp 0x3d4bc
callq 0xfafe
jmp 0x3d46d
callq 0xfb1b
jmp 0x3d46d
callq 0xfb83
jmp 0x3d480
callq 0xfaac
jmp 0x3d480
movl $0x2a65, %edi           # imm = 0x2A65
jmp 0x3d4af
callq 0xfb66
movl $0x14, %eax
jmp 0x3d4bc
movl $0x2a7f, %edi           # imm = 0x2A7F
jmp 0x3d4af
callq 0xfb9f
movl $0xd, %eax
jmp 0x3d4bc
movl $0x2a84, %edi           # imm = 0x2A84
jmp 0x3d4af
movl $0x2a89, %edi           # imm = 0x2A89
jmp 0x3d4af
movl $0x2a8e, %edi           # imm = 0x2A8E
jmp 0x3d4af
movl $0x2aa5, %edi           # imm = 0x2AA5
jmp 0x3d4af
movl $0x2a96, %edi           # imm = 0x2A96
jmp 0x3d4af
movl $0x2a99, %edi           # imm = 0x2A99
movq %r15, %rsi
callq 0xfb38
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xfa90
jmp 0x3d480
callq 0xfa74
jmp 0x3d480