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

; 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 void @arm_relu_q15(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %6

6:                                                ; preds = %26, %2
  %7 = load i16, ptr %5, align 2, !tbaa !9
  %8 = zext i16 %7 to i32
  %9 = load i16, ptr %4, align 2, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = icmp slt i32 %8, %10
  br i1 %11, label %12, label %29

12:                                               ; preds = %6
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i16, ptr %5, align 2, !tbaa !9
  %15 = zext i16 %14 to i64
  %16 = getelementptr inbounds i16, ptr %13, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !9
  %18 = sext i16 %17 to i32
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %12
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i16, ptr %5, align 2, !tbaa !9
  %23 = zext i16 %22 to i64
  %24 = getelementptr inbounds i16, ptr %21, i64 %23
  store i16 0, ptr %24, align 2, !tbaa !9
  br label %25

25:                                               ; preds = %20, %12
  br label %26

26:                                               ; preds = %25
  %27 = load i16, ptr %5, align 2, !tbaa !9
  %28 = add i16 %27, 1
  store i16 %28, ptr %5, align 2, !tbaa !9
  br label %6, !llvm.loop !11

29:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  ret void
}

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

; 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 = { 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 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @arm_relu_q15(ptr nocapture noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %.not = icmp eq i16 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext i16 %1 to i64
  %min.iters.check = icmp ult i16 %1, 16
  br i1 %min.iters.check, label %.lr.ph.preheader39, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 65520
  br label %vector.body

vector.body:                                      ; preds = %pred.store.continue38, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %pred.store.continue38 ]
  %3 = or disjoint i64 %index, 8
  %4 = getelementptr inbounds i16, ptr %0, i64 %index
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load = load <8 x i16>, ptr %4, align 2, !tbaa !5
  %wide.load8 = load <8 x i16>, ptr %5, align 2, !tbaa !5
  %6 = icmp slt <8 x i16> %wide.load, zeroinitializer
  %7 = icmp slt <8 x i16> %wide.load8, zeroinitializer
  %8 = extractelement <8 x i1> %6, i64 0
  br i1 %8, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %9 = getelementptr inbounds i16, ptr %0, i64 %index
  store i16 0, ptr %9, align 2, !tbaa !5
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %10 = extractelement <8 x i1> %6, i64 1
  br i1 %10, label %pred.store.if9, label %pred.store.continue10

pred.store.if9:                                   ; preds = %pred.store.continue
  %11 = or disjoint i64 %index, 1
  %12 = getelementptr inbounds i16, ptr %0, i64 %11
  store i16 0, ptr %12, align 2, !tbaa !5
  br label %pred.store.continue10

pred.store.continue10:                            ; preds = %pred.store.if9, %pred.store.continue
  %13 = extractelement <8 x i1> %6, i64 2
  br i1 %13, label %pred.store.if11, label %pred.store.continue12

pred.store.if11:                                  ; preds = %pred.store.continue10
  %14 = or disjoint i64 %index, 2
  %15 = getelementptr inbounds i16, ptr %0, i64 %14
  store i16 0, ptr %15, align 2, !tbaa !5
  br label %pred.store.continue12

pred.store.continue12:                            ; preds = %pred.store.if11, %pred.store.continue10
  %16 = extractelement <8 x i1> %6, i64 3
  br i1 %16, label %pred.store.if13, label %pred.store.continue14

pred.store.if13:                                  ; preds = %pred.store.continue12
  %17 = or disjoint i64 %index, 3
  %18 = getelementptr inbounds i16, ptr %0, i64 %17
  store i16 0, ptr %18, align 2, !tbaa !5
  br label %pred.store.continue14

pred.store.continue14:                            ; preds = %pred.store.if13, %pred.store.continue12
  %19 = extractelement <8 x i1> %6, i64 4
  br i1 %19, label %pred.store.if15, label %pred.store.continue16

pred.store.if15:                                  ; preds = %pred.store.continue14
  %20 = or disjoint i64 %index, 4
  %21 = getelementptr inbounds i16, ptr %0, i64 %20
  store i16 0, ptr %21, align 2, !tbaa !5
  br label %pred.store.continue16

pred.store.continue16:                            ; preds = %pred.store.if15, %pred.store.continue14
  %22 = extractelement <8 x i1> %6, i64 5
  br i1 %22, label %pred.store.if17, label %pred.store.continue18

pred.store.if17:                                  ; preds = %pred.store.continue16
  %23 = or disjoint i64 %index, 5
  %24 = getelementptr inbounds i16, ptr %0, i64 %23
  store i16 0, ptr %24, align 2, !tbaa !5
  br label %pred.store.continue18

pred.store.continue18:                            ; preds = %pred.store.if17, %pred.store.continue16
  %25 = extractelement <8 x i1> %6, i64 6
  br i1 %25, label %pred.store.if19, label %pred.store.continue20

pred.store.if19:                                  ; preds = %pred.store.continue18
  %26 = or disjoint i64 %index, 6
  %27 = getelementptr inbounds i16, ptr %0, i64 %26
  store i16 0, ptr %27, align 2, !tbaa !5
  br label %pred.store.continue20

pred.store.continue20:                            ; preds = %pred.store.if19, %pred.store.continue18
  %28 = extractelement <8 x i1> %6, i64 7
  br i1 %28, label %pred.store.if21, label %pred.store.continue22

pred.store.if21:                                  ; preds = %pred.store.continue20
  %29 = or disjoint i64 %index, 7
  %30 = getelementptr inbounds i16, ptr %0, i64 %29
  store i16 0, ptr %30, align 2, !tbaa !5
  br label %pred.store.continue22

pred.store.continue22:                            ; preds = %pred.store.if21, %pred.store.continue20
  %31 = extractelement <8 x i1> %7, i64 0
  br i1 %31, label %pred.store.if23, label %pred.store.continue24

pred.store.if23:                                  ; preds = %pred.store.continue22
  %32 = getelementptr inbounds i16, ptr %0, i64 %3
  store i16 0, ptr %32, align 2, !tbaa !5
  br label %pred.store.continue24

pred.store.continue24:                            ; preds = %pred.store.if23, %pred.store.continue22
  %33 = extractelement <8 x i1> %7, i64 1
  br i1 %33, label %pred.store.if25, label %pred.store.continue26

pred.store.if25:                                  ; preds = %pred.store.continue24
  %34 = or disjoint i64 %index, 9
  %35 = getelementptr inbounds i16, ptr %0, i64 %34
  store i16 0, ptr %35, align 2, !tbaa !5
  br label %pred.store.continue26

pred.store.continue26:                            ; preds = %pred.store.if25, %pred.store.continue24
  %36 = extractelement <8 x i1> %7, i64 2
  br i1 %36, label %pred.store.if27, label %pred.store.continue28

pred.store.if27:                                  ; preds = %pred.store.continue26
  %37 = or disjoint i64 %index, 10
  %38 = getelementptr inbounds i16, ptr %0, i64 %37
  store i16 0, ptr %38, align 2, !tbaa !5
  br label %pred.store.continue28

pred.store.continue28:                            ; preds = %pred.store.if27, %pred.store.continue26
  %39 = extractelement <8 x i1> %7, i64 3
  br i1 %39, label %pred.store.if29, label %pred.store.continue30

pred.store.if29:                                  ; preds = %pred.store.continue28
  %40 = or disjoint i64 %index, 11
  %41 = getelementptr inbounds i16, ptr %0, i64 %40
  store i16 0, ptr %41, align 2, !tbaa !5
  br label %pred.store.continue30

pred.store.continue30:                            ; preds = %pred.store.if29, %pred.store.continue28
  %42 = extractelement <8 x i1> %7, i64 4
  br i1 %42, label %pred.store.if31, label %pred.store.continue32

pred.store.if31:                                  ; preds = %pred.store.continue30
  %43 = or disjoint i64 %index, 12
  %44 = getelementptr inbounds i16, ptr %0, i64 %43
  store i16 0, ptr %44, align 2, !tbaa !5
  br label %pred.store.continue32

pred.store.continue32:                            ; preds = %pred.store.if31, %pred.store.continue30
  %45 = extractelement <8 x i1> %7, i64 5
  br i1 %45, label %pred.store.if33, label %pred.store.continue34

pred.store.if33:                                  ; preds = %pred.store.continue32
  %46 = or disjoint i64 %index, 13
  %47 = getelementptr inbounds i16, ptr %0, i64 %46
  store i16 0, ptr %47, align 2, !tbaa !5
  br label %pred.store.continue34

pred.store.continue34:                            ; preds = %pred.store.if33, %pred.store.continue32
  %48 = extractelement <8 x i1> %7, i64 6
  br i1 %48, label %pred.store.if35, label %pred.store.continue36

pred.store.if35:                                  ; preds = %pred.store.continue34
  %49 = or disjoint i64 %index, 14
  %50 = getelementptr inbounds i16, ptr %0, i64 %49
  store i16 0, ptr %50, align 2, !tbaa !5
  br label %pred.store.continue36

pred.store.continue36:                            ; preds = %pred.store.if35, %pred.store.continue34
  %51 = extractelement <8 x i1> %7, i64 7
  br i1 %51, label %pred.store.if37, label %pred.store.continue38

pred.store.if37:                                  ; preds = %pred.store.continue36
  %52 = or disjoint i64 %index, 15
  %53 = getelementptr inbounds i16, ptr %0, i64 %52
  store i16 0, ptr %53, align 2, !tbaa !5
  br label %pred.store.continue38

pred.store.continue38:                            ; preds = %pred.store.if37, %pred.store.continue36
  %index.next = add nuw i64 %index, 16
  %54 = icmp eq i64 %index.next, %n.vec
  br i1 %54, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %pred.store.continue38
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader39

.lr.ph.preheader39:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader39, %59
  %indvars.iv = phi i64 [ %indvars.iv.next, %59 ], [ %indvars.iv.ph, %.lr.ph.preheader39 ]
  %55 = getelementptr inbounds i16, ptr %0, i64 %indvars.iv
  %56 = load i16, ptr %55, align 2, !tbaa !5
  %57 = icmp slt i16 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %.lr.ph
  store i16 0, ptr %55, align 2, !tbaa !5
  br label %59

59:                                               ; preds = %.lr.ph, %58
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %59, %middle.block, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass