; LLVM IR from gem5/gem5 :: src/mem/ruby/profiler/StoreTrace.ll (ZN4gem54ruby10StoreTrace5storeEj)

; 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.gem5::ruby::StoreTrace" = type { i64, i32, i64, i64, i32, i64, %"class.gem5::ruby::Histogram", %"class.gem5::ruby::Histogram", %"class.gem5::ruby::Histogram", %"class.gem5::ruby::Histogram" }
%"class.gem5::ruby::Histogram" = type { %"class.std::vector", i64, i64, i32, i32, i64, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@.str.6 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__._ZN4gem54ruby10StoreTrace5storeEj = external hidden unnamed_addr constant [43 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4gem54ruby10StoreTrace5storeEj(ptr noundef nonnull align 8 dereferenceable(304) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = call noundef i64 @_ZN4gem57curTickEv()
  store i64 %7, ptr %5, align 8, !tbaa !11
  %8 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 1
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %16, label %11

11:                                               ; preds = %2
  %12 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp eq i32 %13, %14
  br label %16

16:                                               ; preds = %11, %2
  %17 = phi i1 [ true, %2 ], [ %15, %11 ]
  br i1 %17, label %18, label %19

18:                                               ; preds = %16
  br label %21

19:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.7, i32 noundef 118, ptr noundef @__PRETTY_FUNCTION__._ZN4gem54ruby10StoreTrace5storeEj) #5
  unreachable

20:                                               ; No predecessors!
  br label %21

21:                                               ; preds = %20, %18
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 1
  store i32 %22, ptr %23, align 8, !tbaa !13
  %24 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %35

27:                                               ; preds = %21
  %28 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 4
  %29 = load i32, ptr %28, align 8, !tbaa !20
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  br label %34

32:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.7, i32 noundef 122, ptr noundef @__PRETTY_FUNCTION__._ZN4gem54ruby10StoreTrace5storeEj) #5
  unreachable

33:                                               ; No predecessors!
  br label %34

34:                                               ; preds = %33, %31
  br label %35

35:                                               ; preds = %34, %21
  %36 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !20
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %35
  %40 = load i64, ptr %5, align 8, !tbaa !11
  %41 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 2
  store i64 %40, ptr %41, align 8, !tbaa !21
  br label %42

42:                                               ; preds = %39, %35
  %43 = load i64, ptr %5, align 8, !tbaa !11
  %44 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 3
  store i64 %43, ptr %44, align 8, !tbaa !22
  %45 = getelementptr inbounds %"class.gem5::ruby::StoreTrace", ptr %6, i32 0, i32 4
  %46 = load i32, ptr %45, align 8, !tbaa !20
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %45, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4gem57curTickEv() #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSN4gem54ruby10StoreTraceE", !12, i64 0, !10, i64 8, !12, i64 16, !12, i64 24, !10, i64 32, !12, i64 40, !15, i64 48, !15, i64 112, !15, i64 176, !15, i64 240}
!15 = !{!"_ZTSN4gem54ruby9HistogramE", !16, i64 0, !12, i64 24, !12, i64 32, !10, i64 40, !10, i64 44, !12, i64 48, !12, i64 56}
!16 = !{!"_ZTSSt6vectorImSaImEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseImSaImEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!14, !10, i64 32}
!21 = !{!14, !12, i64 16}
!22 = !{!14, !12, i64 24}


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

@.str.6 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__._ZN4gem54ruby10StoreTrace5storeEj = external hidden unnamed_addr constant [43 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4gem54ruby10StoreTrace5storeEj(ptr nocapture noundef nonnull align 8 dereferenceable(304) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i64 @_ZN4gem57curTickEv()
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, -1
  %7 = icmp eq i32 %5, %1
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %.critedge, label %8

8:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.7, i32 noundef 118, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4gem54ruby10StoreTrace5storeEj) #3
  unreachable

.critedge:                                        ; preds = %2
  store i32 %1, ptr %4, align 8, !tbaa !5
  %9 = icmp ne i32 %1, -1
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i32, ptr %10, align 8
  %12 = icmp eq i32 %11, 0
  %or.cond6 = select i1 %9, i1 true, i1 %12
  br i1 %or.cond6, label %14, label %13

13:                                               ; preds = %.critedge
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.7, i32 noundef 122, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4gem54ruby10StoreTrace5storeEj) #3
  unreachable

14:                                               ; preds = %.critedge
  br i1 %12, label %15, label %17

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %3, ptr %16, align 8, !tbaa !17
  br label %17

17:                                               ; preds = %15, %14
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %3, ptr %18, align 8, !tbaa !18
  %19 = add nsw i32 %11, 1
  store i32 %19, ptr %10, align 8, !tbaa !19
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4gem57curTickEv() local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 #2 = { noreturn 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 #3 = { noreturn 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, !10, i64 8}
!6 = !{!"_ZTSN4gem54ruby10StoreTraceE", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !11, i64 48, !11, i64 112, !11, i64 176, !11, i64 240}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN4gem54ruby9HistogramE", !12, i64 0, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !7, i64 48, !7, i64 56}
!12 = !{!"_ZTSSt6vectorImSaImEE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseImSaImEE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !16, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!6, !7, i64 16}
!18 = !{!6, !7, i64 24}
!19 = !{!6, !10, i64 32}


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