; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Cont.ll (Z10R2ContainsRK9R2PolygonRK7R2Point)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.R2Ray = type { %class.R2Line, %class.R2Point }
%class.R2Line = type { %class.R2Vector, %class.R2Vector, double }
%class.R2Vector = type { [2 x double] }
%class.R2Point = type { [2 x double] }
%class.R2Span = type { %class.R2Ray, %class.R2Point, double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10R2ContainsRK9R2PolygonRK7R2Point(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %class.R2Ray, align 8
  %7 = alloca %class.R2Vector, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %class.R2Span, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 56, ptr %6) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  call void @_ZN8R2VectorC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %7, double noundef 1.234500e-01, double noundef 0x3FEFC15677051A1B)
  call void @_ZN5R2RayC1ERK7R2PointRK8R2Vectori(ptr noundef nonnull align 8 dereferenceable(56) %6, ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef nonnull align 8 dereferenceable(16) %7, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %38, %2
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call noundef i32 @_ZNK9R2Polygon7NPointsEv(ptr noundef nonnull align 8 dereferenceable(68) %15)
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %41

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK9R2Polygon5PointEi(ptr noundef nonnull align 8 dereferenceable(68) %20, i32 noundef %21)
  store ptr %22, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = add nsw i32 %24, 1
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call noundef i32 @_ZNK9R2Polygon7NPointsEv(ptr noundef nonnull align 8 dereferenceable(68) %26)
  %28 = srem i32 %25, %27
  %29 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK9R2Polygon5PointEi(ptr noundef nonnull align 8 dereferenceable(68) %23, i32 noundef %28)
  store ptr %29, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr %11) #4
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN6R2SpanC1ERK7R2PointS2_(ptr noundef nonnull align 8 dereferenceable(80) %11, ptr noundef nonnull align 8 dereferenceable(16) %30, ptr noundef nonnull align 8 dereferenceable(16) %31)
  %32 = call noundef i32 @_Z12R2IntersectsRK5R2RayRK6R2SpanP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(56) %6, ptr noundef nonnull align 8 dereferenceable(80) %11, ptr noundef null, ptr noundef null, ptr noundef null)
  %33 = icmp ne i32 %32, 0
  call void @llvm.lifetime.end.p0(i64 80, ptr %11) #4
  br i1 %33, label %34, label %37

34:                                               ; preds = %19
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %5, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %34, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %13, !llvm.loop !11

41:                                               ; preds = %18
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = srem i32 %42, 2
  %44 = icmp ne i32 %43, 0
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 1, i32 0
  call void @llvm.lifetime.end.p0(i64 56, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %46
}

declare void @_ZN8R2VectorC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #2

declare void @_ZN5R2RayC1ERK7R2PointRK8R2Vectori(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9R2Polygon7NPointsEv(ptr noundef nonnull align 8 dereferenceable(68)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNK9R2Polygon5PointEi(ptr noundef nonnull align 8 dereferenceable(68), i32 noundef) #3 align 2

declare noundef i32 @_Z12R2IntersectsRK5R2RayRK6R2SpanP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, ptr noundef, ptr noundef) #2

declare void @_ZN6R2SpanC1ERK7R2PointS2_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.R2Ray = type { %class.R2Line, %class.R2Point }
%class.R2Line = type { %class.R2Vector, %class.R2Vector, double }
%class.R2Vector = type { [2 x double] }
%class.R2Point = type { [2 x double] }
%class.R2Span = type { %class.R2Ray, %class.R2Point, double }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z10R2ContainsRK9R2PolygonRK7R2Point(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) local_unnamed_addr #1 {
  %3 = alloca %class.R2Ray, align 8
  %4 = alloca %class.R2Vector, align 8
  %5 = alloca %class.R2Span, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @_ZN8R2VectorC1Edd(ptr noundef nonnull align 8 dereferenceable(16) %4, double noundef 1.234500e-01, double noundef 0x3FEFC15677051A1B)
  call void @_ZN5R2RayC1ERK7R2PointRK8R2Vectori(ptr noundef nonnull align 8 dereferenceable(56) %3, ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  %6 = call noundef i32 @_ZNK9R2Polygon7NPointsEv(ptr noundef nonnull align 8 dereferenceable(68) %0)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %8 = and i32 %spec.select, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ %8, %._crit_edge.loopexit ]
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %3) #4
  ret i32 %.0.lcssa

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.014 = phi i32 [ %spec.select, %.lr.ph ], [ 0, %2 ]
  %.01213 = phi i32 [ %10, %.lr.ph ], [ 0, %2 ]
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK9R2Polygon5PointEi(ptr noundef nonnull align 8 dereferenceable(68) %0, i32 noundef %.01213)
  %10 = add nuw nsw i32 %.01213, 1
  %11 = call noundef i32 @_ZNK9R2Polygon7NPointsEv(ptr noundef nonnull align 8 dereferenceable(68) %0)
  %12 = srem i32 %10, %11
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNK9R2Polygon5PointEi(ptr noundef nonnull align 8 dereferenceable(68) %0, i32 noundef %12)
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %5) #4
  call void @_ZN6R2SpanC1ERK7R2PointS2_(ptr noundef nonnull align 8 dereferenceable(80) %5, ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(16) %13)
  %14 = call noundef i32 @_Z12R2IntersectsRK5R2RayRK6R2SpanP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(56) %3, ptr noundef nonnull align 8 dereferenceable(80) %5, ptr noundef null, ptr noundef null, ptr noundef null)
  %.not = icmp ne i32 %14, 0
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %5) #4
  %15 = zext i1 %.not to i32
  %spec.select = add nuw nsw i32 %.014, %15
  %16 = call noundef i32 @_ZNK9R2Polygon7NPointsEv(ptr noundef nonnull align 8 dereferenceable(68) %0)
  %17 = icmp slt i32 %10, %16
  br i1 %17, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !5
}

declare void @_ZN8R2VectorC1Edd(ptr noundef nonnull align 8 dereferenceable(16), double noundef, double noundef) unnamed_addr #2

declare void @_ZN5R2RayC1ERK7R2PointRK8R2Vectori(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9R2Polygon7NPointsEv(ptr noundef nonnull align 8 dereferenceable(68)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNK9R2Polygon5PointEi(ptr noundef nonnull align 8 dereferenceable(68), i32 noundef) local_unnamed_addr #3 align 2

declare noundef i32 @_Z12R2IntersectsRK5R2RayRK6R2SpanP7R2PointPdS7_(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef nonnull align 8 dereferenceable(80), ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @_ZN6R2SpanC1ERK7R2PointS2_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass