; LLVM IR from siconos/siconos :: externals/lbl/metis4/mkwayfmh.ll_ (ComputeHKWayLoadImbalance)

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

12:                                               ; preds = %56, %4
  %13 = load i32, ptr %9, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %59

16:                                               ; preds = %12
  store float 0.000000e+00, ptr %11, align 4, !tbaa !11
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %44, %16
  %18 = load i32, ptr %10, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %47

21:                                               ; preds = %17
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = mul nsw i32 %23, %24
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = add nsw i32 %25, %26
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds float, ptr %22, i64 %28
  %30 = load float, ptr %29, align 4, !tbaa !11
  %31 = load float, ptr %11, align 4, !tbaa !11
  %32 = fcmp ogt float %30, %31
  br i1 %32, label %33, label %43

33:                                               ; preds = %21
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = mul nsw i32 %35, %36
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = add nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %34, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !11
  store float %42, ptr %11, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %33, %21
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %10, align 4, !tbaa !5
  br label %17, !llvm.loop !13

47:                                               ; preds = %17
  %48 = load float, ptr %11, align 4, !tbaa !11
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sitofp i32 %49 to float
  %51 = fmul float %48, %50
  %52 = load ptr, ptr %8, align 8, !tbaa !9
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds float, ptr %52, i64 %54
  store float %51, ptr %55, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %47
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !5
  br label %12, !llvm.loop !15

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @__ComputeHKWayLoadImbalance(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge26

.preheader.lr.ph:                                 ; preds = %4
  %6 = icmp sgt i32 %1, 0
  %7 = sitofp i32 %1 to float
  br i1 %6, label %.preheader.us.preheader, label %.preheader.lr.ph.split

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %8 = zext nneg i32 %0 to i64
  %wide.trip.count32 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count32, 1
  %9 = icmp eq i32 %1, 1
  %unroll_iter = and i64 %wide.trip.count32, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv34 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next35, %._crit_edge.us ]
  %invariant.gep = getelementptr inbounds float, ptr %2, i64 %indvars.iv34
  br i1 %9, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv29 = phi i64 [ %indvars.iv.next30.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %.024.us = phi float [ %.1.us.1, %.preheader.us.new ], [ 0.000000e+00, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %10 = mul nuw nsw i64 %indvars.iv29, %8
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %10
  %11 = load float, ptr %gep, align 4, !tbaa !5
  %12 = fcmp ogt float %11, %.024.us
  %.1.us = select i1 %12, float %11, float %.024.us
  %indvars.iv.next30 = or disjoint i64 %indvars.iv29, 1
  %13 = mul nuw nsw i64 %indvars.iv.next30, %8
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %13
  %14 = load float, ptr %gep.1, align 4, !tbaa !5
  %15 = fcmp ogt float %14, %.1.us
  %.1.us.1 = select i1 %15, float %14, float %.1.us
  %indvars.iv.next30.1 = add nuw nsw i64 %indvars.iv29, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.1.us.lcssa.ph = phi float [ poison, %.preheader.us ], [ %.1.us.1, %.preheader.us.new ]
  %indvars.iv29.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next30.1, %.preheader.us.new ]
  %.024.us.unr = phi float [ 0.000000e+00, %.preheader.us ], [ %.1.us.1, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %16 = mul nuw nsw i64 %indvars.iv29.unr, %8
  %gep.epil = getelementptr inbounds float, ptr %invariant.gep, i64 %16
  %17 = load float, ptr %gep.epil, align 4, !tbaa !5
  %18 = fcmp ogt float %17, %.024.us.unr
  %.1.us.epil = select i1 %18, float %17, float %.024.us.unr
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.1.us.lcssa = phi float [ %.1.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %.1.us.epil, %._crit_edge.us.epilog-lcssa ]
  %19 = fmul float %.1.us.lcssa, %7
  %20 = getelementptr inbounds float, ptr %3, i64 %indvars.iv34
  store float %19, ptr %20, align 4, !tbaa !5
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %8
  br i1 %exitcond38.not, label %._crit_edge26, label %.preheader.us, !llvm.loop !11

.preheader.lr.ph.split:                           ; preds = %.preheader.lr.ph
  %21 = tail call float @llvm.copysign.f32(float 0.000000e+00, float %7)
  %wide.trip.count = zext nneg i32 %0 to i64
  %min.iters.check = icmp ult i32 %0, 8
  br i1 %min.iters.check, label %.preheader.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader.lr.ph.split
  %n.vec = and i64 %wide.trip.count, 2147483640
  %broadcast.splatinsert = insertelement <4 x float> poison, float %21, 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 ]
  %22 = getelementptr inbounds float, ptr %3, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  store <4 x float> %broadcast.splat, ptr %22, align 4, !tbaa !5
  store <4 x float> %broadcast.splat, ptr %23, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !12

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

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

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ %indvars.iv.ph, %.preheader.preheader ]
  %25 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  store float %21, ptr %25, align 4, !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_edge26, label %.preheader, !llvm.loop !15

._crit_edge26:                                    ; preds = %.preheader, %._crit_edge.us, %middle.block, %4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #1

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" }
attributes #1 = { 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, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass