; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/tiny_audio/b3ADSR.ll (ZN6b3ADSR4tickEv)

; 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.b3ADSR = type <{ ptr, i32, [4 x i8], double, double, double, double, double, double, double, i8, [7 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN6b3ADSR4tickEv(ptr noundef nonnull align 8 dereferenceable(73) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 1
  %5 = load i32, ptr %4, align 8, !tbaa !9
  switch i32 %5, label %90 [
    i32 0, label %6
    i32 1, label %26
    i32 3, label %77
  ]

6:                                                ; preds = %1
  %7 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 5
  %8 = load double, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %10 = load double, ptr %9, align 8, !tbaa !15
  %11 = fadd double %10, %8
  store double %11, ptr %9, align 8, !tbaa !15
  %12 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %13 = load double, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 4
  %15 = load double, ptr %14, align 8, !tbaa !16
  %16 = fcmp oge double %13, %15
  br i1 %16, label %17, label %25

17:                                               ; preds = %6
  %18 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 4
  %19 = load double, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  store double %19, ptr %20, align 8, !tbaa !15
  %21 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 9
  %22 = load double, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 4
  store double %22, ptr %23, align 8, !tbaa !16
  %24 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 1
  store i32 1, ptr %24, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %17, %6
  br label %90

26:                                               ; preds = %1
  %27 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %28 = load double, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 9
  %30 = load double, ptr %29, align 8, !tbaa !17
  %31 = fcmp ogt double %28, %30
  br i1 %31, label %32, label %54

32:                                               ; preds = %26
  %33 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 6
  %34 = load double, ptr %33, align 8, !tbaa !18
  %35 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %36 = load double, ptr %35, align 8, !tbaa !15
  %37 = fsub double %36, %34
  store double %37, ptr %35, align 8, !tbaa !15
  %38 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 9
  %41 = load double, ptr %40, align 8, !tbaa !17
  %42 = fcmp ole double %39, %41
  br i1 %42, label %43, label %53

43:                                               ; preds = %32
  %44 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 9
  %45 = load double, ptr %44, align 8, !tbaa !17
  %46 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  store double %45, ptr %46, align 8, !tbaa !15
  %47 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 1
  store i32 2, ptr %47, align 8, !tbaa !9
  %48 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 10
  %49 = load i8, ptr %48, align 8, !tbaa !19, !range !20, !noundef !21
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  call void @_ZN6b3ADSR6keyOffEv(ptr noundef nonnull align 8 dereferenceable(73) %3)
  br label %52

52:                                               ; preds = %51, %43
  br label %53

53:                                               ; preds = %52, %32
  br label %76

54:                                               ; preds = %26
  %55 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 6
  %56 = load double, ptr %55, align 8, !tbaa !18
  %57 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %58 = load double, ptr %57, align 8, !tbaa !15
  %59 = fadd double %58, %56
  store double %59, ptr %57, align 8, !tbaa !15
  %60 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %61 = load double, ptr %60, align 8, !tbaa !15
  %62 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 9
  %63 = load double, ptr %62, align 8, !tbaa !17
  %64 = fcmp oge double %61, %63
  br i1 %64, label %65, label %75

65:                                               ; preds = %54
  %66 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 9
  %67 = load double, ptr %66, align 8, !tbaa !17
  %68 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  store double %67, ptr %68, align 8, !tbaa !15
  %69 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 1
  store i32 2, ptr %69, align 8, !tbaa !9
  %70 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 10
  %71 = load i8, ptr %70, align 8, !tbaa !19, !range !20, !noundef !21
  %72 = trunc i8 %71 to i1
  br i1 %72, label %73, label %74

73:                                               ; preds = %65
  call void @_ZN6b3ADSR6keyOffEv(ptr noundef nonnull align 8 dereferenceable(73) %3)
  br label %74

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

75:                                               ; preds = %74, %54
  br label %76

76:                                               ; preds = %75, %53
  br label %90

77:                                               ; preds = %1
  %78 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 7
  %79 = load double, ptr %78, align 8, !tbaa !22
  %80 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %81 = load double, ptr %80, align 8, !tbaa !15
  %82 = fsub double %81, %79
  store double %82, ptr %80, align 8, !tbaa !15
  %83 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %84 = load double, ptr %83, align 8, !tbaa !15
  %85 = fcmp ole double %84, 0.000000e+00
  br i1 %85, label %86, label %89

86:                                               ; preds = %77
  %87 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  store double 0.000000e+00, ptr %87, align 8, !tbaa !15
  %88 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 1
  store i32 4, ptr %88, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %86, %77
  br label %90

90:                                               ; preds = %89, %76, %25, %1
  %91 = getelementptr inbounds %class.b3ADSR, ptr %3, i32 0, i32 3
  %92 = load double, ptr %91, align 8, !tbaa !15
  ret double %92
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6b3ADSR6keyOffEv(ptr noundef nonnull align 8 dereferenceable(73)) #1 align 2

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

!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, !11, i64 8}
!10 = !{!"_ZTS6b3ADSR", !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !13, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!10, !12, i64 32}
!15 = !{!10, !12, i64 16}
!16 = !{!10, !12, i64 24}
!17 = !{!10, !12, i64 64}
!18 = !{!10, !12, i64 40}
!19 = !{!10, !13, i64 72}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!10, !12, i64 48}


; 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: mustprogress nounwind uwtable
define dso_local noundef double @_ZN6b3ADSR4tickEv(ptr noundef nonnull align 8 dereferenceable(73) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  switch i32 %3, label %48 [
    i32 0, label %4
    i32 1, label %16
    i32 3, label %40
  ]

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load double, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load double, ptr %7, align 8, !tbaa !13
  %9 = fadd double %6, %8
  store double %9, ptr %7, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load double, ptr %10, align 8, !tbaa !14
  %12 = fcmp ult double %9, %11
  br i1 %12, label %48, label %13

13:                                               ; preds = %4
  store double %11, ptr %7, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %0, i64 64
  %15 = load double, ptr %14, align 8, !tbaa !15
  store double %15, ptr %10, align 8, !tbaa !14
  store i32 1, ptr %2, align 8, !tbaa !5
  br label %48

16:                                               ; preds = %1
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  %20 = load double, ptr %19, align 8, !tbaa !15
  %21 = fcmp ogt double %18, %20
  %22 = getelementptr inbounds i8, ptr %0, i64 40
  %23 = load double, ptr %22, align 8, !tbaa !16
  br i1 %21, label %24, label %32

24:                                               ; preds = %16
  %25 = fsub double %18, %23
  store double %25, ptr %17, align 8, !tbaa !13
  %26 = fcmp ugt double %25, %20
  br i1 %26, label %48, label %27

27:                                               ; preds = %24
  store double %20, ptr %17, align 8, !tbaa !13
  store i32 2, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 72
  %29 = load i8, ptr %28, align 8, !tbaa !17, !range !18, !noundef !19
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %31, label %48

31:                                               ; preds = %27
  tail call void @_ZN6b3ADSR6keyOffEv(ptr noundef nonnull align 8 dereferenceable(73) %0)
  br label %48

32:                                               ; preds = %16
  %33 = fadd double %18, %23
  store double %33, ptr %17, align 8, !tbaa !13
  %34 = fcmp ult double %33, %20
  br i1 %34, label %48, label %35

35:                                               ; preds = %32
  store double %20, ptr %17, align 8, !tbaa !13
  store i32 2, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %0, i64 72
  %37 = load i8, ptr %36, align 8, !tbaa !17, !range !18, !noundef !19
  %38 = trunc nuw i8 %37 to i1
  br i1 %38, label %39, label %48

39:                                               ; preds = %35
  tail call void @_ZN6b3ADSR6keyOffEv(ptr noundef nonnull align 8 dereferenceable(73) %0)
  br label %48

40:                                               ; preds = %1
  %41 = getelementptr inbounds i8, ptr %0, i64 48
  %42 = load double, ptr %41, align 8, !tbaa !20
  %43 = getelementptr inbounds i8, ptr %0, i64 16
  %44 = load double, ptr %43, align 8, !tbaa !13
  %45 = fsub double %44, %42
  store double %45, ptr %43, align 8, !tbaa !13
  %46 = fcmp ugt double %45, 0.000000e+00
  br i1 %46, label %48, label %47

47:                                               ; preds = %40
  store double 0.000000e+00, ptr %43, align 8, !tbaa !13
  store i32 4, ptr %2, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %40, %47, %27, %31, %24, %35, %39, %32, %4, %13, %1
  %49 = getelementptr inbounds i8, ptr %0, i64 16
  %50 = load double, ptr %49, align 8, !tbaa !13
  ret double %50
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6b3ADSR6keyOffEv(ptr noundef nonnull align 8 dereferenceable(73)) local_unnamed_addr #0 align 2

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

!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 8}
!6 = !{!"_ZTS6b3ADSR", !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !11, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !10, i64 32}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !10, i64 64}
!16 = !{!6, !10, i64 40}
!17 = !{!6, !11, i64 72}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!6, !10, i64 48}


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