; 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_add_s16(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8, ptr noundef %9, i32 noundef %10, i32 noundef %11, i32 noundef %12, i32 noundef %13, i32 noundef %14, i32 noundef %15) #0 {
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %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 ptr, align 8
  %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
  store ptr %0, ptr %17, align 8, !tbaa !5
  store ptr %1, ptr %18, align 8, !tbaa !5
  store i32 %2, ptr %19, align 4, !tbaa !9
  store i32 %3, ptr %20, align 4, !tbaa !9
  store i32 %4, ptr %21, align 4, !tbaa !9
  store i32 %5, ptr %22, align 4, !tbaa !9
  store i32 %6, ptr %23, align 4, !tbaa !9
  store i32 %7, ptr %24, align 4, !tbaa !9
  store i32 %8, ptr %25, align 4, !tbaa !9
  store ptr %9, ptr %26, align 8, !tbaa !5
  store i32 %10, ptr %27, align 4, !tbaa !9
  store i32 %11, ptr %28, align 4, !tbaa !9
  store i32 %12, ptr %29, align 4, !tbaa !9
  store i32 %13, ptr %30, align 4, !tbaa !9
  store i32 %14, ptr %31, align 4, !tbaa !9
  store i32 %15, ptr %32, align 4, !tbaa !9
  %37 = load i32, ptr %19, align 4, !tbaa !9
  %38 = load i32, ptr %22, align 4, !tbaa !9
  %39 = load i32, ptr %27, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %33) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %34) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %35) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %36) #3
  %40 = load i32, ptr %32, align 4, !tbaa !9
  store i32 %40, ptr %33, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %88, %16
  %42 = load i32, ptr %33, align 4, !tbaa !9
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %44, label %96

44:                                               ; preds = %41
  %45 = load ptr, ptr %17, align 8, !tbaa !5
  %46 = getelementptr inbounds i16, ptr %45, i32 1
  store ptr %46, ptr %17, align 8, !tbaa !5
  %47 = load i16, ptr %45, align 2, !tbaa !11
  %48 = sext i16 %47 to i32
  %49 = load i32, ptr %25, align 4, !tbaa !9
  %50 = shl i32 %48, %49
  store i32 %50, ptr %34, align 4, !tbaa !9
  %51 = load ptr, ptr %18, align 8, !tbaa !5
  %52 = getelementptr inbounds i16, ptr %51, i32 1
  store ptr %52, ptr %18, align 8, !tbaa !5
  %53 = load i16, ptr %51, align 2, !tbaa !11
  %54 = sext i16 %53 to i32
  %55 = load i32, ptr %25, align 4, !tbaa !9
  %56 = shl i32 %54, %55
  store i32 %56, ptr %35, align 4, !tbaa !9
  %57 = load i32, ptr %34, align 4, !tbaa !9
  %58 = load i32, ptr %20, align 4, !tbaa !9
  %59 = load i32, ptr %21, align 4, !tbaa !9
  %60 = call i32 @arm_nn_requantize(i32 noundef %57, i32 noundef %58, i32 noundef %59)
  store i32 %60, ptr %34, align 4, !tbaa !9
  %61 = load i32, ptr %35, align 4, !tbaa !9
  %62 = load i32, ptr %23, align 4, !tbaa !9
  %63 = load i32, ptr %24, align 4, !tbaa !9
  %64 = call i32 @arm_nn_requantize(i32 noundef %61, i32 noundef %62, i32 noundef %63)
  store i32 %64, ptr %35, align 4, !tbaa !9
  %65 = load i32, ptr %34, align 4, !tbaa !9
  %66 = load i32, ptr %35, align 4, !tbaa !9
  %67 = add nsw i32 %65, %66
  store i32 %67, ptr %36, align 4, !tbaa !9
  %68 = load i32, ptr %36, align 4, !tbaa !9
  %69 = load i32, ptr %28, align 4, !tbaa !9
  %70 = load i32, ptr %29, align 4, !tbaa !9
  %71 = call i32 @arm_nn_requantize(i32 noundef %68, i32 noundef %69, i32 noundef %70)
  store i32 %71, ptr %36, align 4, !tbaa !9
  %72 = load i32, ptr %36, align 4, !tbaa !9
  %73 = load i32, ptr %30, align 4, !tbaa !9
  %74 = icmp sgt i32 %72, %73
  br i1 %74, label %75, label %77

75:                                               ; preds = %44
  %76 = load i32, ptr %36, align 4, !tbaa !9
  br label %79

77:                                               ; preds = %44
  %78 = load i32, ptr %30, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %77, %75
  %80 = phi i32 [ %76, %75 ], [ %78, %77 ]
  store i32 %80, ptr %36, align 4, !tbaa !9
  %81 = load i32, ptr %36, align 4, !tbaa !9
  %82 = load i32, ptr %31, align 4, !tbaa !9
  %83 = icmp slt i32 %81, %82
  br i1 %83, label %84, label %86

84:                                               ; preds = %79
  %85 = load i32, ptr %36, align 4, !tbaa !9
  br label %88

86:                                               ; preds = %79
  %87 = load i32, ptr %31, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %86, %84
  %89 = phi i32 [ %85, %84 ], [ %87, %86 ]
  store i32 %89, ptr %36, align 4, !tbaa !9
  %90 = load i32, ptr %36, align 4, !tbaa !9
  %91 = trunc i32 %90 to i16
  %92 = load ptr, ptr %26, align 8, !tbaa !5
  %93 = getelementptr inbounds i16, ptr %92, i32 1
  store ptr %93, ptr %26, align 8, !tbaa !5
  store i16 %91, ptr %92, align 2, !tbaa !11
  %94 = load i32, ptr %33, align 4, !tbaa !9
  %95 = add nsw i32 %94, -1
  store i32 %95, ptr %33, align 4, !tbaa !9
  br label %41, !llvm.loop !13

96:                                               ; preds = %41
  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
  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_add_s16(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8, ptr nocapture noundef writeonly %9, i32 noundef %10, i32 noundef %11, i32 noundef %12, i32 noundef %13, i32 noundef %14, i32 noundef %15) local_unnamed_addr #0 {
  %17 = icmp sgt i32 %15, 0
  br i1 %17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %16, %.lr.ph
  %.036 = phi ptr [ %18, %.lr.ph ], [ %0, %16 ]
  %.03035 = phi ptr [ %22, %.lr.ph ], [ %1, %16 ]
  %.03134 = phi ptr [ %33, %.lr.ph ], [ %9, %16 ]
  %.03233 = phi i32 [ %34, %.lr.ph ], [ %15, %16 ]
  %18 = getelementptr inbounds i8, ptr %.036, i64 2
  %19 = load i16, ptr %.036, align 2, !tbaa !5
  %20 = sext i16 %19 to i32
  %21 = shl i32 %20, %8
  %22 = getelementptr inbounds i8, ptr %.03035, i64 2
  %23 = load i16, ptr %.03035, align 2, !tbaa !5
  %24 = sext i16 %23 to i32
  %25 = shl i32 %24, %8
  %26 = tail call i32 @arm_nn_requantize(i32 noundef %21, i32 noundef %3, i32 noundef %4)
  %27 = tail call i32 @arm_nn_requantize(i32 noundef %25, i32 noundef %6, i32 noundef %7)
  %28 = add nsw i32 %27, %26
  %29 = tail call i32 @arm_nn_requantize(i32 noundef %28, i32 noundef %11, i32 noundef %12)
  %30 = tail call i32 @llvm.smax.i32(i32 %29, i32 %13)
  %31 = tail call i32 @llvm.smin.i32(i32 %30, i32 %14)
  %32 = trunc i32 %31 to i16
  %33 = getelementptr inbounds i8, ptr %.03134, i64 2
  store i16 %32, ptr %.03134, align 2, !tbaa !5
  %34 = add nsw i32 %.03233, -1
  %35 = icmp ugt i32 %.03233, 1
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %16
  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