; 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.5 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal20CircularBufferExtendEPNS0_14CircularBufferEmi = external hidden unnamed_addr constant [95 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 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_signal23CircularBufferAvailableEPKNS0_14CircularBufferE(ptr noundef) #2

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

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

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

15:                                               ; preds = %3
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = icmp ugt i64 %16, 0
  br i1 %17, label %18, label %114

18:                                               ; preds = %15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call noundef i64 @_ZN6tflite11tflm_signal22CircularBufferCanWriteEPKNS0_14CircularBufferE(ptr noundef %19)
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = mul i64 %21, %23
  %25 = icmp uge i64 %20, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %18
  br label %29

27:                                               ; preds = %18
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 160, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal20CircularBufferExtendEPNS0_14CircularBufferEmi) #3
  unreachable

28:                                               ; No predecessors!
  br label %29

29:                                               ; preds = %28, %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call noundef i64 @_ZN6tflite11tflm_signal23CircularBufferAvailableEPKNS0_14CircularBufferE(ptr noundef %30)
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = icmp uge i64 %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  br label %37

35:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 161, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal20CircularBufferExtendEPNS0_14CircularBufferEmi) #3
  unreachable

36:                                               ; No predecessors!
  br label %37

37:                                               ; preds = %36, %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !13
  store i64 %40, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %42, i32 0, i32 2
  %44 = load i64, ptr %43, align 8, !tbaa !15
  %45 = icmp ugt i64 %41, %44
  br i1 %45, label %46, label %54

46:                                               ; preds = %37
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %47, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !15
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = add i64 %49, %50
  %52 = load i64, ptr %5, align 8, !tbaa !9
  %53 = sub i64 %51, %52
  br label %60

54:                                               ; preds = %37
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %55, i32 0, i32 2
  %57 = load i64, ptr %56, align 8, !tbaa !15
  %58 = load i64, ptr %5, align 8, !tbaa !9
  %59 = sub i64 %57, %58
  br label %60

60:                                               ; preds = %54, %46
  %61 = phi i64 [ %53, %46 ], [ %59, %54 ]
  store i64 %61, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = load i64, ptr %5, align 8, !tbaa !9
  %64 = add i64 %62, %63
  store i64 %64, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = icmp ule i64 %65, %66
  br i1 %67, label %68, label %85

68:                                               ; preds = %60
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %81, %68
  %70 = load i32, ptr %10, align 4, !tbaa !11
  %71 = load i32, ptr %6, align 4, !tbaa !11
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %73, label %84

73:                                               ; preds = %69
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %75, i32 0, i32 5
  %77 = load ptr, ptr %76, align 8, !tbaa !16
  %78 = load i64, ptr %8, align 8, !tbaa !9
  %79 = getelementptr inbounds i16, ptr %77, i64 %78
  %80 = load i64, ptr %5, align 8, !tbaa !9
  call void @_ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm(ptr noundef %74, ptr noundef %79, i64 noundef %80)
  br label %81

81:                                               ; preds = %73
  %82 = load i32, ptr %10, align 4, !tbaa !11
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %10, align 4, !tbaa !11
  br label %69, !llvm.loop !17

84:                                               ; preds = %69
  br label %113

85:                                               ; preds = %60
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %86

86:                                               ; preds = %109, %85
  %87 = load i32, ptr %10, align 4, !tbaa !11
  %88 = load i32, ptr %6, align 4, !tbaa !11
  %89 = icmp slt i32 %87, %88
  br i1 %89, label %90, label %112

90:                                               ; preds = %86
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %91 = load i64, ptr %7, align 8, !tbaa !9
  %92 = load i64, ptr %8, align 8, !tbaa !9
  %93 = sub i64 %91, %92
  store i64 %93, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %94 = load i64, ptr %5, align 8, !tbaa !9
  %95 = load i64, ptr %11, align 8, !tbaa !9
  %96 = sub i64 %94, %95
  store i64 %96, ptr %12, align 8, !tbaa !9
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %98, i32 0, i32 5
  %100 = load ptr, ptr %99, align 8, !tbaa !16
  %101 = load i64, ptr %8, align 8, !tbaa !9
  %102 = getelementptr inbounds i16, ptr %100, i64 %101
  %103 = load i64, ptr %11, align 8, !tbaa !9
  call void @_ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm(ptr noundef %97, ptr noundef %102, i64 noundef %103)
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %105, i32 0, i32 5
  %107 = load ptr, ptr %106, align 8, !tbaa !16
  %108 = load i64, ptr %12, align 8, !tbaa !9
  call void @_ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm(ptr noundef %104, ptr noundef %107, i64 noundef %108)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %109

109:                                              ; preds = %90
  %110 = load i32, ptr %10, align 4, !tbaa !11
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %10, align 4, !tbaa !11
  br label %86, !llvm.loop !19

112:                                              ; preds = %86
  br label %113

113:                                              ; preds = %112, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %114

114:                                              ; preds = %113, %15, %3
  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 = { 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 = { noreturn nounwind }
attributes #4 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSN6tflite11tflm_signal14CircularBufferE", !10, i64 0, !10, i64 8, !10, i64 16, !12, i64 24, !12, i64 28, !6, i64 32}
!15 = !{!14, !10, i64 16}
!16 = !{!14, !6, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !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"

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal20CircularBufferExtendEPNS0_14CircularBufferEmi = external hidden unnamed_addr constant [95 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 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
declare dso_local noundef i64 @_ZN6tflite11tflm_signal22CircularBufferCanWriteEPKNS0_14CircularBufferE(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6tflite11tflm_signal20CircularBufferExtendEPNS0_14CircularBufferEmi(ptr noundef %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = icmp sgt i32 %2, 0
  %5 = icmp ne i64 %1, 0
  %or.cond = and i1 %5, %4
  br i1 %or.cond, label %6, label %.loopexit

6:                                                ; preds = %3
  %7 = tail call noundef i64 @_ZN6tflite11tflm_signal22CircularBufferCanWriteEPKNS0_14CircularBufferE(ptr noundef %0)
  %8 = zext nneg i32 %2 to i64
  %9 = mul i64 %8, %1
  %.not = icmp ult i64 %7, %9
  br i1 %.not, label %10, label %11

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

11:                                               ; preds = %6
  %12 = tail call noundef i64 @_ZN6tflite11tflm_signal23CircularBufferAvailableEPKNS0_14CircularBufferE(ptr noundef %0)
  %.not45 = icmp ult i64 %12, %1
  br i1 %.not45, label %13, label %14

13:                                               ; preds = %11
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 161, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal20CircularBufferExtendEPNS0_14CircularBufferEmi) #2
  unreachable

14:                                               ; preds = %11
  %15 = load i64, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !12
  %18 = icmp ult i64 %17, %1
  %19 = select i1 %18, i64 %15, i64 0
  %.pn = add i64 %19, %17
  %20 = sub i64 %.pn, %1
  %.not46 = icmp ugt i64 %.pn, %15
  br i1 %.not46, label %.lr.ph51, label %.lr.ph

.lr.ph:                                           ; preds = %14
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  br label %25

.lr.ph51:                                         ; preds = %14
  %22 = sub i64 %15, %20
  %23 = sub i64 %1, %22
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  br label %29

25:                                               ; preds = %.lr.ph, %25
  %.049 = phi i32 [ 0, %.lr.ph ], [ %28, %25 ]
  %26 = load ptr, ptr %21, align 8, !tbaa !13
  %27 = getelementptr inbounds i16, ptr %26, i64 %20
  tail call void @_ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm(ptr noundef nonnull %0, ptr noundef %27, i64 noundef %1)
  %28 = add nuw nsw i32 %.049, 1
  %exitcond.not = icmp eq i32 %28, %2
  br i1 %exitcond.not, label %.loopexit, label %25, !llvm.loop !14

29:                                               ; preds = %.lr.ph51, %29
  %.150 = phi i32 [ 0, %.lr.ph51 ], [ %33, %29 ]
  %30 = load ptr, ptr %24, align 8, !tbaa !13
  %31 = getelementptr inbounds i16, ptr %30, i64 %20
  tail call void @_ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm(ptr noundef nonnull %0, ptr noundef %31, i64 noundef %22)
  %32 = load ptr, ptr %24, align 8, !tbaa !13
  tail call void @_ZN6tflite11tflm_signal19CircularBufferWriteEPNS0_14CircularBufferEPKsm(ptr noundef nonnull %0, ptr noundef %32, i64 noundef %23)
  %33 = add nuw nsw i32 %.150, 1
  %exitcond53.not = icmp eq i32 %33, %2
  br i1 %exitcond53.not, label %.loopexit, label %29, !llvm.loop !16

.loopexit:                                        ; preds = %25, %29, %3
  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 0}
!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 16}
!13 = !{!6, !11, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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