// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/discnt-cli.c
// Function: cliFormatReplyTTY
static sds cliFormatReplyTTY(redisReply *r, char *prefix) {
    sds out = sdsempty();
    switch (r->type) {
    case REDIS_REPLY_ERROR:
        out = sdscatprintf(out,"(error) %s\n", r->str);
    break;
    case REDIS_REPLY_STATUS:
        out = sdscat(out,r->str);
        out = sdscat(out,"\n");
    break;
    case REDIS_REPLY_INTEGER:
        out = sdscatprintf(out,"(integer) %lld\n",r->integer);
    break;
    case REDIS_REPLY_STRING:
        /* If you are producing output for the standard output we want
        * a more interesting output with quoted characters and so forth */
        out = sdscatrepr(out,r->str,r->len);
        out = sdscat(out,"\n");
    break;
    case REDIS_REPLY_NIL:
        out = sdscat(out,"(nil)\n");
    break;
    case REDIS_REPLY_ARRAY:
        if (r->elements == 0) {
            out = sdscat(out,"(empty list or set)\n");
        } else {
            unsigned int i, idxlen = 0;
            char _prefixlen[16];
            char _prefixfmt[16];
            sds _prefix;
            sds tmp;

            /* Calculate chars needed to represent the largest index */
            i = r->elements;
            do {
                idxlen++;
                i /= 10;
            } while(i);

            /* Prefix for nested multi bulks should grow with idxlen+2 spaces */
            memset(_prefixlen,' ',idxlen+2);
            _prefixlen[idxlen+2] = '\0';
            _prefix = sdscat(sdsnew(prefix),_prefixlen);

            /* Setup prefix format for every entry */
            snprintf(_prefixfmt,sizeof(_prefixfmt),"%%s%%%ud) ",idxlen);

            for (i = 0; i < r->elements; i++) {
                /* Don't use the prefix for the first element, as the parent
                 * caller already prepended the index number. */
                out = sdscatprintf(out,_prefixfmt,i == 0 ? "" : prefix,i+1);

                /* Format the multi bulk entry */
                tmp = cliFormatReplyTTY(r->element[i],_prefix);
                out = sdscatlen(out,tmp,sdslen(tmp));
                sdsfree(tmp);
            }
            sdsfree(_prefix);
        }
    break;
    default:
        fprintf(stderr,"Unknown reply type: %d\n", r->type);
        exit(1);
    }
    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x1195b
movq %rax, %r15
movl (%rbx), %edi
leal -0x1(%rdi), %eax
cmpl $0x5, %eax
ja 0x16481
leaq 0x23539(%rip), %rcx     # 0x397e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x18(%rbx), %rsi
movslq 0x10(%rbx), %rdx
movq %r15, %rdi
callq 0x132e4
jmp 0x162d6
movq 0x18(%rbx), %rsi
movq %r15, %rdi
callq 0x12259
leaq 0x248bb(%rip), %rsi     # 0x3ab98
movq %rax, %rdi
jmp 0x1646e
movq 0x8(%rbx), %rdx
leaq 0x24e18(%rip), %rsi     # 0x3b108
jmp 0x1644c
leaq 0x24e1c(%rip), %rsi     # 0x3b118
jmp 0x1646b
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x16464
movl $0x2, %ebp
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
movl %eax, %edx
imulq %rcx, %rdx
shrq $0x23, %rdx
incl %ebp
cmpl $0x9, %eax
movl %edx, %eax
ja 0x16318
movl %ebp, %r12d
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movl $0x20, %esi
movq %r12, %rdx
callq 0xc250
movb $0x0, 0x10(%rsp,%r12)
movq %r14, %rdi
callq 0x1197e
movq %rax, %rdi
movq %r13, %rsi
callq 0x12259
movq %rax, %r12
addl $-0x2, %ebp
leaq 0x24dcb(%rip), %rdx     # 0x3b134
movq %rsp, %rdi
movl $0x10, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc1f0
cmpq $0x0, 0x20(%rbx)
je 0x16427
movl $0x1, %ebp
xorl %r13d, %r13d
cmpl $0x1, %ebp
movq %r14, %rdx
leaq 0x247ff(%rip), %rax     # 0x3ab99
cmoveq %rax, %rdx
movq %r15, %rdi
movq %rsp, %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x125ea
movq %rax, %r15
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rdi
movq %r12, %rsi
callq 0x1627e
movq %rax, %r13
movzbl -0x1(%rax), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x16400
leaq 0x23428(%rip), %rcx     # 0x39800
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x16402
movq -0x11(%r13), %rdx
jmp 0x16402
movzwl -0x5(%r13), %edx
jmp 0x16402
movl -0x9(%r13), %edx
jmp 0x16402
movzbl -0x3(%r13), %edx
jmp 0x16402
xorl %edx, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x12189
movq %rax, %r15
movq %r13, %rdi
callq 0x119ef
movl %ebp, %r13d
incl %ebp
cmpq %r13, 0x20(%rbx)
ja 0x1638d
movq %r12, %rdi
callq 0x119ef
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdx
leaq 0x24cb0(%rip), %rsi     # 0x3b0fc
movq %r15, %rdi
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x125ea
leaq 0x24cb4(%rip), %rsi     # 0x3b11f
movq %r15, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12259
callq 0xc8fb