; LLVM IR from Lut1n/ImpGears :: src/ImpGears/Core/Math.ll (ZN3imp14TriangleSignalEdd)

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

; 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: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3imp4FracEd(double noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3imp4LerpEddd(double noundef, double noundef, double noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3imp14TriangleSignalEdd(double noundef %0, double noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store double 0x400921FAFC8B007A, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 0x401921FAFC8B007A, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load double, ptr %3, align 8, !tbaa !5
  %16 = fdiv double %15, 0x401921FAFC8B007A
  %17 = call noundef double @_ZN3imp4FracEd(double noundef %16)
  store double %17, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store double 1.000000e+00, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = load double, ptr %4, align 8, !tbaa !5
  %19 = fsub double 1.000000e+00, %18
  store double %19, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store double 0.000000e+00, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %20 = load double, ptr %4, align 8, !tbaa !5
  %21 = fdiv double %20, 2.000000e+00
  store double %21, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %22 = load double, ptr %4, align 8, !tbaa !5
  store double %22, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %23 = load double, ptr %4, align 8, !tbaa !5
  %24 = load double, ptr %9, align 8, !tbaa !5
  %25 = fdiv double %24, 2.000000e+00
  %26 = fadd double %23, %25
  store double %26, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  store double 1.000000e+00, ptr %14, align 8, !tbaa !5
  %27 = load double, ptr %7, align 8, !tbaa !5
  %28 = load double, ptr %11, align 8, !tbaa !5
  %29 = fcmp ole double %27, %28
  br i1 %29, label %30, label %39

30:                                               ; preds = %2
  %31 = load double, ptr %7, align 8, !tbaa !5
  %32 = load double, ptr %10, align 8, !tbaa !5
  %33 = fsub double %31, %32
  %34 = load double, ptr %11, align 8, !tbaa !5
  %35 = load double, ptr %10, align 8, !tbaa !5
  %36 = fsub double %34, %35
  %37 = fdiv double %33, %36
  %38 = call noundef double @_ZN3imp4LerpEddd(double noundef 0.000000e+00, double noundef 1.000000e+00, double noundef %37)
  store double %38, ptr %8, align 8, !tbaa !5
  br label %76

39:                                               ; preds = %2
  %40 = load double, ptr %7, align 8, !tbaa !5
  %41 = load double, ptr %12, align 8, !tbaa !5
  %42 = fcmp ole double %40, %41
  br i1 %42, label %43, label %52

43:                                               ; preds = %39
  %44 = load double, ptr %7, align 8, !tbaa !5
  %45 = load double, ptr %11, align 8, !tbaa !5
  %46 = fsub double %44, %45
  %47 = load double, ptr %12, align 8, !tbaa !5
  %48 = load double, ptr %11, align 8, !tbaa !5
  %49 = fsub double %47, %48
  %50 = fdiv double %46, %49
  %51 = call noundef double @_ZN3imp4LerpEddd(double noundef 1.000000e+00, double noundef 0.000000e+00, double noundef %50)
  store double %51, ptr %8, align 8, !tbaa !5
  br label %75

52:                                               ; preds = %39
  %53 = load double, ptr %7, align 8, !tbaa !5
  %54 = load double, ptr %13, align 8, !tbaa !5
  %55 = fcmp ole double %53, %54
  br i1 %55, label %56, label %65

56:                                               ; preds = %52
  %57 = load double, ptr %7, align 8, !tbaa !5
  %58 = load double, ptr %12, align 8, !tbaa !5
  %59 = fsub double %57, %58
  %60 = load double, ptr %13, align 8, !tbaa !5
  %61 = load double, ptr %12, align 8, !tbaa !5
  %62 = fsub double %60, %61
  %63 = fdiv double %59, %62
  %64 = call noundef double @_ZN3imp4LerpEddd(double noundef 0.000000e+00, double noundef -1.000000e+00, double noundef %63)
  store double %64, ptr %8, align 8, !tbaa !5
  br label %74

65:                                               ; preds = %52
  %66 = load double, ptr %7, align 8, !tbaa !5
  %67 = load double, ptr %13, align 8, !tbaa !5
  %68 = fsub double %66, %67
  %69 = load double, ptr %14, align 8, !tbaa !5
  %70 = load double, ptr %13, align 8, !tbaa !5
  %71 = fsub double %69, %70
  %72 = fdiv double %68, %71
  %73 = call noundef double @_ZN3imp4LerpEddd(double noundef -1.000000e+00, double noundef 0.000000e+00, double noundef %72)
  store double %73, ptr %8, align 8, !tbaa !5
  br label %74

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

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

76:                                               ; preds = %75, %30
  %77 = load double, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %77
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; 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
declare dso_local noundef double @_ZN3imp4FracEd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN3imp4LerpEddd(double noundef, double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN3imp14TriangleSignalEdd(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fdiv double %0, 0x401921FAFC8B007A
  %4 = tail call noundef double @_ZN3imp4FracEd(double noundef %3)
  %5 = fsub double 1.000000e+00, %1
  %6 = fmul double %1, 5.000000e-01
  %7 = fmul double %5, 5.000000e-01
  %8 = fadd double %7, %1
  %9 = fcmp ugt double %4, %6
  br i1 %9, label %13, label %10

10:                                               ; preds = %2
  %11 = fdiv double %4, %6
  %12 = tail call noundef double @_ZN3imp4LerpEddd(double noundef 0.000000e+00, double noundef 1.000000e+00, double noundef %11)
  br label %32

13:                                               ; preds = %2
  %14 = fcmp ugt double %4, %1
  br i1 %14, label %20, label %15

15:                                               ; preds = %13
  %16 = fsub double %4, %6
  %17 = fsub double %1, %6
  %18 = fdiv double %16, %17
  %19 = tail call noundef double @_ZN3imp4LerpEddd(double noundef 1.000000e+00, double noundef 0.000000e+00, double noundef %18)
  br label %32

20:                                               ; preds = %13
  %21 = fcmp ugt double %4, %8
  br i1 %21, label %27, label %22

22:                                               ; preds = %20
  %23 = fsub double %4, %1
  %24 = fsub double %8, %1
  %25 = fdiv double %23, %24
  %26 = tail call noundef double @_ZN3imp4LerpEddd(double noundef 0.000000e+00, double noundef -1.000000e+00, double noundef %25)
  br label %32

27:                                               ; preds = %20
  %28 = fsub double %4, %8
  %29 = fsub double 1.000000e+00, %8
  %30 = fdiv double %28, %29
  %31 = tail call noundef double @_ZN3imp4LerpEddd(double noundef -1.000000e+00, double noundef 0.000000e+00, double noundef %30)
  br label %32

32:                                               ; preds = %15, %27, %22, %10
  %.0 = phi double [ %12, %10 ], [ %19, %15 ], [ %26, %22 ], [ %31, %27 ]
  ret double %.0
}

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


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