; LLVM IR from ARM-software/Arm-2D :: examples/[template][pc][vscode]/platform/math (arm_sin_f32)

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

@sinTable_f32 = external constant [513 x float], align 16

; Function Attrs: nounwind uwtable
define dso_local float @arm_sin_f32(float noundef %0) #0 {
  %2 = alloca float, align 4
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca i16, align 2
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  store float %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %11 = load float, ptr %2, align 4, !tbaa !5
  %12 = fmul float %11, 0x3FC45F3060000000
  store float %12, ptr %5, align 4, !tbaa !5
  %13 = load float, ptr %5, align 4, !tbaa !5
  %14 = fptosi float %13 to i32
  store i32 %14, ptr %9, align 4, !tbaa !9
  %15 = load float, ptr %5, align 4, !tbaa !5
  %16 = fcmp olt float %15, 0.000000e+00
  br i1 %16, label %17, label %20

17:                                               ; preds = %1
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %9, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %17, %1
  %21 = load float, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = sitofp i32 %22 to float
  %24 = fsub float %21, %23
  store float %24, ptr %5, align 4, !tbaa !5
  %25 = load float, ptr %5, align 4, !tbaa !5
  %26 = fmul float 5.120000e+02, %25
  store float %26, ptr %10, align 4, !tbaa !5
  %27 = load float, ptr %10, align 4, !tbaa !5
  %28 = fptoui float %27 to i16
  store i16 %28, ptr %6, align 2, !tbaa !11
  %29 = load i16, ptr %6, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = icmp sge i32 %30, 512
  br i1 %31, label %32, label %35

32:                                               ; preds = %20
  store i16 0, ptr %6, align 2, !tbaa !11
  %33 = load float, ptr %10, align 4, !tbaa !5
  %34 = fsub float %33, 5.120000e+02
  store float %34, ptr %10, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %32, %20
  %36 = load float, ptr %10, align 4, !tbaa !5
  %37 = load i16, ptr %6, align 2, !tbaa !11
  %38 = uitofp i16 %37 to float
  %39 = fsub float %36, %38
  store float %39, ptr %4, align 4, !tbaa !5
  %40 = load i16, ptr %6, align 2, !tbaa !11
  %41 = zext i16 %40 to i64
  %42 = getelementptr inbounds [513 x float], ptr @sinTable_f32, i64 0, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !5
  store float %43, ptr %7, align 4, !tbaa !5
  %44 = load i16, ptr %6, align 2, !tbaa !11
  %45 = zext i16 %44 to i32
  %46 = add nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [513 x float], ptr @sinTable_f32, i64 0, i64 %47
  %49 = load float, ptr %48, align 4, !tbaa !5
  store float %49, ptr %8, align 4, !tbaa !5
  %50 = load float, ptr %4, align 4, !tbaa !5
  %51 = fsub float 1.000000e+00, %50
  %52 = load float, ptr %7, align 4, !tbaa !5
  %53 = load float, ptr %4, align 4, !tbaa !5
  %54 = load float, ptr %8, align 4, !tbaa !5
  %55 = fmul float %53, %54
  %56 = call float @llvm.fmuladd.f32(float %51, float %52, float %55)
  store float %56, ptr %3, align 4, !tbaa !5
  %57 = load float, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret float %57
}

; 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 float @llvm.fmuladd.f32(float, float, float) #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 = !{!"float", !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 = !{!"short", !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"

@sinTable_f32 = external local_unnamed_addr constant [513 x float], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local float @arm_sin_f32(float noundef %0) local_unnamed_addr #0 {
  %2 = fmul float %0, 0x3FC45F3060000000
  %3 = fptosi float %2 to i32
  %4 = fcmp olt float %2, 0.000000e+00
  %5 = sext i1 %4 to i32
  %.018 = add nsw i32 %5, %3
  %6 = sitofp i32 %.018 to float
  %7 = fsub float %2, %6
  %8 = fmul float %7, 5.120000e+02
  %9 = fptoui float %8 to i16
  %10 = icmp ugt i16 %9, 511
  %11 = fadd float %8, -5.120000e+02
  %.019 = select i1 %10, i16 0, i16 %9
  %.0 = select i1 %10, float %11, float %8
  %12 = uitofp nneg i16 %.019 to float
  %13 = fsub float %.0, %12
  %14 = zext nneg i16 %.019 to i64
  %15 = getelementptr inbounds [513 x float], ptr @sinTable_f32, i64 0, i64 %14
  %16 = load float, ptr %15, align 4, !tbaa !5
  %narrow = add nuw nsw i16 %.019, 1
  %17 = zext nneg i16 %narrow to i64
  %18 = getelementptr inbounds [513 x float], ptr @sinTable_f32, i64 0, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = fsub float 1.000000e+00, %13
  %21 = fmul float %13, %19
  %22 = tail call float @llvm.fmuladd.f32(float %20, float %16, float %21)
  ret float %22
}

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

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

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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