; 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: 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

; Function Attrs: nounwind uwtable
define dso_local double @mCos(double noundef %0) #2 {
  %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 ptr, ptr @morn_cos0, align 8, !tbaa !11
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds double, ptr %85, i64 %87
  %89 = load double, ptr %88, align 8, !tbaa !5
  %90 = load double, ptr %12, align 8, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [450 x double], ptr @morn_sin0, i64 0, 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 = fneg double %96
  %98 = call double @llvm.fmuladd.f64(double %89, double %90, double %97)
  store double %98, ptr %13, align 8, !tbaa !5
  %99 = load double, ptr %13, align 8, !tbaa !5
  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 %99
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #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