; 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_handler14sev_call_countE = external dso_local global [4 x i32], align 16
@_ZN7sc_core17sc_report_handler8messagesE = external dso_local global ptr, align 8
@_ZN7sc_core17sc_report_handler14msg_terminatorE = external dso_local global %"struct.sc_core::sc_report_handler::msg_def_items", align 8
@.str.13 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [26 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: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core17sc_report_handler10initializeEv() #2 align 2 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store i32 0, ptr @_ZN7sc_core17sc_report_handler14sev_call_countE, align 16, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([4 x i32], ptr @_ZN7sc_core17sc_report_handler14sev_call_countE, i64 0, i64 1), align 4, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([4 x i32], ptr @_ZN7sc_core17sc_report_handler14sev_call_countE, i64 0, i64 2), align 8, !tbaa !5
  store i32 0, ptr getelementptr inbounds ([4 x i32], ptr @_ZN7sc_core17sc_report_handler14sev_call_countE, i64 0, i64 3), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %4 = load ptr, ptr @_ZN7sc_core17sc_report_handler8messagesE, align 8, !tbaa !9
  store ptr %4, ptr %1, align 8, !tbaa !9
  br label %5

5:                                                ; preds = %59, %0
  %6 = load ptr, ptr %1, align 8, !tbaa !9
  %7 = icmp ne ptr %6, @_ZN7sc_core17sc_report_handler14msg_terminatorE
  br i1 %7, label %8, label %63

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

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

15:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %59

16:                                               ; preds = %9
  %17 = load ptr, ptr %1, align 8, !tbaa !9
  %18 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %19, i64 %21
  %23 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %22, i32 0, i32 6
  store i32 0, ptr %23, align 4, !tbaa !15
  %24 = load ptr, ptr %1, align 8, !tbaa !9
  %25 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %26, i64 %28
  %30 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %29, i32 0, i32 7
  %31 = getelementptr inbounds [4 x i32], ptr %30, i64 0, i64 0
  store i32 0, ptr %31, align 8, !tbaa !5
  %32 = load ptr, ptr %1, 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 %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %34, i64 %36
  %38 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %37, i32 0, i32 7
  %39 = getelementptr inbounds [4 x i32], ptr %38, i64 0, i64 1
  store i32 0, ptr %39, align 4, !tbaa !5
  %40 = load ptr, ptr %1, align 8, !tbaa !9
  %41 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %42, i64 %44
  %46 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %45, i32 0, i32 7
  %47 = getelementptr inbounds [4 x i32], ptr %46, i64 0, i64 2
  store i32 0, ptr %47, align 8, !tbaa !5
  %48 = load ptr, ptr %1, align 8, !tbaa !9
  %49 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %50, i64 %52
  %54 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %53, i32 0, i32 7
  %55 = getelementptr inbounds [4 x i32], ptr %54, i64 0, i64 3
  store i32 0, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %16
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !17

59:                                               ; preds = %15
  %60 = load ptr, ptr %1, align 8, !tbaa !9
  %61 = getelementptr inbounds %"struct.sc_core::sc_report_handler::msg_def_items", ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  store ptr %62, ptr %1, align 8, !tbaa !9
  br label %5, !llvm.loop !20

63:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %64 = call ptr @getenv(ptr noundef @.str.13) #4
  store ptr %64, ptr %3, align 8, !tbaa !9
  %65 = load ptr, ptr %3, align 8, !tbaa !9
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %73

67:                                               ; preds = %63
  %68 = load ptr, ptr %3, align 8, !tbaa !9
  %69 = call i32 @strcmp(ptr noundef %68, ptr noundef @.str.14) #5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %73, label %71

71:                                               ; preds = %67
  %72 = call noundef i32 @_ZN7sc_core17sc_report_handler11set_actionsEPKcj(ptr noundef @.str.15, i32 noundef 1)
  br label %73

73:                                               ; preds = %71, %67, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; Function Attrs: nounwind
declare ptr @getenv(ptr noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 = { nounwind }
attributes #5 = { 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 = !{!"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 52}
!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_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_handler14sev_call_countE = external dso_local local_unnamed_addr global [4 x i32], align 16
@_ZN7sc_core17sc_report_handler8messagesE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN7sc_core17sc_report_handler14msg_terminatorE = external dso_local global %"struct.sc_core::sc_report_handler::msg_def_items", align 8
@.str.13 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core17sc_report_handler10initializeEv() local_unnamed_addr #1 align 2 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) @_ZN7sc_core17sc_report_handler14sev_call_countE, i8 0, i64 16, i1 false)
  %.021 = load ptr, ptr @_ZN7sc_core17sc_report_handler8messagesE, align 8, !tbaa !5
  %.not22 = icmp eq ptr %.021, @_ZN7sc_core17sc_report_handler14msg_terminatorE
  br i1 %.not22, label %._crit_edge24, label %.preheader

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

.lr.ph:                                           ; preds = %.preheader
  %4 = load ptr, ptr %.023, align 8, !tbaa !13
  br label %6

._crit_edge:                                      ; preds = %6, %.preheader
  %5 = getelementptr inbounds i8, ptr %.023, i64 16
  %.0 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, @_ZN7sc_core17sc_report_handler14msg_terminatorE
  br i1 %.not, label %._crit_edge24, label %.preheader, !llvm.loop !14

6:                                                ; preds = %.lr.ph, %6
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %6 ]
  %7 = getelementptr inbounds %"struct.sc_core::sc_msg_def", ptr %4, i64 %indvars.iv, i32 6
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %7, i8 0, i64 20, i1 false)
  %8 = load i32, ptr %1, align 8, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = icmp slt i64 %indvars.iv.next, %9
  br i1 %10, label %6, label %._crit_edge, !llvm.loop !16

._crit_edge24:                                    ; preds = %._crit_edge, %0
  %11 = tail call ptr @getenv(ptr noundef nonnull @.str.13) #4
  %.not18 = icmp eq ptr %11, null
  br i1 %.not18, label %16, label %12

12:                                               ; preds = %._crit_edge24
  %13 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) @.str.14) #5
  %.not19 = icmp eq i32 %13, 0
  br i1 %.not19, label %14, label %16

14:                                               ; preds = %12
  %15 = tail call noundef i32 @_ZN7sc_core17sc_report_handler11set_actionsEPKcj(ptr noundef nonnull @.str.15, i32 noundef 1)
  br label %16

16:                                               ; preds = %14, %12, %._crit_edge24
  ret void
}

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { 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 #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 = { nofree nounwind 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { 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 = distinct !{!16, !15}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass