; LLVM IR from tensorflow/tflite-micro :: signal/src (circular_buffer)

; 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::tflm_signal::CircularBuffer" = type { i64, i64, i64, i32, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal24CircularBufferWriteZerosEPNS0_14CircularBufferEm = external hidden unnamed_addr constant [90 x i8], align 1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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 nounwind uwtable
declare dso_local noundef i64 @_ZN6tflite11tflm_signal22CircularBufferCanWriteEPKNS0_14CircularBufferE(ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6tflite11tflm_signal24CircularBufferWriteZerosEPNS0_14CircularBufferEm(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp ugt i64 %13, 0
  br i1 %14, label %15, label %85

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call noundef i64 @_ZN6tflite11tflm_signal22CircularBufferCanWriteEPKNS0_14CircularBufferE(ptr noundef %16)
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = icmp uge i64 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  br label %23

21:                                               ; preds = %15
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 119, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal24CircularBufferWriteZerosEPNS0_14CircularBufferEm) #4
  unreachable

22:                                               ; No predecessors!
  br label %23

23:                                               ; preds = %22, %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !11
  store i64 %26, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %27, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !15
  store i64 %32, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = add i64 %33, %34
  store i64 %35, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = getelementptr inbounds i16, ptr %36, i64 %37
  %39 = load i64, ptr %4, align 8, !tbaa !9
  %40 = mul i64 %39, 2
  call void @llvm.memset.p0.i64(ptr align 2 %38, i8 0, i64 %40, i1 false)
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %44, label %55

44:                                               ; preds = %23
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = getelementptr inbounds i16, ptr %45, i64 %46
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds i16, ptr %47, i64 %48
  %50 = load i64, ptr %4, align 8, !tbaa !9
  %51 = mul i64 %50, 2
  call void @llvm.memset.p0.i64(ptr align 2 %49, i8 0, i64 %51, i1 false)
  %52 = load i64, ptr %4, align 8, !tbaa !9
  %53 = load i64, ptr %5, align 8, !tbaa !9
  %54 = add i64 %53, %52
  store i64 %54, ptr %5, align 8, !tbaa !9
  br label %79

55:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %56 = load i64, ptr %7, align 8, !tbaa !9
  %57 = load i64, ptr %5, align 8, !tbaa !9
  %58 = sub i64 %56, %57
  store i64 %58, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %59 = load i64, ptr %9, align 8, !tbaa !9
  %60 = mul i64 %59, 2
  store i64 %60, ptr %10, align 8, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = getelementptr inbounds i16, ptr %61, i64 %62
  %64 = load i64, ptr %5, align 8, !tbaa !9
  %65 = getelementptr inbounds i16, ptr %63, i64 %64
  %66 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 2 %65, i8 0, i64 %66, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %67 = load i64, ptr %8, align 8, !tbaa !9
  %68 = load i64, ptr %7, align 8, !tbaa !9
  %69 = sub i64 %67, %68
  store i64 %69, ptr %11, align 8, !tbaa !9
  %70 = load i64, ptr %11, align 8, !tbaa !9
  %71 = icmp ugt i64 %70, 0
  br i1 %71, label %72, label %77

72:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %73 = load i64, ptr %11, align 8, !tbaa !9
  %74 = mul i64 %73, 2
  store i64 %74, ptr %12, align 8, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 2 %75, i8 0, i64 %76, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %77

77:                                               ; preds = %72, %55
  %78 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %78, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %79

79:                                               ; preds = %77, %44
  %80 = load i64, ptr %5, align 8, !tbaa !9
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %81, i32 0, i32 2
  store i64 %80, ptr %82, align 8, !tbaa !11
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %83, i32 0, i32 3
  store i32 0, ptr %84, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %85

85:                                               ; preds = %79, %2
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTSN6tflite11tflm_signal14CircularBufferE", !10, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !13, i64 28, !6, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !13, i64 24}


; 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.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal24CircularBufferWriteZerosEPNS0_14CircularBufferEm = external hidden unnamed_addr constant [90 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN6tflite11tflm_signal22CircularBufferCanWriteEPKNS0_14CircularBufferE(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6tflite11tflm_signal24CircularBufferWriteZerosEPNS0_14CircularBufferEm(ptr noundef %0, i64 noundef %1) local_unnamed_addr #2 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %29, label %3

3:                                                ; preds = %2
  %4 = tail call noundef i64 @_ZN6tflite11tflm_signal22CircularBufferCanWriteEPKNS0_14CircularBufferE(ptr noundef %0)
  %.not40 = icmp ult i64 %4, %1
  br i1 %.not40, label %5, label %6

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 119, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal24CircularBufferWriteZerosEPNS0_14CircularBufferEm) #3
  unreachable

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = load i64, ptr %0, align 8, !tbaa !13
  %12 = add i64 %8, %1
  %13 = getelementptr inbounds i16, ptr %10, i64 %8
  %14 = shl i64 %1, 1
  tail call void @llvm.memset.p0.i64(ptr align 2 %13, i8 0, i64 %14, i1 false)
  %15 = icmp ult i64 %12, %11
  br i1 %15, label %16, label %19

16:                                               ; preds = %6
  %17 = getelementptr inbounds i16, ptr %10, i64 %11
  %18 = getelementptr inbounds i16, ptr %17, i64 %8
  tail call void @llvm.memset.p0.i64(ptr nonnull align 2 %18, i8 0, i64 %14, i1 false)
  br label %27

19:                                               ; preds = %6
  %20 = sub i64 %11, %8
  %21 = shl i64 %20, 1
  %22 = getelementptr inbounds i16, ptr %10, i64 %11
  %23 = getelementptr inbounds i16, ptr %22, i64 %8
  tail call void @llvm.memset.p0.i64(ptr align 2 %23, i8 0, i64 %21, i1 false)
  %24 = sub i64 %12, %11
  %.not41 = icmp eq i64 %24, 0
  br i1 %.not41, label %27, label %25

25:                                               ; preds = %19
  %26 = shl i64 %24, 1
  tail call void @llvm.memset.p0.i64(ptr align 2 %10, i8 0, i64 %26, i1 false)
  br label %27

27:                                               ; preds = %19, %25, %16
  %.0 = phi i64 [ %12, %16 ], [ %24, %25 ], [ 0, %19 ]
  store i64 %.0, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %28, align 8, !tbaa !14
  br label %29

29:                                               ; preds = %27, %2
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 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 = { 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, !7, i64 16}
!6 = !{!"_ZTSN6tflite11tflm_signal14CircularBufferE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !11, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 32}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 24}


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