; 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

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

23:                                               ; preds = %6
  %24 = load i32, ptr %10, align 4, !tbaa !11
  %25 = load i32, ptr @_ZN7sc_core17sc_report_handler15verbosity_levelE, align 4, !tbaa !11
  %26 = icmp sgt i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i32 1, ptr %14, align 4
  br label %56

28:                                               ; preds = %23, %6
  %29 = load ptr, ptr %13, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %34, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = call noundef ptr @_ZN7sc_core17sc_report_handler12add_msg_typeEPKc(ptr noundef %32)
  store ptr %33, ptr %13, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %31, %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %35 = load ptr, ptr %13, align 8, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = call noundef i32 @_ZN7sc_core17sc_report_handler7executeEPNS_10sc_msg_defENS_11sc_severityE(ptr noundef %35, i32 noundef %36)
  store i32 %37, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 80, ptr %16) #5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load ptr, ptr %13, align 8, !tbaa !9
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = load ptr, ptr %11, align 8, !tbaa !9
  %42 = load i32, ptr %12, align 4, !tbaa !11
  %43 = 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) %16, i32 noundef %38, ptr noundef %39, ptr noundef %40, ptr noundef %41, i32 noundef %42, i32 noundef %43)
  %44 = load i32, ptr %15, align 4, !tbaa !11
  %45 = and i32 %44, 16
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %53

47:                                               ; preds = %34
  invoke void @_ZN7sc_core17sc_report_handler12cache_reportERKNS_9sc_reportE(ptr noundef nonnull align 8 dereferenceable(80) %16)
          to label %48 unwind label %49

48:                                               ; preds = %47
  br label %53

49:                                               ; preds = %53, %47
  %50 = landingpad { ptr, i32 }
          cleanup
  %51 = extractvalue { ptr, i32 } %50, 0
  store ptr %51, ptr %17, align 8
  %52 = extractvalue { ptr, i32 } %50, 1
  store i32 %52, ptr %18, align 4
  call void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %16) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %59

53:                                               ; preds = %48, %34
  %54 = load ptr, ptr @_ZN7sc_core17sc_report_handler7handlerE, align 8, !tbaa !9
  invoke void %54(ptr noundef nonnull align 8 dereferenceable(80) %16, ptr noundef nonnull align 4 dereferenceable(4) %15)
          to label %55 unwind label %49

55:                                               ; preds = %53
  call void @_ZN7sc_core9sc_reportD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %16) #5
  call void @llvm.lifetime.end.p0(i64 80, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  store i32 0, ptr %14, align 4
  br label %56

56:                                               ; preds = %55, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  %57 = load i32, ptr %14, align 4
  switch i32 %57, label %64 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %49
  %60 = load ptr, ptr %17, align 8
  %61 = load i32, ptr %18, align 4
  %62 = insertvalue { ptr, i32 } poison, ptr %60, 0
  %63 = insertvalue { ptr, i32 } %62, i32 %61, 1
  resume { ptr, i32 } %63

64:                                               ; preds = %56
  unreachable
}

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

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

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

13:                                               ; preds = %6
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %14, label %16

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

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

19:                                               ; preds = %16
  invoke void @_ZN7sc_core17sc_report_handler12cache_reportERKNS_9sc_reportE(ptr noundef nonnull align 8 dereferenceable(80) %8)
          to label %22 unwind label %20

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

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

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

25:                                               ; preds = %6, %24
  ret void
}

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

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