; 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
@_ZN7sc_core20SC_ID_UNKNOWN_ERROR_E = external dso_local constant [14 x i8], align 1

; 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_handler8mdlookupEPKc(ptr noundef %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %1
  store ptr @_ZN7sc_core20SC_ID_UNKNOWN_ERROR_E, ptr %3, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %9, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %11 = load ptr, ptr @_ZN7sc_core17sc_report_handler8messagesE, align 8, !tbaa !5
  store ptr %11, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %50, %10
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %5, align 4
  br label %54

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %44, %16
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  store i32 5, ptr %5, align 4
  br label %47

24:                                               ; preds = %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %28, i64 %30
  %32 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = call i32 @strcmp(ptr noundef %25, ptr noundef %33) #4
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %43, label %36

36:                                               ; preds = %24
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %39, i64 %41
  store ptr %42, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %47

43:                                               ; preds = %24
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !9
  br label %17, !llvm.loop !17

47:                                               ; preds = %36, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %48 = load i32, ptr %5, align 4
  switch i32 %48, label %54 [
    i32 5, label %49
  ]

49:                                               ; preds = %47
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  store ptr %53, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !20

54:                                               ; preds = %47, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %55 = load i32, ptr %5, align 4
  switch i32 %55, label %59 [
    i32 2, label %56
    i32 1, label %57
  ]

56:                                               ; preds = %54
  store ptr null, ptr %2, align 8
  br label %57

57:                                               ; preds = %56, %54
  %58 = load ptr, ptr %2, align 8
  ret ptr %58

59:                                               ; preds = %54
  unreachable
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

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 willreturn memory(read) "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 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

!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, !10, i64 8}
!12 = !{!"_ZTSN7sc_core17sc_report_handler13msg_def_itemsE", !6, i64 0, !10, i64 8, !13, i64 12, !6, i64 16}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTSN7sc_core10sc_msg_defE", !6, i64 0, !10, i64 8, !7, i64 12, !10, i64 28, !7, i64 32, !10, i64 48, !10, i64 52, !7, i64 56, !6, i64 72, !10, i64 80}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !6, 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
@_ZN7sc_core20SC_ID_UNKNOWN_ERROR_E = external dso_local constant [14 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_ZN7sc_core17sc_report_handler8mdlookupEPKc(ptr noundef readonly %0) local_unnamed_addr #0 align 2 {
  %.not = icmp eq ptr %0, null
  %spec.store.select = select i1 %.not, ptr @_ZN7sc_core20SC_ID_UNKNOWN_ERROR_E, ptr %0
  %.01425 = load ptr, ptr @_ZN7sc_core17sc_report_handler8messagesE, align 8, !tbaa !5
  %.not1726 = icmp eq ptr %.01425, null
  br i1 %.not1726, label %.thread, label %.preheader

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

.lr.ph:                                           ; preds = %.preheader
  %4 = load ptr, ptr %.01427, 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 = load ptr, ptr %7, align 8, !tbaa !16
  %9 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %spec.store.select, ptr noundef nonnull dereferenceable(1) %8) #2
  %.not18 = icmp eq i32 %9, 0
  br i1 %.not18, label %.thread, label %5

._crit_edge:                                      ; preds = %5, %.preheader
  %10 = getelementptr inbounds i8, ptr %.01427, i64 16
  %.014 = load ptr, ptr %10, align 8, !tbaa !5
  %.not17 = icmp eq ptr %.014, null
  br i1 %.not17, 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
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

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

!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, !6, i64 0}
!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,TailCallElimPass