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

; 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 speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

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

11:                                               ; preds = %29, %4
  %12 = load i64, ptr %9, align 8, !tbaa !5
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = icmp slt i64 %12, %13
  br i1 %14, label %15, label %32

15:                                               ; preds = %11
  %16 = load ptr, ptr %7, align 8, !tbaa !9
  %17 = getelementptr inbounds float, ptr %16, i64 0
  %18 = load float, ptr %17, align 4, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = load i64, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds float, ptr %19, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !11
  %23 = fsub float %18, %22
  %24 = fpext float %23 to double
  %25 = call double @llvm.fabs.f64(double %24)
  %26 = fptrunc double %25 to float
  %27 = load i64, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds [16 x float], ptr %10, i64 0, i64 %27
  store float %26, ptr %28, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %15
  %30 = load i64, ptr %9, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr %9, align 8, !tbaa !5
  br label %11, !llvm.loop !13

32:                                               ; preds = %11
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds [16 x float], ptr %10, i64 0, i64 0
  %35 = call float @gk_fnorm2(i64 noundef %33, ptr noundef %34, i64 noundef 1)
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = call float @gk_fnorm2(i64 noundef %36, ptr noundef %37, i64 noundef 1)
  %39 = fcmp olt float %35, %38
  %40 = zext i1 %39 to i32
  %41 = sext i32 %40 to i64
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret i64 %41
}

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

declare float @gk_fnorm2(i64 noundef, ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 #4 = { 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: mustprogress 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 range(i64 0, 2) i64 @libmetis__BetterBalance(i64 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = alloca [16 x float], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #4
  %6 = icmp sgt i64 %0, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %7 = load float, ptr %2, align 4, !tbaa !5
  %min.iters.check = icmp ult i64 %0, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %0, 9223372036854775800
  %broadcast.splatinsert = insertelement <4 x float> poison, float %7, 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 ]
  %8 = getelementptr inbounds float, ptr %1, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <4 x float>, ptr %8, align 4, !tbaa !5
  %wide.load11 = load <4 x float>, ptr %9, align 4, !tbaa !5
  %10 = fsub <4 x float> %broadcast.splat, %wide.load
  %11 = fsub <4 x float> %broadcast.splat, %wide.load11
  %12 = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> %10)
  %13 = tail call <4 x float> @llvm.fabs.v4f32(<4 x float> %11)
  %14 = getelementptr inbounds [16 x float], ptr %5, i64 0, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <4 x float> %12, ptr %14, align 16, !tbaa !5
  store <4 x float> %13, ptr %15, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %0
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

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

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.010 = phi i64 [ %22, %scalar.ph ], [ %.010.ph, %scalar.ph.preheader ]
  %17 = getelementptr inbounds float, ptr %1, i64 %.010
  %18 = load float, ptr %17, align 4, !tbaa !5
  %19 = fsub float %7, %18
  %20 = tail call float @llvm.fabs.f32(float %19)
  %21 = getelementptr inbounds [16 x float], ptr %5, i64 0, i64 %.010
  store float %20, ptr %21, align 4, !tbaa !5
  %22 = add nuw nsw i64 %.010, 1
  %exitcond.not = icmp eq i64 %22, %0
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %4
  %23 = call float @gk_fnorm2(i64 noundef %0, ptr noundef nonnull %5, i64 noundef 1) #4
  %24 = call float @gk_fnorm2(i64 noundef %0, ptr noundef %3, i64 noundef 1) #4
  %25 = fcmp olt float %23, %24
  %26 = zext i1 %25 to i64
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #4
  ret i64 %26
}

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

declare float @gk_fnorm2(i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fabs.v4f32(<4 x float>) #3

attributes #0 = { mustprogress 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 = { "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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass