// File: /workspace/github_cpp_makefile_star2_O2/jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getsmtrctAB(double, pointxy const*, pointxy const*, pointxy const*, pointxy*, pointxy*, pointxy*, double*)
void getsmtrctAB(double hd, const PXYZ *gst, const PXYZ *pA, const PXYZ *pB,
    PXYZ *smtrctP, PXYZ *jiaodian, PXYZ *normal, double *dis)
{
    double ls1;
    double ls2;
    double b1, b2, xjd, yjd, jl;

    if(fabs(pB->y-pA->y) < 1e-10)
    {
//        smtrctP->x = gst->x;
  //      smtrctP->y = 2.0 * pA->y - gst->y;

        normal->x = 0.0;
        normal->y = (smtrctP->y - gst->y)/fabs(smtrctP->y - gst->y);
        xjd=jiaodian->x = gst->x;
        yjd=jiaodian->y = pA->y;
        *dis = sqrt((gst->x-xjd) * (gst->x-xjd) + (gst->y-yjd) * (gst->y-yjd));
        smtrctP->x=xjd+hd*normal->x;
        smtrctP->y=yjd+hd*normal->y;
    }
    else if(fabs(pA->x - pB->x) < 1e-10)
    {
       // smtrctP->x = 2 * pA->x - gst->x;
        //smtrctP->y = gst->y;

        jiaodian->x = pA->x;
        xjd=jiaodian->x;

        jiaodian->y = gst->y;
        yjd=jiaodian->y;

        *dis=jl = sqrt((gst->x - xjd) * (gst->x - xjd) + (gst->y - yjd) * (gst->y - yjd));

        normal->x = (xjd - gst->x)/jl;
        normal->y = (yjd - gst->y)/jl;
        smtrctP->x=xjd+hd*normal->x;
        smtrctP->y=yjd+hd*normal->y;
    }
    else
    {
        ls1 = (pA->y-pB->y)/(pA->x-pB->x);
        ls2 = - 1.0/ls1;
        b1 = pA->y - ls1 * pA->x;
        b2 = gst->y - ls2 * gst->x;

        xjd = (b2 - b1)/(ls1-ls2);
        yjd = ls1 * xjd + b1;

        jiaodian->x = xjd;
        jiaodian->y = yjd;

//        smtrctP->x = 2 * xjd - gst->x;
  //      smtrctP->y = 2 * yjd - gst->y;	

        *dis=jl = sqrt((gst->x-xjd) * (gst->x-xjd) + (gst->y-yjd) * (gst->y-yjd));

        normal->x = (xjd - gst->x)/jl;
        normal->y = (yjd - gst->y)/jl;
        smtrctP->x=xjd+hd*normal->x;
        smtrctP->y=yjd+hd*normal->y;
    }
}

// Assembly:
movsd 0x8(%rdx), %xmm2
movsd 0x8(%rsi), %xmm4
movapd %xmm2, %xmm1
subsd %xmm4, %xmm1
andpd 0xb928(%rip), %xmm1     # 0x1b240
movq 0x8(%rsp), %rax
movsd 0xbb3b(%rip), %xmm3     # 0x1b460
ucomisd %xmm1, %xmm3
jbe 0xf9a2
andq $0x0, (%r9)
movsd 0x8(%rcx), %xmm1
subsd 0x8(%rdi), %xmm1
movapd 0xb8ff(%rip), %xmm2     # 0x1b240
andpd %xmm1, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, 0x8(%r9)
movsd (%rdi), %xmm1
movsd %xmm1, (%r8)
movsd 0x8(%rsi), %xmm2
movsd %xmm2, 0x8(%r8)
movapd %xmm1, %xmm3
subsd %xmm1, %xmm3
movsd 0x8(%rdi), %xmm4
subsd %xmm2, %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm3, %xmm3
addsd %xmm4, %xmm3
sqrtsd %xmm3, %xmm3
movsd %xmm3, (%rax)
movupd (%r9), %xmm3
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm3, %xmm0
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
addpd %xmm0, %xmm1
movupd %xmm1, (%rcx)
retq
movsd (%rsi), %xmm1
movapd %xmm1, %xmm5
subsd (%rdx), %xmm5
movapd 0xb88a(%rip), %xmm6     # 0x1b240
andpd %xmm5, %xmm6
ucomisd %xmm6, %xmm3
jbe 0xfa1e
movsd %xmm1, (%r8)
movsd 0x8(%rdi), %xmm2
movsd %xmm2, 0x8(%r8)
movsd (%rdi), %xmm3
subsd %xmm1, %xmm3
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
subsd %xmm2, %xmm2
mulsd %xmm2, %xmm2
mulsd %xmm3, %xmm3
addsd %xmm2, %xmm3
sqrtsd %xmm3, %xmm2
movsd %xmm2, (%rax)
movupd (%rdi), %xmm3
movapd %xmm1, %xmm4
subpd %xmm3, %xmm4
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm4
movupd %xmm4, (%r9)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm4, %xmm0
addpd %xmm1, %xmm0
jmp 0xfacc
movapd %xmm4, %xmm3
subsd %xmm2, %xmm3
divsd %xmm5, %xmm3
movsd 0xb9ce(%rip), %xmm5     # 0x1b400
divsd %xmm3, %xmm5
movapd %xmm3, %xmm6
subsd %xmm5, %xmm6
unpcklpd %xmm3, %xmm5            # xmm5 = xmm5[0],xmm3[0]
movsd (%rdi), %xmm7
movsd 0x8(%rdi), %xmm2
unpcklpd %xmm1, %xmm7            # xmm7 = xmm7[0],xmm1[0]
mulpd %xmm5, %xmm7
unpcklpd %xmm4, %xmm2            # xmm2 = xmm2[0],xmm4[0]
subpd %xmm7, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
subsd %xmm1, %xmm2
divsd %xmm6, %xmm2
mulsd %xmm2, %xmm3
addsd %xmm1, %xmm3
movsd %xmm2, (%r8)
movsd %xmm3, 0x8(%r8)
movsd (%rdi), %xmm1
movsd 0x8(%rdi), %xmm4
subsd %xmm2, %xmm1
subsd %xmm3, %xmm4
mulsd %xmm4, %xmm4
mulsd %xmm1, %xmm1
addsd %xmm4, %xmm1
sqrtsd %xmm1, %xmm1
movsd %xmm1, (%rax)
movupd (%rdi), %xmm4
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
movapd %xmm2, %xmm3
subpd %xmm4, %xmm3
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm3
movupd %xmm3, (%r9)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm3, %xmm0
addpd %xmm2, %xmm0
movupd %xmm0, (%rcx)
retq