; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (GetSysClockFreq)

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

%struct.RCC_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [9 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [4 x 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: nounwind uwtable
define dso_local i32 @HAL_RCC_GetSysClockFreq() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %9 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 4), align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = and i64 %10, 56
  switch i64 %11, label %160 [
    i64 0, label %12
    i64 8, label %29
    i64 16, label %30
    i64 24, label %31
  ]

12:                                               ; preds = %0
  %13 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 4, !tbaa !10
  %14 = zext i32 %13 to i64
  %15 = and i64 %14, 32
  %16 = icmp ne i64 %15, 0
  %17 = zext i1 %16 to i64
  %18 = select i1 %16, i32 1, i32 0
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %27

20:                                               ; preds = %12
  %21 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 4, !tbaa !10
  %22 = zext i32 %21 to i64
  %23 = and i64 %22, 24
  %24 = trunc i64 %23 to i32
  %25 = lshr i32 %24, 3
  %26 = lshr i32 64000000, %25
  store i32 %26, ptr %8, align 4, !tbaa !11
  br label %28

27:                                               ; preds = %12
  store i32 64000000, ptr %8, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %27, %20
  br label %161

29:                                               ; preds = %0
  store i32 4000000, ptr %8, align 4, !tbaa !11
  br label %161

30:                                               ; preds = %0
  store i32 16000000, ptr %8, align 4, !tbaa !11
  br label %161

31:                                               ; preds = %0
  %32 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 10), align 4, !tbaa !12
  %33 = zext i32 %32 to i64
  %34 = and i64 %33, 3
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %2, align 4, !tbaa !11
  %36 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 10), align 4, !tbaa !12
  %37 = zext i32 %36 to i64
  %38 = and i64 %37, 1008
  %39 = lshr i64 %38, 4
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %3, align 4, !tbaa !11
  %41 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 11), align 4, !tbaa !13
  %42 = zext i32 %41 to i64
  %43 = and i64 %42, 1
  %44 = lshr i64 %43, 0
  %45 = trunc i64 %44 to i32
  store i32 %45, ptr %4, align 4, !tbaa !11
  %46 = load i32, ptr %4, align 4, !tbaa !11
  %47 = zext i32 %46 to i64
  %48 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 13), align 4, !tbaa !14
  %49 = zext i32 %48 to i64
  %50 = and i64 %49, 65528
  %51 = lshr i64 %50, 3
  %52 = mul i64 %47, %51
  %53 = trunc i64 %52 to i32
  %54 = uitofp i32 %53 to float
  store float %54, ptr %6, align 4, !tbaa !15
  %55 = load i32, ptr %3, align 4, !tbaa !11
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %158

57:                                               ; preds = %31
  %58 = load i32, ptr %2, align 4, !tbaa !11
  switch i32 %58, label %132 [
    i32 0, label %59
    i32 1, label %104
    i32 2, label %118
  ]

59:                                               ; preds = %57
  %60 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 4, !tbaa !10
  %61 = zext i32 %60 to i64
  %62 = and i64 %61, 32
  %63 = icmp ne i64 %62, 0
  %64 = zext i1 %63 to i64
  %65 = select i1 %63, i32 1, i32 0
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %89

67:                                               ; preds = %59
  %68 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 4, !tbaa !10
  %69 = zext i32 %68 to i64
  %70 = and i64 %69, 24
  %71 = trunc i64 %70 to i32
  %72 = lshr i32 %71, 3
  %73 = lshr i32 64000000, %72
  store i32 %73, ptr %5, align 4, !tbaa !11
  %74 = load i32, ptr %5, align 4, !tbaa !11
  %75 = uitofp i32 %74 to float
  %76 = load i32, ptr %3, align 4, !tbaa !11
  %77 = uitofp i32 %76 to float
  %78 = fdiv float %75, %77
  %79 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 12), align 4, !tbaa !17
  %80 = zext i32 %79 to i64
  %81 = and i64 %80, 511
  %82 = trunc i64 %81 to i32
  %83 = uitofp i32 %82 to float
  %84 = load float, ptr %6, align 4, !tbaa !15
  %85 = fdiv float %84, 8.192000e+03
  %86 = fadd float %83, %85
  %87 = fadd float %86, 1.000000e+00
  %88 = fmul float %78, %87
  store float %88, ptr %7, align 4, !tbaa !15
  br label %103

89:                                               ; preds = %59
  %90 = load i32, ptr %3, align 4, !tbaa !11
  %91 = uitofp i32 %90 to float
  %92 = fdiv float 6.400000e+07, %91
  %93 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 12), align 4, !tbaa !17
  %94 = zext i32 %93 to i64
  %95 = and i64 %94, 511
  %96 = trunc i64 %95 to i32
  %97 = uitofp i32 %96 to float
  %98 = load float, ptr %6, align 4, !tbaa !15
  %99 = fdiv float %98, 8.192000e+03
  %100 = fadd float %97, %99
  %101 = fadd float %100, 1.000000e+00
  %102 = fmul float %92, %101
  store float %102, ptr %7, align 4, !tbaa !15
  br label %103

103:                                              ; preds = %89, %67
  br label %146

104:                                              ; preds = %57
  %105 = load i32, ptr %3, align 4, !tbaa !11
  %106 = uitofp i32 %105 to float
  %107 = fdiv float 4.000000e+06, %106
  %108 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 12), align 4, !tbaa !17
  %109 = zext i32 %108 to i64
  %110 = and i64 %109, 511
  %111 = trunc i64 %110 to i32
  %112 = uitofp i32 %111 to float
  %113 = load float, ptr %6, align 4, !tbaa !15
  %114 = fdiv float %113, 8.192000e+03
  %115 = fadd float %112, %114
  %116 = fadd float %115, 1.000000e+00
  %117 = fmul float %107, %116
  store float %117, ptr %7, align 4, !tbaa !15
  br label %146

118:                                              ; preds = %57
  %119 = load i32, ptr %3, align 4, !tbaa !11
  %120 = uitofp i32 %119 to float
  %121 = fdiv float 1.600000e+07, %120
  %122 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 12), align 4, !tbaa !17
  %123 = zext i32 %122 to i64
  %124 = and i64 %123, 511
  %125 = trunc i64 %124 to i32
  %126 = uitofp i32 %125 to float
  %127 = load float, ptr %6, align 4, !tbaa !15
  %128 = fdiv float %127, 8.192000e+03
  %129 = fadd float %126, %128
  %130 = fadd float %129, 1.000000e+00
  %131 = fmul float %121, %130
  store float %131, ptr %7, align 4, !tbaa !15
  br label %146

132:                                              ; preds = %57
  %133 = load i32, ptr %3, align 4, !tbaa !11
  %134 = uitofp i32 %133 to float
  %135 = fdiv float 4.000000e+06, %134
  %136 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 12), align 4, !tbaa !17
  %137 = zext i32 %136 to i64
  %138 = and i64 %137, 511
  %139 = trunc i64 %138 to i32
  %140 = uitofp i32 %139 to float
  %141 = load float, ptr %6, align 4, !tbaa !15
  %142 = fdiv float %141, 8.192000e+03
  %143 = fadd float %140, %142
  %144 = fadd float %143, 1.000000e+00
  %145 = fmul float %135, %144
  store float %145, ptr %7, align 4, !tbaa !15
  br label %146

146:                                              ; preds = %132, %118, %104, %103
  %147 = load volatile i32, ptr getelementptr inbounds (%struct.RCC_TypeDef, ptr inttoptr (i64 1476543488 to ptr), i32 0, i32 12), align 4, !tbaa !17
  %148 = zext i32 %147 to i64
  %149 = and i64 %148, 65024
  %150 = lshr i64 %149, 9
  %151 = add i64 %150, 1
  %152 = trunc i64 %151 to i32
  store i32 %152, ptr %1, align 4, !tbaa !11
  %153 = load float, ptr %7, align 4, !tbaa !15
  %154 = load i32, ptr %1, align 4, !tbaa !11
  %155 = uitofp i32 %154 to float
  %156 = fdiv float %153, %155
  %157 = fptoui float %156 to i32
  store i32 %157, ptr %8, align 4, !tbaa !11
  br label %159

158:                                              ; preds = %31
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %159

159:                                              ; preds = %158, %146
  br label %161

160:                                              ; preds = %0
  store i32 4000000, ptr %8, align 4, !tbaa !11
  br label %161

161:                                              ; preds = %160, %159, %30, %29, %28
  %162 = load i32, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i32 %162
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 16}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !7, i64 148, !7, i64 152, !7, i64 156, !7, i64 160, !7, i64 164, !7, i64 168, !8, i64 172, !7, i64 208, !7, i64 212, !7, i64 216, !7, i64 220, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !7, i64 248, !7, i64 252, !7, i64 256, !7, i64 260, !7, i64 264, !7, i64 268, !7, i64 272, !7, i64 276, !7, i64 280, !7, i64 284, !8, i64 288}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 40}
!13 = !{!6, !7, i64 44}
!14 = !{!6, !7, i64 52}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = !{!6, !7, i64 48}


; 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 nofree norecurse nounwind willreturn uwtable
define dso_local i32 @HAL_RCC_GetSysClockFreq() local_unnamed_addr #0 {
  %1 = load volatile i32, ptr inttoptr (i64 1476543504 to ptr), align 16, !tbaa !5
  %2 = lshr i32 %1, 3
  %3 = and i32 %2, 7
  switch i32 %3, label %53 [
    i32 0, label %4
    i32 3, label %13
    i32 2, label %12
  ]

4:                                                ; preds = %0
  %5 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 1024, !tbaa !10
  %6 = and i32 %5, 32
  %.not19 = icmp eq i32 %6, 0
  br i1 %.not19, label %53, label %7

7:                                                ; preds = %4
  %8 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 1024, !tbaa !10
  %9 = lshr i32 %8, 3
  %10 = and i32 %9, 3
  %11 = lshr exact i32 64000000, %10
  br label %53

12:                                               ; preds = %0
  br label %53

13:                                               ; preds = %0
  %14 = load volatile i32, ptr inttoptr (i64 1476543528 to ptr), align 8, !tbaa !11
  %15 = load volatile i32, ptr inttoptr (i64 1476543528 to ptr), align 8, !tbaa !11
  %16 = lshr i32 %15, 4
  %17 = and i32 %16, 63
  %18 = load volatile i32, ptr inttoptr (i64 1476543532 to ptr), align 4, !tbaa !12
  %19 = load volatile i32, ptr inttoptr (i64 1476543540 to ptr), align 4, !tbaa !13
  %20 = lshr i32 %19, 3
  %21 = and i32 %20, 8191
  %22 = trunc i32 %18 to i1
  %23 = uitofp nneg i32 %21 to float
  %24 = fmul float %23, 0x3F20000000000000
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %53, label %25

25:                                               ; preds = %13
  %26 = and i32 %14, 3
  switch i32 %26, label %default.unreachable [
    i32 0, label %27
    i32 1, label %37
    i32 2, label %36
    i32 3, label %37
  ]

27:                                               ; preds = %25
  %28 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 1024, !tbaa !10
  %29 = and i32 %28, 32
  %.not18 = icmp eq i32 %29, 0
  br i1 %.not18, label %37, label %30

30:                                               ; preds = %27
  %31 = load volatile i32, ptr inttoptr (i64 1476543488 to ptr), align 1024, !tbaa !10
  %32 = lshr i32 %31, 3
  %33 = and i32 %32, 3
  %34 = lshr exact i32 64000000, %33
  %35 = uitofp nneg i32 %34 to float
  br label %37

36:                                               ; preds = %25
  br label %37

default.unreachable:                              ; preds = %25
  unreachable

37:                                               ; preds = %25, %25, %27, %30, %36
  %.sink26 = phi float [ %35, %30 ], [ 1.600000e+07, %36 ], [ 6.400000e+07, %27 ], [ 4.000000e+06, %25 ], [ 4.000000e+06, %25 ]
  %38 = uitofp nneg i32 %17 to float
  %39 = fdiv float %.sink26, %38
  %40 = load volatile i32, ptr inttoptr (i64 1476543536 to ptr), align 16, !tbaa !14
  %41 = and i32 %40, 511
  %42 = uitofp nneg i32 %41 to float
  %43 = select i1 %22, float %24, float 0.000000e+00
  %44 = fadd float %43, %42
  %45 = fadd float %44, 1.000000e+00
  %46 = fmul float %39, %45
  %47 = load volatile i32, ptr inttoptr (i64 1476543536 to ptr), align 16, !tbaa !14
  %48 = lshr i32 %47, 9
  %49 = and i32 %48, 127
  %narrow = add nuw nsw i32 %49, 1
  %50 = uitofp nneg i32 %narrow to float
  %51 = fdiv float %46, %50
  %52 = fptoui float %51 to i32
  br label %53

53:                                               ; preds = %0, %13, %4, %37, %7, %12
  %.0 = phi i32 [ %52, %37 ], [ 16000000, %12 ], [ %11, %7 ], [ 64000000, %4 ], [ 0, %13 ], [ 4000000, %0 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nounwind willreturn 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, !7, i64 16}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !7, i64 136, !7, i64 140, !7, i64 144, !7, i64 148, !7, i64 152, !7, i64 156, !7, i64 160, !7, i64 164, !7, i64 168, !8, i64 172, !7, i64 208, !7, i64 212, !7, i64 216, !7, i64 220, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !7, i64 248, !7, i64 252, !7, i64 256, !7, i64 260, !7, i64 264, !7, i64 268, !7, i64 272, !7, i64 276, !7, i64 280, !7, i64 284, !8, i64 288}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 40}
!12 = !{!6, !7, i64 44}
!13 = !{!6, !7, i64 52}
!14 = !{!6, !7, i64 48}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass