; LLVM IR from Seeed-Studio/Seeed_Arduino_edgeimpulse :: src/edge-impulse-sdk/tensorflow/lite/micro/memory_planner/greedy_memory_planner_93808107 (ZN6tflite19GreedyMemoryPlannerC2EPhi)

; 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::MemoryPlanner", i32, i32, ptr, ptr, ptr, ptr, i32, i32, ptr, i8, [7 x i8] }>
%"class.tflite::MemoryPlanner" = type { ptr }

@_ZTVN6tflite19GreedyMemoryPlannerE = external dso_local unnamed_addr constant { [8 x ptr] }, align 8

; 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 void @_ZN6tflite19GreedyMemoryPlannerC2EPhi(ptr noundef nonnull align 8 dereferenceable(65) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @_ZN6tflite13MemoryPlannerC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %10)
  store ptr getelementptr inbounds inrange(-16, 48) ({ [8 x ptr] }, ptr @_ZTVN6tflite19GreedyMemoryPlannerE, i32 0, i32 0, i32 2), ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 2
  store i32 0, ptr %11, align 4, !tbaa !13
  %12 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 10
  store i8 1, ptr %12, align 8, !tbaa !17
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = invoke noundef i64 @_ZN6tflite19GreedyMemoryPlanner15per_buffer_sizeEv()
          to label %16 unwind label %55

16:                                               ; preds = %3
  %17 = udiv i64 %14, %15
  %18 = trunc i64 %17 to i32
  %19 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 1
  store i32 %18, ptr %19, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %20, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 3
  store ptr %21, ptr %22, align 8, !tbaa !19
  %23 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !18
  %25 = sext i32 %24 to i64
  %26 = mul i64 16, %25
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 %26
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 4
  store ptr %29, ptr %30, align 8, !tbaa !20
  %31 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !18
  %33 = sext i32 %32 to i64
  %34 = mul i64 4, %33
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 %34
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 5
  store ptr %37, ptr %38, align 8, !tbaa !21
  %39 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 1
  %40 = load i32, ptr %39, align 8, !tbaa !18
  %41 = sext i32 %40 to i64
  %42 = mul i64 4, %41
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 %42
  store ptr %44, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 6
  store ptr %45, ptr %46, align 8, !tbaa !22
  %47 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !18
  %49 = sext i32 %48 to i64
  %50 = mul i64 12, %49
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 %50
  store ptr %52, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.tflite::GreedyMemoryPlanner", ptr %10, i32 0, i32 9
  store ptr %53, ptr %54, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void

55:                                               ; preds = %3
  %56 = landingpad { ptr, i32 }
          cleanup
  %57 = extractvalue { ptr, i32 } %56, 0
  store ptr %57, ptr %7, align 8
  %58 = extractvalue { ptr, i32 } %56, 1
  store i32 %58, ptr %8, align 4
  call void @_ZN6tflite13MemoryPlannerD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %10) #3
  br label %59

59:                                               ; preds = %55
  %60 = load ptr, ptr %7, align 8
  %61 = load i32, ptr %8, align 4
  %62 = insertvalue { ptr, i32 } poison, ptr %60, 0
  %63 = insertvalue { ptr, i32 } %62, i32 %61, 1
  resume { ptr, i32 } %63
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6tflite13MemoryPlannerC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN6tflite19GreedyMemoryPlanner15per_buffer_sizeEv() #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6tflite13MemoryPlannerD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 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 = { 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 #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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !10, i64 12}
!14 = !{!"_ZTSN6tflite19GreedyMemoryPlannerE", !15, 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, !16, i64 64}
!15 = !{!"_ZTSN6tflite13MemoryPlannerE"}
!16 = !{!"bool", !7, i64 0}
!17 = !{!14, !16, i64 64}
!18 = !{!14, !10, i64 8}
!19 = !{!14, !6, i64 16}
!20 = !{!14, !6, i64 24}
!21 = !{!14, !6, i64 32}
!22 = !{!14, !6, i64 40}
!23 = !{!14, !6, i64 56}


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

@_ZTVN6tflite19GreedyMemoryPlannerE = external dso_local unnamed_addr constant { [8 x ptr] }, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6tflite19GreedyMemoryPlannerC2EPhi(ptr noundef nonnull align 8 dereferenceable(65) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN6tflite13MemoryPlannerC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0)
  store ptr getelementptr inbounds inrange(-16, 48) (i8, ptr @_ZTVN6tflite19GreedyMemoryPlannerE, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 0, ptr %4, align 4, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  store i8 1, ptr %5, align 8, !tbaa !15
  %6 = sext i32 %2 to i64
  %7 = tail call noundef i64 @_ZN6tflite19GreedyMemoryPlanner15per_buffer_sizeEv()
  %8 = udiv i64 %6, %7
  %9 = trunc i64 %8 to i32
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %9, ptr %10, align 8, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %1, ptr %11, align 8, !tbaa !17
  %sext = shl i64 %8, 32
  %12 = ashr exact i64 %sext, 28
  %13 = getelementptr inbounds i8, ptr %1, i64 %12
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %13, ptr %14, align 8, !tbaa !18
  %15 = ashr exact i64 %sext, 32
  %16 = ashr exact i64 %sext, 30
  %17 = getelementptr inbounds i8, ptr %13, i64 %16
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %17, ptr %18, align 8, !tbaa !19
  %19 = getelementptr inbounds i8, ptr %17, i64 %16
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %19, ptr %20, align 8, !tbaa !20
  %21 = mul nsw i64 %15, 12
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  %23 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %22, ptr %23, align 8, !tbaa !21
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6tflite13MemoryPlannerC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN6tflite19GreedyMemoryPlanner15per_buffer_sizeEv() local_unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

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

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !11, i64 12}
!9 = !{!"_ZTSN6tflite19GreedyMemoryPlannerE", !10, i64 0, !11, i64 8, !11, i64 12, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !11, i64 48, !11, i64 52, !13, i64 56, !14, i64 64}
!10 = !{!"_ZTSN6tflite13MemoryPlannerE"}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"any pointer", !12, i64 0}
!14 = !{!"bool", !12, i64 0}
!15 = !{!9, !14, i64 64}
!16 = !{!9, !11, i64 8}
!17 = !{!9, !13, i64 16}
!18 = !{!9, !13, i64 24}
!19 = !{!9, !13, i64 32}
!20 = !{!9, !13, i64 40}
!21 = !{!9, !13, i64 56}


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