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

%"struct.sc_core::sc_report_handler::msg_def_items" = type { ptr, i32, i8, ptr }
%"struct.sc_core::sc_msg_def" = type { ptr, i32, [4 x i32], i32, [4 x i32], i32, i32, [4 x i32], ptr, i32 }

@_ZN7sc_core17sc_report_handler8messagesE = external dso_local global ptr, align 8

; 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: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN7sc_core17sc_report_handler8mdlookupEi(i32 noundef %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %7 = load ptr, ptr @_ZN7sc_core17sc_report_handler8messagesE, align 8, !tbaa !9
  store ptr %7, ptr %4, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %45, %1
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %5, align 4
  br label %49

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %39, %12
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  store i32 5, ptr %5, align 4
  br label %42

20:                                               ; preds = %13
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %24, i64 %26
  %28 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %27, i32 0, i32 9
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = icmp eq i32 %21, %29
  br i1 %30, label %31, label %38

31:                                               ; preds = %20
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %34, i64 %36
  store ptr %37, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %42

38:                                               ; preds = %20
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !5
  br label %13, !llvm.loop !17

42:                                               ; preds = %31, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %43 = load i32, ptr %5, align 4
  switch i32 %43, label %49 [
    i32 5, label %44
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !19
  store ptr %48, ptr %4, align 8, !tbaa !9
  br label %8, !llvm.loop !20

49:                                               ; preds = %42, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %50 = load i32, ptr %5, align 4
  switch i32 %50, label %54 [
    i32 2, label %51
    i32 1, label %52
  ]

51:                                               ; preds = %49
  store ptr null, ptr %2, align 8
  br label %52

52:                                               ; preds = %51, %49
  %53 = load ptr, ptr %2, align 8
  ret ptr %53

54:                                               ; preds = %49
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN7sc_core17sc_report_handler13msg_def_itemsE", !10, i64 0, !6, i64 8, !13, i64 12, !10, i64 16}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!16, !6, i64 80}
!16 = !{!"_ZTSN7sc_core10sc_msg_defE", !10, i64 0, !6, i64 8, !7, i64 12, !6, i64 28, !7, i64 32, !6, i64 48, !6, i64 52, !7, i64 56, !10, i64 72, !6, i64 80}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !10, i64 16}
!20 = distinct !{!20, !18}


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

%"struct.sc_core::sc_msg_def" = type { ptr, i32, [4 x i32], i32, [4 x i32], i32, i32, [4 x i32], ptr, i32 }

@_ZN7sc_core17sc_report_handler8messagesE = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_ZN7sc_core17sc_report_handler8mdlookupEi(i32 noundef %0) local_unnamed_addr #0 align 2 {
  %.01322 = load ptr, ptr @_ZN7sc_core17sc_report_handler8messagesE, align 8, !tbaa !5
  %.not23 = icmp eq ptr %.01322, null
  br i1 %.not23, label %.thread, label %.preheader

.preheader:                                       ; preds = %1, %._crit_edge
  %.01324 = phi ptr [ %.013, %._crit_edge ], [ %.01322, %1 ]
  %2 = getelementptr inbounds i8, ptr %.01324, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !9
  %.not1620 = icmp sgt i32 %3, 0
  br i1 %.not1620, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %4 = load ptr, ptr %.01324, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %6

5:                                                ; preds = %6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %6, !llvm.loop !14

6:                                                ; preds = %.lr.ph, %5
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %5 ]
  %7 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %4, i64 %indvars.iv
  %8 = getelementptr inbounds i8, ptr %7, i64 80
  %9 = load i32, ptr %8, align 8, !tbaa !16
  %10 = icmp eq i32 %9, %0
  br i1 %10, label %.thread, label %5

._crit_edge:                                      ; preds = %5, %.preheader
  %11 = getelementptr inbounds i8, ptr %.01324, i64 16
  %.013 = load ptr, ptr %11, align 8, !tbaa !5
  %.not = icmp eq ptr %.013, null
  br i1 %.not, label %.thread, label %.preheader, !llvm.loop !18

.thread:                                          ; preds = %._crit_edge, %6, %1
  %spec.select = phi ptr [ null, %1 ], [ %7, %6 ], [ null, %._crit_edge ]
  ret ptr %spec.select
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

!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, !11, i64 8}
!10 = !{!"_ZTSN7sc_core17sc_report_handler13msg_def_itemsE", !6, i64 0, !11, i64 8, !12, i64 12, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !11, i64 80}
!17 = !{!"_ZTSN7sc_core10sc_msg_defE", !6, i64 0, !11, i64 8, !7, i64 12, !11, i64 28, !7, i64 32, !11, i64 48, !11, i64 52, !7, i64 56, !6, i64 72, !11, i64 80}
!18 = distinct !{!18, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass