; LLVM IR from ekoontz/graphlab :: src/graphlab/extern/metis/GKlib (pqueue)

; 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.gk_PQueue_t = type { i32, i32, ptr, ptr }
%struct.gk_fkv_t = type { float, i64 }

; Function Attrs: nounwind uwtable
define dso_local i32 @gk_PQueueInsert(ptr noundef %0, i32 noundef %1, float noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, 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
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gk_PQueue_t, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  store ptr %13, ptr %10, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gk_PQueue_t, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  store ptr %16, ptr %9, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gk_PQueue_t, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 8, !tbaa !16
  store i32 %19, ptr %7, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %56, %3
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %24, label %57

24:                                               ; preds = %21
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = sub nsw i32 %25, 1
  %27 = sdiv i32 %26, 2
  store i32 %27, ptr %8, align 4, !tbaa !9
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.gk_fkv_t, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.gk_fkv_t, ptr %31, i32 0, i32 0
  %33 = load float, ptr %32, align 8, !tbaa !17
  %34 = load float, ptr %6, align 4, !tbaa !11
  %35 = fcmp olt float %33, %34
  br i1 %35, label %36, label %55

36:                                               ; preds = %24
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds %struct.gk_fkv_t, ptr %37, i64 %39
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.gk_fkv_t, ptr %41, i64 %43
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %40, ptr align 8 %44, i64 16, i1 false), !tbaa.struct !20
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.gk_fkv_t, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.gk_fkv_t, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !22
  %53 = getelementptr inbounds i32, ptr %46, i64 %52
  store i32 %45, ptr %53, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %56

55:                                               ; preds = %24
  br label %57

56:                                               ; preds = %36
  br label %21, !llvm.loop !23

57:                                               ; preds = %55, %21
  %58 = load float, ptr %6, align 4, !tbaa !11
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.gk_fkv_t, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.gk_fkv_t, ptr %62, i32 0, i32 0
  store float %58, ptr %63, align 8, !tbaa !17
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.gk_fkv_t, ptr %66, i64 %68
  %70 = getelementptr inbounds %struct.gk_fkv_t, ptr %69, i32 0, i32 1
  store i64 %65, ptr %70, align 8, !tbaa !22
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr %72, i64 %74
  store i32 %71, ptr %75, align 4, !tbaa !9
  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 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 16}
!16 = !{!14, !10, i64 0}
!17 = !{!18, !12, i64 0}
!18 = !{!"", !12, i64 0, !19, i64 8}
!19 = !{!"long", !7, i64 0}
!20 = !{i64 0, i64 4, !11, i64 8, i64 8, !21}
!21 = !{!19, !19, i64 0}
!22 = !{!18, !19, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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"

%struct.gk_fkv_t = type { float, i64 }

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @gk_PQueueInsert(ptr nocapture noundef %0, i32 noundef %1, float noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = load i32, ptr %0, align 8, !tbaa !12
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %0, align 8, !tbaa !12
  %10 = icmp sgt i32 %8, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %17
  %.025 = phi i32 [ %12, %17 ], [ %8, %3 ]
  %11 = add nsw i32 %.025, -1
  %12 = lshr i32 %11, 1
  %13 = zext nneg i32 %12 to i64
  %14 = getelementptr inbounds %struct.gk_fkv_t, ptr %5, i64 %13
  %15 = load float, ptr %14, align 8, !tbaa !13
  %16 = fcmp olt float %15, %2
  br i1 %16, label %17, label %._crit_edge

17:                                               ; preds = %.lr.ph
  %18 = zext nneg i32 %.025 to i64
  %19 = getelementptr inbounds %struct.gk_fkv_t, ptr %5, i64 %18
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %19, ptr noundef nonnull align 8 dereferenceable(16) %14, i64 16, i1 false), !tbaa.struct !17
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !20
  %22 = getelementptr inbounds i32, ptr %7, i64 %21
  store i32 %.025, ptr %22, align 4, !tbaa !21
  %.not = icmp ult i32 %11, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %17, %.lr.ph, %3
  %.0.lcssa = phi i32 [ %8, %3 ], [ %.025, %.lr.ph ], [ %12, %17 ]
  %23 = sext i32 %.0.lcssa to i64
  %24 = getelementptr inbounds %struct.gk_fkv_t, ptr %5, i64 %23
  store float %2, ptr %24, align 8, !tbaa !13
  %25 = sext i32 %1 to i64
  %26 = getelementptr inbounds i8, ptr %24, i64 8
  store i64 %25, ptr %26, align 8, !tbaa !20
  %27 = getelementptr inbounds i32, ptr %7, i64 %25
  store i32 %.0.lcssa, ptr %27, align 4, !tbaa !21
  ret i32 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) #1

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !16, i64 8}
!15 = !{!"float", !8, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{i64 0, i64 4, !18, i64 8, i64 8, !19}
!18 = !{!15, !15, i64 0}
!19 = !{!16, !16, i64 0}
!20 = !{!14, !16, i64 8}
!21 = !{!7, !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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