// File: jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getIndexAtWallPoint(pointxy const*, int&)
int getIndexAtWallPoint(const PXYZ *gst, int &nb)
{
    int ils, ia,ib,i;
    double dis,dis2;
    PXYZ pa,pi1,pi2,pb1,pb2;
    int wy;

    //	ib=NumberAirfoilPoint;
    dis=1.0e10;
    //  ia=0;
    for(wy=0; wy<N_BODY;++wy){
        for(i=0;i<=NWallPts[wy]-1;++i)
        {
            dis2 = (gst->x-MultiCircle[wy][i].x)*(gst->x-MultiCircle[wy][i].x)
                +(gst->y-MultiCircle[wy][i].y)*(gst->y-MultiCircle[wy][i].y);
            if(dis2<dis){
                dis=dis2;
                ia=i;
                nb=wy;
            }
        }
    }

    if(ia==0)
    {
        pa.x = MultiCircle[nb][ia].x;
        pa.y = MultiCircle[nb][ia].y;
        pb1.x = MultiCircle[nb][ia+1].x; 
        pb1.y = MultiCircle[nb][ia+1].y;		

        pb2.x = MultiCircle[nb][NWallPts[nb]-1].x;
        pb2.y = MultiCircle[nb][NWallPts[nb]-1].y;
        getInterAB(gst, &pa, &pb1, &pi1);
        getInterAB(gst, &pa, &pb2, &pi2);

        //	if((pi1.x-pa.x)*(pb1.x-pa.x) + (pi1.y-pa.y)*(pb1.y-pa.y) >= 0.0) ia=ia; //2011-12-23�޸�,��������
        //	else if((pi2.x-pa.x)*(pb2.x-pa.x) + (pi2.y-pa.y)*(pb2.y-pa.y) >= 0.0) ia=NumberAirfoilPoint-1;
        if((pa.x-pi1.x)*(pb1.x-pi1.x) + (pa.y-pi1.y)*(pb1.y-pi1.y) <= 0.0) ia=ia; //2011-12-23�޸�,��������
        else if((pa.x-pi2.x)*(pb2.x-pi2.x) + (pa.y-pi2.y)*(pb2.y-pi2.y) <= 0.0) ia=NWallPts[nb]-1;
        else ia=ia;	
    }
    else
    {
        pa.x = MultiCircle[nb][ia].x;
        pa.y = MultiCircle[nb][ia].y;
        pb1.x = MultiCircle[nb][ia+1].x; 
        pb1.y = MultiCircle[nb][ia+1].y;		

        pb2.x = MultiCircle[nb][ia-1].x;
        pb2.y = MultiCircle[nb][ia-1].y;
        getInterAB(gst, &pa, &pb1, &pi1);
        getInterAB(gst, &pa, &pb2, &pi2);

        //	if((pi1.x-pa.x)*(pb1.x-pa.x) + (pi1.y-pa.y)*(pb1.y-pa.y) >= 0.0) ia=ia;
        //	else if((pi2.x-pa.x)*(pb2.x-pa.x) + (pi2.y-pa.y)*(pb2.y-pa.y) >= 0.0) ia=ia-1;

        if((pa.x-pi1.x)*(pb1.x-pi1.x) + (pa.y-pi1.y)*(pb1.y-pi1.y) <= 0.0) ia=ia; //2011-12-23�޸�,��������
        else if((pa.x-pi2.x)*(pb2.x-pi2.x) + (pa.y-pi2.y)*(pb2.y-pi2.y) <= 0.0) ia=ia-1;
        else ia=ia;		
    }
    return ia;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x6310
leaq 0x38(%rsp), %rdi
callq 0x6310
leaq 0x28(%rsp), %rdi
callq 0x6310
leaq 0x18(%rsp), %rdi
callq 0x6310
leaq 0x8(%rsp), %rdi
callq 0x6310
movsd 0x17d02(%rip), %xmm0    # 0x3f7f0
movsd %xmm0, 0x60(%rsp)
movl $0x0, 0x4(%rsp)
cmpl $0x1, 0x4(%rsp)
jge 0x27c60
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
movslq 0x4(%rsp), %rdx
leaq 0x23771(%rip), %rcx     # 0x4b290
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x27c4e
movq 0x80(%rsp), %rax
movsd (%rax), %xmm0
movslq 0x4(%rsp), %rcx
leaq 0x238cb(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd (%rax), %xmm0
movq 0x80(%rsp), %rax
movsd (%rax), %xmm2
movslq 0x4(%rsp), %rcx
leaq 0x23899(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd (%rax), %xmm2
movq 0x80(%rsp), %rax
movsd 0x8(%rax), %xmm1
movslq 0x4(%rsp), %rcx
leaq 0x23866(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm1
movq 0x80(%rsp), %rax
movsd 0x8(%rax), %xmm3
movslq 0x4(%rsp), %rcx
leaq 0x23832(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x58(%rsp), %xmm1
movsd 0x60(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x27c3c
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x70(%rsp)
movl 0x4(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, (%rax)
jmp 0x27c3e
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x27b0f
jmp 0x27c50
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x27afc
cmpl $0x0, 0x70(%rsp)
jne 0x27eae
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x23796(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x70(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x23767(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x70(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x23737(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0x70(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x23703(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0x70(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x236ce(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movq 0x78(%rsp), %rcx
movslq (%rcx), %rdx
leaq 0x23535(%rip), %rcx     # 0x4b290
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x2368c(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movq 0x78(%rsp), %rcx
movslq (%rcx), %rdx
leaq 0x234f3(%rip), %rcx     # 0x4b290
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x80(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x278b0
movq 0x80(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x278b0
movsd 0x48(%rsp), %xmm1
subsd 0x38(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
subsd 0x38(%rsp), %xmm2
movsd 0x50(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movsd 0x20(%rsp), %xmm3
subsd 0x40(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x27e3f
movl 0x70(%rsp), %eax
movl %eax, 0x70(%rsp)
jmp 0x27ea9
movsd 0x48(%rsp), %xmm1
subsd 0x28(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
subsd 0x28(%rsp), %xmm2
movsd 0x50(%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
movsd 0x10(%rsp), %xmm3
subsd 0x30(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x27e9f
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x233fd(%rip), %rax     # 0x4b290
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x27ea7
movl 0x70(%rsp), %eax
movl %eax, 0x70(%rsp)
jmp 0x27ea9
jmp 0x280c4
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x23553(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x70(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x23524(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movslq 0x70(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x234f4(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0x70(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x234c0(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0x70(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x2348b(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0x70(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x78(%rsp), %rax
movslq (%rax), %rcx
leaq 0x23457(%rip), %rax     # 0x4b410
imulq $0x1f40, %rcx, %rcx     # imm = 0x1F40
addq %rcx, %rax
movl 0x70(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x80(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x38(%rsp), %rcx
callq 0x278b0
movq 0x80(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x278b0
movsd 0x48(%rsp), %xmm1
subsd 0x38(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
subsd 0x38(%rsp), %xmm2
movsd 0x50(%rsp), %xmm0
subsd 0x40(%rsp), %xmm0
movsd 0x20(%rsp), %xmm3
subsd 0x40(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x28066
movl 0x70(%rsp), %eax
movl %eax, 0x70(%rsp)
jmp 0x280c2
movsd 0x48(%rsp), %xmm1
subsd 0x28(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
subsd 0x28(%rsp), %xmm2
movsd 0x50(%rsp), %xmm0
subsd 0x30(%rsp), %xmm0
movsd 0x10(%rsp), %xmm3
subsd 0x30(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x280b8
movl 0x70(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x280c0
movl 0x70(%rsp), %eax
movl %eax, 0x70(%rsp)
jmp 0x280c2
jmp 0x280c4
movl 0x70(%rsp), %eax
addq $0x88, %rsp
retq