// File: schuyler[P]quickfix/include/quickfix/particle_filter.h
// Function: ParticleFilter<float, 2>::shuffle()
void ParticleFilter<F,D>::shuffle() {
    int i = 0, total = 0;
    Particles p_ = P;
    while (i < N) {
        // FIXME: this seems heavy handed
        Weights select(N, 1);
        select << Weights::Random(N, 1).array() * 0.5 + 0.5;
        select -= W;
        for (int j = 0; i < N && j < N; j++) {
            //std::cout << i << ": " << j << " " << W[j] << " > " << select[j] << "\n";
            if (select[j] < 0.) {
                P.row(i)= p_.row(j);
                i++;
            }
            total++;
        }
        //j = (j + 1) % N;
    }
    qfdebug("Particle shuffle took " << total << " iterations");
}

// Assembly:
subq $0x198, %rsp            # imm = 0x198
movq %rdi, 0x190(%rsp)
movq 0x190(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movl $0x0, 0x18c(%rsp)
movl $0x0, 0x188(%rsp)
addq $0x8, %rsi
leaq 0x178(%rsp), %rdi
callq 0x2bb0c0
movq 0x10(%rsp), %rcx
movl 0x18c(%rsp), %eax
cmpl 0x30(%rcx), %eax
jge 0x325293
movq 0x10(%rsp), %rsi
addq $0x30, %rsi
movl $0x1, 0x164(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x164(%rsp), %rdx
callq 0x2b22a0
jmp 0x325083
movq 0x10(%rsp), %rax
movslq 0x30(%rax), %rsi
leaq 0x90(%rsp), %rdi
movl $0x1, %edx
callq 0x294e30
jmp 0x3250a0
leaq 0xa0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x2aa5a0
jmp 0x3250b7
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, 0x88(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x2915d0
jmp 0x3250e8
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, 0x80(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0x2b5020
jmp 0x325119
leaq 0x130(%rsp), %rdi
leaq 0x168(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x2b4430
jmp 0x325138
leaq 0x130(%rsp), %rdi
callq 0x2b0550
movq 0x10(%rsp), %rsi
addq $0x18, %rsi
leaq 0x168(%rsp), %rdi
callq 0x29a7b0
jmp 0x32515d
movl $0x0, 0x7c(%rsp)
movq 0x10(%rsp), %rdx
movl 0x18c(%rsp), %ecx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, 0xf(%rsp)
jge 0x32518f
movq 0x10(%rsp), %rcx
movl 0x7c(%rsp), %eax
cmpl 0x30(%rcx), %eax
setl %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x32519c
jmp 0x325281
movslq 0x7c(%rsp), %rsi
leaq 0x168(%rsp), %rdi
callq 0x293680
movq %rax, (%rsp)
jmp 0x3251b4
movq (%rsp), %rax
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x325260
movslq 0x7c(%rsp), %rdx
leaq 0x48(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x2b28e0
jmp 0x3251e6
movq 0x10(%rsp), %rsi
addq $0x8, %rsi
movslq 0x18c(%rsp), %rdx
leaq 0x18(%rsp), %rdi
callq 0x2b28e0
jmp 0x325203
leaq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x294db0
jmp 0x325214
movl 0x18c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18c(%rsp)
jmp 0x325260
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
jmp 0x3252a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x2b19b0
jmp 0x3252a8
movl 0x188(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x188(%rsp)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x325165
leaq 0x168(%rsp), %rdi
callq 0x2b19b0
jmp 0x325043
leaq 0x178(%rsp), %rdi
callq 0x2a7f00
addq $0x198, %rsp            # imm = 0x198
retq
leaq 0x178(%rsp), %rdi
callq 0x2a7f00
movq 0x158(%rsp), %rdi
callq 0x2b6590
nopw %cs:(%rax,%rax)
nopl (%rax)