// File: /workspace/github_c_makefile_star2_O1/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 0x43045(%rip), %r13     # 0x6f088
movq 0x668(%r13), %rax
andl $-0x3, 0x28(%rax)
movl $0x8, %edi
callq 0x2c218
movq %rax, %rbx
movzbl -0x1(%rax), %r14d
movl %r14d, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x2c09b
leaq 0x2a832(%rip), %rcx     # 0x568a4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %r14d
jmp 0x2c09e
movq -0x11(%rbx), %r14
jmp 0x2c09e
movzwl -0x5(%rbx), %r14d
jmp 0x2c09e
movl -0x9(%rbx), %r14d
jmp 0x2c09e
movzbl -0x3(%rbx), %r14d
jmp 0x2c09e
xorl %r14d, %r14d
movq 0x660(%r13), %rdi
movl $0x41, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x126f0
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x2c1bf
leaq 0x8(%rsp), %rsi
movl %ebp, %edi
callq 0x128a0
cmpl $-0x1, %eax
je 0x2c0fb
movq 0x38(%rsp), %rsi
movq %rsi, %r12
subq %r14, %r12
jle 0x2c0fb
movq %rbx, %rdi
callq 0x1e59e
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 0x2c135
leaq 0x2a7a8(%rip), %rcx     # 0x568b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x2c137
movq -0x11(%rbx), %rdx
jmp 0x2c137
movzwl -0x5(%rbx), %edx
jmp 0x2c137
movl -0x9(%rbx), %edx
jmp 0x2c137
movzbl -0x3(%rbx), %edx
jmp 0x2c137
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 0x2c17b
leaq 0x2a776(%rip), %rsi     # 0x568cc
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
shrl $0x3, %ecx
jmp 0x2c17d
movq -0x11(%rbx), %rcx
jmp 0x2c17d
movzwl -0x5(%rbx), %ecx
jmp 0x2c17d
movl -0x9(%rbx), %ecx
jmp 0x2c17d
movzbl -0x3(%rbx), %ecx
jmp 0x2c17d
xorl %ecx, %ecx
cmpq %rcx, %rax
jne 0x2c1bf
testl %r15d, %r15d
je 0x2c199
movq 0x668(%r13), %rax
andl $-0x5, 0x28(%rax)
movl %ebp, %edi
callq 0x12740
movzbl -0x1(%rbx), %eax
movl %eax, %ecx
andl $0x7, %ecx
xorl %r15d, %r15d
cmpl $0x4, %ecx
ja 0x2c1e3
leaq 0x2a72f(%rip), %rdx     # 0x568e0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x2c1e5
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %ebp
jne 0x2c1f4
jmp 0x2c1fb
movq -0x11(%rbx), %rax
jmp 0x2c1e5
movzwl -0x5(%rbx), %eax
jmp 0x2c1e5
movl -0x9(%rbx), %eax
jmp 0x2c1e5
movzbl -0x3(%rbx), %eax
jmp 0x2c1e5
xorl %eax, %eax
cmpq %rax, %r14
je 0x2c1f4
movl %ebp, %edi
movq %r14, %rsi
callq 0x12680
movl %ebp, %edi
callq 0x123b0
movq %rbx, %rdi
callq 0x1ded3
movl %r15d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq