; 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.10 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal21CircularBufferDiscardEPNS0_14CircularBufferEm = external hidden unnamed_addr constant [87 x i8], align 1

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

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

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

7:                                                ; preds = %2
  br label %10

8:                                                ; preds = %2
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.1, i32 noundef 261, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal21CircularBufferDiscardEPNS0_14CircularBufferEm) #2
  unreachable

9:                                                ; No predecessors!
  br label %10

10:                                               ; preds = %9, %7
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call noundef i64 @_ZN6tflite11tflm_signal23CircularBufferAvailableEPKNS0_14CircularBufferE(ptr noundef %11)
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp uge i64 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  br label %18

16:                                               ; preds = %10
  call void @__assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i32 noundef 262, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal21CircularBufferDiscardEPNS0_14CircularBufferEm) #2
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = add i64 %22, %19
  store i64 %23, ptr %21, align 8, !tbaa !11
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %24, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !14
  %30 = icmp uge i64 %26, %29
  br i1 %30, label %31, label %39

31:                                               ; preds = %18
  %32 = load ptr, ptr %3, 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 !14
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = sub i64 %37, %34
  store i64 %38, ptr %36, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %31, %18
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !15
  %46 = icmp eq i64 %42, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %39
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %48, i32 0, i32 3
  store i32 1, ptr %49, align 8, !tbaa !16
  br label %50

50:                                               ; preds = %47, %39
  ret void
}

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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!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, !10, i64 0}
!15 = !{!12, !10, i64 16}
!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.10 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal21CircularBufferDiscardEPNS0_14CircularBufferEm = external hidden unnamed_addr constant [87 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_signal23CircularBufferAvailableEPKNS0_14CircularBufferE(ptr noundef) local_unnamed_addr #1

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

3:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.1, i32 noundef 261, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal21CircularBufferDiscardEPNS0_14CircularBufferEm) #2
  unreachable

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

6:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i32 noundef 262, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal21CircularBufferDiscardEPNS0_14CircularBufferEm) #2
  unreachable

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = add i64 %9, %1
  store i64 %10, ptr %8, align 8, !tbaa !5
  %11 = load i64, ptr %0, align 8, !tbaa !12
  %.not14 = icmp ult i64 %10, %11
  br i1 %.not14, label %14, label %12

12:                                               ; preds = %7
  %13 = sub i64 %10, %11
  store i64 %13, ptr %8, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %12, %7
  %15 = phi i64 [ %13, %12 ], [ %10, %7 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = icmp eq i64 %15, %17
  br i1 %18, label %19, label %21

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 1, ptr %20, align 8, !tbaa !14
  br label %21

21:                                               ; preds = %19, %14
  ret void
}

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 = { 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 8}
!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, !7, i64 0}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !10, i64 24}


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