; LLVM IR from microsoft/LightAIMD :: src (molecule)

; 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.molecule = type { i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr }
%struct.vec3d = type { double, double, double }

; 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: nounwind uwtable
define dso_local void @center_of_charge(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %75, %2
  %11 = load i64, ptr %9, align 8, !tbaa !11
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.molecule, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp ult i64 %11, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %78

17:                                               ; preds = %10
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.molecule, ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load i64, ptr %9, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.vec3d, ptr %20, i64 %21
  %23 = getelementptr inbounds %struct.vec3d, ptr %22, i32 0, i32 0
  %24 = load double, ptr %23, align 8, !tbaa !16
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.molecule, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = load i64, ptr %9, align 8, !tbaa !11
  %29 = getelementptr inbounds i64, ptr %27, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = uitofp i64 %30 to double
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = call double @llvm.fmuladd.f64(double %24, double %31, double %32)
  store double %33, ptr %5, align 8, !tbaa !9
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.molecule, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = load i64, ptr %9, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.vec3d, ptr %36, i64 %37
  %39 = getelementptr inbounds %struct.vec3d, ptr %38, i32 0, i32 1
  %40 = load double, ptr %39, align 8, !tbaa !19
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.molecule, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  %44 = load i64, ptr %9, align 8, !tbaa !11
  %45 = getelementptr inbounds i64, ptr %43, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = uitofp i64 %46 to double
  %48 = load double, ptr %6, align 8, !tbaa !9
  %49 = call double @llvm.fmuladd.f64(double %40, double %47, double %48)
  store double %49, ptr %6, align 8, !tbaa !9
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.molecule, ptr %50, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = load i64, ptr %9, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.vec3d, ptr %52, i64 %53
  %55 = getelementptr inbounds %struct.vec3d, ptr %54, i32 0, i32 2
  %56 = load double, ptr %55, align 8, !tbaa !20
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.molecule, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !18
  %60 = load i64, ptr %9, align 8, !tbaa !11
  %61 = getelementptr inbounds i64, ptr %59, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !11
  %63 = uitofp i64 %62 to double
  %64 = load double, ptr %7, align 8, !tbaa !9
  %65 = call double @llvm.fmuladd.f64(double %56, double %63, double %64)
  store double %65, ptr %7, align 8, !tbaa !9
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.molecule, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !18
  %69 = load i64, ptr %9, align 8, !tbaa !11
  %70 = getelementptr inbounds i64, ptr %68, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !11
  %72 = uitofp i64 %71 to double
  %73 = load double, ptr %8, align 8, !tbaa !9
  %74 = fadd double %73, %72
  store double %74, ptr %8, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %17
  %76 = load i64, ptr %9, align 8, !tbaa !11
  %77 = add i64 %76, 1
  store i64 %77, ptr %9, align 8, !tbaa !11
  br label %10, !llvm.loop !21

78:                                               ; preds = %16
  %79 = load double, ptr %8, align 8, !tbaa !9
  %80 = load double, ptr %5, align 8, !tbaa !9
  %81 = fdiv double %80, %79
  store double %81, ptr %5, align 8, !tbaa !9
  %82 = load double, ptr %8, align 8, !tbaa !9
  %83 = load double, ptr %6, align 8, !tbaa !9
  %84 = fdiv double %83, %82
  store double %84, ptr %6, align 8, !tbaa !9
  %85 = load double, ptr %8, align 8, !tbaa !9
  %86 = load double, ptr %7, align 8, !tbaa !9
  %87 = fdiv double %86, %85
  store double %87, ptr %7, align 8, !tbaa !9
  %88 = load double, ptr %5, align 8, !tbaa !9
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.vec3d, ptr %89, i32 0, i32 0
  store double %88, ptr %90, align 8, !tbaa !16
  %91 = load double, ptr %6, align 8, !tbaa !9
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.vec3d, ptr %92, i32 0, i32 1
  store double %91, ptr %93, align 8, !tbaa !19
  %94 = load double, ptr %7, align 8, !tbaa !9
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.vec3d, ptr %95, i32 0, i32 2
  store double %94, ptr %96, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"molecule", !12, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !12, i64 64, !6, i64 72}
!15 = !{!14, !6, i64 32}
!16 = !{!17, !10, i64 0}
!17 = !{!"vec3d", !10, i64 0, !10, i64 8, !10, i64 16}
!18 = !{!14, !6, i64 16}
!19 = !{!17, !10, i64 8}
!20 = !{!17, !10, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"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.vec3d = type { double, double, double }

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @center_of_charge(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %xtraiter = and i64 %3, 1
  %8 = icmp eq i64 %3, 1
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %3, -2
  br label %27

._crit_edge.loopexit.unr-lcssa:                   ; preds = %27, %.lr.ph
  %.lcssa54.ph = phi <2 x double> [ poison, %.lr.ph ], [ %49, %27 ]
  %.lcssa53.ph = phi double [ poison, %.lr.ph ], [ %52, %27 ]
  %.lcssa.ph = phi double [ poison, %.lr.ph ], [ %53, %27 ]
  %.040.unr = phi i64 [ 0, %.lr.ph ], [ %54, %27 ]
  %.03239.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %53, %27 ]
  %.03338.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %52, %27 ]
  %.unr = phi <2 x double> [ zeroinitializer, %.lr.ph ], [ %49, %27 ]
  %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
  %9 = getelementptr inbounds %struct.vec3d, ptr %5, i64 %.040.unr
  %10 = getelementptr inbounds i64, ptr %7, i64 %.040.unr
  %11 = load i64, ptr %10, align 8, !tbaa !13
  %12 = uitofp i64 %11 to double
  %13 = load <2 x double>, ptr %9, align 8, !tbaa !14
  %14 = insertelement <2 x double> poison, double %12, i64 0
  %15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
  %16 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %13, <2 x double> %15, <2 x double> %.unr)
  %17 = getelementptr inbounds i8, ptr %9, i64 16
  %18 = load double, ptr %17, align 8, !tbaa !16
  %19 = tail call double @llvm.fmuladd.f64(double %18, double %12, double %.03338.unr)
  %20 = fadd double %.03239.unr, %12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %2
  %.033.lcssa = phi double [ 0.000000e+00, %2 ], [ %.lcssa53.ph, %._crit_edge.loopexit.unr-lcssa ], [ %19, %._crit_edge.loopexit.epilog-lcssa ]
  %.032.lcssa = phi double [ 0.000000e+00, %2 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %20, %._crit_edge.loopexit.epilog-lcssa ]
  %21 = phi <2 x double> [ zeroinitializer, %2 ], [ %.lcssa54.ph, %._crit_edge.loopexit.unr-lcssa ], [ %16, %._crit_edge.loopexit.epilog-lcssa ]
  %22 = insertelement <2 x double> poison, double %.032.lcssa, i64 0
  %23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
  %24 = fdiv <2 x double> %21, %23
  %25 = fdiv double %.033.lcssa, %.032.lcssa
  store <2 x double> %24, ptr %1, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %1, i64 16
  store double %25, ptr %26, align 8, !tbaa !16
  ret void

27:                                               ; preds = %27, %.lr.ph.new
  %.040 = phi i64 [ 0, %.lr.ph.new ], [ %54, %27 ]
  %.03239 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %53, %27 ]
  %.03338 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %52, %27 ]
  %28 = phi <2 x double> [ zeroinitializer, %.lr.ph.new ], [ %49, %27 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %27 ]
  %29 = getelementptr inbounds %struct.vec3d, ptr %5, i64 %.040
  %30 = getelementptr inbounds i64, ptr %7, i64 %.040
  %31 = load i64, ptr %30, align 8, !tbaa !13
  %32 = uitofp i64 %31 to double
  %33 = load <2 x double>, ptr %29, align 8, !tbaa !14
  %34 = insertelement <2 x double> poison, double %32, i64 0
  %35 = shufflevector <2 x double> %34, <2 x double> poison, <2 x i32> zeroinitializer
  %36 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %33, <2 x double> %35, <2 x double> %28)
  %37 = getelementptr inbounds i8, ptr %29, i64 16
  %38 = load double, ptr %37, align 8, !tbaa !16
  %39 = tail call double @llvm.fmuladd.f64(double %38, double %32, double %.03338)
  %40 = fadd double %.03239, %32
  %41 = or disjoint i64 %.040, 1
  %42 = getelementptr inbounds %struct.vec3d, ptr %5, i64 %41
  %43 = getelementptr inbounds i64, ptr %7, i64 %41
  %44 = load i64, ptr %43, align 8, !tbaa !13
  %45 = uitofp i64 %44 to double
  %46 = load <2 x double>, ptr %42, align 8, !tbaa !14
  %47 = insertelement <2 x double> poison, double %45, i64 0
  %48 = shufflevector <2 x double> %47, <2 x double> poison, <2 x i32> zeroinitializer
  %49 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %46, <2 x double> %48, <2 x double> %36)
  %50 = getelementptr inbounds i8, ptr %42, i64 16
  %51 = load double, ptr %50, align 8, !tbaa !16
  %52 = tail call double @llvm.fmuladd.f64(double %51, double %45, double %39)
  %53 = fadd double %40, %45
  %54 = add nuw i64 %.040, 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 %27, !llvm.loop !18
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

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

!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 = !{!"molecule", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !10, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 32}
!12 = !{!6, !10, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = !{!17, !15, i64 16}
!17 = !{!"vec3d", !15, i64 0, !15, i64 8, !15, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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