// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rax
testb $0x1, 0x59(%rax)
je 0xf41a
movb $0x1, -0x1(%rbp)
jmp 0xf5e7
movq -0x10(%rbp), %rdi
callq 0xfa20
testb $0x1, %al
jne 0xf430
movb $0x0, -0x1(%rbp)
jmp 0xf5e7
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
callq 0xfaa0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0xf477
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
leaq -0x24(%rbp), %rdx
callq 0xf600
testb $0x1, %al
jne 0xf471
movb $0x0, -0x1(%rbp)
jmp 0xf5e7
movl -0x24(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5170
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0xfc60
testb $0x1, %al
jne 0xf4a6
jmp 0xf5d6
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
shlq $0x4, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rdx
callq 0xfc60
testb $0x1, %al
jne 0xf4d4
jmp 0xf5d6
movq -0x10(%rbp), %rax
imulq $0x18, 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x48(%rbp), %rdx
callq 0xfc60
testb $0x1, %al
jne 0xf4ff
jmp 0xf5d6
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x70(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x38, -0x58(%rbp)
movl $0x1, -0x54(%rbp)
movabsq $0x7863040378630201, %rax # imm = 0x7863040378630201
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x38, %edx
callq 0xfc60
testb $0x1, %al
jne 0xf572
jmp 0xf5d6
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x55c0
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0xfaa0
movl -0x88(%rbp), %edi
movq %rax, %rsi
callq 0x57a0
cmpl $0x0, %eax
je 0xf5ae
jmp 0xf5d6
testb $0x1, -0x11(%rbp)
je 0xf5c8
movl -0x84(%rbp), %edi
callq 0x5870
cmpl $0x0, %eax
je 0xf5c6
jmp 0xf5d6
jmp 0xf5c8
movq -0x10(%rbp), %rax
movb $0x1, 0x59(%rax)
movb $0x1, -0x1(%rbp)
jmp 0xf5e7
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xfcf0
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)