; LLVM IR from ekoontz/graphlab :: src/graphlab/extern/metis/libmetis/mutil.ll_libmetis (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 @libmetis__ComputeLoadImbalance(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !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 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, 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 i64 0, ptr %9, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %59, %4
  %14 = load i64, ptr %9, align 8, !tbaa !5
  %15 = load i64, ptr %5, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %17, label %62

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

18:                                               ; preds = %43, %17
  %19 = load i64, ptr %10, align 8, !tbaa !5
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %22, label %46

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !5
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = mul nsw i64 %24, %25
  %27 = load i64, ptr %9, align 8, !tbaa !5
  %28 = add nsw i64 %26, %27
  %29 = getelementptr inbounds float, ptr %23, 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 %42

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

42:                                               ; preds = %33, %22
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %10, align 8, !tbaa !5
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %10, align 8, !tbaa !5
  br label %18, !llvm.loop !13

46:                                               ; preds = %18
  %47 = load float, ptr %11, align 4, !tbaa !11
  %48 = load i64, ptr %6, align 8, !tbaa !5
  %49 = sitofp i64 %48 to float
  %50 = fmul float %47, %49
  %51 = load float, ptr %12, align 4, !tbaa !11
  %52 = fcmp ogt float %50, %51
  br i1 %52, label %53, label %58

53:                                               ; preds = %46
  %54 = load float, ptr %11, align 4, !tbaa !11
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = sitofp i64 %55 to float
  %57 = fmul float %54, %56
  store float %57, ptr %12, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %53, %46
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %9, align 8, !tbaa !5
  %61 = add nsw i64 %60, 1
  store i64 %61, ptr %9, align 8, !tbaa !5
  br label %13, !llvm.loop !15

62:                                               ; preds = %13
  %63 = 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 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret float %63
}

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 = !{!"long", !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 @libmetis__ComputeLoadImbalance(i64 noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %5 = icmp sgt i64 %0, 0
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge32

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

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i64 %1, 1
  %8 = icmp eq i64 %1, 1
  %unroll_iter = and i64 %1, 9223372036854775806
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.031.us = phi float [ %.1.us, %._crit_edge.us ], [ 0.000000e+00, %.preheader.us.preheader ]
  %.02330.us = phi i64 [ %22, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %invariant.gep.us = getelementptr float, ptr %2, i64 %.02330.us
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.02029.us = phi float [ %.121.us.1, %.preheader.us.new ], [ 0.000000e+00, %.preheader.us ]
  %.02228.us = phi i64 [ %16, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %9 = mul nuw nsw i64 %.02228.us, %0
  %gep.us = getelementptr float, ptr %invariant.gep.us, i64 %9
  %10 = load float, ptr %gep.us, align 4, !tbaa !5
  %11 = fcmp ogt float %10, %.02029.us
  %.121.us = select i1 %11, float %10, float %.02029.us
  %12 = or disjoint i64 %.02228.us, 1
  %13 = mul nuw nsw i64 %12, %0
  %gep.us.1 = getelementptr float, ptr %invariant.gep.us, i64 %13
  %14 = load float, ptr %gep.us.1, align 4, !tbaa !5
  %15 = fcmp ogt float %14, %.121.us
  %.121.us.1 = select i1 %15, float %14, float %.121.us
  %16 = add nuw nsw i64 %.02228.us, 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 ]
  %.02029.us.unr = phi float [ 0.000000e+00, %.preheader.us ], [ %.121.us.1, %.preheader.us.new ]
  %.02228.us.unr = phi i64 [ 0, %.preheader.us ], [ %16, %.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
  %17 = mul nuw nsw i64 %.02228.us.unr, %0
  %gep.us.epil = getelementptr float, ptr %invariant.gep.us, i64 %17
  %18 = load float, ptr %gep.us.epil, align 4, !tbaa !5
  %19 = fcmp ogt float %18, %.02029.us.unr
  %.121.us.epil = select i1 %19, float %18, 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 ]
  %20 = fmul float %.121.us.lcssa, %7
  %21 = fcmp ogt float %20, %.031.us
  %.1.us = select i1 %21, float %20, float %.031.us
  %22 = add nuw nsw i64 %.02330.us, 1
  %exitcond35.not = icmp eq i64 %22, %0
  br i1 %exitcond35.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