; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/DSP/Examples/ARM/arm_sin_cos_example (main)

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

@testInput_f32 = external dso_local constant [32 x float], align 16
@blockSize = external dso_local global i32, align 4
@cosOutput = external dso_local global float, align 4
@sinOutput = external dso_local global float, align 4
@cosSquareOutput = external dso_local global float, align 4
@sinSquareOutput = external dso_local global float, align 4
@testOutput = external dso_local global float, align 4
@status = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca float, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %30, %0
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr @blockSize, align 4, !tbaa !5
  %7 = icmp ult i32 %5, %6
  br i1 %7, label %8, label %33

8:                                                ; preds = %4
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds [32 x float], ptr @testInput_f32, i64 0, i64 %10
  %12 = load float, ptr %11, align 4, !tbaa !9
  %13 = call float @arm_cos_f32(float noundef %12)
  store float %13, ptr @cosOutput, align 4, !tbaa !9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [32 x float], ptr @testInput_f32, i64 0, i64 %15
  %17 = load float, ptr %16, align 4, !tbaa !9
  %18 = call float @arm_sin_f32(float noundef %17)
  store float %18, ptr @sinOutput, align 4, !tbaa !9
  call void @arm_mult_f32(ptr noundef @cosOutput, ptr noundef @cosOutput, ptr noundef @cosSquareOutput, i32 noundef 1)
  call void @arm_mult_f32(ptr noundef @sinOutput, ptr noundef @sinOutput, ptr noundef @sinSquareOutput, i32 noundef 1)
  call void @arm_add_f32(ptr noundef @cosSquareOutput, ptr noundef @sinSquareOutput, ptr noundef @testOutput, i32 noundef 1)
  %19 = load float, ptr @testOutput, align 4, !tbaa !9
  %20 = fsub float 1.000000e+00, %19
  %21 = call float @llvm.fabs.f32(float %20)
  store float %21, ptr %2, align 4, !tbaa !9
  %22 = load float, ptr %2, align 4, !tbaa !9
  %23 = fcmp ogt float %22, 0x3F1A36E2E0000000
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 -6, i32 0
  store i32 %25, ptr @status, align 4, !tbaa !5
  %26 = load i32, ptr @status, align 4, !tbaa !5
  %27 = icmp eq i32 %26, -6
  br i1 %27, label %28, label %29

28:                                               ; preds = %8
  br label %33

29:                                               ; preds = %8
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = add i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !5
  br label %4, !llvm.loop !11

33:                                               ; preds = %28, %4
  %34 = load i32, ptr @status, align 4, !tbaa !5
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  br label %37

37:                                               ; preds = %38, %36
  br label %38

38:                                               ; preds = %37
  br label %37

39:                                               ; preds = %33
  br label %40

40:                                               ; preds = %41, %39
  br label %41

41:                                               ; preds = %40
  br label %40
}

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

declare float @arm_cos_f32(float noundef) #2

declare float @arm_sin_f32(float noundef) #2

declare void @arm_mult_f32(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

declare void @arm_add_f32(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #3

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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@testInput_f32 = external dso_local local_unnamed_addr constant [32 x float], align 16
@blockSize = external dso_local local_unnamed_addr global i32, align 4
@cosOutput = external dso_local global float, align 4
@sinOutput = external dso_local global float, align 4
@cosSquareOutput = external dso_local global float, align 4
@sinSquareOutput = external dso_local global float, align 4
@testOutput = external dso_local global float, align 4
@status = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = load i32, ptr @blockSize, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.thread-pre-split_crit_edge, label %.lr.ph

.thread-pre-split_crit_edge:                      ; preds = %0
  %.pr.pre = load i32, ptr @status, align 4, !tbaa !5
  %2 = icmp eq i32 %.pr.pre, 0
  br i1 %2, label %.preheader.preheader, label %.critedge.preheader

3:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %4 = load i32, ptr @blockSize, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = icmp ult i64 %indvars.iv.next, %5
  br i1 %6, label %.lr.ph, label %.preheader.preheader, !llvm.loop !9

.preheader.preheader:                             ; preds = %3, %.thread-pre-split_crit_edge
  br label %.preheader

.lr.ph:                                           ; preds = %0, %3
  %indvars.iv = phi i64 [ %indvars.iv.next, %3 ], [ 0, %0 ]
  %7 = getelementptr inbounds [32 x float], ptr @testInput_f32, i64 0, i64 %indvars.iv
  %8 = load float, ptr %7, align 4, !tbaa !11
  %9 = tail call float @arm_cos_f32(float noundef %8) #3
  store float %9, ptr @cosOutput, align 4, !tbaa !11
  %10 = tail call float @arm_sin_f32(float noundef %8) #3
  store float %10, ptr @sinOutput, align 4, !tbaa !11
  tail call void @arm_mult_f32(ptr noundef nonnull @cosOutput, ptr noundef nonnull @cosOutput, ptr noundef nonnull @cosSquareOutput, i32 noundef 1) #3
  tail call void @arm_mult_f32(ptr noundef nonnull @sinOutput, ptr noundef nonnull @sinOutput, ptr noundef nonnull @sinSquareOutput, i32 noundef 1) #3
  tail call void @arm_add_f32(ptr noundef nonnull @cosSquareOutput, ptr noundef nonnull @sinSquareOutput, ptr noundef nonnull @testOutput, i32 noundef 1) #3
  %11 = load float, ptr @testOutput, align 4, !tbaa !11
  %12 = fsub float 1.000000e+00, %11
  %13 = tail call float @llvm.fabs.f32(float %12)
  %14 = fcmp ogt float %13, 0x3F1A36E2E0000000
  %15 = select i1 %14, i32 -6, i32 0
  store i32 %15, ptr @status, align 4, !tbaa !5
  br i1 %14, label %.critedge.preheader, label %3

.critedge.preheader:                              ; preds = %.lr.ph, %.thread-pre-split_crit_edge
  br label %.critedge

.critedge:                                        ; preds = %.critedge.preheader, %.critedge
  br label %.critedge

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  br label %.preheader
}

declare float @arm_cos_f32(float noundef) local_unnamed_addr #1

declare float @arm_sin_f32(float noundef) local_unnamed_addr #1

declare void @arm_mult_f32(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @arm_add_f32(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

attributes #0 = { noreturn 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 = { "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 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass