; 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: nounwind
declare double @sqrt(double noundef) #1

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

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

14:                                               ; preds = %107, %2
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %110

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

52:                                               ; preds = %103, %18
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %106

56:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %57 = load ptr, ptr %4, align 8, !tbaa !9
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %struct.planet, ptr %57, i64 %59
  store ptr %60, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %61 = load ptr, ptr %8, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.planet, ptr %61, i32 0, i32 0
  %63 = load double, ptr %62, align 8, !tbaa !18
  %64 = load ptr, ptr %9, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.planet, ptr %64, i32 0, i32 0
  %66 = load double, ptr %65, align 8, !tbaa !18
  %67 = fsub double %63, %66
  store double %67, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.planet, ptr %68, i32 0, i32 1
  %70 = load double, ptr %69, align 8, !tbaa !19
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.planet, ptr %71, i32 0, i32 1
  %73 = load double, ptr %72, align 8, !tbaa !19
  %74 = fsub double %70, %73
  store double %74, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %75 = load ptr, ptr %8, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.planet, ptr %75, i32 0, i32 2
  %77 = load double, ptr %76, align 8, !tbaa !20
  %78 = load ptr, ptr %9, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.planet, ptr %78, i32 0, i32 2
  %80 = load double, ptr %79, align 8, !tbaa !20
  %81 = fsub double %77, %80
  store double %81, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %82 = load double, ptr %10, align 8, !tbaa !11
  %83 = load double, ptr %10, align 8, !tbaa !11
  %84 = load double, ptr %11, align 8, !tbaa !11
  %85 = load double, ptr %11, align 8, !tbaa !11
  %86 = fmul double %84, %85
  %87 = call double @llvm.fmuladd.f64(double %82, double %83, double %86)
  %88 = load double, ptr %12, align 8, !tbaa !11
  %89 = load double, ptr %12, align 8, !tbaa !11
  %90 = call double @llvm.fmuladd.f64(double %88, double %89, double %87)
  %91 = call double @sqrt(double noundef %90) #4
  store double %91, ptr %13, align 8, !tbaa !11
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.planet, ptr %92, i32 0, i32 6
  %94 = load double, ptr %93, align 8, !tbaa !13
  %95 = load ptr, ptr %9, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.planet, ptr %95, i32 0, i32 6
  %97 = load double, ptr %96, align 8, !tbaa !13
  %98 = fmul double %94, %97
  %99 = load double, ptr %13, align 8, !tbaa !11
  %100 = fdiv double %98, %99
  %101 = load double, ptr %5, align 8, !tbaa !11
  %102 = fsub double %101, %100
  store double %102, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %103

103:                                              ; preds = %56
  %104 = load i32, ptr %7, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %7, align 4, !tbaa !5
  br label %52, !llvm.loop !21

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

107:                                              ; preds = %106
  %108 = load i32, ptr %6, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %6, align 4, !tbaa !5
  br label %14, !llvm.loop !23

110:                                              ; preds = %14
  %111 = load double, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret double %111
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 #4 = { 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 48}
!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 24}
!16 = !{!14, !12, i64 32}
!17 = !{!14, !12, i64 40}
!18 = !{!14, !12, i64 0}
!19 = !{!14, !12, i64 8}
!20 = !{!14, !12, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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: read) uwtable
define dso_local double @energy(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = icmp sgt i32 %0, 0
  br i1 %3, label %.lr.ph42.preheader, label %._crit_edge

.lr.ph42.preheader:                               ; preds = %2
  %4 = zext nneg i32 %0 to i64
  %wide.trip.count50 = zext nneg i32 %0 to i64
  br label %.lr.ph42

.loopexit:                                        ; preds = %25, %.lr.ph42
  %.1.lcssa = phi double [ %18, %.lr.ph42 ], [ %42, %25 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond51.not = icmp eq i64 %indvars.iv.next48, %wide.trip.count50
  br i1 %exitcond51.not, label %._crit_edge, label %.lr.ph42, !llvm.loop !5

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %.loopexit
  %indvars.iv47 = phi i64 [ 0, %.lr.ph42.preheader ], [ %indvars.iv.next48, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph42.preheader ], [ %indvars.iv.next, %.loopexit ]
  %.041 = phi double [ 0.000000e+00, %.lr.ph42.preheader ], [ %.1.lcssa, %.loopexit ]
  %5 = getelementptr inbounds %struct.planet, ptr %1, i64 %indvars.iv47
  %6 = getelementptr inbounds i8, ptr %5, i64 48
  %7 = load double, ptr %6, align 8, !tbaa !7
  %8 = fmul double %7, 5.000000e-01
  %9 = getelementptr inbounds i8, ptr %5, i64 24
  %10 = load double, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %5, i64 32
  %12 = load double, ptr %11, align 8, !tbaa !13
  %13 = fmul double %12, %12
  %14 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %13)
  %15 = getelementptr inbounds i8, ptr %5, i64 40
  %16 = load double, ptr %15, align 8, !tbaa !14
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %14)
  %18 = tail call double @llvm.fmuladd.f64(double %8, double %17, double %.041)
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %19 = icmp ult i64 %indvars.iv.next48, %4
  br i1 %19, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph42
  %20 = load double, ptr %5, align 8, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %5, i64 8
  %22 = load double, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %5, i64 16
  %24 = load double, ptr %23, align 8, !tbaa !17
  br label %25

25:                                               ; preds = %.lr.ph, %25
  %indvars.iv44 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next45, %25 ]
  %.139 = phi double [ %18, %.lr.ph ], [ %42, %25 ]
  %26 = getelementptr inbounds %struct.planet, ptr %1, i64 %indvars.iv44
  %27 = load double, ptr %26, align 8, !tbaa !15
  %28 = fsub double %20, %27
  %29 = getelementptr inbounds i8, ptr %26, i64 8
  %30 = load double, ptr %29, align 8, !tbaa !16
  %31 = fsub double %22, %30
  %32 = getelementptr inbounds i8, ptr %26, i64 16
  %33 = load double, ptr %32, align 8, !tbaa !17
  %34 = fsub double %24, %33
  %35 = fmul double %31, %31
  %36 = tail call double @llvm.fmuladd.f64(double %28, double %28, double %35)
  %37 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %36)
  %sqrt = tail call double @llvm.sqrt.f64(double %37)
  %38 = getelementptr inbounds i8, ptr %26, i64 48
  %39 = load double, ptr %38, align 8, !tbaa !7
  %40 = fmul double %7, %39
  %41 = fdiv double %40, %sqrt
  %42 = fsub double %.139, %41
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count50
  br i1 %exitcond.not, label %.loopexit, label %25, !llvm.loop !18

._crit_edge:                                      ; preds = %.loopexit, %2
  %.0.lcssa = phi double [ 0.000000e+00, %2 ], [ %.1.lcssa, %.loopexit ]
  ret double %.0.lcssa
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: read) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !9, i64 48}
!8 = !{!"planet", !9, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !9, i64 32, !9, i64 40, !9, i64 48}
!9 = !{!"double", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!8, !9, i64 24}
!13 = !{!8, !9, i64 32}
!14 = !{!8, !9, i64 40}
!15 = !{!8, !9, i64 0}
!16 = !{!8, !9, i64 8}
!17 = !{!8, !9, i64 16}
!18 = distinct !{!18, !6}


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