// File: /workspace/github_c_makefile_star2_O2/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, 0x4(%rsp)
leaq 0x5913(%rip), %rsi      # 0xe632
xorl %ebx, %ebx
leaq 0x10(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x711d
pushq $-0x8
popq %rbp
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x6eb5
movl %ebx, %r14d
testl %eax, %eax
je 0x8db5
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rsi
xorl %edi, %edi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x12c, %r8d            # imm = 0x12C
callq 0x7676
testq %rax, %rax
je 0x8d36
movq %rax, %r12
movss 0x3765(%rip), %xmm0     # 0xc4d4
ucomiss 0x40(%rax), %xmm0
jbe 0x8d7f
movq %r12, %rdi
callq 0x75e4
jmp 0x8d36
incq %rbx
movl %ebx, %esi
shlq $0x4, %rsi
movq %r13, %rdi
callq 0x6591
movq %rax, %r13
shlq $0x4, %r14
movq 0x58(%r12), %rdi
xorl %esi, %esi
callq 0x21c0
movsd %xmm0, (%r13,%r14)
movq %r12, 0x8(%r13,%r14)
addq $0x10, %rbp
jmp 0x8d36
leaq 0x2890(%rip), %rcx      # 0xb64c
pushq $0x10
popq %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x2460
leaq 0x589e(%rip), %rdi      # 0xe66f
callq 0x4ef7
movq %rax, %r15
movq %r13, %rdx
movl %ebx, %r13d
shrl %r13d
movl 0x4(%rsp), %eax
cmpl %eax, %r13d
cmovll %r13d, %eax
movl %ebx, %ecx
subl %eax, %ecx
movslq %ecx, %r12
movq %rdx, 0x8(%rsp)
addq %rdx, %rbp
cmpq %r12, %r14
jle 0x8e20
decq %r14
movq (%rbp), %rdx
movq 0x8(%rdx), %rsi
movq %r15, %rdi
pushq $0x2
popq %rcx
callq 0x88de
movq %rax, %r15
addq $-0x10, %rbp
jmp 0x8dfc
movl 0x4(%rsp), %eax
cmpl %r13d, %eax
cmovll %eax, %r13d
movq %r13, %rax
shlq $0x4, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r14
addq $-0x8, %r14
pushq $0x2
popq %rbp
testl %r13d, %r13d
jle 0x8e64
movq (%r14), %rdx
movq 0x8(%rdx), %rsi
movq %r15, %rdi
movl %ebp, %ecx
callq 0x88de
movq %rax, %r15
decl %r13d
addq $-0x10, %r14
jmp 0x8e42
movq 0x8(%rsp), %r12
leaq 0x8(%r12), %r14
subq $0x1, %rbx
jb 0x8e82
movq (%r14), %rdi
callq 0x75e4
addq $0x10, %r14
jmp 0x8e6e
movq %r12, %rdi
callq 0x2478
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq