; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (CalcBusSpeed)

; 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.XSdPs = type { %struct.XSdPs_Config, i32, i32, i32, i32, i8, i8, i8, i8, i32, i8, [4 x i32], i32, [4 x i32], i32, i32, i32, i32, i32, i64, i16, i32, i8, i32 }
%struct.XSdPs_Config = type { i16, i32, i32, i32, i32, i32, i32, i32, i8 }

; 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 @XSdPs_CalcBusSpeed(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.XSdPs, ptr %6, i32 0, i32 5
  %8 = load i8, ptr %7, align 4, !tbaa !11
  %9 = zext i8 %8 to i32
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %41

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.XSdPs, ptr %12, i32 0, i32 16
  %14 = load i32, ptr %13, align 4, !tbaa !16
  switch i32 %14, label %39 [
    i32 0, label %15
    i32 1, label %19
    i32 2, label %23
    i32 3, label %27
    i32 4, label %31
    i32 5, label %35
  ]

15:                                               ; preds = %11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 -2130706448, ptr %16, align 4, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.XSdPs, ptr %17, i32 0, i32 9
  store i32 25000000, ptr %18, align 8, !tbaa !17
  br label %40

19:                                               ; preds = %11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 -2130706447, ptr %20, align 4, !tbaa !9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XSdPs, ptr %21, i32 0, i32 9
  store i32 50000000, ptr %22, align 8, !tbaa !17
  br label %40

23:                                               ; preds = %11
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 -2130706446, ptr %24, align 4, !tbaa !9
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.XSdPs, ptr %25, i32 0, i32 9
  store i32 100000000, ptr %26, align 8, !tbaa !17
  br label %40

27:                                               ; preds = %11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 -2130706445, ptr %28, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.XSdPs, ptr %29, i32 0, i32 9
  store i32 208000000, ptr %30, align 8, !tbaa !17
  br label %40

31:                                               ; preds = %11
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 -2130706444, ptr %32, align 4, !tbaa !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XSdPs, ptr %33, i32 0, i32 9
  store i32 50000000, ptr %34, align 8, !tbaa !17
  br label %40

35:                                               ; preds = %11
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 -2130706447, ptr %36, align 4, !tbaa !9
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XSdPs, ptr %37, i32 0, i32 9
  store i32 50000000, ptr %38, align 8, !tbaa !17
  br label %40

39:                                               ; preds = %11
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %39, %35, %31, %27, %23, %19, %15
  br label %59

41:                                               ; preds = %2
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.XSdPs, ptr %42, i32 0, i32 16
  %44 = load i32, ptr %43, align 4, !tbaa !16
  switch i32 %44, label %57 [
    i32 7, label %45
    i32 4, label %49
    i32 5, label %53
  ]

45:                                               ; preds = %41
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 62456320, ptr %46, align 4, !tbaa !9
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XSdPs, ptr %47, i32 0, i32 9
  store i32 200000000, ptr %48, align 8, !tbaa !17
  br label %58

49:                                               ; preds = %41
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 62456064, ptr %50, align 4, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.XSdPs, ptr %51, i32 0, i32 9
  store i32 52000000, ptr %52, align 8, !tbaa !17
  br label %58

53:                                               ; preds = %41
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 62456064, ptr %54, align 4, !tbaa !9
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.XSdPs, ptr %55, i32 0, i32 9
  store i32 52000000, ptr %56, align 8, !tbaa !17
  br label %58

57:                                               ; preds = %41
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %57, %53, %49, %45
  br label %59

59:                                               ; preds = %58, %40
  %60 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %60
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 52}
!12 = !{!"", !13, i64 0, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !7, i64 52, !7, i64 53, !7, i64 54, !7, i64 55, !10, i64 56, !7, i64 60, !7, i64 64, !10, i64 80, !7, i64 84, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !15, i64 120, !14, i64 128, !10, i64 132, !7, i64 136, !10, i64 140}
!13 = !{!"", !14, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !10, i64 108}
!17 = !{!12, !10, i64 56}


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

@switch.table.XSdPs_CalcBusSpeed = private unnamed_addr constant [6 x i32] [i32 -2130706448, i32 -2130706447, i32 -2130706446, i32 -2130706445, i32 -2130706444, i32 -2130706447], align 4
@switch.table.XSdPs_CalcBusSpeed.1 = private unnamed_addr constant [6 x i32] [i32 25000000, i32 50000000, i32 100000000, i32 208000000, i32 50000000, i32 50000000], align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @XSdPs_CalcBusSpeed(ptr nocapture noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 52
  %4 = load i8, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i8 %4, 1
  %6 = getelementptr inbounds i8, ptr %0, i64 108
  %7 = load i32, ptr %6, align 4, !tbaa !13
  br i1 %5, label %8, label %10

8:                                                ; preds = %2
  %9 = icmp ult i32 %7, 6
  br i1 %9, label %switch.lookup, label %16

10:                                               ; preds = %2
  switch i32 %7, label %16 [
    i32 7, label %.sink.split
    i32 4, label %11
    i32 5, label %12
  ]

11:                                               ; preds = %10
  br label %.sink.split

12:                                               ; preds = %10
  br label %.sink.split

switch.lookup:                                    ; preds = %8
  %13 = zext nneg i32 %7 to i64
  %switch.gep = getelementptr inbounds [6 x i32], ptr @switch.table.XSdPs_CalcBusSpeed, i64 0, i64 %13
  %switch.load = load i32, ptr %switch.gep, align 4
  %14 = zext nneg i32 %7 to i64
  %switch.gep23 = getelementptr inbounds [6 x i32], ptr @switch.table.XSdPs_CalcBusSpeed.1, i64 0, i64 %14
  %switch.load24 = load i32, ptr %switch.gep23, align 4
  br label %.sink.split

.sink.split:                                      ; preds = %switch.lookup, %10, %12, %11
  %.sink22 = phi i32 [ 62456064, %11 ], [ 62456064, %12 ], [ 62456320, %10 ], [ %switch.load, %switch.lookup ]
  %.sink = phi i32 [ 52000000, %11 ], [ 52000000, %12 ], [ 200000000, %10 ], [ %switch.load24, %switch.lookup ]
  store i32 %.sink22, ptr %1, align 4, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %.sink, ptr %15, align 8, !tbaa !15
  br label %16

16:                                               ; preds = %8, %.sink.split, %10
  %.0 = phi i32 [ 1, %8 ], [ 1, %10 ], [ 0, %.sink.split ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !9, i64 52}
!6 = !{!"", !7, i64 0, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !9, i64 52, !9, i64 53, !9, i64 54, !9, i64 55, !11, i64 56, !9, i64 60, !9, i64 64, !11, i64 80, !9, i64 84, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !12, i64 120, !8, i64 128, !11, i64 132, !9, i64 136, !11, i64 140}
!7 = !{!"", !8, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !9, i64 32}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!6, !11, i64 108}
!14 = !{!11, !11, i64 0}
!15 = !{!6, !11, i64 56}


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