// File: /workspace/github_c_makefile_star2_O3/erikdubbelboer[P]discnt/src/cluster.c
// Function: clusterSaveConfig
int clusterSaveConfig(int do_fsync) {
    sds ci;
    size_t content_size;
    struct stat sb;
    int fd;

    server.cluster->todo_before_sleep &= ~CLUSTER_TODO_SAVE_CONFIG;

    /* Get the nodes description and concatenate our "vars" directive to
     * save other persistent state. */
    ci = clusterGenNodesDescription(CLUSTER_NODE_HANDSHAKE);
#if 0 /* TODO: check if we are going to use persistent vars. */
    ci = sdscatprintf(ci,"vars currentEpoch %llu lastVoteEpoch %llu\n",
        (unsigned long long) server.cluster->currentEpoch,
        (unsigned long long) server.cluster->lastVoteEpoch);
#endif
    content_size = sdslen(ci);

    if ((fd = open(server.cluster_configfile,O_WRONLY|O_CREAT,0644))
        == -1) goto err;

    /* Pad the new payload if the existing file length is greater. */
    if (fstat(fd,&sb) != -1) {
        if (sb.st_size > (off_t)content_size) {
            ci = sdsgrowzero(ci,sb.st_size);
            memset(ci+content_size,'\n',sb.st_size-content_size);
        }
    }
    if (write(fd,ci,sdslen(ci)) != (ssize_t)sdslen(ci)) goto err;
    if (do_fsync) {
        server.cluster->todo_before_sleep &= ~CLUSTER_TODO_FSYNC_CONFIG;
        fsync(fd);
    }

    /* Truncate the file if needed to remove the final \n padding that
     * is just garbage. */
    if (content_size != sdslen(ci) && ftruncate(fd,content_size) == -1) {
        /* ftruncate() failing is not a critical error. */
    }
    close(fd);
    sdsfree(ci);
    return 0;

err:
    if (fd != -1) close(fd);
    sdsfree(ci);
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %edi, %r15d
leaq 0x43632(%rip), %r13     # 0x6f088
movq 0x668(%r13), %rax
andl $-0x3, 0x28(%rax)
movl $0x8, %edi
callq 0x2bc2d
movq %rax, %rbx
movzbl -0x1(%rax), %r14d
movl %r14d, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x2baae
leaq 0x2ae0f(%rip), %rcx     # 0x56894
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %r14d
jmp 0x2bab1
movq -0x11(%rbx), %r14
jmp 0x2bab1
movzwl -0x5(%rbx), %r14d
jmp 0x2bab1
movl -0x9(%rbx), %r14d
jmp 0x2bab1
movzbl -0x3(%rbx), %r14d
jmp 0x2bab1
xorl %r14d, %r14d
movq 0x660(%r13), %rdi
movl $0x41, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x126e0
cmpl $-0x1, %eax
je 0x2bb2d
movl %eax, %ebp
leaq 0x8(%rsp), %rsi
movl %eax, %edi
callq 0x12890
cmpl $-0x1, %eax
je 0x2bb0a
movq 0x38(%rsp), %rsi
movq %rsi, %r12
subq %r14, %r12
jle 0x2bb0a
movq %rbx, %rdi
callq 0x1e2fb
movq %rax, %rbx
leaq (%rax,%r14), %rdi
movl $0xa, %esi
movq %r12, %rdx
callq 0x12380
movzbl -0x1(%rbx), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x2bb4f
leaq 0x2ad89(%rip), %rcx     # 0x568a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x2bb51
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x2bc10
movq -0x11(%rbx), %rdx
jmp 0x2bb51
movzwl -0x5(%rbx), %edx
jmp 0x2bb51
movl -0x9(%rbx), %edx
jmp 0x2bb51
movzbl -0x3(%rbx), %edx
jmp 0x2bb51
xorl %edx, %edx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x121e0
movzbl -0x1(%rbx), %ecx
movl %ecx, %edx
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x2bb97
leaq 0x2ad4c(%rip), %rsi     # 0x568bc
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl %ecx, %edx
shrl $0x3, %edx
jmp 0x2bb99
movq -0x11(%rbx), %rdx
jmp 0x2bb99
movzwl -0x5(%rbx), %edx
jmp 0x2bb99
movl -0x9(%rbx), %edx
jmp 0x2bb99
movzbl -0x3(%rbx), %edx
jmp 0x2bb99
xorl %edx, %edx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq %rdx, %rax
jne 0x2bc09
testl %r15d, %r15d
je 0x2bbbf
movq 0x668(%r13), %rax
andl $-0x5, 0x28(%rax)
movl %ebp, %edi
callq 0x12730
movzbl -0x1(%rbx), %ecx
movl %ecx, %eax
andl $0x7, %eax
xorl %r12d, %r12d
cmpl $0x4, %eax
ja 0x2bbf8
leaq 0x2acfd(%rip), %rdx     # 0x568d0
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
shrl $0x3, %ecx
jmp 0x2bbfa
movq -0x11(%rbx), %rcx
jmp 0x2bbfa
movzwl -0x5(%rbx), %ecx
jmp 0x2bbfa
movl -0x9(%rbx), %ecx
jmp 0x2bbfa
movzbl -0x3(%rbx), %ecx
jmp 0x2bbfa
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x2bc09
movl %ebp, %edi
movq %r14, %rsi
callq 0x12670
movl %ebp, %edi
callq 0x123b0
movq %rbx, %rdi
callq 0x1dc25
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq