// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movw %ax, -0x16(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x5539d
movq 0x27c78(%rip), %rax     # 0x7cff8
movq (%rax), %rdi
leaq 0x1840f(%rip), %rsi     # 0x6d799
movb $0x0, %al
callq 0xc8f0
movl $0xc, -0x4(%rbp)
jmp 0x5563f
movq -0x10(%rbp), %rax
movq 0xc8(%rax), %rdi
callq 0xc8b0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x553c4
movl $0x3, -0x4(%rbp)
jmp 0x5563f
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x1, %esi
callq 0xd030
cmpq -0x28(%rbp), %rax
je 0x553f5
movq -0x38(%rbp), %rdi
callq 0xc460
movl $0x3, -0x4(%rbp)
jmp 0x5563f
movq -0x38(%rbp), %rdi
callq 0xc560
movl $0x1, %edi
movl $0xc0, %esi
callq 0xc870
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5542d
movq -0x38(%rbp), %rdi
callq 0xc460
movl $0x1, -0x4(%rbp)
jmp 0x5563f
movq -0x28(%rbp), %rsi
movl $0x1, %edi
callq 0xc870
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x58(%rax)
jne 0x5546f
movq -0x40(%rbp), %rdi
callq 0x46550
movq -0x38(%rbp), %rdi
callq 0xc460
movl $0x1, -0x4(%rbp)
jmp 0x5563f
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xc980
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x40(%rbp), %rax
movb $0x1, 0x51(%rax)
cmpq $0x0, -0x30(%rbp)
je 0x55548
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movq -0x30(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xcd80
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xcd80
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
movb 0x18(%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, 0x40(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xcd80
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movb 0x28(%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, 0xb0(%rax)
leaq 0x18295(%rip), %rdi     # 0x6d7e4
callq 0xcd80
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x14(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x18(%rax)
movw -0x16(%rbp), %cx
movq -0x40(%rbp), %rax
movw %cx, 0x1c(%rax)
movq -0x40(%rbp), %rax
movsd 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x555a6
jp 0x555a6
movq -0x40(%rbp), %rax
movsd 0x124f7(%rip), %xmm0    # 0x67a98
movsd %xmm0, 0x8(%rax)
movq -0x40(%rbp), %rax
movsd 0x10(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x555cb
jp 0x555cb
movq -0x40(%rbp), %rax
movsd 0x124d2(%rip), %xmm0    # 0x67a98
movsd %xmm0, 0x10(%rax)
movq -0x40(%rbp), %rdi
callq 0x4c4c0
cmpl $0x0, %eax
jne 0x55626
jmp 0x555db
movq -0x40(%rbp), %rax
movq $0x0, 0xb8(%rax)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
addq $0xb8, %rcx
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rdi
callq 0xc460
movl $0x0, -0x4(%rbp)
jmp 0x5563f
movq -0x40(%rbp), %rdi
callq 0x46550
movq -0x38(%rbp), %rdi
callq 0xc460
movl $0x1a, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)