; 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_int64_trace" = type { %"class.sc_core::wif_trace.base", ptr, i64, i64 }
%"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.10 = external hidden unnamed_addr constant [18 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

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 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, ...) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7sc_core15wif_int64_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [1000 x i8], align 16
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1000, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = getelementptr inbounds %"class.sc_core::wif_int64_trace", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = load i64, ptr %10, align 8, !tbaa !17
  %12 = getelementptr inbounds %"class.sc_core::wif_int64_trace", ptr %8, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !18
  %14 = and i64 %11, %13
  %15 = getelementptr inbounds %"class.sc_core::wif_int64_trace", ptr %8, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load i64, ptr %16, align 8, !tbaa !17
  %18 = icmp ne i64 %14, %17
  br i1 %18, label %19, label %33

19:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !19
  br label %20

20:                                               ; preds = %29, %19
  %21 = load i32, ptr %6, align 4, !tbaa !19
  %22 = getelementptr inbounds %"class.sc_core::wif_trace", ptr %8, i32 0, i32 4
  %23 = load i32, ptr %22, align 8, !tbaa !20
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %25, label %32

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

29:                                               ; preds = %25
  %30 = load i32, ptr %6, align 4, !tbaa !19
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !19
  br label %20, !llvm.loop !22

32:                                               ; preds = %20
  br label %63

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

40:                                               ; preds = %59, %33
  %41 = load i32, ptr %6, align 4, !tbaa !19
  %42 = getelementptr inbounds %"class.sc_core::wif_trace", ptr %8, i32 0, i32 4
  %43 = load i32, ptr %42, align 8, !tbaa !20
  %44 = icmp slt i32 %41, %43
  br i1 %44, label %45, label %62

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

59:                                               ; preds = %45
  %60 = load i32, ptr %6, align 4, !tbaa !19
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !19
  br label %40, !llvm.loop !24

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

63:                                               ; preds = %62, %32
  %64 = load i32, ptr %6, align 4, !tbaa !19
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 %65
  store i8 0, ptr %66, align 1, !tbaa !21
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %"class.sc_core::wif_trace", ptr %8, i32 0, i32 2
  %69 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %68) #3
  %70 = getelementptr inbounds [1000 x i8], ptr %5, i64 0, i64 0
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.10, ptr noundef %69, ptr noundef %70) #3
  %72 = getelementptr inbounds %"class.sc_core::wif_int64_trace", ptr %8, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !9
  %74 = load i64, ptr %73, align 8, !tbaa !17
  %75 = getelementptr inbounds %"class.sc_core::wif_int64_trace", ptr %8, i32 0, i32 2
  store i64 %74, ptr %75, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1000, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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_core15wif_int64_traceE", !11, i64 0, !6, i64 88, !16, i64 96, !16, i64 104}
!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 = !{!"long long", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!10, !16, i64 104}
!19 = !{!15, !15, i64 0}
!20 = !{!11, !15, i64 80}
!21 = !{!7, !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}
!25 = !{!10, !16, 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.10 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7sc_core15wif_int64_trace5writeEP8_IO_FILE(ptr noundef nonnull align 8 dereferenceable(112) %0, ptr nocapture noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca [1000 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1000, ptr nonnull %3) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 88
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load i64, ptr %5, align 8, !tbaa !16
  %7 = getelementptr inbounds i8, ptr %0, i64 104
  %8 = load i64, ptr %7, align 8, !tbaa !17
  %9 = and i64 %8, %6
  %.not = icmp eq i64 %9, %6
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  %11 = load i32, ptr %10, align 8, !tbaa !18
  %12 = icmp sgt i32 %11, 0
  br i1 %.not, label %14, label %.preheader

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

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

14:                                               ; preds = %2
  br i1 %12, label %.lr.ph17.preheader, label %.loopexit

.lr.ph17.preheader:                               ; preds = %14
  %15 = add nsw i32 %11, -1
  %16 = zext nneg i32 %15 to i64
  %17 = shl nuw i64 1, %16
  %wide.trip.count23 = zext nneg i32 %11 to i64
  %xtraiter = and i64 %wide.trip.count23, 1
  %18 = icmp eq i32 %11, 1
  br i1 %18, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph17.preheader.new

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

.lr.ph17:                                         ; preds = %.lr.ph17, %.lr.ph17.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph17.preheader.new ], [ %indvars.iv.next.1, %.lr.ph17 ]
  %.016 = phi i64 [ %17, %.lr.ph17.preheader.new ], [ %26, %.lr.ph17 ]
  %niter = phi i64 [ 0, %.lr.ph17.preheader.new ], [ %niter.next.1, %.lr.ph17 ]
  %19 = and i64 %6, %.016
  %.not12 = icmp eq i64 %19, 0
  %20 = select i1 %.not12, i8 48, i8 49
  %21 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %indvars.iv
  store i8 %20, ptr %21, align 2, !tbaa !19
  %22 = lshr i64 %.016, 1
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = and i64 %6, %22
  %.not12.1 = icmp eq i64 %23, 0
  %24 = select i1 %.not12.1, i8 48, i8 49
  %25 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %indvars.iv.next
  store i8 %24, ptr %25, align 1, !tbaa !19
  %26 = lshr i64 %.016, 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.ph17, !llvm.loop !20

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

.lr.ph17.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa
  %27 = and i64 %6, %.016.unr
  %.not12.epil = icmp eq i64 %27, 0
  %28 = select i1 %.not12.epil, i8 48, i8 49
  %29 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %indvars.iv.unr
  store i8 %28, ptr %29, align 1, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph17.epil, %.loopexit.loopexit.unr-lcssa, %.lr.ph.preheader, %.preheader, %14
  %.2 = phi i32 [ 0, %14 ], [ 0, %.preheader ], [ %11, %.lr.ph.preheader ], [ %11, %.loopexit.loopexit.unr-lcssa ], [ %11, %.lr.ph17.epil ]
  %30 = zext nneg i32 %.2 to i64
  %31 = getelementptr inbounds [1000 x i8], ptr %3, i64 0, i64 %30
  store i8 0, ptr %31, align 1, !tbaa !19
  %32 = getelementptr inbounds i8, ptr %0, i64 40
  %33 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %32) #4
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.10, ptr noundef %33, ptr noundef nonnull %3) #4
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = getelementptr inbounds i8, ptr %0, i64 96
  store i64 %36, ptr %37, align 8, !tbaa !22
  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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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_core15wif_int64_traceE", !7, i64 0, !10, i64 88, !15, i64 96, !15, i64 104}
!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 = !{!"long long", !11, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!6, !15, i64 104}
!18 = !{!7, !14, i64 80}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!6, !15, 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,TailCallElimPass