; LLVM IR from Try/Tempest :: Engine/thirdparty/openal-soft/al/effects (chorus)

; 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.std::optional" = type { %"struct.std::_Optional_base" }
%"struct.std::_Optional_base" = type { %"struct.std::_Optional_payload" }
%"struct.std::_Optional_payload" = type { %"struct.std::_Optional_payload_base.base", [3 x i8] }
%"struct.std::_Optional_payload_base.base" = type <{ %"union.std::_Optional_payload_base<ChorusWaveform>::_Storage", i8 }>
%"union.std::_Optional_payload_base<ChorusWaveform>::_Storage" = type { i32 }
%struct.ChorusProps = type { i32, i32, float, float, float, float }

@.str = external hidden unnamed_addr constant [32 x i8], align 1
@_ZTIN2al13context_errorE = external constant ptr
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19ChorusEffectHandler9SetParamiER11ChorusPropsii(ptr noundef nonnull align 4 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"class.std::optional", align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %10, label %49 [
    i32 1, label %11
    i32 2, label %31
  ]

11:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = call i64 @_ZN12_GLOBAL__N_116WaveformFromEnumEi(i32 noundef %12) #5
  %14 = getelementptr inbounds %"class.std::optional", ptr %7, i32 0, i32 0
  %15 = getelementptr inbounds %"struct.std::_Optional_base", ptr %14, i32 0, i32 0
  store i64 %13, ptr %15, align 4
  %16 = call noundef zeroext i1 @_ZNKSt8optionalI14ChorusWaveformEcvbEv(ptr noundef nonnull align 4 dereferenceable(8) %7) #5
  br i1 %16, label %17, label %22

17:                                               ; preds = %11
  %18 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNRSt8optionalI14ChorusWaveformEdeEv(ptr noundef nonnull align 4 dereferenceable(8) %7) #5
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ChorusProps, ptr %20, i32 0, i32 0
  store i32 %19, ptr %21, align 4, !tbaa !13
  br label %30

22:                                               ; preds = %11
  %23 = call ptr @__cxa_allocate_exception(i64 48) #5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  invoke void (ptr, i32, ptr, ...) @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48) %23, i32 noundef 40963, ptr noundef @.str, i32 noundef %24)
          to label %25 unwind label %26

25:                                               ; preds = %22
  call void @__cxa_throw(ptr %23, ptr @_ZTIN2al13context_errorE, ptr @_ZN2al13context_errorD1Ev) #6
  unreachable

26:                                               ; preds = %22
  %27 = landingpad { ptr, i32 }
          cleanup
  %28 = extractvalue { ptr, i32 } %27, 0
  store ptr %28, ptr %8, align 8
  %29 = extractvalue { ptr, i32 } %27, 1
  store i32 %29, ptr %9, align 4
  call void @__cxa_free_exception(ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %58

30:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %57

31:                                               ; preds = %3
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp sge i32 %32, -180
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp sle i32 %35, 180
  br i1 %36, label %45, label %37

37:                                               ; preds = %34, %31
  %38 = call ptr @__cxa_allocate_exception(i64 48) #5
  %39 = load i32, ptr %6, align 4, !tbaa !9
  invoke void (ptr, i32, ptr, ...) @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48) %38, i32 noundef 40963, ptr noundef @.str.1, i32 noundef %39)
          to label %40 unwind label %41

40:                                               ; preds = %37
  call void @__cxa_throw(ptr %38, ptr @_ZTIN2al13context_errorE, ptr @_ZN2al13context_errorD1Ev) #6
  unreachable

41:                                               ; preds = %37
  %42 = landingpad { ptr, i32 }
          cleanup
  %43 = extractvalue { ptr, i32 } %42, 0
  store ptr %43, ptr %8, align 8
  %44 = extractvalue { ptr, i32 } %42, 1
  store i32 %44, ptr %9, align 4
  call void @__cxa_free_exception(ptr %38) #5
  br label %58

45:                                               ; preds = %34
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ChorusProps, ptr %47, i32 0, i32 1
  store i32 %46, ptr %48, align 4, !tbaa !16
  br label %57

49:                                               ; preds = %3
  %50 = call ptr @__cxa_allocate_exception(i64 48) #5
  %51 = load i32, ptr %5, align 4, !tbaa !9
  invoke void (ptr, i32, ptr, ...) @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48) %50, i32 noundef 40962, ptr noundef @.str.2, i32 noundef %51)
          to label %52 unwind label %53

52:                                               ; preds = %49
  call void @__cxa_throw(ptr %50, ptr @_ZTIN2al13context_errorE, ptr @_ZN2al13context_errorD1Ev) #6
  unreachable

53:                                               ; preds = %49
  %54 = landingpad { ptr, i32 }
          cleanup
  %55 = extractvalue { ptr, i32 } %54, 0
  store ptr %55, ptr %8, align 8
  %56 = extractvalue { ptr, i32 } %54, 1
  store i32 %56, ptr %9, align 4
  call void @__cxa_free_exception(ptr %50) #5
  br label %58

57:                                               ; preds = %45, %30
  ret void

58:                                               ; preds = %53, %41, %26
  %59 = load ptr, ptr %8, align 8
  %60 = load i32, ptr %9, align 4
  %61 = insertvalue { ptr, i32 } poison, ptr %59, 0
  %62 = insertvalue { ptr, i32 } %61, i32 %60, 1
  resume { ptr, i32 } %62
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden i64 @_ZN12_GLOBAL__N_116WaveformFromEnumEi(i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt8optionalI14ChorusWaveformEcvbEv(ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNRSt8optionalI14ChorusWaveformEdeEv(ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef, ptr noundef, ...) unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZN2al13context_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #4

declare void @__cxa_throw(ptr, ptr, ptr)

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

attributes #0 = { mustprogress 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 = { 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 = { "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 = { 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 = { nounwind }
attributes #6 = { noreturn }

!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 = !{!"_ZTS14ChorusWaveform", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS11ChorusProps", !12, i64 0, !10, i64 4, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20}
!15 = !{!"float", !7, i64 0}
!16 = !{!14, !10, i64 4}


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

%"class.std::optional" = type { %"struct.std::_Optional_base" }
%"struct.std::_Optional_base" = type { %"struct.std::_Optional_payload" }
%"struct.std::_Optional_payload" = type { %"struct.std::_Optional_payload_base.base", [3 x i8] }
%"struct.std::_Optional_payload_base.base" = type <{ %"union.std::_Optional_payload_base<ChorusWaveform>::_Storage", i8 }>
%"union.std::_Optional_payload_base<ChorusWaveform>::_Storage" = type { i32 }

@.str = external hidden unnamed_addr constant [32 x i8], align 1
@_ZTIN2al13context_errorE = external constant ptr
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19ChorusEffectHandler9SetParamiER11ChorusPropsii(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"class.std::optional", align 8
  switch i32 %1, label %25 [
    i32 1, label %5
    i32 2, label %16
  ]

5:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %6 = tail call i64 @_ZN12_GLOBAL__N_116WaveformFromEnumEi(i32 noundef %2) #5
  store i64 %6, ptr %4, align 8
  %7 = call noundef zeroext i1 @_ZNKSt8optionalI14ChorusWaveformEcvbEv(ptr noundef nonnull align 4 dereferenceable(8) %4) #5
  br i1 %7, label %8, label %11

8:                                                ; preds = %5
  %9 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNRSt8optionalI14ChorusWaveformEdeEv(ptr noundef nonnull align 4 dereferenceable(8) %4) #5
  %10 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %10, ptr %0, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  br label %30

11:                                               ; preds = %5
  %12 = call ptr @__cxa_allocate_exception(i64 48) #5
  invoke void (ptr, i32, ptr, ...) @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48) %12, i32 noundef 40963, ptr noundef nonnull @.str, i32 noundef %2)
          to label %13 unwind label %14

13:                                               ; preds = %11
  call void @__cxa_throw(ptr nonnull %12, ptr nonnull @_ZTIN2al13context_errorE, ptr nonnull @_ZN2al13context_errorD1Ev) #6
  unreachable

14:                                               ; preds = %11
  %15 = landingpad { ptr, i32 }
          cleanup
  call void @__cxa_free_exception(ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  br label %31

16:                                               ; preds = %3
  %17 = add i32 %2, 180
  %or.cond = icmp ult i32 %17, 361
  br i1 %or.cond, label %23, label %18

18:                                               ; preds = %16
  %19 = tail call ptr @__cxa_allocate_exception(i64 48) #5
  invoke void (ptr, i32, ptr, ...) @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48) %19, i32 noundef 40963, ptr noundef nonnull @.str.1, i32 noundef %2)
          to label %20 unwind label %21

20:                                               ; preds = %18
  tail call void @__cxa_throw(ptr nonnull %19, ptr nonnull @_ZTIN2al13context_errorE, ptr nonnull @_ZN2al13context_errorD1Ev) #6
  unreachable

21:                                               ; preds = %18
  %22 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %19) #5
  br label %31

23:                                               ; preds = %16
  %24 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %2, ptr %24, align 4, !tbaa !13
  br label %30

25:                                               ; preds = %3
  %26 = tail call ptr @__cxa_allocate_exception(i64 48) #5
  invoke void (ptr, i32, ptr, ...) @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48) %26, i32 noundef 40962, ptr noundef nonnull @.str.2, i32 noundef %1)
          to label %27 unwind label %28

27:                                               ; preds = %25
  tail call void @__cxa_throw(ptr nonnull %26, ptr nonnull @_ZTIN2al13context_errorE, ptr nonnull @_ZN2al13context_errorD1Ev) #6
  unreachable

28:                                               ; preds = %25
  %29 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %26) #5
  br label %31

30:                                               ; preds = %23, %8
  ret void

31:                                               ; preds = %28, %21, %14
  %.pn = phi { ptr, i32 } [ %29, %28 ], [ %22, %21 ], [ %15, %14 ]
  resume { ptr, i32 } %.pn
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden i64 @_ZN12_GLOBAL__N_116WaveformFromEnumEi(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt8optionalI14ChorusWaveformEcvbEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNRSt8optionalI14ChorusWaveformEdeEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 2

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZN2al13context_errorC1EiPKcz(ptr noundef nonnull align 8 dereferenceable(48), i32 noundef, ptr noundef, ...) unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZN2al13context_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #4

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

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

attributes #0 = { mustprogress 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 = { mustprogress 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 = { "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 = { 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 = { nounwind }
attributes #6 = { noreturn }

!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 = !{!"_ZTS14ChorusWaveform", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS11ChorusProps", !6, i64 0, !11, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !11, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass