// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_set_header_footer_image
lxw_error
_worksheet_set_header_footer_image(lxw_worksheet *self, const char *filename,
                                   uint8_t image_position)
{
    FILE *image_stream;
    const char *description;
    lxw_object_properties *object_props;
    char *image_strings[] = { "LH", "CH", "RH", "LF", "CF", "RF" };

    /* Not all slots will have image files. */
    if (!filename)
        return LXW_NO_ERROR;

    /* Check that the image file exists and can be opened. */
    image_stream = lxw_fopen(filename, "rb");
    if (!image_stream) {
        LXW_WARN_FORMAT1("worksheet_set_header_opt/footer_opt(): "
                         "file doesn't exist or can't be opened: %s.",
                         filename);
        return LXW_ERROR_PARAMETER_VALIDATION;
    }

    /* Use the filename as the default description, like Excel. */
    description = lxw_basename(filename);
    if (!description) {
        LXW_WARN_FORMAT1("worksheet_set_header_opt/footer_opt(): "
                         "couldn't get basename for file: %s.", filename);
        fclose(image_stream);
        return LXW_ERROR_PARAMETER_VALIDATION;
    }

    /* Create a new object to hold the image properties. */
    object_props = calloc(1, sizeof(lxw_object_properties));
    if (!object_props) {
        fclose(image_stream);
        return LXW_ERROR_MEMORY_MALLOC_FAILED;
    }

    /* Copy other options or set defaults. */
    object_props->filename = lxw_strdup(filename);
    object_props->description = lxw_strdup(description);
    object_props->stream = image_stream;

    /* Set VML image position string based on the header/footer/position. */
    object_props->image_position = lxw_strdup(image_strings[image_position]);

    if (_get_image_properties(object_props) == LXW_NO_ERROR) {
        *self->header_footer_objs[image_position] = object_props;
        self->has_header_vml = LXW_TRUE;
        fclose(image_stream);
        return LXW_NO_ERROR;
    }
    else {
        _free_object_properties(object_props);
        fclose(image_stream);
        return LXW_ERROR_IMAGE_DIMENSIONS;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
testq %rsi, %rsi
je 0x306a5
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r13
leaq 0xca65(%rip), %rsi      # 0x3d000
movq %r12, %rdi
callq 0xc270
testq %rax, %rax
je 0x30662
movq %rax, %r14
movq %r12, %rdi
callq 0xc9c0
testq %rax, %rax
je 0x3067f
movq %rax, %r15
movq %r13, (%rsp)
pushq $0x1
popq %rdi
movl $0xc0, %esi
callq 0xc850
testq %rax, %rax
je 0x30636
movq %rax, %r13
movq %r12, %rdi
callq 0xcd50
movq %rax, 0x20(%r13)
movq %r15, %rdi
callq 0xcd50
movq %rax, 0x28(%r13)
movq %r14, 0x48(%r13)
movzbl %bpl, %r15d
leaq 0x13265(%rip), %rax     # 0x43868
movslq (%rax,%r15,4), %rdi
addq %rax, %rdi
callq 0xcd50
movq %rax, 0xa8(%r13)
movq %r13, %rdi
callq 0x306b6
testl %eax, %eax
je 0x30642
movq %r13, %rdi
callq 0x2c85b
movq %r14, %rdi
callq 0xc450
pushq $0x1a
jmp 0x306a4
movq %r14, %rdi
callq 0xc450
pushq $0x1
jmp 0x306a4
movq (%rsp), %rcx
movq 0x348(%rcx,%r15,8), %rax
movq %r13, (%rax)
movb $0x1, 0x2a2(%rcx)
movq %r14, %rdi
callq 0xc450
jmp 0x306a5
movq 0x2298f(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x139aa(%rip), %rsi     # 0x4401d
movq %r12, %rdx
xorl %eax, %eax
callq 0xc8d0
jmp 0x306a2
movq 0x22972(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x139eb(%rip), %rsi     # 0x4407b
movq %r12, %rdx
xorl %eax, %eax
callq 0xc8d0
movq %r14, %rdi
callq 0xc450
pushq $0xd
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq