; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/adc/stm32 (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_t = type { %struct.ADC_HandleTypeDef, %struct.dma_t, [16 x %struct.adc_channel_t], i32, %struct.adc_private_t }
%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.dma_t = type { %struct.__DMA_HandleTypeDef, i32, %struct.dma_private_t }
%struct.__DMA_HandleTypeDef = type { ptr, %struct.DMA_InitTypeDef, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, ptr, i32 }
%struct.DMA_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.dma_private_t = type { i32 }
%struct.adc_channel_t = type { i32, %struct.ADC_ChannelConfTypeDef }
%struct.ADC_ChannelConfTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.adc_private_t = type { i32, [16 x i16], [16 x float], [16 x float], [16 x float], ptr, ptr }

; 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 @adc_reset_stat(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %13, label %7

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.adc_t, ptr %8, i32 0, i32 4
  %10 = getelementptr inbounds %struct.adc_private_t, ptr %9, i32 0, i32 6
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %7, %1
  store i32 0, ptr %2, align 4
  br label %28

14:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !21
  br label %15

15:                                               ; preds = %24, %14
  %16 = load i32, ptr %4, align 4, !tbaa !21
  %17 = icmp slt i32 %16, 16
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %27

19:                                               ; preds = %15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !21
  %22 = trunc i32 %21 to i8
  %23 = call i32 @adc_reset_stat_channel(ptr noundef %20, i8 noundef zeroext %22)
  br label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %4, align 4, !tbaa !21
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %4, align 4, !tbaa !21
  br label %15, !llvm.loop !22

27:                                               ; preds = %18
  store i32 0, ptr %2, align 4
  br label %28

28:                                               ; preds = %27, %13
  %29 = load i32, ptr %2, align 4
  ret i32 %29
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @adc_reset_stat_channel(ptr noundef, i8 noundef zeroext) #1

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, !6, i64 1136}
!10 = !{!"", !11, i64 0, !16, i64 120, !7, i64 312, !13, i64 888, !20, i64 896}
!11 = !{!"", !6, i64 0, !12, i64 8, !6, i64 88, !13, i64 96, !13, i64 100, !13, i64 104, !15, i64 108}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !14, i64 60}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12}
!15 = !{!"", !13, i64 0, !13, i64 4}
!16 = !{!"", !17, i64 0, !13, i64 184, !19, i64 188}
!17 = !{!"__DMA_HandleTypeDef", !6, i64 0, !18, i64 8, !13, i64 56, !13, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !13, i64 120, !13, i64 124, !13, i64 128, !6, i64 136, !6, i64 144, !13, i64 152, !6, i64 160, !6, i64 168, !13, i64 176}
!18 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44}
!19 = !{!"", !13, i64 0}
!20 = !{!"", !13, i64 0, !7, i64 4, !7, i64 36, !7, i64 100, !7, i64 164, !6, i64 232, !6, i64 240}
!21 = !{!13, !13, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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: nounwind uwtable
define dso_local noundef i32 @adc_reset_stat(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 1136
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %3
  %7 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 0)
  %8 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 1)
  %9 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 2)
  %10 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 3)
  %11 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 4)
  %12 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 5)
  %13 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 6)
  %14 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 7)
  %15 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 8)
  %16 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 9)
  %17 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 10)
  %18 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 11)
  %19 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 12)
  %20 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 13)
  %21 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 14)
  %22 = tail call i32 @adc_reset_stat_channel(ptr noundef nonnull %0, i8 noundef zeroext 15)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.preheader, %1, %3
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @adc_reset_stat_channel(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

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, !8, i64 1136}
!6 = !{!"", !7, i64 0, !15, i64 120, !9, i64 312, !12, i64 888, !19, i64 896}
!7 = !{!"", !8, i64 0, !11, i64 8, !8, i64 88, !12, i64 96, !12, i64 100, !12, i64 104, !14, i64 108}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!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", !9, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!14 = !{!"", !12, i64 0, !12, i64 4}
!15 = !{!"", !16, i64 0, !12, i64 184, !18, i64 188}
!16 = !{!"__DMA_HandleTypeDef", !8, i64 0, !17, i64 8, !12, i64 56, !12, i64 60, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !8, i64 112, !12, i64 120, !12, i64 124, !12, i64 128, !8, i64 136, !8, i64 144, !12, i64 152, !8, i64 160, !8, i64 168, !12, i64 176}
!17 = !{!"", !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}
!18 = !{!"", !12, i64 0}
!19 = !{!"", !12, i64 0, !9, i64 4, !9, i64 36, !9, i64 100, !9, i64 164, !8, i64 232, !8, i64 240}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass