; 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_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm = external hidden unnamed_addr constant [102 x i8], align 1

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

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

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

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

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

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

22:                                               ; preds = %17
  br label %25

23:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 91, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm) #4
  unreachable

24:                                               ; No predecessors!
  br label %25

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

47:                                               ; preds = %25
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = getelementptr inbounds i16, ptr %48, i64 %49
  %51 = load i64, ptr %7, align 8, !tbaa !9
  %52 = getelementptr inbounds i16, ptr %50, i64 %51
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %6, align 8, !tbaa !9
  %55 = mul i64 %54, 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %52, ptr align 2 %53, i64 %55, i1 false)
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = add i64 %57, %56
  store i64 %58, ptr %7, align 8, !tbaa !9
  br label %87

59:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = sub i64 %60, %61
  store i64 %62, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = mul i64 %63, 2
  store i64 %64, ptr %12, align 8, !tbaa !9
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = getelementptr inbounds i16, ptr %65, i64 %66
  %68 = load i64, ptr %7, align 8, !tbaa !9
  %69 = getelementptr inbounds i16, ptr %67, i64 %68
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %69, ptr align 2 %70, i64 %71, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %72 = load i64, ptr %10, align 8, !tbaa !9
  %73 = load i64, ptr %9, align 8, !tbaa !9
  %74 = sub i64 %72, %73
  store i64 %74, ptr %13, align 8, !tbaa !9
  %75 = load i64, ptr %13, align 8, !tbaa !9
  %76 = icmp ugt i64 %75, 0
  br i1 %76, label %77, label %85

77:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %78 = load i64, ptr %13, align 8, !tbaa !9
  %79 = mul i64 %78, 2
  store i64 %79, ptr %14, align 8, !tbaa !9
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i64, ptr %11, align 8, !tbaa !9
  %83 = getelementptr inbounds i16, ptr %81, i64 %82
  %84 = load i64, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %80, ptr align 2 %83, i64 %84, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %85

85:                                               ; preds = %77, %59
  %86 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %86, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %87

87:                                               ; preds = %85, %47
  %88 = load i64, ptr %7, align 8, !tbaa !9
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %89, i32 0, i32 2
  store i64 %88, ptr %90, align 8, !tbaa !11
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %91, i32 0, i32 3
  store i32 0, ptr %92, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %93

93:                                               ; preds = %87, %3
  ret void
}

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm = external hidden unnamed_addr constant [102 x i8], align 1

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

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

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

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

6:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 91, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm) #3
  unreachable

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

17:                                               ; preds = %7
  %18 = getelementptr inbounds i16, ptr %11, i64 %12
  %19 = getelementptr inbounds i16, ptr %18, i64 %9
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 2 %19, ptr align 2 %1, i64 %15, i1 false)
  br label %29

20:                                               ; preds = %7
  %21 = sub i64 %12, %9
  %22 = shl i64 %21, 1
  %23 = getelementptr inbounds i16, ptr %11, i64 %12
  %24 = getelementptr inbounds i16, ptr %23, i64 %9
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 2 %24, ptr align 2 %1, i64 %22, i1 false)
  %25 = sub i64 %13, %12
  %.not46 = icmp eq i64 %25, 0
  br i1 %.not46, label %29, label %26

26:                                               ; preds = %20
  %27 = shl i64 %25, 1
  %28 = getelementptr inbounds i16, ptr %1, i64 %21
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 2 %11, ptr align 2 %28, i64 %27, i1 false)
  br label %29

29:                                               ; preds = %20, %26, %17
  %.0 = phi i64 [ %13, %17 ], [ %25, %26 ], [ 0, %20 ]
  store i64 %.0, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %30, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %29, %3
  ret void
}

; Function Attrs: mustprogress 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) #2

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass