// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movl %edi, -0x8(%rbp)
leaq 0x8d203(%rip), %rax     # 0xbf0e8
movq 0x668(%rax), %rax
movl 0x28(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x28(%rax)
movl $0x8, %edi
callq 0x320a0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x32160
movq %rax, -0x18(%rbp)
leaq 0x8d1d1(%rip), %rax     # 0xbf0e8
movq 0x660(%rax), %rdi
movl $0x41, %esi
movl $0x1a4, %edx            # imm = 0x1A4
movb $0x0, %al
callq 0x126d0
movl %eax, -0xac(%rbp)
cmpl $-0x1, %eax
jne 0x31f3f
jmp 0x32061
movl -0xac(%rbp), %edi
leaq -0xa8(%rbp), %rsi
callq 0x128a0
cmpl $-0x1, %eax
je 0x31f8d
movq -0x78(%rbp), %rax
cmpq -0x18(%rbp), %rax
jle 0x31f8b
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x1ed40
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
addq -0x18(%rbp), %rdi
movq -0x78(%rbp), %rdx
subq -0x18(%rbp), %rdx
movl $0xa, %esi
callq 0x12370
jmp 0x31f8d
movl -0xac(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x32160
movl -0xc4(%rbp), %edi
movq -0xc0(%rbp), %rsi
movq %rax, %rdx
callq 0x121c0
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x32160
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq %rcx, %rax
je 0x31fe3
jmp 0x32061
cmpl $0x0, -0x8(%rbp)
je 0x3200b
leaq 0x8d0f8(%rip), %rax     # 0xbf0e8
movq 0x668(%rax), %rax
movl 0x28(%rax), %ecx
andl $-0x5, %ecx
movl %ecx, 0x28(%rax)
movl -0xac(%rbp), %edi
callq 0x12720
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x32160
movq %rax, %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
je 0x32044
movl -0xac(%rbp), %edi
movq -0x18(%rbp), %rsi
callq 0x12650
cmpl $-0x1, %eax
jne 0x32044
jmp 0x32044
movl -0xac(%rbp), %edi
callq 0x123a0
movq -0x10(%rbp), %rdi
callq 0x1e3c0
movl $0x0, -0x4(%rbp)
jmp 0x32085
cmpl $-0x1, -0xac(%rbp)
je 0x32075
movl -0xac(%rbp), %edi
callq 0x123a0
movq -0x10(%rbp), %rdi
callq 0x1e3c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)