// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: worksheet_set_background_buffer
lxw_error
worksheet_set_background_buffer(lxw_worksheet *self,
                                const unsigned char *image_buffer,
                                size_t image_size)
{
    FILE *image_stream;
    lxw_object_properties *object_props;

    if (!image_size) {
        LXW_WARN("worksheet_set_background(): " "size must be non-zero.");
        return LXW_ERROR_NULL_PARAMETER_IGNORED;
    }

    /* Write the image buffer to a file (preferably in memory) so we can read
     * the dimensions like an ordinary file. */
#ifdef USE_FMEMOPEN
    image_stream = fmemopen((void *) image_buffer, image_size, "rb");

    if (!image_stream)
        return LXW_ERROR_CREATING_TMPFILE;
#else
    image_stream = lxw_tmpfile(self->tmpdir);

    if (!image_stream)
        return LXW_ERROR_CREATING_TMPFILE;

    if (fwrite(image_buffer, 1, image_size, image_stream) != image_size) {
        fclose(image_stream);
        return LXW_ERROR_CREATING_TMPFILE;
    }

    rewind(image_stream);
#endif

    /* 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;
    }

    /* Store the image data in the properties structure. */
    object_props->image_buffer = calloc(1, image_size);
    if (!object_props->image_buffer) {
        _free_object_properties(object_props);
        fclose(image_stream);
        return LXW_ERROR_MEMORY_MALLOC_FAILED;
    }
    else {
        memcpy(object_props->image_buffer, image_buffer, image_size);
        object_props->image_buffer_size = image_size;
        object_props->is_image_buffer = LXW_TRUE;
    }

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

    if (_get_image_properties(object_props) == LXW_NO_ERROR) {
        _free_object_properties(self->background_image);
        self->background_image = object_props;
        self->has_background_image = 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
testq %rdx, %rdx
je 0x39ec7
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq 0xc8(%rdi), %rdi
callq 0xc890
pushq $0x3
popq %rbp
testq %rax, %rax
je 0x39ee6
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %rax, %rcx
callq 0xd000
cmpq %r15, %rax
jne 0x39ea9
movq %rbx, %rdi
callq 0xc540
pushq $0x1
popq %rdi
movl $0xc0, %esi
callq 0xc850
testq %rax, %rax
je 0x39ebb
movq %rax, %r13
pushq $0x1
popq %rdi
movq %r15, %rsi
callq 0xc850
movq %rax, 0x58(%r13)
testq %rax, %rax
je 0x39eb3
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc960
movq %r15, 0x60(%r13)
movb $0x1, %bpl
movb %bpl, 0x51(%r13)
leaq 0xaf4f(%rip), %rdi      # 0x44dc4
callq 0xcd50
movq %rax, 0x20(%r13)
movq %rbx, 0x48(%r13)
movb %bpl, 0x99(%r13)
movq %r13, %rdi
callq 0x306b6
testl %eax, %eax
je 0x39ef7
movq %r13, %rdi
callq 0x2c85b
movq %rbx, %rdi
callq 0xc450
pushq $0x1a
jmp 0x39ee5
movq %rbx, %rdi
callq 0xc450
jmp 0x39ee6
movq %r13, %rdi
callq 0x2c85b
movq %rbx, %rdi
callq 0xc450
pushq $0x1
jmp 0x39ee5
movq 0x1912a(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xaf90(%rip), %rdi      # 0x44e68
pushq $0x3e
popq %rsi
pushq $0x1
popq %rdx
callq 0xd000
pushq $0xc
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3a8(%r14), %rdi
callq 0x2c85b
movq %r13, 0x3a8(%r14)
movb $0x1, 0x2a3(%r14)
movq %rbx, %rdi
callq 0xc450
xorl %ebp, %ebp
jmp 0x39ee6