; LLVM IR from sca-secure-library-sca25519/sca25519 :: libopencm3/lib/vf6xx (ccm)

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

@ccm_core_clk = external dso_local global i32, align 4
@ccm_platform_bus_clk = external dso_local global i32, align 4
@ccm_ipg_bus_clk = external dso_local global i32, align 4

; 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
declare dso_local i32 @ccm_get_pll_pfd(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ccm_calculate_clocks() #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 i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %7 = load volatile i32, ptr inttoptr (i64 1074180104 to ptr), align 4, !tbaa !5
  store i32 %7, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %8 = load volatile i32, ptr inttoptr (i64 1074180108 to ptr), align 4, !tbaa !5
  store i32 %8, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = and i32 %9, 7
  %11 = add i32 %10, 1
  store i32 %11, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = and i32 %12, 56
  store i32 %13, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = and i32 %14, 6144
  store i32 %15, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = lshr i32 %16, 3
  store i32 %17, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = add i32 %18, 1
  store i32 %19, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = lshr i32 %20, 11
  store i32 %21, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = add i32 %22, 1
  store i32 %23, ptr %5, align 4, !tbaa !5
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = and i32 %24, 7
  switch i32 %25, label %46 [
    i32 0, label %26
    i32 1, label %27
    i32 2, label %28
    i32 3, label %36
    i32 4, label %37
    i32 5, label %45
  ]

26:                                               ; preds = %0
  store i32 24000000, ptr @ccm_core_clk, align 4, !tbaa !5
  br label %46

27:                                               ; preds = %0
  store i32 32000, ptr @ccm_core_clk, align 4, !tbaa !5
  br label %46

28:                                               ; preds = %0
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = and i32 %29, 3670016
  store i32 %30, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = lshr i32 %31, 19
  store i32 %32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load volatile i32, ptr inttoptr (i64 1074069760 to ptr), align 4, !tbaa !5
  %35 = call i32 @ccm_get_pll_pfd(i32 noundef %33, i32 noundef %34, i32 noundef 528000000)
  store i32 %35, ptr @ccm_core_clk, align 4, !tbaa !5
  br label %46

36:                                               ; preds = %0
  store i32 528000000, ptr @ccm_core_clk, align 4, !tbaa !5
  br label %46

37:                                               ; preds = %0
  %38 = load i32, ptr %1, align 4, !tbaa !5
  %39 = and i32 %38, 458752
  store i32 %39, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = lshr i32 %40, 16
  store i32 %41, ptr %6, align 4, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = load volatile i32, ptr inttoptr (i64 1074070192 to ptr), align 4, !tbaa !5
  %44 = call i32 @ccm_get_pll_pfd(i32 noundef %42, i32 noundef %43, i32 noundef 528000000)
  store i32 %44, ptr @ccm_core_clk, align 4, !tbaa !5
  br label %46

45:                                               ; preds = %0
  store i32 480000000, ptr @ccm_core_clk, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %45, %37, %36, %28, %27, %26, %0
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr @ccm_core_clk, align 4, !tbaa !5
  %49 = udiv i32 %48, %47
  store i32 %49, ptr @ccm_core_clk, align 4, !tbaa !5
  %50 = load i32, ptr @ccm_core_clk, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = udiv i32 %50, %51
  store i32 %52, ptr @ccm_platform_bus_clk, align 4, !tbaa !5
  %53 = load i32, ptr @ccm_platform_bus_clk, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = udiv i32 %53, %54
  store i32 %55, ptr @ccm_ipg_bus_clk, align 4, !tbaa !5
  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 void
}

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

@ccm_core_clk = external dso_local local_unnamed_addr global i32, align 4
@ccm_platform_bus_clk = external dso_local local_unnamed_addr global i32, align 4
@ccm_ipg_bus_clk = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @ccm_get_pll_pfd(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @ccm_calculate_clocks() local_unnamed_addr #0 {
  %1 = load volatile i32, ptr inttoptr (i64 1074180104 to ptr), align 8, !tbaa !5
  %2 = load volatile i32, ptr inttoptr (i64 1074180108 to ptr), align 4, !tbaa !5
  %3 = and i32 %1, 7
  switch i32 %3, label %._crit_edge [
    i32 0, label %17
    i32 1, label %4
    i32 2, label %5
    i32 3, label %10
    i32 4, label %11
    i32 5, label %16
  ]

._crit_edge:                                      ; preds = %0
  %.pre = load i32, ptr @ccm_core_clk, align 4, !tbaa !5
  br label %17

4:                                                ; preds = %0
  br label %17

5:                                                ; preds = %0
  %6 = lshr i32 %1, 19
  %7 = and i32 %6, 7
  %8 = load volatile i32, ptr inttoptr (i64 1074069760 to ptr), align 256, !tbaa !5
  %9 = tail call i32 @ccm_get_pll_pfd(i32 noundef %7, i32 noundef %8, i32 noundef 528000000)
  br label %17

10:                                               ; preds = %0
  br label %17

11:                                               ; preds = %0
  %12 = lshr i32 %1, 16
  %13 = and i32 %12, 7
  %14 = load volatile i32, ptr inttoptr (i64 1074070192 to ptr), align 16, !tbaa !5
  %15 = tail call i32 @ccm_get_pll_pfd(i32 noundef %13, i32 noundef %14, i32 noundef 528000000)
  br label %17

16:                                               ; preds = %0
  br label %17

17:                                               ; preds = %0, %._crit_edge, %16, %11, %10, %5, %4
  %18 = phi i32 [ %.pre, %._crit_edge ], [ 480000000, %16 ], [ %15, %11 ], [ 528000000, %10 ], [ %9, %5 ], [ 32000, %4 ], [ 24000000, %0 ]
  %19 = lshr i32 %2, 11
  %20 = and i32 %19, 3
  %21 = add nuw nsw i32 %20, 1
  %22 = lshr i32 %2, 3
  %23 = and i32 %22, 7
  %24 = add nuw nsw i32 %23, 1
  %25 = and i32 %2, 7
  %26 = add nuw nsw i32 %25, 1
  %27 = udiv i32 %18, %26
  store i32 %27, ptr @ccm_core_clk, align 4, !tbaa !5
  %28 = udiv i32 %27, %24
  store i32 %28, ptr @ccm_platform_bus_clk, align 4, !tbaa !5
  %29 = udiv i32 %28, %21
  store i32 %29, ptr @ccm_ipg_bus_clk, align 4, !tbaa !5
  ret void
}

attributes #0 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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