; LLVM IR from ekoontz/graphlab :: src/graphlab/extern/metis/libmetis/mkwayfmh.ll_libmetis (MocIsHBalanced)

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

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

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

19:                                               ; preds = %44, %18
  %20 = load i64, ptr %11, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = icmp slt i64 %20, %21
  br i1 %22, label %23, label %47

23:                                               ; preds = %19
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = load i64, ptr %11, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = mul nsw i64 %25, %26
  %28 = load i64, ptr %10, align 8, !tbaa !5
  %29 = add nsw i64 %27, %28
  %30 = getelementptr inbounds float, ptr %24, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !11
  %32 = load float, ptr %12, align 4, !tbaa !11
  %33 = fcmp ogt float %31, %32
  br i1 %33, label %34, label %43

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

43:                                               ; preds = %34, %23
  br label %44

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

47:                                               ; preds = %19
  %48 = load ptr, ptr %9, align 8, !tbaa !9
  %49 = load i64, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds float, ptr %48, i64 %49
  %51 = load float, ptr %50, align 4, !tbaa !11
  %52 = load float, ptr %12, align 4, !tbaa !11
  %53 = load i64, ptr %7, align 8, !tbaa !5
  %54 = sitofp i64 %53 to float
  %55 = fmul float %52, %54
  %56 = fcmp olt float %51, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %47
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %63

58:                                               ; preds = %47
  br label %59

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

62:                                               ; preds = %14
  store i64 1, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %63

63:                                               ; preds = %62, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %64 = load i64, ptr %5, align 8
  ret i64 %64
}

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

.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 %.preheader.lr.ph.split

.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, %17
  %.02027.us = phi i64 [ %18, %17 ], [ 0, %.preheader.us.preheader ]
  %invariant.gep.us = getelementptr float, ptr %2, i64 %.02027.us
  br i1 %8, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.026.us = phi float [ %.1.us.1, %.preheader.us.new ], [ 0.000000e+00, %.preheader.us ]
  %.01925.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 %.01925.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, %.026.us
  %.1.us = select i1 %11, float %10, float %.026.us
  %12 = or disjoint i64 %.01925.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, %.1.us
  %.1.us.1 = select i1 %15, float %14, float %.1.us
  %16 = add nuw nsw i64 %.01925.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

17:                                               ; preds = %._crit_edge.us
  %18 = add nuw nsw i64 %.02027.us, 1
  %exitcond36.not = icmp eq i64 %18, %0
  br i1 %exitcond36.not, label %._crit_edge28, label %.preheader.us, !llvm.loop !11

._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 ]
  %.026.us.unr = phi float [ 0.000000e+00, %.preheader.us ], [ %.1.us.1, %.preheader.us.new ]
  %.01925.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
  %19 = mul nuw nsw i64 %.01925.us.unr, %0
  %gep.us.epil = getelementptr float, ptr %invariant.gep.us, i64 %19
  %20 = load float, ptr %gep.us.epil, align 4, !tbaa !5
  %21 = fcmp ogt float %20, %.026.us.unr
  %.1.us.epil = select i1 %21, float %20, float %.026.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 ]
  %22 = getelementptr inbounds float, ptr %3, i64 %.02027.us
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = fmul float %.1.us.lcssa, %7
  %25 = fcmp olt float %23, %24
  br i1 %25, label %._crit_edge28, label %17

.preheader.lr.ph.split:                           ; preds = %.preheader.lr.ph
  %26 = tail call float @llvm.copysign.f32(float 0.000000e+00, float %7)
  br label %.preheader

27:                                               ; preds = %.preheader
  %28 = add nuw nsw i64 %.02027, 1
  %exitcond.not = icmp eq i64 %28, %0
  br i1 %exitcond.not, label %._crit_edge28, label %.preheader, !llvm.loop !11

.preheader:                                       ; preds = %.preheader.lr.ph.split, %27
  %.02027 = phi i64 [ 0, %.preheader.lr.ph.split ], [ %28, %27 ]
  %29 = getelementptr inbounds float, ptr %3, i64 %.02027
  %30 = load float, ptr %29, align 4, !tbaa !5
  %31 = fcmp olt float %30, %26
  br i1 %31, label %._crit_edge28, label %27

._crit_edge28:                                    ; preds = %.preheader, %27, %._crit_edge.us, %17, %4
  %.021 = phi i64 [ 1, %4 ], [ 1, %17 ], [ 0, %._crit_edge.us ], [ 1, %27 ], [ 0, %.preheader ]
  ret i64 %.021
}

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


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