; LLVM IR from kostya/crystal-benchmarks-game :: nbody (nbody)

; 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.planet = type { double, double, double, double, 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

9:                                                ; preds = %56, %2
  %10 = load i32, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %59

13:                                               ; preds = %9
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %struct.planet, ptr %14, i64 %16
  %18 = getelementptr inbounds %struct.planet, ptr %17, i32 0, i32 3
  %19 = load double, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.planet, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.planet, ptr %23, i32 0, i32 6
  %25 = load double, ptr %24, align 8, !tbaa !15
  %26 = load double, ptr %5, align 8, !tbaa !11
  %27 = call double @llvm.fmuladd.f64(double %19, double %25, double %26)
  store double %27, ptr %5, align 8, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.planet, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.planet, ptr %31, i32 0, i32 4
  %33 = load double, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.planet, ptr %34, i64 %36
  %38 = getelementptr inbounds %struct.planet, ptr %37, i32 0, i32 6
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = load double, ptr %6, align 8, !tbaa !11
  %41 = call double @llvm.fmuladd.f64(double %33, double %39, double %40)
  store double %41, ptr %6, align 8, !tbaa !11
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.planet, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.planet, ptr %45, i32 0, i32 5
  %47 = load double, ptr %46, align 8, !tbaa !17
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.planet, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.planet, ptr %51, i32 0, i32 6
  %53 = load double, ptr %52, align 8, !tbaa !15
  %54 = load double, ptr %7, align 8, !tbaa !11
  %55 = call double @llvm.fmuladd.f64(double %47, double %53, double %54)
  store double %55, ptr %7, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %13
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !5
  br label %9, !llvm.loop !18

59:                                               ; preds = %9
  %60 = load double, ptr %5, align 8, !tbaa !11
  %61 = fneg double %60
  %62 = fdiv double %61, 0x4043BD3CC9BE45DE
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.planet, ptr %63, i64 0
  %65 = getelementptr inbounds %struct.planet, ptr %64, i32 0, i32 3
  store double %62, ptr %65, align 8, !tbaa !13
  %66 = load double, ptr %6, align 8, !tbaa !11
  %67 = fneg double %66
  %68 = fdiv double %67, 0x4043BD3CC9BE45DE
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.planet, ptr %69, i64 0
  %71 = getelementptr inbounds %struct.planet, ptr %70, i32 0, i32 4
  store double %68, ptr %71, align 8, !tbaa !16
  %72 = load double, ptr %7, align 8, !tbaa !11
  %73 = fneg double %72
  %74 = fdiv double %73, 0x4043BD3CC9BE45DE
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.planet, ptr %75, i64 0
  %77 = getelementptr inbounds %struct.planet, ptr %76, i32 0, i32 5
  store double %74, ptr %77, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, 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
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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 = !{!"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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"planet", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!15 = !{!14, !12, i64 48}
!16 = !{!14, !12, i64 32}
!17 = !{!14, !12, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"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.planet = type { double, double, double, double, double, double, double }

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @offset_momentum(i32 noundef %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = icmp sgt i32 %0, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %4 = icmp eq i32 %0, 1
  br i1 %4, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

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

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.02328 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %27, %.lr.ph ]
  %5 = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader.new ], [ %24, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %6 = getelementptr inbounds %struct.planet, ptr %1, i64 %indvars.iv
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = getelementptr inbounds i8, ptr %6, i64 48
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = load <2 x double>, ptr %7, align 8, !tbaa !10
  %11 = insertelement <2 x double> poison, double %9, i64 0
  %12 = shufflevector <2 x double> %11, <2 x double> poison, <2 x i32> zeroinitializer
  %13 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %10, <2 x double> %12, <2 x double> %5)
  %14 = getelementptr inbounds i8, ptr %6, i64 40
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = tail call double @llvm.fmuladd.f64(double %15, double %9, double %.02328)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds %struct.planet, ptr %1, i64 %indvars.iv.next
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  %19 = getelementptr inbounds i8, ptr %17, i64 48
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = load <2 x double>, ptr %18, align 8, !tbaa !10
  %22 = insertelement <2 x double> poison, double %20, i64 0
  %23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
  %24 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> %23, <2 x double> %13)
  %25 = getelementptr inbounds i8, ptr %17, i64 40
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = tail call double @llvm.fmuladd.f64(double %26, double %20, double %16)
  %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 %.lr.ph, !llvm.loop !12

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa39.ph = phi <2 x double> [ poison, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.02328.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %27, %.lr.ph ]
  %.unr = phi <2 x double> [ zeroinitializer, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %28 = getelementptr inbounds %struct.planet, ptr %1, i64 %indvars.iv.unr
  %29 = getelementptr inbounds i8, ptr %28, i64 24
  %30 = getelementptr inbounds i8, ptr %28, i64 48
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = load <2 x double>, ptr %29, align 8, !tbaa !10
  %33 = insertelement <2 x double> poison, double %31, i64 0
  %34 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> zeroinitializer
  %35 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %32, <2 x double> %34, <2 x double> %.unr)
  %36 = getelementptr inbounds i8, ptr %28, i64 40
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = tail call double @llvm.fmuladd.f64(double %37, double %31, double %.02328.unr)
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %2
  %.023.lcssa = phi double [ 0.000000e+00, %2 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %38, %.lr.ph.epil ]
  %39 = phi <2 x double> [ zeroinitializer, %2 ], [ %.lcssa39.ph, %._crit_edge.loopexit.unr-lcssa ], [ %35, %.lr.ph.epil ]
  %40 = fdiv <2 x double> %39, <double 0xC043BD3CC9BE45DE, double 0xC043BD3CC9BE45DE>
  %41 = getelementptr inbounds i8, ptr %1, i64 24
  store <2 x double> %40, ptr %41, align 8, !tbaa !10
  %42 = fdiv double %.023.lcssa, 0xC043BD3CC9BE45DE
  %43 = getelementptr inbounds i8, ptr %1, i64 40
  store double %42, ptr %43, align 8, !tbaa !11
  ret void
}

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

!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 48}
!6 = !{!"planet", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 40}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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