; LLVM IR from PetarV-/Algorithms :: Data Structures/Bit Queue.ll (ZN8BitQueue4pushEii)

; 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.QueueOverflowException = type { %"class.std::exception" }
%"class.std::exception" = type { ptr }
%class.BitQueue = type { i32, i32 }

@qoverex = external dso_local global %class.QueueOverflowException, align 8
@_ZTI22QueueOverflowException = external dso_local constant { ptr, ptr, ptr }, align 8

; Function Attrs: nounwind
declare void @_ZNSt9exceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8BitQueue4sizeEv(ptr noundef nonnull align 4 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8BitQueue4pushEii(ptr noundef nonnull align 4 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = call noundef i32 @_ZN8BitQueue4sizeEv(ptr noundef nonnull align 4 dereferenceable(8) %7)
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = add nsw i32 %8, %9
  %11 = icmp sgt i32 %10, 32
  br i1 %11, label %12, label %14

12:                                               ; preds = %3
  %13 = call ptr @__cxa_allocate_exception(i64 8) #4
  call void @_ZN22QueueOverflowExceptionC2ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %13, ptr noundef nonnull align 8 dereferenceable(8) @qoverex) #4
  call void @__cxa_throw(ptr %13, ptr @_ZTI22QueueOverflowException, ptr @_ZNSt9exceptionD2Ev) #5
  unreachable

14:                                               ; preds = %3
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = getelementptr inbounds %class.BitQueue, ptr %7, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = shl i32 %17, %15
  store i32 %18, ptr %16, align 4, !tbaa !11
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 32
  br i1 %20, label %21, label %27

21:                                               ; preds = %14
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = shl i32 1, %22
  %24 = sub nsw i32 %23, 1
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = and i32 %25, %24
  store i32 %26, ptr %5, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %21, %14
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = getelementptr inbounds %class.BitQueue, ptr %7, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = or i32 %30, %28
  store i32 %31, ptr %29, align 4, !tbaa !11
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = getelementptr inbounds %class.BitQueue, ptr %7, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = add nsw i32 %34, %32
  store i32 %35, ptr %33, align 4, !tbaa !13
  ret void
}

declare ptr @__cxa_allocate_exception(i64)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN22QueueOverflowExceptionC2ERKS_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

declare void @__cxa_throw(ptr, ptr, ptr)

attributes #0 = { nounwind "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 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 = { 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 = { inlinehint 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 }
attributes #5 = { noreturn }

!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 = !{!"_ZTS8BitQueue", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, 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.QueueOverflowException = type { %"class.std::exception" }
%"class.std::exception" = type { ptr }

@qoverex = external dso_local global %class.QueueOverflowException, align 8
@_ZTI22QueueOverflowException = external dso_local constant { ptr, ptr, ptr }, align 8

; Function Attrs: nounwind
declare void @_ZNSt9exceptionD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8BitQueue4sizeEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8BitQueue4pushEii(ptr noundef nonnull align 4 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = tail call noundef i32 @_ZN8BitQueue4sizeEv(ptr noundef nonnull align 4 dereferenceable(8) %0)
  %5 = add nsw i32 %4, %2
  %6 = icmp sgt i32 %5, 32
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = tail call ptr @__cxa_allocate_exception(i64 8) #4
  tail call void @_ZN22QueueOverflowExceptionC2ERKS_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef nonnull align 8 dereferenceable(8) @qoverex) #4
  tail call void @__cxa_throw(ptr nonnull %8, ptr nonnull @_ZTI22QueueOverflowException, ptr nonnull @_ZNSt9exceptionD2Ev) #5
  unreachable

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = shl i32 %11, %2
  %.not = icmp eq i32 %2, 32
  %notmask = shl nsw i32 -1, %2
  %13 = xor i32 %notmask, -1
  %14 = select i1 %.not, i32 -1, i32 %13
  %.0 = and i32 %14, %1
  %15 = or i32 %12, %.0
  store i32 %15, ptr %10, align 4, !tbaa !5
  %16 = load i32, ptr %0, align 4, !tbaa !10
  %17 = add nsw i32 %16, %2
  store i32 %17, ptr %0, align 4, !tbaa !10
  ret void
}

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN22QueueOverflowExceptionC2ERKS_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

attributes #0 = { nounwind "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 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 = { 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 = { inlinehint 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 }
attributes #5 = { noreturn }

!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 = !{!"_ZTS8BitQueue", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}


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