// File: /workspace/github_c_makefile_star2_O1/Paxa[P]fast_excel/libxlsxwriter/src/worksheet.c
// Function: lxw_worksheet_prepare_vml_objects
uint32_t
lxw_worksheet_prepare_vml_objects(lxw_worksheet *self,
                                  uint32_t vml_data_id,
                                  uint32_t vml_shape_id,
                                  uint32_t vml_drawing_id,
                                  uint32_t comment_id)
{
    lxw_row *row;
    lxw_cell *cell;
    lxw_rel_tuple *relationship;
    char filename[LXW_FILENAME_LENGTH];
    uint32_t comment_count = 0;
    uint32_t i;
    uint32_t tmp_data_id;
    size_t data_str_len = 0;
    size_t used = 0;
    char *vml_data_id_str;

    RB_FOREACH(row, lxw_table_rows, self->comments) {

        RB_FOREACH(cell, lxw_table_cells, row->cells) {
            /* Calculate the worksheet position of the comment. */
            _worksheet_position_vml_object(self, cell->comment);

            /* Store comment in a simple list for use by packager. */
            STAILQ_INSERT_TAIL(self->comment_objs, cell->comment,
                               list_pointers);
            comment_count++;
        }
    }

    /* Set up the VML relationship for comments/buttons/header images. */
    relationship = calloc(1, sizeof(lxw_rel_tuple));
    GOTO_LABEL_ON_MEM_ERROR(relationship, mem_error);

    relationship->type = lxw_strdup("/vmlDrawing");
    GOTO_LABEL_ON_MEM_ERROR(relationship->type, mem_error);

    lxw_snprintf(filename, 32, "../drawings/vmlDrawing%d.vml",
                 vml_drawing_id);

    relationship->target = lxw_strdup(filename);
    GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);

    self->external_vml_comment_link = relationship;

    if (self->has_comments) {
        /* Only need this relationship object for comment VMLs. */

        relationship = calloc(1, sizeof(lxw_rel_tuple));
        GOTO_LABEL_ON_MEM_ERROR(relationship, mem_error);

        relationship->type = lxw_strdup("/comments");
        GOTO_LABEL_ON_MEM_ERROR(relationship->type, mem_error);

        lxw_snprintf(filename, 32, "../comments%d.xml", comment_id);

        relationship->target = lxw_strdup(filename);
        GOTO_LABEL_ON_MEM_ERROR(relationship->target, mem_error);

        self->external_comment_link = relationship;
    }

    /* The vml.c <o:idmap> element data id contains a comma separated range
     * when there is more than one 1024 block of comments, like this:
     * data="1,2,3". Since this could potentially (but unlikely) exceed
     * LXW_MAX_ATTRIBUTE_LENGTH we need to allocate space dynamically. */

    /* Calculate the total space required for the ID for each 1024 block. */
    for (i = 0; i <= comment_count / 1024; i++) {
        tmp_data_id = vml_data_id + i;

        /* Calculate the space required for the digits in the id. */
        while (tmp_data_id) {
            data_str_len++;
            tmp_data_id /= 10;
        }

        /* Add an extra char for comma separator or '\O'. */
        data_str_len++;
    };

    /* If this allocation fails it will be dealt with in packager.c. */
    vml_data_id_str = calloc(1, data_str_len + 2);
    GOTO_LABEL_ON_MEM_ERROR(vml_data_id_str, mem_error);

    /* Create the CSV list in the allocated space. */
    for (i = 0; i <= comment_count / 1024; i++) {
        tmp_data_id = vml_data_id + i;
        lxw_snprintf(vml_data_id_str + used, data_str_len - used, "%d,",
                     tmp_data_id);

        used = strlen(vml_data_id_str);
    };

    self->vml_shape_id = vml_shape_id;
    self->vml_data_id_str = vml_data_id_str;

    return comment_count;

mem_error:
    if (relationship) {
        free(relationship->type);
        free(relationship->target);
        free(relationship->target_mode);
        free(relationship);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, 0x14(%rsp)
movl %ecx, 0x8(%rsp)
movl %edx, 0x18(%rsp)
movl %esi, %ebp
movq %rdi, %r14
movq 0x30(%rdi), %rax
xorl %ecx, %ecx
movq %rcx, %r13
movq (%rax), %rcx
leaq 0x28(%rcx), %rax
testq %rcx, %rcx
jne 0x3209d
xorl %r15d, %r15d
testq %r13, %r13
je 0x32144
movl $0xb8, %ebx
movq 0x20(%r13), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x320d7
movq %rax, %r12
movq 0x48(%rax), %rax
testq %rax, %rax
jne 0x320c9
jmp 0x320da
xorl %r12d, %r12d
testq %r12, %r12
je 0x32130
movq 0x18(%r12), %rsi
movq %r14, %rdi
callq 0xcbd0
movq 0x18(%r12), %rax
movq $0x0, 0xb8(%rax)
movq 0x80(%r14), %rcx
movq 0x8(%rcx), %rcx
movq %rax, (%rcx)
movq 0x18(%r12), %rax
addq %rbx, %rax
movq 0x80(%r14), %rcx
movq %rax, 0x8(%rcx)
incl %r15d
movq %r12, %rdi
callq 0x32324
movq %rax, %r12
testq %rax, %rax
jne 0x320df
movq %r13, %rdi
callq 0x2f48f
movq %rax, %r13
testq %rax, %rax
jne 0x320bd
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x322c5
movq %rax, %r13
leaq 0x14d5f(%rip), %rdi     # 0x46ec5
callq 0xcce0
movq %rax, (%r13)
testq %rax, %rax
je 0x322cc
leaq 0x14d52(%rip), %rdx     # 0x46ed1
leaq 0x20(%rsp), %r12
movl $0x20, %esi
movq %r12, %rdi
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0xc570
movq %r12, %rdi
callq 0xcce0
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x322d3
movq %r13, 0x2a8(%r14)
cmpb $0x0, 0x2a1(%r14)
je 0x3222c
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x322e6
movq %rax, %r13
leaq 0x14d0f(%rip), %rdi     # 0x46eee
callq 0xcce0
movq %rax, (%r13)
testq %rax, %rax
je 0x322f0
leaq 0x14d00(%rip), %rdx     # 0x46ef8
leaq 0x20(%rsp), %rbx
movl $0x20, %esi
movq %rbx, %rdi
movl 0x14(%rsp), %ecx
xorl %eax, %eax
callq 0xc570
movq %rbx, %rdi
callq 0xcce0
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x322f7
movq %r13, 0x2b0(%r14)
movq %r13, 0x8(%rsp)
movl %r15d, %r13d
shrl $0xa, %r13d
xorl %r12d, %r12d
movl $0xcccccccd, %eax       # imm = 0xCCCCCCCD
xorl %ecx, %ecx
movl %ecx, %edx
movq %r12, %rsi
addl %ebp, %edx
je 0x3225f
incq %rsi
movl %edx, %edi
imulq %rax, %rdi
shrq $0x23, %rdi
cmpl $0x9, %edx
movl %edi, %edx
ja 0x3224b
leaq 0x1(%rsi), %r12
leal 0x1(%rcx), %edx
cmpl %r13d, %ecx
movl %edx, %ecx
jne 0x32242
addq $0x3, %rsi
movl $0x1, %edi
callq 0xc7f0
testq %rax, %rax
je 0x322da
movq %rax, %rbx
incl %r13d
xorl %eax, %eax
leaq (%rbx,%rax), %rdi
movq %r12, %rsi
subq %rax, %rsi
leaq 0x14c71(%rip), %rdx     # 0x46f0a
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc570
movq %rbx, %rdi
callq 0xc480
incl %ebp
decl %r13d
jne 0x32288
movl 0x18(%rsp), %eax
movl %eax, 0x2e0(%r14)
movq %rbx, 0x2d0(%r14)
jmp 0x3230f
movl $0xe76, %esi            # imm = 0xE76
jmp 0x322eb
movl $0xe79, %esi            # imm = 0xE79
jmp 0x322fc
movl $0xe7f, %esi            # imm = 0xE7F
jmp 0x322fc
movl $0xea9, %esi            # imm = 0xEA9
movq 0x8(%rsp), %r13
jmp 0x322fc
movl $0xe87, %esi            # imm = 0xE87
xorl %r13d, %r13d
jmp 0x322fc
movl $0xe8a, %esi            # imm = 0xE8A
jmp 0x322fc
movl $0xe8f, %esi            # imm = 0xE8F
leaq 0x1c(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rdx
callq 0xebbc
movl (%rbx), %r15d
movl %r15d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq