// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/aof.c
// Function: loadAppendOnlyFile
int loadAppendOnlyFile(char *filename) {
    struct client *fakeClient;
    FILE *fp = fopen(filename,"r");
    struct redis_stat sb;
    int old_aof_state = server.aof_state;
    long loops = 0;
    off_t valid_up_to = 0; /* Offset of the latest well-formed command loaded. */

    if (fp && redis_fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) {
        server.aof_current_size = 0;
        fclose(fp);
        return C_ERR;
    }

    if (fp == NULL) {
        serverLog(LL_WARNING,"Fatal error: can't open the append log file for reading: %s",strerror(errno));
        exit(1);
    }

    /* Temporarily disable AOF, to prevent EXEC from feeding a MULTI
     * to the same file we're about to read. */
    server.aof_state = AOF_OFF;

    fakeClient = createFakeClient();
    startLoading(fp);

    while(1) {
        int argc, j;
        unsigned long len;
        robj **argv;
        char buf[128];
        sds argsds;
        struct redisCommand *cmd;

        /* Serve the clients from time to time */
        if (!(loops++ % 1000)) {
            loadingProgress(ftello(fp));
            processEventsWhileBlocked();
        }

        if (fgets(buf,sizeof(buf),fp) == NULL) {
            if (feof(fp))
                break;
            else
                goto readerr;
        }
        if (buf[0] != '*') goto fmterr;
        if (buf[1] == '\0') goto readerr;
        argc = atoi(buf+1);
        if (argc < 1) goto fmterr;

        argv = zmalloc(sizeof(robj*)*argc);
        fakeClient->argc = argc;
        fakeClient->argv = argv;

        for (j = 0; j < argc; j++) {
            if (fgets(buf,sizeof(buf),fp) == NULL) {
                fakeClient->argc = j; /* Free up to j-1. */
                freeFakeClientArgv(fakeClient);
                goto readerr;
            }
            if (buf[0] != '$') goto fmterr;
            len = strtol(buf+1,NULL,10);
            argsds = sdsnewlen(NULL,len);
            if (len && fread(argsds,len,1,fp) == 0) {
                sdsfree(argsds);
                fakeClient->argc = j; /* Free up to j-1. */
                freeFakeClientArgv(fakeClient);
                goto readerr;
            }
            argv[j] = createObject(OBJ_STRING,argsds);
            if (fread(buf,2,1,fp) == 0) {
                fakeClient->argc = j+1; /* Free up to j. */
                freeFakeClientArgv(fakeClient);
                goto readerr; /* discard CRLF */
            }
        }

        /* Command lookup */
        cmd = lookupCommand(argv[0]->ptr);
        if (!cmd) {
            serverLog(LL_WARNING,"Unknown command '%s' reading the append only file", (char*)argv[0]->ptr);
            exit(1);
        }

        /* Run the command in the context of a fake client */
        cmd->proc(fakeClient);

        /* The fake client should not have a reply */
        serverAssert(fakeClient->bufpos == 0 && listLength(fakeClient->reply) == 0);
        /* The fake client should never get blocked */
        serverAssert((fakeClient->flags & CLIENT_BLOCKED) == 0);

        /* Clean up. Command code may have changed argv/argc so we use the
         * argv/argc of the client instead of the local variables. */
        freeFakeClientArgv(fakeClient);
        if (server.aof_load_truncated) valid_up_to = ftello(fp);
    }

    /* This point can only be reached when EOF is reached without errors.
     * If the client is in the middle of a MULTI/EXEC, log error and quit. */
    if (fakeClient->flags & CLIENT_MULTI) goto uxeof;

loaded_ok: /* DB loaded, cleanup and return C_OK to the caller. */
    fclose(fp);
    freeFakeClient(fakeClient);
    server.aof_state = old_aof_state;
    stopLoading();
    aofUpdateCurrentSize();
    server.aof_rewrite_base_size = server.aof_current_size;
    return C_OK;

readerr: /* Read error. If feof(fp) is true, fall through to unexpected EOF. */
    if (!feof(fp)) {
        if (fakeClient) freeFakeClient(fakeClient); /* avoid valgrind warning */
        serverLog(LL_WARNING,"Unrecoverable error reading the append only file: %s", strerror(errno));
        exit(1);
    }

uxeof: /* Unexpected AOF end of file. */
    if (server.aof_load_truncated) {
        serverLog(LL_WARNING,"!!! Warning: short read while loading the AOF file !!!");
        serverLog(LL_WARNING,"!!! Truncating the AOF at offset %llu !!!",
            (unsigned long long) valid_up_to);
        if (valid_up_to == -1 || truncate(filename,valid_up_to) == -1) {
            if (valid_up_to == -1) {
                serverLog(LL_WARNING,"Last valid command offset is invalid");
            } else {
                serverLog(LL_WARNING,"Error truncating the AOF file: %s",
                    strerror(errno));
            }
        } else {
            /* Make sure the AOF file descriptor points to the end of the
             * file after the truncate call. */
            if (server.aof_fd != -1 && lseek(server.aof_fd,0,SEEK_END) == -1) {
                serverLog(LL_WARNING,"Can't seek the end of the AOF file: %s",
                    strerror(errno));
            } else {
                serverLog(LL_WARNING,
                    "AOF loaded anyway because aof-load-truncated is enabled");
                goto loaded_ok;
            }
        }
    }
    if (fakeClient) freeFakeClient(fakeClient); /* avoid valgrind warning */
    serverLog(LL_WARNING,"Unexpected end of file reading the append only file. You can: 1) Make a backup of your AOF file, then use ./redis-check-aof --fix <filename>. 2) Alternatively you can set the 'aof-load-truncated' configuration option to yes and restart the server.");
    exit(1);

fmterr: /* Format error. */
    if (fakeClient) freeFakeClient(fakeClient); /* avoid valgrind warning */
    serverLog(LL_WARNING,"Bad file format reading the append only file: make a backup of your AOF file, then use ./redis-check-aof --fix <filename>");
    exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xc856f(%rip), %rsi     # 0x13a7c9
callq 0x26ae0
movq %rax, -0x20(%rbp)
leaq 0x105f6e(%rip), %rax    # 0x1781d8
movl 0x668(%rax), %eax
movl %eax, -0xb4(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x722dd
movq -0x20(%rbp), %rdi
callq 0x26070
movl %eax, %edi
leaq -0xb0(%rbp), %rsi
callq 0x266f0
cmpl $-0x1, %eax
je 0x722dd
cmpq $0x0, -0x80(%rbp)
jne 0x722dd
leaq 0x105f1b(%rip), %rax    # 0x1781d8
movq $0x0, 0x690(%rax)
movq -0x20(%rbp), %rdi
callq 0x26a10
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x728ac
cmpq $0x0, -0x20(%rbp)
jne 0x72310
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq %rax, %rdx
movl $0x3, %edi
leaq 0xcd4d2(%rip), %rsi     # 0x13f7d1
movb $0x0, %al
callq 0x2fc60
movl $0x1, %edi
callq 0x262d0
leaq 0x105ec1(%rip), %rax    # 0x1781d8
movl $0x0, 0x668(%rax)
callq 0x72060
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rdi
callq 0x56270
movq -0xc0(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0xc0(%rbp)
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x7236e
movq -0x20(%rbp), %rdi
callq 0x26be0
movq %rax, %rdi
callq 0x56310
callq 0x46e80
leaq -0x160(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x80, %esi
callq 0x26440
cmpq $0x0, %rax
jne 0x723a1
movq -0x20(%rbp), %rdi
callq 0x269f0
cmpl $0x0, %eax
je 0x7239c
jmp 0x72682
jmp 0x726f2
movsbl -0x160(%rbp), %eax
cmpl $0x2a, %eax
je 0x723b2
jmp 0x7287f
movsbl -0x15f(%rbp), %eax
cmpl $0x0, %eax
jne 0x723c3
jmp 0x726f2
leaq -0x160(%rbp), %rdi
addq $0x1, %rdi
callq 0x26760
movl %eax, -0xcc(%rbp)
cmpl $0x1, -0xcc(%rbp)
jge 0x723e7
jmp 0x7287f
movslq -0xcc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3acd0
movq %rax, -0xe0(%rbp)
movl -0xcc(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0xe0(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movl $0x0, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jge 0x7257e
leaq -0x160(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x80, %esi
callq 0x26440
cmpq $0x0, %rax
jne 0x7246c
movl -0xd0(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rdi
callq 0x72190
jmp 0x726f2
movsbl -0x160(%rbp), %eax
cmpl $0x24, %eax
je 0x7247d
jmp 0x7287f
leaq -0x160(%rbp), %rdi
addq $0x1, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x26720
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x38230
movq %rax, -0x168(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x72507
movq -0x168(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0x20(%rbp), %rcx
movl $0x1, %edx
callq 0x26820
cmpq $0x0, %rax
jne 0x72507
movq -0x168(%rbp), %rdi
callq 0x38620
movl -0xd0(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rdi
callq 0x72190
jmp 0x726f2
movq -0x168(%rbp), %rsi
xorl %edi, %edi
callq 0x48480
movq %rax, %rdx
movq -0xe0(%rbp), %rax
movslq -0xd0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq -0x160(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x2, %esi
movl $0x1, %edx
callq 0x26820
cmpq $0x0, %rax
jne 0x72568
movl -0xd0(%rbp), %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rdi
callq 0x72190
jmp 0x726f2
jmp 0x7256a
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x72424
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdi
callq 0x33b00
movq %rax, -0x170(%rbp)
cmpq $0x0, -0x170(%rbp)
jne 0x725cd
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0xcd251(%rip), %rsi     # 0x13f80d
movb $0x0, %al
callq 0x2fc60
movl $0x1, %edi
callq 0x262d0
movq -0x170(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1c0(%rax)
jne 0x725fc
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
cmpq $0x0, 0x28(%rax)
jne 0x725fc
jmp 0x7261e
leaq 0xcd23c(%rip), %rdi     # 0x13f83f
leaq 0xccd6d(%rip), %rsi     # 0x13f377
movl $0x2cf, %edx            # imm = 0x2CF
callq 0x76ce0
movl $0x1, %edi
callq 0x263c0
movq -0x18(%rbp), %rax
movl 0x98(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x72632
jmp 0x72654
leaq 0xcd244(%rip), %rdi     # 0x13f87d
leaq 0xccd37(%rip), %rsi     # 0x13f377
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x76ce0
movl $0x1, %edi
callq 0x263c0
movq -0x18(%rbp), %rdi
callq 0x72190
leaq 0x105b74(%rip), %rax    # 0x1781d8
cmpl $0x0, 0x6f4(%rax)
je 0x7267d
movq -0x20(%rbp), %rdi
callq 0x26be0
movq %rax, -0xc8(%rbp)
jmp 0x72333
movq -0x18(%rbp), %rax
movl 0x98(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x72699
jmp 0x7273e
jmp 0x7269b
movq -0x20(%rbp), %rdi
callq 0x26a10
movq -0x18(%rbp), %rdi
callq 0x721f0
movl -0xb4(%rbp), %ecx
leaq 0x105b1e(%rip), %rax    # 0x1781d8
movl %ecx, 0x668(%rax)
callq 0x56370
callq 0x728c0
leaq 0x105b07(%rip), %rax    # 0x1781d8
movq 0x690(%rax), %rcx
leaq 0x105af9(%rip), %rax    # 0x1781d8
movq %rcx, 0x688(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x728ac
movq -0x20(%rbp), %rdi
callq 0x269f0
cmpl $0x0, %eax
jne 0x7273c
cmpq $0x0, -0x18(%rbp)
je 0x72710
movq -0x18(%rbp), %rdi
callq 0x721f0
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq %rax, %rdx
movl $0x3, %edi
leaq 0xcd17c(%rip), %rsi     # 0x13f8a7
movb $0x0, %al
callq 0x2fc60
movl $0x1, %edi
callq 0x262d0
jmp 0x7273e
leaq 0x105a93(%rip), %rax    # 0x1781d8
cmpl $0x0, 0x6f4(%rax)
je 0x72852
movl $0x3, %edi
leaq 0xcd17e(%rip), %rsi     # 0x13f8dc
movb $0x0, %al
callq 0x2fc60
movq -0xc8(%rbp), %rdx
movl $0x3, %edi
leaq 0xcd19b(%rip), %rsi     # 0x13f913
movb $0x0, %al
callq 0x2fc60
cmpq $-0x1, -0xc8(%rbp)
je 0x7279e
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x26150
cmpl $-0x1, %eax
jne 0x727e1
cmpq $-0x1, -0xc8(%rbp)
jne 0x727bd
movl $0x3, %edi
leaq 0xcd189(%rip), %rsi     # 0x13f93d
movb $0x0, %al
callq 0x2fc60
jmp 0x727df
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq %rax, %rdx
movl $0x3, %edi
leaq 0xcd18a(%rip), %rsi     # 0x13f962
movb $0x0, %al
callq 0x2fc60
jmp 0x72850
leaq 0x1059f0(%rip), %rax    # 0x1781d8
cmpl $-0x1, 0x6b0(%rax)
je 0x72836
leaq 0x1059e0(%rip), %rax    # 0x1781d8
movl 0x6b0(%rax), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x26a60
cmpq $-0x1, %rax
jne 0x72836
callq 0x26880
movl (%rax), %edi
callq 0x26690
movq %rax, %rdx
movl $0x3, %edi
leaq 0xcd157(%rip), %rsi     # 0x13f984
movb $0x0, %al
callq 0x2fc60
jmp 0x7284e
movl $0x3, %edi
leaq 0xcd169(%rip), %rsi     # 0x13f9ab
movb $0x0, %al
callq 0x2fc60
jmp 0x7269b
jmp 0x72850
jmp 0x72852
cmpq $0x0, -0x18(%rbp)
je 0x72862
movq -0x18(%rbp), %rdi
callq 0x721f0
movl $0x3, %edi
leaq 0xcd175(%rip), %rsi     # 0x13f9e3
movb $0x0, %al
callq 0x2fc60
movl $0x1, %edi
callq 0x262d0
cmpq $0x0, -0x18(%rbp)
je 0x7288f
movq -0x18(%rbp), %rdi
callq 0x721f0
movl $0x3, %edi
leaq 0xcd240(%rip), %rsi     # 0x13fadb
movb $0x0, %al
callq 0x2fc60
movl $0x1, %edi
callq 0x262d0
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax,%rax)