// File: /workspace/github_c_makefile_star2_O2/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 0x39431
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq %rsi, %rdi
callq 0xd150
cmpq $0x100, %rax            # imm = 0x100
jae 0x39451
movq %r12, %rdi
callq 0xcd50
testq %rax, %rax
je 0x39471
movq %rax, %rbx
leaq 0xb8b5(%rip), %r13      # 0x44b86
movq %rbx, %rdi
movq %r13, %rsi
callq 0xd100
testq %rax, %rax
je 0x392f7
movb $0x47, 0x1(%rax)
addq $0xa, %rax
movb (%rax), %cl
movb %cl, -0x8(%rax)
incq %rax
testb %cl, %cl
jne 0x392e9
jmp 0x392d1
movq %rbx, %rax
incq %rax
xorl %ebp, %ebp
movzbl -0x1(%rax), %ecx
cmpl $0x26, %ecx
je 0x3930e
testl %ecx, %ecx
jne 0x39317
jmp 0x3931c
cmpb $0x47, (%rax)
sete %cl
addb %cl, %bpl
incq %rax
jmp 0x392ff
testq %r15, %r15
jne 0x3932a
testb %bpl, %bpl
jne 0x3940a
movq 0x1b8(%r14), %rdi
callq 0xc0d0
andq $0x0, 0x1b8(%r14)
testq %r15, %r15
je 0x393f4
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 0x3940a
movq 0x390(%r14), %rdi
callq 0x2c85b
movq 0x398(%r14), %rdi
callq 0x2c85b
movq 0x3a0(%r14), %rdi
callq 0x2c85b
movsd (%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x393ac
movsd %xmm0, 0x190(%r14)
movq 0x8(%r15), %rsi
pushq $0x3
popq %rdx
movq %r14, %rdi
callq 0xc0b0
testl %eax, %eax
jne 0x393e5
movq 0x10(%r15), %rsi
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0xc0b0
testl %eax, %eax
jne 0x393e5
movq 0x18(%r15), %rsi
pushq $0x5
popq %rdx
movq %r14, %rdi
callq 0xc0b0
testl %eax, %eax
je 0x393f4
movl %eax, %ebp
movq %rbx, %rdi
callq 0xc0d0
jmp 0x39498
movq %rbx, 0x1b8(%r14)
movb $0x1, 0x1ac(%r14)
xorl %ebp, %ebp
jmp 0x39498
movq 0x19be7(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0xb776(%rip), %rsi      # 0x44b91
movq %r12, %rdx
xorl %eax, %eax
callq 0xc8d0
movq %rbx, %rdi
callq 0xc0d0
pushq $0xd
jmp 0x39497
movq 0x19bc0(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xb67b(%rip), %rdi      # 0x44abd
pushq $0x57
popq %rsi
pushq $0x1
popq %rdx
callq 0xd000
pushq $0xc
jmp 0x39497
movq 0x19ba0(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xb6b3(%rip), %rdi      # 0x44b15
pushq $0x70
popq %rsi
pushq $0x1
popq %rdx
callq 0xd000
pushq $0x14
jmp 0x39497
movq 0x19b80(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x3c5e(%rip), %rsi      # 0x3d0e0
leaq 0xa557(%rip), %rdx      # 0x439e0
movl $0x2635, %ecx           # imm = 0x2635
xorl %eax, %eax
callq 0xc8d0
pushq $0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq