; LLVM IR from tanakamasayuki/Arduino_TensorFlowLite_ESP32 :: examples/OldExamples/magic_wand_M5StackFire/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"

@continuous_count = external dso_local global i32, align 4
@last_predict = external dso_local global i32, align 4
@kConsecutiveInferenceThresholds = external constant [3 x 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 i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 -1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %22, %1
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 3
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %25

11:                                               ; preds = %7
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds float, ptr %12, i64 %14
  %16 = load float, ptr %15, align 4, !tbaa !11
  %17 = fpext float %16 to double
  %18 = fcmp ogt double %17, 8.000000e-01
  br i1 %18, label %19, label %21

19:                                               ; preds = %11
  %20 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %20, ptr %4, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %19, %11
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !13

25:                                               ; preds = %10
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i32 0, ptr @continuous_count, align 4, !tbaa !9
  store i32 3, ptr @last_predict, align 4, !tbaa !9
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %48

29:                                               ; preds = %25
  %30 = load i32, ptr @last_predict, align 4, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load i32, ptr @continuous_count, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @continuous_count, align 4, !tbaa !9
  br label %37

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

37:                                               ; preds = %36, %33
  %38 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %38, ptr @last_predict, align 4, !tbaa !9
  %39 = load i32, ptr @continuous_count, align 4, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [3 x i32], ptr @kConsecutiveInferenceThresholds, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = icmp slt i32 %39, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %37
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %48

46:                                               ; preds = %37
  store i32 0, ptr @continuous_count, align 4, !tbaa !9
  store i32 -1, ptr @last_predict, align 4, !tbaa !9
  %47 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %47, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %48

48:                                               ; preds = %46, %45, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %49 = load i32, ptr %2, align 4
  ret i32 %49
}

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


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

@continuous_count = external dso_local local_unnamed_addr global i32, align 4
@last_predict = external dso_local local_unnamed_addr global i32, align 4
@kConsecutiveInferenceThresholds = external local_unnamed_addr constant [3 x i32], align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: read, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, -1) i32 @_Z14PredictGesturePf(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load float, ptr %0, align 4, !tbaa !5
  %3 = fpext float %2 to double
  %4 = fcmp ule double %3, 8.000000e-01
  %.1 = sext i1 %4 to i32
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fpext float %6 to double
  %8 = fcmp ogt double %7, 8.000000e-01
  %.1.1 = select i1 %8, i32 1, i32 %.1
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = fpext float %10 to double
  %12 = fcmp ogt double %11, 8.000000e-01
  %.1.2 = select i1 %12, i32 2, i32 %.1.1
  %13 = icmp eq i32 %.1.2, -1
  br i1 %13, label %.sink.split, label %14

14:                                               ; preds = %1
  %15 = load i32, ptr @last_predict, align 4, !tbaa !9
  %16 = icmp eq i32 %15, %.1.2
  %17 = load i32, ptr @continuous_count, align 4
  %18 = add nsw i32 %17, 1
  %storemerge = select i1 %16, i32 %18, i32 0
  store i32 %storemerge, ptr @continuous_count, align 4, !tbaa !9
  store i32 %.1.2, ptr @last_predict, align 4, !tbaa !9
  %19 = zext nneg i32 %.1.2 to i64
  %20 = getelementptr inbounds [3 x i32], ptr @kConsecutiveInferenceThresholds, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp slt i32 %storemerge, %21
  br i1 %22, label %23, label %.sink.split

.sink.split:                                      ; preds = %14, %1
  %.sink = phi i32 [ 3, %1 ], [ -1, %14 ]
  %.011.ph = phi i32 [ 3, %1 ], [ %.1.2, %14 ]
  store i32 0, ptr @continuous_count, align 4, !tbaa !9
  store i32 %.sink, ptr @last_predict, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %.sink.split, %14
  %.011 = phi i32 [ 3, %14 ], [ %.011.ph, %.sink.split ]
  ret i32 %.011
}

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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass