// File: /workspace/github_c_makefile_star2_O1/Paxa[P]fast_excel/libxlsxwriter/src/workbook.c
// Function: workbook_add_worksheet
lxw_worksheet *
workbook_add_worksheet(lxw_workbook *self, const char *sheetname)
{
    lxw_sheet *sheet = NULL;
    lxw_worksheet *worksheet = NULL;
    lxw_worksheet_name *worksheet_name = NULL;
    lxw_error error;
    lxw_worksheet_init_data init_data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    char *new_name = NULL;

    if (sheetname) {
        /* Use the user supplied name. */
        init_data.name = lxw_strdup(sheetname);
        init_data.quoted_name = lxw_quote_sheetname(sheetname);
    }
    else {
        /* Use the default SheetN name. */
        new_name = malloc(LXW_MAX_SHEETNAME_LENGTH);
        GOTO_LABEL_ON_MEM_ERROR(new_name, mem_error);

        lxw_snprintf(new_name, LXW_MAX_SHEETNAME_LENGTH, "Sheet%d",
                     self->num_worksheets + 1);
        init_data.name = new_name;
        init_data.quoted_name = lxw_strdup(new_name);
    }

    /* Check that the worksheet name is valid. */
    error = workbook_validate_sheet_name(self, init_data.name);
    if (error) {
        LXW_WARN_FORMAT2("workbook_add_worksheet(): worksheet name '%s' has "
                         "error: %s", init_data.name, lxw_strerror(error));
        goto mem_error;
    }

    /* Create a struct to find/store the worksheet name/pointer. */
    worksheet_name = calloc(1, sizeof(struct lxw_worksheet_name));
    GOTO_LABEL_ON_MEM_ERROR(worksheet_name, mem_error);

    /* Initialize the metadata to pass to the worksheet. */
    init_data.hidden = 0;
    init_data.index = self->num_sheets;
    init_data.sst = self->sst;
    init_data.optimize = self->options.constant_memory;
    init_data.active_sheet = &self->active_sheet;
    init_data.first_sheet = &self->first_sheet;
    init_data.tmpdir = self->options.tmpdir;
    init_data.default_url_format = self->default_url_format;
    init_data.max_url_length = self->max_url_length;

    /* Create a new worksheet object. */
    worksheet = lxw_worksheet_new(&init_data);
    GOTO_LABEL_ON_MEM_ERROR(worksheet, mem_error);

    /* Add it to the worksheet list. */
    self->num_worksheets++;
    STAILQ_INSERT_TAIL(self->worksheets, worksheet, list_pointers);

    /* Create a new sheet object. */
    sheet = calloc(1, sizeof(lxw_sheet));
    GOTO_LABEL_ON_MEM_ERROR(sheet, mem_error);
    sheet->u.worksheet = worksheet;

    /* Add it to the worksheet list. */
    self->num_sheets++;
    STAILQ_INSERT_TAIL(self->sheets, sheet, list_pointers);

    /* Store the worksheet so we can look it up by name. */
    worksheet_name->name = init_data.name;
    worksheet_name->worksheet = worksheet;
    RB_INSERT(lxw_worksheet_names, self->worksheet_names, worksheet_name);

    return worksheet;

mem_error:
    free((void *) init_data.name);
    free((void *) init_data.quoted_name);
    free(worksheet_name);
    free(worksheet);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
movq $0x0, 0x40(%rsp)
testq %rsi, %rsi
je 0x2b267
movq %rsi, %rbx
movq %rsi, %rdi
callq 0xcce0
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0xc380
jmp 0x2b2aa
movl $0x7f, %edi
callq 0xca50
testq %rax, %rax
je 0x2b622
movq %rax, %rbx
movzwl 0xb2(%r15), %ecx
incl %ecx
leaq 0x1a6de(%rip), %rdx     # 0x4596c
movl $0x7f, %esi
movq %rax, %rdi
xorl %eax, %eax
callq 0xc570
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
callq 0xcce0
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xcfa0
testl %eax, %eax
jne 0x2b5fd
movl $0x1, %edi
movl $0x30, %esi
callq 0xc7f0
testq %rax, %rax
je 0x2b60b
movq %rax, %r14
movq %rsp, %rdi
movb $0x0, 0x2(%rdi)
movzwl 0xb0(%r15), %eax
movw %ax, (%rdi)
movq 0x68(%r15), %rax
movq %rax, 0x18(%rdi)
movb 0x88(%r15), %al
movb %al, 0x3(%rdi)
leaq 0xb8(%r15), %rax
movq %rax, 0x8(%rdi)
leaq 0xb6(%r15), %rax
movq %rax, 0x10(%rdi)
movq 0x90(%r15), %rax
movq %rax, 0x30(%rdi)
movq 0x100(%r15), %rax
movq %rax, 0x38(%rdi)
movzwl 0xcc(%r15), %eax
movw %ax, 0x40(%rdi)
callq 0xc9e0
testq %rax, %rax
je 0x2b612
movq %rax, %rbx
incw 0xb2(%r15)
addq $0x3c0, %rax            # imm = 0x3C0
movq $0x0, 0x3c0(%rbx)
movq 0x10(%r15), %rcx
movq 0x8(%rcx), %rcx
movq %rbx, (%rcx)
movq 0x10(%r15), %rcx
movq %rax, 0x8(%rcx)
movl $0x18, %ebp
movl $0x1, %edi
movl $0x18, %esi
callq 0xc7f0
testq %rax, %rax
je 0x2b61b
movq %rbx, 0x8(%rax)
incw 0xb0(%r15)
movq %rax, %rcx
addq $0x10, %rcx
movq $0x0, 0x10(%rax)
movq 0x8(%r15), %rdx
movq 0x8(%rdx), %rdx
movq %rax, (%rdx)
movq 0x8(%r15), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %r12
movq %r12, (%r14)
movq %rbx, 0x8(%r14)
movq 0x20(%r15), %r15
movq (%r15), %rcx
testq %rcx, %rcx
je 0x2b416
movq %rcx, %r13
movq (%rcx), %rsi
movq %r12, %rdi
callq 0xc130
movl $0x10, %ecx
testl %eax, %eax
js 0x2b3fd
movl $0x18, %ecx
je 0x2b652
movq (%r13,%rcx), %rcx
testq %rcx, %rcx
jne 0x2b3db
notl %eax
shrl $0x1f, %eax
leaq 0x10(,%rax,8), %rbp
jmp 0x2b419
xorl %r13d, %r13d
movq %r13, 0x20(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
movl $0x1, 0x28(%r14)
testq %r13, %r13
je 0x2b5ee
movq %r14, (%r13,%rbp)
xorl %eax, %eax
cmpl $0x1, 0x28(%r13)
jne 0x2b5f1
movq 0x20(%r13), %rcx
movq 0x10(%rcx), %rdx
cmpq %rdx, %r13
je 0x2b474
testq %rdx, %rdx
je 0x2b460
cmpl $0x1, 0x28(%rdx)
je 0x2b483
movq 0x10(%r13), %rdx
cmpq %r14, %rdx
je 0x2b4b1
movq %r13, %rdx
movq %r14, %r13
jmp 0x2b4f4
movq 0x18(%rcx), %rdx
testq %rdx, %rdx
je 0x2b499
cmpl $0x1, 0x28(%rdx)
jne 0x2b499
movl %eax, 0x28(%rdx)
movl %eax, 0x28(%r13)
movl $0x1, 0x28(%rcx)
movq %rcx, %r13
jmp 0x2b5dc
movq 0x18(%r13), %rdx
cmpq %r14, %rdx
je 0x2b547
movq %r13, %rdx
movq %r14, %r13
jmp 0x2b58a
movq 0x18(%rdx), %rsi
movq %rsi, 0x10(%r13)
testq %rsi, %rsi
je 0x2b4c2
movq %r13, 0x20(%rsi)
movq 0x20(%r13), %rdi
movq %rdi, 0x20(%rdx)
movq %r15, %rsi
testq %rdi, %rdi
je 0x2b4e6
movq 0x20(%r13), %rdi
leaq 0x10(%rdi), %r8
leaq 0x18(%rdi), %rsi
cmpq 0x10(%rdi), %r13
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %r13, 0x18(%rdx)
movq %rdx, 0x20(%r13)
movq %r14, %rdx
movl $0x0, 0x28(%rdx)
movl $0x1, 0x28(%rcx)
movq 0x18(%rcx), %rdx
movq 0x10(%rdx), %rsi
movq %rsi, 0x18(%rcx)
testq %rsi, %rsi
je 0x2b517
movq %rcx, 0x20(%rsi)
movq 0x20(%rcx), %rdi
movq %rdi, 0x20(%rdx)
movq %r15, %rsi
testq %rdi, %rdi
je 0x2b53b
movq 0x20(%rcx), %rdi
leaq 0x10(%rdi), %r8
leaq 0x18(%rdi), %rsi
cmpq 0x10(%rdi), %rcx
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %rcx, 0x10(%rdx)
jmp 0x2b5d8
movq 0x10(%rdx), %rsi
movq %rsi, 0x18(%r13)
testq %rsi, %rsi
je 0x2b558
movq %r13, 0x20(%rsi)
movq 0x20(%r13), %rdi
movq %rdi, 0x20(%rdx)
movq %r15, %rsi
testq %rdi, %rdi
je 0x2b57c
movq 0x20(%r13), %rdi
leaq 0x10(%rdi), %r8
leaq 0x18(%rdi), %rsi
cmpq 0x10(%rdi), %r13
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %r13, 0x10(%rdx)
movq %rdx, 0x20(%r13)
movq %r14, %rdx
movl $0x0, 0x28(%rdx)
movl $0x1, 0x28(%rcx)
movq 0x10(%rcx), %rdx
movq 0x18(%rdx), %rsi
movq %rsi, 0x10(%rcx)
testq %rsi, %rsi
je 0x2b5ad
movq %rcx, 0x20(%rsi)
movq 0x20(%rcx), %rdi
movq %rdi, 0x20(%rdx)
movq %r15, %rsi
testq %rdi, %rdi
je 0x2b5d1
movq 0x20(%rcx), %rdi
leaq 0x10(%rdi), %r8
leaq 0x18(%rdi), %rsi
cmpq 0x10(%rdi), %rcx
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %rcx, 0x18(%rdx)
movq %rdx, 0x20(%rcx)
movq %r13, %r14
movq 0x20(%r13), %r13
testq %r13, %r13
jne 0x2b43d
jmp 0x2b5f1
movq %r14, (%r15)
movq (%r15), %rax
movl $0x0, 0x28(%rax)
jmp 0x2b652
leaq 0x20(%rsp), %rdi
movl %eax, %esi
callq 0xdf65
jmp 0x2b627
callq 0xdfef
jmp 0x2b627
callq 0xdfc5
xorl %ebx, %ebx
jmp 0x2b62c
callq 0xdf9b
jmp 0x2b62c
callq 0xe013
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x20(%rsp), %rdi
callq 0xc0c0
movq 0x28(%rsp), %rdi
callq 0xc0c0
movq %r14, %rdi
callq 0xc0c0
movq %rbx, %rdi
callq 0xc0c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq