; LLVM IR from TheAlgorithms/C-Plus-Plus :: data_structures/queue_using_array2.ll (Z5Dequev)

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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@queue = external dso_local global [10 x i32], align 16
@front = external dso_local global i32, align 4
@rear = external dso_local global i32, align 4
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5Dequev() #1 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @front, align 4, !tbaa !5
  %3 = load i32, ptr @rear, align 4, !tbaa !5
  %4 = icmp eq i32 %2, %3
  br i1 %4, label %5, label %7

5:                                                ; preds = %0
  %6 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.1)
  br label %39

7:                                                ; preds = %0
  %8 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.2)
  %9 = load i32, ptr @front, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @front, align 4, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %8, i32 noundef %13)
  %15 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %16 = load i32, ptr @front, align 4, !tbaa !5
  store i32 %16, ptr %1, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %32, %7
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = load i32, ptr @rear, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %35

22:                                               ; preds = %17
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = load i32, ptr @front, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %30
  store i32 %26, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %22
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %1, align 4, !tbaa !5
  br label %17, !llvm.loop !9

35:                                               ; preds = %21
  %36 = load i32, ptr @rear, align 4, !tbaa !5
  %37 = load i32, ptr @front, align 4, !tbaa !5
  %38 = sub nsw i32 %36, %37
  store i32 %38, ptr @rear, align 4, !tbaa !5
  store i32 0, ptr @front, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %35, %5
  ret void
}

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #2

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

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

attributes #0 = { inlinehint mustprogress 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 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 = { "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 nosync 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@queue = external dso_local local_unnamed_addr global [10 x i32], align 16
@front = external dso_local local_unnamed_addr global i32, align 4
@rear = external dso_local local_unnamed_addr global i32, align 4
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5Dequev() local_unnamed_addr #1 {
  %1 = load i32, ptr @front, align 4, !tbaa !5
  %2 = load i32, ptr @rear, align 4, !tbaa !5
  %3 = icmp eq i32 %1, %2
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.1)
  br label %50

6:                                                ; preds = %0
  %7 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.2)
  %8 = load i32, ptr @front, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @front, align 4, !tbaa !5
  %10 = sext i32 %8 to i64
  %11 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %7, i32 noundef %12)
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef nonnull @.str.3)
  %15 = load i32, ptr @front, align 4, !tbaa !5
  %16 = load i32, ptr @rear, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %18 = sext i32 %15 to i64
  %wide.trip.count = sext i32 %16 to i64
  %19 = sub nsw i64 %wide.trip.count, %18
  %min.iters.check = icmp ult i64 %19, 8
  %20 = mul nsw i64 %18, -4
  %diff.check = icmp ult i64 %20, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %.lr.ph.preheader8, label %vector.ph

.lr.ph.preheader8:                                ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ %18, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %21 = sub nsw i64 %wide.trip.count, %indvars.iv.ph
  %xtraiter = and i64 %21, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader8, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader8 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader8 ]
  %22 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %indvars.iv.prol
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sub nsw i64 %indvars.iv.prol, %18
  %25 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %24
  store i32 %23, ptr %25, align 4, !tbaa !5
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !9

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader8
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader8 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %26 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %27 = icmp ugt i64 %26, -4
  br i1 %27, label %._crit_edge, label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %19, -8
  %ind.end = add nsw i64 %n.vec, %18
  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 %index, %18
  %28 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %offset.idx
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %wide.load = load <4 x i32>, ptr %28, align 4, !tbaa !5
  %wide.load7 = load <4 x i32>, ptr %29, align 4, !tbaa !5
  %30 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %index
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  store <4 x i32> %wide.load, ptr %30, align 16, !tbaa !5
  store <4 x i32> %wide.load7, ptr %31, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %19, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader8

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %6
  %33 = sub nsw i32 %16, %15
  store i32 %33, ptr @rear, align 4, !tbaa !5
  store i32 0, ptr @front, align 4, !tbaa !5
  br label %50

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %34 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %indvars.iv
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sub nsw i64 %indvars.iv, %18
  %37 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %36
  store i32 %35, ptr %37, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %38 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %indvars.iv.next
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sub nsw i64 %indvars.iv.next, %18
  %41 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %40
  store i32 %39, ptr %41, align 4, !tbaa !5
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %42 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %indvars.iv.next.1
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sub nsw i64 %indvars.iv.next.1, %18
  %45 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %44
  store i32 %43, ptr %45, align 4, !tbaa !5
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %46 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %indvars.iv.next.2
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sub nsw i64 %indvars.iv.next.2, %18
  %49 = getelementptr inbounds [10 x i32], ptr @queue, i64 0, i64 %48
  store i32 %47, ptr %49, align 4, !tbaa !5
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !15

50:                                               ; preds = %._crit_edge, %4
  ret void
}

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #2

attributes #0 = { inlinehint mustprogress 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 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 = { "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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !13}


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