; LLVM IR from tanakamasayuki/Arduino_TensorFlowLite_ESP32 :: src/tensorflow/lite/micro/micro_profiler.ll (ZN6tflite13MicroProfiler10BeginEventEPKc)

; 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::MicroProfiler" = type <{ ptr, [1024 x ptr], [1024 x i32], [1024 x i32], i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6tflite13MicroProfiler10BeginEventEPKc(ptr noundef nonnull align 8 dereferenceable(16396) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 4
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp eq i32 %7, 1024
  br i1 %8, label %9, label %11

9:                                                ; preds = %2
  %10 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 4
  store i32 0, ptr %10, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %9, %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 1
  %14 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 4
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1024 x ptr], ptr %13, i64 0, i64 %16
  store ptr %12, ptr %17, align 8, !tbaa !5
  %18 = call noundef i32 @_ZN6tflite19GetCurrentTimeTicksEv()
  %19 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 2
  %20 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 4
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1024 x i32], ptr %19, i64 0, i64 %22
  store i32 %18, ptr %23, align 4, !tbaa !12
  %24 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 2
  %25 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 4
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1024 x i32], ptr %24, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = sub nsw i32 %29, 1
  %31 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 3
  %32 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1024 x i32], ptr %31, i64 0, i64 %34
  store i32 %30, ptr %35, align 4, !tbaa !12
  %36 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %5, i32 0, i32 4
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %36, align 8, !tbaa !9
  ret i32 %37
}

declare noundef i32 @_ZN6tflite19GetCurrentTimeTicksEv() #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, !11, i64 16392}
!10 = !{!"_ZTSN6tflite13MicroProfilerE", !7, i64 8, !7, i64 8200, !7, i64 12296, !11, i64 16392}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6tflite13MicroProfiler10BeginEventEPKc(ptr nocapture noundef nonnull align 8 dereferenceable(16396) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16392
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 1024
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  store i32 0, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %2
  %8 = phi i32 [ 0, %6 ], [ %4, %2 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = sext i32 %8 to i64
  %11 = getelementptr inbounds [1024 x ptr], ptr %9, i64 0, i64 %10
  store ptr %1, ptr %11, align 8, !tbaa !10
  %12 = tail call noundef i32 @_ZN6tflite19GetCurrentTimeTicksEv()
  %13 = getelementptr inbounds i8, ptr %0, i64 8200
  %14 = load i32, ptr %3, align 8, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1024 x i32], ptr %13, i64 0, i64 %15
  store i32 %12, ptr %16, align 4, !tbaa !12
  %17 = load i32, ptr %3, align 8, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1024 x i32], ptr %13, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = add nsw i32 %20, -1
  %22 = getelementptr inbounds i8, ptr %0, i64 12296
  %23 = getelementptr inbounds [1024 x i32], ptr %22, i64 0, i64 %18
  store i32 %21, ptr %23, align 4, !tbaa !12
  %24 = load i32, ptr %3, align 8, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %3, align 8, !tbaa !5
  ret i32 %24
}

declare noundef i32 @_ZN6tflite19GetCurrentTimeTicksEv() 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, !9, i64 16392}
!6 = !{!"_ZTSN6tflite13MicroProfilerE", !7, i64 8, !7, i64 8200, !7, i64 12296, !9, i64 16392}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!9, !9, i64 0}


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