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

; 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_ieee_double" = type { %"union.sc_dt::ieee_double" }
%"union.sc_dt::ieee_double" = type { double }
%"class.sc_dt::sc_fxnum_fast" = type { double, %"class.sc_dt::scfx_params", i8, i8, ptr }
%"class.sc_dt::scfx_params" = type { %"class.sc_dt::sc_fxtype_params", i32, %"class.sc_dt::sc_fxcast_switch" }
%"class.sc_dt::sc_fxtype_params" = type { i32, i32, i32, i32, i32 }
%"class.sc_dt::sc_fxcast_switch" = type { i32 }

; 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
declare dso_local noundef zeroext i1 @_ZNK5sc_dt13sc_fxnum_fast7get_bitEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5sc_dt13sc_fxnum_fast7set_bitEib(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, i1 noundef zeroext %2) #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca %"class.sc_dt::scfx_ieee_double", align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %7, align 1, !tbaa !11
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %12 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 0
  %13 = load double, ptr %12, align 8, !tbaa !13
  call void @_ZN5sc_dt16scfx_ieee_doubleC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %8, double noundef %13)
  %14 = call noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_nanEv(ptr noundef nonnull align 8 dereferenceable(8) %8)
  br i1 %14, label %17, label %15

15:                                               ; preds = %3
  %16 = call noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_infEv(ptr noundef nonnull align 8 dereferenceable(8) %8)
  br i1 %16, label %17, label %18

17:                                               ; preds = %15, %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %76

18:                                               ; preds = %15
  %19 = load i8, ptr %7, align 1, !tbaa !11, !range !23, !noundef !24
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %48

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = call noundef zeroext i1 @_ZNK5sc_dt13sc_fxnum_fast7get_bitEi(ptr noundef nonnull align 8 dereferenceable(48) %11, i32 noundef %22)
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %76

25:                                               ; preds = %21
  %26 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 1
  %27 = call noundef i32 @_ZNK5sc_dt11scfx_params3encEv(ptr noundef nonnull align 4 dereferenceable(28) %26)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %41

29:                                               ; preds = %25
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 1
  %32 = call noundef i32 @_ZNK5sc_dt11scfx_params3iwlEv(ptr noundef nonnull align 4 dereferenceable(28) %31)
  %33 = sub nsw i32 %32, 1
  %34 = icmp eq i32 %30, %33
  br i1 %34, label %35, label %41

35:                                               ; preds = %29
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %36)
  %38 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 0
  %39 = load double, ptr %38, align 8, !tbaa !13
  %40 = fsub double %39, %37
  store double %40, ptr %38, align 8, !tbaa !13
  br label %47

41:                                               ; preds = %29, %25
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %42)
  %44 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 0
  %45 = load double, ptr %44, align 8, !tbaa !13
  %46 = fadd double %45, %43
  store double %46, ptr %44, align 8, !tbaa !13
  br label %47

47:                                               ; preds = %41, %35
  br label %75

48:                                               ; preds = %18
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = call noundef zeroext i1 @_ZNK5sc_dt13sc_fxnum_fast7get_bitEi(ptr noundef nonnull align 8 dereferenceable(48) %11, i32 noundef %49)
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %76

52:                                               ; preds = %48
  %53 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 1
  %54 = call noundef i32 @_ZNK5sc_dt11scfx_params3encEv(ptr noundef nonnull align 4 dereferenceable(28) %53)
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %68

56:                                               ; preds = %52
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 1
  %59 = call noundef i32 @_ZNK5sc_dt11scfx_params3iwlEv(ptr noundef nonnull align 4 dereferenceable(28) %58)
  %60 = sub nsw i32 %59, 1
  %61 = icmp eq i32 %57, %60
  br i1 %61, label %62, label %68

62:                                               ; preds = %56
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %63)
  %65 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 0
  %66 = load double, ptr %65, align 8, !tbaa !13
  %67 = fadd double %66, %64
  store double %67, ptr %65, align 8, !tbaa !13
  br label %74

68:                                               ; preds = %56, %52
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %69)
  %71 = getelementptr inbounds %"class.sc_dt::sc_fxnum_fast", ptr %11, i32 0, i32 0
  %72 = load double, ptr %71, align 8, !tbaa !13
  %73 = fsub double %72, %70
  store double %73, ptr %71, align 8, !tbaa !13
  br label %74

74:                                               ; preds = %68, %62
  br label %75

75:                                               ; preds = %74, %47
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %76

76:                                               ; preds = %75, %51, %24, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %77 = load i1, ptr %4, align 1
  ret i1 %77
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_nanEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_infEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5sc_dt11scfx_params3encEv(ptr noundef nonnull align 4 dereferenceable(28)) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK5sc_dt11scfx_params3iwlEv(ptr noundef nonnull align 4 dereferenceable(28)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef) #3

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

!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 = !{!"bool", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN5sc_dt13sc_fxnum_fastE", !15, i64 0, !16, i64 8, !12, i64 36, !12, i64 37, !6, i64 40}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTSN5sc_dt11scfx_paramsE", !17, i64 0, !20, i64 20, !21, i64 24}
!17 = !{!"_ZTSN5sc_dt16sc_fxtype_paramsE", !10, i64 0, !10, i64 4, !18, i64 8, !19, i64 12, !10, i64 16}
!18 = !{!"_ZTSN5sc_dt9sc_q_modeE", !7, i64 0}
!19 = !{!"_ZTSN5sc_dt9sc_o_modeE", !7, i64 0}
!20 = !{!"_ZTSN5sc_dt6sc_encE", !7, i64 0}
!21 = !{!"_ZTSN5sc_dt16sc_fxcast_switchE", !22, i64 0}
!22 = !{!"_ZTSN5sc_dt9sc_switchE", !7, i64 0}
!23 = !{i8 0, i8 2}
!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"

%"class.sc_dt::scfx_ieee_double" = type { %"union.sc_dt::ieee_double" }
%"union.sc_dt::ieee_double" = type { double }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5sc_dt13sc_fxnum_fast7get_bitEi(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5sc_dt13sc_fxnum_fast7set_bitEib(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #1 align 2 {
  %4 = alloca %"class.sc_dt::scfx_ieee_double", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %5 = load double, ptr %0, align 8, !tbaa !5
  call void @_ZN5sc_dt16scfx_ieee_doubleC2Ed(ptr noundef nonnull align 8 dereferenceable(8) %4, double noundef %5)
  %6 = call noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_nanEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %6, label %45, label %7

7:                                                ; preds = %3
  %8 = call noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_infEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %8, label %45, label %9

9:                                                ; preds = %7
  %10 = call noundef zeroext i1 @_ZNK5sc_dt13sc_fxnum_fast7get_bitEi(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1)
  br i1 %2, label %11, label %28

11:                                               ; preds = %9
  br i1 %10, label %45, label %12

12:                                               ; preds = %11
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = call noundef i32 @_ZNK5sc_dt11scfx_params3encEv(ptr noundef nonnull align 4 dereferenceable(28) %13)
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %24

16:                                               ; preds = %12
  %17 = call noundef i32 @_ZNK5sc_dt11scfx_params3iwlEv(ptr noundef nonnull align 4 dereferenceable(28) %13)
  %18 = add nsw i32 %17, -1
  %19 = icmp eq i32 %18, %1
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %1)
  %22 = load double, ptr %0, align 8, !tbaa !5
  %23 = fsub double %22, %21
  br label %.sink.split

24:                                               ; preds = %16, %12
  %25 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %1)
  %26 = load double, ptr %0, align 8, !tbaa !5
  %27 = fadd double %25, %26
  br label %.sink.split

28:                                               ; preds = %9
  br i1 %10, label %29, label %45

29:                                               ; preds = %28
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  %31 = call noundef i32 @_ZNK5sc_dt11scfx_params3encEv(ptr noundef nonnull align 4 dereferenceable(28) %30)
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %29
  %34 = call noundef i32 @_ZNK5sc_dt11scfx_params3iwlEv(ptr noundef nonnull align 4 dereferenceable(28) %30)
  %35 = add nsw i32 %34, -1
  %36 = icmp eq i32 %35, %1
  br i1 %36, label %37, label %41

37:                                               ; preds = %33
  %38 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %1)
  %39 = load double, ptr %0, align 8, !tbaa !5
  %40 = fadd double %38, %39
  br label %.sink.split

41:                                               ; preds = %33, %29
  %42 = call noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef %1)
  %43 = load double, ptr %0, align 8, !tbaa !5
  %44 = fsub double %43, %42
  br label %.sink.split

.sink.split:                                      ; preds = %37, %41, %20, %24
  %.sink = phi double [ %27, %24 ], [ %23, %20 ], [ %44, %41 ], [ %40, %37 ]
  store double %.sink, ptr %0, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %.sink.split, %28, %11, %3, %7
  %.0 = phi i1 [ false, %7 ], [ false, %3 ], [ true, %11 ], [ true, %28 ], [ true, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i1 %.0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_nanEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5sc_dt16scfx_ieee_double6is_infEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK5sc_dt11scfx_params3encEv(ptr noundef nonnull align 4 dereferenceable(28)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK5sc_dt11scfx_params3iwlEv(ptr noundef nonnull align 4 dereferenceable(28)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN5sc_dt9scfx_pow2Ei(i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 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 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 }

!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, !7, i64 0}
!6 = !{!"_ZTSN5sc_dt13sc_fxnum_fastE", !7, i64 0, !10, i64 8, !18, i64 36, !18, i64 37, !19, i64 40}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN5sc_dt11scfx_paramsE", !11, i64 0, !15, i64 20, !16, i64 24}
!11 = !{!"_ZTSN5sc_dt16sc_fxtype_paramsE", !12, i64 0, !12, i64 4, !13, i64 8, !14, i64 12, !12, i64 16}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_ZTSN5sc_dt9sc_q_modeE", !8, i64 0}
!14 = !{!"_ZTSN5sc_dt9sc_o_modeE", !8, i64 0}
!15 = !{!"_ZTSN5sc_dt6sc_encE", !8, i64 0}
!16 = !{!"_ZTSN5sc_dt16sc_fxcast_switchE", !17, i64 0}
!17 = !{!"_ZTSN5sc_dt9sc_switchE", !8, i64 0}
!18 = !{!"bool", !8, i64 0}
!19 = !{!"any pointer", !8, i64 0}


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