// File: /workspace/github_c_makefile_star2_O2/chriso[P]columnix/lib/writer.c
// Function: cx_row_group_writer_finish
bool cx_row_group_writer_finish(struct cx_row_group_writer *writer, bool sync)
{
    if (writer->footer_written)
        return true;
    if (!cx_row_group_writer_ensure_header(writer))
        return false;

    int32_t metadata_id = -1;
    size_t offset = cx_row_group_writer_offset(writer);

    // write metadata to the string repository
    if (writer->strings.metadata) {
        uint32_t id;
        if (!cx_row_group_writer_add_string(writer, writer->strings.metadata,
                                            &id))
            return false;
        metadata_id = id;
    }

    // write strings
    size_t strings_size;
    const void *strings =
        cx_column_export(writer->strings.column, &strings_size);
    if (!cx_row_group_writer_write(writer, strings, strings_size))
        goto error;

    // write row group headers
    size_t row_group_headers_size =
        writer->row_groups.count * sizeof(struct cx_row_group_header);
    if (!cx_row_group_writer_write(writer, writer->row_groups.headers,
                                   row_group_headers_size))
        goto error;

    // write column headers
    size_t column_descriptors_size =
        writer->columns.count * sizeof(struct cx_column_descriptor);
    if (!cx_row_group_writer_write(writer, writer->columns.descriptors,
                                   column_descriptors_size))
        goto error;

    // write the footer
    struct cx_footer footer = {offset,
                               strings_size,
                               metadata_id,
                               0,
                               writer->row_groups.count,
                               writer->columns.count,
                               writer->row_count,
                               sizeof(footer),
                               CX_FILE_VERSION,
                               CX_FILE_MAGIC};
    if (!cx_row_group_writer_write(writer, &footer, sizeof(footer)))
        goto error;

    // set the file size
    int fd = fileno(writer->file);
    if (ftruncate(fd, cx_row_group_writer_offset(writer)))
        goto error;

    // sync the file
    if (sync) {
#ifdef __APPLE__
        if (fcntl(fd, F_FULLFSYNC))
            goto error;
#else
        if (fsync(fd))
            goto error;
#endif
    }

    writer->footer_written = true;
    return true;
error:
    cx_row_group_writer_seek(writer, offset);
    return false;
}

// Assembly:
movb $0x1, %al
cmpb $0x0, 0x59(%rdi)
jne 0xa86e
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl %esi, %ebp
movq %rdi, %rbx
callq 0xab4b
testb %al, %al
je 0xa860
movq %rbx, %rdi
callq 0xab8f
movq %rax, %r14
movq 0x48(%rbx), %rsi
testq %rsi, %rsi
je 0xa782
movq %rsp, %rdx
movq %rbx, %rdi
callq 0xa888
testb %al, %al
je 0xa860
movl (%rsp), %r12d
jmp 0xa786
pushq $-0x1
popq %r12
movq 0x38(%rbx), %rdi
movq %rsp, %r15
movq %r15, %rsi
callq 0x5160
movq (%r15), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xacae
testb %al, %al
je 0xa855
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
shlq $0x4, %rdx
movq %rbx, %rdi
callq 0xacae
testb %al, %al
je 0xa855
imulq $0x18, 0x10(%rbx), %rdx
movq 0x8(%rbx), %rsi
movq %rbx, %rdi
callq 0xacae
testb %al, %al
je 0xa855
leaq 0x8(%rsp), %rsi
movq %r14, (%rsi)
movq (%rsp), %rax
movq %rax, 0x8(%rsi)
movl %r12d, 0x10(%rsi)
andl $0x0, 0x14(%rsi)
movl 0x28(%rbx), %eax
movl %eax, 0x18(%rsi)
movl 0x10(%rbx), %eax
movl %eax, 0x1c(%rsi)
movq 0x50(%rbx), %rax
movq %rax, 0x20(%rsi)
movabsq $0x100000038, %rax      # imm = 0x100000038
movq %rax, 0x28(%rsi)
movabsq $0x7863040378630201, %rax # imm = 0x7863040378630201
movq %rax, 0x30(%rsi)
pushq $0x38
popq %rdx
movq %rbx, %rdi
callq 0xacae
testb %al, %al
je 0xa855
movq (%rbx), %rdi
callq 0x5570
movl %eax, %r15d
movq %rbx, %rdi
callq 0xab8f
movl %r15d, %edi
movq %rax, %rsi
callq 0x5750
testl %eax, %eax
je 0xa86f
movq %rbx, %rdi
movq %r14, %rsi
callq 0xad04
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testb %bpl, %bpl
je 0xa880
movl %r15d, %edi
callq 0x5820
testl %eax, %eax
jne 0xa855
movb $0x1, 0x59(%rbx)
movb $0x1, %al
jmp 0xa862