; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/fx/scfx_rep.ll (ZN5sc_dt8scfx_repC2Ei)

; 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_dt::scfx_rep" = type <{ %"class.sc_dt::scfx_mant", i32, i32, i32, i32, i32, i8, [3 x i8] }>
%"class.sc_dt::scfx_mant" = type <{ ptr, i32, [4 x i8] }>

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt9scfx_mantC2Em(ptr noundef nonnull align 8 dereferenceable(12), i64 noundef) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt8scfx_rep8set_zeroEi(ptr noundef nonnull align 8 dereferenceable(37), i32 noundef) #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt9scfx_mantD2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt8scfx_repC2Ei(ptr noundef nonnull align 8 dereferenceable(37) %0, i32 noundef %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 0
  call void @_ZN5sc_dt9scfx_mantC2Em(ptr noundef nonnull align 8 dereferenceable(12) %8, i64 noundef 4)
  %9 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 1
  store i32 0, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 2
  store i32 0, ptr %10, align 4, !tbaa !16
  %11 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 3
  store i32 0, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 4
  store i32 0, ptr %12, align 4, !tbaa !18
  %13 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 5
  store i32 0, ptr %13, align 8, !tbaa !19
  %14 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 6
  store i8 0, ptr %14, align 4, !tbaa !20
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %44

17:                                               ; preds = %2
  %18 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 0
  invoke void @_ZN5sc_dt9scfx_mant5clearEv(ptr noundef nonnull align 8 dereferenceable(12) %18)
          to label %19 unwind label %32

19:                                               ; preds = %17
  %20 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 5
  store i32 2, ptr %20, align 8, !tbaa !19
  %21 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 4
  store i32 2, ptr %21, align 4, !tbaa !18
  %22 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 1
  store i32 2, ptr %22, align 8, !tbaa !11
  %23 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 3
  store i32 0, ptr %23, align 8, !tbaa !17
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %36

26:                                               ; preds = %19
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 0
  %29 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %28, i32 noundef 2)
          to label %30 unwind label %32

30:                                               ; preds = %26
  store i32 %27, ptr %29, align 4, !tbaa !9
  %31 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 2
  store i32 1, ptr %31, align 4, !tbaa !16
  br label %43

32:                                               ; preds = %44, %36, %26, %17
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %5, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %6, align 4
  call void @_ZN5sc_dt9scfx_mantD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %8) #3
  br label %47

36:                                               ; preds = %19
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = sub nsw i32 0, %37
  %39 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 0
  %40 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %39, i32 noundef 2)
          to label %41 unwind label %32

41:                                               ; preds = %36
  store i32 %38, ptr %40, align 4, !tbaa !9
  %42 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 2
  store i32 -1, ptr %42, align 4, !tbaa !16
  br label %43

43:                                               ; preds = %41, %30
  br label %46

44:                                               ; preds = %2
  invoke void @_ZN5sc_dt8scfx_rep8set_zeroEi(ptr noundef nonnull align 8 dereferenceable(37) %7, i32 noundef 1)
          to label %45 unwind label %32

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45, %43
  ret void

47:                                               ; preds = %32
  %48 = load ptr, ptr %5, align 8
  %49 = load i32, ptr %6, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt9scfx_mant5clearEv(ptr noundef nonnull align 8 dereferenceable(12)) #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) #1 align 2

attributes #0 = { 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 #1 = { inlinehint 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 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTSN5sc_dt8scfx_repE", !13, i64 0, !10, i64 16, !10, i64 20, !14, i64 24, !10, i64 28, !10, i64 32, !15, i64 36}
!13 = !{!"_ZTSN5sc_dt9scfx_mantE", !6, i64 0, !10, i64 8}
!14 = !{!"_ZTSN5sc_dt8scfx_rep5stateE", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !10, i64 20}
!17 = !{!12, !14, i64 24}
!18 = !{!12, !10, i64 28}
!19 = !{!12, !10, i64 32}
!20 = !{!12, !15, i64 36}


; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt9scfx_mantC2Em(ptr noundef nonnull align 8 dereferenceable(12), i64 noundef) unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt8scfx_rep8set_zeroEi(ptr noundef nonnull align 8 dereferenceable(37), i32 noundef) local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt9scfx_mantD2Ev(ptr noundef nonnull align 8 dereferenceable(12)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt8scfx_repC2Ei(ptr noundef nonnull align 8 dereferenceable(37) %0, i32 noundef %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN5sc_dt9scfx_mantC2Em(ptr noundef nonnull align 8 dereferenceable(12) %0, i64 noundef 4)
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = getelementptr inbounds i8, ptr %0, i64 20
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = getelementptr inbounds i8, ptr %0, i64 28
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %.not = icmp eq i32 %1, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(21) %3, i8 0, i64 21, i1 false)
  br i1 %.not, label %12, label %8

8:                                                ; preds = %2
  invoke void @_ZN5sc_dt9scfx_mant5clearEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
          to label %.sink.split unwind label %10

.sink.split:                                      ; preds = %8
  store i32 2, ptr %7, align 8, !tbaa !5
  store i32 2, ptr %6, align 4, !tbaa !14
  store i32 2, ptr %3, align 8, !tbaa !15
  store i32 0, ptr %5, align 8, !tbaa !16
  %.sink6 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
  %.inv = icmp slt i32 %1, 1
  %.sink = select i1 %.inv, i32 -1, i32 1
  %9 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef 2)
  store i32 %.sink6, ptr %9, align 4, !tbaa !17
  store i32 %.sink, ptr %4, align 4, !tbaa !18
  br label %13

10:                                               ; preds = %12, %8
  %11 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN5sc_dt9scfx_mantD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %0) #5
  resume { ptr, i32 } %11

12:                                               ; preds = %2
  invoke void @_ZN5sc_dt8scfx_rep8set_zeroEi(ptr noundef nonnull align 8 dereferenceable(37) %0, i32 noundef 1)
          to label %13 unwind label %10

13:                                               ; preds = %.sink.split, %12
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt9scfx_mant5clearEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #0 align 2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

attributes #0 = { 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 #1 = { inlinehint 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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 32}
!6 = !{!"_ZTSN5sc_dt8scfx_repE", !7, i64 0, !11, i64 16, !11, i64 20, !12, i64 24, !11, i64 28, !11, i64 32, !13, i64 36}
!7 = !{!"_ZTSN5sc_dt9scfx_mantE", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"_ZTSN5sc_dt8scfx_rep5stateE", !9, i64 0}
!13 = !{!"bool", !9, i64 0}
!14 = !{!6, !11, i64 28}
!15 = !{!6, !11, i64 16}
!16 = !{!6, !12, i64 24}
!17 = !{!11, !11, i64 0}
!18 = !{!6, !11, i64 20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass