anchor.diff:      type(SegmentNode), intent(in) :: curr_node
       type(SegmentNode), intent(out) :: next_node
       ! Variables outside of signature.
  -    integer(c_int) :: i, index
  -    logical(c_bool) :: already_set
  -
  -    already_set = .FALSE.
  +    integer(c_int) :: i, local_index, intersection_index
  +
  +    intersection_index = -1
       if (curr_node%edge_index <= 3) then
          ! NOTE: This assumes but does not check that ``curr_node%edge_index``
          !       is in {1, 2, 3}.
  -       index = curr_node%edge_index
  +       local_index = curr_node%edge_index
          do i = 1, num_intersections
             if ( &
  -               intersections(i)%index_first == index .AND. &
  +               intersections(i)%index_first == local_index .AND. &
                  intersections(i)%s > curr_node%edge_param) then
  -             if (.NOT. already_set) then
  -                already_set = .TRUE.
  +             if (intersection_index == -1) then
  +                intersection_index = i
                   next_node%edge_index = curr_node%edge_index
                   next_node%edge_param = intersections(i)%s
                   next_node%interior_curve = intersections(i)%interior_curve
                else
                   if (intersections(i)%s < next_node%edge_param) then
                      ! Assumes ``edge_index`` is already set.
  +                   intersection_index = i
                      next_node%edge_param = intersections(i)%s
                      next_node%interior_curve = intersections(i)%interior_curve
                   end if
  
positive.code: 
         ! If there is no other intersection on the edge, just return
         ! the segment end.
         if (.NOT. already_set) then
            next_node%edge_index = curr_node%edge_index
            next_node%edge_param = 1.0_dp
            next_node%interior_curve = IntersectionClassification_SECOND
  
negative.code: 
         ! If there is no other intersection on the edge, just return
         ! the segment end.
         if (intersection_index == -1) then
            next_node%edge_index = curr_node%edge_index
            next_node%edge_param = 1.0_dp
            next_node%interior_curve = IntersectionClassification_FIRST
  