; LLVM IR from jingweizhanghuai/Morn :: src/wave (morn_audio_volume)

; 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.MWave = type { i32, i32, [32 x ptr] }

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@__FUNCTION__.mWaveActive = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @mWaveActive(ptr noundef %0, float noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %18, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = ptrtoint ptr %15 to i64
  %17 = icmp eq i64 %16, -1
  br i1 %17, label %18, label %19

18:                                               ; preds = %14, %11
  br label %43

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MWave, ptr %20, i32 0, i32 2
  %22 = getelementptr inbounds [32 x ptr], ptr %21, i64 0, i64 0
  %23 = icmp eq ptr %22, null
  br i1 %23, label %40, label %24

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MWave, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds [32 x ptr], ptr %26, i64 0, i64 0
  %28 = ptrtoint ptr %27 to i64
  %29 = icmp eq i64 %28, -1
  br i1 %29, label %40, label %30

30:                                               ; preds = %24
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MWave, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp sle i32 %33, 0
  br i1 %34, label %40, label %35

35:                                               ; preds = %30
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.MWave, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = icmp sle i32 %38, 0
  br label %40

40:                                               ; preds = %35, %30, %24, %19
  %41 = phi i1 [ true, %30 ], [ true, %24 ], [ true, %19 ], [ %39, %35 ]
  %42 = zext i1 %41 to i32
  br label %43

43:                                               ; preds = %40, %18
  %44 = phi i32 [ 1, %18 ], [ %42, %40 ]
  store i32 %44, ptr %6, align 4, !tbaa !15
  %45 = load i32, ptr %6, align 4, !tbaa !15
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %43
  %48 = load i32, ptr %6, align 4, !tbaa !15
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %48, i32 noundef -1, ptr noundef @.str, i32 noundef 48, ptr noundef @__FUNCTION__.mWaveActive, ptr noundef @.str.1)
  br label %49

49:                                               ; preds = %47, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %50

50:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call ptr @m_PropertyRead(ptr noundef %51, ptr noundef @.str.2, ptr noundef %7, ptr noundef null)
  br label %53

53:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %54 = load i32, ptr %7, align 4, !tbaa !15
  %55 = icmp ne i32 %54, 0
  %56 = zext i1 %55 to i32
  store i32 %56, ptr %8, align 4, !tbaa !15
  %57 = load i32, ptr %8, align 4, !tbaa !15
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %53
  %60 = load i32, ptr %8, align 4, !tbaa !15
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %60, i32 noundef -1, ptr noundef @.str, i32 noundef 50, ptr noundef @__FUNCTION__.mWaveActive, ptr noundef @.str.3)
  br label %61

61:                                               ; preds = %59, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = load float, ptr %5, align 4, !tbaa !9
  %65 = fcmp olt float %64, 0.000000e+00
  br i1 %65, label %66, label %67

66:                                               ; preds = %63
  store float 0x3FA99999A0000000, ptr %5, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %66, %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !15
  br label %68

68:                                               ; preds = %90, %67
  %69 = load i32, ptr %9, align 4, !tbaa !15
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.MWave, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 8, !tbaa !11
  %73 = icmp slt i32 %69, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %68
  store i32 6, ptr %10, align 4
  br label %93

75:                                               ; preds = %68
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.MWave, ptr %76, i32 0, i32 2
  %78 = load i32, ptr %9, align 4, !tbaa !15
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [32 x ptr], ptr %77, i64 0, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.MWave, ptr %82, i32 0, i32 1
  %84 = load i32, ptr %83, align 4, !tbaa !14
  %85 = load float, ptr %5, align 4, !tbaa !9
  %86 = call i32 @WaveThresh(ptr noundef %81, i32 noundef %84, float noundef %85)
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %75
  store i32 1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %93

89:                                               ; preds = %75
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %9, align 4, !tbaa !15
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %9, align 4, !tbaa !15
  br label %68, !llvm.loop !16

93:                                               ; preds = %88, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  %94 = load i32, ptr %10, align 4
  switch i32 %94, label %96 [
    i32 6, label %95
  ]

95:                                               ; preds = %93
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %96

96:                                               ; preds = %95, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %97 = load i32, ptr %3, align 4
  ret i32 %97
}

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

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

declare ptr @m_PropertyRead(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @WaveThresh(ptr noundef, i32 noundef, float noundef) #0

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"MWave", !13, i64 0, !13, i64 4, !7, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@__FUNCTION__.mWaveActive = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @mWaveActive(ptr noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %4 [
    i64 -1, label %.critedge
    i64 0, label %.critedge
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = icmp eq ptr %5, inttoptr (i64 -1 to ptr)
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %4
  %8 = load i32, ptr %0, align 8, !tbaa !5
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %.critedge, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %.critedge

.critedge:                                        ; preds = %2, %2, %7, %4, %10
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 48, ptr noundef nonnull @__FUNCTION__.mWaveActive, ptr noundef nonnull @.str.1) #3
  br label %14

14:                                               ; preds = %.critedge, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %15 = call ptr @m_PropertyRead(ptr noundef %0, ptr noundef nonnull @.str.2, ptr noundef nonnull %3, ptr noundef null) #3
  %16 = load i32, ptr %3, align 4, !tbaa !11
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %18, label %17

17:                                               ; preds = %14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 50, ptr noundef nonnull @__FUNCTION__.mWaveActive, ptr noundef nonnull @.str.3) #3
  br label %18

18:                                               ; preds = %17, %14
  %19 = fcmp olt float %1, 0.000000e+00
  %.029 = select i1 %19, float 0x3FA99999A0000000, float %1
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i32, ptr %0, align 8, !tbaa !5
  %.not3435 = icmp sgt i32 %21, 0
  br i1 %.not3435, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 4
  br label %26

23:                                               ; preds = %26
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load i32, ptr %0, align 8, !tbaa !5
  %25 = sext i32 %24 to i64
  %.not34 = icmp slt i64 %indvars.iv.next, %25
  br i1 %.not34, label %26, label %._crit_edge.loopexit, !llvm.loop !12

26:                                               ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %27 = getelementptr inbounds [32 x ptr], ptr %20, i64 0, i64 %indvars.iv
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %22, align 4, !tbaa !10
  %30 = call i32 @WaveThresh(ptr noundef %28, i32 noundef %29, float noundef %.029)
  %.not33 = icmp ne i32 %30, 0
  br i1 %.not33, label %._crit_edge.loopexit, label %23

._crit_edge.loopexit:                             ; preds = %26, %23
  %31 = zext i1 %.not33 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %18
  %.not34.lcssa = phi i32 [ 0, %18 ], [ %31, %._crit_edge.loopexit ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i32 %.not34.lcssa
}

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #2

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

declare ptr @m_PropertyRead(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @WaveThresh(ptr noundef, i32 noundef, float noundef) local_unnamed_addr #0

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !7, i64 0}
!6 = !{!"MWave", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !8, i64 0}


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