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

    if (!image_size) {
        LXW_WARN("worksheet_insert_image_buffer()/_opt(): "
                 "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;
    }

    if (user_options) {
        object_props->x_offset = user_options->x_offset;
        object_props->y_offset = user_options->y_offset;
        object_props->x_scale = user_options->x_scale;
        object_props->y_scale = user_options->y_scale;
        object_props->url = lxw_strdup(user_options->url);
        object_props->tip = lxw_strdup(user_options->tip);
        object_props->object_position = user_options->object_position;
        object_props->description = lxw_strdup(user_options->description);
        object_props->decorative = user_options->decorative;
    }

    /* Copy other options or set defaults. */
    object_props->filename = lxw_strdup("image_buffer");
    object_props->stream = image_stream;
    object_props->row = row_num;
    object_props->col = col_num;

    if (object_props->x_scale == 0.0)
        object_props->x_scale = 1;

    if (object_props->y_scale == 0.0)
        object_props->y_scale = 1;

    if (_get_image_properties(object_props) == LXW_NO_ERROR) {
        STAILQ_INSERT_TAIL(self->image_props, object_props, list_pointers);
        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 %r8, %r8
je 0x39c68
movq %r9, %r13
movq %r8, %rbp
movq %rcx, %r15
movq %rdi, %r14
movl %esi, (%rsp)
movl %edx, 0x4(%rsp)
movq 0xc8(%rdi), %rdi
callq 0xc890
pushq $0x3
popq %r12
testq %rax, %rax
je 0x39c88
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %r15, %rdi
movq %rbp, %rdx
movq %rax, %rcx
callq 0xd000
cmpq %rbp, %rax
jne 0x39c4a
movq %rbx, %rdi
callq 0xc540
pushq $0x1
popq %rdi
movl $0xc0, %esi
callq 0xc850
testq %rax, %rax
je 0x39c5c
movq %rax, %r12
pushq $0x1
popq %rdi
movq %rbp, %rsi
callq 0xc850
movq %rax, 0x58(%r12)
testq %rax, %rax
je 0x39c54
movq %rax, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xc960
movq %rbp, 0x60(%r12)
movb $0x1, 0x51(%r12)
testq %r13, %r13
je 0x39bcc
movq (%r13), %rax
movq %rax, (%r12)
movupd 0x8(%r13), %xmm0
movupd %xmm0, 0x8(%r12)
movq 0x30(%r13), %rdi
callq 0xcd50
movq %rax, 0x30(%r12)
movq 0x38(%r13), %rdi
callq 0xcd50
movq %rax, 0x38(%r12)
movb 0x18(%r13), %al
movb %al, 0x40(%r12)
movq 0x20(%r13), %rdi
callq 0xcd50
movq %rax, 0x28(%r12)
movb 0x28(%r13), %al
movb %al, 0xb0(%r12)
leaq 0xb1f1(%rip), %rdi      # 0x44dc4
callq 0xcd50
movq %rax, 0x20(%r12)
movq %rbx, 0x48(%r12)
movl (%rsp), %eax
movl %eax, 0x18(%r12)
movl 0x4(%rsp), %eax
movw %ax, 0x1c(%r12)
movsd 0x8(%r12), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
jne 0x39c16
jp 0x39c16
movq %rax, 0x8(%r12)
movsd 0x10(%r12), %xmm1
ucomisd %xmm0, %xmm1
jne 0x39c2a
jp 0x39c2a
movq %rax, 0x10(%r12)
movq %r12, %rdi
callq 0x306b6
testl %eax, %eax
je 0x39c9a
movq %r12, %rdi
callq 0x2c85b
movq %rbx, %rdi
callq 0xc450
pushq $0x1a
jmp 0x39c86
movq %rbx, %rdi
callq 0xc450
jmp 0x39c88
movq %r12, %rdi
callq 0x2c85b
movq %rbx, %rdi
callq 0xc450
pushq $0x1
jmp 0x39c86
movq 0x19389(%rip), %rax     # 0x52ff8
movq (%rax), %rcx
leaq 0xb100(%rip), %rdi      # 0x44d79
pushq $0x4a
popq %rsi
pushq $0x1
popq %rdx
callq 0xd000
pushq $0xc
popq %r12
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rax
addq $0xb8, %rax
andq $0x0, 0xb8(%r12)
movq 0x60(%r14), %rcx
movq 0x8(%rcx), %rcx
movq %r12, (%rcx)
movq 0x60(%r14), %rcx
movq %rax, 0x8(%rcx)
movq %rbx, %rdi
callq 0xc450
xorl %r12d, %r12d
jmp 0x39c88