// File: jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getIndexAtWallPoint(pointxy const*, int, pointxy*)
int getIndexAtWallPoint(const PXYZ *gst, int NumberPoint,PXYZ wallpnt[]   )
{
    int ils, ia,ib,i;
    double dis,dis2;
    PXYZ pa,pi1,pi2,pb1,pb2;

    ia=0;
    //	ib=NumberAirfoilPoint;

    dis=(gst->x-wallpnt[0].x)*(gst->x-wallpnt[0].x)
        +(gst->y-wallpnt[0].y)*(gst->y-wallpnt[0].y);

    for(i=1;i<=NumberPoint-1;++i)
    {
        dis2 = (gst->x-wallpnt[i].x)*(gst->x-wallpnt[i].x)
            +(gst->y-wallpnt[i].y)*(gst->y-wallpnt[i].y);
        if(dis2<dis){
            dis=dis2;
            ia=i;
        }
    }
    if(ia==0)
    {
        pa.x = wallpnt[ia].x;
        pa.y = wallpnt[ia].y;
        pb1.x = wallpnt[ia+1].x; 
        pb1.y = wallpnt[ia+1].y;		

        pb2.x = wallpnt[NumberPoint-1].x;
        pb2.y = wallpnt[NumberPoint-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=NumberPoint-1;
        else ia=ia;	
    }
    else
    {
        pa.x = wallpnt[ia].x;
        pa.y = wallpnt[ia].y;
        pb1.x = wallpnt[ia+1].x; 
        pb1.y = wallpnt[ia+1].y;		

        pb2.x = wallpnt[ia-1].x;
        pb2.y = wallpnt[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)
movl %esi, 0x7c(%rsp)
movq %rdx, 0x70(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x6310
leaq 0x30(%rsp), %rdi
callq 0x6310
leaq 0x20(%rsp), %rdi
callq 0x6310
leaq 0x10(%rsp), %rdi
callq 0x6310
movq %rsp, %rdi
callq 0x6310
movl $0x0, 0x68(%rsp)
movq 0x80(%rsp), %rax
movsd (%rax), %xmm0
movq 0x70(%rsp), %rax
subsd (%rax), %xmm0
movq 0x80(%rsp), %rax
movsd (%rax), %xmm2
movq 0x70(%rsp), %rax
subsd (%rax), %xmm2
movq 0x80(%rsp), %rax
movsd 0x8(%rax), %xmm1
movq 0x70(%rsp), %rax
subsd 0x8(%rax), %xmm1
movq 0x80(%rsp), %rax
movsd 0x8(%rax), %xmm3
movq 0x70(%rsp), %rax
subsd 0x8(%rax), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movl $0x1, 0x60(%rsp)
movl 0x60(%rsp), %eax
movl 0x7c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x28277
movq 0x80(%rsp), %rax
movsd (%rax), %xmm0
movq 0x70(%rsp), %rax
movslq 0x60(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd (%rax), %xmm0
movq 0x80(%rsp), %rax
movsd (%rax), %xmm2
movq 0x70(%rsp), %rax
movslq 0x60(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd (%rax), %xmm2
movq 0x80(%rsp), %rax
movsd 0x8(%rax), %xmm1
movq 0x70(%rsp), %rax
movslq 0x60(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm1
movq 0x80(%rsp), %rax
movsd 0x8(%rax), %xmm3
movq 0x70(%rsp), %rax
movslq 0x60(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
subsd 0x8(%rax), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28265
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x68(%rsp)
jmp 0x28267
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x28192
cmpl $0x0, 0x68(%rsp)
jne 0x2841f
movq 0x70(%rsp), %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x70(%rsp), %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x70(%rsp), %rax
movl 0x68(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x70(%rsp), %rax
movl 0x68(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x70(%rsp), %rax
movl 0x7c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x70(%rsp), %rax
movl 0x7c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x278b0
movq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movq %rsp, %rdx
leaq 0x20(%rsp), %rcx
callq 0x278b0
movsd 0x40(%rsp), %xmm1
subsd 0x30(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
subsd 0x30(%rsp), %xmm2
movsd 0x48(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
movsd 0x18(%rsp), %xmm3
subsd 0x38(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x283bf
movl 0x68(%rsp), %eax
movl %eax, 0x68(%rsp)
jmp 0x2841a
movsd 0x40(%rsp), %xmm1
subsd 0x20(%rsp), %xmm1
movsd (%rsp), %xmm2
subsd 0x20(%rsp), %xmm2
movsd 0x48(%rsp), %xmm0
subsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm3
subsd 0x28(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x28410
movl 0x7c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x28418
movl 0x68(%rsp), %eax
movl %eax, 0x68(%rsp)
jmp 0x2841a
jmp 0x285b9
movq 0x70(%rsp), %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x70(%rsp), %rax
movslq 0x68(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x70(%rsp), %rax
movl 0x68(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x70(%rsp), %rax
movl 0x68(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x70(%rsp), %rax
movl 0x68(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0x70(%rsp), %rax
movl 0x68(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x278b0
movq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movq %rsp, %rdx
leaq 0x20(%rsp), %rcx
callq 0x278b0
movsd 0x40(%rsp), %xmm1
subsd 0x30(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
subsd 0x30(%rsp), %xmm2
movsd 0x48(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
movsd 0x18(%rsp), %xmm3
subsd 0x38(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x2855c
movl 0x68(%rsp), %eax
movl %eax, 0x68(%rsp)
jmp 0x285b7
movsd 0x40(%rsp), %xmm1
subsd 0x20(%rsp), %xmm1
movsd (%rsp), %xmm2
subsd 0x20(%rsp), %xmm2
movsd 0x48(%rsp), %xmm0
subsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm3
subsd 0x28(%rsp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jb 0x285ad
movl 0x68(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x285b5
movl 0x68(%rsp), %eax
movl %eax, 0x68(%rsp)
jmp 0x285b7
jmp 0x285b9
movl 0x68(%rsp), %eax
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)