; LLVM IR from tanakamasayuki/Arduino_TensorFlowLite_ESP32 :: src/tensorflow/lite/micro/memory_planner (linear_memory_planner)

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

%"class.tflite::LinearMemoryPlanner" = type { %"class.tflite::MicroMemoryPlanner", [1024 x i64], i32, i64 }
%"class.tflite::MicroMemoryPlanner" = type { ptr }

@.str = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6tflite19LinearMemoryPlanner9AddBufferEPNS_13ErrorReporterEiii(ptr noundef nonnull align 8 dereferenceable(8216) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #0 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %7, align 8
  %13 = getelementptr inbounds %"class.tflite::LinearMemoryPlanner", ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp sge i32 %14, 1024
  br i1 %15, label %16, label %21

16:                                               ; preds = %5
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = call noundef i32 (ptr, ptr, ...) @_ZN6tflite13ErrorReporter6ReportEPKcz(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef @.str, i32 noundef 1024)
  br label %20

20:                                               ; preds = %17
  store i32 1, ptr %6, align 4
  br label %37

21:                                               ; preds = %5
  %22 = getelementptr inbounds %"class.tflite::LinearMemoryPlanner", ptr %12, i32 0, i32 3
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds %"class.tflite::LinearMemoryPlanner", ptr %12, i32 0, i32 1
  %25 = getelementptr inbounds %"class.tflite::LinearMemoryPlanner", ptr %12, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1024 x i64], ptr %24, i64 0, i64 %27
  store i64 %23, ptr %28, align 8, !tbaa !16
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %"class.tflite::LinearMemoryPlanner", ptr %12, i32 0, i32 3
  %32 = load i64, ptr %31, align 8, !tbaa !15
  %33 = add i64 %32, %30
  store i64 %33, ptr %31, align 8, !tbaa !15
  %34 = getelementptr inbounds %"class.tflite::LinearMemoryPlanner", ptr %12, i32 0, i32 2
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %34, align 8, !tbaa !11
  store i32 0, ptr %6, align 4
  br label %37

37:                                               ; preds = %21, %20
  %38 = load i32, ptr %6, align 4
  ret i32 %38
}

declare noundef i32 @_ZN6tflite13ErrorReporter6ReportEPKcz(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ...) #1

attributes #0 = { mustprogress 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 = { "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 = !{!"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, !10, i64 8200}
!12 = !{!"_ZTSN6tflite19LinearMemoryPlannerE", !13, i64 0, !7, i64 8, !10, i64 8200, !14, i64 8208}
!13 = !{!"_ZTSN6tflite18MicroMemoryPlannerE"}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !14, i64 8208}
!16 = !{!14, !14, i64 0}


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

@.str = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN6tflite19LinearMemoryPlanner9AddBufferEPNS_13ErrorReporterEiii(ptr nocapture noundef nonnull align 8 dereferenceable(8216) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8200
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, 1023
  br i1 %8, label %9, label %11

9:                                                ; preds = %5
  %10 = tail call noundef i32 (ptr, ptr, ...) @_ZN6tflite13ErrorReporter6ReportEPKcz(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull @.str, i32 noundef 1024)
  br label %20

11:                                               ; preds = %5
  %12 = getelementptr inbounds i8, ptr %0, i64 8208
  %13 = load i64, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = sext i32 %7 to i64
  %16 = getelementptr inbounds [1024 x i64], ptr %14, i64 0, i64 %15
  store i64 %13, ptr %16, align 8, !tbaa !13
  %17 = sext i32 %2 to i64
  %18 = add i64 %13, %17
  store i64 %18, ptr %12, align 8, !tbaa !12
  %19 = add nsw i32 %7, 1
  store i32 %19, ptr %6, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %11, %9
  %.0 = phi i32 [ 1, %9 ], [ 0, %11 ]
  ret i32 %.0
}

declare noundef i32 @_ZN6tflite13ErrorReporter6ReportEPKcz(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, ...) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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, !10, i64 8200}
!6 = !{!"_ZTSN6tflite19LinearMemoryPlannerE", !7, i64 0, !8, i64 8, !10, i64 8200, !11, i64 8208}
!7 = !{!"_ZTSN6tflite18MicroMemoryPlannerE"}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !11, i64 8208}
!13 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass