; LLVM IR from Wodnerstruck/CPP-Quantum-Chemistry-Practice :: Project1-Molecular-Geometry-Analysis/src/molecule.ll (ZN8Molecule9translateEddd)

; 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.Molecule = type { i32, i32, ptr, ptr }

; 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 void @_ZN8Molecule9translateEddd(ptr noundef nonnull align 8 dereferenceable(24) %0, double noundef %1, double noundef %2, double noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  store double %3, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %48, %4
  %12 = load i32, ptr %9, align 4, !tbaa !11
  %13 = getelementptr inbounds %class.Molecule, ptr %10, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %51

17:                                               ; preds = %11
  %18 = load double, ptr %6, align 8, !tbaa !9
  %19 = getelementptr inbounds %class.Molecule, ptr %10, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load i32, ptr %9, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %24, i64 0
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = fadd double %26, %18
  store double %27, ptr %25, align 8, !tbaa !9
  %28 = load double, ptr %7, align 8, !tbaa !9
  %29 = getelementptr inbounds %class.Molecule, ptr %10, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load i32, ptr %9, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds ptr, ptr %30, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %34, i64 1
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = fadd double %36, %28
  store double %37, ptr %35, align 8, !tbaa !9
  %38 = load double, ptr %8, align 8, !tbaa !9
  %39 = getelementptr inbounds %class.Molecule, ptr %10, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %9, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds double, ptr %44, i64 2
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = fadd double %46, %38
  store double %47, ptr %45, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %17
  %49 = load i32, ptr %9, align 4, !tbaa !11
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %9, align 4, !tbaa !11
  br label %11, !llvm.loop !16

51:                                               ; preds = %16
  ret void
}

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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS8Molecule", !12, i64 0, !12, i64 4, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN8Molecule9translateEddd(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, double noundef %1, double noundef %2, double noundef %3) local_unnamed_addr #0 align 2 {
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %wide.trip.count = zext nneg i32 %5 to i64
  %9 = insertelement <2 x double> poison, double %1, i64 0
  %10 = insertelement <2 x double> %9, double %2, i64 1
  %xtraiter = and i64 %wide.trip.count, 1
  %11 = icmp eq i32 %5, 1
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %19

._crit_edge.loopexit.unr-lcssa:                   ; preds = %19, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %19 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %12 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv.unr
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = load <2 x double>, ptr %13, align 8, !tbaa !13
  %15 = fadd <2 x double> %14, %10
  store <2 x double> %15, ptr %13, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %13, i64 16
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = fadd double %17, %3
  store double %18, ptr %16, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %4
  ret void

19:                                               ; preds = %19, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %19 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %19 ]
  %20 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = load <2 x double>, ptr %21, align 8, !tbaa !13
  %23 = fadd <2 x double> %22, %10
  store <2 x double> %23, ptr %21, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %21, i64 16
  %25 = load double, ptr %24, align 8, !tbaa !13
  %26 = fadd double %25, %3
  store double %26, ptr %24, align 8, !tbaa !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %27 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv.next
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = load <2 x double>, ptr %28, align 8, !tbaa !13
  %30 = fadd <2 x double> %29, %10
  store <2 x double> %30, ptr %28, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %28, i64 16
  %32 = load double, ptr %31, align 8, !tbaa !13
  %33 = fadd double %32, %3
  store double %33, ptr %31, align 8, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %19, !llvm.loop !15
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 0}
!6 = !{!"_ZTS8Molecule", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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