; LLVM IR from jingweizhanghuai/Morn :: src/math (morn_math_common)

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

@morn_sin1 = external hidden global [100 x double], align 16
@morn_cos1 = external hidden global [100 x double], align 16
@morn_sin0 = external hidden global [450 x double], align 16
@morn_cos0 = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local double @mSin(double noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %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
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %14 = load double, ptr %2, align 8, !tbaa !5
  %15 = fcmp ogt double %14, 0.000000e+00
  br i1 %15, label %16, label %18

16:                                               ; preds = %1
  %17 = load double, ptr %2, align 8, !tbaa !5
  br label %21

18:                                               ; preds = %1
  %19 = load double, ptr %2, align 8, !tbaa !5
  %20 = fsub double 0.000000e+00, %19
  br label %21

21:                                               ; preds = %18, %16
  %22 = phi double [ %17, %16 ], [ %20, %18 ]
  %23 = fmul double %22, 1.000000e+02
  store double %23, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %24 = load double, ptr %3, align 8, !tbaa !5
  %25 = fadd double %24, 5.000000e-01
  %26 = fptosi double %25 to i32
  store i32 %26, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %27 = load double, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = sitofp i32 %28 to double
  %30 = fsub double %27, %29
  %31 = fmul double %30, 0x400921FB54442D18
  %32 = fdiv double %31, 1.800000e+04
  store double %32, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = add nsw i32 %33, 50
  %35 = sdiv i32 %34, 100
  store i32 %35, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = mul nsw i32 %37, 100
  %39 = sub nsw i32 %36, %38
  %40 = add nsw i32 %39, 50
  store i32 %40, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = srem i32 %41, 360
  store i32 %42, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %43 = load double, ptr %5, align 8, !tbaa !5
  %44 = load double, ptr %5, align 8, !tbaa !5
  %45 = fmul double %43, %44
  store double %45, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %46 = load double, ptr %5, align 8, !tbaa !5
  %47 = load double, ptr %8, align 8, !tbaa !5
  %48 = load double, ptr %5, align 8, !tbaa !5
  %49 = fmul double %47, %48
  %50 = fdiv double %49, 6.000000e+00
  %51 = fsub double %46, %50
  store double %51, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %52 = load double, ptr %8, align 8, !tbaa !5
  %53 = fdiv double %52, 2.000000e+00
  %54 = fsub double 1.000000e+00, %53
  %55 = load double, ptr %8, align 8, !tbaa !5
  %56 = load double, ptr %8, align 8, !tbaa !5
  %57 = fmul double %55, %56
  %58 = fdiv double %57, 2.400000e+01
  %59 = fadd double %54, %58
  store double %59, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100 x double], ptr @morn_sin1, i64 0, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !5
  %64 = load double, ptr %10, align 8, !tbaa !5
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100 x double], ptr @morn_cos1, i64 0, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !5
  %69 = load double, ptr %9, align 8, !tbaa !5
  %70 = fmul double %68, %69
  %71 = call double @llvm.fmuladd.f64(double %63, double %64, double %70)
  store double %71, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100 x double], ptr @morn_cos1, i64 0, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !5
  %76 = load double, ptr %10, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100 x double], ptr @morn_sin1, i64 0, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !5
  %81 = load double, ptr %9, align 8, !tbaa !5
  %82 = fmul double %80, %81
  %83 = fneg double %82
  %84 = call double @llvm.fmuladd.f64(double %75, double %76, double %83)
  store double %84, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [450 x double], ptr @morn_sin0, i64 0, i64 %86
  %88 = load double, ptr %87, align 8, !tbaa !5
  %89 = load double, ptr %12, align 8, !tbaa !5
  %90 = load ptr, ptr @morn_cos0, align 8, !tbaa !11
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds double, ptr %90, i64 %92
  %94 = load double, ptr %93, align 8, !tbaa !5
  %95 = load double, ptr %11, align 8, !tbaa !5
  %96 = fmul double %94, %95
  %97 = call double @llvm.fmuladd.f64(double %88, double %89, double %96)
  store double %97, ptr %13, align 8, !tbaa !5
  %98 = load double, ptr %2, align 8, !tbaa !5
  %99 = fcmp ogt double %98, 0.000000e+00
  br i1 %99, label %100, label %102

100:                                              ; preds = %21
  %101 = load double, ptr %13, align 8, !tbaa !5
  br label %105

102:                                              ; preds = %21
  %103 = load double, ptr %13, align 8, !tbaa !5
  %104 = fsub double 0.000000e+00, %103
  br label %105

105:                                              ; preds = %102, %100
  %106 = phi double [ %101, %100 ], [ %104, %102 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %106
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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

@morn_sin1 = external hidden local_unnamed_addr global [100 x double], align 16
@morn_cos1 = external hidden local_unnamed_addr global [100 x double], align 16
@morn_sin0 = external hidden local_unnamed_addr global [450 x double], align 16
@morn_cos0 = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local double @mSin(double noundef %0) local_unnamed_addr #0 {
  %2 = fcmp ogt double %0, 0.000000e+00
  %3 = tail call double @llvm.fabs.f64(double %0)
  %4 = fmul double %3, 1.000000e+02
  %5 = fadd double %4, 5.000000e-01
  %6 = fptosi double %5 to i32
  %7 = sitofp i32 %6 to double
  %8 = fsub double %4, %7
  %9 = fmul double %8, 0x400921FB54442D18
  %10 = fdiv double %9, 1.800000e+04
  %11 = add i32 %6, 50
  %12 = sdiv i32 %11, 100
  %.neg = mul nsw i32 %12, -100
  %13 = add i32 %11, %.neg
  %14 = srem i32 %12, 360
  %15 = fmul double %10, %10
  %16 = fmul double %10, %15
  %17 = fdiv double %16, 6.000000e+00
  %18 = fsub double %10, %17
  %19 = fmul double %15, 5.000000e-01
  %20 = fsub double 1.000000e+00, %19
  %21 = fmul double %15, %15
  %22 = fdiv double %21, 2.400000e+01
  %23 = fadd double %20, %22
  %24 = sext i32 %13 to i64
  %25 = getelementptr inbounds [100 x double], ptr @morn_sin1, i64 0, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds [100 x double], ptr @morn_cos1, i64 0, i64 %24
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fmul double %18, %28
  %30 = tail call double @llvm.fmuladd.f64(double %26, double %23, double %29)
  %31 = fneg double %26
  %32 = fmul double %18, %31
  %33 = tail call double @llvm.fmuladd.f64(double %28, double %23, double %32)
  %34 = sext i32 %14 to i64
  %35 = getelementptr inbounds [450 x double], ptr @morn_sin0, i64 0, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = load ptr, ptr @morn_cos0, align 8, !tbaa !9
  %38 = getelementptr inbounds double, ptr %37, i64 %34
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = fmul double %30, %39
  %41 = tail call double @llvm.fmuladd.f64(double %36, double %33, double %40)
  %42 = fsub double 0.000000e+00, %41
  %43 = select i1 %2, double %41, double %42
  ret double %43
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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