; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/tracing (sc_vcd_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::vcd_sc_int_base_trace" = type { %"class.sc_core::vcd_trace.base", ptr, %"class.sc_dt::sc_int_base" }
%"class.sc_core::vcd_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_dt::sc_int_base" = type { %"class.sc_dt::sc_value_base", i64, i32, i32 }
%"class.sc_dt::sc_value_base" = type { ptr }

@.str.13 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7sc_core9vcd_trace17compose_data_lineEPcS1_(ptr noundef nonnull align 8 dereferenceable(84), ptr noundef, ptr noundef) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @fputs(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5sc_dt11sc_int_base6lengthEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN5sc_dt11sc_int_baseaSERKS0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core21vcd_sc_int_base_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [1000 x i8], align 16
  %6 = alloca ptr, align 8
  %7 = alloca [1000 x i8], align 16
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1000, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %10 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 0
  store ptr %10, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1000, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %11 = getelementptr inbounds %"class.sc_core::vcd_sc_int_base_trace", ptr %9, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call noundef i32 @_ZNK5sc_dt11sc_int_base6lengthEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = sub nsw i32 %13, 1
  store i32 %14, ptr %8, align 4, !tbaa !19
  br label %15

15:                                               ; preds = %29, %2
  %16 = load i32, ptr %8, align 4, !tbaa !19
  %17 = icmp sge i32 %16, 0
  br i1 %17, label %18, label %32

18:                                               ; preds = %15
  %19 = getelementptr inbounds %"class.sc_core::vcd_sc_int_base_trace", ptr %9, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !19
  %22 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5sc_dt11sc_int_baseixEi(ptr noundef nonnull align 8 dereferenceable(24) %20, i32 noundef %21)
  %23 = call noundef zeroext i1 @_ZNK5sc_dt15sc_int_bitref_r7to_boolEv(ptr noundef nonnull align 8 dereferenceable(24) %22)
  %24 = zext i1 %23 to i64
  %25 = getelementptr inbounds [3 x i8], ptr @.str.13, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !20
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %6, align 8, !tbaa !5
  store i8 %26, ptr %27, align 1, !tbaa !20
  br label %29

29:                                               ; preds = %18
  %30 = load i32, ptr %8, align 4, !tbaa !19
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %8, align 4, !tbaa !19
  br label %15, !llvm.loop !21

32:                                               ; preds = %15
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 0, ptr %33, align 1, !tbaa !20
  %34 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 0
  %35 = getelementptr inbounds [1000 x i8], ptr %7, i64 0, i64 0
  call void @_ZN7sc_core9vcd_trace17compose_data_lineEPcS1_(ptr noundef nonnull align 8 dereferenceable(84) %9, ptr noundef %34, ptr noundef %35)
  %36 = getelementptr inbounds [1000 x i8], ptr %7, i64 0, i64 0
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call i32 @fputs(ptr noundef %36, ptr noundef %37)
  %39 = getelementptr inbounds %"class.sc_core::vcd_sc_int_base_trace", ptr %9, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %"class.sc_core::vcd_sc_int_base_trace", ptr %9, i32 0, i32 2
  %42 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5sc_dt11sc_int_baseaSERKS0_(ptr noundef nonnull align 8 dereferenceable(24) %41, ptr noundef nonnull align 8 dereferenceable(24) %40)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1000, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 1000, ptr %5) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5sc_dt11sc_int_baseixEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5sc_dt15sc_int_bitref_r7to_boolEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 #4 = { inlinehint 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_core21vcd_sc_int_base_traceE", !11, i64 0, !6, i64 88, !16, i64 96}
!11 = !{!"_ZTSN7sc_core9vcd_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 = !{!"_ZTSN5sc_dt11sc_int_baseE", !17, i64 0, !18, i64 8, !15, i64 16, !15, i64 20}
!17 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!18 = !{!"long long", !7, i64 0}
!19 = !{!15, !15, i64 0}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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.13 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7sc_core9vcd_trace17compose_data_lineEPcS1_(ptr noundef nonnull align 8 dereferenceable(84), ptr noundef, ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5sc_dt11sc_int_base6lengthEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN5sc_dt11sc_int_baseaSERKS0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core21vcd_sc_int_base_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(120) %0, ptr nocapture noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca [1000 x i8], align 16
  %4 = alloca [1000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1000, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 1000, ptr nonnull %4) #5
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call noundef i32 @_ZNK5sc_dt11sc_int_base6lengthEv(ptr noundef nonnull align 8 dereferenceable(24) %6)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %9 = zext nneg i32 %7 to i64
  %10 = getelementptr i8, ptr %3, i64 %9
  %scevgep = getelementptr i8, ptr %10, i64 -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.0.in8 = phi i32 [ %.0, %.lr.ph ], [ %7, %.lr.ph.preheader ]
  %.067 = phi ptr [ %17, %.lr.ph ], [ %3, %.lr.ph.preheader ]
  %.0 = add nsw i32 %.0.in8, -1
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5sc_dt11sc_int_baseixEi(ptr noundef nonnull align 8 dereferenceable(24) %11, i32 noundef %.0)
  %13 = tail call noundef zeroext i1 @_ZNK5sc_dt15sc_int_bitref_r7to_boolEv(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = zext i1 %13 to i64
  %15 = getelementptr inbounds [3 x i8], ptr @.str.13, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %.067, i64 1
  store i8 %16, ptr %.067, align 1, !tbaa !18
  %exitcond.not = icmp eq ptr %.067, %scevgep
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.06.lcssa = phi ptr [ %3, %2 ], [ %17, %.lr.ph ]
  store i8 0, ptr %.06.lcssa, align 1, !tbaa !18
  call void @_ZN7sc_core9vcd_trace17compose_data_lineEPcS1_(ptr noundef nonnull align 8 dereferenceable(84) %0, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %18 = call i32 @fputs(ptr noundef nonnull %4, ptr noundef %1)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 96
  %21 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5sc_dt11sc_int_baseaSERKS0_(ptr noundef nonnull align 8 dereferenceable(24) %20, ptr noundef nonnull align 8 dereferenceable(24) %19)
  call void @llvm.lifetime.end.p0(i64 1000, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 1000, ptr nonnull %3) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNK5sc_dt11sc_int_baseixEi(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5sc_dt15sc_int_bitref_r7to_boolEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #4 = { inlinehint 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, !10, i64 88}
!6 = !{!"_ZTSN7sc_core21vcd_sc_int_base_traceE", !7, i64 0, !10, i64 88, !15, i64 96}
!7 = !{!"_ZTSN7sc_core9vcd_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 = !{!"_ZTSN5sc_dt11sc_int_baseE", !16, i64 0, !17, i64 8, !14, i64 16, !14, i64 20}
!16 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!17 = !{!"long long", !11, i64 0}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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