; LLVM IR from BigdogManLuo/DSPLibrary :: Test (PLLTest)

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

%struct.PID = type { float, float, float, float, float, float, float }
%struct.ButterQueue = type { [3 x float], i32, float, float }

@pidTheta = external dso_local global %struct.PID, align 4
@qVin = external dso_local global %struct.ButterQueue, align 4
@SOS_PLL = external dso_local global [6 x float], align 16
@scale_PLL = external dso_local global float, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@theta = external global float, align 4
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  store ptr @pidTheta, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store ptr @qVin, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store float 0.000000e+00, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store float 0.000000e+00, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store float 0.000000e+00, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store float 0.000000e+00, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 50, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store float 0x3F1A36E2E0000000, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store float 0.000000e+00, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %14 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %14, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %0
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %12, align 4
  br label %93

19:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %89, %19
  %21 = load i32, ptr %13, align 4, !tbaa !11
  %22 = icmp sle i32 %21, 999
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %92

24:                                               ; preds = %20
  %25 = load i32, ptr %8, align 4, !tbaa !11
  %26 = uitofp i32 %25 to double
  %27 = fmul double 6.283180e+00, %26
  %28 = load i32, ptr %13, align 4, !tbaa !11
  %29 = sitofp i32 %28 to double
  %30 = fmul double %27, %29
  %31 = load float, ptr %9, align 4, !tbaa !9
  %32 = fpext float %31 to double
  %33 = fmul double %30, %32
  %34 = call double @sin(double noundef %33) #5
  %35 = fmul double 6.000000e+00, %34
  %36 = fptrunc double %35 to float
  store float %36, ptr %4, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !11
  %38 = uitofp i32 %37 to double
  %39 = fmul double 6.283180e+00, %38
  %40 = load i32, ptr %13, align 4, !tbaa !11
  %41 = sitofp i32 %40 to double
  %42 = fmul double %39, %41
  %43 = load float, ptr %9, align 4, !tbaa !9
  %44 = fpext float %43 to double
  %45 = fmul double %42, %44
  %46 = call double @sin(double noundef %45) #5
  %47 = fmul double 6.000000e+00, %46
  %48 = fptrunc double %47 to float
  store float %48, ptr %5, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !11
  %50 = uitofp i32 %49 to double
  %51 = fmul double 6.283180e+00, %50
  %52 = load i32, ptr %13, align 4, !tbaa !11
  %53 = sitofp i32 %52 to double
  %54 = fmul double %51, %53
  %55 = load float, ptr %9, align 4, !tbaa !9
  %56 = fpext float %55 to double
  %57 = call double @llvm.fmuladd.f64(double %54, double %56, double 0x4000C1514ABD0449)
  %58 = call double @sin(double noundef %57) #5
  %59 = fmul double 6.000000e+00, %58
  %60 = fptrunc double %59 to float
  store float %60, ptr %6, align 4, !tbaa !9
  %61 = load i32, ptr %8, align 4, !tbaa !11
  %62 = uitofp i32 %61 to double
  %63 = fmul double 6.283180e+00, %62
  %64 = load i32, ptr %13, align 4, !tbaa !11
  %65 = sitofp i32 %64 to double
  %66 = fmul double %63, %65
  %67 = load float, ptr %9, align 4, !tbaa !9
  %68 = fpext float %67 to double
  %69 = call double @llvm.fmuladd.f64(double %66, double %68, double 0x4010C1514ABD0449)
  %70 = call double @sin(double noundef %69) #5
  %71 = fmul double 6.000000e+00, %70
  %72 = fptrunc double %71 to float
  store float %72, ptr %7, align 4, !tbaa !9
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = load float, ptr %4, align 4, !tbaa !9
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = load float, ptr @scale_PLL, align 4, !tbaa !9
  call void @singlePhasePLLCalc(ptr noundef %73, float noundef %74, ptr noundef %75, ptr noundef @SOS_PLL, float noundef %76)
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = load float, ptr %4, align 4, !tbaa !9
  %79 = fpext float %78 to double
  %80 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef @.str.3, double noundef %79) #5
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str.4) #5
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = load float, ptr @theta, align 4, !tbaa !9
  %85 = fpext float %84 to double
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %83, ptr noundef @.str.3, double noundef %85) #5
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str.5) #5
  br label %89

89:                                               ; preds = %24
  %90 = load i32, ptr %13, align 4, !tbaa !11
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %13, align 4, !tbaa !11
  br label %20, !llvm.loop !13

92:                                               ; preds = %23
  store i32 0, ptr %12, align 4
  br label %93

93:                                               ; preds = %92, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %94 = load i32, ptr %12, align 4
  switch i32 %94, label %97 [
    i32 0, label %95
    i32 1, label %95
  ]

95:                                               ; preds = %93, %93
  %96 = load i32, ptr %1, align 4
  ret i32 %96

97:                                               ; preds = %93
  unreachable
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind
declare double @sin(double noundef) #3

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

declare void @singlePhasePLLCalc(ptr noundef, float noundef, ptr noundef, ptr noundef, float noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; 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 = { "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 "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"any pointer", !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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct.PID = type { float, float, float, float, float, float, float }
%struct.ButterQueue = type { [3 x float], i32, float, float }

@pidTheta = external dso_local global %struct.PID, align 4
@qVin = external dso_local global %struct.ButterQueue, align 4
@SOS_PLL = external dso_local global [6 x float], align 16
@scale_PLL = external dso_local local_unnamed_addr global float, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@theta = external local_unnamed_addr global float, align 4
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %2 = icmp eq ptr %1, null
  br i1 %2, label %3, label %.preheader

3:                                                ; preds = %0
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.loopexit

.preheader:                                       ; preds = %0, %cdce.end28
  %.029 = phi i32 [ %29, %cdce.end28 ], [ 0, %0 ]
  %5 = uitofp nneg i32 %.029 to double
  %6 = fmul double %5, 3.141590e+02
  %7 = fmul double %6, 0x3F1A36E2E0000000
  %8 = tail call double @sin(double noundef %7) #6
  %9 = fmul double %8, 6.000000e+00
  %10 = fptrunc double %9 to float
  %11 = fcmp oeq double %7, 0x7FF0000000000000
  br i1 %11, label %cdce.call, label %cdce.end, !prof !5

cdce.call:                                        ; preds = %.preheader
  %12 = tail call double @sin(double noundef 0x7FF0000000000000) #6
  br label %cdce.end

cdce.end:                                         ; preds = %.preheader, %cdce.call
  %13 = tail call double @llvm.fmuladd.f64(double %6, double 0x3F1A36E2E0000000, double 0x4000C1514ABD0449)
  %14 = tail call double @llvm.fabs.f64(double %13)
  %15 = fcmp oeq double %14, 0x7FF0000000000000
  br i1 %15, label %cdce.call25, label %cdce.end26, !prof !5

cdce.call25:                                      ; preds = %cdce.end
  %16 = tail call double @sin(double noundef %13) #6
  br label %cdce.end26

cdce.end26:                                       ; preds = %cdce.end, %cdce.call25
  %17 = tail call double @llvm.fmuladd.f64(double %6, double 0x3F1A36E2E0000000, double 0x4010C1514ABD0449)
  %18 = tail call double @llvm.fabs.f64(double %17)
  %19 = fcmp oeq double %18, 0x7FF0000000000000
  br i1 %19, label %cdce.call27, label %cdce.end28, !prof !5

cdce.call27:                                      ; preds = %cdce.end26
  %20 = tail call double @sin(double noundef %17) #6
  br label %cdce.end28

cdce.end28:                                       ; preds = %cdce.end26, %cdce.call27
  %21 = load float, ptr @scale_PLL, align 4, !tbaa !6
  tail call void @singlePhasePLLCalc(ptr noundef nonnull @pidTheta, float noundef %10, ptr noundef nonnull @qVin, ptr noundef nonnull @SOS_PLL, float noundef %21) #6
  %22 = fpext float %10 to double
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %1, ptr noundef nonnull @.str.3, double noundef %22) #6
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %1, ptr noundef nonnull @.str.4) #6
  %25 = load float, ptr @theta, align 4, !tbaa !6
  %26 = fpext float %25 to double
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %1, ptr noundef nonnull @.str.3, double noundef %26) #6
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %1, ptr noundef nonnull @.str.5) #6
  %29 = add nuw nsw i32 %.029, 1
  %exitcond.not = icmp eq i32 %29, 1000
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !10

.loopexit:                                        ; preds = %cdce.end28, %3
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

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

declare void @singlePhasePLLCalc(ptr noundef, float noundef, ptr noundef, ptr noundef, float noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

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


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