; LLVM IR from ange-yaghi/simple-2d-constraint-solver :: src/gravity_force_generator.ll (ZN7atg_scs21GravityForceGenerator5applyEPNS_11SystemStateE)

; 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"

%"class.atg_scs::SystemState" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, double }
%"class.atg_scs::GravityForceGenerator" = type { %"class.atg_scs::ForceGenerator.base", double }
%"class.atg_scs::ForceGenerator.base" = type <{ ptr, i32 }>

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7atg_scs21GravityForceGenerator5applyEPNS_11SystemStateE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %8, i32 0, i32 17
  %10 = load i32, ptr %9, align 8, !tbaa !9
  store i32 %10, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %11

11:                                               ; preds = %35, %2
  %12 = load i32, ptr %6, align 4, !tbaa !13
  %13 = load i32, ptr %5, align 4, !tbaa !13
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %38

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %17, i32 0, i32 16
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load i32, ptr %6, align 4, !tbaa !13
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %19, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !15
  %24 = fneg double %23
  %25 = getelementptr inbounds %"class.atg_scs::GravityForceGenerator", ptr %7, i32 0, i32 1
  %26 = load double, ptr %25, align 8, !tbaa !16
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.atg_scs::SystemState", ptr %27, i32 0, i32 11
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = load i32, ptr %6, align 4, !tbaa !13
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %29, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !15
  %34 = call double @llvm.fmuladd.f64(double %24, double %26, double %33)
  store double %34, ptr %32, align 8, !tbaa !15
  br label %35

35:                                               ; preds = %16
  %36 = load i32, ptr %6, align 4, !tbaa !13
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !13
  br label %11, !llvm.loop !20

38:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  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 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) #1

attributes #0 = { mustprogress 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 136}
!10 = !{!"_ZTSN7atg_scs11SystemStateE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !11, i64 136, !11, i64 140, !12, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 128}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !12, i64 16}
!17 = !{!"_ZTSN7atg_scs21GravityForceGeneratorE", !18, i64 0, !12, i64 16}
!18 = !{!"_ZTSN7atg_scs14ForceGeneratorE", !11, i64 8}
!19 = !{!10, !6, i64 88}
!20 = distinct !{!20, !21}
!21 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN7atg_scs21GravityForceGenerator5applyEPNS_11SystemStateE(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, ptr nocapture noundef readonly %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 136
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 128
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = getelementptr inbounds i8, ptr %1, i64 88
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %4 to i64
  %min.iters.check = icmp ult i32 %4, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %11 = getelementptr inbounds double, ptr %7, i64 %indvars.iv.ph
  %12 = load double, ptr %11, align 8, !tbaa !14
  %13 = fneg double %12
  %14 = load double, ptr %8, align 8, !tbaa !15
  %15 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.ph
  %16 = load double, ptr %15, align 8, !tbaa !14
  %17 = tail call double @llvm.fmuladd.f64(double %13, double %14, double %16)
  store double %17, ptr %15, align 8, !tbaa !14
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %18 = add nsw i64 %wide.trip.count, -1
  %19 = icmp eq i64 %indvars.iv.ph, %18
  br i1 %19, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %20 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep = getelementptr i8, ptr %10, i64 %20
  %scevgep10 = getelementptr i8, ptr %7, i64 %20
  %scevgep11 = getelementptr inbounds i8, ptr %0, i64 24
  %bound0 = icmp ult ptr %10, %scevgep10
  %bound1 = icmp ult ptr %7, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  %bound012 = icmp ult ptr %10, %scevgep11
  %bound113 = icmp ult ptr %8, %scevgep
  %found.conflict14 = and i1 %bound012, %bound113
  %conflict.rdx = or i1 %found.conflict, %found.conflict14
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483644
  %21 = load double, ptr %8, align 8, !tbaa !15, !alias.scope !18
  %broadcast.splatinsert18 = insertelement <2 x double> poison, double %21, i64 0
  %broadcast.splat19 = shufflevector <2 x double> %broadcast.splatinsert18, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %22 = getelementptr inbounds double, ptr %7, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %wide.load = load <2 x double>, ptr %22, align 8, !tbaa !14, !alias.scope !21
  %wide.load15 = load <2 x double>, ptr %23, align 8, !tbaa !14, !alias.scope !21
  %24 = fneg <2 x double> %wide.load
  %25 = fneg <2 x double> %wide.load15
  %26 = getelementptr inbounds double, ptr %10, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load16 = load <2 x double>, ptr %26, align 8, !tbaa !14, !alias.scope !23, !noalias !25
  %wide.load17 = load <2 x double>, ptr %27, align 8, !tbaa !14, !alias.scope !23, !noalias !25
  %28 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %24, <2 x double> %broadcast.splat19, <2 x double> %wide.load16)
  %29 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %broadcast.splat19, <2 x double> %wide.load17)
  store <2 x double> %28, ptr %26, align 8, !tbaa !14, !alias.scope !23, !noalias !25
  store <2 x double> %29, ptr %27, align 8, !tbaa !14, !alias.scope !23, !noalias !25
  %index.next = add nuw i64 %index, 4
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !26

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %2
  ret void

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %31 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  %32 = load double, ptr %31, align 8, !tbaa !14
  %33 = fneg double %32
  %34 = load double, ptr %8, align 8, !tbaa !15
  %35 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %36 = load double, ptr %35, align 8, !tbaa !14
  %37 = tail call double @llvm.fmuladd.f64(double %33, double %34, double %36)
  store double %37, ptr %35, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %38 = getelementptr inbounds double, ptr %7, i64 %indvars.iv.next
  %39 = load double, ptr %38, align 8, !tbaa !14
  %40 = fneg double %39
  %41 = load double, ptr %8, align 8, !tbaa !15
  %42 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next
  %43 = load double, ptr %42, align 8, !tbaa !14
  %44 = tail call double @llvm.fmuladd.f64(double %40, double %41, double %43)
  store double %44, ptr %42, align 8, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge, label %scalar.ph, !llvm.loop !30
}

; 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 = { mustprogress 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, !10, i64 136}
!6 = !{!"_ZTSN7atg_scs11SystemStateE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !10, i64 136, !10, i64 140, !11, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !7, i64 128}
!13 = !{!6, !7, i64 88}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 16}
!16 = !{!"_ZTSN7atg_scs21GravityForceGeneratorE", !17, i64 0, !11, i64 16}
!17 = !{!"_ZTSN7atg_scs14ForceGeneratorE", !10, i64 8}
!18 = !{!19}
!19 = distinct !{!19, !20}
!20 = distinct !{!20, !"LVerDomain"}
!21 = !{!22}
!22 = distinct !{!22, !20}
!23 = !{!24}
!24 = distinct !{!24, !20}
!25 = !{!22, !19}
!26 = distinct !{!26, !27, !28, !29}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!"llvm.loop.isvectorized", i32 1}
!29 = !{!"llvm.loop.unroll.runtime.disable"}
!30 = distinct !{!30, !27, !28}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass