// File: /workspace/github_cpp_makefile_star2_O2/jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getsmtrctAB(pointxy const*, pointxy const*, pointxy const*, pointxy*, pointxy*, pointxy*)
void getsmtrctAB(const PXYZ *gst, const PXYZ *pA, const PXYZ *pB,
    PXYZ *smtrctP, PXYZ *jiaodian, PXYZ *normal)
{
    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);

        jiaodian->x = gst->x;
        jiaodian->y = pA->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;

        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;
    }
    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;	

        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;
    }
}

// Assembly:
movsd 0x8(%rdx), %xmm2
movsd 0x8(%rsi), %xmm1
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
andpd 0xbad6(%rip), %xmm3     # 0x1b240
movsd 0xbcee(%rip), %xmm0     # 0x1b460
ucomisd %xmm3, %xmm0
jbe 0xf7c0
movsd (%rdi), %xmm0
movsd %xmm0, (%rcx)
addsd %xmm1, %xmm1
subsd 0x8(%rdi), %xmm1
movsd %xmm1, 0x8(%rcx)
andq $0x0, (%r9)
subsd 0x8(%rdi), %xmm1
movapd 0xbaa1(%rip), %xmm0     # 0x1b240
andpd %xmm1, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%r9)
movsd (%rdi), %xmm0
movsd %xmm0, (%r8)
movsd 0x8(%rsi), %xmm0
jmp 0xf8f7
movsd (%rsi), %xmm3
movapd %xmm3, %xmm4
subsd (%rdx), %xmm4
movapd 0xba6c(%rip), %xmm5     # 0x1b240
andpd %xmm4, %xmm5
ucomisd %xmm5, %xmm0
jbe 0xf83e
addsd %xmm3, %xmm3
subsd (%rdi), %xmm3
movsd %xmm3, (%rcx)
movsd 0x8(%rdi), %xmm0
movsd %xmm0, 0x8(%rcx)
movsd (%rsi), %xmm1
movsd %xmm1, (%r8)
movsd %xmm0, 0x8(%r8)
movsd (%rdi), %xmm2
movsd 0x8(%rdi), %xmm3
movapd %xmm2, %xmm4
subsd %xmm1, %xmm4
movapd %xmm3, %xmm5
subsd %xmm0, %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm4, %xmm4
addsd %xmm5, %xmm4
sqrtsd %xmm4, %xmm4
subsd %xmm2, %xmm1
divsd %xmm4, %xmm1
movsd %xmm1, (%r9)
jmp 0xf8ec
movapd %xmm1, %xmm0
subsd %xmm2, %xmm0
divsd %xmm4, %xmm0
movsd 0xbbae(%rip), %xmm4     # 0x1b400
divsd %xmm0, %xmm4
movapd %xmm0, %xmm5
subsd %xmm4, %xmm5
unpcklpd %xmm0, %xmm4            # xmm4 = xmm4[0],xmm0[0]
movsd (%rdi), %xmm6
movsd 0x8(%rdi), %xmm2
unpcklpd %xmm3, %xmm6            # xmm6 = xmm6[0],xmm3[0]
mulpd %xmm4, %xmm6
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
subpd %xmm6, %xmm2
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
subsd %xmm1, %xmm2
divsd %xmm5, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm2, (%r8)
movsd %xmm0, 0x8(%r8)
movupd (%rdi), %xmm1
movapd %xmm2, %xmm3
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
addpd %xmm3, %xmm3
subpd %xmm1, %xmm3
movupd %xmm3, (%rcx)
movsd (%rdi), %xmm1
movsd 0x8(%rdi), %xmm3
movapd %xmm1, %xmm4
subsd %xmm2, %xmm4
movapd %xmm3, %xmm5
subsd %xmm0, %xmm5
mulsd %xmm5, %xmm5
mulsd %xmm4, %xmm4
addsd %xmm5, %xmm4
sqrtsd %xmm4, %xmm4
subsd %xmm1, %xmm2
divsd %xmm4, %xmm2
movsd %xmm2, (%r9)
subsd %xmm3, %xmm0
divsd %xmm4, %xmm0
movq %r9, %r8
movsd %xmm0, 0x8(%r8)
retq