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

; 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 i64 @libmetis__IsBetter2wayBalance(i64 noundef %0, ptr 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 ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  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 float 0.000000e+00, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store float 0.000000e+00, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  store float 0.000000e+00, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store float 0.000000e+00, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %69, %4
  %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 %72

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds float, ptr %23, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = fsub float %26, 1.000000e+00
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = load i64, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds float, ptr %28, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !11
  %32 = fsub float %31, 1.000000e+00
  %33 = fdiv float %27, %32
  store float %33, ptr %16, align 4, !tbaa !11
  %34 = load float, ptr %12, align 4, !tbaa !11
  %35 = load float, ptr %16, align 4, !tbaa !11
  %36 = fcmp olt float %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %22
  %38 = load float, ptr %16, align 4, !tbaa !11
  br label %41

39:                                               ; preds = %22
  %40 = load float, ptr %12, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %39, %37
  %42 = phi float [ %38, %37 ], [ %40, %39 ]
  store float %42, ptr %12, align 4, !tbaa !11
  %43 = load float, ptr %16, align 4, !tbaa !11
  %44 = load float, ptr %14, align 4, !tbaa !11
  %45 = fadd float %44, %43
  store float %45, ptr %14, align 4, !tbaa !11
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  %47 = load i64, ptr %10, align 8, !tbaa !5
  %48 = getelementptr inbounds float, ptr %46, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = fsub float %49, 1.000000e+00
  %51 = load ptr, ptr %9, align 8, !tbaa !9
  %52 = load i64, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds float, ptr %51, i64 %52
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = fsub float %54, 1.000000e+00
  %56 = fdiv float %50, %55
  store float %56, ptr %16, align 4, !tbaa !11
  %57 = load float, ptr %13, align 4, !tbaa !11
  %58 = load float, ptr %16, align 4, !tbaa !11
  %59 = fcmp olt float %57, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %41
  %61 = load float, ptr %16, align 4, !tbaa !11
  br label %64

62:                                               ; preds = %41
  %63 = load float, ptr %13, align 4, !tbaa !11
  br label %64

64:                                               ; preds = %62, %60
  %65 = phi float [ %61, %60 ], [ %63, %62 ]
  store float %65, ptr %13, align 4, !tbaa !11
  %66 = load float, ptr %16, align 4, !tbaa !11
  %67 = load float, ptr %15, align 4, !tbaa !11
  %68 = fadd float %67, %66
  store float %68, ptr %15, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %64
  %70 = load i64, ptr %10, align 8, !tbaa !5
  %71 = add nsw i64 %70, 1
  store i64 %71, ptr %10, align 8, !tbaa !5
  br label %18, !llvm.loop !13

72:                                               ; preds = %18
  %73 = load float, ptr %12, align 4, !tbaa !11
  %74 = load float, ptr %13, align 4, !tbaa !11
  %75 = fcmp olt float %73, %74
  br i1 %75, label %76, label %77

76:                                               ; preds = %72
  store i64 1, ptr %5, align 8
  store i32 1, ptr %17, align 4
  br label %88

77:                                               ; preds = %72
  %78 = load float, ptr %12, align 4, !tbaa !11
  %79 = load float, ptr %13, align 4, !tbaa !11
  %80 = fcmp ogt float %78, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %77
  store i64 0, ptr %5, align 8
  store i32 1, ptr %17, align 4
  br label %88

82:                                               ; preds = %77
  %83 = load float, ptr %14, align 4, !tbaa !11
  %84 = load float, ptr %15, align 4, !tbaa !11
  %85 = fcmp ole float %83, %84
  %86 = zext i1 %85 to i32
  %87 = sext i32 %86 to i64
  store i64 %87, ptr %5, align 8
  store i32 1, ptr %17, align 4
  br label %88

88:                                               ; preds = %82, %81, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  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 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %89 = load i64, ptr %5, align 8
  ret i64 %89
}

; 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 = !{!"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"}


; 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__IsBetter2wayBalance(i64 noundef %0, ptr nocapture noundef readonly %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 %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.03334 = phi i64 [ %24, %.lr.ph ], [ 0, %4 ]
  %6 = phi <2 x float> [ %23, %.lr.ph ], [ zeroinitializer, %4 ]
  %7 = phi <2 x float> [ %22, %.lr.ph ], [ zeroinitializer, %4 ]
  %8 = getelementptr inbounds float, ptr %1, i64 %.03334
  %9 = load float, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds float, ptr %3, i64 %.03334
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = fadd float %11, -1.000000e+00
  %13 = getelementptr inbounds float, ptr %2, i64 %.03334
  %14 = load float, ptr %13, align 4, !tbaa !5
  %15 = insertelement <2 x float> poison, float %9, i64 0
  %16 = insertelement <2 x float> %15, float %14, i64 1
  %17 = fadd <2 x float> %16, <float -1.000000e+00, float -1.000000e+00>
  %18 = insertelement <2 x float> poison, float %12, i64 0
  %19 = shufflevector <2 x float> %18, <2 x float> poison, <2 x i32> zeroinitializer
  %20 = fdiv <2 x float> %17, %19
  %21 = fcmp olt <2 x float> %7, %20
  %22 = select <2 x i1> %21, <2 x float> %20, <2 x float> %7
  %23 = fadd <2 x float> %6, %20
  %24 = add nuw nsw i64 %.03334, 1
  %exitcond.not = icmp eq i64 %24, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  %25 = extractelement <2 x float> %22, i64 0
  %26 = extractelement <2 x float> %22, i64 1
  %27 = fcmp olt float %25, %26
  br i1 %27, label %35, label %28

28:                                               ; preds = %._crit_edge
  %29 = fcmp ogt float %25, %26
  br i1 %29, label %35, label %.thread

.thread:                                          ; preds = %4, %28
  %30 = phi <2 x float> [ %23, %28 ], [ zeroinitializer, %4 ]
  %31 = extractelement <2 x float> %30, i64 0
  %32 = extractelement <2 x float> %30, i64 1
  %33 = fcmp ole float %31, %32
  %34 = zext i1 %33 to i64
  br label %35

35:                                               ; preds = %28, %._crit_edge, %.thread
  %.0 = phi i64 [ %34, %.thread ], [ 1, %._crit_edge ], [ 0, %28 ]
  ret i64 %.0
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass