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

; 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.PQueueType = type { i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr }

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

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

; 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
define dso_local void @libmetis__PQueueReset(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.PQueueType, ptr %5, i32 0, i32 1
  store i64 0, ptr %6, align 8, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.PQueueType, ptr %7, i32 0, i32 0
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %10 = icmp eq i64 %9, 1
  br i1 %10, label %11, label %55

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.PQueueType, ptr %12, i32 0, i32 5
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = sub nsw i64 0, %14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.PQueueType, ptr %16, i32 0, i32 6
  store i64 %15, ptr %17, align 8, !tbaa !14
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.PQueueType, ptr %18, i32 0, i32 5
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.PQueueType, ptr %21, i32 0, i32 4
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = add nsw i64 %20, %23
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %4, align 8, !tbaa !16
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.PQueueType, ptr %26, i32 0, i32 5
  %28 = load i64, ptr %27, align 8, !tbaa !13
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.PQueueType, ptr %29, i32 0, i32 8
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = sub i64 0, %28
  %33 = getelementptr inbounds ptr, ptr %31, i64 %32
  store ptr %33, ptr %30, align 8, !tbaa !17
  store i64 0, ptr %3, align 8, !tbaa !16
  br label %34

34:                                               ; preds = %44, %11
  %35 = load i64, ptr %3, align 8, !tbaa !16
  %36 = load i64, ptr %4, align 8, !tbaa !16
  %37 = icmp slt i64 %35, %36
  br i1 %37, label %38, label %47

38:                                               ; preds = %34
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PQueueType, ptr %39, i32 0, i32 8
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = load i64, ptr %3, align 8, !tbaa !16
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  store ptr null, ptr %43, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %38
  %45 = load i64, ptr %3, align 8, !tbaa !16
  %46 = add nsw i64 %45, 1
  store i64 %46, ptr %3, align 8, !tbaa !16
  br label %34, !llvm.loop !18

47:                                               ; preds = %34
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PQueueType, ptr %48, i32 0, i32 5
  %50 = load i64, ptr %49, align 8, !tbaa !13
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.PQueueType, ptr %51, i32 0, i32 8
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = getelementptr inbounds ptr, ptr %53, i64 %50
  store ptr %54, ptr %52, align 8, !tbaa !17
  br label %63

55:                                               ; preds = %1
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.PQueueType, ptr %56, i32 0, i32 2
  %58 = load i64, ptr %57, align 8, !tbaa !20
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.PQueueType, ptr %59, i32 0, i32 10
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  %62 = call ptr @libmetis__idxset(i64 noundef %58, i64 noundef -1, ptr noundef %61)
  br label %63

63:                                               ; preds = %55, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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 = { 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, !11, i64 8}
!10 = !{!"PQueueType", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!10, !11, i64 40}
!14 = !{!10, !11, i64 48}
!15 = !{!10, !11, i64 32}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !6, i64 64}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !11, i64 16}
!21 = !{!10, !6, i64 80}


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

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

; Function Attrs: nounwind uwtable
define dso_local void @libmetis__PQueueReset(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 0, ptr %2, align 8, !tbaa !5
  %3 = load i64, ptr %0, align 8, !tbaa !11
  %4 = icmp eq i64 %3, 1
  br i1 %4, label %5, label %36

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = sub i64 0, %7
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %8, ptr %9, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %12 = add i64 %11, %7
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds ptr, ptr %14, i64 %8
  store ptr %15, ptr %13, align 8, !tbaa !15
  %.not16 = icmp slt i64 %12, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %16 = add i64 %11, %7
  %17 = add i64 %16, 1
  %xtraiter = and i64 %17, 3
  %18 = icmp ult i64 %12, 3
  br i1 %18, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %17, -4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.017 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %30, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %19 = load ptr, ptr %13, align 8, !tbaa !15
  %20 = getelementptr inbounds ptr, ptr %19, i64 %.017
  store ptr null, ptr %20, align 8, !tbaa !16
  %21 = or disjoint i64 %.017, 1
  %22 = load ptr, ptr %13, align 8, !tbaa !15
  %23 = getelementptr inbounds ptr, ptr %22, i64 %21
  store ptr null, ptr %23, align 8, !tbaa !16
  %24 = or disjoint i64 %.017, 2
  %25 = load ptr, ptr %13, align 8, !tbaa !15
  %26 = getelementptr inbounds ptr, ptr %25, i64 %24
  store ptr null, ptr %26, align 8, !tbaa !16
  %27 = or disjoint i64 %.017, 3
  %28 = load ptr, ptr %13, align 8, !tbaa !15
  %29 = getelementptr inbounds ptr, ptr %28, i64 %27
  store ptr null, ptr %29, align 8, !tbaa !16
  %30 = add nuw i64 %.017, 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 !17

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

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.017.epil = phi i64 [ %33, %.lr.ph.epil ], [ %.017.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %31 = load ptr, ptr %13, align 8, !tbaa !15
  %32 = getelementptr inbounds ptr, ptr %31, i64 %.017.epil
  store ptr null, ptr %32, align 8, !tbaa !16
  %33 = add nuw i64 %.017.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.loopexit, label %.lr.ph.epil, !llvm.loop !19

._crit_edge.loopexit:                             ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa
  %.pre = load ptr, ptr %13, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %5
  %34 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %15, %5 ]
  %35 = getelementptr inbounds ptr, ptr %34, i64 %7
  store ptr %35, ptr %13, align 8, !tbaa !15
  br label %42

36:                                               ; preds = %1
  %37 = getelementptr inbounds i8, ptr %0, i64 16
  %38 = load i64, ptr %37, align 8, !tbaa !21
  %39 = getelementptr inbounds i8, ptr %0, i64 80
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  %41 = tail call ptr @libmetis__idxset(i64 noundef %38, i64 noundef -1, ptr noundef %40) #2
  br label %42

42:                                               ; preds = %36, %._crit_edge
  ret void
}

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 = { 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 = !{!"PQueueType", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 40}
!13 = !{!6, !7, i64 48}
!14 = !{!6, !7, i64 32}
!15 = !{!6, !10, i64 64}
!16 = !{!10, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.unroll.disable"}
!21 = !{!6, !7, i64 16}
!22 = !{!6, !10, i64 80}


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