; LLVM IR from Lut1n/ImpGears :: src/ImpGears/Geometry/Path.ll (ZNK3imp4Path13windingNumberEv)

; 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.imp::Vec3" = type { %"class.imp::Vec.base", [4 x i8] }
%"class.imp::Vec.base" = type <{ %"class.imp::Object", [3 x float] }>
%"class.imp::Object" = type { ptr, %"class.std::shared_ptr" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

@_ZN3imp4Vec31ZE = external global %"class.imp::Vec3", align 8

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3imp4Vec3C2ERKS0_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef nonnull align 8 dereferenceable(36)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3imp4Path5countEv(ptr noundef nonnull align 8 dereferenceable(48)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3imp4Path3tanEi(ptr dead_on_unwind noalias writable sret(%"class.imp::Vec3") align 8, ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN3imp4Vec39angleFromES0_S0_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef, ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK3imp4Path13windingNumberEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.imp::Vec3", align 8
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  %6 = alloca %"class.imp::Vec3", align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca %"class.imp::Vec3", align 8
  %10 = alloca %"class.imp::Vec3", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr %3) #4
  call void @_ZN3imp4Vec3C2ERKS0_(ptr noundef nonnull align 8 dereferenceable(36) %3, ptr noundef nonnull align 8 dereferenceable(36) @_ZN3imp4Vec31ZE) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store float 0.000000e+00, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %27, %1
  %13 = load i32, ptr %5, align 4, !tbaa !11
  %14 = call noundef i32 @_ZNK3imp4Path5countEv(ptr noundef nonnull align 8 dereferenceable(48) %11)
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %44

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #4
  %18 = load i32, ptr %5, align 4, !tbaa !11
  invoke void @_ZNK3imp4Path3tanEi(ptr dead_on_unwind writable sret(%"class.imp::Vec3") align 8 %6, ptr noundef nonnull align 8 dereferenceable(48) %11, i32 noundef %18)
          to label %19 unwind label %30

19:                                               ; preds = %17
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %21 = sub nsw i32 %20, 1
  invoke void @_ZNK3imp4Path3tanEi(ptr dead_on_unwind writable sret(%"class.imp::Vec3") align 8 %9, ptr noundef nonnull align 8 dereferenceable(48) %11, i32 noundef %21)
          to label %22 unwind label %34

22:                                               ; preds = %19
  call void @_ZN3imp4Vec3C2ERKS0_(ptr noundef nonnull align 8 dereferenceable(36) %10, ptr noundef nonnull align 8 dereferenceable(36) %3) #4
  %23 = invoke noundef float @_ZN3imp4Vec39angleFromES0_S0_(ptr noundef nonnull align 8 dereferenceable(36) %6, ptr noundef %9, ptr noundef %10)
          to label %24 unwind label %38

24:                                               ; preds = %22
  %25 = load float, ptr %4, align 4, !tbaa !9
  %26 = fadd float %25, %23
  store float %26, ptr %4, align 4, !tbaa !9
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %10) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %9) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %6) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #4
  br label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !11
  br label %12, !llvm.loop !13

30:                                               ; preds = %17
  %31 = landingpad { ptr, i32 }
          cleanup
  %32 = extractvalue { ptr, i32 } %31, 0
  store ptr %32, ptr %7, align 8
  %33 = extractvalue { ptr, i32 } %31, 1
  store i32 %33, ptr %8, align 4
  br label %43

34:                                               ; preds = %19
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %7, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %8, align 4
  br label %42

38:                                               ; preds = %22
  %39 = landingpad { ptr, i32 }
          cleanup
  %40 = extractvalue { ptr, i32 } %39, 0
  store ptr %40, ptr %7, align 8
  %41 = extractvalue { ptr, i32 } %39, 1
  store i32 %41, ptr %8, align 4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %10) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %9) #4
  br label %42

42:                                               ; preds = %38, %34
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %6) #4
  br label %43

43:                                               ; preds = %42, %30
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %3) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #4
  br label %49

44:                                               ; preds = %16
  %45 = load float, ptr %4, align 4, !tbaa !9
  %46 = fpext float %45 to double
  %47 = fdiv double %46, 0x401921FAFC8B007A
  %48 = fptosi double %47 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %3) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %3) #4
  ret i32 %48

49:                                               ; preds = %43
  %50 = load ptr, ptr %7, align 8
  %51 = load i32, ptr %8, align 4
  %52 = insertvalue { ptr, i32 } poison, ptr %50, 0
  %53 = insertvalue { ptr, i32 } %52, i32 %51, 1
  resume { ptr, i32 } %53
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!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"

%"class.imp::Vec3" = type { %"class.imp::Vec.base", [4 x i8] }
%"class.imp::Vec.base" = type <{ %"class.imp::Object", [3 x float] }>
%"class.imp::Object" = type { ptr, %"class.std::shared_ptr" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

@_ZN3imp4Vec31ZE = external global %"class.imp::Vec3", align 8

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3imp4Vec3C2ERKS0_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef nonnull align 8 dereferenceable(36)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3imp4Path5countEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK3imp4Path3tanEi(ptr dead_on_unwind noalias writable sret(%"class.imp::Vec3") align 8, ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZN3imp4Vec39angleFromES0_S0_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef, ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK3imp4Path13windingNumberEv(ptr noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.imp::Vec3", align 8
  %3 = alloca %"class.imp::Vec3", align 8
  %4 = alloca %"class.imp::Vec3", align 8
  %5 = alloca %"class.imp::Vec3", align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #4
  call void @_ZN3imp4Vec3C2ERKS0_(ptr noundef nonnull align 8 dereferenceable(36) %2, ptr noundef nonnull align 8 dereferenceable(36) @_ZN3imp4Vec31ZE) #4
  %6 = call noundef i32 @_ZNK3imp4Path5countEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %15
  %8 = fpext float %16 to double
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.011.lcssa = phi double [ 0.000000e+00, %1 ], [ %8, %._crit_edge.loopexit ]
  %9 = fdiv double %.011.lcssa, 0x401921FAFC8B007A
  %10 = fptosi double %9 to i32
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %2) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #4
  ret i32 %10

.lr.ph:                                           ; preds = %1, %15
  %.01018 = phi i32 [ %17, %15 ], [ 0, %1 ]
  %.01117 = phi float [ %16, %15 ], [ 0.000000e+00, %1 ]
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  invoke void @_ZNK3imp4Path3tanEi(ptr dead_on_unwind nonnull writable sret(%"class.imp::Vec3") align 8 %3, ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %.01018)
          to label %11 unwind label %20

11:                                               ; preds = %.lr.ph
  %12 = add nsw i32 %.01018, -1
  invoke void @_ZNK3imp4Path3tanEi(ptr dead_on_unwind nonnull writable sret(%"class.imp::Vec3") align 8 %4, ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %12)
          to label %13 unwind label %22

13:                                               ; preds = %11
  call void @_ZN3imp4Vec3C2ERKS0_(ptr noundef nonnull align 8 dereferenceable(36) %5, ptr noundef nonnull align 8 dereferenceable(36) %2) #4
  %14 = invoke noundef float @_ZN3imp4Vec39angleFromES0_S0_(ptr noundef nonnull align 8 dereferenceable(36) %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
          to label %15 unwind label %24

15:                                               ; preds = %13
  %16 = fadd float %.01117, %14
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %5) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %4) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %3) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  %17 = add nuw nsw i32 %.01018, 1
  %18 = call noundef i32 @_ZNK3imp4Path5countEv(ptr noundef nonnull align 8 dereferenceable(48) %0)
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !5

20:                                               ; preds = %.lr.ph
  %21 = landingpad { ptr, i32 }
          cleanup
  br label %27

22:                                               ; preds = %11
  %23 = landingpad { ptr, i32 }
          cleanup
  br label %26

24:                                               ; preds = %13
  %25 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %5) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %4) #4
  br label %26

26:                                               ; preds = %24, %22
  %.pn = phi { ptr, i32 } [ %25, %24 ], [ %23, %22 ]
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %3) #4
  br label %27

27:                                               ; preds = %26, %20
  %.pn.pn = phi { ptr, i32 } [ %.pn, %26 ], [ %21, %20 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  call void @_ZN3imp6ObjectD2Ev(ptr noundef nonnull align 8 dereferenceable(36) %2) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #4
  resume { ptr, i32 } %.pn.pn
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #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: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass