; LLVM IR from siconos/siconos :: externals/lbl/metis4/mutil.ll_ (ComputeLoadImbalance)

; 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: nounwind uwtable
define dso_local float @__ComputeLoadImbalance(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
  %12 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store float 0.000000e+00, ptr %12, align 4, !tbaa !11
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %13

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

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

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

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

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

44:                                               ; preds = %34, %22
  br label %45

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

48:                                               ; preds = %18
  %49 = load float, ptr %11, align 4, !tbaa !11
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sitofp i32 %50 to float
  %52 = fmul float %49, %51
  %53 = load float, ptr %12, align 4, !tbaa !11
  %54 = fcmp ogt float %52, %53
  br i1 %54, label %55, label %60

55:                                               ; preds = %48
  %56 = load float, ptr %11, align 4, !tbaa !11
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = sitofp i32 %57 to float
  %59 = fmul float %56, %58
  store float %59, ptr %12, align 4, !tbaa !11
  br label %60

60:                                               ; preds = %55, %48
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %9, align 4, !tbaa !5
  br label %13, !llvm.loop !15

64:                                               ; preds = %13
  %65 = load float, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  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 float %65
}

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: read) uwtable
define dso_local float @__ComputeLoadImbalance(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge32

.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 %._crit_edge32

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

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv36 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next37, %._crit_edge.us ]
  %.031.us = phi float [ 0.000000e+00, %.preheader.us.preheader ], [ %.1.us, %._crit_edge.us ]
  %invariant.gep = getelementptr inbounds float, ptr %2, i64 %indvars.iv36
  br i1 %9, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %.02029.us = phi float [ %.121.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.iv, %8
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %10
  %11 = load float, ptr %gep, align 4, !tbaa !5
  %12 = fcmp ogt float %11, %.02029.us
  %.121.us = select i1 %12, float %11, float %.02029.us
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %13 = mul nuw nsw i64 %indvars.iv.next, %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, %.121.us
  %.121.us.1 = select i1 %15, float %14, float %.121.us
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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
  %.121.us.lcssa.ph = phi float [ poison, %.preheader.us ], [ %.121.us.1, %.preheader.us.new ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %.preheader.us.new ]
  %.02029.us.unr = phi float [ 0.000000e+00, %.preheader.us ], [ %.121.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.iv.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, %.02029.us.unr
  %.121.us.epil = select i1 %18, float %17, float %.02029.us.unr
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.121.us.lcssa = phi float [ %.121.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %.121.us.epil, %._crit_edge.us.epilog-lcssa ]
  %19 = fmul float %.121.us.lcssa, %7
  %20 = fcmp ogt float %19, %.031.us
  %.1.us = select i1 %20, float %19, float %.031.us
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %8
  br i1 %exitcond40.not, label %._crit_edge32, label %.preheader.us, !llvm.loop !11

._crit_edge32:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %4
  %.0.lcssa = phi float [ 0.000000e+00, %4 ], [ 0.000000e+00, %.preheader.lr.ph ], [ %.1.us, %._crit_edge.us ]
  ret float %.0.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass