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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt11sc_unsignedaSEd(ptr noundef nonnull align 8 dereferenceable(32) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load double, ptr %4, align 8, !tbaa !9
  call void @_ZN5sc_dt13is_bad_doubleEd(double noundef %7)
  %8 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %6, i32 0, i32 1
  store i32 1, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !15
  br label %9

9:                                                ; preds = %20, %2
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = call double @llvm.floor.f64(double %10)
  %12 = fcmp une double %11, 0.000000e+00
  br i1 %12, label %13, label %18

13:                                               ; preds = %9
  %14 = load i32, ptr %5, align 4, !tbaa !15
  %15 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %6, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %17 = icmp slt i32 %14, %16
  br label %18

18:                                               ; preds = %13, %9
  %19 = phi i1 [ false, %9 ], [ %17, %13 ]
  br i1 %19, label %20, label %36

20:                                               ; preds = %18
  %21 = load double, ptr %4, align 8, !tbaa !9
  %22 = call noundef double @_ZSt9remainderIdmEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(double noundef %21, i64 noundef 1073741824)
  %23 = call double @llvm.floor.f64(double %22)
  %24 = fptoui double %23 to i32
  %25 = zext i32 %24 to i64
  %26 = and i64 %25, 1073741823
  %27 = trunc i64 %26 to i32
  %28 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %6, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !17
  %30 = load i32, ptr %5, align 4, !tbaa !15
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %5, align 4, !tbaa !15
  %32 = sext i32 %30 to i64
  %33 = getelementptr inbounds i32, ptr %29, i64 %32
  store i32 %27, ptr %33, align 4, !tbaa !15
  %34 = load double, ptr %4, align 8, !tbaa !9
  %35 = fdiv double %34, 0x41D0000000000000
  store double %35, ptr %4, align 8, !tbaa !9
  br label %9, !llvm.loop !18

36:                                               ; preds = %18
  %37 = load i32, ptr %5, align 4, !tbaa !15
  %38 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %6, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !16
  %40 = getelementptr inbounds %"class.sc_dt::sc_unsigned", ptr %6, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  call void @_ZN5sc_dt8vec_zeroEiiPj(i32 noundef %37, i32 noundef %39, ptr noundef %41)
  call void @_ZN5sc_dt11sc_unsigned22convert_SM_to_2C_to_SMEv(ptr noundef nonnull align 8 dereferenceable(32) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  ret ptr %6
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt13is_bad_doubleEd(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt9remainderIdmEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(double noundef, i64 noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt8vec_zeroEiiPj(i32 noundef, i32 noundef, ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { 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 #6 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !14, i64 8}
!12 = !{!"_ZTSN5sc_dt11sc_unsignedE", !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 = !{!14, !14, i64 0}
!16 = !{!12, !14, i64 16}
!17 = !{!12, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZN5sc_dt11sc_unsignedaSEd(ptr noundef nonnull returned align 8 dereferenceable(32) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  tail call void @_ZN5sc_dt13is_bad_doubleEd(double noundef %1)
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = tail call double @llvm.floor.f64(double %1)
  %6 = fcmp une double %5, 0.000000e+00
  %7 = load i32, ptr %4, align 8
  %8 = icmp sgt i32 %7, 0
  %or.cond10 = select i1 %6, i1 %8, i1 false
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  br i1 %or.cond10, label %.lr.ph, label %..critedge_crit_edge

..critedge_crit_edge:                             ; preds = %2
  %.pre = load ptr, ptr %9, align 8, !tbaa !12
  br label %.critedge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %.0711 = phi double [ %16, %.lr.ph ], [ %1, %2 ]
  %10 = tail call noundef double @_ZSt9remainderIdmEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(double noundef %.0711, i64 noundef 1073741824)
  %11 = tail call double @llvm.floor.f64(double %10)
  %12 = fptoui double %11 to i32
  %13 = and i32 %12, 1073741823
  %14 = load ptr, ptr %9, align 8, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv
  store i32 %13, ptr %15, align 4, !tbaa !13
  %16 = fmul double %.0711, 0x3E10000000000000
  %17 = tail call double @llvm.floor.f64(double %16)
  %18 = fcmp une double %17, 0.000000e+00
  %19 = load i32, ptr %4, align 8
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  %or.cond = select i1 %18, i1 %21, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge.loopexit, !llvm.loop !14

.critedge.loopexit:                               ; preds = %.lr.ph
  %22 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %.critedge

.critedge:                                        ; preds = %..critedge_crit_edge, %.critedge.loopexit
  %23 = phi ptr [ %.pre, %..critedge_crit_edge ], [ %14, %.critedge.loopexit ]
  %.0.lcssa = phi i32 [ 0, %..critedge_crit_edge ], [ %22, %.critedge.loopexit ]
  %.lcssa = phi i32 [ %7, %..critedge_crit_edge ], [ %19, %.critedge.loopexit ]
  tail call void @_ZN5sc_dt8vec_zeroEiiPj(i32 noundef %.0.lcssa, i32 noundef %.lcssa, ptr noundef %23)
  tail call void @_ZN5sc_dt11sc_unsigned22convert_SM_to_2C_to_SMEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  ret ptr %0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN5sc_dt13is_bad_doubleEd(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt9remainderIdmEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(double noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5sc_dt8vec_zeroEiiPj(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { 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 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = { 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" }

!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, !8, i64 8}
!6 = !{!"_ZTSN5sc_dt11sc_unsignedE", !7, i64 0, !8, i64 8, !8, i64 12, !8, i64 16, !11, i64 24}
!7 = !{!"_ZTSN5sc_dt13sc_value_baseE"}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!6, !11, i64 24}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass