; LLVM IR from modlfo/AudioEngine :: AudioEngine/JuceLibraryCode (juce_audio_basics)

; 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.juce::AudioChannelSet" = type { %"class.juce::BigInteger" }
%"class.juce::BigInteger" = type <{ %"class.juce::HeapBlock.9", [4 x i32], i64, i32, i8, [3 x i8] }>
%"class.juce::HeapBlock.9" = type { ptr }

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

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

; Function Attrs: nounwind
declare noundef i32 @_ZNK4juce10BigInteger14findNextSetBitEi(ptr noundef nonnull align 8 dereferenceable(37), i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK4juce15AudioChannelSet22getChannelIndexForTypeENS0_11ChannelTypeE(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = getelementptr inbounds %"class.juce::AudioChannelSet", ptr %9, i32 0, i32 0
  %11 = call noundef i32 @_ZNK4juce10BigInteger14findNextSetBitEi(ptr noundef nonnull align 8 dereferenceable(37) %10, i32 noundef 0) #3
  store i32 %11, ptr %7, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %25, %2
  %13 = load i32, ptr %7, align 4, !tbaa !11
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %8, align 4
  br label %30

16:                                               ; preds = %12
  %17 = load i32, ptr %7, align 4, !tbaa !11
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp eq i32 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %21, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %30

22:                                               ; preds = %16
  %23 = load i32, ptr %6, align 4, !tbaa !11
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %6, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %22
  %26 = getelementptr inbounds %"class.juce::AudioChannelSet", ptr %9, i32 0, i32 0
  %27 = load i32, ptr %7, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  %29 = call noundef i32 @_ZNK4juce10BigInteger14findNextSetBitEi(ptr noundef nonnull align 8 dereferenceable(37) %26, i32 noundef %28) #3
  store i32 %29, ptr %7, align 4, !tbaa !11
  br label %12, !llvm.loop !13

30:                                               ; preds = %20, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %31 = load i32, ptr %8, align 4
  switch i32 %31, label %33 [
    i32 2, label %32
  ]

32:                                               ; preds = %30
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %33

33:                                               ; preds = %32, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %34 = load i32, ptr %3, align 4
  ret i32 %34
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"_ZTSN4juce15AudioChannelSet11ChannelTypeE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind
declare noundef i32 @_ZNK4juce10BigInteger14findNextSetBitEi(ptr noundef nonnull align 8 dereferenceable(37), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK4juce15AudioChannelSet22getChannelIndexForTypeENS0_11ChannelTypeE(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i32 @_ZNK4juce10BigInteger14findNextSetBitEi(ptr noundef nonnull align 8 dereferenceable(37) %0, i32 noundef 0) #2
  %4 = icmp slt i32 %3, 0
  %5 = icmp eq i32 %3, %1
  %or.cond11 = or i1 %4, %5
  br i1 %or.cond11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.0813 = phi i32 [ %8, %.lr.ph ], [ %3, %2 ]
  %.0912 = phi i32 [ %6, %.lr.ph ], [ 0, %2 ]
  %6 = add nuw nsw i32 %.0912, 1
  %7 = add nuw nsw i32 %.0813, 1
  %8 = tail call noundef i32 @_ZNK4juce10BigInteger14findNextSetBitEi(ptr noundef nonnull align 8 dereferenceable(37) %0, i32 noundef %7) #2
  %9 = icmp slt i32 %8, 0
  %10 = icmp eq i32 %8, %1
  %or.cond = or i1 %9, %10
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.09.lcssa = phi i32 [ 0, %2 ], [ %6, %.lr.ph ]
  %.lcssa = phi i1 [ %4, %2 ], [ %9, %.lr.ph ]
  %spec.select = select i1 %.lcssa, i32 -1, i32 %.09.lcssa
  ret i32 %spec.select
}

attributes #0 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass