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

; 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: 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

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

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

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 %37

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

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

29:                                               ; preds = %24
  store i32 %26, ptr %28, align 4, !tbaa !22
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = ashr i64 %30, 32
  %32 = trunc i64 %31 to i32
  %33 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 0
  %34 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %33, i32 noundef 2)
          to label %35 unwind label %37

35:                                               ; preds = %29
  store i32 %32, ptr %34, align 4, !tbaa !22
  %36 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 2
  store i32 1, ptr %36, align 4, !tbaa !17
  br label %56

37:                                               ; preds = %58, %56, %47, %41, %29, %24, %17
  %38 = landingpad { ptr, i32 }
          cleanup
  %39 = extractvalue { ptr, i32 } %38, 0
  store ptr %39, ptr %5, align 8
  %40 = extractvalue { ptr, i32 } %38, 1
  store i32 %40, ptr %6, align 4
  call void @_ZN5sc_dt9scfx_mantD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %8) #3
  br label %61

41:                                               ; preds = %19
  %42 = load i64, ptr %4, align 8, !tbaa !9
  %43 = sub nsw i64 0, %42
  %44 = trunc i64 %43 to i32
  %45 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 0
  %46 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %45, i32 noundef 1)
          to label %47 unwind label %37

47:                                               ; preds = %41
  store i32 %44, ptr %46, align 4, !tbaa !22
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = sub nsw i64 0, %48
  %50 = ashr i64 %49, 32
  %51 = trunc i64 %50 to i32
  %52 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 0
  %53 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %52, i32 noundef 2)
          to label %54 unwind label %37

54:                                               ; preds = %47
  store i32 %51, ptr %53, align 4, !tbaa !22
  %55 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %7, i32 0, i32 2
  store i32 -1, ptr %55, align 4, !tbaa !17
  br label %56

56:                                               ; preds = %54, %35
  invoke void @_ZN5sc_dt8scfx_rep7find_swEv(ptr noundef nonnull align 8 dereferenceable(37) %7)
          to label %57 unwind label %37

57:                                               ; preds = %56
  br label %60

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

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59, %57
  ret void

61:                                               ; preds = %37
  %62 = load ptr, ptr %5, align 8
  %63 = load i32, ptr %6, align 4
  %64 = insertvalue { ptr, i32 } poison, ptr %62, 0
  %65 = insertvalue { ptr, i32 } %64, i32 %63, 1
  resume { ptr, i32 } %65
}

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


; 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: 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: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt8scfx_rep7find_swEv(ptr noundef nonnull align 8 dereferenceable(37)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt8scfx_repC2Ex(ptr noundef nonnull align 8 dereferenceable(37) %0, i64 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
  %.not = icmp eq i64 %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 %16, label %6

6:                                                ; preds = %2
  invoke void @_ZN5sc_dt9scfx_mant5clearEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
          to label %7 unwind label %14

7:                                                ; preds = %6
  store i32 1, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %5, align 8, !tbaa !14
  %8 = icmp sgt i64 %1, 0
  %.sink12 = tail call i64 @llvm.abs.i64(i64 %1, i1 true)
  %storemerge = select i1 %8, i32 1, i32 -1
  %9 = trunc i64 %.sink12 to i32
  %10 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef 1)
  store i32 %9, ptr %10, align 4, !tbaa !15
  %11 = lshr i64 %.sink12, 32
  %12 = trunc nuw nsw i64 %11 to i32
  %13 = 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 %12, ptr %13, align 4, !tbaa !15
  store i32 %storemerge, ptr %4, align 4, !tbaa !16
  invoke void @_ZN5sc_dt8scfx_rep7find_swEv(ptr noundef nonnull align 8 dereferenceable(37) %0)
          to label %17 unwind label %14

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

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

17:                                               ; preds = %16, %7
  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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, 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 16}
!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, !12, i64 24}
!15 = !{!11, !11, i64 0}
!16 = !{!6, !11, i64 20}


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