; LLVM IR from atlantis13579/Riemann :: Src/Geometry/Polygon2.ll (ZN7Riemann16PointInPolygon2DERKN5Maths8TVector2IfEEPS3_i)

; 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.Maths::TVector2" = type { float, float }

; 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 nounwind uwtable
define dso_local noundef zeroext i1 @_ZN7Riemann16PointInPolygon2DERKN5Maths8TVector2IfEEPS3_i(ptr noundef nonnull align 4 dereferenceable(8) %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  store i8 0, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = sub nsw i32 %12, 1
  store i32 %13, ptr %9, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %83, %3
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %"class.Maths::TVector2", ptr %20, i64 %22
  store ptr %23, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %"class.Maths::TVector2", ptr %24, i64 %26
  store ptr %27, ptr %11, align 8, !tbaa !5
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds %"class.Maths::TVector2", ptr %28, i32 0, i32 1
  %30 = load float, ptr %29, align 4, !tbaa !13
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %"class.Maths::TVector2", ptr %31, i32 0, i32 1
  %33 = load float, ptr %32, align 4, !tbaa !13
  %34 = fcmp ogt float %30, %33
  %35 = zext i1 %34 to i32
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.Maths::TVector2", ptr %36, i32 0, i32 1
  %38 = load float, ptr %37, align 4, !tbaa !13
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.Maths::TVector2", ptr %39, i32 0, i32 1
  %41 = load float, ptr %40, align 4, !tbaa !13
  %42 = fcmp ogt float %38, %41
  %43 = zext i1 %42 to i32
  %44 = icmp ne i32 %35, %43
  br i1 %44, label %45, label %82

45:                                               ; preds = %19
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %"class.Maths::TVector2", ptr %46, i32 0, i32 0
  %48 = load float, ptr %47, align 4, !tbaa !16
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.Maths::TVector2", ptr %49, i32 0, i32 0
  %51 = load float, ptr %50, align 4, !tbaa !16
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.Maths::TVector2", ptr %52, i32 0, i32 0
  %54 = load float, ptr %53, align 4, !tbaa !16
  %55 = fsub float %51, %54
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %"class.Maths::TVector2", ptr %56, i32 0, i32 1
  %58 = load float, ptr %57, align 4, !tbaa !13
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %"class.Maths::TVector2", ptr %59, i32 0, i32 1
  %61 = load float, ptr %60, align 4, !tbaa !13
  %62 = fsub float %58, %61
  %63 = fmul float %55, %62
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = getelementptr inbounds %"class.Maths::TVector2", ptr %64, i32 0, i32 1
  %66 = load float, ptr %65, align 4, !tbaa !13
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %"class.Maths::TVector2", ptr %67, i32 0, i32 1
  %69 = load float, ptr %68, align 4, !tbaa !13
  %70 = fsub float %66, %69
  %71 = fdiv float %63, %70
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %"class.Maths::TVector2", ptr %72, i32 0, i32 0
  %74 = load float, ptr %73, align 4, !tbaa !16
  %75 = fadd float %71, %74
  %76 = fcmp olt float %48, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %45
  %78 = load i8, ptr %7, align 1, !tbaa !11, !range !17, !noundef !18
  %79 = trunc i8 %78 to i1
  %80 = xor i1 %79, true
  %81 = zext i1 %80 to i8
  store i8 %81, ptr %7, align 1, !tbaa !11
  br label %82

82:                                               ; preds = %77, %45, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %8, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %8, align 4, !tbaa !9
  store i32 %84, ptr %9, align 4, !tbaa !9
  br label %14, !llvm.loop !19

86:                                               ; preds = %18
  %87 = load i8, ptr %7, align 1, !tbaa !11, !range !17, !noundef !18
  %88 = trunc i8 %87 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  ret i1 %88
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !15, i64 4}
!14 = !{!"_ZTSN5Maths8TVector2IfEE", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!14, !15, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"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.Maths::TVector2" = type { float, float }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i1 @_ZN7Riemann16PointInPolygon2DERKN5Maths8TVector2IfEEPS3_i(ptr nocapture noundef nonnull readonly align 4 dereferenceable(8) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %5 = add nsw i32 %2, -1
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load float, ptr %6, align 4, !tbaa !5
  %8 = load float, ptr %0, align 4
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %9

._crit_edge:                                      ; preds = %31, %3
  %.0.lcssa = phi i1 [ false, %3 ], [ %.1, %31 ]
  ret i1 %.0.lcssa

9:                                                ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %.025 = phi i1 [ false, %.lr.ph ], [ %.1, %31 ]
  %.02223 = phi i32 [ %5, %.lr.ph ], [ %32, %31 ]
  %10 = getelementptr inbounds %"class.Maths::TVector2", ptr %1, i64 %indvars.iv
  %11 = sext i32 %.02223 to i64
  %12 = getelementptr inbounds %"class.Maths::TVector2", ptr %1, i64 %11
  %13 = getelementptr inbounds i8, ptr %10, i64 4
  %14 = load float, ptr %13, align 4, !tbaa !5
  %15 = fcmp ogt float %14, %7
  %16 = getelementptr inbounds i8, ptr %12, i64 4
  %17 = load float, ptr %16, align 4, !tbaa !5
  %18 = fcmp ule float %17, %7
  %.not = xor i1 %15, %18
  br i1 %.not, label %31, label %19

19:                                               ; preds = %9
  %20 = load float, ptr %12, align 4, !tbaa !10
  %21 = load float, ptr %10, align 4, !tbaa !10
  %22 = fsub float %20, %21
  %23 = fsub float %7, %14
  %24 = fmul float %23, %22
  %25 = fsub float %17, %14
  %26 = fdiv float %24, %25
  %27 = fadd float %21, %26
  %28 = fcmp olt float %8, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %19
  %30 = xor i1 %.025, true
  br label %31

31:                                               ; preds = %29, %19, %9
  %.1 = phi i1 [ %30, %29 ], [ %.025, %19 ], [ %.025, %9 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = trunc nuw nsw i64 %indvars.iv to i32
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %9, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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" }

!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 4}
!6 = !{!"_ZTSN5Maths8TVector2IfEE", !7, i64 0, !7, i64 4}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass