; LLVM IR from introlab/odas :: src/system (particle2particle)

; 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.particles_obj = type { i32, ptr, ptr }

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

15:                                               ; preds = %82, %5
  %16 = load i32, ptr %11, align 4, !tbaa !11
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.particles_obj, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = icmp ult i32 %16, %19
  br i1 %20, label %21, label %85

21:                                               ; preds = %15
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.particles_obj, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = load i32, ptr %11, align 4, !tbaa !11
  %26 = mul i32 %25, 7
  %27 = add i32 %26, 6
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds float, ptr %24, i64 %28
  %30 = load float, ptr %29, align 4, !tbaa !9
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.particles_obj, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load i32, ptr %11, align 4, !tbaa !11
  %35 = mul i32 %34, 7
  %36 = add i32 %35, 0
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds float, ptr %33, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !9
  %40 = load float, ptr %12, align 4, !tbaa !9
  %41 = call float @llvm.fmuladd.f32(float %30, float %39, float %40)
  store float %41, ptr %12, align 4, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.particles_obj, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load i32, ptr %11, align 4, !tbaa !11
  %46 = mul i32 %45, 7
  %47 = add i32 %46, 6
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %44, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.particles_obj, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load i32, ptr %11, align 4, !tbaa !11
  %55 = mul i32 %54, 7
  %56 = add i32 %55, 1
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds float, ptr %53, i64 %57
  %59 = load float, ptr %58, align 4, !tbaa !9
  %60 = load float, ptr %13, align 4, !tbaa !9
  %61 = call float @llvm.fmuladd.f32(float %50, float %59, float %60)
  store float %61, ptr %13, align 4, !tbaa !9
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.particles_obj, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !15
  %65 = load i32, ptr %11, align 4, !tbaa !11
  %66 = mul i32 %65, 7
  %67 = add i32 %66, 6
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds float, ptr %64, i64 %68
  %70 = load float, ptr %69, align 4, !tbaa !9
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.particles_obj, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load i32, ptr %11, align 4, !tbaa !11
  %75 = mul i32 %74, 7
  %76 = add i32 %75, 2
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds float, ptr %73, i64 %77
  %79 = load float, ptr %78, align 4, !tbaa !9
  %80 = load float, ptr %14, align 4, !tbaa !9
  %81 = call float @llvm.fmuladd.f32(float %70, float %79, float %80)
  store float %81, ptr %14, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %21
  %83 = load i32, ptr %11, align 4, !tbaa !11
  %84 = add i32 %83, 1
  store i32 %84, ptr %11, align 4, !tbaa !11
  br label %15, !llvm.loop !16

85:                                               ; preds = %15
  %86 = load float, ptr %12, align 4, !tbaa !9
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  store float %86, ptr %87, align 4, !tbaa !9
  %88 = load float, ptr %13, align 4, !tbaa !9
  %89 = load ptr, ptr %9, align 8, !tbaa !5
  store float %88, ptr %89, align 4, !tbaa !9
  %90 = load float, ptr %14, align 4, !tbaa !9
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  store float %90, ptr %91, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"particles_obj", !12, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @particle2particle_estimate(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %6 = load i32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %wide.trip.count = zext i32 %6 to i64
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %.02427 = phi float [ 0.000000e+00, %.lr.ph ], [ %20, %9 ]
  %10 = phi <2 x float> [ zeroinitializer, %.lr.ph ], [ %33, %9 ]
  %11 = trunc nuw i64 %indvars.iv to i32
  %12 = mul i32 %11, 7
  %13 = add i32 %12, 6
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds float, ptr %8, i64 %14
  %16 = load float, ptr %15, align 4, !tbaa !12
  %17 = zext i32 %12 to i64
  %18 = getelementptr inbounds float, ptr %8, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !12
  %20 = tail call float @llvm.fmuladd.f32(float %16, float %19, float %.02427)
  %21 = add i32 %12, 1
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %8, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !12
  %25 = add i32 %12, 2
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds float, ptr %8, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !12
  %29 = insertelement <2 x float> poison, float %16, i64 0
  %30 = shufflevector <2 x float> %29, <2 x float> poison, <2 x i32> zeroinitializer
  %31 = insertelement <2 x float> poison, float %24, i64 0
  %32 = insertelement <2 x float> %31, float %28, i64 1
  %33 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %30, <2 x float> %32, <2 x float> %10)
  %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 %9, !llvm.loop !14

._crit_edge:                                      ; preds = %9, %5
  %.024.lcssa = phi float [ 0.000000e+00, %5 ], [ %20, %9 ]
  %34 = phi <2 x float> [ zeroinitializer, %5 ], [ %33, %9 ]
  store float %.024.lcssa, ptr %2, align 4, !tbaa !12
  %35 = extractelement <2 x float> %34, i64 0
  store float %35, ptr %3, align 4, !tbaa !12
  %36 = extractelement <2 x float> %34, i64 1
  store float %36, ptr %4, align 4, !tbaa !12
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x float> @llvm.fmuladd.v2f32(<2 x float>, <2 x float>, <2 x float>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(read, argmem: 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 #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 0}
!6 = !{!"particles_obj", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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