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

18:                                               ; preds = %2
  store i32 %17, ptr %13, align 4, !tbaa !18
  %19 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %7, i32 0, i32 3
  store i32 0, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %7, i32 0, i32 4
  store ptr null, ptr %20, align 8, !tbaa !20
  %21 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %7, 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 %7, i32 0, i32 3
  store i32 %25, ptr %26, align 8, !tbaa !19
  %27 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %7, 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 %7, i32 0, i32 4
  store ptr %34, ptr %36, align 8, !tbaa !20
  %37 = load ptr, ptr %4, 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 !17
  %40 = load ptr, ptr %4, 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 %4, 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) %7, i32 noundef %39, i32 noundef %42, ptr noundef %45)
          to label %46 unwind label %47

46:                                               ; preds = %35
  ret void

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

51:                                               ; preds = %47
  %52 = load ptr, ptr %5, align 8
  %53 = load i32, ptr %6, 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 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 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !14, i64 8}
!12 = !{!"_ZTSN5sc_dt9sc_signedE", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !6, i64 24}
!13 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 8}
!16 = !{!"_ZTSN5sc_dt11sc_unsignedE", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !6, i64 24}
!17 = !{!12, !14, i64 12}
!18 = !{!16, !14, i64 12}
!19 = !{!16, !14, i64 16}
!20 = !{!16, !6, i64 24}
!21 = !{!12, !14, i64 16}
!22 = !{!12, !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
define dso_local void @_ZN5sc_dt11sc_unsignedC2ERKNS_9sc_signedE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) 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
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !8
  store i32 %5, ptr %3, align 8, !tbaa !14
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = getelementptr inbounds i8, ptr %1, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !16
  %9 = tail call noundef i32 @_ZNK5sc_dt11sc_unsigned8num_bitsEi(ptr noundef nonnull align 8 dereferenceable(32) %0, i32 noundef %8)
  store i32 %9, ptr %6, align 4, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr null, ptr %11, align 8, !tbaa !18
  %12 = add nsw i32 %9, -1
  %13 = sdiv i32 %12, 30
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %10, align 8, !tbaa !19
  %15 = sext i32 %14 to i64
  %16 = icmp slt i32 %9, -58
  %17 = shl nsw i64 %15, 2
  %18 = select i1 %16, i64 -1, i64 %17
  %19 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %18) #5
          to label %20 unwind label %27

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

26:                                               ; preds = %20
  ret void

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

; 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 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_dt9sc_signedE", !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 8}
!15 = !{!"_ZTSN5sc_dt11sc_unsignedE", !10, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !13, i64 24}
!16 = !{!9, !11, i64 12}
!17 = !{!15, !11, i64 12}
!18 = !{!15, !13, i64 24}
!19 = !{!15, !11, i64 16}
!20 = !{!9, !11, i64 16}
!21 = !{!9, !13, i64 24}


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