; 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_enum_trace" = type <{ %"class.sc_core::vcd_trace.base", [4 x i8], ptr, i32, i32, ptr, i32, [4 x i8] }>
%"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_core::vcd_trace" = type <{ ptr, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", ptr, i32, [4 x i8] }>

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@_ZTVN7sc_core14vcd_enum_traceE = external dso_local unnamed_addr constant { [8 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7sc_core9vcd_traceC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_(ptr noundef nonnull align 8 dereferenceable(84), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core14vcd_enum_traceC2ERKjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_PPKc(ptr noundef nonnull align 8 dereferenceable(116) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef %4) unnamed_addr #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN7sc_core9vcd_traceC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_(ptr noundef nonnull align 8 dereferenceable(84) %12, ptr noundef nonnull align 8 dereferenceable(32) %13, ptr noundef nonnull align 8 dereferenceable(32) %14)
  store ptr getelementptr inbounds inrange(-16, 48) ({ [8 x ptr] }, ptr @_ZTVN7sc_core14vcd_enum_traceE, i32 0, i32 0, i32 2), ptr %12, align 8, !tbaa !9
  %15 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %16, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !11
  store i32 %19, ptr %17, align 8, !tbaa !13
  %20 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 4
  store i32 -1, ptr %20, align 4, !tbaa !19
  %21 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %22, ptr %21, align 8, !tbaa !20
  %23 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 6
  store i32 0, ptr %23, align 8, !tbaa !21
  %24 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 6
  store i32 0, ptr %24, align 8, !tbaa !21
  br label %25

25:                                               ; preds = %34, %5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 6
  %28 = load i32, ptr %27, align 8, !tbaa !21
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %26, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %25
  br label %34

34:                                               ; preds = %33
  %35 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 6
  %36 = load i32, ptr %35, align 8, !tbaa !21
  %37 = add i32 %36, 1
  store i32 %37, ptr %35, align 8, !tbaa !21
  br label %25, !llvm.loop !22

38:                                               ; preds = %25
  %39 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %12, i32 0, i32 4
  store i32 0, ptr %39, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %40 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 6
  %41 = load i32, ptr %40, align 8, !tbaa !21
  %42 = sub i32 %41, 1
  store i32 %42, ptr %11, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %46, %38
  %44 = load i32, ptr %11, align 4, !tbaa !11
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %52

46:                                               ; preds = %43
  %47 = load i32, ptr %11, align 4, !tbaa !11
  %48 = lshr i32 %47, 1
  store i32 %48, ptr %11, align 4, !tbaa !11
  %49 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %12, i32 0, i32 4
  %50 = load i32, ptr %49, align 8, !tbaa !24
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %49, align 8, !tbaa !24
  br label %43, !llvm.loop !25

52:                                               ; preds = %43
  %53 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %12, i32 0, i32 4
  %54 = load i32, ptr %53, align 8, !tbaa !24
  %55 = icmp slt i32 %54, 32
  br i1 %55, label %56, label %62

56:                                               ; preds = %52
  %57 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %12, i32 0, i32 4
  %58 = load i32, ptr %57, align 8, !tbaa !24
  %59 = shl i32 -1, %58
  %60 = xor i32 %59, -1
  %61 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 4
  store i32 %60, ptr %61, align 4, !tbaa !19
  br label %64

62:                                               ; preds = %52
  %63 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %12, i32 0, i32 4
  store i32 -1, ptr %63, align 4, !tbaa !19
  br label %64

64:                                               ; preds = %62, %56
  %65 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %12, i32 0, i32 3
  store ptr @.str, ptr %65, align 8, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret void
}

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 = { 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, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 96}
!14 = !{!"_ZTSN7sc_core14vcd_enum_traceE", !15, i64 0, !6, i64 88, !12, i64 96, !12, i64 100, !6, i64 104, !12, i64 112}
!15 = !{!"_ZTSN7sc_core9vcd_traceE", !16, i64 8, !16, i64 40, !6, i64 72, !12, i64 80}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !7, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!14, !12, i64 100}
!20 = !{!14, !6, i64 104}
!21 = !{!14, !12, i64 112}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!15, !12, i64 80}
!25 = distinct !{!25, !23}
!26 = !{!15, !6, i64 72}


; 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 = external hidden unnamed_addr constant [5 x i8], align 1
@_ZTVN7sc_core14vcd_enum_traceE = external dso_local unnamed_addr constant { [8 x ptr] }, align 8

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7sc_core14vcd_enum_traceC2ERKjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_PPKc(ptr noundef nonnull align 8 dereferenceable(116) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef %4) unnamed_addr #0 align 2 {
  tail call void @_ZN7sc_core9vcd_traceC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_(ptr noundef nonnull align 8 dereferenceable(84) %0, ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(32) %3)
  store ptr getelementptr inbounds inrange(-16, 48) (i8, ptr @_ZTVN7sc_core14vcd_enum_traceE, i64 16), ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr %1, ptr %6, align 8, !tbaa !8
  %7 = getelementptr inbounds i8, ptr %0, i64 96
  %8 = load i32, ptr %1, align 4, !tbaa !11
  store i32 %8, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %4, ptr %9, align 8, !tbaa !19
  br label %10

10:                                               ; preds = %10, %5
  %storemerge = phi i32 [ 0, %5 ], [ %14, %10 ]
  %11 = zext i32 %storemerge to i64
  %12 = getelementptr inbounds ptr, ptr %4, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !8
  %.not = icmp eq ptr %13, null
  %14 = add i32 %storemerge, 1
  br i1 %.not, label %15, label %10, !llvm.loop !20

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 112
  store i32 %storemerge, ptr %16, align 8, !tbaa !22
  %17 = add i32 %storemerge, -1
  %.not912 = icmp eq i32 %17, 0
  br i1 %.not912, label %.thread, label %19

.thread:                                          ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 0, ptr %18, align 8, !tbaa !23
  br label %25

19:                                               ; preds = %15
  %20 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %17, i1 true)
  %.fr = freeze i32 %20
  %21 = sub nuw nsw i32 32, %.fr
  %22 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 %21, ptr %22, align 8, !tbaa !23
  %.not16 = icmp eq i32 %.fr, 0
  %23 = shl nsw i32 -1, %21
  %24 = xor i32 %23, -1
  %spec.select = select i1 %.not16, i32 -1, i32 %24
  br label %25

25:                                               ; preds = %19, %.thread
  %26 = phi i32 [ 0, %.thread ], [ %spec.select, %19 ]
  %27 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 %26, ptr %27, align 4, !tbaa !24
  %28 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr @.str, ptr %28, align 8, !tbaa !25
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #1

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 speculatable willreturn memory(none) }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !10, i64 0}
!13 = !{!14, !12, i64 96}
!14 = !{!"_ZTSN7sc_core14vcd_enum_traceE", !15, i64 0, !9, i64 88, !12, i64 96, !12, i64 100, !9, i64 104, !12, i64 112}
!15 = !{!"_ZTSN7sc_core9vcd_traceE", !16, i64 8, !16, i64 40, !9, i64 72, !12, i64 80}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !10, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!18 = !{!"long", !10, i64 0}
!19 = !{!14, !9, i64 104}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!14, !12, i64 112}
!23 = !{!15, !12, i64 80}
!24 = !{!14, !12, i64 100}
!25 = !{!15, !9, i64 72}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass