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

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

7:                                                ; preds = %45, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp ult i32 %8, %9
  br i1 %10, label %11, label %48

11:                                               ; preds = %7
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %41, %11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp ult i32 %13, 3
  br i1 %14, label %15, label %44

15:                                               ; preds = %12
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i32, ptr %5, 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 2
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [3 x double], ptr %20, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds %struct.body, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.body, ptr %28, i32 0, i32 3
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = fmul double %24, %30
  %32 = fdiv double %31, 0x4043BD3CC9BE45DE
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.body, ptr %33, i64 0
  %35 = getelementptr inbounds %struct.body, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [3 x double], ptr %35, i64 0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = fsub double %39, %32
  store double %40, ptr %38, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %15
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !15

44:                                               ; preds = %12
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = add i32 %46, 1
  store i32 %47, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !17

48:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @offset_momentum(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %wide.trip.count = zext i32 %1 to i64
  %4 = load <2 x double>, ptr %3, align 8, !tbaa !5
  %.phi.trans.insert17 = getelementptr inbounds i8, ptr %0, i64 48
  %.pre18 = load double, ptr %.phi.trans.insert17, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %5 = phi double [ %.pre18, %.preheader.lr.ph ], [ %21, %.preheader ]
  %indvars.iv = phi i64 [ 0, %.preheader.lr.ph ], [ %indvars.iv.next, %.preheader ]
  %6 = phi <2 x double> [ %4, %.preheader.lr.ph ], [ %16, %.preheader ]
  %7 = getelementptr inbounds %struct.body, ptr %0, i64 %indvars.iv
  %8 = getelementptr inbounds i8, ptr %7, i64 32
  %9 = getelementptr inbounds i8, ptr %7, i64 56
  %10 = load double, ptr %9, align 8, !tbaa !9
  %11 = load <2 x double>, ptr %8, align 8, !tbaa !5
  %12 = insertelement <2 x double> poison, double %10, i64 0
  %13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> zeroinitializer
  %14 = fmul <2 x double> %11, %13
  %15 = fdiv <2 x double> %14, <double 0x4043BD3CC9BE45DE, double 0x4043BD3CC9BE45DE>
  %16 = fsub <2 x double> %6, %15
  store <2 x double> %16, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %7, i64 48
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fmul double %18, %10
  %20 = fdiv double %19, 0x4043BD3CC9BE45DE
  %21 = fsub double %5, %20
  store double %21, ptr %.phi.trans.insert17, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !11

._crit_edge:                                      ; preds = %.preheader, %2
  ret void
}

attributes #0 = { 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" }

!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, !6, i64 56}
!10 = !{!"body", !7, i64 0, !6, i64 24, !7, i64 32, !6, i64 56}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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