; 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_int64_trace" = type { %"class.sc_core::vcd_trace.base", ptr, i64, i64 }
%"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_core15vcd_int64_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_core15vcd_int64_traceC2ERKxRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(32) %3, i32 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 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 i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load ptr, ptr %6, align 8
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  call void @_ZN7sc_core9vcd_traceC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_(ptr noundef nonnull align 8 dereferenceable(84) %11, ptr noundef nonnull align 8 dereferenceable(32) %12, ptr noundef nonnull align 8 dereferenceable(32) %13)
  store ptr getelementptr inbounds inrange(-16, 48) ({ [8 x ptr] }, ptr @_ZTVN7sc_core15vcd_int64_traceE, i32 0, i32 0, i32 2), ptr %11, align 8, !tbaa !11
  %14 = getelementptr inbounds %"class.sc_core::vcd_int64_trace", ptr %11, i32 0, i32 1
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %15, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.sc_core::vcd_int64_trace", ptr %11, i32 0, i32 2
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i64, ptr %17, align 8, !tbaa !13
  store i64 %18, ptr %16, align 8, !tbaa !15
  %19 = getelementptr inbounds %"class.sc_core::vcd_int64_trace", ptr %11, i32 0, i32 3
  store i64 -1, ptr %19, align 8, !tbaa !21
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %11, i32 0, i32 4
  store i32 %20, ptr %21, align 8, !tbaa !22
  %22 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %11, i32 0, i32 4
  %23 = load i32, ptr %22, align 8, !tbaa !22
  %24 = icmp slt i32 %23, 64
  br i1 %24, label %25, label %34

25:                                               ; preds = %5
  %26 = getelementptr inbounds %"class.sc_core::vcd_int64_trace", ptr %11, i32 0, i32 3
  %27 = load i64, ptr %26, align 8, !tbaa !21
  %28 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %11, i32 0, i32 4
  %29 = load i32, ptr %28, align 8, !tbaa !22
  %30 = zext i32 %29 to i64
  %31 = shl i64 %27, %30
  %32 = xor i64 %31, -1
  %33 = getelementptr inbounds %"class.sc_core::vcd_int64_trace", ptr %11, i32 0, i32 3
  store i64 %32, ptr %33, align 8, !tbaa !21
  br label %34

34:                                               ; preds = %25, %5
  %35 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %11, i32 0, i32 3
  store ptr @.str, ptr %35, align 8, !tbaa !23
  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" }

!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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = !{!16, !14, i64 96}
!16 = !{!"_ZTSN7sc_core15vcd_int64_traceE", !17, i64 0, !6, i64 88, !14, i64 96, !14, i64 104}
!17 = !{!"_ZTSN7sc_core9vcd_traceE", !18, i64 8, !18, i64 40, !6, i64 72, !10, i64 80}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !19, i64 0, !20, i64 8, !7, i64 16}
!19 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!16, !14, i64 104}
!22 = !{!17, !10, i64 80}
!23 = !{!17, !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_core15vcd_int64_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_core15vcd_int64_traceC2ERKxRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESA_i(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull align 8 dereferenceable(32) %3, i32 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_core15vcd_int64_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 i64, ptr %1, align 8, !tbaa !11
  store i64 %8, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 -1, ptr %9, align 8, !tbaa !20
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 %4, ptr %10, align 8, !tbaa !21
  %11 = icmp slt i32 %4, 64
  br i1 %11, label %12, label %16

12:                                               ; preds = %5
  %13 = zext nneg i32 %4 to i64
  %14 = shl nsw i64 -1, %13
  %15 = xor i64 %14, -1
  store i64 %15, ptr %9, align 8, !tbaa !20
  br label %16

16:                                               ; preds = %12, %5
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr @.str, ptr %17, align 8, !tbaa !22
  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" }

!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 = !{!"long long", !10, i64 0}
!13 = !{!14, !12, i64 96}
!14 = !{!"_ZTSN7sc_core15vcd_int64_traceE", !15, i64 0, !9, i64 88, !12, i64 96, !12, i64 104}
!15 = !{!"_ZTSN7sc_core9vcd_traceE", !16, i64 8, !16, i64 40, !9, i64 72, !19, 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 = !{!"int", !10, i64 0}
!20 = !{!14, !12, i64 104}
!21 = !{!15, !19, i64 80}
!22 = !{!15, !9, i64 72}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,InstCombinePass,SROAPass,TailCallElimPass