; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_hal_adc)

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @LL_ADC_IsEnabled(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @LL_ADC_GetMultimode(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ADC_Enable(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = call i32 @LL_ADC_IsEnabled(ptr noundef %9)
  %11 = zext i32 %10 to i64
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %131

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.ADC_TypeDef, ptr %16, i32 0, i32 2
  %18 = load volatile i32, ptr %17, align 4, !tbaa !15
  %19 = zext i32 %18 to i64
  %20 = and i64 %19, 2147483711
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %33

22:                                               ; preds = %13
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %23, i32 0, i32 4
  %25 = load volatile i32, ptr %24, align 4, !tbaa !17
  %26 = zext i32 %25 to i64
  %27 = or i64 %26, 16
  %28 = trunc i64 %27 to i32
  store volatile i32 %28, ptr %24, align 4, !tbaa !17
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %29, i32 0, i32 5
  %31 = load volatile i32, ptr %30, align 8, !tbaa !18
  %32 = or i32 %31, 1
  store volatile i32 %32, ptr %30, align 8, !tbaa !18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %132

33:                                               ; preds = %13
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  call void @LL_ADC_Enable(ptr noundef %36)
  %37 = call i32 @HAL_GetTick()
  store i32 %37, ptr %4, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = icmp eq ptr %40, inttoptr (i64 1073881088 to ptr)
  br i1 %41, label %47, label %42

42:                                               ; preds = %33
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = icmp eq ptr %45, inttoptr (i64 1073881344 to ptr)
  br label %47

47:                                               ; preds = %42, %33
  %48 = phi i1 [ true, %33 ], [ %46, %42 ]
  %49 = zext i1 %48 to i64
  %50 = select i1 %48, ptr inttoptr (i64 1073881856 to ptr), ptr inttoptr (i64 1476551424 to ptr)
  %51 = call i32 @LL_ADC_GetMultimode(ptr noundef %50)
  store i32 %51, ptr %6, align 4, !tbaa !19
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = icmp eq ptr %54, inttoptr (i64 1073881344 to ptr)
  br i1 %55, label %56, label %57

56:                                               ; preds = %47
  br label %61

57:                                               ; preds = %47
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %57, %56
  %62 = phi ptr [ inttoptr (i64 1073881088 to ptr), %56 ], [ %60, %57 ]
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = icmp eq ptr %62, %65
  br i1 %66, label %71, label %67

67:                                               ; preds = %61
  %68 = load i32, ptr %6, align 4, !tbaa !19
  %69 = zext i32 %68 to i64
  %70 = icmp eq i64 %69, 0
  br i1 %70, label %71, label %127

71:                                               ; preds = %67, %61
  br label %72

72:                                               ; preds = %125, %71
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.ADC_TypeDef, ptr %75, i32 0, i32 0
  %77 = load volatile i32, ptr %76, align 4, !tbaa !20
  %78 = zext i32 %77 to i64
  %79 = and i64 %78, 1
  %80 = icmp eq i64 %79, 1
  %81 = zext i1 %80 to i32
  %82 = sext i32 %81 to i64
  %83 = icmp eq i64 %82, 0
  br i1 %83, label %84, label %126

84:                                               ; preds = %72
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  %88 = call i32 @LL_ADC_IsEnabled(ptr noundef %87)
  %89 = zext i32 %88 to i64
  %90 = icmp eq i64 %89, 0
  br i1 %90, label %91, label %95

91:                                               ; preds = %84
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !9
  call void @LL_ADC_Enable(ptr noundef %94)
  br label %95

95:                                               ; preds = %91, %84
  %96 = call i32 @HAL_GetTick()
  %97 = load i32, ptr %4, align 4, !tbaa !19
  %98 = sub i32 %96, %97
  %99 = zext i32 %98 to i64
  %100 = icmp ugt i64 %99, 2
  br i1 %100, label %101, label %125

101:                                              ; preds = %95
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %102, i32 0, i32 0
  %104 = load ptr, ptr %103, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.ADC_TypeDef, ptr %104, i32 0, i32 0
  %106 = load volatile i32, ptr %105, align 4, !tbaa !20
  %107 = zext i32 %106 to i64
  %108 = and i64 %107, 1
  %109 = icmp eq i64 %108, 1
  %110 = zext i1 %109 to i32
  %111 = sext i32 %110 to i64
  %112 = icmp eq i64 %111, 0
  br i1 %112, label %113, label %124

113:                                              ; preds = %101
  %114 = load ptr, ptr %3, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %114, i32 0, i32 4
  %116 = load volatile i32, ptr %115, align 4, !tbaa !17
  %117 = zext i32 %116 to i64
  %118 = or i64 %117, 16
  %119 = trunc i64 %118 to i32
  store volatile i32 %119, ptr %115, align 4, !tbaa !17
  %120 = load ptr, ptr %3, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.ADC_HandleTypeDef, ptr %120, i32 0, i32 5
  %122 = load volatile i32, ptr %121, align 8, !tbaa !18
  %123 = or i32 %122, 1
  store volatile i32 %123, ptr %121, align 8, !tbaa !18
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %128

124:                                              ; preds = %101
  br label %125

125:                                              ; preds = %124, %95
  br label %72, !llvm.loop !21

126:                                              ; preds = %72
  br label %127

127:                                              ; preds = %126, %67
  store i32 0, ptr %5, align 4
  br label %128

128:                                              ; preds = %127, %113
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %129 = load i32, ptr %5, align 4
  switch i32 %129, label %132 [
    i32 0, label %130
  ]

130:                                              ; preds = %128
  br label %131

131:                                              ; preds = %130, %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %132

132:                                              ; preds = %131, %128, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %133 = load i32, ptr %2, align 4
  ret i32 %133
}

declare i32 @HAL_GetTick() #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @LL_ADC_Enable(ptr noundef) #1

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


; 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: inlinehint nounwind uwtable
declare hidden i32 @LL_ADC_IsEnabled(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @LL_ADC_GetMultimode(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ADC_Enable(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call i32 @LL_ADC_IsEnabled(ptr noundef %2)
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %.loopexit

5:                                                ; preds = %1
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load volatile i32, ptr %7, align 4, !tbaa !14
  %9 = and i32 %8, -2147483585
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %.loopexit.sink.split

10:                                               ; preds = %5
  tail call void @LL_ADC_Enable(ptr noundef nonnull %6)
  %11 = tail call i32 @HAL_GetTick() #3
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = icmp eq ptr %12, inttoptr (i64 1073881088 to ptr)
  %14 = icmp eq ptr %12, inttoptr (i64 1073881344 to ptr)
  %spec.select = or i1 %13, %14
  %15 = select i1 %spec.select, ptr inttoptr (i64 1073881856 to ptr), ptr inttoptr (i64 1476551424 to ptr)
  %16 = tail call i32 @LL_ADC_GetMultimode(ptr noundef nonnull %15)
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = icmp ne ptr %17, inttoptr (i64 1073881344 to ptr)
  %19 = icmp eq i32 %16, 0
  %or.cond = select i1 %18, i1 true, i1 %19
  br i1 %or.cond, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %10
  %20 = load volatile i32, ptr %17, align 4, !tbaa !16
  %21 = and i32 %20, 1
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %36
  %23 = phi ptr [ %.pre, %36 ], [ %17, %.preheader ]
  %24 = tail call i32 @LL_ADC_IsEnabled(ptr noundef nonnull %23)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %.lr.ph
  %27 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @LL_ADC_Enable(ptr noundef %27)
  br label %28

28:                                               ; preds = %26, %.lr.ph
  %29 = tail call i32 @HAL_GetTick() #3
  %30 = sub i32 %29, %11
  %31 = icmp ugt i32 %30, 2
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %31, label %32, label %36

32:                                               ; preds = %28
  %33 = load volatile i32, ptr %.pre, align 4, !tbaa !16
  %34 = and i32 %33, 1
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %.loopexit.sink.split, label %36

36:                                               ; preds = %32, %28
  %37 = load volatile i32, ptr %.pre, align 4, !tbaa !16
  %38 = and i32 %37, 1
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %.lr.ph, label %.loopexit, !llvm.loop !17

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

.loopexit:                                        ; preds = %36, %.loopexit.sink.split, %.preheader, %1, %10
  %.1 = phi i32 [ 0, %10 ], [ 0, %1 ], [ 0, %.preheader ], [ 1, %.loopexit.sink.split ], [ 0, %36 ]
  ret i32 %.1
}

declare i32 @HAL_GetTick() local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @LL_ADC_Enable(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #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 = { "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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 88, !11, i64 96, !11, i64 100, !11, i64 104, !13, i64 108}
!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, !12, i64 60}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!13 = !{!"", !11, i64 0, !11, i64 4}
!14 = !{!15, !11, i64 8}
!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, !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, !8, i64 80, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !8, i64 112, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !8, i64 144, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !11, i64 180, !11, i64 184, !11, i64 188, !11, i64 192, !11, i64 196, !11, i64 200}
!16 = !{!15, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !11, i64 100}
!20 = !{!6, !11, i64 104}


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