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

; 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_signed" = 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_dt9sc_signedaSEd(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 = load double, ptr %4, align 8, !tbaa !9
  %9 = fcmp olt double %8, 0.000000e+00
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  %11 = load double, ptr %4, align 8, !tbaa !9
  %12 = fneg double %11
  store double %12, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %6, i32 0, i32 1
  store i32 -1, ptr %13, align 8, !tbaa !11
  br label %16

14:                                               ; preds = %2
  %15 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %6, i32 0, i32 1
  store i32 1, ptr %15, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %14, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !15
  br label %17

17:                                               ; preds = %28, %16
  %18 = load double, ptr %4, align 8, !tbaa !9
  %19 = call double @llvm.floor.f64(double %18)
  %20 = fcmp une double %19, 0.000000e+00
  br i1 %20, label %21, label %26

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 4, !tbaa !15
  %23 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %6, i32 0, i32 3
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = icmp slt i32 %22, %24
  br label %26

26:                                               ; preds = %21, %17
  %27 = phi i1 [ false, %17 ], [ %25, %21 ]
  br i1 %27, label %28, label %44

28:                                               ; preds = %26
  %29 = load double, ptr %4, align 8, !tbaa !9
  %30 = 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 %29, i64 noundef 1073741824)
  %31 = call double @llvm.floor.f64(double %30)
  %32 = fptoui double %31 to i32
  %33 = zext i32 %32 to i64
  %34 = and i64 %33, 1073741823
  %35 = trunc i64 %34 to i32
  %36 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %6, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = load i32, ptr %5, align 4, !tbaa !15
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !15
  %40 = sext i32 %38 to i64
  %41 = getelementptr inbounds i32, ptr %37, i64 %40
  store i32 %35, ptr %41, align 4, !tbaa !15
  %42 = load double, ptr %4, align 8, !tbaa !9
  %43 = fdiv double %42, 0x41D0000000000000
  store double %43, ptr %4, align 8, !tbaa !9
  br label %17, !llvm.loop !18

44:                                               ; preds = %26
  %45 = load i32, ptr %5, align 4, !tbaa !15
  %46 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %6, i32 0, i32 3
  %47 = load i32, ptr %46, align 8, !tbaa !16
  %48 = getelementptr inbounds %"class.sc_dt::sc_signed", ptr %6, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  call void @_ZN5sc_dt8vec_zeroEiiPj(i32 noundef %45, i32 noundef %47, ptr noundef %49)
  call void @_ZN5sc_dt9sc_signed22convert_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_dt9sc_signed22convert_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_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 = !{!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_dt9sc_signedaSEd(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 = fcmp olt double %1, 0.000000e+00
  %4 = fneg double %1
  %.sink = select i1 %3, i32 -1, i32 1
  %.09 = select i1 %3, double %4, double %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.sink, ptr %5, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = tail call double @llvm.floor.f64(double %.09)
  %8 = fcmp une double %7, 0.000000e+00
  %9 = load i32, ptr %6, align 8
  %10 = icmp sgt i32 %9, 0
  %or.cond14 = select i1 %8, i1 %10, i1 false
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  br i1 %or.cond14, label %.lr.ph, label %..critedge_crit_edge

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

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

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

.critedge:                                        ; preds = %..critedge_crit_edge, %.critedge.loopexit
  %25 = phi ptr [ %.pre, %..critedge_crit_edge ], [ %16, %.critedge.loopexit ]
  %.0.lcssa = phi i32 [ 0, %..critedge_crit_edge ], [ %24, %.critedge.loopexit ]
  %.lcssa = phi i32 [ %9, %..critedge_crit_edge ], [ %21, %.critedge.loopexit ]
  tail call void @_ZN5sc_dt8vec_zeroEiiPj(i32 noundef %.0.lcssa, i32 noundef %.lcssa, ptr noundef %25)
  tail call void @_ZN5sc_dt9sc_signed22convert_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_dt9sc_signed22convert_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, !11, i64 24}
!6 = !{!"_ZTSN5sc_dt9sc_signedE", !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 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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