; LLVM IR from greensoftwarelab/Energy-Languages :: C/n-body/nbody.gcc-4 (bodies_energy)

; 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.body = type { [3 x double], double, [3 x 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local double @bodies_energy(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [3 x double], align 16
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %145, %2
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %15, label %148

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

73:                                               ; preds = %141, %15
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = load i32, ptr %4, align 4, !tbaa !9
  %76 = icmp ult i32 %74, %75
  br i1 %76, label %77, label %144

77:                                               ; preds = %73
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %104, %77
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = icmp ult i32 %79, 3
  br i1 %80, label %81, label %107

81:                                               ; preds = %78
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds %struct.body, ptr %82, i64 %84
  %86 = getelementptr inbounds %struct.body, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %10, align 4, !tbaa !9
  %88 = zext i32 %87 to i64
  %89 = getelementptr inbounds [3 x double], ptr %86, i64 0, i64 %88
  %90 = load double, ptr %89, align 8, !tbaa !11
  %91 = load ptr, ptr %3, align 8, !tbaa !5
  %92 = load i32, ptr %9, align 4, !tbaa !9
  %93 = zext i32 %92 to i64
  %94 = getelementptr inbounds %struct.body, ptr %91, i64 %93
  %95 = getelementptr inbounds %struct.body, ptr %94, i32 0, i32 0
  %96 = load i32, ptr %10, align 4, !tbaa !9
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds [3 x double], ptr %95, i64 0, i64 %97
  %99 = load double, ptr %98, align 8, !tbaa !11
  %100 = fsub double %90, %99
  %101 = load i32, ptr %10, align 4, !tbaa !9
  %102 = zext i32 %101 to i64
  %103 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 %102
  store double %100, ptr %103, align 8, !tbaa !11
  br label %104

104:                                              ; preds = %81
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = add i32 %105, 1
  store i32 %106, ptr %10, align 4, !tbaa !9
  br label %78, !llvm.loop !15

107:                                              ; preds = %78
  %108 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 0
  %109 = load double, ptr %108, align 16, !tbaa !11
  %110 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 0
  %111 = load double, ptr %110, align 16, !tbaa !11
  %112 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 1
  %113 = load double, ptr %112, align 8, !tbaa !11
  %114 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 1
  %115 = load double, ptr %114, align 8, !tbaa !11
  %116 = fmul double %113, %115
  %117 = call double @llvm.fmuladd.f64(double %109, double %111, double %116)
  %118 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 2
  %119 = load double, ptr %118, align 16, !tbaa !11
  %120 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 2
  %121 = load double, ptr %120, align 16, !tbaa !11
  %122 = call double @llvm.fmuladd.f64(double %119, double %121, double %117)
  %123 = call double @sqrt(double noundef %122) #4
  store double %123, ptr %6, align 8, !tbaa !11
  %124 = load ptr, ptr %3, align 8, !tbaa !5
  %125 = load i32, ptr %8, align 4, !tbaa !9
  %126 = zext i32 %125 to i64
  %127 = getelementptr inbounds %struct.body, ptr %124, i64 %126
  %128 = getelementptr inbounds %struct.body, ptr %127, i32 0, i32 3
  %129 = load double, ptr %128, align 8, !tbaa !13
  %130 = load ptr, ptr %3, align 8, !tbaa !5
  %131 = load i32, ptr %9, align 4, !tbaa !9
  %132 = zext i32 %131 to i64
  %133 = getelementptr inbounds %struct.body, ptr %130, i64 %132
  %134 = getelementptr inbounds %struct.body, ptr %133, i32 0, i32 3
  %135 = load double, ptr %134, align 8, !tbaa !13
  %136 = fmul double %129, %135
  %137 = load double, ptr %6, align 8, !tbaa !11
  %138 = fdiv double %136, %137
  %139 = load double, ptr %7, align 8, !tbaa !11
  %140 = fsub double %139, %138
  store double %140, ptr %7, align 8, !tbaa !11
  br label %141

141:                                              ; preds = %107
  %142 = load i32, ptr %9, align 4, !tbaa !9
  %143 = add i32 %142, 1
  store i32 %143, ptr %9, align 4, !tbaa !9
  br label %73, !llvm.loop !17

144:                                              ; preds = %73
  br label %145

145:                                              ; preds = %144
  %146 = load i32, ptr %8, align 4, !tbaa !9
  %147 = add i32 %146, 1
  store i32 %147, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !18

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

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 "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 = !{!"any pointer", !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 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 56}
!14 = !{!"body", !7, i64 0, !12, i64 24, !7, i64 32, !12, i64 56}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


; 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.body = type { [3 x double], double, [3 x 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 @bodies_energy(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = zext i32 %1 to i64
  br label %4

.loopexit:                                        ; preds = %.preheader, %4
  %.1.lcssa = phi double [ %19, %4 ], [ %39, %.preheader ]
  %exitcond49.not = icmp eq i64 %indvars.iv.next, %3
  br i1 %exitcond49.not, label %._crit_edge, label %4, !llvm.loop !5

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

.preheader.lr.ph:                                 ; preds = %4
  %21 = trunc nuw i64 %indvars.iv.next to i32
  %.pre = load double, ptr %5, align 8, !tbaa !12
  %.phi.trans.insert = getelementptr inbounds i8, ptr %5, i64 8
  %.pre50 = load double, ptr %.phi.trans.insert, align 8, !tbaa !12
  %.phi.trans.insert51 = getelementptr inbounds i8, ptr %5, i64 16
  %.pre52 = load double, ptr %.phi.trans.insert51, align 8, !tbaa !12
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.03743 = phi i32 [ %21, %.preheader.lr.ph ], [ %40, %.preheader ]
  %.142 = phi double [ %19, %.preheader.lr.ph ], [ %39, %.preheader ]
  %22 = zext i32 %.03743 to i64
  %23 = getelementptr inbounds %struct.body, ptr %0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !12
  %25 = fsub double %.pre, %24
  %26 = getelementptr inbounds i8, ptr %23, i64 8
  %27 = load double, ptr %26, align 8, !tbaa !12
  %28 = fsub double %.pre50, %27
  %29 = getelementptr inbounds i8, ptr %23, i64 16
  %30 = load double, ptr %29, align 8, !tbaa !12
  %31 = fsub double %.pre52, %30
  %32 = fmul double %28, %28
  %33 = tail call double @llvm.fmuladd.f64(double %25, double %25, double %32)
  %34 = tail call double @llvm.fmuladd.f64(double %31, double %31, double %33)
  %sqrt = tail call double @llvm.sqrt.f64(double %34)
  %35 = getelementptr inbounds %struct.body, ptr %0, i64 %22, i32 3
  %36 = load double, ptr %35, align 8, !tbaa !7
  %37 = fmul double %7, %36
  %38 = fdiv double %37, %sqrt
  %39 = fsub double %.142, %38
  %40 = add nuw i32 %.03743, 1
  %exitcond.not = icmp eq i32 %40, %1
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !13

._crit_edge:                                      ; preds = %.loopexit, %2
  %.039.lcssa = phi double [ 0.000000e+00, %2 ], [ %.1.lcssa, %.loopexit ]
  ret double %.039.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, !11, i64 56}
!8 = !{!"body", !9, i64 0, !11, i64 24, !9, i64 32, !11, i64 56}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"double", !9, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !6}


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