; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/NN/Source/BasicMathFunctions (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"

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_elementwise_mul_s16(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8, i32 noundef %9, i32 noundef %10) #0 {
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  store ptr %0, ptr %12, align 8, !tbaa !5
  store ptr %1, ptr %13, align 8, !tbaa !5
  store i32 %2, ptr %14, align 4, !tbaa !9
  store i32 %3, ptr %15, align 4, !tbaa !9
  store ptr %4, ptr %16, align 8, !tbaa !5
  store i32 %5, ptr %17, align 4, !tbaa !9
  store i32 %6, ptr %18, align 4, !tbaa !9
  store i32 %7, ptr %19, align 4, !tbaa !9
  store i32 %8, ptr %20, align 4, !tbaa !9
  store i32 %9, ptr %21, align 4, !tbaa !9
  store i32 %10, ptr %22, align 4, !tbaa !9
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = load i32, ptr %15, align 4, !tbaa !9
  %29 = load i32, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #3
  %30 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %30, ptr %23, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %66, %11
  %32 = load i32, ptr %23, align 4, !tbaa !9
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %34, label %74

34:                                               ; preds = %31
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds i16, ptr %35, i32 1
  store ptr %36, ptr %12, align 8, !tbaa !5
  %37 = load i16, ptr %35, align 2, !tbaa !11
  %38 = sext i16 %37 to i32
  store i32 %38, ptr %24, align 4, !tbaa !9
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = getelementptr inbounds i16, ptr %39, i32 1
  store ptr %40, ptr %13, align 8, !tbaa !5
  %41 = load i16, ptr %39, align 2, !tbaa !11
  %42 = sext i16 %41 to i32
  store i32 %42, ptr %25, align 4, !tbaa !9
  %43 = load i32, ptr %24, align 4, !tbaa !9
  %44 = load i32, ptr %25, align 4, !tbaa !9
  %45 = mul nsw i32 %43, %44
  store i32 %45, ptr %26, align 4, !tbaa !9
  %46 = load i32, ptr %26, align 4, !tbaa !9
  %47 = load i32, ptr %18, align 4, !tbaa !9
  %48 = load i32, ptr %19, align 4, !tbaa !9
  %49 = call i32 @arm_nn_requantize(i32 noundef %46, i32 noundef %47, i32 noundef %48)
  store i32 %49, ptr %26, align 4, !tbaa !9
  %50 = load i32, ptr %26, align 4, !tbaa !9
  %51 = load i32, ptr %20, align 4, !tbaa !9
  %52 = icmp sgt i32 %50, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %34
  %54 = load i32, ptr %26, align 4, !tbaa !9
  br label %57

55:                                               ; preds = %34
  %56 = load i32, ptr %20, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %55, %53
  %58 = phi i32 [ %54, %53 ], [ %56, %55 ]
  store i32 %58, ptr %26, align 4, !tbaa !9
  %59 = load i32, ptr %26, align 4, !tbaa !9
  %60 = load i32, ptr %21, align 4, !tbaa !9
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %62, label %64

62:                                               ; preds = %57
  %63 = load i32, ptr %26, align 4, !tbaa !9
  br label %66

64:                                               ; preds = %57
  %65 = load i32, ptr %21, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %64, %62
  %67 = phi i32 [ %63, %62 ], [ %65, %64 ]
  store i32 %67, ptr %26, align 4, !tbaa !9
  %68 = load i32, ptr %26, align 4, !tbaa !9
  %69 = trunc i32 %68 to i16
  %70 = load ptr, ptr %16, align 8, !tbaa !5
  %71 = getelementptr inbounds i16, ptr %70, i32 1
  store ptr %71, ptr %16, align 8, !tbaa !5
  store i16 %69, ptr %70, align 2, !tbaa !11
  %72 = load i32, ptr %23, align 4, !tbaa !9
  %73 = add nsw i32 %72, -1
  store i32 %73, ptr %23, align 4, !tbaa !9
  br label %31, !llvm.loop !13

74:                                               ; preds = %31
  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 4, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  ret i32 0
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @arm_nn_requantize(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 @arm_elementwise_mul_s16(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef writeonly %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8, i32 noundef %9, i32 noundef %10) local_unnamed_addr #0 {
  %12 = icmp sgt i32 %10, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.028 = phi ptr [ %13, %.lr.ph ], [ %0, %11 ]
  %.02227 = phi ptr [ %16, %.lr.ph ], [ %1, %11 ]
  %.02326 = phi ptr [ %24, %.lr.ph ], [ %4, %11 ]
  %.02425 = phi i32 [ %25, %.lr.ph ], [ %10, %11 ]
  %13 = getelementptr inbounds i8, ptr %.028, i64 2
  %14 = load i16, ptr %.028, align 2, !tbaa !5
  %15 = sext i16 %14 to i32
  %16 = getelementptr inbounds i8, ptr %.02227, i64 2
  %17 = load i16, ptr %.02227, align 2, !tbaa !5
  %18 = sext i16 %17 to i32
  %19 = mul nsw i32 %18, %15
  %20 = tail call i32 @arm_nn_requantize(i32 noundef %19, i32 noundef %6, i32 noundef %7)
  %21 = tail call i32 @llvm.smax.i32(i32 %20, i32 %8)
  %22 = tail call i32 @llvm.smin.i32(i32 %21, i32 %9)
  %23 = trunc i32 %22 to i16
  %24 = getelementptr inbounds i8, ptr %.02326, i64 2
  store i16 %23, ptr %.02326, align 2, !tbaa !5
  %25 = add nsw i32 %.02425, -1
  %26 = icmp ugt i32 %.02425, 1
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %11
  ret i32 0
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @arm_nn_requantize(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { alwaysinline 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass