; LLVM IR from Ultrawipf/OpenFFBoard :: Firmware/FFBoard/Src/ringbufferwrapper.ll (ZN17RingBufferWrapperC2EPhj)

; 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"

%class.RingBufferWrapper = type <{ ptr, %struct.RingBuffer, i8, [7 x i8] }>
%struct.RingBuffer = type { i64, i64, i64, ptr }

@_ZTV17RingBufferWrapper = external dso_local unnamed_addr constant { [4 x ptr] }, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN17RingBufferWrapperC2EPhj(ptr noundef nonnull align 8 dereferenceable(41) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV17RingBufferWrapper, i32 0, i32 0, i32 2), ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds %class.RingBufferWrapper, ptr %7, i32 0, i32 1
  %9 = getelementptr inbounds %class.RingBufferWrapper, ptr %7, i32 0, i32 2
  store i8 0, ptr %9, align 8, !tbaa !13
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = zext i32 %10 to i64
  %12 = invoke noundef i32 @_ZL13isMultipleTwom(i64 noundef %11)
          to label %13 unwind label %40

13:                                               ; preds = %3
  %14 = icmp ne i32 %12, 0
  br i1 %14, label %17, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds %class.RingBufferWrapper, ptr %7, i32 0, i32 2
  store i8 0, ptr %16, align 8, !tbaa !13
  br label %32

17:                                               ; preds = %13
  %18 = getelementptr inbounds %class.RingBufferWrapper, ptr %7, i32 0, i32 1
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = invoke i32 @ringBufferInit(ptr noundef %18, ptr noundef %19, i64 noundef %21)
          to label %23 unwind label %40

23:                                               ; preds = %17
  %24 = icmp ne i32 %22, 0
  %25 = getelementptr inbounds %class.RingBufferWrapper, ptr %7, i32 0, i32 2
  %26 = zext i1 %24 to i8
  store i8 %26, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds %class.RingBufferWrapper, ptr %7, i32 0, i32 2
  %28 = load i8, ptr %27, align 8, !tbaa !13, !range !18, !noundef !19
  %29 = trunc i8 %28 to i1
  br i1 %29, label %31, label %30

30:                                               ; preds = %23
  br label %32

31:                                               ; preds = %23
  br label %39

32:                                               ; preds = %30, %15
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = icmp eq ptr %33, null
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  call void @_ZdaPv(ptr noundef %33) #5
  br label %36

36:                                               ; preds = %35, %32
  %37 = getelementptr inbounds %class.RingBufferWrapper, ptr %7, i32 0, i32 1
  %38 = getelementptr inbounds %struct.RingBuffer, ptr %37, i32 0, i32 3
  store ptr null, ptr %38, align 8, !tbaa !20
  br label %39

39:                                               ; preds = %36, %31
  ret void

40:                                               ; preds = %17, %3
  %41 = landingpad { ptr, i32 }
          catch ptr null
  %42 = extractvalue { ptr, i32 } %41, 0
  call void @__clang_call_terminate(ptr %42) #6
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13isMultipleTwom(i64 noundef) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

declare i32 @ringBufferInit(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #4

attributes #0 = { 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 #1 = { inlinehint 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 = { noinline noreturn nounwind uwtable "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 = { "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 = { nobuiltin 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 #5 = { builtin nounwind }
attributes #6 = { 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !17, i64 40}
!14 = !{!"_ZTS17RingBufferWrapper", !15, i64 8, !17, i64 40}
!15 = !{!"_ZTS10RingBuffer", !16, i64 0, !16, i64 8, !16, i64 16, !6, i64 24}
!16 = !{!"long", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!14, !6, i64 32}


; 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"

@_ZTV17RingBufferWrapper = external dso_local unnamed_addr constant { [4 x ptr] }, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN17RingBufferWrapperC2EPhj(ptr noundef nonnull align 8 dereferenceable(41) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  store ptr getelementptr inbounds inrange(-16, 16) (i8, ptr @_ZTV17RingBufferWrapper, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 0, ptr %4, align 8, !tbaa !8
  %5 = zext i32 %2 to i64
  %6 = tail call noundef i32 @_ZL13isMultipleTwom(i64 noundef %5)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %8

7:                                                ; preds = %3
  store i8 0, ptr %4, align 8, !tbaa !8
  br label %14

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = invoke i32 @ringBufferInit(ptr noundef nonnull %9, ptr noundef %1, i64 noundef %5)
          to label %11 unwind label %20

11:                                               ; preds = %8
  %12 = icmp ne i32 %10, 0
  %13 = zext i1 %12 to i8
  store i8 %13, ptr %4, align 8, !tbaa !8
  br i1 %12, label %19, label %14

14:                                               ; preds = %11, %7
  %15 = icmp eq ptr %1, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %14
  tail call void @_ZdaPv(ptr noundef nonnull %1) #5
  br label %17

17:                                               ; preds = %16, %14
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr null, ptr %18, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %11, %17
  ret void

20:                                               ; preds = %8
  %21 = landingpad { ptr, i32 }
          catch ptr null
  %22 = extractvalue { ptr, i32 } %21, 0
  tail call void @__clang_call_terminate(ptr %22) #6
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL13isMultipleTwom(i64 noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #2

declare i32 @ringBufferInit(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #4

attributes #0 = { 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 #1 = { inlinehint 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 = { noinline noreturn nounwind uwtable "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 = { "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 = { nobuiltin 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 #5 = { builtin nounwind }
attributes #6 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !14, i64 40}
!9 = !{!"_ZTS17RingBufferWrapper", !10, i64 8, !14, i64 40}
!10 = !{!"_ZTS10RingBuffer", !11, i64 0, !11, i64 8, !11, i64 16, !13, i64 24}
!11 = !{!"long", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"any pointer", !12, i64 0}
!14 = !{!"bool", !12, i64 0}
!15 = !{!9, !13, i64 32}


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