; LLVM IR from alexzheng42/sDMD :: src (ToolFunctions)

; 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.AtomStr = type { ptr, ptr }
%struct.DynamicStr = type { [4 x i32], [4 x double], [4 x double], %struct.HBStr, %struct.HBNeighborStr, %struct.InteractionEventStr }
%struct.HBStr = type { i32, i32, i8, i32 }
%struct.HBNeighborStr = type { [5 x i32], i32, i32 }
%struct.InteractionEventStr = type { i32, i64, i64, double, double, i32, i32 }

@atomnum = external global i32, align 4
@atom = external global ptr, 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: nounwind uwtable
define dso_local void @UpdateData(double noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca i32, align 4
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %70, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = load i32, ptr @atomnum, align 4, !tbaa !9
  %7 = icmp sle i32 %5, %6
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %73

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

70:                                               ; preds = %9
  %71 = load i32, ptr %3, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !15

73:                                               ; preds = %8
  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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"AtomStr", !12, i64 0, !12, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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.AtomStr = type { ptr, ptr }

@atomnum = external local_unnamed_addr global i32, align 4
@atom = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @UpdateData(double noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @atomnum, align 4, !tbaa !5
  %.not10 = icmp slt i32 %2, 1
  br i1 %.not10, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %3 = load ptr, ptr @atom, align 8, !tbaa !9
  %4 = insertelement <2 x double> poison, double %0, i64 0
  %5 = shufflevector <2 x double> %4, <2 x double> poison, <2 x i32> zeroinitializer
  %6 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %6, 1
  %7 = icmp eq i32 %2, 1
  br i1 %7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %6, 2147483646
  br label %20

._crit_edge.loopexit.unr-lcssa:                   ; preds = %20, %.lr.ph
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.1, %20 ]
  %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
  %8 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv.unr, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %9, i64 56
  %11 = getelementptr inbounds i8, ptr %9, i64 24
  %12 = load <2 x double>, ptr %10, align 8, !tbaa !13
  %13 = load <2 x double>, ptr %11, align 8, !tbaa !13
  %14 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %12, <2 x double> %5, <2 x double> %13)
  store <2 x double> %14, ptr %11, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %9, i64 72
  %16 = load double, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %9, i64 40
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = tail call double @llvm.fmuladd.f64(double %16, double %0, double %18)
  store double %19, ptr %17, align 8, !tbaa !13
  br label %._crit_edge

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

20:                                               ; preds = %20, %.lr.ph.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %20 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %20 ]
  %21 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %22, i64 56
  %24 = getelementptr inbounds i8, ptr %22, i64 24
  %25 = load <2 x double>, ptr %23, align 8, !tbaa !13
  %26 = load <2 x double>, ptr %24, align 8, !tbaa !13
  %27 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %5, <2 x double> %26)
  store <2 x double> %27, ptr %24, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %22, i64 72
  %29 = load double, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %22, i64 40
  %31 = load double, ptr %30, align 8, !tbaa !13
  %32 = tail call double @llvm.fmuladd.f64(double %29, double %0, double %31)
  store double %32, ptr %30, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = getelementptr inbounds %struct.AtomStr, ptr %3, i64 %indvars.iv.next, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %34, i64 56
  %36 = getelementptr inbounds i8, ptr %34, i64 24
  %37 = load <2 x double>, ptr %35, align 8, !tbaa !13
  %38 = load <2 x double>, ptr %36, align 8, !tbaa !13
  %39 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %37, <2 x double> %5, <2 x double> %38)
  store <2 x double> %39, ptr %36, align 8, !tbaa !13
  %40 = getelementptr inbounds i8, ptr %34, i64 72
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = getelementptr inbounds i8, ptr %34, i64 40
  %43 = load double, ptr %42, align 8, !tbaa !13
  %44 = tail call double @llvm.fmuladd.f64(double %41, double %0, double %43)
  store double %44, ptr %42, 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 %20, !llvm.loop !15
}

; 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(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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"AtomStr", !10, i64 0, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, 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,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass