; LLVM IR from gem5/gem5 :: src/systemc/tlm_bridge/sc_mm.ll (ZN11Gem5SystemC13MemoryManager8allocateEv)

; 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.Gem5SystemC::MemoryManager" = type { %"class.tlm::tlm_mm_interface", i32, i32, %"class.std::vector" }
%"class.tlm::tlm_mm_interface" = type { ptr }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<tlm::tlm_generic_payload *, std::allocator<tlm::tlm_generic_payload *>>::_Vector_impl" }
%"struct.std::_Vector_base<tlm::tlm_generic_payload *, std::allocator<tlm::tlm_generic_payload *>>::_Vector_impl" = type { %"struct.std::_Vector_base<tlm::tlm_generic_payload *, std::allocator<tlm::tlm_generic_payload *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<tlm::tlm_generic_payload *, std::allocator<tlm::tlm_generic_payload *>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN11Gem5SystemC13MemoryManager8allocateEv(ptr noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"class.Gem5SystemC::MemoryManager", ptr %7, i32 0, i32 3
  %9 = call noundef zeroext i1 @_ZNKSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #6
  br i1 %9, label %10, label %20

10:                                               ; preds = %1
  %11 = getelementptr inbounds %"class.Gem5SystemC::MemoryManager", ptr %7, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = add i32 %12, 1
  store i32 %13, ptr %11, align 8, !tbaa !9
  %14 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 136) #7
  invoke void @_ZN3tlm19tlm_generic_payloadC1EPNS_16tlm_mm_interfaceE(ptr noundef nonnull align 8 dereferenceable(132) %14, ptr noundef %7)
          to label %15 unwind label %16

15:                                               ; preds = %10
  store ptr %14, ptr %2, align 8
  br label %26

16:                                               ; preds = %10
  %17 = landingpad { ptr, i32 }
          cleanup
  %18 = extractvalue { ptr, i32 } %17, 0
  store ptr %18, ptr %4, align 8
  %19 = extractvalue { ptr, i32 } %17, 1
  store i32 %19, ptr %5, align 4
  call void @_ZdlPvm(ptr noundef %14, i64 noundef 136) #8
  br label %28

20:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %21 = getelementptr inbounds %"class.Gem5SystemC::MemoryManager", ptr %7, i32 0, i32 3
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %21) #6
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %"class.Gem5SystemC::MemoryManager", ptr %7, i32 0, i32 3
  call void @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24) %24) #6
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %25, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %26

26:                                               ; preds = %20, %15
  %27 = load ptr, ptr %2, align 8
  ret ptr %27

28:                                               ; preds = %16
  %29 = load ptr, ptr %4, align 8
  %30 = load i32, ptr %5, align 4
  %31 = insertvalue { ptr, i32 } poison, ptr %29, 0
  %32 = insertvalue { ptr, i32 } %31, i32 %30, 1
  resume { ptr, i32 } %32
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #4

declare void @_ZN3tlm19tlm_generic_payloadC1EPNS_16tlm_mm_interfaceE(ptr noundef nonnull align 8 dereferenceable(132), ptr noundef) unnamed_addr #5

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin 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 #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 = { 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 = { nobuiltin allocsize(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 #5 = { "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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }
attributes #8 = { builtin 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, !12, i64 8}
!10 = !{!"_ZTSN11Gem5SystemC13MemoryManagerE", !11, i64 0, !12, i64 8, !12, i64 12, !13, i64 16}
!11 = !{!"_ZTSN3tlm16tlm_mm_interfaceE"}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTSSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIPN3tlm19tlm_generic_payloadESaIS2_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIPN3tlm19tlm_generic_payloadESaIS2_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPN3tlm19tlm_generic_payloadESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !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"

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN11Gem5SystemC13MemoryManager8allocateEv(ptr noundef nonnull align 8 dereferenceable(40) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = tail call noundef zeroext i1 @_ZNKSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #5
  br i1 %3, label %4, label %11

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = add i32 %6, 1
  store i32 %7, ptr %5, align 8, !tbaa !5
  %8 = tail call noalias noundef nonnull dereferenceable(136) ptr @_Znwm(i64 noundef 136) #6
  invoke void @_ZN3tlm19tlm_generic_payloadC1EPNS_16tlm_mm_interfaceE(ptr noundef nonnull align 8 dereferenceable(132) %8, ptr noundef nonnull %0)
          to label %14 unwind label %9

9:                                                ; preds = %4
  %10 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %8, i64 noundef 136) #7
  resume { ptr, i32 } %10

11:                                               ; preds = %1
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #5
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  tail call void @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #5
  br label %14

14:                                               ; preds = %4, %11
  %.0 = phi ptr [ %13, %11 ], [ %8, %4 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #3

declare void @_ZN3tlm19tlm_generic_payloadC1EPNS_16tlm_mm_interfaceE(ptr noundef nonnull align 8 dereferenceable(132), ptr noundef) unnamed_addr #4

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

attributes #0 = { nobuiltin 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 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 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 #3 = { nobuiltin allocsize(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 = { "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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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, !8, i64 8}
!6 = !{!"_ZTSN11Gem5SystemC13MemoryManagerE", !7, i64 0, !8, i64 8, !8, i64 12, !11, i64 16}
!7 = !{!"_ZTSN3tlm16tlm_mm_interfaceE"}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSSt6vectorIPN3tlm19tlm_generic_payloadESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIPN3tlm19tlm_generic_payloadESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIPN3tlm19tlm_generic_payloadESaIS2_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIPN3tlm19tlm_generic_payloadESaIS2_EE17_Vector_impl_dataE", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !9, i64 0}
!16 = !{!15, !15, i64 0}


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