; LLVM IR from zephyrproject-rtos/zephyr :: samples/modules/tflite-micro/magic_wand/src/gesture_predictor.ll (Z14PredictGesturePf)

; 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"

@_ZN12_GLOBAL__N_118prediction_historyE = external hidden global [4 x [5 x float]], align 16
@_ZN12_GLOBAL__N_124prediction_history_indexE = external hidden global i32, align 4
@_ZN12_GLOBAL__N_128prediction_suppression_countE = external hidden global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z14PredictGesturePf(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %28, %1
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 4
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %31

16:                                               ; preds = %12
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds float, ptr %17, i64 %19
  %21 = load float, ptr %20, align 4, !tbaa !11
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [4 x [5 x float]], ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 0, i64 %23
  %25 = load i32, ptr @_ZN12_GLOBAL__N_124prediction_history_indexE, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [5 x float], ptr %24, i64 0, i64 %26
  store float %21, ptr %27, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %16
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !13

31:                                               ; preds = %15
  %32 = load i32, ptr @_ZN12_GLOBAL__N_124prediction_history_indexE, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @_ZN12_GLOBAL__N_124prediction_history_indexE, align 4, !tbaa !9
  %34 = load i32, ptr @_ZN12_GLOBAL__N_124prediction_history_indexE, align 4, !tbaa !9
  %35 = icmp sge i32 %34, 5
  br i1 %35, label %36, label %37

36:                                               ; preds = %31
  store i32 0, ptr @_ZN12_GLOBAL__N_124prediction_history_indexE, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %36, %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 -1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store float 0.000000e+00, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %73, %37
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp slt i32 %39, 4
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %76

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %57, %42
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp slt i32 %44, 5
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %60

47:                                               ; preds = %43
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [4 x [5 x float]], ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 0, i64 %49
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [5 x float], ptr %50, i64 0, i64 %52
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = load float, ptr %9, align 4, !tbaa !11
  %56 = fadd float %55, %54
  store float %56, ptr %9, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %47
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %10, align 4, !tbaa !9
  br label %43, !llvm.loop !15

60:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %61 = load float, ptr %9, align 4, !tbaa !11
  %62 = fdiv float %61, 5.000000e+00
  store float %62, ptr %11, align 4, !tbaa !11
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = icmp eq i32 %63, -1
  br i1 %64, label %69, label %65

65:                                               ; preds = %60
  %66 = load float, ptr %11, align 4, !tbaa !11
  %67 = load float, ptr %6, align 4, !tbaa !11
  %68 = fcmp ogt float %66, %67
  br i1 %68, label %69, label %72

69:                                               ; preds = %65, %60
  %70 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %70, ptr %5, align 4, !tbaa !9
  %71 = load float, ptr %11, align 4, !tbaa !11
  store float %71, ptr %6, align 4, !tbaa !11
  br label %72

72:                                               ; preds = %69, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %7, align 4, !tbaa !9
  br label %38, !llvm.loop !16

76:                                               ; preds = %41
  %77 = load i32, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4, !tbaa !9
  %78 = icmp sgt i32 %77, 0
  br i1 %78, label %79, label %82

79:                                               ; preds = %76
  %80 = load i32, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4, !tbaa !9
  %81 = add nsw i32 %80, -1
  store i32 %81, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %79, %76
  %83 = load i32, ptr %5, align 4, !tbaa !9
  %84 = icmp eq i32 %83, 3
  br i1 %84, label %91, label %85

85:                                               ; preds = %82
  %86 = load float, ptr %6, align 4, !tbaa !11
  %87 = fcmp olt float %86, 0x3FE99999A0000000
  br i1 %87, label %91, label %88

88:                                               ; preds = %85
  %89 = load i32, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4, !tbaa !9
  %90 = icmp sgt i32 %89, 0
  br i1 %90, label %91, label %92

91:                                               ; preds = %88, %85, %82
  store i32 3, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %94

92:                                               ; preds = %88
  store i32 25, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4, !tbaa !9
  %93 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %93, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %94

94:                                               ; preds = %92, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %95 = load i32, ptr %2, align 4
  ret i32 %95
}

; 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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"

@_ZN12_GLOBAL__N_118prediction_historyE = external hidden local_unnamed_addr global [4 x [5 x float]], align 16
@_ZN12_GLOBAL__N_124prediction_history_indexE = external hidden local_unnamed_addr global i32, align 4
@_ZN12_GLOBAL__N_128prediction_suppression_countE = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z14PredictGesturePf(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
.preheader:
  %1 = load i32, ptr @_ZN12_GLOBAL__N_124prediction_history_indexE, align 4, !tbaa !5
  %2 = sext i32 %1 to i64
  %3 = load float, ptr %0, align 4, !tbaa !9
  %4 = getelementptr inbounds [4 x [5 x float]], ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 0, i64 0, i64 %2
  store float %3, ptr %4, align 4, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load float, ptr %5, align 4, !tbaa !9
  %7 = getelementptr inbounds [4 x [5 x float]], ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 0, i64 1, i64 %2
  store float %6, ptr %7, align 4, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load float, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds [4 x [5 x float]], ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 0, i64 2, i64 %2
  store float %9, ptr %10, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load float, ptr %11, align 4, !tbaa !9
  %13 = getelementptr inbounds [4 x [5 x float]], ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 0, i64 3, i64 %2
  store float %12, ptr %13, align 4, !tbaa !9
  %14 = add nsw i32 %1, 1
  %15 = icmp sgt i32 %1, 3
  %spec.store.select = select i1 %15, i32 0, i32 %14
  store i32 %spec.store.select, ptr @_ZN12_GLOBAL__N_124prediction_history_indexE, align 4
  %16 = load float, ptr @_ZN12_GLOBAL__N_118prediction_historyE, align 16, !tbaa !9
  %17 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 4), align 4, !tbaa !9
  %18 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 8), align 8, !tbaa !9
  %19 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 12), align 4, !tbaa !9
  %20 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 16), align 16, !tbaa !9
  %21 = load <4 x float>, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 20), align 4
  %22 = shufflevector <4 x float> %21, <4 x float> poison, <2 x i32> <i32 0, i32 poison>
  %23 = load <4 x float>, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 24), align 8
  %24 = shufflevector <4 x float> %23, <4 x float> poison, <2 x i32> <i32 0, i32 poison>
  %25 = load <4 x float>, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 28), align 4
  %26 = shufflevector <4 x float> %25, <4 x float> poison, <2 x i32> <i32 0, i32 poison>
  %27 = load <4 x float>, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 32), align 16
  %28 = shufflevector <4 x float> %27, <4 x float> poison, <2 x i32> <i32 0, i32 poison>
  %29 = load <4 x float>, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 36), align 4
  %30 = shufflevector <4 x float> %29, <4 x float> poison, <2 x i32> <i32 0, i32 poison>
  %31 = insertelement <2 x float> %22, float %16, i64 1
  %32 = fadd <2 x float> %31, zeroinitializer
  %33 = insertelement <2 x float> %24, float %17, i64 1
  %34 = fadd <2 x float> %32, %33
  %35 = insertelement <2 x float> %26, float %18, i64 1
  %36 = fadd <2 x float> %34, %35
  %37 = insertelement <2 x float> %28, float %19, i64 1
  %38 = fadd <2 x float> %36, %37
  %39 = insertelement <2 x float> %30, float %20, i64 1
  %40 = fadd <2 x float> %38, %39
  %41 = fdiv <2 x float> %40, <float 5.000000e+00, float 5.000000e+00>
  %42 = extractelement <2 x float> %41, i64 0
  %43 = extractelement <2 x float> %41, i64 1
  %44 = fcmp ogt float %42, %43
  %.129.1 = zext i1 %44 to i32
  %.1.1 = select i1 %44, float %42, float %43
  %45 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 40), align 8, !tbaa !9
  %46 = fadd float %45, 0.000000e+00
  %47 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 44), align 4, !tbaa !9
  %48 = fadd float %46, %47
  %49 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 48), align 16, !tbaa !9
  %50 = fadd float %48, %49
  %51 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 52), align 4, !tbaa !9
  %52 = fadd float %50, %51
  %53 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 56), align 8, !tbaa !9
  %54 = fadd float %52, %53
  %55 = fdiv float %54, 5.000000e+00
  %56 = fcmp ogt float %55, %.1.1
  %.129.2 = select i1 %56, i32 2, i32 %.129.1
  %.1.2 = select i1 %56, float %55, float %.1.1
  %57 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 60), align 4, !tbaa !9
  %58 = fadd float %57, 0.000000e+00
  %59 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 64), align 16, !tbaa !9
  %60 = fadd float %58, %59
  %61 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 68), align 4, !tbaa !9
  %62 = fadd float %60, %61
  %63 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 72), align 8, !tbaa !9
  %64 = fadd float %62, %63
  %65 = load float, ptr getelementptr inbounds (i8, ptr @_ZN12_GLOBAL__N_118prediction_historyE, i64 76), align 4, !tbaa !9
  %66 = fadd float %64, %65
  %67 = fdiv float %66, 5.000000e+00
  %68 = fcmp ogt float %67, %.1.2
  %.129.3 = select i1 %68, i32 3, i32 %.129.2
  %.1.3 = select i1 %68, float %67, float %.1.2
  %69 = load i32, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4
  %70 = icmp sgt i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %.preheader
  %72 = add nsw i32 %69, -1
  store i32 %72, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4, !tbaa !5
  %73 = icmp ne i32 %69, 1
  br label %74

74:                                               ; preds = %71, %.preheader
  %75 = phi i1 [ %73, %71 ], [ false, %.preheader ]
  %76 = fcmp olt float %.1.3, 0x3FE99999A0000000
  %77 = or i1 %76, %75
  %or.cond3 = or i1 %77, %68
  br i1 %or.cond3, label %79, label %78

78:                                               ; preds = %74
  store i32 25, ptr @_ZN12_GLOBAL__N_128prediction_suppression_countE, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %74, %78
  %.0 = phi i32 [ %.129.3, %78 ], [ 3, %74 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass