; LLVM IR from Slingshot-Physics/slingshot-community :: common/geometry/src (polygon)

; 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"

%"struct.geometry::types::polygon50_t" = type { i32, [50 x %class.Vector3] }
%class.Vector3 = type { [3 x float] }

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8geometry7polygon9halfPlaneERK7Vector3S3_S3_b(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12), i1 noundef zeroext) #0

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8geometry5types11polygon50_tC2ERKS1_(ptr noundef nonnull align 4 dereferenceable(604), ptr noundef nonnull align 4 dereferenceable(604)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry7polygon13orderVertsCcwERNS_5types11polygon50_tE(ptr noundef nonnull align 4 dereferenceable(604)) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8geometry7polygon11pointInsideERKNS_5types11polygon50_tERK7Vector3(ptr noundef nonnull align 4 dereferenceable(604) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"struct.geometry::types::polygon50_t", align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 604, ptr %6) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN8geometry5types11polygon50_tC2ERKS1_(ptr noundef nonnull align 4 dereferenceable(604) %6, ptr noundef nonnull align 4 dereferenceable(604) %9)
  call void @_ZN8geometry7polygon13orderVertsCcwERNS_5types11polygon50_tE(ptr noundef nonnull align 4 dereferenceable(604) %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %33, %2
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = getelementptr inbounds %"struct.geometry::types::polygon50_t", ptr %6, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp ult i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  store i32 2, ptr %8, align 4
  br label %36

16:                                               ; preds = %10
  %17 = getelementptr inbounds %"struct.geometry::types::polygon50_t", ptr %6, i32 0, i32 1
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds [50 x %class.Vector3], ptr %17, i64 0, i64 %19
  %21 = getelementptr inbounds %"struct.geometry::types::polygon50_t", ptr %6, i32 0, i32 1
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = add i32 %22, 1
  %24 = getelementptr inbounds %"struct.geometry::types::polygon50_t", ptr %6, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = urem i32 %23, %25
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [50 x %class.Vector3], ptr %21, i64 0, i64 %27
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call noundef zeroext i1 @_ZN8geometry7polygon9halfPlaneERK7Vector3S3_S3_b(ptr noundef nonnull align 4 dereferenceable(12) %20, ptr noundef nonnull align 4 dereferenceable(12) %28, ptr noundef nonnull align 4 dereferenceable(12) %29, i1 noundef zeroext true)
  br i1 %30, label %32, label %31

31:                                               ; preds = %16
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %36

32:                                               ; preds = %16
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !13

36:                                               ; preds = %31, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %37 = load i32, ptr %8, align 4
  switch i32 %37, label %39 [
    i32 2, label %38
  ]

38:                                               ; preds = %36
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %39

39:                                               ; preds = %38, %36
  call void @llvm.lifetime.end.p0(i64 604, ptr %6) #3
  %40 = load i1, ptr %3, align 1
  ret i1 %40
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN8geometry5types11polygon50_tE", !10, i64 0, !7, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"struct.geometry::types::polygon50_t" = type { i32, [50 x %class.Vector3] }
%class.Vector3 = type { [3 x float] }

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8geometry7polygon9halfPlaneERK7Vector3S3_S3_b(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12), i1 noundef zeroext) local_unnamed_addr #0

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8geometry5types11polygon50_tC2ERKS1_(ptr noundef nonnull align 4 dereferenceable(604), ptr noundef nonnull align 4 dereferenceable(604)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8geometry7polygon13orderVertsCcwERNS_5types11polygon50_tE(ptr noundef nonnull align 4 dereferenceable(604)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8geometry7polygon11pointInsideERKNS_5types11polygon50_tERK7Vector3(ptr noundef nonnull align 4 dereferenceable(604) %0, ptr noundef nonnull align 4 dereferenceable(12) %1) local_unnamed_addr #0 {
  %3 = alloca %"struct.geometry::types::polygon50_t", align 4
  call void @llvm.lifetime.start.p0(i64 604, ptr nonnull %3) #3
  call void @_ZN8geometry5types11polygon50_tC2ERKS1_(ptr noundef nonnull align 4 dereferenceable(604) %3, ptr noundef nonnull align 4 dereferenceable(604) %0)
  call void @_ZN8geometry7polygon13orderVertsCcwERNS_5types11polygon50_tE(ptr noundef nonnull align 4 dereferenceable(604) %3)
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  br label %5

5:                                                ; preds = %8, %2
  %indvars.iv = phi i64 [ %indvars.iv.next, %8 ], [ 0, %2 ]
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = zext i32 %6 to i64
  %.not.not = icmp uge i64 %indvars.iv, %7
  br i1 %.not.not, label %.critedge, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds [50 x %class.Vector3], ptr %4, i64 0, i64 %indvars.iv
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = icmp eq i64 %indvars.iv.next, %7
  %11 = select i1 %10, i64 0, i64 %indvars.iv.next
  %12 = getelementptr inbounds [50 x %class.Vector3], ptr %4, i64 0, i64 %11
  %13 = call noundef zeroext i1 @_ZN8geometry7polygon9halfPlaneERK7Vector3S3_S3_b(ptr noundef nonnull align 4 dereferenceable(12) %9, ptr noundef nonnull align 4 dereferenceable(12) %12, ptr noundef nonnull align 4 dereferenceable(12) %1, i1 noundef zeroext true)
  br i1 %13, label %5, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %5, %8
  call void @llvm.lifetime.end.p0(i64 604, ptr nonnull %3) #3
  ret i1 %.not.not
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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, !7, i64 0}
!6 = !{!"_ZTSN8geometry5types11polygon50_tE", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass