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

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

%struct.graphdef = type { i64, i64, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i64, i64, ptr, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr, ptr, ptr, ptr }
%struct.rinfodef = type { i64, i64, i64, ptr }

; 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 void @libmetis__ComputeKWayBoundary(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.graphdef, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !11
  store i64 %14, ptr %8, align 8, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.graphdef, ptr %15, i32 0, i32 22
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.graphdef, ptr %19, i32 0, i32 21
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = call ptr @libmetis__idxset(i64 noundef %18, i64 noundef -1, ptr noundef %21)
  store ptr %22, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %58, %3
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %27, label %61

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.graphdef, ptr %28, i32 0, i32 25
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.rinfodef, ptr %30, i64 %31
  %33 = getelementptr inbounds %struct.rinfodef, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !17
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.graphdef, ptr %35, i32 0, i32 25
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.rinfodef, ptr %37, i64 %38
  %40 = getelementptr inbounds %struct.rinfodef, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !19
  %42 = sub nsw i64 %34, %41
  %43 = icmp sge i64 %42, 0
  br i1 %43, label %44, label %57

44:                                               ; preds = %27
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = getelementptr inbounds i64, ptr %47, i64 %48
  store i64 %46, ptr %49, align 8, !tbaa !9
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = add nsw i64 %50, 1
  store i64 %51, ptr %9, align 8, !tbaa !9
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = getelementptr inbounds i64, ptr %52, i64 %53
  store i64 %50, ptr %54, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %45
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56, %27
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %7, align 8, !tbaa !9
  br label %23, !llvm.loop !20

61:                                               ; preds = %23
  %62 = load i64, ptr %9, align 8, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.graphdef, ptr %63, i32 0, i32 20
  store i64 %62, ptr %64, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

declare ptr @libmetis__idxset(i64 noundef, i64 noundef, ptr noundef) #2

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 = { "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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"graphdef", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !13, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !10, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 160}
!15 = !{!12, !6, i64 152}
!16 = !{!12, !6, i64 184}
!17 = !{!18, !10, i64 8}
!18 = !{!"rinfodef", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!19 = !{!18, !10, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!12, !10, i64 144}


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

%struct.rinfodef = type { i64, i64, i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @libmetis__ComputeKWayBoundary(ptr nocapture noundef readnone %0, ptr nocapture noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 160
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %1, i64 152
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = tail call ptr @libmetis__idxset(i64 noundef %4, i64 noundef -1, ptr noundef %8) #2
  %10 = icmp sgt i64 %4, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %11 = getelementptr inbounds i8, ptr %1, i64 184
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %xtraiter = and i64 %4, 1
  %13 = icmp eq i64 %4, 1
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %4, 9223372036854775806
  br label %14

14:                                               ; preds = %33, %.lr.ph.new
  %.020 = phi i64 [ 0, %.lr.ph.new ], [ %34, %33 ]
  %.01819 = phi i64 [ 0, %.lr.ph.new ], [ %.1.1, %33 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %33 ]
  %15 = getelementptr inbounds %struct.rinfodef, ptr %12, i64 %.020
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = load i64, ptr %15, align 8, !tbaa !17
  %.not = icmp slt i64 %17, %18
  br i1 %.not, label %23, label %19

19:                                               ; preds = %14
  %20 = getelementptr inbounds i64, ptr %6, i64 %.01819
  store i64 %.020, ptr %20, align 8, !tbaa !18
  %21 = add nsw i64 %.01819, 1
  %22 = getelementptr inbounds i64, ptr %9, i64 %.020
  store i64 %.01819, ptr %22, align 8, !tbaa !18
  br label %23

23:                                               ; preds = %14, %19
  %.1 = phi i64 [ %21, %19 ], [ %.01819, %14 ]
  %24 = or disjoint i64 %.020, 1
  %25 = getelementptr inbounds %struct.rinfodef, ptr %12, i64 %24
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = load i64, ptr %25, align 8, !tbaa !17
  %.not.1 = icmp slt i64 %27, %28
  br i1 %.not.1, label %33, label %29

29:                                               ; preds = %23
  %30 = getelementptr inbounds i64, ptr %6, i64 %.1
  store i64 %24, ptr %30, align 8, !tbaa !18
  %31 = add nsw i64 %.1, 1
  %32 = getelementptr inbounds i64, ptr %9, i64 %24
  store i64 %.1, ptr %32, align 8, !tbaa !18
  br label %33

33:                                               ; preds = %29, %23
  %.1.1 = phi i64 [ %31, %29 ], [ %.1, %23 ]
  %34 = add nuw nsw i64 %.020, 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.loopexit.unr-lcssa, label %14, !llvm.loop !19

._crit_edge.loopexit.unr-lcssa:                   ; preds = %33, %.lr.ph
  %.1.lcssa.ph = phi i64 [ poison, %.lr.ph ], [ %.1.1, %33 ]
  %.020.unr = phi i64 [ 0, %.lr.ph ], [ %34, %33 ]
  %.01819.unr = phi i64 [ 0, %.lr.ph ], [ %.1.1, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %35 = getelementptr inbounds %struct.rinfodef, ptr %12, i64 %.020.unr
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = load i64, ptr %35, align 8, !tbaa !17
  %.not.epil = icmp slt i64 %37, %38
  br i1 %.not.epil, label %._crit_edge, label %39

39:                                               ; preds = %.epil.preheader
  %40 = getelementptr inbounds i64, ptr %6, i64 %.01819.unr
  store i64 %.020.unr, ptr %40, align 8, !tbaa !18
  %41 = add nsw i64 %.01819.unr, 1
  %42 = getelementptr inbounds i64, ptr %9, i64 %.020.unr
  store i64 %.01819.unr, ptr %42, align 8, !tbaa !18
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %39, %.epil.preheader, %3
  %.018.lcssa = phi i64 [ 0, %3 ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %41, %39 ], [ %.01819.unr, %.epil.preheader ]
  %43 = getelementptr inbounds i8, ptr %1, i64 144
  store i64 %.018.lcssa, ptr %43, align 8, !tbaa !21
  ret void
}

declare ptr @libmetis__idxset(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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, !7, i64 0}
!6 = !{!"graphdef", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !7, i64 112, !7, i64 120, !10, i64 128, !10, i64 136, !7, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !7, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 160}
!13 = !{!6, !10, i64 152}
!14 = !{!6, !10, i64 184}
!15 = !{!16, !7, i64 8}
!16 = !{!"rinfodef", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!17 = !{!16, !7, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!6, !7, i64 144}


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