// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/config.c
// Function: rewriteConfigOverwriteFile
int rewriteConfigOverwriteFile(char *configfile, sds content) {
    int retval = 0;
    int fd = open(configfile,O_RDWR|O_CREAT,0644);
    int content_size = sdslen(content), padding = 0;
    struct stat sb;
    sds content_padded;

    /* 1) Open the old file (or create a new one if it does not
     *    exist), get the size. */
    if (fd == -1) return -1; /* errno set by open(). */
    if (fstat(fd,&sb) == -1) {
        close(fd);
        return -1; /* errno set by fstat(). */
    }

    /* 2) Pad the content at least match the old file size. */
    content_padded = sdsdup(content);
    if (content_size < sb.st_size) {
        /* If the old file was bigger, pad the content with
         * a newline plus as many "#" chars as required. */
        padding = sb.st_size - content_size;
        content_padded = sdsgrowzero(content_padded,sb.st_size);
        content_padded[content_size] = '\n';
        memset(content_padded+content_size+1,'#',padding-1);
    }

    /* 3) Write the new content using a single write(2). */
    if (write(fd,content_padded,strlen(content_padded)) == -1) {
        retval = -1;
        goto cleanup;
    }

    /* 4) Truncate the file to the right length if we used padding. */
    if (padding) {
        if (ftruncate(fd,content_size) == -1) {
            /* Non critical error... */
        }
    }

cleanup:
    sdsfree(content_padded);
    close(fd);
    return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x42, %esi
movl $0x1a4, %edx            # imm = 0x1A4
movb $0x0, %al
callq 0x266a0
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6a970
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x6f827
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6f949
movl -0x20(%rbp), %edi
leaq -0xb8(%rbp), %rsi
callq 0x266f0
cmpl $-0x1, %eax
jne 0x6f84f
movl -0x20(%rbp), %edi
callq 0x26180
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6f949
movq -0x18(%rbp), %rdi
callq 0x38560
movq %rax, -0xc0(%rbp)
movslq -0x24(%rbp), %rax
cmpq -0x88(%rbp), %rax
jge 0x6f8cb
movq -0x88(%rbp), %rax
movslq -0x24(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x28(%rbp)
movq -0xc0(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x38fa0
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb $0xa, (%rax,%rcx)
movq -0xc0(%rbp), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
addq $0x1, %rdi
movl -0x28(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
movl $0x23, %esi
callq 0x26110
movl -0x20(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x264f0
movl -0xcc(%rbp), %edi
movq -0xc8(%rbp), %rsi
movq %rax, %rdx
callq 0x26bc0
cmpq $-0x1, %rax
jne 0x6f912
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x6f92f
cmpl $0x0, -0x28(%rbp)
je 0x6f92d
movl -0x20(%rbp), %edi
movslq -0x24(%rbp), %rsi
callq 0x26730
cmpl $-0x1, %eax
jne 0x6f92b
jmp 0x6f92b
jmp 0x6f92d
jmp 0x6f92f
movq -0xc0(%rbp), %rdi
callq 0x38620
movl -0x20(%rbp), %edi
callq 0x26180
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)