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

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

; Function Attrs: nounwind uwtable
define dso_local void @libmetis__Project2WayNodePartition(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %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 ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  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 %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.graphdef, ptr %12, i32 0, i32 31
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.graphdef, ptr %15, i32 0, i32 18
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.graphdef, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !14
  store i64 %20, ptr %7, align 8, !tbaa !15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.graphdef, ptr %21, i32 0, i32 15
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @libmetis__Allocate2WayNodePartitionMemory(ptr noundef %24, ptr noundef %25)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.graphdef, ptr %26, i32 0, i32 18
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store ptr %28, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %5, align 8, !tbaa !15
  br label %29

29:                                               ; preds = %44, %2
  %30 = load i64, ptr %5, align 8, !tbaa !15
  %31 = load i64, ptr %7, align 8, !tbaa !15
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %33, label %47

33:                                               ; preds = %29
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i64, ptr %5, align 8, !tbaa !15
  %37 = getelementptr inbounds i64, ptr %35, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds i64, ptr %34, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !15
  %43 = getelementptr inbounds i64, ptr %41, i64 %42
  store i64 %40, ptr %43, align 8, !tbaa !15
  br label %44

44:                                               ; preds = %33
  %45 = load i64, ptr %5, align 8, !tbaa !15
  %46 = add nsw i64 %45, 1
  store i64 %46, ptr %5, align 8, !tbaa !15
  br label %29, !llvm.loop !17

47:                                               ; preds = %29
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.graphdef, ptr %48, i32 0, i32 31
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  call void @libmetis__FreeGraph(ptr noundef %50, i32 noundef 1)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.graphdef, ptr %51, i32 0, i32 31
  store ptr null, ptr %52, align 8, !tbaa !9
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @libmetis__Compute2WayNodePartitionParams(ptr noundef %53, ptr noundef %54)
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @libmetis__Allocate2WayNodePartitionMemory(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @libmetis__Compute2WayNodePartitionParams(ptr noundef, ptr noundef) #0

declare void @libmetis__FreeGraph(ptr noundef, i32 noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 232}
!10 = !{!"graphdef", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !11, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !11, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !11, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 128}
!14 = !{!10, !11, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 104}
!17 = distinct !{!17, !18}
!18 = !{!"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: nounwind uwtable
define dso_local void @libmetis__Project2WayNodePartition(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 232
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 128
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = load i64, ptr %1, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %1, i64 104
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  tail call void @libmetis__Allocate2WayNodePartitionMemory(ptr noundef %0, ptr noundef nonnull %1)
  %10 = getelementptr inbounds i8, ptr %1, i64 128
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp sgt i64 %7, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i64 %7, 3
  %13 = icmp ult i64 %7, 4
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %7, 9223372036854775804
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.018 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %37, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %14 = getelementptr inbounds i64, ptr %9, i64 %.018
  %15 = load i64, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds i64, ptr %6, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = getelementptr inbounds i64, ptr %11, i64 %.018
  store i64 %17, ptr %18, align 8, !tbaa !15
  %19 = or disjoint i64 %.018, 1
  %20 = getelementptr inbounds i64, ptr %9, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i64, ptr %6, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i64, ptr %11, i64 %19
  store i64 %23, ptr %24, align 8, !tbaa !15
  %25 = or disjoint i64 %.018, 2
  %26 = getelementptr inbounds i64, ptr %9, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = getelementptr inbounds i64, ptr %6, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = getelementptr inbounds i64, ptr %11, i64 %25
  store i64 %29, ptr %30, align 8, !tbaa !15
  %31 = or disjoint i64 %.018, 3
  %32 = getelementptr inbounds i64, ptr %9, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds i64, ptr %6, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = getelementptr inbounds i64, ptr %11, i64 %31
  store i64 %35, ptr %36, align 8, !tbaa !15
  %37 = add nuw nsw i64 %.018, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !16

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.018.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %37, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.018.epil = phi i64 [ %43, %.lr.ph.epil ], [ %.018.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %38 = getelementptr inbounds i64, ptr %9, i64 %.018.epil
  %39 = load i64, ptr %38, align 8, !tbaa !15
  %40 = getelementptr inbounds i64, ptr %6, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds i64, ptr %11, i64 %.018.epil
  store i64 %41, ptr %42, align 8, !tbaa !15
  %43 = add nuw nsw i64 %.018.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !18

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %2
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @libmetis__FreeGraph(ptr noundef %44, i32 noundef 1) #2
  store ptr null, ptr %3, align 8, !tbaa !5
  tail call void @libmetis__Compute2WayNodePartitionParams(ptr noundef %0, ptr noundef nonnull %1)
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @libmetis__Allocate2WayNodePartitionMemory(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @libmetis__Compute2WayNodePartitionParams(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @libmetis__FreeGraph(ptr noundef, i32 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, !10, i64 232}
!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 128}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 104}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}


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