; LLVM IR from amritansh22/Data-Structures-and-Algorithms-in-cpp :: circular_queue_using_array.ll (ZN5Queue7enQueueEi)

; 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 }
%struct.Queue = type { i32, i32, i32, ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Queue7enQueueEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %16

9:                                                ; preds = %2
  %10 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = sub nsw i32 %13, 1
  %15 = icmp eq i32 %11, %14
  br i1 %15, label %27, label %16

16:                                               ; preds = %9, %2
  %17 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = sub nsw i32 %20, 1
  %22 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = sub nsw i32 %23, 1
  %25 = srem i32 %21, %24
  %26 = icmp eq i32 %18, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %16, %9
  %28 = 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 %76

29:                                               ; preds = %16
  %30 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = icmp eq i32 %31, -1
  br i1 %32, label %33, label %43

33:                                               ; preds = %29
  %34 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  store i32 0, ptr %34, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 1
  store i32 0, ptr %35, align 4, !tbaa !11
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !13
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %38, i64 %41
  store i32 %36, ptr %42, align 4, !tbaa !9
  br label %75

43:                                               ; preds = %29
  %44 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !13
  %46 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !14
  %48 = sub nsw i32 %47, 1
  %49 = icmp eq i32 %45, %48
  br i1 %49, label %50, label %63

50:                                               ; preds = %43
  %51 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %63

54:                                               ; preds = %50
  %55 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  store i32 0, ptr %55, align 8, !tbaa !13
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %58, i64 %61
  store i32 %56, ptr %62, align 4, !tbaa !9
  br label %74

63:                                               ; preds = %50, %43
  %64 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !13
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %64, align 8, !tbaa !13
  %67 = load i32, ptr %4, align 4, !tbaa !9
  %68 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = getelementptr inbounds %struct.Queue, ptr %5, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !13
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %69, i64 %72
  store i32 %67, ptr %73, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %63, %54
  br label %75

75:                                               ; preds = %74, %33
  br label %76

76:                                               ; preds = %75, %27
  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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTS5Queue", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 16}


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

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Queue7enQueueEi(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  %.pre = load i32, ptr %0, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = add nsw i32 %7, -1
  br i1 %5, label %9, label %11

9:                                                ; preds = %2
  %10 = icmp eq i32 %.pre, %8
  br i1 %10, label %17, label %.thread

11:                                               ; preds = %2
  %12 = add nsw i32 %4, -1
  %13 = srem i32 %12, %8
  %14 = icmp eq i32 %.pre, %13
  br i1 %14, label %17, label %19

.thread:                                          ; preds = %9
  %15 = srem i32 -1, %8
  %16 = icmp eq i32 %.pre, %15
  br i1 %16, label %17, label %.thread11

17:                                               ; preds = %.thread, %11, %9
  %18 = 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 %34

19:                                               ; preds = %11
  %20 = icmp eq i32 %4, -1
  br i1 %20, label %21, label %24

21:                                               ; preds = %19
  store i32 0, ptr %0, align 8, !tbaa !11
  store i32 0, ptr %3, align 4, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  store i32 %1, ptr %23, align 4, !tbaa !14
  br label %34

24:                                               ; preds = %19
  %25 = icmp ne i32 %.pre, %8
  %or.cond = or i1 %5, %25
  br i1 %or.cond, label %.thread11, label %26

26:                                               ; preds = %24
  store i32 0, ptr %0, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store i32 %1, ptr %28, align 4, !tbaa !14
  br label %34

.thread11:                                        ; preds = %.thread, %24
  %29 = add nsw i32 %.pre, 1
  store i32 %29, ptr %0, align 8, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = sext i32 %29 to i64
  %33 = getelementptr inbounds i32, ptr %31, i64 %32
  store i32 %1, ptr %33, align 4, !tbaa !14
  br label %34

34:                                               ; preds = %21, %.thread11, %26, %17
  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, !7, i64 4}
!6 = !{!"_ZTS5Queue", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 16}
!14 = !{!7, !7, i64 0}


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