// File: /workspace/github_cpp_makefile_star2_O3/jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: getRadius(pointxy const*, pointxy const*, pointxy const*, pointxy&)
double getRadius(const PXYZ *pt1, const PXYZ *pt2,const PXYZ *pt3, PXYZ &centr)
{
    //Ҫ�����㹲�߻��߽ӽ������������Ŀ��Ҳ��� TODO
    double rd,dls1,dls2,dls3,dls4;
    dls1=(pt1->x-pt2->x)*(pt1->x-pt2->x)+(pt1->y-pt2->y)*(pt1->y-pt2->y);
    dls2=(pt1->x-pt3->x)*(pt1->x-pt3->x)+(pt1->y-pt3->y)*(pt1->y-pt3->y);
    dls3=(pt2->x-pt3->x)*(pt2->x-pt3->x)+(pt2->y-pt3->y)*(pt2->y-pt3->y);
    dls4=2.0*(pt3->x * (pt2->y - pt1->y) + pt2->x * (pt1->y - pt3->y) 
        + pt1->x * (pt3->y-pt2->y));
    rd = sqrt(dls1*dls2*dls3)/(fabs(dls4)+1.0e-18);

    double xc12,yc12;
    xc12=0.5*(pt1->x+pt2->x);
    yc12=0.5*(pt1->y+pt2->y);

    double dis1c, dis;
    dis1c=sqrt((pt1->x-xc12)*(pt1->x-xc12)+(pt1->y-yc12)*(pt1->y-yc12));
    dis=sqrt(rd*rd-dis1c*dis1c);

    //   PXYZ tdir;
    PXYZ nml, cen1;       
    //  tdir.x=(pt1->x-xc12)/dis1c;
    // tdir.y=(pt1->y-yc12)/dis1c;       

    nml.x=(pt1->y-yc12)/dis1c;  
    nml.y=-(pt1->x-xc12)/dis1c;

    cen1.x= xc12+nml.x*dis;
    cen1.y= yc12+nml.y*dis;

    if(fabs(rd*rd-(cen1.x-pt3->x)*(cen1.x-pt3->x)-(cen1.y-pt3->y)*(cen1.y-pt3->y))<ERRS) {
        centr=cen1;
    }
    else {
        centr.x= xc12-nml.x*dis;
        centr.y= yc12-nml.y*dis;        
    }  

    double a1,b1,a2,b2;
    a1=pt2->x-pt1->x;
    b1=pt2->y-pt1->y;

    a2=pt3->x-pt1->x;
    b2=pt3->y-pt1->y;
    if(fabs(a1*b2-b1*a2)<1.0e-12) rd=1.0e15;
    return rd;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movsd (%rdi), %xmm3
movsd 0x8(%rdi), %xmm0
movsd (%rsi), %xmm2
movsd 0x8(%rsi), %xmm4
movsd (%rdx), %xmm1
movsd 0x8(%rdx), %xmm8
movapd %xmm4, %xmm6
unpcklpd %xmm8, %xmm6            # xmm6 = xmm6[0],xmm8[0]
movapd %xmm4, %xmm5
subsd %xmm8, %xmm5
subsd %xmm4, %xmm8
mulsd %xmm3, %xmm8
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
subsd %xmm0, %xmm4
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
subpd %xmm6, %xmm0
movapd %xmm0, %xmm6
movapd %xmm2, %xmm7
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
mulsd %xmm2, %xmm0
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
subpd %xmm2, %xmm3
mulpd %xmm6, %xmm6
mulpd %xmm3, %xmm3
addpd %xmm6, %xmm3
subsd %xmm1, %xmm7
mulsd %xmm5, %xmm5
mulsd %xmm7, %xmm7
addsd %xmm5, %xmm7
mulsd %xmm1, %xmm4
addsd %xmm0, %xmm4
addsd %xmm4, %xmm8
addsd %xmm8, %xmm8
movapd %xmm3, %xmm0
unpckhpd %xmm3, %xmm0            # xmm0 = xmm0[1],xmm3[1]
mulsd %xmm3, %xmm0
mulsd %xmm7, %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jb 0x11dff
xorps %xmm7, %xmm7
sqrtsd %xmm0, %xmm7
jmp 0x11e18
movapd %xmm8, (%rsp)
callq 0x31b0
xorpd %xmm2, %xmm2
movapd (%rsp), %xmm8
movapd %xmm0, %xmm7
andpd 0xb39f(%rip), %xmm8     # 0x1d1c0
addsd 0xba2e(%rip), %xmm8     # 0x1d858
divsd %xmm8, %xmm7
movupd (%r14), %xmm0
movupd (%r15), %xmm4
addpd %xmm0, %xmm4
mulpd 0xb7ab(%rip), %xmm4     # 0x1d5f0
subpd %xmm4, %xmm0
movapd %xmm4, %xmm3
unpckhpd %xmm4, %xmm3            # xmm3 = xmm3[1],xmm4[1]
movapd %xmm0, %xmm1
mulpd %xmm0, %xmm1
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorps %xmm6, %xmm6
sqrtsd %xmm0, %xmm6
movapd %xmm6, %xmm1
mulsd %xmm6, %xmm1
movapd %xmm7, %xmm5
mulsd %xmm7, %xmm5
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x11e90
sqrtsd %xmm0, %xmm0
jmp 0x11ecf
movapd %xmm7, (%rsp)
movapd %xmm4, 0x40(%rsp)
movapd %xmm5, 0x30(%rsp)
movapd %xmm3, 0x20(%rsp)
movapd %xmm6, 0x10(%rsp)
callq 0x31b0
movapd 0x10(%rsp), %xmm6
movapd 0x20(%rsp), %xmm3
movapd 0x30(%rsp), %xmm5
movapd 0x40(%rsp), %xmm4
movapd (%rsp), %xmm7
movsd (%r14), %xmm1
movsd 0x8(%r14), %xmm2
subsd %xmm4, %xmm1
xorpd 0xb1ba(%rip), %xmm1     # 0x1d0a0
subsd %xmm3, %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
divpd %xmm6, %xmm2
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm2, %xmm0
movapd %xmm0, %xmm2
addpd %xmm4, %xmm2
movsd (%rbx), %xmm1
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
mulsd %xmm3, %xmm3
movapd %xmm2, %xmm1
unpckhpd %xmm2, %xmm1            # xmm1 = xmm1[1],xmm2[1]
subsd 0x8(%rbx), %xmm1
subsd %xmm3, %xmm5
mulsd %xmm1, %xmm1
subsd %xmm1, %xmm5
movapd 0xb289(%rip), %xmm1     # 0x1d1c0
andpd %xmm1, %xmm5
movsd 0xb20d(%rip), %xmm3     # 0x1d150
ucomisd %xmm5, %xmm3
ja 0x11f51
subpd %xmm0, %xmm4
movapd %xmm4, %xmm2
movupd %xmm2, (%r12)
movsd (%r15), %xmm2
movsd 0x8(%r15), %xmm3
movsd (%r14), %xmm4
movsd 0x8(%r14), %xmm5
subsd %xmm4, %xmm2
subsd %xmm5, %xmm3
movsd (%rbx), %xmm6
movsd 0x8(%rbx), %xmm0
subsd %xmm4, %xmm6
mulsd %xmm3, %xmm6
subsd %xmm5, %xmm0
mulsd %xmm2, %xmm0
subsd %xmm6, %xmm0
andpd %xmm1, %xmm0
cmpltsd 0xb8c1(%rip), %xmm0     # 0x1d860
movsd 0xb8c1(%rip), %xmm1     # 0x1d868
andpd %xmm0, %xmm1
andnpd %xmm7, %xmm0
orpd %xmm1, %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq