; 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.12 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi = external hidden unnamed_addr constant [82 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [23 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
define dso_local void @_ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %7, label %41

7:                                                ; preds = %2
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = sub nsw i32 0, %8
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = trunc i64 %12 to i32
  %14 = icmp sle i32 %9, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %7
  br label %18

16:                                               ; preds = %7
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.1, i32 noundef 274, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi) #2
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !14
  %22 = trunc i64 %21 to i32
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = sub nsw i32 0, %23
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %26, label %34

26:                                               ; preds = %18
  %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 !11
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = add i64 %32, %29
  store i64 %33, ptr %31, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %26, %18
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !14
  %40 = add i64 %39, %36
  store i64 %40, ptr %38, align 8, !tbaa !14
  br label %74

41:                                               ; preds = %2
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %43, i32 0, i32 0
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = trunc i64 %45 to i32
  %47 = icmp sle i32 %42, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %41
  br label %51

49:                                               ; preds = %41
  call void @__assert_fail(ptr noundef @.str.13, ptr noundef @.str.1, i32 noundef 281, ptr noundef @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi) #2
  unreachable

50:                                               ; No predecessors!
  br label %51

51:                                               ; preds = %50, %48
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !14
  %57 = add i64 %56, %53
  store i64 %57, ptr %55, align 8, !tbaa !14
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 8, !tbaa !14
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %61, i32 0, i32 0
  %63 = load i64, ptr %62, align 8, !tbaa !11
  %64 = icmp uge i64 %60, %63
  br i1 %64, label %65, label %73

65:                                               ; preds = %51
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %66, i32 0, i32 0
  %68 = load i64, ptr %67, align 8, !tbaa !11
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.tflite::tflm_signal::CircularBuffer", ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !14
  %72 = sub i64 %71, %68
  store i64 %72, ptr %70, align 8, !tbaa !14
  br label %73

73:                                               ; preds = %65, %51
  br label %74

74:                                               ; preds = %73, %34
  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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN6tflite11tflm_signal14CircularBufferE", !13, i64 0, !13, i64 8, !13, i64 16, !10, i64 24, !10, i64 28, !6, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}


; 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.12 = external hidden unnamed_addr constant [24 x i8], align 1
@__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi = external hidden unnamed_addr constant [82 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [23 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
define dso_local void @_ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp slt i32 %1, 0
  br i1 %3, label %4, label %17

4:                                                ; preds = %2
  %5 = sub nsw i32 0, %1
  %6 = load i64, ptr %0, align 8, !tbaa !5
  %7 = trunc i64 %6 to i32
  %.not20 = icmp sgt i32 %5, %7
  br i1 %.not20, label %8, label %9

8:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.1, i32 noundef 274, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi) #2
  unreachable

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = trunc i64 %11 to i32
  %13 = icmp slt i32 %12, %5
  %14 = select i1 %13, i64 %6, i64 0
  %spec.select = add i64 %11, %14
  %15 = sext i32 %1 to i64
  %16 = add i64 %spec.select, %15
  store i64 %16, ptr %10, align 8, !tbaa !12
  br label %28

17:                                               ; preds = %2
  %18 = load i64, ptr %0, align 8, !tbaa !5
  %19 = trunc i64 %18 to i32
  %.not = icmp slt i32 %19, %1
  br i1 %.not, label %20, label %21

20:                                               ; preds = %17
  tail call void @__assert_fail(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.1, i32 noundef 281, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6tflite11tflm_signal19CircularBufferShiftEPNS0_14CircularBufferEi) #2
  unreachable

21:                                               ; preds = %17
  %22 = zext nneg i32 %1 to i64
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load i64, ptr %23, align 8, !tbaa !12
  %25 = add i64 %24, %22
  store i64 %25, ptr %23, align 8, !tbaa !12
  %.not19 = icmp ult i64 %25, %18
  br i1 %.not19, label %28, label %26

26:                                               ; preds = %21
  %27 = sub i64 %25, %18
  store i64 %27, ptr %23, align 8, !tbaa !12
  br label %28

28:                                               ; preds = %21, %26, %9
  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 8}


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