// File: /workspace/github_c_makefile_star2_O3/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 $0x98, %rsp
movl %r8d, 0x8(%rsp)
movl %ecx, (%rsp)
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
movq 0x30(%rdi), %rax
xorl %ecx, %ecx
movq %rcx, %r12
movq (%rax), %rcx
leaq 0x28(%rcx), %rax
testq %rcx, %rcx
jne 0x32302
xorl %r15d, %r15d
testq %r12, %r12
je 0x32390
movq 0x20(%r12), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x32380
movq %rax, %r13
movq 0x48(%rax), %rax
testq %rax, %rax
jne 0x32326
movq 0x18(%r13), %rsi
movq %r14, %rdi
callq 0xcbd0
movq 0x18(%r13), %rax
leaq 0xb8(%rax), %rcx
movq $0x0, 0xb8(%rax)
movq 0x80(%r14), %rdx
movq 0x8(%rdx), %rdx
movq %rax, (%rdx)
movq 0x80(%r14), %rax
movq %rcx, 0x8(%rax)
incl %r15d
movq %r13, %rdi
callq 0x325b3
movq %rax, %r13
testq %rax, %rax
jne 0x32332
movq %r12, %rdi
callq 0x2f5c0
movq %rax, %r12
testq %rax, %rax
jne 0x32319
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x3251e
movq %rax, %r12
leaq 0x14bff(%rip), %rdi     # 0x46fb1
callq 0xcce0
movq %rax, (%r12)
testq %rax, %rax
je 0x32525
movq %rax, %r13
movl %ebx, 0xc(%rsp)
leaq 0x14beb(%rip), %rdx     # 0x46fbd
leaq 0x10(%rsp), %rbx
movl $0x20, %esi
movq %rbx, %rdi
movl (%rsp), %ecx
xorl %eax, %eax
callq 0xc570
movq %rbx, %rdi
callq 0xcce0
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x3252c
movq %r12, 0x2a8(%r14)
cmpb $0x0, 0x2a1(%r14)
je 0x32483
movl $0x1, %edi
movl $0x20, %esi
callq 0xc7f0
testq %rax, %rax
je 0x32561
movq %rax, %r12
leaq 0x14ba8(%rip), %rdi     # 0x46fda
callq 0xcce0
movq %rax, (%r12)
testq %rax, %rax
je 0x32568
movq %rax, %r13
leaq 0x14b96(%rip), %rdx     # 0x46fe4
leaq 0x10(%rsp), %rbx
movl $0x20, %esi
movq %rbx, %rdi
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0xc570
movq %rbx, %rdi
callq 0xcce0
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x32572
movq %r12, 0x2b0(%r14)
movq %r12, (%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 0x324b5
incq %rsi
movl %edx, %edi
imulq %rax, %rdi
shrq $0x23, %rdi
cmpl $0x9, %edx
movl %edi, %edx
ja 0x324a1
leaq 0x1(%rsi), %r12
leal 0x1(%rcx), %edx
cmpl %r13d, %ecx
movl %edx, %ecx
jne 0x32498
addq $0x3, %rsi
movl $0x1, %edi
callq 0xc7f0
testq %rax, %rax
je 0x32533
movq %rax, %rbx
incl %r13d
xorl %eax, %eax
leaq (%rbx,%rax), %rdi
movq %r12, %rsi
subq %rax, %rsi
leaq 0x14b07(%rip), %rdx     # 0x46ff6
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc570
movq %rbx, %rdi
callq 0xc480
incl %ebp
decl %r13d
jne 0x324de
movl 0xc(%rsp), %eax
movl %eax, 0x2e0(%r14)
movq %rbx, 0x2d0(%r14)
jmp 0x3259e
callq 0xeff5
jmp 0x3259b
callq 0xefd1
jmp 0x3256d
callq 0xefa7
jmp 0x32577
movq 0x24abe(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0xdb9c(%rip), %rsi      # 0x400e0
leaq 0x144a9(%rip), %rdx     # 0x469f4
movl $0xea9, %ecx            # imm = 0xEA9
xorl %eax, %eax
callq 0xc870
movq (%rsp), %r12
movq (%r12), %r13
jmp 0x32577
callq 0xef7d
jmp 0x3259b
callq 0xef53
xorl %r13d, %r13d
jmp 0x32577
callq 0xef29
movq %r13, %rdi
callq 0xc0c0
movq 0x8(%r12), %rdi
callq 0xc0c0
movq 0x10(%r12), %rdi
callq 0xc0c0
movq %r12, %rdi
callq 0xc0c0
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq