; LLVM IR from Firmament-Autopilot/FMT-Firmware :: target/pixhawk/fmt-io/libc/minilibc (math)

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

@cos_off_tbl = external hidden global [4 x double], align 16
@cos_sign_tbl = external hidden global [4 x double], align 16

; 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 @cos(double noundef %0) #2 {
  %2 = alloca double, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = load double, ptr %2, align 8, !tbaa !5
  %7 = fmul double %6, 0x3FE45F306DC9C883
  %8 = fptosi double %7 to i32
  store i32 %8, ptr %3, align 4, !tbaa !9
  %9 = load double, ptr %2, align 8, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = sitofp i32 %10 to double
  %12 = fneg double %11
  %13 = call double @llvm.fmuladd.f64(double %12, double 0x3FF921FB54442D18, double %9)
  store double %13, ptr %2, align 8, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !9
  %15 = and i32 %14, 3
  store i32 %15, ptr %3, align 4, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [4 x double], ptr @cos_off_tbl, i64 0, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = load double, ptr %2, align 8, !tbaa !5
  %21 = fadd double %20, %19
  store double %21, ptr %2, align 8, !tbaa !5
  %22 = load double, ptr %2, align 8, !tbaa !5
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = fmul double %22, %23
  %25 = fneg double %24
  store double %25, ptr %4, align 8, !tbaa !5
  store double 0.000000e+00, ptr %5, align 8, !tbaa !5
  %26 = load double, ptr %5, align 8, !tbaa !5
  %27 = fadd double %26, 0x3CA6827863B97D97
  store double %27, ptr %5, align 8, !tbaa !5
  %28 = load double, ptr %4, align 8, !tbaa !5
  %29 = load double, ptr %5, align 8, !tbaa !5
  %30 = fmul double %29, %28
  store double %30, ptr %5, align 8, !tbaa !5
  %31 = load double, ptr %5, align 8, !tbaa !5
  %32 = fadd double %31, 0x3D2AE7F3E733B81F
  store double %32, ptr %5, align 8, !tbaa !5
  %33 = load double, ptr %4, align 8, !tbaa !5
  %34 = load double, ptr %5, align 8, !tbaa !5
  %35 = fmul double %34, %33
  store double %35, ptr %5, align 8, !tbaa !5
  %36 = load double, ptr %5, align 8, !tbaa !5
  %37 = fadd double %36, 0x3DA93974A8C07C9D
  store double %37, ptr %5, align 8, !tbaa !5
  %38 = load double, ptr %4, align 8, !tbaa !5
  %39 = load double, ptr %5, align 8, !tbaa !5
  %40 = fmul double %39, %38
  store double %40, ptr %5, align 8, !tbaa !5
  %41 = load double, ptr %5, align 8, !tbaa !5
  %42 = fadd double %41, 0x3E21EED8EFF8D898
  store double %42, ptr %5, align 8, !tbaa !5
  %43 = load double, ptr %4, align 8, !tbaa !5
  %44 = load double, ptr %5, align 8, !tbaa !5
  %45 = fmul double %44, %43
  store double %45, ptr %5, align 8, !tbaa !5
  %46 = load double, ptr %5, align 8, !tbaa !5
  %47 = fadd double %46, 0x3E927E4FB7789F5C
  store double %47, ptr %5, align 8, !tbaa !5
  %48 = load double, ptr %4, align 8, !tbaa !5
  %49 = load double, ptr %5, align 8, !tbaa !5
  %50 = fmul double %49, %48
  store double %50, ptr %5, align 8, !tbaa !5
  %51 = load double, ptr %5, align 8, !tbaa !5
  %52 = fadd double %51, 0x3EFA01A01A01A01A
  store double %52, ptr %5, align 8, !tbaa !5
  %53 = load double, ptr %4, align 8, !tbaa !5
  %54 = load double, ptr %5, align 8, !tbaa !5
  %55 = fmul double %54, %53
  store double %55, ptr %5, align 8, !tbaa !5
  %56 = load double, ptr %5, align 8, !tbaa !5
  %57 = fadd double %56, 0x3F56C16C16C16C17
  store double %57, ptr %5, align 8, !tbaa !5
  %58 = load double, ptr %4, align 8, !tbaa !5
  %59 = load double, ptr %5, align 8, !tbaa !5
  %60 = fmul double %59, %58
  store double %60, ptr %5, align 8, !tbaa !5
  %61 = load double, ptr %5, align 8, !tbaa !5
  %62 = fadd double %61, 0x3FA5555555555555
  store double %62, ptr %5, align 8, !tbaa !5
  %63 = load double, ptr %4, align 8, !tbaa !5
  %64 = load double, ptr %5, align 8, !tbaa !5
  %65 = fmul double %64, %63
  store double %65, ptr %5, align 8, !tbaa !5
  %66 = load double, ptr %5, align 8, !tbaa !5
  %67 = fadd double %66, 5.000000e-01
  store double %67, ptr %5, align 8, !tbaa !5
  %68 = load double, ptr %4, align 8, !tbaa !5
  %69 = load double, ptr %5, align 8, !tbaa !5
  %70 = fmul double %69, %68
  store double %70, ptr %5, align 8, !tbaa !5
  %71 = load double, ptr %5, align 8, !tbaa !5
  %72 = fadd double %71, 1.000000e+00
  store double %72, ptr %5, align 8, !tbaa !5
  %73 = load i32, ptr %3, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [4 x double], ptr @cos_sign_tbl, i64 0, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !5
  %77 = load double, ptr %5, align 8, !tbaa !5
  %78 = fmul double %77, %76
  store double %78, ptr %5, align 8, !tbaa !5
  %79 = load double, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret double %79
}

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}


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

@cos_off_tbl = external hidden local_unnamed_addr global [4 x double], align 16
@cos_sign_tbl = external hidden local_unnamed_addr global [4 x double], align 16

; 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, argmem: none, inaccessiblemem: none) uwtable
define dso_local double @cos(double noundef %0) local_unnamed_addr #1 {
  %2 = fmul double %0, 0x3FE45F306DC9C883
  %3 = fptosi double %2 to i32
  %4 = sitofp i32 %3 to double
  %5 = fneg double %4
  %6 = tail call double @llvm.fmuladd.f64(double %5, double 0x3FF921FB54442D18, double %0)
  %7 = and i32 %3, 3
  %8 = zext nneg i32 %7 to i64
  %9 = getelementptr inbounds [4 x double], ptr @cos_off_tbl, i64 0, i64 %8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = fadd double %6, %10
  %12 = fneg double %11
  %13 = fmul double %11, %12
  %14 = fmul double %13, 0x3CA6827863B97D97
  %15 = fadd double %14, 0x3D2AE7F3E733B81F
  %16 = fmul double %13, %15
  %17 = fadd double %16, 0x3DA93974A8C07C9D
  %18 = fmul double %13, %17
  %19 = fadd double %18, 0x3E21EED8EFF8D898
  %20 = fmul double %13, %19
  %21 = fadd double %20, 0x3E927E4FB7789F5C
  %22 = fmul double %13, %21
  %23 = fadd double %22, 0x3EFA01A01A01A01A
  %24 = fmul double %13, %23
  %25 = fadd double %24, 0x3F56C16C16C16C17
  %26 = fmul double %13, %25
  %27 = fadd double %26, 0x3FA5555555555555
  %28 = fmul double %13, %27
  %29 = fadd double %28, 5.000000e-01
  %30 = fmul double %13, %29
  %31 = fadd double %30, 1.000000e+00
  %32 = getelementptr inbounds [4 x double], ptr @cos_sign_tbl, i64 0, i64 %8
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fmul double %33, %31
  ret double %34
}

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

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


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