// File: /workspace/github_cpp_makefile_star2_O2/koraa[P]sbcrack/cube/geom.cpp
// Function: linecylinderintersect(vec const&, vec const&, vec const&, vec const&, float, float&)
bool linecylinderintersect(const vec &from, const vec &to, const vec &start, const vec &end, float radius, float &dist)
{
    vec d(end), m(from), n(to);
    d.sub(start);
    m.sub(start);
    n.sub(from);
    float md = m.dot(d),
          nd = n.dot(d),
          dd = d.squaredlen();
    if(md < 0 && md + nd < 0) return false;
    if(md > dd && md + nd > dd) return false;
    float nn = n.squaredlen(),
          mn = m.dot(n),
          a = dd*nn - nd*nd,
          k = m.squaredlen() - radius*radius,
          c = dd*k - md*md;
    if(fabs(a) < 0.005f)
    {
        if(c > 0) return false;
        if(md < 0) dist = -mn / nn;
        else if(md > dd) dist = (nd - mn) / nn;
        else dist = 0;
        return true;
    }
    else if(c > 0)
    {
        float b = dd*mn - nd*md,
              discrim = b*b - a*c;
        if(discrim < 0) return false;
        dist = (-b - sqrtf(discrim)) / a;
    }
    else dist = 0;
    float offset = md + dist*nd;
    if(offset < 0)
    {
        if(nd <= 0) return false;
        dist = -md / nd;
        if(k + dist*(2*mn + dist*nn) > 0) return false;
    }
    else if(offset > dd)
    {
        if(nd >= 0) return false;
        dist = (dd - md) / nd;
        if(k + dd - 2*md + dist*(2*(mn-nd) + dist*nn) > 0) return false;
    }
    return dist >= 0 && dist <= 1;
}

// Assembly:
movss 0x8(%rcx), %xmm1
movss 0x8(%rdx), %xmm3
subss %xmm3, %xmm1
movss (%rsi), %xmm2
movss 0x4(%rsi), %xmm4
movss 0x8(%rsi), %xmm5
movss (%rdi), %xmm8
movss 0x4(%rdi), %xmm9
movss 0x8(%rdi), %xmm6
movaps %xmm9, %xmm7
unpcklps %xmm2, %xmm7            # xmm7 = xmm7[0],xmm2[0],xmm7[1],xmm2[1]
movaps %xmm8, %xmm2
unpcklps %xmm4, %xmm2            # xmm2 = xmm2[0],xmm4[0],xmm2[1],xmm4[1]
unpcklps %xmm6, %xmm3            # xmm3 = xmm3[0],xmm6[0],xmm3[1],xmm6[1]
unpcklps %xmm5, %xmm6            # xmm6 = xmm6[0],xmm5[0],xmm6[1],xmm5[1]
subps %xmm3, %xmm6
movaps %xmm1, %xmm5
mulss %xmm6, %xmm5
movsd (%rcx), %xmm4
movsd (%rdx), %xmm3
subps %xmm3, %xmm4
shufps $0xd4, %xmm3, %xmm8     # xmm8 = xmm8[0,1],xmm3[1,3]
shufps $0x52, %xmm3, %xmm8     # xmm8 = xmm8[2,0],xmm3[1,1]
subps %xmm8, %xmm7
movlhps %xmm3, %xmm9            # xmm9 = xmm9[0],xmm3[0]
shufps $0xe2, %xmm3, %xmm9     # xmm9 = xmm9[2,0],xmm3[2,3]
subps %xmm9, %xmm2
movaps %xmm4, %xmm8
mulss %xmm2, %xmm8
movaps %xmm4, %xmm3
shufps $0x55, %xmm4, %xmm3     # xmm3 = xmm3[1,1],xmm4[1,1]
mulss %xmm7, %xmm3
addss %xmm8, %xmm3
addss %xmm5, %xmm3
movaps %xmm2, %xmm5
shufps $0x1, %xmm4, %xmm5      # xmm5 = xmm5[1,0],xmm4[0,0]
shufps $0xe2, %xmm4, %xmm5     # xmm5 = xmm5[2,0],xmm4[2,3]
mulps %xmm4, %xmm5
movaps %xmm7, %xmm8
shufps $0x55, %xmm4, %xmm8     # xmm8 = xmm8[1,1],xmm4[1,1]
shufps $0xe2, %xmm4, %xmm8     # xmm8 = xmm8[2,0],xmm4[2,3]
shufps $0xe1, %xmm4, %xmm4     # xmm4 = xmm4[1,0,2,3]
mulps %xmm8, %xmm4
addps %xmm5, %xmm4
movaps %xmm6, %xmm5
movss %xmm1, %xmm5            # xmm5 = xmm1[0],xmm5[1,2,3]
shufps $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
mulps %xmm5, %xmm1
addps %xmm4, %xmm1
movaps %xmm1, %xmm4
shufps $0x55, %xmm1, %xmm4     # xmm4 = xmm4[1,1],xmm1[1,1]
xorps %xmm8, %xmm8
ucomiss %xmm8, %xmm3
movaps %xmm3, %xmm5
addss %xmm4, %xmm5
jae 0x40ff
ucomiss %xmm8, %xmm5
jb 0x4109
ucomiss %xmm1, %xmm3
jbe 0x410c
ucomiss %xmm1, %xmm5
jbe 0x410c
xorl %eax, %eax
retq
movaps %xmm7, %xmm8
shufps $0x11, %xmm2, %xmm8     # xmm8 = xmm8[1,0],xmm2[1,0]
movaps %xmm8, %xmm5
shufps $0xe2, %xmm2, %xmm5     # xmm5 = xmm5[2,0],xmm2[2,3]
mulps %xmm7, %xmm5
shufps $0xe8, %xmm2, %xmm8     # xmm8 = xmm8[0,2],xmm2[2,3]
mulps %xmm2, %xmm8
addps %xmm5, %xmm8
movaps %xmm6, %xmm5
shufps $0x55, %xmm6, %xmm5     # xmm5 = xmm5[1,1],xmm6[1,1]
mulps %xmm6, %xmm5
addps %xmm8, %xmm5
movaps %xmm1, %xmm8
shufps $0x11, %xmm5, %xmm8     # xmm8 = xmm8[1,0],xmm5[1,0]
shufps $0xe2, %xmm5, %xmm8     # xmm8 = xmm8[2,0],xmm5[2,3]
mulps %xmm1, %xmm8
movaps %xmm8, %xmm9
shufps $0x55, %xmm8, %xmm9     # xmm9 = xmm9[1,1],xmm8[1,1]
subss %xmm9, %xmm8
mulss %xmm2, %xmm2
mulss %xmm7, %xmm7
mulss %xmm6, %xmm6
addss %xmm7, %xmm6
mulss %xmm0, %xmm0
subss %xmm0, %xmm2
addss %xmm6, %xmm2
movaps %xmm2, %xmm6
mulss %xmm1, %xmm6
movaps %xmm3, %xmm0
mulss %xmm3, %xmm0
subss %xmm0, %xmm6
movaps 0x1020(%rip), %xmm0     # 0x51b0
andps %xmm8, %xmm0
ucomiss 0x1039(%rip), %xmm0     # 0x51d4
jae 0x41ce
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm6
ja 0x4109
ucomiss %xmm0, %xmm3
jae 0x42ec
movaps 0xfe7(%rip), %xmm0      # 0x51a0
xorps %xmm5, %xmm0
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
divss %xmm5, %xmm0
movss %xmm0, (%r8)
jmp 0x4308
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm6
xorps %xmm7, %xmm7
jbe 0x422b
movaps %xmm3, %xmm7
movlhps %xmm5, %xmm7            # xmm7 = xmm7[0],xmm5[0]
shufps $0xe2, %xmm5, %xmm7     # xmm7 = xmm7[2,0],xmm5[2,3]
movaps %xmm1, %xmm9
mulps %xmm7, %xmm9
movaps %xmm9, %xmm7
shufps $0x55, %xmm9, %xmm7     # xmm7 = xmm7[1,1],xmm9[1,1]
subps %xmm7, %xmm9
movaps %xmm9, %xmm7
mulss %xmm9, %xmm7
mulss %xmm8, %xmm6
subss %xmm6, %xmm7
xorps %xmm6, %xmm6
ucomiss %xmm6, %xmm7
jb 0x4109
sqrtss %xmm7, %xmm7
addss %xmm9, %xmm7
xorps 0xf7a(%rip), %xmm7      # 0x51a0
divss %xmm8, %xmm7
movss %xmm7, (%r8)
movaps %xmm7, %xmm6
mulss %xmm4, %xmm6
addss %xmm3, %xmm6
ucomiss %xmm0, %xmm6
jae 0x4287
ucomiss %xmm0, %xmm4
jbe 0x4109
xorps 0xf50(%rip), %xmm3      # 0x51a0
divss %xmm4, %xmm3
movss %xmm3, (%r8)
movaps 0xf60(%rip), %xmm1      # 0x51c0
unpcklps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
mulps %xmm5, %xmm1
movaps %xmm1, %xmm4
shufps $0x55, %xmm1, %xmm4     # xmm4 = xmm4[1,1],xmm1[1,1]
addss %xmm1, %xmm4
mulss %xmm3, %xmm4
addss %xmm2, %xmm4
ucomiss %xmm0, %xmm4
movaps %xmm3, %xmm7
ja 0x4109
jmp 0x42d9
ucomiss %xmm1, %xmm6
jbe 0x42d9
ucomiss %xmm0, %xmm4
jae 0x4109
addss %xmm1, %xmm2
subss %xmm3, %xmm1
divss %xmm4, %xmm1
movss %xmm1, (%r8)
addss %xmm3, %xmm3
subss %xmm3, %xmm2
movaps %xmm5, %xmm3
subss %xmm4, %xmm3
addss %xmm3, %xmm3
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
mulss %xmm1, %xmm5
addss %xmm3, %xmm5
mulss %xmm1, %xmm5
addss %xmm2, %xmm5
ucomiss %xmm0, %xmm5
movaps %xmm1, %xmm7
ja 0x4109
ucomiss %xmm0, %xmm7
setae %cl
ucomiss 0xeea(%rip), %xmm7      # 0x51d0
setbe %al
andb %cl, %al
retq
ucomiss %xmm1, %xmm3
jbe 0x4304
subss %xmm5, %xmm4
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
divss %xmm5, %xmm4
movss %xmm4, (%r8)
jmp 0x4308
andl $0x0, (%r8)
movb $0x1, %al
retq