// File: /workspace/github_c_makefile_star2_O2/radforddc[P]icpc_siggen/detector_geometry.c
// Function: outside_detector
int outside_detector(point pt, MJD_Siggen_Setup *setup){
  float r, z, r1, z1, br, a, b;

  z = pt.z;
  if (z > setup->zmax || z < 0) return 1;

  r = sqrt(SQ(pt.x)+SQ(pt.y));
  if (r > setup->rmax) return 1;
  r1 = setup->rmax - r;  // distance from outer radius
  z1 = setup->zmax - z;  // distance from top of crystal

  /* check point contact */
  if (z < setup->pc_length && r < setup->pc_radius) {
    if (!setup->bulletize_PC) return 1;
    if (setup->pc_length > setup->pc_radius) {
      a = setup->pc_length - setup->pc_radius;
      if (z < a || SQ(z-a) + SQ(r) < SQ(setup->pc_radius)) return 1;
    } else {
      a = setup->pc_radius - setup->pc_length;
      if (r < a || SQ(z) + SQ(r-a) < SQ(setup->pc_length)) return 1;
    }
    return 0;
  }

  /* check ditch */
  if (z < setup->ditch_depth  &&
      setup->ditch_thickness > 0 && setup->wrap_around_radius > 0 &&
      r < setup->wrap_around_radius &&
      r > setup->wrap_around_radius - setup->ditch_thickness) return 1;

  /* check hole */
  if ( r < setup->hole_radius &&
      z1 < setup->hole_length) {
    b = setup->zmax - setup->hole_length + setup->hole_bullet_radius;
    if (z > b) return 1;
    a = setup->hole_radius - setup->hole_bullet_radius;
    if (r < a || SQ(b-z) + SQ(r-a) < SQ(setup->hole_bullet_radius)) return 1;
  }

  /* check inner taper of hole */
  if (z1 < setup->inner_taper_length &&
      r  < setup->hole_radius +
            ((setup->inner_taper_length - z1) *
              setup->inner_taper_width / setup->inner_taper_length)) return 1;      
  /* check outer taper of crystal */
  if (z1 < setup->outer_taper_length &&
      r1 < ((setup->outer_taper_length - z1) *
              setup->outer_taper_width / setup->outer_taper_length)) return 1;
  /* check 45-degree bottom outer taper of crystal */
  if ( z < setup->bottom_taper_length &&
      r1 < setup->bottom_taper_length - z) return 1;

  /* check bulletizations */
  br = setup->top_bullet_radius;
  // adjust top bulletization position for top outer taper
  a = 0;
  if (setup->outer_taper_length > br)
    a = ((setup->outer_taper_length - br) *
         setup->outer_taper_width / setup->outer_taper_length);
  if (z1 < br &&
      r1 < br + a &&
      SQ(br - r1 + a) + SQ(br - z1) > br*br) return 1;
  br = setup->bottom_bullet_radius;
  if ( z < br &&
      r1 < br &&
      SQ(br - r1) + SQ(br - z ) > br*br) return 1;

  return 0;
}

// Assembly:
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
pushq $0x1
popq %rax
ja 0x715f
movss 0x3c0(%rdi), %xmm4
ucomiss %xmm4, %xmm1
ja 0x715f
movaps %xmm0, %xmm2
mulps %xmm0, %xmm2
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
mulss %xmm0, %xmm0
addss %xmm2, %xmm0
sqrtss %xmm0, %xmm2
movss 0x3b4(%rdi), %xmm0
ucomiss %xmm0, %xmm2
jbe 0x7160
retq
movss 0xc(%rdi), %xmm3
ucomiss %xmm1, %xmm3
jbe 0x71ad
movss 0x10(%rdi), %xmm5
ucomiss %xmm2, %xmm5
jbe 0x71ad
cmpl $0x0, 0x84(%rdi)
je 0x715f
ucomiss %xmm5, %xmm3
jbe 0x733b
subss %xmm5, %xmm3
ucomiss %xmm1, %xmm3
ja 0x715f
subss %xmm3, %xmm1
mulss %xmm2, %xmm2
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
mulss %xmm5, %xmm5
ucomiss %xmm1, %xmm5
ja 0x715f
jmp 0x7365
movss 0x18(%rdi), %xmm3
ucomiss %xmm1, %xmm3
jbe 0x71dc
movss 0x1c(%rdi), %xmm3
xorps %xmm6, %xmm6
ucomiss %xmm6, %xmm3
jbe 0x71dc
movss 0x14(%rdi), %xmm5
ucomiss %xmm6, %xmm5
jbe 0x71dc
ucomiss %xmm2, %xmm5
jbe 0x71dc
subss %xmm3, %xmm5
ucomiss %xmm5, %xmm2
ja 0x715f
movaps %xmm4, %xmm3
subss %xmm1, %xmm3
movss 0x28(%rdi), %xmm5
ucomiss %xmm2, %xmm5
jbe 0x7245
movss 0x24(%rdi), %xmm6
ucomiss %xmm3, %xmm6
jbe 0x7245
subss %xmm6, %xmm4
movss 0x48(%rdi), %xmm6
addss %xmm6, %xmm4
ucomiss %xmm4, %xmm1
ja 0x715f
movaps %xmm5, %xmm7
subss %xmm6, %xmm7
ucomiss %xmm2, %xmm7
ja 0x715f
subss %xmm1, %xmm4
movaps %xmm2, %xmm8
subss %xmm7, %xmm8
mulss %xmm8, %xmm8
mulss %xmm4, %xmm4
addss %xmm8, %xmm4
mulss %xmm6, %xmm6
ucomiss %xmm4, %xmm6
ja 0x715f
movss 0x34(%rdi), %xmm4
ucomiss %xmm3, %xmm4
jbe 0x726c
movaps %xmm4, %xmm6
subss %xmm3, %xmm6
mulss 0x3c(%rdi), %xmm6
divss %xmm4, %xmm6
addss %xmm6, %xmm5
ucomiss %xmm2, %xmm5
ja 0x715f
subss %xmm2, %xmm0
movss 0x2c(%rdi), %xmm4
ucomiss %xmm3, %xmm4
jbe 0x7293
movaps %xmm4, %xmm2
subss %xmm3, %xmm2
mulss 0x38(%rdi), %xmm2
divss %xmm4, %xmm2
ucomiss %xmm0, %xmm2
ja 0x715f
movss 0x20(%rdi), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x72aa
subss %xmm1, %xmm2
ucomiss %xmm0, %xmm2
ja 0x715f
movss 0x40(%rdi), %xmm2
xorps %xmm5, %xmm5
ucomiss %xmm2, %xmm4
jbe 0x72c7
movaps %xmm4, %xmm5
subss %xmm2, %xmm5
mulss 0x38(%rdi), %xmm5
divss %xmm4, %xmm5
ucomiss %xmm3, %xmm2
jbe 0x7303
movaps %xmm2, %xmm4
addss %xmm5, %xmm4
ucomiss %xmm0, %xmm4
jbe 0x7303
movaps %xmm2, %xmm4
subss %xmm0, %xmm4
addss %xmm5, %xmm4
movaps %xmm2, %xmm5
subss %xmm3, %xmm5
mulss %xmm5, %xmm5
mulss %xmm4, %xmm4
addss %xmm5, %xmm4
mulss %xmm2, %xmm2
ucomiss %xmm2, %xmm4
ja 0x715f
movss 0x44(%rdi), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x7365
ucomiss %xmm0, %xmm2
jbe 0x7365
movaps %xmm2, %xmm3
subss %xmm0, %xmm3
movaps %xmm2, %xmm0
subss %xmm1, %xmm0
mulss %xmm0, %xmm0
mulss %xmm3, %xmm3
addss %xmm0, %xmm3
mulss %xmm2, %xmm2
ucomiss %xmm2, %xmm3
ja 0x715f
jmp 0x7365
subss %xmm3, %xmm5
ucomiss %xmm2, %xmm5
ja 0x715f
subss %xmm5, %xmm2
mulss %xmm2, %xmm2
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
mulss %xmm3, %xmm3
ucomiss %xmm1, %xmm3
ja 0x715f
xorl %eax, %eax
retq