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

; Function Attrs: nounwind uwtable
declare dso_local i32 @gk_PQueueSeeMaxVal(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @gk_PQueueSeeConstraintMax(ptr noundef %0, float noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.gk_PQueue_t, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

15:                                               ; preds = %3
  %16 = load float, ptr %6, align 4, !tbaa !9
  %17 = fcmp ole float %16, 1.000000e+03
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @gk_PQueueSeeMaxVal(ptr noundef %19)
  store i32 %20, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

21:                                               ; preds = %15
  store i32 0, ptr %8, align 4, !tbaa !14
  br label %22

22:                                               ; preds = %78, %21
  %23 = load i32, ptr %8, align 4, !tbaa !14
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.gk_PQueue_t, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %28, label %81

28:                                               ; preds = %22
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gk_PQueue_t, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = load i32, ptr %8, align 4, !tbaa !14
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.gk_fkv_t, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.gk_fkv_t, ptr %34, i32 0, i32 0
  %36 = load float, ptr %35, align 8, !tbaa !16
  %37 = fcmp ogt float %36, 0.000000e+00
  br i1 %37, label %38, label %64

38:                                               ; preds = %28
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.gk_PQueue_t, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load i32, ptr %8, align 4, !tbaa !14
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.gk_fkv_t, ptr %42, i64 %44
  %46 = getelementptr inbounds %struct.gk_fkv_t, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !19
  %48 = getelementptr inbounds double, ptr %39, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !20
  %50 = load float, ptr %6, align 4, !tbaa !9
  %51 = fpext float %50 to double
  %52 = fcmp ole double %49, %51
  br i1 %52, label %53, label %63

53:                                               ; preds = %38
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.gk_PQueue_t, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = load i32, ptr %8, align 4, !tbaa !14
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds %struct.gk_fkv_t, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct.gk_fkv_t, ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !19
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

63:                                               ; preds = %38
  br label %77

64:                                               ; preds = %28
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gk_PQueue_t, ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = load i32, ptr %8, align 4, !tbaa !14
  %69 = sdiv i32 %68, 2
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds %struct.gk_fkv_t, ptr %67, i64 %70
  %72 = getelementptr inbounds %struct.gk_fkv_t, ptr %71, i32 0, i32 0
  %73 = load float, ptr %72, align 8, !tbaa !16
  %74 = fcmp ole float %73, 0.000000e+00
  br i1 %74, label %75, label %76

75:                                               ; preds = %64
  br label %81

76:                                               ; preds = %64
  br label %77

77:                                               ; preds = %76, %63
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %8, align 4, !tbaa !14
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %8, align 4, !tbaa !14
  br label %22, !llvm.loop !22

81:                                               ; preds = %75, %22
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.gk_PQueue_t, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !15
  %85 = getelementptr inbounds %struct.gk_fkv_t, ptr %84, i64 0
  %86 = getelementptr inbounds %struct.gk_fkv_t, ptr %85, i32 0, i32 1
  %87 = load i64, ptr %86, align 8, !tbaa !19
  %88 = trunc i64 %87 to i32
  store i32 %88, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %89

89:                                               ; preds = %81, %53, %18, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %90 = load i32, ptr %4, align 4
  ret i32 %90
}

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 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !18, i64 8}
!18 = !{!"long", !7, i64 0}
!19 = !{!17, !18, i64 8}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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: nounwind uwtable
declare dso_local i32 @gk_PQueueSeeMaxVal(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @gk_PQueueSeeConstraintMax(ptr noundef %0, float noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %38, label %6

6:                                                ; preds = %3
  %7 = fcmp ugt float %1, 1.000000e+03
  br i1 %7, label %.preheader, label %12

.preheader:                                       ; preds = %6
  %8 = icmp sgt i32 %4, 0
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %11 = fpext float %1 to double
  br label %.backedge

12:                                               ; preds = %6
  %13 = tail call i32 @gk_PQueueSeeMaxVal(ptr noundef nonnull %0)
  br label %38

.backedge:                                        ; preds = %.backedge.backedge, %.lr.ph
  %.019 = phi i32 [ 0, %.lr.ph ], [ %.019.be, %.backedge.backedge ]
  %14 = zext nneg i32 %.019 to i64
  %15 = getelementptr inbounds %struct.gk_fkv_t, ptr %10, i64 %14
  %16 = load float, ptr %15, align 8, !tbaa !12
  %17 = fcmp ogt float %16, 0.000000e+00
  br i1 %17, label %18, label %26

18:                                               ; preds = %.backedge
  %19 = getelementptr inbounds i8, ptr %15, i64 8
  %20 = load i64, ptr %19, align 8, !tbaa !16
  %21 = getelementptr inbounds double, ptr %2, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !17
  %23 = fcmp ugt double %22, %11
  br i1 %23, label %34, label %24

24:                                               ; preds = %18
  %25 = trunc i64 %20 to i32
  br label %38

26:                                               ; preds = %.backedge
  %27 = lshr i32 %.019, 1
  %28 = zext nneg i32 %27 to i64
  %29 = getelementptr inbounds %struct.gk_fkv_t, ptr %10, i64 %28
  %30 = load float, ptr %29, align 8, !tbaa !12
  %31 = fcmp ugt float %30, 0.000000e+00
  %32 = add nuw nsw i32 %.019, 1
  %33 = icmp slt i32 %32, %4
  %or.cond = select i1 %31, i1 %33, i1 false
  br i1 %or.cond, label %.backedge.backedge, label %._crit_edge

34:                                               ; preds = %18
  %.old = add nuw nsw i32 %.019, 1
  %.old21 = icmp slt i32 %.old, %4
  br i1 %.old21, label %.backedge.backedge, label %._crit_edge

.backedge.backedge:                               ; preds = %34, %26
  %.019.be = phi i32 [ %.old, %34 ], [ %32, %26 ]
  br label %.backedge, !llvm.loop !19

._crit_edge:                                      ; preds = %34, %26, %.preheader
  %35 = getelementptr inbounds i8, ptr %10, i64 8
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = trunc i64 %36 to i32
  br label %38

38:                                               ; preds = %3, %._crit_edge, %24, %12
  %.017 = phi i32 [ %13, %12 ], [ %25, %24 ], [ %37, %._crit_edge ], [ -1, %3 ]
  ret i32 %.017
}

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

!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 = !{!"", !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 8}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !15, i64 8}
!14 = !{!"float", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!13, !15, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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