// File: /workspace/github_cpp_makefile_star2_O2/jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getWallCurvatureRadius(pointxy const*, pointxy&)
double getWallCurvatureRadius(const PXYZ *pt, PXYZ &ndir)
{
    int ils1;
    double rd1=0.0,rd2=0.0, dis1,dis2;
    PXYZ pp1,pp2,pp3, cen1,cen2, ndir1,ndir2;
    int nb;
    ils1=getIndexAtWallPoint(pt,nb);
    if(ils1==NWallPts[nb]-1)
    {
        pp1.x = MultiCircle[nb][0].x;
        pp1.y = MultiCircle[nb][0].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1-1].x;
        pp3.y = MultiCircle[nb][ils1-1].y;

        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir.x=(pt->x-cen1.x)/dis1;
        ndir.y=(pt->y-cen1.y)/dis1;		

        return rd1;
    }
    else if(ils1==NWallPts[nb]-2)
    {
        pp1.x = MultiCircle[nb][0].x;
        pp1.y = MultiCircle[nb][0].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1+1].x;
        pp3.y = MultiCircle[nb][ils1+1].y;

        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir1.x=(pt->x-cen1.x)/dis1;
        ndir1.y=(pt->y-cen1.y)/dis1;	

        pp1.x = MultiCircle[nb][ils1+1].x;
        pp1.y = MultiCircle[nb][ils1+1].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1-1].x;
        pp3.y = MultiCircle[nb][ils1-1].y;

        rd2=getRadius(&pp1,&pp2,&pp3, cen2);

        dis2=sqrt((pt->x-cen2.x)*(pt->x-cen2.x)+(pt->y-cen2.y)*(pt->y-cen2.y));
        ndir2.x=(pt->x-cen2.x)/dis2;
        ndir2.y=(pt->y-cen2.y)/dis2;

        ndir.x=0.5*(ndir1.x+ndir2.x);
        ndir.y=0.5*(ndir1.y+ndir2.y);			

        return (0.5*(rd1+rd2));
    }
    else if(ils1==0)
    {
        pp1.x = MultiCircle[nb][0].x;
        pp1.y = MultiCircle[nb][0].y;
        pp2.x = MultiCircle[nb][1].x;
        pp2.y = MultiCircle[nb][1].y;
        pp3.x = MultiCircle[nb][2].x;
        pp3.y = MultiCircle[nb][2].y;
        //	rd1=getRadius(&pp1,&pp2,&pp3);
        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir.x=(pt->x-cen1.x)/dis1;
        ndir.y=(pt->y-cen1.y)/dis1;	

        return rd1;
    }
    else
    {
        pp1.x = MultiCircle[nb][ils1+2].x;
        pp1.y = MultiCircle[nb][ils1+2].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1+1].x;
        pp3.y = MultiCircle[nb][ils1+1].y;

        rd1=getRadius(&pp1,&pp2,&pp3,cen1);
        dis1=sqrt((pt->x-cen1.x)*(pt->x-cen1.x)+(pt->y-cen1.y)*(pt->y-cen1.y));
        ndir1.x=(pt->x-cen1.x)/dis1;
        ndir1.y=(pt->y-cen1.y)/dis1;

        pp1.x = MultiCircle[nb][ils1+1].x;
        pp1.y = MultiCircle[nb][ils1+1].y;
        pp2.x = MultiCircle[nb][ils1].x;
        pp2.y = MultiCircle[nb][ils1].y;
        pp3.x = MultiCircle[nb][ils1-1].x;
        pp3.y = MultiCircle[nb][ils1-1].y;

        rd2=getRadius(&pp1,&pp2,&pp3, cen2);

        dis2=sqrt((pt->x-cen2.x)*(pt->x-cen2.x)+(pt->y-cen2.y)*(pt->y-cen2.y));
        ndir2.x=(pt->x-cen2.x)/dis2;
        ndir2.y=(pt->y-cen2.y)/dis2;

        ndir.x=0.5*(ndir1.x+ndir2.x);
        ndir.y=0.5*(ndir1.y+ndir2.y);

        return (0.5*(rd1+rd2));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0xa0(%rsp)
leaq 0x9c(%rsp), %r15
movq %r15, %rsi
callq 0x1016a
movslq (%r15), %rcx
leaq 0x12683(%rip), %rdx     # 0x23200
movl (%rdx,%rcx,4), %edx
leal -0x1(%rdx), %esi
cmpl %esi, %eax
jne 0x10c10
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
leaq 0x127e7(%rip), %rdx     # 0x23380
leaq (%rdx,%rcx), %r8
movaps (%rdx,%rcx), %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
cltq
shlq $0x4, %rax
movaps (%rax,%r8), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movapd -0x10(%rax,%r8), %xmm0
leaq 0x30(%rsp), %rdx
movapd %xmm0, (%rdx)
leaq 0x20(%rsp), %r15
movq %r15, %rcx
callq 0x108ab
movupd (%r14), %xmm1
subpd (%r15), %xmm1
movapd %xmm1, %xmm2
mulpd %xmm1, %xmm2
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
sqrtsd %xmm3, %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm1
movupd %xmm1, (%rbx)
jmp 0x10d9c
addl $-0x2, %edx
cmpl %edx, %eax
jne 0x10c46
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
leaq 0x1275b(%rip), %rdx     # 0x23380
movq %rbx, 0x8(%rsp)
leaq (%rdx,%rcx), %rbx
movaps (%rdx,%rcx), %xmm0
leaq 0x10(%rsp), %rcx
movaps %xmm0, (%rcx)
movq %rcx, %rdi
movslq %eax, %r15
shlq $0x4, %r15
jmp 0x10c79
testl %eax, %eax
je 0x10dae
movq %rbx, 0x8(%rsp)
imulq $0x1f40, %rcx, %rbx     # imm = 0x1F40
addq 0x1236f(%rip), %rbx     # 0x22fd0
movslq %eax, %r15
shlq $0x4, %r15
movaps 0x20(%r15,%rbx), %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
movq %rax, %rdi
movaps (%r15,%rbx), %xmm0
leaq 0x40(%rsp), %r12
movaps %xmm0, (%r12)
movaps 0x10(%r15,%rbx), %xmm0
leaq 0x30(%rsp), %r13
movaps %xmm0, (%r13)
leaq 0x20(%rsp), %rbp
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x108ab
movsd %xmm0, (%rsp)
movaps (%rbp), %xmm0
movaps %xmm0, 0x80(%rsp)
movaps 0x10(%r15,%rbx), %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps (%r15,%rbx), %xmm0
movaps %xmm0, (%r12)
movaps -0x10(%r15,%rbx), %xmm0
movaps %xmm0, (%r13)
movsd (%r14), %xmm0
movaps %xmm0, 0x70(%rsp)
movsd 0x8(%r14), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0x8(%rbp), %xmm0
movapd %xmm0, 0x50(%rsp)
leaq 0xa0(%rsp), %rbp
movq %r12, %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x108ab
movapd (%rbp), %xmm1
unpcklpd 0x50(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movsd (%r14), %xmm2
unpcklpd 0x60(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
movapd 0x70(%rsp), %xmm4
movhpd 0x8(%r14), %xmm4        # xmm4 = xmm4[0],mem[0]
movapd 0x80(%rsp), %xmm3
movhpd 0x8(%rbp), %xmm3        # xmm3 = xmm3[0],mem[0]
subpd %xmm1, %xmm2
subpd %xmm3, %xmm4
movapd %xmm4, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
mulpd %xmm1, %xmm1
movapd %xmm2, %xmm3
unpcklpd %xmm4, %xmm3            # xmm3 = xmm3[0],xmm4[0]
mulpd %xmm3, %xmm3
addpd %xmm1, %xmm3
sqrtpd %xmm3, %xmm1
divpd %xmm1, %xmm2
shufpd $0x1, %xmm1, %xmm1      # xmm1 = xmm1[1,0]
divpd %xmm1, %xmm4
addpd %xmm2, %xmm4
mulpd 0xa88a(%rip), %xmm4     # 0x1b610
movq 0x8(%rsp), %rax
movupd %xmm4, (%rax)
addsd (%rsp), %xmm0
mulsd 0xa3dc(%rip), %xmm0     # 0x1b178
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
imulq $0x1f40, %rcx, %rax     # imm = 0x1F40
leaq 0x125c4(%rip), %rcx     # 0x23380
movaps (%rcx,%rax), %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps 0x10(%rcx,%rax), %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movapd 0x20(%rcx,%rax), %xmm0
jmp 0x10bc3