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

; 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.ADC_HandleTypeDef = type { ptr, %struct.ADC_InitTypeDef, ptr, i32, i32, i32, %struct.ADC_InjectionConfigTypeDef }
%struct.ADC_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ADC_OversamplingTypeDef }
%struct.ADC_OversamplingTypeDef = type { i32, i32, i32, i32 }
%struct.ADC_InjectionConfigTypeDef = type { i32, i32 }
%struct.ADC_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@SystemCoreClock = external 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
define dso_local i32 @HAL_ADCEx_LinearCalibration_SetValue(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store volatile i32 0, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.ADC_TypeDef, ptr %11, i32 0, i32 2
  %13 = load volatile i32, ptr %12, align 4, !tbaa !16
  %14 = zext i32 %13 to i64
  %15 = and i64 %14, 536870912
  %16 = icmp eq i64 %15, 536870912
  br i1 %16, label %17, label %26

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.ADC_TypeDef, ptr %20, i32 0, i32 2
  %22 = load volatile i32, ptr %21, align 4, !tbaa !16
  %23 = zext i32 %22 to i64
  %24 = and i64 %23, -536870913
  %25 = trunc i64 %24 to i32
  store volatile i32 %25, ptr %21, align 4, !tbaa !16
  br label %26

26:                                               ; preds = %17, %2
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.ADC_TypeDef, ptr %29, i32 0, i32 2
  %31 = load volatile i32, ptr %30, align 4, !tbaa !16
  %32 = zext i32 %31 to i64
  %33 = and i64 %32, 268435456
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %57

35:                                               ; preds = %26
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct.ADC_TypeDef, ptr %38, i32 0, i32 2
  %40 = load volatile i32, ptr %39, align 4, !tbaa !16
  %41 = zext i32 %40 to i64
  %42 = or i64 %41, 268435456
  %43 = trunc i64 %42 to i32
  store volatile i32 %43, ptr %39, align 4, !tbaa !16
  %44 = load i32, ptr @SystemCoreClock, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = udiv i64 %45, 2000000
  %47 = mul i64 10, %46
  %48 = trunc i64 %47 to i32
  store volatile i32 %48, ptr %7, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %53, %35
  %50 = load volatile i32, ptr %7, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %49
  %54 = load volatile i32, ptr %7, align 4, !tbaa !9
  %55 = add i32 %54, -1
  store volatile i32 %55, ptr %7, align 4, !tbaa !9
  br label %49, !llvm.loop !18

56:                                               ; preds = %49
  br label %57

57:                                               ; preds = %56, %26
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.ADC_TypeDef, ptr %60, i32 0, i32 2
  %62 = load volatile i32, ptr %61, align 4, !tbaa !16
  %63 = zext i32 %62 to i64
  %64 = and i64 %63, 268435456
  %65 = icmp eq i64 %64, 0
  br i1 %65, label %66, label %77

66:                                               ; preds = %57
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %67, i32 0, i32 4
  %69 = load volatile i32, ptr %68, align 4, !tbaa !20
  %70 = zext i32 %69 to i64
  %71 = or i64 %70, 16
  %72 = trunc i64 %71 to i32
  store volatile i32 %72, ptr %68, align 4, !tbaa !20
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %73, i32 0, i32 5
  %75 = load volatile i32, ptr %74, align 8, !tbaa !21
  %76 = or i32 %75, 1
  store volatile i32 %76, ptr %74, align 8, !tbaa !21
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %99

77:                                               ; preds = %57
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %95, %77
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = zext i32 %79 to i64
  %81 = icmp ult i64 %80, 6
  br i1 %81, label %82, label %98

82:                                               ; preds = %78
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !11
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = zext i32 %86 to i64
  %88 = lshr i64 134217728, %87
  %89 = trunc i64 %88 to i32
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds i32, ptr %90, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !9
  call void @LL_ADC_SetCalibrationLinearFactor(ptr noundef %85, i32 noundef %89, i32 noundef %94)
  br label %95

95:                                               ; preds = %82
  %96 = load i32, ptr %6, align 4, !tbaa !9
  %97 = add i32 %96, 1
  store i32 %97, ptr %6, align 4, !tbaa !9
  br label %78, !llvm.loop !22

98:                                               ; preds = %78
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %99

99:                                               ; preds = %98, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %100 = load i32, ptr %3, align 4
  ret i32 %100
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @LL_ADC_SetCalibrationLinearFactor(ptr noundef, i32 noundef, i32 noundef) #2

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 = { inlinehint 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 = { 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, !6, i64 0}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 88, !10, i64 96, !10, i64 100, !10, i64 104, !15, i64 108}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !14, i64 60}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!"", !10, i64 0, !10, i64 4}
!16 = !{!17, !10, i64 8}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !7, i64 80, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !7, i64 112, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !7, i64 144, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192, !10, i64 196, !10, i64 200}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !10, i64 100}
!21 = !{!12, !10, i64 104}
!22 = distinct !{!22, !19}


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

@SystemCoreClock = external local_unnamed_addr global i32, align 4

; 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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_ADCEx_LinearCalibration_SetValue(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3)
  store volatile i32 0, ptr %3, align 4, !tbaa !5
  %4 = load ptr, ptr %0, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load volatile i32, ptr %5, align 4, !tbaa !15
  %7 = and i32 %6, 536870912
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %11, label %8

8:                                                ; preds = %2
  %9 = load volatile i32, ptr %5, align 4, !tbaa !15
  %10 = and i32 %9, -536870913
  store volatile i32 %10, ptr %5, align 4, !tbaa !15
  br label %11

11:                                               ; preds = %8, %2
  %12 = load volatile i32, ptr %5, align 4, !tbaa !15
  %13 = and i32 %12, 268435456
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %.loopexit18

15:                                               ; preds = %11
  %16 = load volatile i32, ptr %5, align 4, !tbaa !15
  %17 = or i32 %16, 268435456
  store volatile i32 %17, ptr %5, align 4, !tbaa !15
  %18 = load i32, ptr @SystemCoreClock, align 4, !tbaa !5
  %19 = udiv i32 %18, 2000000
  %narrow = mul nuw nsw i32 %19, 10
  store volatile i32 %narrow, ptr %3, align 4, !tbaa !5
  %.0..0..0..0.19 = load volatile i32, ptr %3, align 4, !tbaa !5
  %.not1720 = icmp eq i32 %.0..0..0..0.19, 0
  br i1 %.not1720, label %.loopexit18, label %.lr.ph

.lr.ph:                                           ; preds = %15, %.lr.ph
  %.0..0..0..0.1 = load volatile i32, ptr %3, align 4, !tbaa !5
  %20 = add i32 %.0..0..0..0.1, -1
  store volatile i32 %20, ptr %3, align 4, !tbaa !5
  %.0..0..0..0. = load volatile i32, ptr %3, align 4, !tbaa !5
  %.not17 = icmp eq i32 %.0..0..0..0., 0
  br i1 %.not17, label %.loopexit18, label %.lr.ph, !llvm.loop !17

.loopexit18:                                      ; preds = %.lr.ph, %15, %11
  %21 = load volatile i32, ptr %5, align 4, !tbaa !15
  %22 = and i32 %21, 268435456
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %40, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.loopexit18
  %24 = load i32, ptr %1, align 4, !tbaa !5
  tail call void @LL_ADC_SetCalibrationLinearFactor(ptr noundef nonnull %4, i32 noundef 134217728, i32 noundef %24)
  %25 = load ptr, ptr %0, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %1, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !5
  tail call void @LL_ADC_SetCalibrationLinearFactor(ptr noundef %25, i32 noundef 67108864, i32 noundef %27)
  %28 = load ptr, ptr %0, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %1, i64 8
  %30 = load i32, ptr %29, align 4, !tbaa !5
  tail call void @LL_ADC_SetCalibrationLinearFactor(ptr noundef %28, i32 noundef 33554432, i32 noundef %30)
  %31 = load ptr, ptr %0, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %1, i64 12
  %33 = load i32, ptr %32, align 4, !tbaa !5
  tail call void @LL_ADC_SetCalibrationLinearFactor(ptr noundef %31, i32 noundef 16777216, i32 noundef %33)
  %34 = load ptr, ptr %0, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %1, i64 16
  %36 = load i32, ptr %35, align 4, !tbaa !5
  tail call void @LL_ADC_SetCalibrationLinearFactor(ptr noundef %34, i32 noundef 8388608, i32 noundef %36)
  %37 = load ptr, ptr %0, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %1, i64 20
  %39 = load i32, ptr %38, align 4, !tbaa !5
  tail call void @LL_ADC_SetCalibrationLinearFactor(ptr noundef %37, i32 noundef 4194304, i32 noundef %39)
  br label %.loopexit

40:                                               ; preds = %.loopexit18
  %41 = getelementptr inbounds i8, ptr %0, i64 100
  %42 = load volatile i32, ptr %41, align 4, !tbaa !19
  %43 = or i32 %42, 16
  store volatile i32 %43, ptr %41, align 4, !tbaa !19
  %44 = getelementptr inbounds i8, ptr %0, i64 104
  %45 = load volatile i32, ptr %44, align 8, !tbaa !20
  %46 = or i32 %45, 1
  store volatile i32 %46, ptr %44, align 8, !tbaa !20
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.preheader, %40
  %.015 = phi i32 [ 1, %40 ], [ 0, %.preheader.preheader ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3)
  ret i32 %.015
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @LL_ADC_SetCalibrationLinearFactor(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { inlinehint 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"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !11, i64 88, !6, i64 96, !6, i64 100, !6, i64 104, !14, i64 108}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !13, i64 60}
!13 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!14 = !{!"", !6, i64 0, !6, i64 4}
!15 = !{!16, !6, i64 8}
!16 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !7, i64 80, !6, i64 96, !6, i64 100, !6, i64 104, !6, i64 108, !7, i64 112, !6, i64 128, !6, i64 132, !6, i64 136, !6, i64 140, !7, i64 144, !6, i64 160, !6, i64 164, !6, i64 168, !6, i64 172, !6, i64 176, !6, i64 180, !6, i64 184, !6, i64 188, !6, i64 192, !6, i64 196, !6, i64 200}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !6, i64 100}
!20 = !{!10, !6, i64 104}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass