; LLVM IR from TheAlgorithms/C-Plus-Plus :: data_structures (queue_using_array)

; 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 }
%"class.data_structures::queue_using_array::Queue_Array" = type { i8, i8, %"struct.std::array" }
%"struct.std::array" = type { [10 x i16] }

@_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 @_ZN15data_structures17queue_using_array11Queue_Array7enqueueERKs(ptr noundef nonnull align 2 dereferenceable(22) %0, ptr noundef nonnull align 2 dereferenceable(2) %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 1
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = sext i8 %7 to i64
  %9 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 2
  %10 = call noundef i64 @_ZNKSt5arrayIsLm10EE4sizeEv(ptr noundef nonnull align 2 dereferenceable(20) %9) #4
  %11 = sub i64 %10, 1
  %12 = icmp eq i64 %8, %11
  br i1 %12, label %13, label %15

13:                                               ; preds = %2
  %14 = 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 %55

15:                                               ; preds = %2
  %16 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 0
  %17 = load i8, ptr %16, align 2, !tbaa !12
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, -1
  br i1 %19, label %20, label %35

20:                                               ; preds = %15
  %21 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 1
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %25, label %35

25:                                               ; preds = %20
  %26 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 0
  store i8 0, ptr %26, align 2, !tbaa !12
  %27 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 1
  store i8 0, ptr %27, align 1, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i16, ptr %28, align 2, !tbaa !13
  %30 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 2
  %31 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 1
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i64
  %34 = call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EEixEm(ptr noundef nonnull align 2 dereferenceable(20) %30, i64 noundef %33) #5
  store i16 %29, ptr %34, align 2, !tbaa !13
  br label %54

35:                                               ; preds = %20, %15
  %36 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 1
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %38 = sext i8 %37 to i64
  %39 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 2
  %40 = call noundef i64 @_ZNKSt5arrayIsLm10EE4sizeEv(ptr noundef nonnull align 2 dereferenceable(20) %39) #4
  %41 = icmp ult i64 %38, %40
  br i1 %41, label %42, label %53

42:                                               ; preds = %35
  %43 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 1
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = add i8 %44, 1
  store i8 %45, ptr %43, align 1, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i16, ptr %46, align 2, !tbaa !13
  %48 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 2
  %49 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %5, i32 0, i32 1
  %50 = load i8, ptr %49, align 1, !tbaa !9
  %51 = sext i8 %50 to i64
  %52 = call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EEixEm(ptr noundef nonnull align 2 dereferenceable(20) %48, i64 noundef %51) #5
  store i16 %47, ptr %52, align 2, !tbaa !13
  br label %53

53:                                               ; preds = %42, %35
  br label %54

54:                                               ; preds = %53, %25
  br label %55

55:                                               ; preds = %54, %13
  ret void
}

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef i64 @_ZNKSt5arrayIsLm10EE4sizeEv(ptr noundef nonnull align 2 dereferenceable(20)) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EEixEm(ptr noundef nonnull align 2 dereferenceable(20), i64 noundef) #3 align 2

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 = { mustprogress nounwind willreturn memory(none) 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 = { 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 #3 = { mustprogress 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 #4 = { nounwind willreturn memory(none) }
attributes #5 = { 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++ TBAA"}
!9 = !{!10, !7, i64 1}
!10 = !{!"_ZTSN15data_structures17queue_using_array11Queue_ArrayE", !7, i64 0, !7, i64 1, !11, i64 2}
!11 = !{!"_ZTSSt5arrayIsLm10EE", !7, i64 0}
!12 = !{!10, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}


; 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 @_ZN15data_structures17queue_using_array11Queue_Array7enqueueERKs(ptr noundef nonnull align 2 dereferenceable(22) %0, ptr nocapture noundef nonnull readonly align 2 dereferenceable(2) %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 1
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = sext i8 %4 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 2
  %7 = tail call noundef i64 @_ZNKSt5arrayIsLm10EE4sizeEv(ptr noundef nonnull align 2 dereferenceable(20) %6) #4
  %8 = add i64 %7, -1
  %9 = icmp eq i64 %8, %5
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = 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 %25

12:                                               ; preds = %2
  %13 = load i8, ptr %0, align 2, !tbaa !10
  %14 = and i8 %13, %4
  %or.cond = icmp eq i8 %14, -1
  br i1 %or.cond, label %15, label %18

15:                                               ; preds = %12
  store i8 0, ptr %0, align 2, !tbaa !10
  store i8 0, ptr %3, align 1, !tbaa !5
  %16 = load i16, ptr %1, align 2, !tbaa !11
  %17 = tail call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EEixEm(ptr noundef nonnull align 2 dereferenceable(20) %6, i64 noundef 0) #5
  store i16 %16, ptr %17, align 2, !tbaa !11
  br label %25

18:                                               ; preds = %12
  %19 = icmp ugt i64 %7, %5
  br i1 %19, label %20, label %25

20:                                               ; preds = %18
  %21 = add i8 %4, 1
  store i8 %21, ptr %3, align 1, !tbaa !5
  %22 = load i16, ptr %1, align 2, !tbaa !11
  %23 = sext i8 %21 to i64
  %24 = tail call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EEixEm(ptr noundef nonnull align 2 dereferenceable(20) %6, i64 noundef %23) #5
  store i16 %22, ptr %24, align 2, !tbaa !11
  br label %25

25:                                               ; preds = %15, %20, %18, %10
  ret void
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef i64 @_ZNKSt5arrayIsLm10EE4sizeEv(ptr noundef nonnull align 2 dereferenceable(20)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EEixEm(ptr noundef nonnull align 2 dereferenceable(20), i64 noundef) local_unnamed_addr #3 align 2

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 = { mustprogress nofree nosync nounwind willreturn memory(none) 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 = { 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 #3 = { mustprogress 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 #4 = { nounwind willreturn memory(none) }
attributes #5 = { 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 1}
!6 = !{!"_ZTSN15data_structures17queue_using_array11Queue_ArrayE", !7, i64 0, !7, i64 1, !9, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"_ZTSSt5arrayIsLm10EE", !7, i64 0}
!10 = !{!6, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass