// File: /workspace/github_c_makefile_star2_O1/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 0x66e2(%rip), %rsi      # 0x109ea
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x85df
movq %rbx, %rdi
callq 0x836f
testl %eax, %eax
je 0xa3ac
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 0x8b50
testq %rax, %rax
je 0xa39e
movq %rax, %r15
movss 0x4526(%rip), %xmm0     # 0xe884
ucomiss 0x40(%rax), %xmm0
jbe 0xa36e
movq %r15, %rdi
callq 0x8abe
jmp 0xa39e
movslq %r13d, %r12
incl %r13d
shlq $0x4, %r12
leaq 0x10(%r12), %rsi
movq %rbx, %rdi
callq 0x799b
movq %rax, %rbx
movq 0x58(%r15), %rdi
xorl %esi, %esi
callq 0x21b0
movsd %xmm0, (%rbx,%r12)
movq %r15, 0x8(%rbx,%r12)
movq %r14, %rdi
callq 0x836f
testl %eax, %eax
jne 0xa334
jmp 0xa3ae
xorl %ebx, %ebx
movslq %r13d, %r15
leaq 0x2e12(%rip), %rcx      # 0xd1ca
movl $0x10, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2450
leaq 0x6658(%rip), %rdi      # 0x10a27
callq 0x58ac
movq %rax, %r14
movq %r13, %rax
movl %r15d, %r13d
shrl $0x1f, %r13d
movq %rax, 0x8(%rsp)
addl %eax, %r13d
sarl %r13d
cmpl %ebp, %r13d
cmovgel %ebp, %r13d
testl %r13d, %r13d
jle 0xa434
movl %r15d, %eax
subl %r13d, %eax
movslq %eax, %rbp
movq %r15, %rax
shlq $0x4, %rax
leaq (%rax,%rbx), %r12
addq $-0x8, %r12
decq %r15
movq (%r12), %rdx
movq 0x8(%rdx), %rsi
movq %r14, %rdi
movl $0x2, %ecx
callq 0x9e70
movq %rax, %r14
addq $-0x10, %r12
cmpq %rbp, %r15
jg 0xa410
testl %r13d, %r13d
jle 0xa471
movl %r13d, %eax
leaq 0x1(%rax), %r15
shlq $0x4, %rax
leaq (%rax,%rbx), %r12
addq $-0x8, %r12
movq (%r12), %rdx
movq 0x8(%rdx), %rsi
movq %r14, %rdi
movl $0x2, %ecx
callq 0x9e70
movq %rax, %r14
decq %r15
addq $-0x10, %r12
cmpq $0x1, %r15
jg 0xa44c
movq 0x8(%rsp), %rax
testl %eax, %eax
jle 0xa497
movl %eax, %r15d
shlq $0x4, %r15
xorl %r12d, %r12d
movq 0x8(%rbx,%r12), %rdi
callq 0x8abe
addq $0x10, %r12
cmpq %r12, %r15
jne 0xa484
movq %rbx, %rdi
callq 0x2468
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq