// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_set_header_opt
lxw_error
worksheet_set_header_opt(lxw_worksheet *self, const char *string,
                         lxw_header_footer_options *options)
{
    lxw_error err;
    char *tmp_header;
    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_header = lxw_strdup(string);
    RETURN_ON_MEM_ERROR(tmp_header, LXW_ERROR_MEMORY_MALLOC_FAILED);

    /* Replace &[Picture] with &G which is used internally by Excel. */
    while ((found_string = strstr(tmp_header, "&[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_header;
    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_header);
        return LXW_ERROR_PARAMETER_VALIDATION;
    }

    /* Free any previous header string so we can overwrite it. */
    free(self->header);
    self->header = 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_header);
            return LXW_ERROR_PARAMETER_VALIDATION;
        }

        /* Free any existing header image objects. */
        _free_object_properties(self->header_left_object_props);
        _free_object_properties(self->header_center_object_props);
        _free_object_properties(self->header_right_object_props);

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

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

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

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

    self->header = tmp_header;
    self->header_footer_changed = LXW_TRUE;

    return LXW_NO_ERROR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movb $0x0, -0x41(%rbp)
movb $0x0, -0x42(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x540a7
movq 0x28f6e(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x19449(%rip), %rsi     # 0x6d4dd
movb $0x0, %al
callq 0xc8f0
movl $0xc, -0x4(%rbp)
jmp 0x543a9
movq -0x18(%rbp), %rdi
callq 0xd180
cmpq $0xff, %rax
jbe 0x540dc
movq 0x28f39(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x1946c(%rip), %rsi     # 0x6d535
movb $0x0, %al
callq 0xc8f0
movl $0x14, -0x4(%rbp)
jmp 0x543a9
movq -0x18(%rbp), %rdi
callq 0xcd80
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x54120
movq 0x28f01(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x11fcf(%rip), %rsi     # 0x660d0
leaq 0x182ec(%rip), %rdx     # 0x6c3f4
movl $0x25b9, %ecx           # imm = 0x25B9
movb $0x0, %al
callq 0xc8f0
movl $0x1, -0x4(%rbp)
jmp 0x543a9
jmp 0x54122
jmp 0x54124
movq -0x30(%rbp), %rdi
leaq 0x19477(%rip), %rsi     # 0x6d5a6
callq 0xd130
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x54180
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movb $0x47, (%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movb (%rax), %cl
movq -0x38(%rbp), %rax
movb %cl, (%rax)
movq -0x40(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x54151
jmp 0x54124
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, (%rax)
je 0x541c0
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x26, %eax
jne 0x541b2
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x47, %eax
jne 0x541b2
movb -0x41(%rbp), %al
addb $0x1, %al
movb %al, -0x41(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x54188
movzbl -0x41(%rbp), %eax
cmpl $0x0, %eax
jle 0x54201
cmpq $0x0, -0x20(%rbp)
jne 0x54201
movq 0x28e21(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x193cc(%rip), %rsi     # 0x6d5b1
movb $0x0, %al
callq 0xc8f0
movq -0x30(%rbp), %rdi
callq 0xc0d0
movl $0xd, -0x4(%rbp)
jmp 0x543a9
movq -0x10(%rbp), %rax
movq 0x1b0(%rax), %rdi
callq 0xc0d0
movq -0x10(%rbp), %rax
movq $0x0, 0x1b0(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x54388
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x5423e
movb -0x42(%rbp), %al
addb $0x1, %al
movb %al, -0x42(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x54251
movb -0x42(%rbp), %al
addb $0x1, %al
movb %al, -0x42(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x54264
movb -0x42(%rbp), %al
addb $0x1, %al
movb %al, -0x42(%rbp)
movzbl -0x41(%rbp), %eax
movzbl -0x42(%rbp), %ecx
cmpl %ecx, %eax
je 0x542a1
movq 0x28d81(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x1932c(%rip), %rsi     # 0x6d5b1
movb $0x0, %al
callq 0xc8f0
movq -0x30(%rbp), %rdi
callq 0xc0d0
movl $0xd, -0x4(%rbp)
jmp 0x543a9
movq -0x10(%rbp), %rax
movq 0x378(%rax), %rdi
callq 0x46550
movq -0x10(%rbp), %rax
movq 0x380(%rax), %rdi
callq 0x46550
movq -0x10(%rbp), %rax
movq 0x388(%rax), %rdi
callq 0x46550
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x542f6
movq -0x20(%rbp), %rax
movsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x188(%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0xc0b0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x54326
movq -0x30(%rbp), %rdi
callq 0xc0d0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x543a9
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %edx
callq 0xc0b0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x54356
movq -0x30(%rbp), %rdi
callq 0xc0d0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x543a9
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rsi
movl $0x2, %edx
callq 0xc0b0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x54386
movq -0x30(%rbp), %rdi
callq 0xc0d0
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x543a9
jmp 0x54388
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x1b0(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x1ac(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)