; 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] }>

; 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 uwtable
define dso_local void @_ZN7sc_core14vcd_enum_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(116) %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 [1000 x i8], align 16
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  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) #3
  call void @llvm.lifetime.start.p0(i64 1000, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = load i32, ptr %11, align 4, !tbaa !16
  %13 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %9, i32 0, i32 4
  %14 = load i32, ptr %13, align 4, !tbaa !17
  %15 = and i32 %12, %14
  %16 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %9, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = load i32, ptr %17, align 4, !tbaa !16
  %19 = icmp ne i32 %15, %18
  br i1 %19, label %20, label %34

20:                                               ; preds = %2
  store i32 0, ptr %7, align 4, !tbaa !16
  br label %21

21:                                               ; preds = %30, %20
  %22 = load i32, ptr %7, align 4, !tbaa !16
  %23 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %9, i32 0, i32 4
  %24 = load i32, ptr %23, align 8, !tbaa !18
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %26, label %33

26:                                               ; preds = %21
  %27 = load i32, ptr %7, align 4, !tbaa !16
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 %28
  store i8 120, ptr %29, align 1, !tbaa !19
  br label %30

30:                                               ; preds = %26
  %31 = load i32, ptr %7, align 4, !tbaa !16
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %7, align 4, !tbaa !16
  br label %21, !llvm.loop !20

33:                                               ; preds = %21
  br label %64

34:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %35 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %9, i32 0, i32 4
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %37 = sub nsw i32 %36, 1
  %38 = zext i32 %37 to i64
  %39 = shl i64 1, %38
  store i64 %39, ptr %8, align 8, !tbaa !22
  store i32 0, ptr %7, align 4, !tbaa !16
  br label %40

40:                                               ; preds = %60, %34
  %41 = load i32, ptr %7, align 4, !tbaa !16
  %42 = getelementptr inbounds %"class.sc_core::vcd_trace", ptr %9, i32 0, i32 4
  %43 = load i32, ptr %42, align 8, !tbaa !18
  %44 = icmp slt i32 %41, %43
  br i1 %44, label %45, label %63

45:                                               ; preds = %40
  %46 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %9, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = load i32, ptr %47, align 4, !tbaa !16
  %49 = zext i32 %48 to i64
  %50 = load i64, ptr %8, align 8, !tbaa !22
  %51 = and i64 %49, %50
  %52 = icmp ne i64 %51, 0
  %53 = zext i1 %52 to i64
  %54 = select i1 %52, i8 49, i8 48
  %55 = load i32, ptr %7, align 4, !tbaa !16
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 %56
  store i8 %54, ptr %57, align 1, !tbaa !19
  %58 = load i64, ptr %8, align 8, !tbaa !22
  %59 = lshr i64 %58, 1
  store i64 %59, ptr %8, align 8, !tbaa !22
  br label %60

60:                                               ; preds = %45
  %61 = load i32, ptr %7, align 4, !tbaa !16
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %7, align 4, !tbaa !16
  br label %40, !llvm.loop !23

63:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %64

64:                                               ; preds = %63, %33
  %65 = load i32, ptr %7, align 4, !tbaa !16
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 %66
  store i8 0, ptr %67, align 1, !tbaa !19
  %68 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 0
  %69 = getelementptr inbounds [1000 x i8], ptr %6, i64 0, i64 0
  call void @_ZN7sc_core9vcd_trace17compose_data_lineEPcS1_(ptr noundef nonnull align 8 dereferenceable(84) %9, ptr noundef %68, ptr noundef %69)
  %70 = getelementptr inbounds [1000 x i8], ptr %6, i64 0, i64 0
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = call i32 @fputs(ptr noundef %70, ptr noundef %71)
  %73 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %9, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = load i32, ptr %74, align 4, !tbaa !16
  %76 = getelementptr inbounds %"class.sc_core::vcd_enum_trace", ptr %9, i32 0, i32 3
  store i32 %75, ptr %76, align 8, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1000, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1000, ptr %5) #3
  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 = { "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 }

!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_core14vcd_enum_traceE", !11, i64 0, !6, i64 88, !15, i64 96, !15, i64 100, !6, i64 104, !15, i64 112}
!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 = !{!15, !15, i64 0}
!17 = !{!10, !15, i64 100}
!18 = !{!11, !15, i64 80}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!14, !14, i64 0}
!23 = distinct !{!23, !21}
!24 = !{!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"

; 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 uwtable
define dso_local void @_ZN7sc_core14vcd_enum_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(116) %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) #4
  call void @llvm.lifetime.start.p0(i64 1000, ptr nonnull %4) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 100
  %9 = load i32, ptr %8, align 4, !tbaa !16
  %10 = and i32 %9, %7
  %.not = icmp eq i32 %10, %7
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  %12 = load i32, ptr %11, align 8, !tbaa !17
  %13 = icmp sgt i32 %12, 0
  br i1 %.not, label %15, label %.preheader

.preheader:                                       ; preds = %2
  br i1 %13, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %14 = zext nneg i32 %12 to i64
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %3, i8 120, i64 %14, i1 false), !tbaa !18
  br label %.loopexit

15:                                               ; preds = %2
  br i1 %13, label %.lr.ph16.preheader, label %.loopexit

.lr.ph16.preheader:                               ; preds = %15
  %16 = add nsw i32 %12, -1
  %17 = zext nneg i32 %16 to i64
  %18 = shl nuw i64 1, %17
  %wide.trip.count22 = zext nneg i32 %12 to i64
  %19 = zext i32 %7 to i64
  %xtraiter = and i64 %wide.trip.count22, 1
  %20 = icmp eq i32 %12, 1
  br i1 %20, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph16.preheader.new

.lr.ph16.preheader.new:                           ; preds = %.lr.ph16.preheader
  %unroll_iter = and i64 %wide.trip.count22, 2147483646
  br label %.lr.ph16

.lr.ph16:                                         ; preds = %.lr.ph16, %.lr.ph16.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph16.preheader.new ], [ %indvars.iv.next.1, %.lr.ph16 ]
  %.015 = phi i64 [ %18, %.lr.ph16.preheader.new ], [ %28, %.lr.ph16 ]
  %niter = phi i64 [ 0, %.lr.ph16.preheader.new ], [ %niter.next.1, %.lr.ph16 ]
  %21 = and i64 %.015, %19
  %.not11 = icmp eq i64 %21, 0
  %22 = select i1 %.not11, i8 48, i8 49
  %23 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %indvars.iv
  store i8 %22, ptr %23, align 2, !tbaa !18
  %24 = lshr i64 %.015, 1
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %25 = and i64 %24, %19
  %.not11.1 = icmp eq i64 %25, 0
  %26 = select i1 %.not11.1, i8 48, i8 49
  %27 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %indvars.iv.next
  store i8 %26, ptr %27, align 1, !tbaa !18
  %28 = lshr i64 %.015, 2
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph16, !llvm.loop !19

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph16, %.lr.ph16.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph16.preheader ], [ %indvars.iv.next.1, %.lr.ph16 ]
  %.015.unr = phi i64 [ %18, %.lr.ph16.preheader ], [ %28, %.lr.ph16 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph16.epil

.lr.ph16.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa
  %29 = and i64 %.015.unr, %19
  %.not11.epil = icmp eq i64 %29, 0
  %30 = select i1 %.not11.epil, i8 48, i8 49
  %31 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %indvars.iv.unr
  store i8 %30, ptr %31, align 1, !tbaa !18
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph16.epil, %.loopexit.loopexit.unr-lcssa, %.lr.ph.preheader, %.preheader, %15
  %.2 = phi i32 [ 0, %15 ], [ 0, %.preheader ], [ %12, %.lr.ph.preheader ], [ %12, %.loopexit.loopexit.unr-lcssa ], [ %12, %.lr.ph16.epil ]
  %32 = zext nneg i32 %.2 to i64
  %33 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %32
  store i8 0, ptr %33, 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)
  %34 = call i32 @fputs(ptr noundef nonnull %4, ptr noundef %1)
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 %36, ptr %37, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 1000, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 1000, ptr nonnull %3) #4
  ret void
}

; 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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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_core14vcd_enum_traceE", !7, i64 0, !10, i64 88, !14, i64 96, !14, i64 100, !10, i64 104, !14, i64 112}
!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 = !{!14, !14, i64 0}
!16 = !{!6, !14, i64 100}
!17 = !{!7, !14, i64 80}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!6, !14, i64 96}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass