// File: Cell-veto[P]postlhc/jellium4.cpp
// Function: Jellium4<2u, Monodisperse2D>::lr_event_rate(std::array<double, 2ul> const&, unsigned int, bool)
double lr_event_rate (const vector_t &r, unsigned direction, bool clip = true)
    {
        // FIXME 3D missing
        if (DIM != 2)
            std::cerr << "not impl" << ABORT;

        double pr = 0.;

        for (int i = -LATTICE_ORDER; i <= LATTICE_ORDER; ++i)
        {
            double x = r[direction] + i*periods[direction];
            for (int j = -LATTICE_ORDER; j <= LATTICE_ORDER; ++j)
            {
                double y = r[!direction] + j*periods[!direction];
                double rsq = x*x + y*y;
                if (rsq >= sr_lr_split*sr_lr_split)
                    pr += unit_directional_derivative (x, rsq);
            }
        }

        // screening charges
        double spr = 0;
        double xf = r[direction] + (LATTICE_ORDER+.5) * periods[direction];
        double xb = r[direction] - (LATTICE_ORDER+.5) * periods[direction];
        for (int j = -LATTICE_ORDER; j <= LATTICE_ORDER; ++j)
        {
            double y = r[!direction] + j*periods[!direction];
            spr += unit_potential (xf*xf + y*y);
            spr -= unit_potential (xb*xb + y*y);
        }

        pr += spr / periods[direction];

        if (clip && pr < 0.)
            return 0.;
        else
            return stren * pr;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0xfffffffc, -0x2c(%rbp) # imm = 0xFFFFFFFC
cmpl $0x4, -0x2c(%rbp)
jg 0x433c33
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x418dc0
movq -0x80(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
addq $0x20, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x419310
movsd -0x90(%rbp), %xmm0
movsd -0x88(%rbp), %xmm1
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0xfffffffc, -0x3c(%rbp) # imm = 0xFFFFFFFC
cmpl $0x4, -0x3c(%rbp)
jg 0x433c23
movq -0x18(%rbp), %rdi
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
callq 0x418dc0
movq -0x80(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
cvtsi2sdl -0x3c(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
addq $0x20, %rdi
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
callq 0x419310
movsd -0xa0(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
movq %rax, %rcx
movq -0x80(%rbp), %rax
movsd (%rcx), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
movsd -0x38(%rbp), %xmm2
movsd -0x48(%rbp), %xmm1
mulsd -0x48(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movsd 0x18(%rax), %xmm1
mulsd 0x18(%rax), %xmm1
ucomisd %xmm1, %xmm0
jb 0x433c13
movq -0x80(%rbp), %rdi
movsd -0x38(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
callq 0x41c270
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x433c15
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x433b3f
jmp 0x433c25
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x433ad4
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x418dc0
movq -0x80(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
addq $0x20, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x419310
movsd -0xb0(%rbp), %xmm1
movsd (%rax), %xmm0
movsd 0x1cb47d(%rip), %xmm2   # 0x5ff0f8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x418dc0
movq -0x80(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
addq $0x20, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x419310
movsd -0xa8(%rbp), %xmm1
movsd (%rax), %xmm0
movsd 0x1cb428(%rip), %xmm2   # 0x5ff0f0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movl $0xfffffffc, -0x6c(%rbp) # imm = 0xFFFFFFFC
cmpl $0x4, -0x6c(%rbp)
jg 0x433dc9
movq -0x18(%rbp), %rdi
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
callq 0x418dc0
movq -0x80(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
cvtsi2sdl -0x6c(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
addq $0x20, %rdi
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, %esi
callq 0x419310
movsd -0xc0(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm1
movq -0x80(%rbp), %rdi
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
movsd -0x78(%rbp), %xmm1
mulsd -0x78(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x41c2d0
movq -0x80(%rbp), %rdi
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x68(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
movsd -0x78(%rbp), %xmm1
mulsd -0x78(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x41c2d0
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x433cdc
movq -0x80(%rbp), %rdi
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
addq $0x20, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x419310
movsd -0xc8(%rbp), %xmm0
divsd (%rax), %xmm0
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
testb $0x1, -0x1d(%rbp)
je 0x433e18
xorps %xmm0, %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x433e18
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x433e2b
movq -0x80(%rbp), %rax
movsd 0x8(%rax), %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)