; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/NN/Source/ConvolutionFunctions (s16)

; 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.cmsis_nn_dims = type { i32, i32, i32, i32 }
%struct.cmsis_nn_context = type { ptr, i32 }
%struct.cmsis_nn_conv_params = type { i32, i32, %struct.cmsis_nn_tile, %struct.cmsis_nn_tile, %struct.cmsis_nn_tile, %struct.cmsis_nn_activation }
%struct.cmsis_nn_tile = type { i32, i32 }
%struct.cmsis_nn_activation = type { i32, i32 }
%struct.cmsis_nn_per_channel_quant_params = type { ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_convolve_fast_s16(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10) #0 {
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  %28 = alloca i32, align 4
  %29 = alloca i32, align 4
  %30 = alloca i32, align 4
  %31 = alloca i32, align 4
  %32 = alloca i32, align 4
  %33 = alloca i32, align 4
  %34 = alloca i32, align 4
  %35 = alloca i32, align 4
  %36 = alloca i32, align 4
  %37 = alloca i32, align 4
  %38 = alloca i16, align 2
  %39 = alloca i16, align 2
  %40 = alloca ptr, align 8
  %41 = alloca ptr, align 8
  %42 = alloca i32, align 4
  %43 = alloca i32, align 4
  store ptr %0, ptr %13, align 8, !tbaa !5
  store ptr %1, ptr %14, align 8, !tbaa !5
  store ptr %2, ptr %15, align 8, !tbaa !5
  store ptr %3, ptr %16, align 8, !tbaa !5
  store ptr %4, ptr %17, align 8, !tbaa !5
  store ptr %5, ptr %18, align 8, !tbaa !5
  store ptr %6, ptr %19, align 8, !tbaa !5
  store ptr %7, ptr %20, align 8, !tbaa !5
  store ptr %8, ptr %21, align 8, !tbaa !5
  store ptr %9, ptr %22, align 8, !tbaa !5
  store ptr %10, ptr %23, align 8, !tbaa !5
  %44 = load ptr, ptr %20, align 8, !tbaa !5
  %45 = load ptr, ptr %18, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = load ptr, ptr %18, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = mul nsw i32 %47, %50
  %52 = load ptr, ptr %16, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !13
  %55 = mul nsw i32 %51, %54
  %56 = icmp sge i32 %55, 512
  br i1 %56, label %57, label %58

57:                                               ; preds = %11
  store i32 -3, ptr %12, align 4
  br label %160

58:                                               ; preds = %11
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.cmsis_nn_context, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !14
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %69

63:                                               ; preds = %58
  %64 = load ptr, ptr %16, align 8, !tbaa !5
  %65 = load ptr, ptr %18, align 8, !tbaa !5
  %66 = call i32 @arm_convolve_s8_get_buffer_size(ptr noundef %64, ptr noundef %65)
  %67 = icmp sgt i32 %66, 0
  br i1 %67, label %68, label %69

68:                                               ; preds = %63
  store i32 -1, ptr %12, align 4
  br label %160

69:                                               ; preds = %63, %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.cmsis_nn_context, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  store ptr %72, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #3
  %73 = load ptr, ptr %16, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 4, !tbaa !16
  store i32 %75, ptr %25, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #3
  %76 = load ptr, ptr %16, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %76, i32 0, i32 2
  %78 = load i32, ptr %77, align 4, !tbaa !9
  store i32 %78, ptr %26, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #3
  %79 = load ptr, ptr %16, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !12
  store i32 %81, ptr %27, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #3
  %82 = load ptr, ptr %16, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %82, i32 0, i32 3
  %84 = load i32, ptr %83, align 4, !tbaa !13
  store i32 %84, ptr %28, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %29) #3
  %85 = load ptr, ptr %18, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %85, i32 0, i32 2
  %87 = load i32, ptr %86, align 4, !tbaa !9
  store i32 %87, ptr %29, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #3
  %88 = load ptr, ptr %18, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %88, i32 0, i32 1
  %90 = load i32, ptr %89, align 4, !tbaa !12
  store i32 %90, ptr %30, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %31) #3
  %91 = load ptr, ptr %22, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %91, i32 0, i32 2
  %93 = load i32, ptr %92, align 4, !tbaa !9
  store i32 %93, ptr %31, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %32) #3
  %94 = load ptr, ptr %22, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 4, !tbaa !12
  store i32 %96, ptr %32, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %33) #3
  %97 = load ptr, ptr %22, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.cmsis_nn_dims, ptr %97, i32 0, i32 3
  %99 = load i32, ptr %98, align 4, !tbaa !13
  store i32 %99, ptr %33, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %34) #3
  %100 = load ptr, ptr %14, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.cmsis_nn_conv_params, ptr %100, i32 0, i32 3
  %102 = getelementptr inbounds %struct.cmsis_nn_tile, ptr %101, i32 0, i32 0
  %103 = load i32, ptr %102, align 4, !tbaa !18
  store i32 %103, ptr %34, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %35) #3
  %104 = load ptr, ptr %14, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.cmsis_nn_conv_params, ptr %104, i32 0, i32 3
  %106 = getelementptr inbounds %struct.cmsis_nn_tile, ptr %105, i32 0, i32 1
  %107 = load i32, ptr %106, align 4, !tbaa !21
  store i32 %107, ptr %35, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %36) #3
  %108 = load ptr, ptr %14, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.cmsis_nn_conv_params, ptr %108, i32 0, i32 2
  %110 = getelementptr inbounds %struct.cmsis_nn_tile, ptr %109, i32 0, i32 0
  %111 = load i32, ptr %110, align 4, !tbaa !22
  store i32 %111, ptr %36, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %37) #3
  %112 = load ptr, ptr %14, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.cmsis_nn_conv_params, ptr %112, i32 0, i32 2
  %114 = getelementptr inbounds %struct.cmsis_nn_tile, ptr %113, i32 0, i32 1
  %115 = load i32, ptr %114, align 4, !tbaa !23
  store i32 %115, ptr %37, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 2, ptr %38) #3
  %116 = load ptr, ptr %14, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.cmsis_nn_conv_params, ptr %116, i32 0, i32 5
  %118 = getelementptr inbounds %struct.cmsis_nn_activation, ptr %117, i32 0, i32 0
  %119 = load i32, ptr %118, align 4, !tbaa !24
  %120 = trunc i32 %119 to i16
  store i16 %120, ptr %38, align 2, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 2, ptr %39) #3
  %121 = load ptr, ptr %14, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.cmsis_nn_conv_params, ptr %121, i32 0, i32 5
  %123 = getelementptr inbounds %struct.cmsis_nn_activation, ptr %122, i32 0, i32 1
  %124 = load i32, ptr %123, align 4, !tbaa !27
  %125 = trunc i32 %124 to i16
  store i16 %125, ptr %39, align 2, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 8, ptr %40) #3
  %126 = load ptr, ptr %15, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.cmsis_nn_per_channel_quant_params, ptr %126, i32 0, i32 0
  %128 = load ptr, ptr %127, align 8, !tbaa !28
  store ptr %128, ptr %40, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %41) #3
  %129 = load ptr, ptr %15, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.cmsis_nn_per_channel_quant_params, ptr %129, i32 0, i32 1
  %131 = load ptr, ptr %130, align 8, !tbaa !30
  store ptr %131, ptr %41, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %42) #3
  store i32 0, ptr %42, align 4, !tbaa !17
  br label %132

132:                                              ; preds = %153, %69
  %133 = load i32, ptr %42, align 4, !tbaa !17
  %134 = load i32, ptr %25, align 4, !tbaa !17
  %135 = icmp slt i32 %133, %134
  br i1 %135, label %137, label %136

136:                                              ; preds = %132
  store i32 2, ptr %43, align 4
  br label %156

137:                                              ; preds = %132
  %138 = load ptr, ptr %17, align 8, !tbaa !5
  %139 = load ptr, ptr %23, align 8, !tbaa !5
  %140 = load ptr, ptr %21, align 8, !tbaa !5
  %141 = load ptr, ptr %19, align 8, !tbaa !5
  %142 = load ptr, ptr %24, align 8, !tbaa !5
  %143 = load i32, ptr %29, align 4, !tbaa !17
  %144 = load i32, ptr %30, align 4, !tbaa !17
  %145 = load i32, ptr %34, align 4, !tbaa !17
  %146 = load i32, ptr %35, align 4, !tbaa !17
  %147 = load i32, ptr %36, align 4, !tbaa !17
  %148 = load i32, ptr %37, align 4, !tbaa !17
  %149 = load i16, ptr %38, align 2, !tbaa !25
  %150 = load i16, ptr %39, align 2, !tbaa !25
  %151 = load ptr, ptr %40, align 8, !tbaa !5
  %152 = load ptr, ptr %41, align 8, !tbaa !5
  store i32 -1, ptr %12, align 4
  store i32 1, ptr %43, align 4
  br label %156

153:                                              ; No predecessors!
  %154 = load i32, ptr %42, align 4, !tbaa !17
  %155 = add nsw i32 %154, 1
  store i32 %155, ptr %42, align 4, !tbaa !17
  br label %132, !llvm.loop !31

156:                                              ; preds = %137, %136
  call void @llvm.lifetime.end.p0(i64 4, ptr %42) #3
  %157 = load i32, ptr %43, align 4
  switch i32 %157, label %159 [
    i32 2, label %158
  ]

158:                                              ; preds = %156
  store i32 0, ptr %12, align 4
  store i32 1, ptr %43, align 4
  br label %159

159:                                              ; preds = %158, %156
  call void @llvm.lifetime.end.p0(i64 8, ptr %41) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %40) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %39) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %38) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %37) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %36) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %35) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %34) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %33) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %32) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %31) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %29) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #3
  br label %160

160:                                              ; preds = %159, %68, %57
  %161 = load i32, ptr %12, align 4
  ret i32 %161
}

declare i32 @arm_convolve_s8_get_buffer_size(ptr noundef, ptr noundef) #1

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

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

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" }
attributes #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 12}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !6, i64 0, !11, i64 8}
!16 = !{!10, !11, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !11, i64 16}
!19 = !{!"", !11, i64 0, !11, i64 4, !20, i64 8, !20, i64 16, !20, i64 24, !20, i64 32}
!20 = !{!"", !11, i64 0, !11, i64 4}
!21 = !{!19, !11, i64 20}
!22 = !{!19, !11, i64 8}
!23 = !{!19, !11, i64 12}
!24 = !{!19, !11, i64 32}
!25 = !{!26, !26, i64 0}
!26 = !{!"short", !7, i64 0}
!27 = !{!19, !11, i64 36}
!28 = !{!29, !6, i64 0}
!29 = !{!"", !6, i64 0, !6, i64 8}
!30 = !{!29, !6, i64 8}
!31 = distinct !{!31, !32}
!32 = !{!"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 range(i32 -3, 1) i32 @arm_convolve_fast_s16(ptr nocapture noundef readonly %0, ptr nocapture noundef readnone %1, ptr nocapture noundef readnone %2, ptr noundef %3, ptr nocapture noundef readnone %4, ptr noundef %5, ptr nocapture noundef readnone %6, ptr nocapture noundef readnone %7, ptr nocapture noundef readnone %8, ptr nocapture noundef readnone %9, ptr nocapture noundef readnone %10) local_unnamed_addr #0 {
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %5, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %16 = mul nsw i32 %15, %13
  %17 = getelementptr inbounds i8, ptr %3, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = mul nsw i32 %16, %18
  %20 = icmp sgt i32 %19, 511
  br i1 %20, label %30, label %21

21:                                               ; preds = %11
  %22 = load ptr, ptr %0, align 8, !tbaa !12
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = tail call i32 @arm_convolve_s8_get_buffer_size(ptr noundef nonnull %3, ptr noundef nonnull %5) #2
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %30, label %27

27:                                               ; preds = %24, %21
  %28 = load i32, ptr %3, align 4, !tbaa !15
  %29 = icmp sgt i32 %28, 0
  %.1 = sext i1 %29 to i32
  br label %30

30:                                               ; preds = %24, %11, %27
  %.2 = phi i32 [ %.1, %27 ], [ -3, %11 ], [ -1, %24 ]
  ret i32 %.2
}

declare i32 @arm_convolve_s8_get_buffer_size(ptr noundef, ptr noundef) local_unnamed_addr #1

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" }
attributes #1 = { "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, !7, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 12}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !7, i64 8}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !7, i64 0}


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