// File: /workspace/github_c_makefile_star2_O2/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)
andq $0x0, 0x40(%rsp)
testq %rsi, %rsi
je 0x27e42
movq %rsi, %rbx
movq %rsi, %rdi
callq 0xcd50
movq %rax, %r14
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0xc3b0
jmp 0x27e81
pushq $0x7f
popq %rdi
callq 0xcab0
testq %rax, %rax
je 0x2824a
movq %rax, %r14
movzwl 0xb2(%r15), %ecx
incl %ecx
leaq 0x1aaf5(%rip), %rdx     # 0x4295c
pushq $0x7f
popq %rsi
movq %rax, %rdi
xorl %eax, %eax
callq 0xc5b0
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0xcd50
movq %rax, 0x28(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0xd020
testl %eax, %eax
jne 0x281b3
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0xc850
testq %rax, %rax
je 0x281e2
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 0xca40
testq %rax, %rax
je 0x28203
movq %rax, %rbx
incw 0xb2(%r15)
addq $0x3c0, %rax            # imm = 0x3C0
andq $0x0, 0x3c0(%rbx)
movq 0x10(%r15), %rcx
movq 0x8(%rcx), %rcx
movq %rbx, (%rcx)
movq 0x10(%r15), %rcx
movq %rax, 0x8(%rcx)
pushq $0x1
popq %rdi
pushq $0x18
popq %r12
movq %r12, %rsi
callq 0xc850
testq %rax, %rax
je 0x28224
movq %rbx, 0x8(%rax)
incw 0xb0(%r15)
movq %rax, %rcx
addq $0x10, %rcx
movq 0x8(%r15), %rdx
movq 0x8(%rdx), %rdx
movq %rax, (%rdx)
movq 0x8(%r15), %rax
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rax
movq %rax, (%r14)
movq %rbx, 0x8(%r14)
movq 0x20(%r15), %r13
xorl %ecx, %ecx
pushq $0x10
popq %rbp
movq %r13, %rdx
xorl %eax, %eax
movq (%rdx), %r15
testq %r15, %r15
je 0x27fc9
movq %r14, %rdi
movq %r15, %rsi
callq 0x2a14e
movq %rbp, %rdx
testl %eax, %eax
js 0x27fc1
movq %r12, %rdx
je 0x28299
addq %r15, %rdx
movq %r15, %rcx
jmp 0x27f9e
movq %rcx, 0x20(%r14)
movl $0x1, 0x28(%r14)
movq %r13, %rdx
testq %rcx, %rcx
je 0x27feb
testl %eax, %eax
js 0x27fe7
leaq 0x18(%rcx), %rdx
jmp 0x27feb
leaq 0x10(%rcx), %rdx
movq %r14, (%rdx)
testq %rcx, %rcx
je 0x281a6
cmpl $0x1, 0x28(%rcx)
jne 0x281a6
movq 0x20(%rcx), %rax
movq 0x10(%rax), %rdx
cmpq %rdx, %rcx
je 0x28033
testq %rdx, %rdx
je 0x2801f
cmpl $0x1, 0x28(%rdx)
jne 0x2801f
andl $0x0, 0x28(%rdx)
jmp 0x28046
movq 0x10(%rcx), %rdx
cmpq %r14, %rdx
je 0x2806d
movq %rcx, %rdx
movq %r14, %rcx
jmp 0x280e0
movq 0x18(%rax), %rsi
testq %rsi, %rsi
je 0x28059
cmpl $0x1, 0x28(%rsi)
jne 0x28059
andl $0x0, 0x28(%rsi)
andl $0x0, 0x28(%rcx)
movl $0x1, 0x28(%rax)
movq %rax, %rcx
jmp 0x2819a
movq 0x18(%rcx), %rsi
cmpq %r14, %rsi
je 0x28090
movq %rcx, %rsi
movq %r14, %rcx
jmp 0x28153
movq 0x18(%rdx), %rsi
movq %rsi, 0x10(%rcx)
testq %rsi, %rsi
je 0x280ba
movq %rcx, 0x20(%rsi)
movq 0x20(%rcx), %rsi
movq %rsi, 0x20(%rdx)
movq %r13, %rdi
testq %rsi, %rsi
jne 0x280c2
jmp 0x280d2
movq 0x10(%rsi), %rdx
movq %rdx, 0x18(%rcx)
testq %rdx, %rdx
je 0x28129
movq %rcx, 0x20(%rdx)
movq 0x20(%rcx), %rdx
movq %rdx, 0x20(%rsi)
movq %r13, %rdi
testq %rdx, %rdx
jne 0x28131
jmp 0x28141
movq %rax, 0x20(%rdx)
movq 0x20(%rcx), %rsi
leaq 0x10(%rsi), %r8
leaq 0x18(%rsi), %rdi
cmpq 0x10(%rsi), %rcx
cmoveq %r8, %rdi
movq %rdx, (%rdi)
movq %rcx, 0x18(%rdx)
movq %rdx, 0x20(%rcx)
movq %r14, %rdx
andl $0x0, 0x28(%rdx)
movl $0x1, 0x28(%rax)
movq 0x18(%rax), %rdx
movq 0x10(%rdx), %rsi
movq %rsi, 0x18(%rax)
testq %rsi, %rsi
je 0x28100
movq %rax, 0x20(%rsi)
movq 0x20(%rax), %rdi
movq %rdi, 0x20(%rdx)
movq %r13, %rsi
testq %rdi, %rdi
je 0x28120
leaq 0x10(%rdi), %r8
leaq 0x18(%rdi), %rsi
cmpq 0x10(%rdi), %rax
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %rax, 0x10(%rdx)
jmp 0x28196
movq %rax, 0x20(%rsi)
movq 0x20(%rcx), %rdx
leaq 0x10(%rdx), %r8
leaq 0x18(%rdx), %rdi
cmpq 0x10(%rdx), %rcx
cmoveq %r8, %rdi
movq %rsi, (%rdi)
movq %rcx, 0x10(%rsi)
movq %rsi, 0x20(%rcx)
movq 0x10(%rax), %rdx
movq %r14, %rsi
andl $0x0, 0x28(%rsi)
movl $0x1, 0x28(%rax)
movq 0x18(%rdx), %rsi
movq %rsi, 0x10(%rax)
testq %rsi, %rsi
je 0x2816f
movq %rax, 0x20(%rsi)
movq 0x20(%rax), %rdi
movq %rdi, 0x20(%rdx)
movq %r13, %rsi
testq %rdi, %rdi
je 0x2818f
leaq 0x10(%rdi), %r8
leaq 0x18(%rdi), %rsi
cmpq 0x10(%rdi), %rax
cmoveq %r8, %rsi
movq %rdx, (%rsi)
movq %rax, 0x18(%rdx)
movq %rdx, 0x20(%rax)
movq %rcx, %r14
movq 0x20(%rcx), %rcx
jmp 0x27fee
movq (%r13), %rax
andl $0x0, 0x28(%rax)
jmp 0x28299
movq 0x2ae3e(%rip), %rcx     # 0x52ff8
movq (%rcx), %r15
movl %eax, %edi
callq 0xc3f0
leaq 0x1a799(%rip), %rsi     # 0x42964
xorl %ebx, %ebx
movq %r15, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xc8d0
jmp 0x28270
movq 0x2ae0f(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x14eed(%rip), %rsi     # 0x3d0e0
leaq 0x1a757(%rip), %rdx     # 0x42951
xorl %ebx, %ebx
movl $0x791, %ecx            # imm = 0x791
jmp 0x28269
movq 0x2adee(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x14ecc(%rip), %rsi     # 0x3d0e0
leaq 0x1a736(%rip), %rdx     # 0x42951
xorl %ebx, %ebx
movl $0x7a0, %ecx            # imm = 0x7A0
jmp 0x28241
movq 0x2adcd(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x14eab(%rip), %rsi     # 0x3d0e0
leaq 0x1a715(%rip), %rdx     # 0x42951
movl $0x7a8, %ecx            # imm = 0x7A8
xorl %eax, %eax
callq 0xc8d0
jmp 0x28273
movq 0x2ada7(%rip), %rax     # 0x52ff8
movq (%rax), %rdi
leaq 0x14e85(%rip), %rsi     # 0x3d0e0
leaq 0x1a6ef(%rip), %rdx     # 0x42951
xorl %ebx, %ebx
movl $0x77f, %ecx            # imm = 0x77F
xorl %eax, %eax
callq 0xc8d0
xorl %r14d, %r14d
movq 0x20(%rsp), %rdi
callq 0xc0d0
movq 0x28(%rsp), %rdi
callq 0xc0d0
movq %r14, %rdi
callq 0xc0d0
movq %rbx, %rdi
callq 0xc0d0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq