; LLVM IR from tensorflow/tflite-micro :: tensorflow/lite/micro/micro_profiler.ll (ZN6tflite13MicroProfiler17LogTicksPerTagCsvEv)

; 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.tflite::MicroProfiler::TicksPerTag" = type { ptr, i32 }
%"class.tflite::MicroProfiler" = type { %"class.tflite::MicroProfilerInterface", [4096 x ptr], [4096 x i32], [4096 x i32], i32, [4096 x %"struct.tflite::MicroProfiler::TicksPerTag"] }
%"class.tflite::MicroProfilerInterface" = type { ptr }

@.str.4 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1

declare void @_Z11MicroPrintfPKcz(ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @abort() #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6tflite13MicroProfiler17LogTicksPerTagCsvEv(ptr noundef nonnull align 8 dereferenceable(131088) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %"struct.tflite::MicroProfiler::TicksPerTag", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  call void (ptr, ...) @_Z11MicroPrintfPKcz(ptr noundef @.str.4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %77, %1
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 4
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %80

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %18 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 3
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4096 x i32], ptr %18, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 2
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4096 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = sub i32 %22, %27
  store i32 %28, ptr %5, align 4, !tbaa !9
  %29 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 1
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4096 x ptr], ptr %29, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %36

35:                                               ; preds = %17
  br label %38

36:                                               ; preds = %17
  call void @abort() #7
  unreachable

37:                                               ; No predecessors!
  br label %38

38:                                               ; preds = %37, %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %39 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 1
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [4096 x ptr], ptr %39, i64 0, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = call noundef i32 @_ZN6tflite13MicroProfiler26FindExistingOrNextPositionEPKc(ptr noundef nonnull align 8 dereferenceable(131088) %10, ptr noundef %43)
  store i32 %44, ptr %6, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = icmp sge i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  br label %50

48:                                               ; preds = %38
  call void @abort() #7
  unreachable

49:                                               ; No predecessors!
  br label %50

50:                                               ; preds = %49, %47
  %51 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 1
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [4096 x ptr], ptr %51, i64 0, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 5
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [4096 x %"struct.tflite::MicroProfiler::TicksPerTag"], ptr %56, i64 0, i64 %58
  %60 = getelementptr inbounds %"struct.tflite::MicroProfiler::TicksPerTag", ptr %59, i32 0, i32 0
  store ptr %55, ptr %60, align 8, !tbaa !14
  %61 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 5
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [4096 x %"struct.tflite::MicroProfiler::TicksPerTag"], ptr %61, i64 0, i64 %63
  %65 = getelementptr inbounds %"struct.tflite::MicroProfiler::TicksPerTag", ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !16
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = add i32 %66, %67
  %69 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 5
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [4096 x %"struct.tflite::MicroProfiler::TicksPerTag"], ptr %69, i64 0, i64 %71
  %73 = getelementptr inbounds %"struct.tflite::MicroProfiler::TicksPerTag", ptr %72, i32 0, i32 1
  store i32 %68, ptr %73, align 8, !tbaa !16
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = load i32, ptr %3, align 4, !tbaa !9
  %76 = add i32 %75, %74
  store i32 %76, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %77

77:                                               ; preds = %50
  %78 = load i32, ptr %4, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !9
  br label %11, !llvm.loop !17

80:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %104, %80
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 4
  %84 = load i32, ptr %83, align 8, !tbaa !11
  %85 = icmp slt i32 %82, %84
  br i1 %85, label %87, label %86

86:                                               ; preds = %81
  store i32 5, ptr %8, align 4
  br label %107

87:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #6
  %88 = getelementptr inbounds %"class.tflite::MicroProfiler", ptr %10, i32 0, i32 5
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [4096 x %"struct.tflite::MicroProfiler::TicksPerTag"], ptr %88, i64 0, i64 %90
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %91, i64 16, i1 false), !tbaa.struct !19
  %92 = getelementptr inbounds %"struct.tflite::MicroProfiler::TicksPerTag", ptr %9, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !14
  %94 = icmp eq ptr %93, null
  br i1 %94, label %95, label %96

95:                                               ; preds = %87
  store i32 5, ptr %8, align 4
  br label %101

96:                                               ; preds = %87
  %97 = getelementptr inbounds %"struct.tflite::MicroProfiler::TicksPerTag", ptr %9, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !14
  %99 = getelementptr inbounds %"struct.tflite::MicroProfiler::TicksPerTag", ptr %9, i32 0, i32 1
  %100 = load i32, ptr %99, align 8, !tbaa !16
  call void (ptr, ...) @_Z11MicroPrintfPKcz(ptr noundef @.str.5, ptr noundef %98, i32 noundef %100)
  store i32 0, ptr %8, align 4
  br label %101

101:                                              ; preds = %96, %95
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #6
  %102 = load i32, ptr %8, align 4
  switch i32 %102, label %107 [
    i32 0, label %103
  ]

103:                                              ; preds = %101
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %7, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %7, align 4, !tbaa !9
  br label %81, !llvm.loop !20

107:                                              ; preds = %101, %86
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %108

108:                                              ; preds = %107
  %109 = load i32, ptr %3, align 4, !tbaa !9
  call void (ptr, ...) @_Z11MicroPrintfPKcz(ptr noundef @.str.6, i32 noundef %109)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6tflite13MicroProfiler26FindExistingOrNextPositionEPKc(ptr noundef nonnull align 8 dereferenceable(131088), ptr noundef) #4 align 2

; 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) #5

attributes #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 = { noreturn 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 65544}
!12 = !{!"_ZTSN6tflite13MicroProfilerE", !13, i64 0, !7, i64 8, !7, i64 32776, !7, i64 49160, !10, i64 65544, !7, i64 65552}
!13 = !{!"_ZTSN6tflite22MicroProfilerInterfaceE"}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN6tflite13MicroProfiler11TicksPerTagE", !6, i64 0, !10, i64 8}
!16 = !{!15, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{i64 0, i64 8, !5, i64 8, i64 4, !9}
!20 = distinct !{!20, !18}


; 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::MicroProfiler::TicksPerTag" = type { ptr, i32 }

@.str.4 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [28 x i8], align 1

declare void @_Z11MicroPrintfPKcz(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6tflite13MicroProfiler17LogTicksPerTagCsvEv(ptr noundef nonnull align 8 dereferenceable(131088) %0) local_unnamed_addr #2 align 2 {
  tail call void (ptr, ...) @_Z11MicroPrintfPKcz(ptr noundef nonnull @.str.4)
  %2 = getelementptr inbounds i8, ptr %0, i64 65544
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 49160
  %6 = getelementptr inbounds i8, ptr %0, i64 32776
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %0, i64 65552
  br label %11

.preheader:                                       ; preds = %24
  %9 = icmp sgt i32 %32, 0
  %10 = getelementptr inbounds i8, ptr %0, i64 65552
  br i1 %9, label %.lr.ph33, label %.critedge

11:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %.031 = phi i32 [ 0, %.lr.ph ], [ %31, %24 ]
  %12 = getelementptr inbounds [4096 x i32], ptr %5, i64 0, i64 %indvars.iv
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = getelementptr inbounds [4096 x i32], ptr %6, i64 0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sub i32 %13, %15
  %17 = getelementptr inbounds [4096 x ptr], ptr %7, i64 0, i64 %indvars.iv
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %.not25 = icmp eq ptr %18, null
  br i1 %.not25, label %19, label %20

19:                                               ; preds = %11
  tail call void @abort() #4
  unreachable

20:                                               ; preds = %11
  %21 = tail call noundef i32 @_ZN6tflite13MicroProfiler26FindExistingOrNextPositionEPKc(ptr noundef nonnull align 8 dereferenceable(131088) %0, ptr noundef nonnull %18)
  %22 = icmp sgt i32 %21, -1
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  tail call void @abort() #4
  unreachable

24:                                               ; preds = %20
  %25 = load ptr, ptr %17, align 8, !tbaa !12
  %26 = zext nneg i32 %21 to i64
  %27 = getelementptr inbounds [4096 x %"struct.tflite::MicroProfiler::TicksPerTag"], ptr %8, i64 0, i64 %26
  store ptr %25, ptr %27, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = add i32 %29, %16
  store i32 %30, ptr %28, align 8, !tbaa !16
  %31 = add i32 %16, %.031
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr %2, align 8, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %11, label %.preheader, !llvm.loop !17

.lr.ph33:                                         ; preds = %.preheader, %36
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %36 ], [ 0, %.preheader ]
  %35 = getelementptr inbounds [4096 x %"struct.tflite::MicroProfiler::TicksPerTag"], ptr %10, i64 0, i64 %indvars.iv36
  %.sroa.0.0.copyload = load ptr, ptr %35, align 8, !tbaa !12
  %.not = icmp eq ptr %.sroa.0.0.copyload, null
  br i1 %.not, label %.critedge, label %36

36:                                               ; preds = %.lr.ph33
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %35, i64 8
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !11
  tail call void (ptr, ...) @_Z11MicroPrintfPKcz(ptr noundef nonnull @.str.5, ptr noundef nonnull %.sroa.0.0.copyload, i32 noundef %.sroa.5.0.copyload)
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %37 = load i32, ptr %2, align 8, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = icmp slt i64 %indvars.iv.next37, %38
  br i1 %39, label %.lr.ph33, label %.critedge, !llvm.loop !19

.critedge:                                        ; preds = %36, %.lr.ph33, %1, %.preheader
  %.0.lcssa40 = phi i32 [ %31, %.preheader ], [ 0, %1 ], [ %31, %.lr.ph33 ], [ %31, %36 ]
  tail call void (ptr, ...) @_Z11MicroPrintfPKcz(ptr noundef nonnull @.str.6, i32 noundef %.0.lcssa40)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6tflite13MicroProfiler26FindExistingOrNextPositionEPKc(ptr noundef nonnull align 8 dereferenceable(131088), ptr noundef) local_unnamed_addr #3 align 2

attributes #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 = { noreturn 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 #2 = { 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 #3 = { 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 #4 = { noreturn 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, !10, i64 65544}
!6 = !{!"_ZTSN6tflite13MicroProfilerE", !7, i64 0, !8, i64 8, !8, i64 32776, !8, i64 49160, !10, i64 65544, !8, i64 65552}
!7 = !{!"_ZTSN6tflite22MicroProfilerInterfaceE"}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTSN6tflite13MicroProfiler11TicksPerTagE", !13, i64 0, !10, i64 8}
!16 = !{!15, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass