; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libSimuTilts/library.ll (Z19sample_aglomerationPfS_fii)

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

; 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: mustprogress nounwind uwtable
declare dso_local void @_Z5clearPffi(ptr noundef, float noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z19sample_aglomerationPfS_fii(ptr noundef %0, ptr noundef %1, float noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store float %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  store i32 %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %19 = load i32, ptr %9, align 4, !tbaa !11
  %20 = sitofp i32 %19 to float
  %21 = load float, ptr %8, align 4, !tbaa !9
  %22 = fdiv float %20, %21
  %23 = fptosi float %22 to i32
  store i32 %23, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %24 = load i32, ptr %10, align 4, !tbaa !11
  %25 = sitofp i32 %24 to float
  %26 = load float, ptr %8, align 4, !tbaa !9
  %27 = fdiv float %25, %26
  %28 = fptosi float %27 to i32
  store i32 %28, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %29 = load i32, ptr %11, align 4, !tbaa !11
  %30 = load i32, ptr %12, align 4, !tbaa !11
  %31 = mul nsw i32 %29, %30
  store i32 %31, ptr %13, align 4, !tbaa !11
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %11, align 4, !tbaa !11
  %34 = load i32, ptr %12, align 4, !tbaa !11
  %35 = mul nsw i32 %33, %34
  call void @_Z5clearPffi(ptr noundef %32, float noundef 0.000000e+00, i32 noundef %35)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %36

36:                                               ; preds = %85, %5
  %37 = load i32, ptr %14, align 4, !tbaa !11
  %38 = load i32, ptr %10, align 4, !tbaa !11
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 2, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %88

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  store i32 0, ptr %16, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %81, %41
  %43 = load i32, ptr %16, align 4, !tbaa !11
  %44 = load i32, ptr %9, align 4, !tbaa !11
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 5, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  br label %84

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %48 = load i32, ptr %14, align 4, !tbaa !11
  %49 = sitofp i32 %48 to float
  %50 = load float, ptr %8, align 4, !tbaa !9
  %51 = fdiv float %49, %50
  %52 = fptosi float %51 to i32
  %53 = load i32, ptr %11, align 4, !tbaa !11
  %54 = mul nsw i32 %52, %53
  %55 = load i32, ptr %16, align 4, !tbaa !11
  %56 = sitofp i32 %55 to float
  %57 = load float, ptr %8, align 4, !tbaa !9
  %58 = fdiv float %56, %57
  %59 = fptosi float %58 to i32
  %60 = add nsw i32 %54, %59
  store i32 %60, ptr %17, align 4, !tbaa !11
  %61 = load i32, ptr %17, align 4, !tbaa !11
  %62 = load i32, ptr %13, align 4, !tbaa !11
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %64, label %80

64:                                               ; preds = %47
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %14, align 4, !tbaa !11
  %67 = load i32, ptr %9, align 4, !tbaa !11
  %68 = mul nsw i32 %66, %67
  %69 = load i32, ptr %16, align 4, !tbaa !11
  %70 = add nsw i32 %68, %69
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds float, ptr %65, i64 %71
  %73 = load float, ptr %72, align 4, !tbaa !9
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i32, ptr %17, align 4, !tbaa !11
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds float, ptr %74, i64 %76
  %78 = load float, ptr %77, align 4, !tbaa !9
  %79 = fadd float %78, %73
  store float %79, ptr %77, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %64, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %16, align 4, !tbaa !11
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %16, align 4, !tbaa !11
  br label %42, !llvm.loop !13

84:                                               ; preds = %46
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %14, align 4, !tbaa !11
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %14, align 4, !tbaa !11
  br label %36, !llvm.loop !15

88:                                               ; preds = %40
  %89 = load float, ptr %8, align 4, !tbaa !9
  %90 = load float, ptr %8, align 4, !tbaa !9
  %91 = fmul float %90, %89
  store float %91, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #2
  store i32 0, ptr %18, align 4, !tbaa !11
  br label %92

92:                                               ; preds = %107, %88
  %93 = load i32, ptr %18, align 4, !tbaa !11
  %94 = load i32, ptr %11, align 4, !tbaa !11
  %95 = load i32, ptr %12, align 4, !tbaa !11
  %96 = mul nsw i32 %94, %95
  %97 = icmp slt i32 %93, %96
  br i1 %97, label %99, label %98

98:                                               ; preds = %92
  store i32 8, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  br label %110

99:                                               ; preds = %92
  %100 = load float, ptr %8, align 4, !tbaa !9
  %101 = load ptr, ptr %7, align 8, !tbaa !5
  %102 = load i32, ptr %18, align 4, !tbaa !11
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds float, ptr %101, i64 %103
  %105 = load float, ptr %104, align 4, !tbaa !9
  %106 = fdiv float %105, %100
  store float %106, ptr %104, align 4, !tbaa !9
  br label %107

107:                                              ; preds = %99
  %108 = load i32, ptr %18, align 4, !tbaa !11
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %18, align 4, !tbaa !11
  br label %92, !llvm.loop !16

110:                                              ; preds = %98
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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 nounwind uwtable
declare dso_local void @_Z5clearPffi(ptr noundef, float noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z19sample_aglomerationPfS_fii(ptr nocapture noundef readonly %0, ptr noundef %1, float noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = insertelement <2 x i32> poison, i32 %4, i64 0
  %7 = insertelement <2 x i32> %6, i32 %3, i64 1
  %8 = sitofp <2 x i32> %7 to <2 x float>
  %9 = insertelement <2 x float> poison, float %2, i64 0
  %10 = shufflevector <2 x float> %9, <2 x float> poison, <2 x i32> zeroinitializer
  %11 = fdiv <2 x float> %8, %10
  %12 = fptosi <2 x float> %11 to <2 x i32>
  %13 = extractelement <2 x i32> %12, i64 0
  %14 = extractelement <2 x i32> %12, i64 1
  %15 = mul nsw i32 %13, %14
  tail call void @_Z5clearPffi(ptr noundef %1, float noundef 0.000000e+00, i32 noundef %15)
  %16 = icmp sgt i32 %4, 0
  %17 = icmp sgt i32 %3, 0
  %or.cond = and i1 %16, %17
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge42

.preheader.us.preheader:                          ; preds = %5
  %18 = zext nneg i32 %3 to i64
  %wide.trip.count49 = zext nneg i32 %4 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv46 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next47, %._crit_edge.us ]
  %19 = trunc nuw nsw i64 %indvars.iv46 to i32
  %20 = uitofp nneg i32 %19 to float
  %21 = fdiv float %20, %2
  %22 = fptosi float %21 to i32
  %23 = mul nsw i32 %14, %22
  %24 = mul nuw nsw i64 %indvars.iv46, %18
  %invariant.gep = getelementptr inbounds float, ptr %0, i64 %24
  br label %25

25:                                               ; preds = %.preheader.us, %38
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %38 ]
  %26 = trunc nuw nsw i64 %indvars.iv to i32
  %27 = uitofp nneg i32 %26 to float
  %28 = fdiv float %27, %2
  %29 = fptosi float %28 to i32
  %30 = add nsw i32 %23, %29
  %31 = icmp slt i32 %30, %15
  br i1 %31, label %32, label %38

32:                                               ; preds = %25
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %33 = load float, ptr %gep, align 4, !tbaa !5
  %34 = sext i32 %30 to i64
  %35 = getelementptr inbounds float, ptr %1, i64 %34
  %36 = load float, ptr %35, align 4, !tbaa !5
  %37 = fadd float %33, %36
  store float %37, ptr %35, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %32, %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %18
  br i1 %exitcond.not, label %._crit_edge.us, label %25, !llvm.loop !9

._crit_edge.us:                                   ; preds = %38
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond50.not = icmp eq i64 %indvars.iv.next47, %wide.trip.count49
  br i1 %exitcond50.not, label %._crit_edge42, label %.preheader.us, !llvm.loop !11

._crit_edge42:                                    ; preds = %._crit_edge.us, %5
  %39 = fmul float %2, %2
  %40 = icmp sgt i32 %15, 0
  br i1 %40, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %._crit_edge42
  %wide.trip.count54 = zext nneg i32 %15 to i64
  %min.iters.check = icmp ult i32 %15, 4
  br i1 %min.iters.check, label %.lr.ph.preheader56, label %vector.ph

.lr.ph.preheader56:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv51.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count54, 2147483644
  %broadcast.splatinsert = insertelement <4 x float> poison, float %39, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %41 = getelementptr inbounds float, ptr %1, i64 %index
  %wide.load = load <4 x float>, ptr %41, align 4, !tbaa !5
  %42 = fdiv <4 x float> %wide.load, %broadcast.splat
  store <4 x float> %42, ptr %41, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %43 = icmp eq i64 %index.next, %n.vec
  br i1 %43, label %middle.block, label %vector.body, !llvm.loop !12

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

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %._crit_edge42
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader56, %.lr.ph
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %.lr.ph ], [ %indvars.iv51.ph, %.lr.ph.preheader56 ]
  %44 = getelementptr inbounds float, ptr %1, i64 %indvars.iv51
  %45 = load float, ptr %44, align 4, !tbaa !5
  %46 = fdiv float %45, %39
  store float %46, ptr %44, align 4, !tbaa !5
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next52, %wide.trip.count54
  br i1 %exitcond55.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15
}

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

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10, !13, !14}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !10, !14, !13}


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