; 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.1 = external hidden unnamed_addr constant [17 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 noundef i32 @_ZN15data_structures17queue_using_array11Queue_Array7dequeueEv(ptr noundef nonnull align 2 dereferenceable(22) %0) #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  store i8 0, ptr %4, align 1, !tbaa !9
  %7 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 0
  %8 = load i8, ptr %7, align 2, !tbaa !10
  %9 = sext i8 %8 to i32
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %11, label %13

11:                                               ; preds = %1
  %12 = 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)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %44

13:                                               ; preds = %1
  %14 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 0
  %15 = load i8, ptr %14, align 2, !tbaa !10
  %16 = sext i8 %15 to i32
  %17 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 1
  %18 = load i8, ptr %17, align 1, !tbaa !13
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %16, %19
  br i1 %20, label %21, label %31

21:                                               ; preds = %13
  %22 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 2
  %23 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 0
  %24 = load i8, ptr %23, align 2, !tbaa !10
  %25 = sext i8 %24 to i64
  %26 = call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EE2atEm(ptr noundef nonnull align 2 dereferenceable(20) %22, i64 noundef %25)
  %27 = load i16, ptr %26, align 2, !tbaa !14
  %28 = trunc i16 %27 to i8
  store i8 %28, ptr %4, align 1, !tbaa !9
  %29 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 1
  store i8 -1, ptr %29, align 1, !tbaa !13
  %30 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 0
  store i8 -1, ptr %30, align 2, !tbaa !10
  br label %40

31:                                               ; preds = %13
  %32 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 2
  %33 = getelementptr inbounds %"class.data_structures::queue_using_array::Queue_Array", ptr %6, i32 0, i32 0
  %34 = load i8, ptr %33, align 2, !tbaa !10
  %35 = add i8 %34, 1
  store i8 %35, ptr %33, align 2, !tbaa !10
  %36 = sext i8 %34 to i64
  %37 = call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EE2atEm(ptr noundef nonnull align 2 dereferenceable(20) %32, i64 noundef %36)
  %38 = load i16, ptr %37, align 2, !tbaa !14
  %39 = trunc i16 %38 to i8
  store i8 %39, ptr %4, align 1, !tbaa !9
  br label %40

40:                                               ; preds = %31, %21
  br label %41

41:                                               ; preds = %40
  %42 = load i8, ptr %4, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  store i32 %43, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %44

44:                                               ; preds = %41, %11
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %45 = load i32, ptr %2, align 4
  ret i32 %45
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTSN15data_structures17queue_using_array11Queue_ArrayE", !7, i64 0, !7, i64 1, !12, i64 2}
!12 = !{!"_ZTSSt5arrayIsLm10EE", !7, i64 0}
!13 = !{!11, !7, i64 1}
!14 = !{!15, !15, i64 0}
!15 = !{!"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.1 = external hidden unnamed_addr constant [17 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 noundef range(i32 -128, 128) i32 @_ZN15data_structures17queue_using_array11Queue_Array7dequeueEv(ptr noundef nonnull align 2 dereferenceable(22) %0) local_unnamed_addr #1 align 2 {
  %2 = load i8, ptr %0, align 2, !tbaa !5
  %3 = icmp eq i8 %2, -1
  br i1 %3, label %4, label %6

4:                                                ; preds = %1
  %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 %22

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 1
  %8 = load i8, ptr %7, align 1, !tbaa !10
  %9 = icmp eq i8 %2, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 2
  br i1 %9, label %11, label %15

11:                                               ; preds = %6
  %12 = sext i8 %2 to i64
  %13 = tail call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EE2atEm(ptr noundef nonnull align 2 dereferenceable(20) %10, i64 noundef %12)
  %14 = load i16, ptr %13, align 2, !tbaa !11
  store i8 -1, ptr %7, align 1, !tbaa !10
  store i8 -1, ptr %0, align 2, !tbaa !5
  br label %20

15:                                               ; preds = %6
  %16 = add nuw i8 %2, 1
  store i8 %16, ptr %0, align 2, !tbaa !5
  %17 = sext i8 %2 to i64
  %18 = tail call noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EE2atEm(ptr noundef nonnull align 2 dereferenceable(20) %10, i64 noundef %17)
  %19 = load i16, ptr %18, align 2, !tbaa !11
  br label %20

20:                                               ; preds = %11, %15
  %.0.in = phi i16 [ %14, %11 ], [ %19, %15 ]
  %.0 = zext i16 %.0.in to i32
  %sext = shl i32 %.0, 24
  %21 = ashr exact i32 %sext, 24
  br label %22

22:                                               ; preds = %20, %4
  %.02 = phi i32 [ 0, %4 ], [ %21, %20 ]
  ret i32 %.02
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 2 dereferenceable(2) ptr @_ZNSt5arrayIsLm10EE2atEm(ptr noundef nonnull align 2 dereferenceable(20), i64 noundef) local_unnamed_addr #1 align 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" }

!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 0}
!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 1}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}


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