; LLVM IR from FOSS-UCSC/FOSSALGO :: data-structures/ds-cque/cpp/circular_queue.ll (Z8insertCQi)

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

@cqueue = external dso_local global [5 x i32], align 16
@front = external dso_local global i32, align 4
@rear = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8insertCQi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr @front, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %10

5:                                                ; preds = %1
  %6 = load i32, ptr @rear, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sub nsw i32 %7, 1
  %9 = icmp eq i32 %6, %8
  br i1 %9, label %15, label %10

10:                                               ; preds = %5, %1
  %11 = load i32, ptr @front, align 4, !tbaa !5
  %12 = load i32, ptr @rear, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %10, %5
  %16 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str)
  br label %36

17:                                               ; preds = %10
  %18 = load i32, ptr @front, align 4, !tbaa !5
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i32 0, ptr @front, align 4, !tbaa !5
  store i32 0, ptr @rear, align 4, !tbaa !5
  br label %31

21:                                               ; preds = %17
  %22 = load i32, ptr @rear, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = icmp eq i32 %22, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 0, ptr @rear, align 4, !tbaa !5
  br label %30

27:                                               ; preds = %21
  %28 = load i32, ptr @rear, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @rear, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %27, %26
  br label %31

31:                                               ; preds = %30, %20
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr @rear, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [5 x i32], ptr @cqueue, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %31, %15
  ret void
}

; 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) #1

attributes #0 = { 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 = { 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" }

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


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

@cqueue = external dso_local local_unnamed_addr global [5 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
@n = external dso_local local_unnamed_addr global i32, align 4
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [17 x i8], align 1

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

5:                                                ; preds = %1
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  %8 = icmp eq i32 %4, %7
  %9 = add nsw i32 %4, 1
  %10 = icmp eq i32 %9, 0
  %or.cond = select i1 %8, i1 true, i1 %10
  br i1 %or.cond, label %14, label %.thread2

11:                                               ; preds = %1
  %12 = add nsw i32 %4, 1
  %13 = icmp eq i32 %2, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %11, %5
  %15 = 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)
  br label %27

16:                                               ; preds = %11
  %17 = icmp eq i32 %2, -1
  br i1 %17, label %18, label %..thread2_crit_edge

..thread2_crit_edge:                              ; preds = %16
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  %.pre3 = add nsw i32 %.pre, -1
  br label %.thread2

18:                                               ; preds = %16
  store i32 0, ptr @front, align 4, !tbaa !5
  store i32 0, ptr @rear, align 4, !tbaa !5
  br label %24

.thread2:                                         ; preds = %5, %..thread2_crit_edge
  %.pre-phi = phi i32 [ %.pre3, %..thread2_crit_edge ], [ %7, %5 ]
  %19 = phi i32 [ %12, %..thread2_crit_edge ], [ %9, %5 ]
  %20 = icmp eq i32 %4, %.pre-phi
  br i1 %20, label %21, label %22

21:                                               ; preds = %.thread2
  store i32 0, ptr @rear, align 4, !tbaa !5
  br label %24

22:                                               ; preds = %.thread2
  store i32 %19, ptr @rear, align 4, !tbaa !5
  %23 = sext i32 %19 to i64
  br label %24

24:                                               ; preds = %21, %22, %18
  %25 = phi i64 [ 0, %21 ], [ %23, %22 ], [ 0, %18 ]
  %26 = getelementptr inbounds [5 x i32], ptr @cqueue, i64 0, i64 %25
  store i32 %0, ptr %26, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %24, %14
  ret void
}

; 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 #1

attributes #0 = { 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 = { 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" }

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass