; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/tracing (sc_wif_trace)

; 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::wif_enum_trace" = type { %"class.sc_core::wif_trace.base", ptr, i32, ptr, i32, %"class.std::__cxx11::basic_string" }
%"class.sc_core::wif_trace.base" = type <{ ptr, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", ptr, i32 }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.sc_core::wif_trace" = type <{ ptr, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", ptr, i32, [4 x i8] }>

@.str.5 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1
@_ZZN7sc_core14wif_enum_trace5writeEP8_IO_FILEE14warning_issued = external hidden global i8, align 1
@_ZN7sc_core33SC_ID_TRACING_INVALID_ENUM_VALUE_E = external constant [0 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [13 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

declare void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; 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 i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core14wif_enum_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1) unnamed_addr #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %7 = getelementptr inbounds %"class.sc_core::wif_enum_trace", ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = load i32, ptr %8, align 4, !tbaa !16
  %10 = getelementptr inbounds %"class.sc_core::wif_enum_trace", ptr %6, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !17
  %12 = icmp uge i32 %9, %11
  br i1 %12, label %13, label %20

13:                                               ; preds = %2
  %14 = load i8, ptr @_ZZN7sc_core14wif_enum_trace5writeEP8_IO_FILEE14warning_issued, align 1, !tbaa !18, !range !20, !noundef !21
  %15 = trunc i8 %14 to i1
  br i1 %15, label %19, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds %"class.sc_core::wif_trace", ptr %6, i32 0, i32 1
  %18 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %17) #5
  call void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef 1, ptr noundef @_ZN7sc_core33SC_ID_TRACING_INVALID_ENUM_VALUE_E, ptr noundef %18, ptr noundef @.str.5, i32 noundef 1497)
  store i8 1, ptr @_ZZN7sc_core14wif_enum_trace5writeEP8_IO_FILEE14warning_issued, align 1, !tbaa !18
  br label %19

19:                                               ; preds = %16, %13
  store ptr @.str.22, ptr %5, align 8, !tbaa !5
  br label %29

20:                                               ; preds = %2
  %21 = getelementptr inbounds %"class.sc_core::wif_enum_trace", ptr %6, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = getelementptr inbounds %"class.sc_core::wif_enum_trace", ptr %6, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = load i32, ptr %24, align 4, !tbaa !16
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %22, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  store ptr %28, ptr %5, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %20, %19
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.sc_core::wif_trace", ptr %6, i32 0, i32 2
  %32 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %31) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.10, ptr noundef %32, ptr noundef %33) #5
  %35 = getelementptr inbounds %"class.sc_core::wif_enum_trace", ptr %6, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = load i32, ptr %36, align 4, !tbaa !16
  %38 = getelementptr inbounds %"class.sc_core::wif_enum_trace", ptr %6, i32 0, i32 2
  store i32 %37, ptr %38, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 88}
!10 = !{!"_ZTSN7sc_core14wif_enum_traceE", !11, i64 0, !6, i64 88, !15, i64 96, !6, i64 104, !15, i64 112, !12, i64 120}
!11 = !{!"_ZTSN7sc_core9wif_traceE", !12, i64 8, !12, i64 40, !6, i64 72, !15, i64 80}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !13, i64 0, !14, i64 8, !7, i64 16}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!10, !15, i64 112}
!18 = !{!19, !19, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!10, !6, i64 104}
!23 = !{!10, !15, i64 96}


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

@.str.5 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1
@_ZZN7sc_core14wif_enum_trace5writeEP8_IO_FILEE14warning_issued = external hidden local_unnamed_addr global i8, align 1
@_ZN7sc_core33SC_ID_TRACING_INVALID_ENUM_VALUE_E = external constant [0 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [13 x i8], align 1

declare void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core14wif_enum_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr nocapture noundef %1) unnamed_addr #3 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 112
  %7 = load i32, ptr %6, align 8, !tbaa !16
  %.not = icmp ult i32 %5, %7
  br i1 %.not, label %14, label %8

8:                                                ; preds = %2
  %9 = load i8, ptr @_ZZN7sc_core14wif_enum_trace5writeEP8_IO_FILEE14warning_issued, align 1, !tbaa !17, !range !19, !noundef !20
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %20, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %12) #4
  tail call void @_ZN7sc_core17sc_report_handler6reportENS_11sc_severityEPKcS3_S3_i(i32 noundef 1, ptr noundef nonnull @_ZN7sc_core33SC_ID_TRACING_INVALID_ENUM_VALUE_E, ptr noundef %13, ptr noundef nonnull @.str.5, i32 noundef 1497)
  store i8 1, ptr @_ZZN7sc_core14wif_enum_trace5writeEP8_IO_FILEE14warning_issued, align 1, !tbaa !17
  br label %20

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 104
  %16 = load ptr, ptr %15, align 8, !tbaa !21
  %17 = zext i32 %5 to i64
  %18 = getelementptr inbounds ptr, ptr %16, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  br label %20

20:                                               ; preds = %8, %11, %14
  %.0 = phi ptr [ %19, %14 ], [ @.str.22, %11 ], [ @.str.22, %8 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 40
  %22 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %21) #4
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.10, ptr noundef %22, ptr noundef %.0) #4
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 %25, ptr %26, align 8, !tbaa !23
  ret void
}

attributes #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 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 = { nofree 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 #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 = { 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, !10, i64 88}
!6 = !{!"_ZTSN7sc_core14wif_enum_traceE", !7, i64 0, !10, i64 88, !14, i64 96, !10, i64 104, !14, i64 112, !8, i64 120}
!7 = !{!"_ZTSN7sc_core9wif_traceE", !8, i64 8, !8, i64 40, !10, i64 72, !14, i64 80}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !9, i64 0, !13, i64 8, !11, i64 16}
!9 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!"int", !11, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!6, !14, i64 112}
!17 = !{!18, !18, i64 0}
!18 = !{!"bool", !11, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!6, !10, i64 104}
!22 = !{!10, !10, i64 0}
!23 = !{!6, !14, i64 96}


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