// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/redis-cli.c
// Function: getRDB
static void getRDB(void) {
    int s = context->fd;
    int fd;
    unsigned long long payload = sendSync(s);
    char buf[4096];

    fprintf(stderr,"SYNC sent to master, writing %llu bytes to '%s'\n",
        payload, config.rdb_filename);

    /* Write to file. */
    if (!strcmp(config.rdb_filename,"-")) {
        fd = STDOUT_FILENO;
    } else {
        fd = open(config.rdb_filename, O_CREAT|O_WRONLY, 0644);
        if (fd == -1) {
            fprintf(stderr, "Error opening '%s': %s\n", config.rdb_filename,
                strerror(errno));
            exit(1);
        }
    }

    while(payload) {
        ssize_t nread, nwritten;

        nread = read(s,buf,(payload > sizeof(buf)) ? sizeof(buf) : payload);
        if (nread <= 0) {
            fprintf(stderr,"I/O Error reading RDB payload from socket\n");
            exit(1);
        }
        nwritten = write(fd, buf, nread);
        if (nwritten != nread) {
            fprintf(stderr,"Error writing data to file: %s\n",
                strerror(errno));
            exit(1);
        }
        payload -= nread;
    }
    close(s); /* Close the file descriptor ASAP as fsync() may take time. */
    fsync(fd);
    fprintf(stderr,"Transfer finished with success.\n");
    exit(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1050, %rsp           # imm = 0x1050
movq 0x8ca16(%rip), %rax     # 0xa15d8
movl 0x84(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %edi
callq 0x13300
movq %rax, -0x10(%rbp)
movq 0x8a412(%rip), %rax     # 0x9eff0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq 0x8c924(%rip), %rcx     # 0xa1510
leaq 0x7738e(%rip), %rsi     # 0x8bf81
movb $0x0, %al
callq 0x10360
movq 0x8c90f(%rip), %rdi     # 0xa1510
leaq 0x729cb(%rip), %rsi     # 0x875d3
callq 0x10330
cmpl $0x0, %eax
jne 0x14c1b
movl $0x1, -0x8(%rbp)
jmp 0x14c92
movq 0x8c8ee(%rip), %rdi     # 0xa1510
movl $0x41, %esi
movl $0x1a4, %edx            # imm = 0x1A4
movb $0x0, %al
callq 0x104e0
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
jne 0x14c90
movq 0x8a3ad(%rip), %rax     # 0x9eff0
movq (%rax), %rax
movq %rax, -0x1030(%rbp)
movq 0x8c8bc(%rip), %rax     # 0xa1510
movq %rax, -0x1028(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x1030(%rbp), %rdi
movq -0x1028(%rbp), %rdx
movq %rax, %rcx
leaq 0x77333(%rip), %rsi     # 0x8bfb2
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
jmp 0x14c92
jmp 0x14c94
cmpq $0x0, -0x10(%rbp)
je 0x14da8
movl -0x4(%rbp), %eax
movl %eax, -0x103c(%rbp)
leaq -0x1010(%rbp), %rax
movq %rax, -0x1038(%rbp)
cmpq $0x1000, -0x10(%rbp)    # imm = 0x1000
jbe 0x14cce
movl $0x1000, %eax           # imm = 0x1000
movq %rax, -0x1048(%rbp)
jmp 0x14cd9
movq -0x10(%rbp), %rax
movq %rax, -0x1048(%rbp)
movq -0x1038(%rbp), %rsi
movl -0x103c(%rbp), %edi
movq -0x1048(%rbp), %rdx
callq 0x102b0
movq %rax, -0x1018(%rbp)
cmpq $0x0, -0x1018(%rbp)
jg 0x14d25
movq 0x8a2e6(%rip), %rax     # 0x9eff0
movq (%rax), %rdi
leaq 0x772b6(%rip), %rsi     # 0x8bfca
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
movl -0x8(%rbp), %edi
leaq -0x1010(%rbp), %rsi
movq -0x1018(%rbp), %rdx
callq 0x10150
movq %rax, -0x1020(%rbp)
movq -0x1020(%rbp), %rax
cmpq -0x1018(%rbp), %rax
je 0x14d91
movq 0x8a297(%rip), %rax     # 0x9eff0
movq (%rax), %rax
movq %rax, -0x1050(%rbp)
callq 0x10080
movl (%rax), %edi
callq 0x10660
movq -0x1050(%rbp), %rdi
movq %rax, %rdx
leaq 0x77275(%rip), %rsi     # 0x8bff5
movb $0x0, %al
callq 0x10360
movl $0x1, %edi
callq 0x10600
movq -0x1018(%rbp), %rcx
movq -0x10(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x10(%rbp)
jmp 0x14c94
movl -0x4(%rbp), %edi
callq 0x10280
movl -0x8(%rbp), %edi
callq 0x10510
movq 0x8a231(%rip), %rax     # 0x9eff0
movq (%rax), %rdi
leaq 0x7724c(%rip), %rsi     # 0x8c015
movb $0x0, %al
callq 0x10360
xorl %edi, %edi
callq 0x10600
nopw (%rax,%rax)