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

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

@_ZN4gem54ruby10StoreTrace6s_initE = external dso_local global i8, align 1
@_ZN4gem54ruby10StoreTrace15s_total_samplesE = external dso_local global i64, align 8
@_ZN4gem54ruby10StoreTrace17s_store_count_ptrE = external dso_local global ptr, align 8
@_ZN4gem54ruby10StoreTrace27s_store_first_to_stolen_ptrE = external dso_local global ptr, align 8
@_ZN4gem54ruby10StoreTrace26s_store_last_to_stolen_ptrE = external dso_local global ptr, align 8
@_ZN4gem54ruby10StoreTrace25s_store_first_to_last_ptrE = external dso_local global ptr, align 8

declare void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i32 noundef) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4gem54ruby10StoreTrace11initSummaryEv() #1 align 2 personality ptr @__gxx_personality_v0 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = load i8, ptr @_ZN4gem54ruby10StoreTrace6s_initE, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc i8 %3 to i1
  br i1 %4, label %30, label %5

5:                                                ; preds = %0
  store i64 0, ptr @_ZN4gem54ruby10StoreTrace15s_total_samplesE, align 8, !tbaa !11
  %6 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %6, i32 noundef -1, i32 noundef 50)
          to label %7 unwind label %14

7:                                                ; preds = %5
  store ptr %6, ptr @_ZN4gem54ruby10StoreTrace17s_store_count_ptrE, align 8, !tbaa !13
  %8 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %8, i32 noundef -1, i32 noundef 50)
          to label %9 unwind label %18

9:                                                ; preds = %7
  store ptr %8, ptr @_ZN4gem54ruby10StoreTrace27s_store_first_to_stolen_ptrE, align 8, !tbaa !13
  %10 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %10, i32 noundef -1, i32 noundef 50)
          to label %11 unwind label %22

11:                                               ; preds = %9
  store ptr %10, ptr @_ZN4gem54ruby10StoreTrace26s_store_last_to_stolen_ptrE, align 8, !tbaa !13
  %12 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %12, i32 noundef -1, i32 noundef 50)
          to label %13 unwind label %26

13:                                               ; preds = %11
  store ptr %12, ptr @_ZN4gem54ruby10StoreTrace25s_store_first_to_last_ptrE, align 8, !tbaa !13
  br label %30

14:                                               ; preds = %5
  %15 = landingpad { ptr, i32 }
          cleanup
  %16 = extractvalue { ptr, i32 } %15, 0
  store ptr %16, ptr %1, align 8
  %17 = extractvalue { ptr, i32 } %15, 1
  store i32 %17, ptr %2, align 4
  call void @_ZdlPvm(ptr noundef %6, i64 noundef 64) #5
  br label %31

18:                                               ; preds = %7
  %19 = landingpad { ptr, i32 }
          cleanup
  %20 = extractvalue { ptr, i32 } %19, 0
  store ptr %20, ptr %1, align 8
  %21 = extractvalue { ptr, i32 } %19, 1
  store i32 %21, ptr %2, align 4
  call void @_ZdlPvm(ptr noundef %8, i64 noundef 64) #5
  br label %31

22:                                               ; preds = %9
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %1, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %2, align 4
  call void @_ZdlPvm(ptr noundef %10, i64 noundef 64) #5
  br label %31

26:                                               ; preds = %11
  %27 = landingpad { ptr, i32 }
          cleanup
  %28 = extractvalue { ptr, i32 } %27, 0
  store ptr %28, ptr %1, align 8
  %29 = extractvalue { ptr, i32 } %27, 1
  store i32 %29, ptr %2, align 4
  call void @_ZdlPvm(ptr noundef %12, i64 noundef 64) #5
  br label %31

30:                                               ; preds = %13, %0
  store i8 1, ptr @_ZN4gem54ruby10StoreTrace6s_initE, align 1, !tbaa !5
  ret void

31:                                               ; preds = %26, %22, %18, %14
  %32 = load ptr, ptr %1, align 8
  %33 = load i32, ptr %2, align 4
  %34 = insertvalue { ptr, i32 } poison, ptr %32, 0
  %35 = insertvalue { ptr, i32 } %34, i32 %33, 1
  resume { ptr, i32 } %35
}

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

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

attributes #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 = { 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 #3 = { 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 #4 = { builtin allocsize(0) }
attributes #5 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !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"

@_ZN4gem54ruby10StoreTrace6s_initE = external dso_local local_unnamed_addr global i8, align 1
@_ZN4gem54ruby10StoreTrace15s_total_samplesE = external dso_local local_unnamed_addr global i64, align 8
@_ZN4gem54ruby10StoreTrace17s_store_count_ptrE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN4gem54ruby10StoreTrace27s_store_first_to_stolen_ptrE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN4gem54ruby10StoreTrace26s_store_last_to_stolen_ptrE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN4gem54ruby10StoreTrace25s_store_first_to_last_ptrE = external dso_local local_unnamed_addr global ptr, align 8

declare void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64), i32 noundef, i32 noundef) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4gem54ruby10StoreTrace11initSummaryEv() local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %1 = load i8, ptr @_ZN4gem54ruby10StoreTrace6s_initE, align 1, !tbaa !5, !range !9, !noundef !10
  %2 = trunc nuw i8 %1 to i1
  br i1 %2, label %20, label %3

3:                                                ; preds = %0
  store i64 0, ptr @_ZN4gem54ruby10StoreTrace15s_total_samplesE, align 8, !tbaa !11
  %4 = tail call noalias noundef nonnull dereferenceable(64) ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %4, i32 noundef -1, i32 noundef 50)
          to label %5 unwind label %12

5:                                                ; preds = %3
  store ptr %4, ptr @_ZN4gem54ruby10StoreTrace17s_store_count_ptrE, align 8, !tbaa !13
  %6 = tail call noalias noundef nonnull dereferenceable(64) ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %6, i32 noundef -1, i32 noundef 50)
          to label %7 unwind label %14

7:                                                ; preds = %5
  store ptr %6, ptr @_ZN4gem54ruby10StoreTrace27s_store_first_to_stolen_ptrE, align 8, !tbaa !13
  %8 = tail call noalias noundef nonnull dereferenceable(64) ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %8, i32 noundef -1, i32 noundef 50)
          to label %9 unwind label %16

9:                                                ; preds = %7
  store ptr %8, ptr @_ZN4gem54ruby10StoreTrace26s_store_last_to_stolen_ptrE, align 8, !tbaa !13
  %10 = tail call noalias noundef nonnull dereferenceable(64) ptr @_Znwm(i64 noundef 64) #4
  invoke void @_ZN4gem54ruby9HistogramC1Eij(ptr noundef nonnull align 8 dereferenceable(64) %10, i32 noundef -1, i32 noundef 50)
          to label %11 unwind label %18

11:                                               ; preds = %9
  store ptr %10, ptr @_ZN4gem54ruby10StoreTrace25s_store_first_to_last_ptrE, align 8, !tbaa !13
  br label %20

12:                                               ; preds = %3
  %13 = landingpad { ptr, i32 }
          cleanup
  br label %21

14:                                               ; preds = %5
  %15 = landingpad { ptr, i32 }
          cleanup
  br label %21

16:                                               ; preds = %7
  %17 = landingpad { ptr, i32 }
          cleanup
  br label %21

18:                                               ; preds = %9
  %19 = landingpad { ptr, i32 }
          cleanup
  br label %21

20:                                               ; preds = %11, %0
  store i8 1, ptr @_ZN4gem54ruby10StoreTrace6s_initE, align 1, !tbaa !5
  ret void

21:                                               ; preds = %18, %16, %14, %12
  %.sink = phi ptr [ %10, %18 ], [ %8, %16 ], [ %6, %14 ], [ %4, %12 ]
  %.pn = phi { ptr, i32 } [ %19, %18 ], [ %17, %16 ], [ %15, %14 ], [ %13, %12 ]
  tail call void @_ZdlPvm(ptr noundef nonnull %.sink, i64 noundef 64) #5
  resume { ptr, i32 } %.pn
}

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

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

attributes #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 = { 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 #3 = { 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 #4 = { builtin allocsize(0) }
attributes #5 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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