; LLVM IR from Seeed-Studio/Seeed_Arduino_edgeimpulse :: src/edge-impulse-sdk/tensorflow/lite/c (common)

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

%struct.TfLiteDimensionMetadata = type { i32, i32, ptr, ptr }
%struct.TfLiteSparsity = type { ptr, ptr, ptr, i32 }

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local void @TfLiteIntArrayFree(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @TfLiteSparsityFree(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.TfLiteDimensionMetadata, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  br label %71

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.TfLiteSparsity, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %19

13:                                               ; preds = %8
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TfLiteSparsity, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  call void @TfLiteIntArrayFree(ptr noundef %16)
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TfLiteSparsity, ptr %17, i32 0, i32 0
  store ptr null, ptr %18, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %13, %8
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TfLiteSparsity, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %30

24:                                               ; preds = %19
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TfLiteSparsity, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  call void @TfLiteIntArrayFree(ptr noundef %27)
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TfLiteSparsity, ptr %28, i32 0, i32 1
  store ptr null, ptr %29, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %24, %19
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TfLiteSparsity, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %69

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %36

36:                                               ; preds = %60, %35
  %37 = load i32, ptr %3, align 4, !tbaa !14
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TfLiteSparsity, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = icmp slt i32 %37, %40
  br i1 %41, label %42, label %63

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #4
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TfLiteSparsity, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = load i32, ptr %3, align 4, !tbaa !14
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.TfLiteDimensionMetadata, ptr %45, i64 %47
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %48, i64 24, i1 false), !tbaa.struct !16
  %49 = getelementptr inbounds %struct.TfLiteDimensionMetadata, ptr %4, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !17
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %59

52:                                               ; preds = %42
  %53 = getelementptr inbounds %struct.TfLiteDimensionMetadata, ptr %4, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  call void @TfLiteIntArrayFree(ptr noundef %54)
  %55 = getelementptr inbounds %struct.TfLiteDimensionMetadata, ptr %4, i32 0, i32 2
  store ptr null, ptr %55, align 8, !tbaa !19
  %56 = getelementptr inbounds %struct.TfLiteDimensionMetadata, ptr %4, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  call void @TfLiteIntArrayFree(ptr noundef %57)
  %58 = getelementptr inbounds %struct.TfLiteDimensionMetadata, ptr %4, i32 0, i32 3
  store ptr null, ptr %58, align 8, !tbaa !20
  br label %59

59:                                               ; preds = %52, %42
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #4
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %3, align 4, !tbaa !14
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %3, align 4, !tbaa !14
  br label %36, !llvm.loop !21

63:                                               ; preds = %36
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TfLiteSparsity, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  call void @free(ptr noundef %66) #4
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TfLiteSparsity, ptr %67, i32 0, i32 2
  store ptr null, ptr %68, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %69

69:                                               ; preds = %63, %30
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %70) #4
  br label %71

71:                                               ; preds = %69, %7
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 "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 #4 = { 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, !6, i64 0}
!10 = !{!"TfLiteSparsity", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 16}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 24}
!16 = !{i64 0, i64 4, !14, i64 4, i64 4, !14, i64 8, i64 8, !5, i64 16, i64 8, !5}
!17 = !{!18, !11, i64 0}
!18 = !{!"TfLiteDimensionMetadata", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!19 = !{!18, !6, i64 8}
!20 = !{!18, !6, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.TfLiteDimensionMetadata = type { i32, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @TfLiteIntArrayFree(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @TfLiteSparsityFree(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %27, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %3
  tail call void @TfLiteIntArrayFree(ptr noundef nonnull %4)
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %5, %3
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %.not19 = icmp eq ptr %8, null
  br i1 %.not19, label %10, label %9

9:                                                ; preds = %6
  tail call void @TfLiteIntArrayFree(ptr noundef nonnull %8)
  store ptr null, ptr %7, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %9, %6
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %.not20 = icmp eq ptr %12, null
  br i1 %.not20, label %26, label %.preheader

.preheader:                                       ; preds = %10
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %21
  %16 = phi i32 [ %22, %21 ], [ %14, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %21 ], [ 0, %.preheader ]
  %17 = load ptr, ptr %11, align 8, !tbaa !12
  %18 = getelementptr inbounds %struct.TfLiteDimensionMetadata, ptr %17, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %18, align 8, !tbaa !14
  %19 = icmp eq i32 %.sroa.0.0.copyload, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %.lr.ph
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %18, i64 16
  %.sroa.6.0.copyload = load ptr, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !15
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %18, i64 8
  %.sroa.41.0.copyload = load ptr, ptr %.sroa.41.0..sroa_idx, align 8, !tbaa !15
  tail call void @TfLiteIntArrayFree(ptr noundef %.sroa.41.0.copyload)
  tail call void @TfLiteIntArrayFree(ptr noundef %.sroa.6.0.copyload)
  %.pre = load i32, ptr %13, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %20, %.lr.ph
  %22 = phi i32 [ %.pre, %20 ], [ %16, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv.next, %23
  br i1 %24, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %21
  %.pre23 = load ptr, ptr %11, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %25 = phi ptr [ %.pre23, %._crit_edge.loopexit ], [ %12, %.preheader ]
  tail call void @free(ptr noundef %25) #2
  br label %26

26:                                               ; preds = %._crit_edge, %10
  tail call void @free(ptr noundef nonnull %0) #2
  br label %27

27:                                               ; preds = %1, %26
  ret void
}

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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, !7, i64 0}
!6 = !{!"TfLiteSparsity", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 24}
!14 = !{!10, !10, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass