// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 currentEpoch and lastVoteEpoch. */
    ci = clusterGenNodesDescription(CLUSTER_NODE_HANDSHAKE);
    ci = sdscatprintf(ci,"vars currentEpoch %llu lastVoteEpoch %llu\n",
        (unsigned long long) server.cluster->currentEpoch,
        (unsigned long long) server.cluster->lastVoteEpoch);
    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, %ebp
leaq 0x9bec8(%rip), %r13     # 0x1018a8
movq 0x9b0(%r13), %rax
andl $-0x5, 0x60080(%rax)
movl $0x20, %edi
callq 0x65be2
movq 0x9b0(%r13), %rcx
movq 0x8(%rcx), %rdx
movq 0x60078(%rcx), %rcx
leaq 0x61dad(%rip), %rsi     # 0xc77be
xorl %r14d, %r14d
movq %rax, %rdi
xorl %eax, %eax
callq 0x36f2d
movq %rax, %rbx
movzbl -0x1(%rax), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x65a5f
leaq 0x61972(%rip), %rdx     # 0xc73a8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
movq %rax, %r14
jmp 0x65a5f
movq -0x11(%rbx), %r14
jmp 0x65a5f
movzwl -0x5(%rbx), %r14d
jmp 0x65a5f
movl -0x9(%rbx), %r14d
jmp 0x65a5f
movzbl -0x3(%rbx), %r14d
movq 0x9a8(%r13), %rdi
movl $0x41, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x26690
cmpl $-0x1, %eax
je 0x65adc
movl %eax, %r15d
leaq 0x8(%rsp), %rsi
movl %eax, %edi
callq 0x266e0
cmpl $-0x1, %eax
je 0x65ab9
movq 0x38(%rsp), %rsi
movq %rsi, %r12
subq %r14, %r12
jle 0x65ab9
movq %rbx, %rdi
callq 0x36a02
movq %rax, %rbx
leaq (%rax,%r14), %rdi
movl $0xa, %esi
movq %r12, %rdx
callq 0x26110
movzbl -0x1(%rbx), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x65afe
leaq 0x618ee(%rip), %rcx     # 0xc73bc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x65b00
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x65bc5
movq -0x11(%rbx), %rdx
jmp 0x65b00
movzwl -0x5(%rbx), %edx
jmp 0x65b00
movl -0x9(%rbx), %edx
jmp 0x65b00
movzbl -0x3(%rbx), %edx
jmp 0x65b00
xorl %edx, %edx
movl %r15d, %edi
movq %rbx, %rsi
callq 0x26bb0
movzbl -0x1(%rbx), %ecx
movl %ecx, %edx
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x65b47
leaq 0x618b0(%rip), %rsi     # 0xc73d0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl %ecx, %edx
shrl $0x3, %edx
jmp 0x65b49
movq -0x11(%rbx), %rdx
jmp 0x65b49
movzwl -0x5(%rbx), %edx
jmp 0x65b49
movl -0x9(%rbx), %edx
jmp 0x65b49
movzbl -0x3(%rbx), %edx
jmp 0x65b49
xorl %edx, %edx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq %rdx, %rax
jne 0x65bbd
testl %ebp, %ebp
je 0x65b72
movq 0x9b0(%r13), %rax
andl $-0x9, 0x60080(%rax)
movl %r15d, %edi
callq 0x26600
movzbl -0x1(%rbx), %ecx
movl %ecx, %eax
andl $0x7, %eax
xorl %r12d, %r12d
cmpl $0x4, %eax
ja 0x65bab
leaq 0x6185e(%rip), %rdx     # 0xc73e4
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
shrl $0x3, %ecx
jmp 0x65bad
movq -0x11(%rbx), %rcx
jmp 0x65bad
movzwl -0x5(%rbx), %ecx
jmp 0x65bad
movl -0x9(%rbx), %ecx
jmp 0x65bad
movzbl -0x3(%rbx), %ecx
jmp 0x65bad
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x65bbd
movl %r15d, %edi
movq %r14, %rsi
callq 0x26730
movl %r15d, %edi
callq 0x26180
movq %rbx, %rdi
callq 0x36330
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq