; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C/Data-Structures/Queue (Priority_queue)

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

@rear = external dso_local global i32, align 4
@front = external dso_local global i32, align 4
@pri_que = external dso_local global [5 x i32], align 16
@.str.10 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [33 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @delete_by_priority(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = load i32, ptr @front, align 4, !tbaa !5
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %7, label %12

7:                                                ; preds = %1
  %8 = load i32, ptr @rear, align 4, !tbaa !5
  %9 = icmp eq i32 %8, -1
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  store i32 1, ptr %4, align 4
  br label %58

12:                                               ; preds = %7, %1
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %52, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @rear, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %55

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp eq i32 %18, %22
  br i1 %23, label %24, label %51

24:                                               ; preds = %17
  br label %25

25:                                               ; preds = %38, %24
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr @rear, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %41

29:                                               ; preds = %25
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %29
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %3, align 4, !tbaa !5
  br label %25, !llvm.loop !9

41:                                               ; preds = %25
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %43
  store i32 -99, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr @rear, align 4, !tbaa !5
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr @rear, align 4, !tbaa !5
  %47 = load i32, ptr @rear, align 4, !tbaa !5
  %48 = icmp eq i32 %47, -1
  br i1 %48, label %49, label %50

49:                                               ; preds = %41
  store i32 -1, ptr @front, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %49, %41
  store i32 1, ptr %4, align 4
  br label %58

51:                                               ; preds = %17
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !11

55:                                               ; preds = %13
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, i32 noundef %56)
  store i32 0, ptr %4, align 4
  br label %58

58:                                               ; preds = %55, %50, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %59 = load i32, ptr %4, align 4
  switch i32 %59, label %61 [
    i32 0, label %60
    i32 1, label %60
  ]

60:                                               ; preds = %58, %58
  ret void

61:                                               ; preds = %58
  unreachable
}

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

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@rear = external dso_local local_unnamed_addr global i32, align 4
@front = external dso_local local_unnamed_addr global i32, align 4
@pri_que = external dso_local local_unnamed_addr global [5 x i32], align 16
@.str.10 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @delete_by_priority(i32 noundef %0) local_unnamed_addr #1 {
  %2 = load i32, ptr @front, align 4, !tbaa !5
  %3 = icmp eq i32 %2, -1
  %4 = load i32, ptr @rear, align 4
  %5 = icmp eq i32 %4, -1
  %or.cond = select i1 %3, i1 %5, i1 false
  br i1 %or.cond, label %7, label %.preheader11

.preheader11:                                     ; preds = %1
  %.not13 = icmp slt i32 %4, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader11
  %6 = add nuw i32 %4, 1
  %wide.trip.count = zext i32 %6 to i64
  br label %.lr.ph

7:                                                ; preds = %1
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  br label %30

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %28 ]
  %9 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, %0
  br i1 %11, label %.preheader, label %28

.preheader:                                       ; preds = %.lr.ph
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = icmp sgt i32 %4, %12
  br i1 %13, label %.lr.ph16.preheader, label %.preheader.._crit_edge17_crit_edge

.preheader.._crit_edge17_crit_edge:               ; preds = %.preheader
  %.pre = and i64 %indvars.iv, 4294967295
  br label %._crit_edge17

.lr.ph16.preheader:                               ; preds = %.preheader
  %wide.trip.count26 = zext nneg i32 %4 to i64
  %14 = sub nsw i64 %wide.trip.count26, %indvars.iv
  %min.iters.check = icmp ult i64 %14, 8
  br i1 %min.iters.check, label %.lr.ph16.preheader33, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph16.preheader
  %n.vec = and i64 %14, -8
  %ind.end = add i64 %indvars.iv, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %indvars.iv, %index
  %15 = add nuw nsw i64 %offset.idx, 1
  %16 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %wide.load = load <4 x i32>, ptr %16, align 4, !tbaa !5
  %wide.load32 = load <4 x i32>, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %offset.idx
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  store <4 x i32> %wide.load, ptr %18, align 4, !tbaa !5
  store <4 x i32> %wide.load32, ptr %19, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %14, %n.vec
  br i1 %cmp.n, label %._crit_edge17, label %.lr.ph16.preheader33

.lr.ph16.preheader33:                             ; preds = %middle.block, %.lr.ph16.preheader
  %indvars.iv23.ph = phi i64 [ %indvars.iv, %.lr.ph16.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph16

.lr.ph16:                                         ; preds = %.lr.ph16.preheader33, %.lr.ph16
  %indvars.iv23 = phi i64 [ %indvars.iv.next24, %.lr.ph16 ], [ %indvars.iv23.ph, %.lr.ph16.preheader33 ]
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %21 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %indvars.iv.next24
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %indvars.iv23
  store i32 %22, ptr %23, align 4, !tbaa !5
  %exitcond27.not = icmp eq i64 %indvars.iv.next24, %wide.trip.count26
  br i1 %exitcond27.not, label %._crit_edge17, label %.lr.ph16, !llvm.loop !13

._crit_edge17:                                    ; preds = %.lr.ph16, %middle.block, %.preheader.._crit_edge17_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader.._crit_edge17_crit_edge ], [ %wide.trip.count26, %middle.block ], [ %wide.trip.count26, %.lr.ph16 ]
  %24 = getelementptr inbounds [5 x i32], ptr @pri_que, i64 0, i64 %.pre-phi
  store i32 -99, ptr %24, align 4, !tbaa !5
  %25 = add nsw i32 %4, -1
  store i32 %25, ptr @rear, align 4, !tbaa !5
  %26 = icmp eq i32 %4, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %._crit_edge17
  store i32 -1, ptr @front, align 4, !tbaa !5
  br label %30

28:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %28, %.preheader11
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11, i32 noundef %0)
  br label %30

30:                                               ; preds = %._crit_edge17, %27, %._crit_edge, %7
  ret void
}

attributes #0 = { nofree nounwind "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 = { nofree 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}


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