; LLVM IR from ekoontz/graphlab :: src/graphlab/extern/metis/libmetis (rkmetis)

; 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.controldef = type { i64, i64, i64, i64, i64, i64, float, i64, i64, i64, i64, %struct.workspacedef, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double }
%struct.workspacedef = type { ptr, i64, i64, ptr, ptr, i64, ptr, ptr }
%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 }

@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1

; 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

declare double @gk_CPUSeconds() #1

; Function Attrs: nounwind uwtable
define dso_local i64 @MlevelKWayRefinement(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, float noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca float, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca [2 x i64], align 16
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca [10 x i64], align 16
  %22 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store float %5, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  store i64 3, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  store i64 0, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 80, ptr %21) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call ptr @libmetis__Coarsen2Way(ptr noundef %23, ptr noundef %24)
  store ptr %25, ptr %18, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.controldef, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !13
  %29 = and i64 %28, 1
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %37

31:                                               ; preds = %6
  %32 = call double @gk_CPUSeconds()
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.controldef, ptr %33, i32 0, i32 13
  %35 = load double, ptr %34, align 8, !tbaa !17
  %36 = fsub double %35, %32
  store double %36, ptr %34, align 8, !tbaa !17
  br label %37

37:                                               ; preds = %31, %6
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %18, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  call void @libmetis__AllocateKWayPartitionMemory(ptr noundef %38, ptr noundef %39, i64 noundef %40)
  %41 = load ptr, ptr %18, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.graphdef, ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !18
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.graphdef, ptr %44, i32 0, i32 0
  %46 = load i64, ptr %45, align 8, !tbaa !18
  %47 = icmp ne i64 %43, %46
  br i1 %47, label %48, label %55

48:                                               ; preds = %37
  %49 = load ptr, ptr %18, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.graphdef, ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !18
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.graphdef, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %53, align 8, !tbaa !18
  call void (ptr, ...) @errexit(ptr noundef @.str.1, i64 noundef %51, i64 noundef %54)
  br label %55

55:                                               ; preds = %48, %37
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %77, %55
  %57 = load i64, ptr %13, align 8, !tbaa !9
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.graphdef, ptr %58, i32 0, i32 0
  %60 = load i64, ptr %59, align 8, !tbaa !18
  %61 = icmp slt i64 %57, %60
  br i1 %61, label %62, label %80

62:                                               ; preds = %56
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load i64, ptr %13, align 8, !tbaa !9
  %65 = getelementptr inbounds i64, ptr %63, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !9
  %67 = load ptr, ptr %18, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.graphdef, ptr %67, i32 0, i32 18
  %69 = load ptr, ptr %68, align 8, !tbaa !21
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.graphdef, ptr %70, i32 0, i32 15
  %72 = load ptr, ptr %71, align 8, !tbaa !22
  %73 = load i64, ptr %13, align 8, !tbaa !9
  %74 = getelementptr inbounds i64, ptr %72, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = getelementptr inbounds i64, ptr %69, i64 %75
  store i64 %66, ptr %76, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %62
  %78 = load i64, ptr %13, align 8, !tbaa !9
  %79 = add nsw i64 %78, 1
  store i64 %79, ptr %13, align 8, !tbaa !9
  br label %56, !llvm.loop !23

80:                                               ; preds = %56
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load ptr, ptr %18, align 8, !tbaa !5
  %84 = load i64, ptr %9, align 8, !tbaa !9
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = load float, ptr %12, align 4, !tbaa !11
  call void @RefineKWayRefinement(ptr noundef %81, ptr noundef %82, ptr noundef %83, i64 noundef %84, ptr noundef %85, float noundef %86)
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.graphdef, ptr %88, i32 0, i32 18
  %90 = load ptr, ptr %89, align 8, !tbaa !21
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.graphdef, ptr %91, i32 0, i32 0
  %93 = load i64, ptr %92, align 8, !tbaa !18
  %94 = mul i64 8, %93
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %87, ptr align 1 %90, i64 %94, i1 false)
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  call void @libmetis__FreeGraph(ptr noundef %95, i32 noundef 0)
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.graphdef, ptr %96, i32 0, i32 16
  %98 = load i64, ptr %97, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 80, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret i64 %98
}

declare ptr @libmetis__Coarsen2Way(ptr noundef, ptr noundef) #1

declare void @libmetis__AllocateKWayPartitionMemory(ptr noundef, ptr noundef, i64 noundef) #1

declare void @errexit(ptr noundef, ...) #1

declare void @RefineKWayRefinement(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, float noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"controldef", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !12, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !15, i64 88, !16, i64 152, !16, i64 160, !16, i64 168, !16, i64 176, !16, i64 184, !16, i64 192, !16, i64 200, !16, i64 208, !16, i64 216, !16, i64 224, !16, i64 232, !16, i64 240, !16, i64 248, !16, i64 256, !16, i64 264, !16, i64 272}
!15 = !{!"workspacedef", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 56}
!16 = !{!"double", !7, i64 0}
!17 = !{!14, !16, i64 160}
!18 = !{!19, !10, i64 0}
!19 = !{!"graphdef", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !20, i64 56, !20, i64 60, !20, i64 64, !20, i64 68, !20, 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}
!20 = !{!"int", !7, i64 0}
!21 = !{!19, !6, i64 128}
!22 = !{!19, !6, i64 104}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!19, !10, i64 112}


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

@.str.1 = external hidden unnamed_addr constant [22 x i8], align 1

declare double @gk_CPUSeconds() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @MlevelKWayRefinement(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef %3, ptr noundef %4, float noundef %5) local_unnamed_addr #1 {
  %7 = tail call ptr @libmetis__Coarsen2Way(ptr noundef %0, ptr noundef %1) #3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = and i64 %9, 1
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %16, label %11

11:                                               ; preds = %6
  %12 = tail call double @gk_CPUSeconds() #3
  %13 = getelementptr inbounds i8, ptr %0, i64 160
  %14 = load double, ptr %13, align 8, !tbaa !14
  %15 = fsub double %14, %12
  store double %15, ptr %13, align 8, !tbaa !14
  br label %16

16:                                               ; preds = %11, %6
  tail call void @libmetis__AllocateKWayPartitionMemory(ptr noundef nonnull %0, ptr noundef %7, i64 noundef %2) #3
  %17 = load i64, ptr %7, align 8, !tbaa !15
  %18 = load i64, ptr %1, align 8, !tbaa !15
  %.not31 = icmp eq i64 %17, %18
  br i1 %.not31, label %20, label %19

19:                                               ; preds = %16
  tail call void (ptr, ...) @errexit(ptr noundef nonnull @.str.1, i64 noundef %17, i64 noundef %18) #3
  %.pre = load i64, ptr %1, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %19, %16
  %21 = phi i64 [ %.pre, %19 ], [ %17, %16 ]
  %22 = icmp sgt i64 %21, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %20
  %23 = getelementptr inbounds i8, ptr %7, i64 128
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %1, i64 104
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  br label %27

27:                                               ; preds = %.lr.ph, %27
  %.032 = phi i64 [ 0, %.lr.ph ], [ %33, %27 ]
  %28 = getelementptr inbounds i64, ptr %3, i64 %.032
  %29 = load i64, ptr %28, align 8, !tbaa !20
  %30 = getelementptr inbounds i64, ptr %26, i64 %.032
  %31 = load i64, ptr %30, align 8, !tbaa !20
  %32 = getelementptr inbounds i64, ptr %24, i64 %31
  store i64 %29, ptr %32, align 8, !tbaa !20
  %33 = add nuw nsw i64 %.032, 1
  %34 = load i64, ptr %1, align 8, !tbaa !15
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %27, label %._crit_edge, !llvm.loop !21

._crit_edge:                                      ; preds = %27, %20
  tail call void @RefineKWayRefinement(ptr noundef %0, ptr noundef nonnull %1, ptr noundef nonnull %7, i64 noundef %2, ptr noundef %4, float noundef %5) #3
  %36 = getelementptr inbounds i8, ptr %1, i64 128
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = load i64, ptr %1, align 8, !tbaa !15
  %39 = shl i64 %38, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 %37, i64 %39, i1 false)
  tail call void @libmetis__FreeGraph(ptr noundef nonnull %1, i32 noundef 0) #3
  %40 = getelementptr inbounds i8, ptr %1, i64 112
  %41 = load i64, ptr %40, align 8, !tbaa !23
  ret i64 %41
}

declare ptr @libmetis__Coarsen2Way(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @libmetis__AllocateKWayPartitionMemory(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @errexit(ptr noundef, ...) local_unnamed_addr #0

declare void @RefineKWayRefinement(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare void @libmetis__FreeGraph(ptr noundef, i32 noundef) local_unnamed_addr #0

attributes #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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 8}
!6 = !{!"controldef", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !11, i64 88, !13, i64 152, !13, i64 160, !13, i64 168, !13, i64 176, !13, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !13, i64 216, !13, i64 224, !13, i64 232, !13, i64 240, !13, i64 248, !13, i64 256, !13, i64 264, !13, i64 272}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"workspacedef", !12, i64 0, !7, i64 8, !7, i64 16, !12, i64 24, !12, i64 32, !7, i64 40, !12, i64 48, !12, i64 56}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!6, !13, i64 160}
!15 = !{!16, !7, i64 0}
!16 = !{!"graphdef", !7, i64 0, !7, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !17, i64 56, !17, i64 60, !17, i64 64, !17, i64 68, !17, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !7, i64 112, !7, i64 120, !12, i64 128, !12, i64 136, !7, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !7, i64 208, !12, i64 216, !12, i64 224, !12, i64 232, !12, i64 240}
!17 = !{!"int", !8, i64 0}
!18 = !{!16, !12, i64 128}
!19 = !{!16, !12, i64 104}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!16, !7, i64 112}


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