; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/utils (sc_report_handler)

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

@_ZN7sc_core17sc_report_handler15verbosity_levelE = external dso_local global i32, align 4
@_ZN7sc_core17sc_report_handler7handlerE = external dso_local global ptr, align 8

declare i32 @__gxx_personality_v0(...)

; 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: nounwind
declare void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7sc_core17sc_report_handler8mdlookupEPKc(ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7sc_core17sc_report_handler12add_msg_typeEPKc(ptr noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7sc_core17sc_report_handler7executeEPNS_10sc_msg_defENS_11sc_severityE(ptr noundef, i32 noundef) #2 align 2

declare void @_ZN7sc_core9sc_reportC1ENS_11sc_severityEPKNS_10sc_msg_defEPKcS6_ii(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) unnamed_addr #4

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #3 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca %"class.sc_core::sc_report", align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = call noundef ptr @_ZN7sc_core17sc_report_handler8mdlookupEPKc(ptr noundef %17)
  store ptr %18, ptr %11, align 8, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %25

21:                                               ; preds = %5
  %22 = load i32, ptr @_ZN7sc_core17sc_report_handler15verbosity_levelE, align 4, !tbaa !11
  %23 = icmp sgt i32 200, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 1, ptr %12, align 4
  br label %52

25:                                               ; preds = %21, %5
  %26 = load ptr, ptr %11, align 8, !tbaa !9
  %27 = icmp ne ptr %26, null
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr %7, align 8, !tbaa !9
  %30 = call noundef ptr @_ZN7sc_core17sc_report_handler12add_msg_typeEPKc(ptr noundef %29)
  store ptr %30, ptr %11, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %28, %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %32 = load ptr, ptr %11, align 8, !tbaa !9
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = call noundef i32 @_ZN7sc_core17sc_report_handler7executeEPNS_10sc_msg_defENS_11sc_severityE(ptr noundef %32, i32 noundef %33)
  store i32 %34, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 80, ptr %14) #5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load ptr, ptr %11, align 8, !tbaa !9
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !11
  call void @_ZN7sc_core9sc_reportC1ENS_11sc_severityEPKNS_10sc_msg_defEPKcS6_ii(ptr noundef nonnull align 8 dereferenceable(80) %14, i32 noundef %35, ptr noundef %36, ptr noundef %37, ptr noundef %38, i32 noundef %39, i32 noundef 200)
  %40 = load i32, ptr %13, align 4, !tbaa !11
  %41 = and i32 %40, 16
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %49

43:                                               ; preds = %31
  invoke void @_ZN7sc_core17sc_report_handler12cache_reportERKNS_9sc_reportE(ptr noundef nonnull align 8 dereferenceable(80) %14)
          to label %44 unwind label %45

44:                                               ; preds = %43
  br label %49

45:                                               ; preds = %49, %43
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %15, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %16, align 4
  call void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %14) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %55

49:                                               ; preds = %44, %31
  %50 = load ptr, ptr @_ZN7sc_core17sc_report_handler7handlerE, align 8, !tbaa !9
  invoke void %50(ptr noundef nonnull align 8 dereferenceable(80) %14, ptr noundef nonnull align 4 dereferenceable(4) %13)
          to label %51 unwind label %45

51:                                               ; preds = %49
  call void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %14) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  store i32 0, ptr %12, align 4
  br label %52

52:                                               ; preds = %51, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %53 = load i32, ptr %12, align 4
  switch i32 %53, label %60 [
    i32 0, label %54
    i32 1, label %54
  ]

54:                                               ; preds = %52, %52
  ret void

55:                                               ; preds = %45
  %56 = load ptr, ptr %15, align 8
  %57 = load i32, ptr %16, align 4
  %58 = insertvalue { ptr, i32 } poison, ptr %56, 0
  %59 = insertvalue { ptr, i32 } %58, i32 %57, 1
  resume { ptr, i32 } %59

60:                                               ; preds = %52
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 = { 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 #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 }

!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 = !{!"_ZTSN7sc_core11sc_severityE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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.sc_core::sc_report" = type { %"class.std::exception", i32, ptr, ptr, ptr, i32, ptr, ptr, i32, ptr }
%"class.std::exception" = type { ptr }

@_ZN7sc_core17sc_report_handler15verbosity_levelE = external dso_local local_unnamed_addr global i32, align 4
@_ZN7sc_core17sc_report_handler7handlerE = external dso_local local_unnamed_addr global ptr, align 8

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: nounwind
declare void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80)) unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7sc_core17sc_report_handler8mdlookupEPKc(ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7sc_core17sc_report_handler12add_msg_typeEPKc(ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7sc_core17sc_report_handler7executeEPNS_10sc_msg_defENS_11sc_severityE(ptr noundef, i32 noundef) local_unnamed_addr #2 align 2

declare void @_ZN7sc_core9sc_reportC1ENS_11sc_severityEPKNS_10sc_msg_defEPKcS6_ii(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7sc_core17sc_report_handler12cache_reportERKNS_9sc_reportE(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca i32, align 4
  %7 = alloca %"class.sc_core::sc_report", align 8
  %8 = tail call noundef ptr @_ZN7sc_core17sc_report_handler8mdlookupEPKc(ptr noundef %1)
  %9 = icmp eq i32 %0, 0
  %10 = load i32, ptr @_ZN7sc_core17sc_report_handler15verbosity_levelE, align 4
  %11 = icmp slt i32 %10, 200
  %or.cond = select i1 %9, i1 %11, i1 false
  br i1 %or.cond, label %24, label %12

12:                                               ; preds = %5
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %13, label %15

13:                                               ; preds = %12
  %14 = tail call noundef ptr @_ZN7sc_core17sc_report_handler12add_msg_typeEPKc(ptr noundef %1)
  br label %15

15:                                               ; preds = %13, %12
  %.0 = phi ptr [ %8, %12 ], [ %14, %13 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #5
  %16 = tail call noundef i32 @_ZN7sc_core17sc_report_handler7executeEPNS_10sc_msg_defENS_11sc_severityE(ptr noundef %.0, i32 noundef %0)
  store i32 %16, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %7) #5
  call void @_ZN7sc_core9sc_reportC1ENS_11sc_severityEPKNS_10sc_msg_defEPKcS6_ii(ptr noundef nonnull align 8 dereferenceable(80) %7, i32 noundef %0, ptr noundef %.0, ptr noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef 200)
  %17 = and i32 %16, 16
  %.not14 = icmp eq i32 %17, 0
  br i1 %.not14, label %21, label %18

18:                                               ; preds = %15
  invoke void @_ZN7sc_core17sc_report_handler12cache_reportERKNS_9sc_reportE(ptr noundef nonnull align 8 dereferenceable(80) %7)
          to label %21 unwind label %19

19:                                               ; preds = %21, %18
  %20 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %7) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  resume { ptr, i32 } %20

21:                                               ; preds = %18, %15
  %22 = load ptr, ptr @_ZN7sc_core17sc_report_handler7handlerE, align 8, !tbaa !9
  invoke void %22(ptr noundef nonnull align 8 dereferenceable(80) %7, ptr noundef nonnull align 4 dereferenceable(4) %6)
          to label %23 unwind label %19

23:                                               ; preds = %21
  call void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %7) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  br label %24

24:                                               ; preds = %5, %23
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 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 = { 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 #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 }

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


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