// File: /workspace/github_c_makefile_star2_O3/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_set_footer_opt
lxw_error
worksheet_set_footer_opt(lxw_worksheet *self, const char *string,
                         lxw_header_footer_options *options)
{
    lxw_error err;
    char *tmp_footer;
    char *found_string;
    char *offset_string;
    uint8_t placeholder_count = 0;
    uint8_t image_count = 0;

    if (!string) {
        LXW_WARN_FORMAT("worksheet_set_header_opt/footer_opt(): "
                        "header/footer string cannot be NULL.");
        return LXW_ERROR_NULL_PARAMETER_IGNORED;
    }

    if (lxw_utf8_strlen(string) > LXW_HEADER_FOOTER_MAX) {
        LXW_WARN_FORMAT("worksheet_set_header_opt/footer_opt(): "
                        "header/footer string exceeds Excel's limit of "
                        "255 characters.");
        return LXW_ERROR_255_STRING_LENGTH_EXCEEDED;
    }

    tmp_footer = lxw_strdup(string);
    RETURN_ON_MEM_ERROR(tmp_footer, LXW_ERROR_MEMORY_MALLOC_FAILED);

    /* Replace &[Picture] with &G which is used internally by Excel. */
    while ((found_string = strstr(tmp_footer, "&[Picture]"))) {
        found_string++;
        *found_string = 'G';

        do {
            found_string++;
            offset_string = found_string + sizeof("Picture");
            *found_string = *offset_string;
        } while (*offset_string);
    }

    /* Count &G placeholders and ensure there are sufficient images. */
    found_string = tmp_footer;
    while (*found_string) {
        if (*found_string == '&' && *(found_string + 1) == 'G')
            placeholder_count++;
        found_string++;
    }

    if (placeholder_count > 0 && !options) {
        LXW_WARN_FORMAT1("worksheet_set_header_opt/footer_opt(): "
                         "the number of &G/&[Picture] placeholders in option "
                         "string \"%s\" does not match the number of supplied "
                         "images.", string);

        free(tmp_footer);
        return LXW_ERROR_PARAMETER_VALIDATION;
    }

    /* Free any previous footer string so we can overwrite it. */
    free(self->footer);
    self->footer = NULL;

    if (options) {
        /* Ensure there are enough images to match the placeholders. There is
         * a potential bug where there are sufficient images but in the wrong
         * positions but we don't currently try to deal with that.*/
        if (options->image_left)
            image_count++;
        if (options->image_center)
            image_count++;
        if (options->image_right)
            image_count++;

        if (placeholder_count != image_count) {
            LXW_WARN_FORMAT1("worksheet_set_header_opt/footer_opt(): "
                             "the number of &G/&[Picture] placeholders in option "
                             "string \"%s\" does not match the number of supplied "
                             "images.", string);

            free(tmp_footer);
            return LXW_ERROR_PARAMETER_VALIDATION;
        }

        /* Free any existing footer image objects. */
        _free_object_properties(self->footer_left_object_props);
        _free_object_properties(self->footer_center_object_props);
        _free_object_properties(self->footer_right_object_props);

        if (options->margin > 0.0)
            self->margin_footer = options->margin;

        err = _worksheet_set_header_footer_image(self,
                                                 options->image_left,
                                                 FOOTER_LEFT);
        if (err) {
            free(tmp_footer);
            return err;
        }

        err = _worksheet_set_header_footer_image(self,
                                                 options->image_center,
                                                 FOOTER_CENTER);
        if (err) {
            free(tmp_footer);
            return err;
        }

        err = _worksheet_set_header_footer_image(self,
                                                 options->image_right,
                                                 FOOTER_RIGHT);
        if (err) {
            free(tmp_footer);
            return err;
        }
    }

    self->footer = tmp_footer;
    self->header_footer_changed = LXW_TRUE;

    return LXW_NO_ERROR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
je 0x3c40e
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq %rsi, %rdi
callq 0xd0d0
cmpq $0x100, %rax            # imm = 0x100
jae 0x3c41a
movq %r12, %rdi
callq 0xcce0
testq %rax, %rax
je 0x3c426
movq %rax, %rbx
leaq 0xb913(%rip), %rsi      # 0x47b9a
movq %rax, %rdi
callq 0xd080
testq %rax, %rax
je 0x3c2bf
leaq 0xb8ff(%rip), %r13      # 0x47b9a
movb $0x47, 0x1(%rax)
addq $0xa, %rax
movb (%rax), %cl
movb %cl, -0x8(%rax)
incq %rax
testb %cl, %cl
jne 0x3c2a3
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd080
testq %rax, %rax
jne 0x3c29b
movq %rbx, %rax
incq %rax
xorl %ebp, %ebp
movzbl -0x1(%rax), %ecx
cmpl $0x26, %ecx
je 0x3c2d6
testl %ecx, %ecx
jne 0x3c2df
jmp 0x3c2e4
cmpb $0x47, (%rax)
sete %cl
addb %cl, %bpl
incq %rax
jmp 0x3c2c7
testq %r15, %r15
jne 0x3c2f2
testb %bpl, %bpl
jne 0x3c3e4
movq 0x1b8(%r14), %rdi
callq 0xc0c0
movq $0x0, 0x1b8(%r14)
testq %r15, %r15
je 0x3c3c2
xorl %eax, %eax
cmpq $0x0, 0x8(%r15)
setne %al
leal 0x1(%rax), %ecx
cmpq $0x0, 0x10(%r15)
movzbl %cl, %ecx
cmovel %eax, %ecx
cmpq $0x1, 0x18(%r15)
sbbb $-0x1, %cl
cmpb %cl, %bpl
jne 0x3c3e4
movq 0x390(%r14), %rdi
callq 0x2fa62
movq 0x398(%r14), %rdi
callq 0x2fa62
movq 0x3a0(%r14), %rdi
callq 0x2fa62
movsd (%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3c377
movsd %xmm0, 0x190(%r14)
movq 0x8(%r15), %rsi
movq %r14, %rdi
movl $0x3, %edx
callq 0xc0a0
testl %eax, %eax
jne 0x3c3b6
movq 0x10(%r15), %rsi
movq %r14, %rdi
movl $0x4, %edx
callq 0xc0a0
testl %eax, %eax
jne 0x3c3b6
movq 0x18(%r15), %rsi
movq %r14, %rdi
movl $0x5, %edx
callq 0xc0a0
testl %eax, %eax
je 0x3c3c2
movl %eax, %ebp
movq %rbx, %rdi
callq 0xc0c0
jmp 0x3c3d3
movq %rbx, 0x1b8(%r14)
movb $0x1, 0x1ac(%r14)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1ac0d(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0xb7b0(%rip), %rsi      # 0x47ba5
movq %r12, %rdx
xorl %eax, %eax
callq 0xc870
movq %rbx, %rdi
callq 0xc0c0
movl $0xd, %ebp
jmp 0x3c3d3
callq 0xf8f0
movl $0xc, %ebp
jmp 0x3c3d3
callq 0xf8d4
movl $0x14, %ebp
jmp 0x3c3d3
callq 0xf8b0
movl $0x1, %ebp
jmp 0x3c3d3