; LLVM IR from ShahjalalShohag/code-library :: Geometry/Geometry 3D.ll (Z33area_on_the_surface_of_the_spheredSt6vectorI2p3SaIS0_EE)

; 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.p3 = type { double, double, double }

@_ZL2PI = external hidden global double, align 8

; 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
declare dso_local void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI2p3SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z24oriented_angle_on_sphere2p3S_S_(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z33area_on_the_surface_of_the_spheredSt6vectorI2p3SaIS0_EE(double noundef %0, ptr noundef %1) #2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.p3, align 8
  %9 = alloca %struct.p3, align 8
  %10 = alloca %struct.p3, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %11 = call noundef i64 @_ZNKSt6vectorI2p3SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #3
  %12 = trunc i64 %11 to i32
  store i32 %12, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load i32, ptr %5, align 4, !tbaa !11
  %14 = sub nsw i32 %13, 2
  %15 = sub nsw i32 0, %14
  %16 = sitofp i32 %15 to double
  %17 = load double, ptr @_ZL2PI, align 8, !tbaa !5
  %18 = fmul double %16, %17
  store double %18, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %43, %2
  %20 = load i32, ptr %7, align 4, !tbaa !11
  %21 = load i32, ptr %5, align 4, !tbaa !11
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %46

24:                                               ; preds = %19
  %25 = load i32, ptr %7, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr %5, align 4, !tbaa !11
  %28 = srem i32 %26, %27
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %29) #3
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %8, ptr noundef nonnull align 8 dereferenceable(24) %30)
  %31 = load i32, ptr %7, align 4, !tbaa !11
  %32 = add nsw i32 %31, 2
  %33 = load i32, ptr %5, align 4, !tbaa !11
  %34 = srem i32 %32, %33
  %35 = sext i32 %34 to i64
  %36 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %35) #3
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %9, ptr noundef nonnull align 8 dereferenceable(24) %36)
  %37 = load i32, ptr %7, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %38) #3
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %10, ptr noundef nonnull align 8 dereferenceable(24) %39)
  %40 = call noundef double @_Z24oriented_angle_on_sphere2p3S_S_(ptr noundef %8, ptr noundef %9, ptr noundef %10)
  %41 = load double, ptr %6, align 8, !tbaa !5
  %42 = fadd double %41, %40
  store double %42, ptr %6, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %24
  %44 = load i32, ptr %7, align 4, !tbaa !11
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %7, align 4, !tbaa !11
  br label %19, !llvm.loop !13

46:                                               ; preds = %23
  %47 = load double, ptr %3, align 8, !tbaa !5
  %48 = load double, ptr %3, align 8, !tbaa !5
  %49 = fmul double %47, %48
  %50 = load double, ptr %6, align 8, !tbaa !5
  %51 = fmul double %49, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret double %51
}

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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

%struct.p3 = type { double, double, double }

@_ZL2PI = external hidden local_unnamed_addr global double, align 8

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI2p3SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_Z24oriented_angle_on_sphere2p3S_S_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z33area_on_the_surface_of_the_spheredSt6vectorI2p3SaIS0_EE(double noundef %0, ptr noundef nonnull %1) local_unnamed_addr #1 {
  %3 = alloca %struct.p3, align 8
  %4 = alloca %struct.p3, align 8
  %5 = alloca %struct.p3, align 8
  %6 = tail call noundef i64 @_ZNKSt6vectorI2p3SaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %1) #2
  %7 = trunc i64 %6 to i32
  %8 = sub nsw i32 2, %7
  %9 = sitofp i32 %8 to double
  %10 = load double, ptr @_ZL2PI, align 8, !tbaa !5
  %11 = fmul double %10, %9
  %12 = icmp sgt i32 %7, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %13 = and i64 %6, 2147483647
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.012.lcssa = phi double [ %11, %2 ], [ %27, %.lr.ph ]
  %14 = fmul double %0, %0
  %15 = fmul double %14, %.012.lcssa
  ret double %15

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.01214 = phi double [ %11, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = icmp eq i64 %indvars.iv.next, %13
  %17 = and i64 %indvars.iv.next, 4294967295
  %18 = select i1 %16, i64 0, i64 %17
  %19 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %18) #2
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 8 dereferenceable(24) %19)
  %20 = trunc i64 %indvars.iv to i32
  %21 = add i32 %20, 2
  %22 = urem i32 %21, %7
  %23 = zext nneg i32 %22 to i64
  %24 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %23) #2
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %24)
  %25 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI2p3SaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef %indvars.iv) #2
  call void @_ZN2p3C2ERKS_(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef nonnull align 8 dereferenceable(24) %25)
  %26 = call noundef double @_Z24oriented_angle_on_sphere2p3S_S_(ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %27 = fadd double %.01214, %26
  %exitcond.not = icmp eq i64 %indvars.iv.next, %13
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

attributes #0 = { 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 #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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass