; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/int (sc_unsigned)

; 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::sc_unsigned" = type { %"class.sc_dt::sc_value_base", i32, i32, i32, ptr }
%"class.sc_dt::sc_value_base" = type { ptr }
%"class.sc_dt::sc_signed" = type { %"class.sc_dt::sc_value_base", i32, i32, i32, ptr }

@_ZTVN5sc_dt11sc_unsignedE = external dso_local unnamed_addr constant { [13 x ptr] }, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5sc_dt11sc_unsigned8num_bitsEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt13sc_value_baseC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5sc_dt11sc_unsigned11copy_digitsEiiPKj(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, ptr noundef) #4 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt11sc_unsignedC2ERKNS_9sc_signedEi(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef %2) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN5sc_dt13sc_value_baseC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %10) #5
  store ptr getelementptr inbounds inrange(-16, 88) ({ [13 x ptr] }, ptr @_ZTVN5sc_dt11sc_unsignedE, i32 0, i32 0, i32 2), ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 1
  %12 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %12, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = invoke noundef i32 @_ZNK5sc_dt11sc_unsigned8num_bitsEi(ptr noundef nonnull align 8 dereferenceable(32) %9, i32 noundef %16)
          to label %18 unwind label %47

18:                                               ; preds = %3
  store i32 %17, ptr %13, align 4, !tbaa !18
  %19 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 3
  store i32 0, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 4
  store ptr null, ptr %20, align 8, !tbaa !20
  %21 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !18
  %23 = sub nsw i32 %22, 1
  %24 = sdiv i32 %23, 30
  %25 = add nsw i32 %24, 1
  %26 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 3
  store i32 %25, ptr %26, align 8, !tbaa !19
  %27 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 3
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = sext i32 %28 to i64
  %30 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %29, i64 4)
  %31 = extractvalue { i64, i1 } %30, 1
  %32 = extractvalue { i64, i1 } %30, 0
  %33 = select i1 %31, i64 -1, i64 %32
  %34 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %33) #6
          to label %35 unwind label %47

35:                                               ; preds = %18
  %36 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %9, i32 0, i32 4
  store ptr %34, ptr %36, align 8, !tbaa !20
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !16
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %40, i32 0, i32 3
  %42 = load i32, ptr %41, align 8, !tbaa !21
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  invoke void @_ZN5sc_dt11sc_unsigned11copy_digitsEiiPKj(ptr noundef nonnull align 8 dereferenceable(32) %9, i32 noundef %39, i32 noundef %42, ptr noundef %45)
          to label %46 unwind label %47

46:                                               ; preds = %35
  ret void

47:                                               ; preds = %35, %18, %3
  %48 = landingpad { ptr, i32 }
          cleanup
  %49 = extractvalue { ptr, i32 } %48, 0
  store ptr %49, ptr %7, align 8
  %50 = extractvalue { ptr, i32 } %48, 1
  store i32 %50, ptr %8, align 4
  call void @_ZN5sc_dt13sc_value_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %9) #5
  br label %51

51:                                               ; preds = %47
  %52 = load ptr, ptr %7, align 8
  %53 = load i32, ptr %8, align 4
  %54 = insertvalue { ptr, i32 } poison, ptr %52, 0
  %55 = insertvalue { ptr, i32 } %54, i32 %53, 1
  resume { ptr, i32 } %55
}

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nobuiltin allocsize(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 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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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, !10, i64 8}
!14 = !{!"_ZTSN5sc_dt11sc_unsignedE", !15, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24}
!15 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!16 = !{!17, !10, i64 12}
!17 = !{!"_ZTSN5sc_dt9sc_signedE", !15, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24}
!18 = !{!14, !10, i64 12}
!19 = !{!14, !10, i64 16}
!20 = !{!14, !6, i64 24}
!21 = !{!17, !10, i64 16}
!22 = !{!17, !6, i64 24}


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

@_ZTVN5sc_dt11sc_unsignedE = external dso_local unnamed_addr constant { [13 x ptr] }, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5sc_dt11sc_unsigned11copy_digitsEiiPKj(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt11sc_unsignedC2ERKNS_9sc_signedEi(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef %2) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN5sc_dt13sc_value_baseC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %1) #4
  store ptr getelementptr inbounds inrange(-16, 88) (i8, ptr @_ZTVN5sc_dt11sc_unsignedE, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %2, ptr %4, align 8, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !14
  %8 = tail call noundef i32 @_ZNK5sc_dt11sc_unsigned8num_bitsEi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %7)
  store i32 %8, ptr %5, align 4, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr null, ptr %10, align 8, !tbaa !17
  %11 = add nsw i32 %8, -1
  %12 = sdiv i32 %11, 30
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %9, align 8, !tbaa !18
  %14 = sext i32 %13 to i64
  %15 = icmp slt i32 %8, -58
  %16 = shl nsw i64 %14, 2
  %17 = select i1 %15, i64 -1, i64 %16
  %18 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %17) #5
          to label %19 unwind label %26

19:                                               ; preds = %3
  store ptr %18, ptr %10, align 8, !tbaa !17
  %20 = load i32, ptr %6, align 4, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %1, i64 16
  %22 = load i32, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %1, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !20
  invoke void @_ZN5sc_dt11sc_unsigned11copy_digitsEiiPKj(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %20, i32 noundef %22, ptr noundef %24)
          to label %25 unwind label %26

25:                                               ; preds = %19
  ret void

26:                                               ; preds = %19, %3
  %27 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN5sc_dt13sc_value_baseD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #4
  resume { ptr, i32 } %27
}

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

attributes #0 = { nobuiltin allocsize(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 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 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { builtin allocsize(0) }

!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, !11, i64 8}
!9 = !{!"_ZTSN5sc_dt11sc_unsignedE", !10, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !13, i64 24}
!10 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"any pointer", !12, i64 0}
!14 = !{!15, !11, i64 12}
!15 = !{!"_ZTSN5sc_dt9sc_signedE", !10, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !13, i64 24}
!16 = !{!9, !11, i64 12}
!17 = !{!9, !13, i64 24}
!18 = !{!9, !11, i64 16}
!19 = !{!15, !11, i64 16}
!20 = !{!15, !13, i64 24}


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