; LLVM IR from Seeed-Studio/Seeed_Arduino_edgeimpulse :: src/edge-impulse-sdk/CMSIS/NN/Source/BasicMathFunctions (s8)

; 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_s8(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
  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
  %37 = load i32, ptr %32, align 4, !tbaa !9
  store i32 %37, ptr %33, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %101, %16
  %39 = load i32, ptr %33, align 4, !tbaa !9
  %40 = icmp ugt i32 %39, 0
  br i1 %40, label %41, label %109

41:                                               ; preds = %38
  %42 = load ptr, ptr %17, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %17, align 8, !tbaa !5
  %44 = load i8, ptr %42, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = load i32, ptr %19, align 4, !tbaa !9
  %47 = add nsw i32 %45, %46
  %48 = load i32, ptr %25, align 4, !tbaa !9
  %49 = shl i32 %47, %48
  store i32 %49, ptr %34, align 4, !tbaa !9
  %50 = load ptr, ptr %18, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %18, align 8, !tbaa !5
  %52 = load i8, ptr %50, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = load i32, ptr %22, align 4, !tbaa !9
  %55 = add nsw i32 %53, %54
  %56 = load i32, ptr %25, align 4, !tbaa !9
  %57 = shl i32 %55, %56
  store i32 %57, ptr %35, align 4, !tbaa !9
  %58 = load i32, ptr %34, align 4, !tbaa !9
  %59 = load i32, ptr %20, align 4, !tbaa !9
  %60 = call i32 @arm_nn_sat_doubling_high_mult(i32 noundef %58, i32 noundef %59)
  store i32 %60, ptr %34, align 4, !tbaa !9
  %61 = load i32, ptr %34, align 4, !tbaa !9
  %62 = load i32, ptr %21, align 4, !tbaa !9
  %63 = sub nsw i32 0, %62
  %64 = call i32 @arm_nn_divide_by_power_of_two(i32 noundef %61, i32 noundef %63)
  store i32 %64, ptr %34, align 4, !tbaa !9
  %65 = load i32, ptr %35, align 4, !tbaa !9
  %66 = load i32, ptr %23, align 4, !tbaa !9
  %67 = call i32 @arm_nn_sat_doubling_high_mult(i32 noundef %65, i32 noundef %66)
  store i32 %67, ptr %35, align 4, !tbaa !9
  %68 = load i32, ptr %35, align 4, !tbaa !9
  %69 = load i32, ptr %24, align 4, !tbaa !9
  %70 = sub nsw i32 0, %69
  %71 = call i32 @arm_nn_divide_by_power_of_two(i32 noundef %68, i32 noundef %70)
  store i32 %71, ptr %35, align 4, !tbaa !9
  %72 = load i32, ptr %34, align 4, !tbaa !9
  %73 = load i32, ptr %35, align 4, !tbaa !9
  %74 = add nsw i32 %72, %73
  store i32 %74, ptr %36, align 4, !tbaa !9
  %75 = load i32, ptr %36, align 4, !tbaa !9
  %76 = load i32, ptr %28, align 4, !tbaa !9
  %77 = call i32 @arm_nn_sat_doubling_high_mult(i32 noundef %75, i32 noundef %76)
  store i32 %77, ptr %36, align 4, !tbaa !9
  %78 = load i32, ptr %36, align 4, !tbaa !9
  %79 = load i32, ptr %29, align 4, !tbaa !9
  %80 = sub nsw i32 0, %79
  %81 = call i32 @arm_nn_divide_by_power_of_two(i32 noundef %78, i32 noundef %80)
  store i32 %81, ptr %36, align 4, !tbaa !9
  %82 = load i32, ptr %27, align 4, !tbaa !9
  %83 = load i32, ptr %36, align 4, !tbaa !9
  %84 = add nsw i32 %83, %82
  store i32 %84, ptr %36, align 4, !tbaa !9
  %85 = load i32, ptr %36, align 4, !tbaa !9
  %86 = load i32, ptr %30, align 4, !tbaa !9
  %87 = icmp sgt i32 %85, %86
  br i1 %87, label %88, label %90

88:                                               ; preds = %41
  %89 = load i32, ptr %36, align 4, !tbaa !9
  br label %92

90:                                               ; preds = %41
  %91 = load i32, ptr %30, align 4, !tbaa !9
  br label %92

92:                                               ; preds = %90, %88
  %93 = phi i32 [ %89, %88 ], [ %91, %90 ]
  store i32 %93, ptr %36, align 4, !tbaa !9
  %94 = load i32, ptr %36, align 4, !tbaa !9
  %95 = load i32, ptr %31, align 4, !tbaa !9
  %96 = icmp slt i32 %94, %95
  br i1 %96, label %97, label %99

97:                                               ; preds = %92
  %98 = load i32, ptr %36, align 4, !tbaa !9
  br label %101

99:                                               ; preds = %92
  %100 = load i32, ptr %31, align 4, !tbaa !9
  br label %101

101:                                              ; preds = %99, %97
  %102 = phi i32 [ %98, %97 ], [ %100, %99 ]
  store i32 %102, ptr %36, align 4, !tbaa !9
  %103 = load i32, ptr %36, align 4, !tbaa !9
  %104 = trunc i32 %103 to i8
  %105 = load ptr, ptr %26, align 8, !tbaa !5
  %106 = getelementptr inbounds i8, ptr %105, i32 1
  store ptr %106, ptr %26, align 8, !tbaa !5
  store i8 %104, ptr %105, align 1, !tbaa !11
  %107 = load i32, ptr %33, align 4, !tbaa !9
  %108 = add i32 %107, -1
  store i32 %108, ptr %33, align 4, !tbaa !9
  br label %38, !llvm.loop !12

109:                                              ; preds = %38
  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_sat_doubling_high_mult(i32 noundef, i32 noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @arm_nn_divide_by_power_of_two(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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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_s8(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 {
  %.not37 = icmp eq i32 %15, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %16
  %17 = sub nsw i32 0, %4
  %18 = sub nsw i32 0, %7
  %19 = sub nsw i32 0, %12
  br label %20

20:                                               ; preds = %.lr.ph, %20
  %.041 = phi ptr [ %0, %.lr.ph ], [ %21, %20 ]
  %.03440 = phi ptr [ %1, %.lr.ph ], [ %26, %20 ]
  %.03539 = phi ptr [ %9, %.lr.ph ], [ %42, %20 ]
  %.03638 = phi i32 [ %15, %.lr.ph ], [ %43, %20 ]
  %21 = getelementptr inbounds i8, ptr %.041, i64 1
  %22 = load i8, ptr %.041, align 1, !tbaa !5
  %23 = sext i8 %22 to i32
  %24 = add nsw i32 %23, %2
  %25 = shl i32 %24, %8
  %26 = getelementptr inbounds i8, ptr %.03440, i64 1
  %27 = load i8, ptr %.03440, align 1, !tbaa !5
  %28 = sext i8 %27 to i32
  %29 = add nsw i32 %28, %5
  %30 = shl i32 %29, %8
  %31 = tail call i32 @arm_nn_sat_doubling_high_mult(i32 noundef %25, i32 noundef %3)
  %32 = tail call i32 @arm_nn_divide_by_power_of_two(i32 noundef %31, i32 noundef %17)
  %33 = tail call i32 @arm_nn_sat_doubling_high_mult(i32 noundef %30, i32 noundef %6)
  %34 = tail call i32 @arm_nn_divide_by_power_of_two(i32 noundef %33, i32 noundef %18)
  %35 = add nsw i32 %34, %32
  %36 = tail call i32 @arm_nn_sat_doubling_high_mult(i32 noundef %35, i32 noundef %11)
  %37 = tail call i32 @arm_nn_divide_by_power_of_two(i32 noundef %36, i32 noundef %19)
  %38 = add nsw i32 %37, %10
  %39 = tail call i32 @llvm.smax.i32(i32 %38, i32 %13)
  %40 = tail call i32 @llvm.smin.i32(i32 %39, i32 %14)
  %41 = trunc i32 %40 to i8
  %42 = getelementptr inbounds i8, ptr %.03539, i64 1
  store i8 %41, ptr %.03539, align 1, !tbaa !5
  %43 = add i32 %.03638, -1
  %.not = icmp eq i32 %43, 0
  br i1 %.not, label %._crit_edge, label %20, !llvm.loop !8

._crit_edge:                                      ; preds = %20, %16
  ret i32 0
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @arm_nn_divide_by_power_of_two(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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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