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

; 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.FDCAN_ClkCalUnitTypeDef = type { i32, i32, i32, i32, i32, i32 }
%struct.FDCAN_HandleTypeDef = type { ptr, ptr, %struct.FDCAN_InitTypeDef, %struct.FDCAN_MsgRamAddressTypeDef, i32, i32, i32, i32 }
%struct.FDCAN_InitTypeDef = 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 }
%struct.FDCAN_MsgRamAddressTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.FDCAN_ClockCalibrationUnit_TypeDef = type { i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_FDCAN_ConfigClockCalibration(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.FDCAN_ClkCalUnitTypeDef, ptr %6, i32 0, i32 0
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  br label %12

12:                                               ; preds = %11, %10
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = icmp ne ptr %15, inttoptr (i64 1073782784 to ptr)
  br i1 %16, label %17, label %22

17:                                               ; preds = %12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %18, i32 0, i32 7
  %20 = load volatile i32, ptr %19, align 8, !tbaa !16
  %21 = or i32 %20, 32
  store volatile i32 %21, ptr %19, align 8, !tbaa !16
  store i32 1, ptr %3, align 4
  br label %85

22:                                               ; preds = %12
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %23, i32 0, i32 5
  %25 = load volatile i32, ptr %24, align 8, !tbaa !17
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %80

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.FDCAN_ClkCalUnitTypeDef, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %46

32:                                               ; preds = %27
  %33 = load volatile i32, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  %34 = zext i32 %33 to i64
  %35 = or i64 %34, 64
  %36 = trunc i64 %35 to i32
  store volatile i32 %36, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  %37 = load volatile i32, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  %38 = zext i32 %37 to i64
  %39 = and i64 %38, -983041
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.FDCAN_ClkCalUnitTypeDef, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !18
  %43 = zext i32 %42 to i64
  %44 = or i64 %39, %43
  %45 = trunc i64 %44 to i32
  store volatile i32 %45, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  br label %79

46:                                               ; preds = %27
  %47 = load volatile i32, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  %48 = zext i32 %47 to i64
  %49 = and i64 %48, -65
  %50 = trunc i64 %49 to i32
  store volatile i32 %50, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  %51 = load volatile i32, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  %52 = zext i32 %51 to i64
  %53 = and i64 %52, -65440
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.FDCAN_ClkCalUnitTypeDef, ptr %54, i32 0, i32 4
  %56 = load i32, ptr %55, align 4, !tbaa !19
  %57 = shl i32 %56, 0
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.FDCAN_ClkCalUnitTypeDef, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 4, !tbaa !20
  %61 = or i32 %57, %60
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.FDCAN_ClkCalUnitTypeDef, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 4, !tbaa !21
  %65 = shl i32 %64, 8
  %66 = or i32 %61, %65
  %67 = zext i32 %66 to i64
  %68 = or i64 %53, %67
  %69 = trunc i64 %68 to i32
  store volatile i32 %69, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 1), align 4, !tbaa !18
  %70 = load volatile i32, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 3), align 4, !tbaa !20
  %71 = zext i32 %70 to i64
  %72 = and i64 %71, -65536
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.FDCAN_ClkCalUnitTypeDef, ptr %73, i32 0, i32 5
  %75 = load i32, ptr %74, align 4, !tbaa !22
  %76 = zext i32 %75 to i64
  %77 = or i64 %72, %76
  %78 = trunc i64 %77 to i32
  store volatile i32 %78, ptr getelementptr inbounds (%struct.FDCAN_ClockCalibrationUnit_TypeDef, ptr inttoptr (i64 1073784832 to ptr), i32 0, i32 3), align 4, !tbaa !20
  br label %79

79:                                               ; preds = %46, %32
  store i32 0, ptr %3, align 4
  br label %85

80:                                               ; preds = %22
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.FDCAN_HandleTypeDef, ptr %81, i32 0, i32 7
  %83 = load volatile i32, ptr %82, align 8, !tbaa !16
  %84 = or i32 %83, 4
  store volatile i32 %84, ptr %82, align 8, !tbaa !16
  store i32 1, ptr %3, align 4
  br label %85

85:                                               ; preds = %80, %79, %17
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 8, !14, i64 16, !15, i64 124, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36}
!16 = !{!13, !11, i64 176}
!17 = !{!13, !11, i64 168}
!18 = !{!10, !11, i64 4}
!19 = !{!10, !11, i64 16}
!20 = !{!10, !11, i64 12}
!21 = !{!10, !11, i64 8}
!22 = !{!10, !11, i64 20}


; 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: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_FDCAN_ConfigClockCalibration(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %3, inttoptr (i64 1073782784 to ptr)
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 176
  %6 = load volatile i32, ptr %5, align 8, !tbaa !13
  %7 = or i32 %6, 32
  store volatile i32 %7, ptr %5, align 8, !tbaa !13
  br label %46

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 168
  %10 = load volatile i32, ptr %9, align 8, !tbaa !14
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %42

12:                                               ; preds = %8
  %13 = load i32, ptr %1, align 4, !tbaa !15
  %14 = icmp eq i32 %13, 0
  %15 = load volatile i32, ptr inttoptr (i64 1073784836 to ptr), align 4, !tbaa !17
  br i1 %14, label %16, label %23

16:                                               ; preds = %12
  %17 = or i32 %15, 64
  store volatile i32 %17, ptr inttoptr (i64 1073784836 to ptr), align 4, !tbaa !17
  %18 = load volatile i32, ptr inttoptr (i64 1073784836 to ptr), align 4, !tbaa !17
  %19 = and i32 %18, -983041
  %20 = getelementptr inbounds i8, ptr %1, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = or i32 %19, %21
  store volatile i32 %22, ptr inttoptr (i64 1073784836 to ptr), align 4, !tbaa !17
  br label %46

23:                                               ; preds = %12
  %24 = and i32 %15, -65
  store volatile i32 %24, ptr inttoptr (i64 1073784836 to ptr), align 4, !tbaa !17
  %25 = load volatile i32, ptr inttoptr (i64 1073784836 to ptr), align 4, !tbaa !17
  %26 = and i32 %25, -65440
  %27 = getelementptr inbounds i8, ptr %1, i64 16
  %28 = load i32, ptr %27, align 4, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %1, i64 12
  %30 = load i32, ptr %29, align 4, !tbaa !19
  %31 = getelementptr inbounds i8, ptr %1, i64 8
  %32 = load i32, ptr %31, align 4, !tbaa !20
  %33 = shl i32 %32, 8
  %34 = or i32 %26, %28
  %35 = or i32 %34, %30
  %36 = or i32 %35, %33
  store volatile i32 %36, ptr inttoptr (i64 1073784836 to ptr), align 4, !tbaa !17
  %37 = load volatile i32, ptr inttoptr (i64 1073784844 to ptr), align 4, !tbaa !19
  %38 = and i32 %37, -65536
  %39 = getelementptr inbounds i8, ptr %1, i64 20
  %40 = load i32, ptr %39, align 4, !tbaa !21
  %41 = or i32 %38, %40
  store volatile i32 %41, ptr inttoptr (i64 1073784844 to ptr), align 4, !tbaa !19
  br label %46

42:                                               ; preds = %8
  %43 = getelementptr inbounds i8, ptr %0, i64 176
  %44 = load volatile i32, ptr %43, align 8, !tbaa !13
  %45 = or i32 %44, 4
  store volatile i32 %45, ptr %43, align 8, !tbaa !13
  br label %46

46:                                               ; preds = %16, %23, %42, %4
  %.0 = phi i32 [ 1, %4 ], [ 1, %42 ], [ 0, %23 ], [ 0, %16 ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !12, i64 124, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36}
!13 = !{!6, !11, i64 176}
!14 = !{!6, !11, i64 168}
!15 = !{!16, !11, i64 0}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!17 = !{!16, !11, i64 4}
!18 = !{!16, !11, i64 16}
!19 = !{!16, !11, i64 12}
!20 = !{!16, !11, i64 8}
!21 = !{!16, !11, i64 20}


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