// File: /workspace/github_c_makefile_star2_O2/radforddc[P]icpc_siggen/detector_geometry.c
// Function: outside_detector_cyl
int outside_detector_cyl(cyl_pt 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 = pt.r;
  if (r < 0) r = -r;
  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;
  a = setup->Li_thickness;   // FIXME ? added for fieldgen
  if ( z < br + a &&
      r1 < br &&
      SQ(br - r1) + SQ(br - z + a) > br*br) return 1;

  return 0;
}

// Assembly:
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
pushq $0x1
popq %rax
ja 0x739b
movss 0x3c0(%rdi), %xmm4
ucomiss %xmm4, %xmm1
ja 0x739b
movaps %xmm0, %xmm2
xorps 0xdc6(%rip), %xmm2      # 0x8150
maxss %xmm0, %xmm2
movss 0x3b4(%rdi), %xmm0
ucomiss %xmm0, %xmm2
jbe 0x739c
retq
movss 0xc(%rdi), %xmm3
ucomiss %xmm1, %xmm3
jbe 0x73e9
movss 0x10(%rdi), %xmm5
ucomiss %xmm2, %xmm5
jbe 0x73e9
cmpl $0x0, 0x84(%rdi)
je 0x739b
ucomiss %xmm5, %xmm3
jbe 0x7587
subss %xmm5, %xmm3
ucomiss %xmm1, %xmm3
ja 0x739b
subss %xmm3, %xmm1
mulss %xmm2, %xmm2
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
mulss %xmm5, %xmm5
ucomiss %xmm1, %xmm5
ja 0x739b
jmp 0x75b1
movss 0x18(%rdi), %xmm3
ucomiss %xmm1, %xmm3
jb 0x7418
movss 0x1c(%rdi), %xmm3
xorps %xmm6, %xmm6
ucomiss %xmm6, %xmm3
jbe 0x7418
movss 0x14(%rdi), %xmm5
ucomiss %xmm6, %xmm5
jbe 0x7418
ucomiss %xmm2, %xmm5
jbe 0x7418
subss %xmm3, %xmm5
ucomiss %xmm5, %xmm2
ja 0x739b
movaps %xmm4, %xmm3
subss %xmm1, %xmm3
movss 0x28(%rdi), %xmm5
ucomiss %xmm2, %xmm5
jbe 0x7481
movss 0x24(%rdi), %xmm6
ucomiss %xmm3, %xmm6
jbe 0x7481
subss %xmm6, %xmm4
movss 0x48(%rdi), %xmm6
addss %xmm6, %xmm4
ucomiss %xmm4, %xmm1
ja 0x739b
movaps %xmm5, %xmm7
subss %xmm6, %xmm7
ucomiss %xmm2, %xmm7
ja 0x739b
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 0x739b
movss 0x34(%rdi), %xmm4
ucomiss %xmm3, %xmm4
jbe 0x74a8
movaps %xmm4, %xmm6
subss %xmm3, %xmm6
mulss 0x3c(%rdi), %xmm6
divss %xmm4, %xmm6
addss %xmm6, %xmm5
ucomiss %xmm2, %xmm5
ja 0x739b
subss %xmm2, %xmm0
movss 0x2c(%rdi), %xmm4
ucomiss %xmm3, %xmm4
jbe 0x74cf
movaps %xmm4, %xmm2
subss %xmm3, %xmm2
mulss 0x38(%rdi), %xmm2
divss %xmm4, %xmm2
ucomiss %xmm0, %xmm2
ja 0x739b
movss 0x20(%rdi), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x74e6
subss %xmm1, %xmm2
ucomiss %xmm0, %xmm2
ja 0x739b
movss 0x40(%rdi), %xmm2
xorps %xmm5, %xmm5
ucomiss %xmm2, %xmm4
jbe 0x7503
movaps %xmm4, %xmm5
subss %xmm2, %xmm5
mulss 0x38(%rdi), %xmm5
divss %xmm4, %xmm5
ucomiss %xmm3, %xmm2
jbe 0x753f
movaps %xmm2, %xmm4
addss %xmm5, %xmm4
ucomiss %xmm0, %xmm4
jbe 0x753f
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 0x739b
movss 0x44(%rdi), %xmm2
ucomiss %xmm0, %xmm2
jbe 0x75b1
movss 0x4c(%rdi), %xmm3
movaps %xmm2, %xmm4
addss %xmm3, %xmm4
ucomiss %xmm1, %xmm4
jbe 0x75b1
movaps %xmm2, %xmm4
subss %xmm0, %xmm4
movaps %xmm2, %xmm0
subss %xmm1, %xmm0
addss %xmm3, %xmm0
mulss %xmm0, %xmm0
mulss %xmm4, %xmm4
addss %xmm0, %xmm4
mulss %xmm2, %xmm2
ucomiss %xmm2, %xmm4
ja 0x739b
jmp 0x75b1
subss %xmm3, %xmm5
ucomiss %xmm2, %xmm5
ja 0x739b
subss %xmm5, %xmm2
mulss %xmm2, %xmm2
mulss %xmm1, %xmm1
addss %xmm2, %xmm1
mulss %xmm3, %xmm3
ucomiss %xmm1, %xmm3
ja 0x739b
xorl %eax, %eax
retq