// File: /workspace/github_c_makefile_star2_O3/antirez[P]stonky/stonky.c
// Function: genBigMoversMessage
sds genBigMoversMessage(int count) {
    sqlRow row;
    sqlSelect(&row,
        "SELECT DISTINCT UPPER(symbol) FROM ListStock ORDER BY symbol");

    int numstocks = 0;
    bmStock *stocks = NULL;
    while(sqlNextRow(&row)) {
        const char *sym = row.col[0].s;
        ydata *yd = getYahooData(YDATA_QUOTE,sym,NULL,NULL,60*5);
        if (yd) {
            /* Limit the list to important companies (total capitalization
             * greater or equal to 10B. */
            if (yd->cap < 10000000000) {
                freeYahooData(yd);
                continue;
            }
            stocks = xrealloc(stocks,(numstocks+1)*sizeof(bmStock));
            bmStock *s = stocks+numstocks;
            s->change = strtod(yd->regchange,NULL);
            s->yd = yd;
            numstocks++;
        }
    }

    /* Sort the stocks by change. */
    qsort(stocks,numstocks,sizeof(bmStock),bmStockCompare);

    /* Create the message to send. */
    sds reply = sdsnew("Big movers: ");
    int top = numstocks/2;
    if (top > count) top = count;

    for (int j = numstocks-1; j >= numstocks-top; j--) {
        reply = sdsCatPriceRequest(reply,stocks[j].yd->symbol,
                                   stocks[j].yd,STONKY_VERY_SHORT);
    }
    for (int j = top-1; j >= 0; j--) {
        reply = sdsCatPriceRequest(reply,stocks[j].yd->symbol,
                                   stocks[j].yd,STONKY_VERY_SHORT);
    }
    /* Cleanup. */
    for (int j = 0; j < numstocks; j++) freeYahooData(stocks[j].yd);
    xfree(stocks);
    return reply;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %ebp
leaq 0x6968(%rip), %rsi      # 0x109ca
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8357
movq %rbx, %rdi
callq 0x80e3
testl %eax, %eax
je 0xa106
xorl %r13d, %r13d
leaq 0x10(%rsp), %r14
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rsi
xorl %edi, %edi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x12c, %r8d            # imm = 0x12C
callq 0x88ec
testq %rax, %rax
je 0xa0f8
movq %rax, %r15
movss 0x47ac(%rip), %xmm0     # 0xe864
ucomiss 0x40(%rax), %xmm0
jbe 0xa0c8
movq %r15, %rdi
callq 0x885a
jmp 0xa0f8
movslq %r13d, %r12
incl %r13d
shlq $0x4, %r12
leaq 0x10(%r12), %rsi
movq %rbx, %rdi
callq 0x774b
movq %rax, %rbx
movq 0x58(%r15), %rdi
xorl %esi, %esi
callq 0x21c0
movsd %xmm0, (%rbx,%r12)
movq %r15, 0x8(%rbx,%r12)
movq %r14, %rdi
callq 0x80e3
testl %eax, %eax
jne 0xa08e
jmp 0xa108
xorl %ebx, %ebx
movslq %r13d, %r12
leaq 0x2d68(%rip), %rcx      # 0xce7a
movl $0x10, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2460
leaq 0x68de(%rip), %rdi      # 0x10a07
callq 0x56e9
movq %rax, %r15
movq %r13, %rax
movl %r12d, %r13d
shrl $0x1f, %r13d
addl %r12d, %r13d
sarl %r13d
cmpl %ebp, %r13d
cmovgel %ebp, %r13d
testl %r13d, %r13d
movq %rax, 0x8(%rsp)
jle 0xa1dd
subl %r13d, %eax
movslq %eax, %rbp
movq %r12, %rax
shlq $0x4, %rax
movq %r12, %r14
leaq (%rax,%rbx), %r12
addq $-0x8, %r12
movq %r14, (%rsp)
decq %r14
movq (%r12), %rdx
movq 0x8(%rdx), %rsi
movq %r15, %rdi
movl $0x2, %ecx
callq 0x9be2
movq %rax, %r15
addq $-0x10, %r12
cmpq %rbp, %r14
jg 0xa172
testl %r13d, %r13d
jle 0xa1d9
movl %r13d, %eax
leaq 0x1(%rax), %r13
shlq $0x4, %rax
leaq (%rax,%rbx), %rbp
addq $-0x8, %rbp
movq (%rsp), %r12
movq (%rbp), %rdx
movq 0x8(%rdx), %rsi
movq %r15, %rdi
movl $0x2, %ecx
callq 0x9be2
movq %rax, %r15
decq %r13
addq $-0x10, %rbp
cmpq $0x1, %r13
ja 0xa1b2
jmp 0xa1dd
movq (%rsp), %r12
cmpl $0x0, 0x8(%rsp)
jle 0xa1fe
shlq $0x4, %r12
xorl %r14d, %r14d
movq 0x8(%rbx,%r14), %rdi
callq 0x885a
addq $0x10, %r14
cmpq %r14, %r12
jne 0xa1eb
movq %rbx, %rdi
callq 0x2478
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq