; LLVM IR from tanakamasayuki/Arduino_TensorFlowLite_ESP32 :: src/tensorflow/lite/micro/memory_planner (greedy_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::GreedyMemoryPlanner" = type <{ %"class.tflite::MicroMemoryPlanner", i32, i32, ptr, ptr, ptr, ptr, i32, i32, ptr, i8, [7 x i8] }>
%"class.tflite::MicroMemoryPlanner" = type { ptr }
%"struct.tflite::GreedyMemoryPlanner::BufferRequirements" = type { i32, i32, i32, i32 }

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

; 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: mustprogress uwtable
define dso_local noundef i32 @_ZN6tflite19GreedyMemoryPlanner9AddBufferEPNS_13ErrorReporterEiii(ptr noundef nonnull align 8 dereferenceable(65) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #1 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
  %12 = alloca ptr, align 8
  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
  %13 = load ptr, ptr %7, align 8
  %14 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %13, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %18 = icmp sge i32 %15, %17
  br i1 %18, label %19, label %26

19:                                               ; preds = %5
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %13, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !15
  %24 = call noundef i32 (ptr, ptr, ...) @_ZN6tflite13ErrorReporter6ReportEPKcz(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr noundef @.str, i32 noundef %23)
  br label %25

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

26:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %27 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %13, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %13, i32 0, i32 2
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %"struct.tflite::GreedyMemoryPlanner::BufferRequirements", ptr %28, i64 %31
  store ptr %32, ptr %12, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.tflite::GreedyMemoryPlanner::BufferRequirements", ptr %34, i32 0, i32 0
  store i32 %33, ptr %35, align 4, !tbaa !17
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.tflite::GreedyMemoryPlanner::BufferRequirements", ptr %37, i32 0, i32 2
  store i32 %36, ptr %38, align 4, !tbaa !19
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.tflite::GreedyMemoryPlanner::BufferRequirements", ptr %40, i32 0, i32 3
  store i32 %39, ptr %41, align 4, !tbaa !20
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.tflite::GreedyMemoryPlanner::BufferRequirements", ptr %42, i32 0, i32 1
  store i32 -1, ptr %43, align 4, !tbaa !21
  %44 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %13, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %44, align 4, !tbaa !11
  %47 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %13, i32 0, i32 10
  store i8 1, ptr %47, align 8, !tbaa !22
  store i32 0, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %48

48:                                               ; preds = %26, %25
  %49 = load i32, ptr %6, align 4
  ret i32 %49
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 }

!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 12}
!12 = !{!"_ZTSN6tflite19GreedyMemoryPlannerE", !13, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !6, i64 56, !14, i64 64}
!13 = !{!"_ZTSN6tflite18MicroMemoryPlannerE"}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !6, i64 16}
!17 = !{!18, !10, i64 0}
!18 = !{!"_ZTSN6tflite19GreedyMemoryPlanner18BufferRequirementsE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!19 = !{!18, !10, i64 8}
!20 = !{!18, !10, i64 12}
!21 = !{!18, !10, i64 4}
!22 = !{!12, !14, i64 64}


; 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.tflite::GreedyMemoryPlanner::BufferRequirements" = type { i32, i32, i32, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN6tflite19GreedyMemoryPlanner9AddBufferEPNS_13ErrorReporterEiii(ptr nocapture noundef nonnull align 8 dereferenceable(65) %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 12
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %.not = icmp slt i32 %7, %9
  br i1 %.not, label %12, label %10

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

12:                                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = sext i32 %7 to i64
  %16 = getelementptr inbounds %"struct.tflite::GreedyMemoryPlanner::BufferRequirements", ptr %14, i64 %15
  store i32 %2, ptr %16, align 4, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  store i32 %3, ptr %17, align 4, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %16, i64 12
  store i32 %4, ptr %18, align 4, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %16, i64 4
  store i32 -1, ptr %19, align 4, !tbaa !19
  %20 = add nsw i32 %7, 1
  store i32 %20, ptr %6, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 64
  store i8 1, ptr %21, align 8, !tbaa !20
  br label %22

22:                                               ; preds = %12, %10
  %.0 = phi i32 [ 1, %10 ], [ 0, %12 ]
  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, !8, i64 12}
!6 = !{!"_ZTSN6tflite19GreedyMemoryPlannerE", !7, i64 0, !8, i64 8, !8, i64 12, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !8, i64 48, !8, i64 52, !11, i64 56, !12, i64 64}
!7 = !{!"_ZTSN6tflite18MicroMemoryPlannerE"}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!6, !8, i64 8}
!14 = !{!6, !11, i64 16}
!15 = !{!16, !8, i64 0}
!16 = !{!"_ZTSN6tflite19GreedyMemoryPlanner18BufferRequirementsE", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12}
!17 = !{!16, !8, i64 8}
!18 = !{!16, !8, i64 12}
!19 = !{!16, !8, i64 4}
!20 = !{!6, !12, i64 64}


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