// File: /workspace/github_cpp_makefile_star2_O2/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 0x10970
sqrtsd %xmm0, %xmm7
jmp 0x10989
movapd %xmm8, (%rsp)
callq 0x3180
xorpd %xmm2, %xmm2
movapd (%rsp), %xmm8
movapd %xmm0, %xmm7
andpd 0xa8ae(%rip), %xmm8     # 0x1b240
addsd 0xaeed(%rip), %xmm8     # 0x1b888
divsd %xmm8, %xmm7
movupd (%r14), %xmm0
movupd (%r15), %xmm4
addpd %xmm0, %xmm4
mulpd 0xac5a(%rip), %xmm4     # 0x1b610
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
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 0x109fe
sqrtsd %xmm0, %xmm0
jmp 0x10a3d
movapd %xmm7, (%rsp)
movapd %xmm4, 0x40(%rsp)
movapd %xmm5, 0x30(%rsp)
movapd %xmm3, 0x20(%rsp)
movapd %xmm6, 0x10(%rsp)
callq 0x3180
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 0xa64c(%rip), %xmm1     # 0x1b0a0
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 0xa79b(%rip), %xmm1     # 0x1b240
andpd %xmm1, %xmm5
movsd 0xa6cf(%rip), %xmm3     # 0x1b180
ucomisd %xmm5, %xmm3
ja 0x10abf
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 0xad83(%rip), %xmm0     # 0x1b890
movsd 0xad83(%rip), %xmm1     # 0x1b898
andpd %xmm0, %xmm1
andnpd %xmm7, %xmm0
orpd %xmm1, %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq