; LLVM IR from introlab/odas :: src/system (freq2freq)

; 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.freqs_obj = type { i32, i32, ptr }
%struct.freq2freq_phasor_obj = type { i32, float }

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @freq2freq_phasor_process(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %97, %3
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.freqs_obj, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp ult i32 %13, %16
  br i1 %17, label %18, label %100

18:                                               ; preds = %12
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %93, %18
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.freqs_obj, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp ult i32 %20, %23
  br i1 %24, label %25, label %96

25:                                               ; preds = %19
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.freqs_obj, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = mul i32 %33, 2
  %35 = add i32 %34, 0
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds float, ptr %32, i64 %36
  %38 = load float, ptr %37, align 4, !tbaa !15
  store float %38, ptr %9, align 4, !tbaa !15
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.freqs_obj, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = mul i32 %46, 2
  %48 = add i32 %47, 1
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds float, ptr %45, i64 %49
  %51 = load float, ptr %50, align 4, !tbaa !15
  store float %51, ptr %10, align 4, !tbaa !15
  %52 = load float, ptr %9, align 4, !tbaa !15
  %53 = load float, ptr %9, align 4, !tbaa !15
  %54 = load float, ptr %10, align 4, !tbaa !15
  %55 = load float, ptr %10, align 4, !tbaa !15
  %56 = fmul float %54, %55
  %57 = call float @llvm.fmuladd.f32(float %52, float %53, float %56)
  %58 = call float @sqrtf(float noundef %57) #4
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.freq2freq_phasor_obj, ptr %59, i32 0, i32 1
  %61 = load float, ptr %60, align 4, !tbaa !17
  %62 = fadd float %58, %61
  store float %62, ptr %11, align 4, !tbaa !15
  %63 = load float, ptr %9, align 4, !tbaa !15
  %64 = load float, ptr %11, align 4, !tbaa !15
  %65 = fdiv float %63, %64
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.freqs_obj, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %68, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = mul i32 %73, 2
  %75 = add i32 %74, 0
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds float, ptr %72, i64 %76
  store float %65, ptr %77, align 4, !tbaa !15
  %78 = load float, ptr %10, align 4, !tbaa !15
  %79 = load float, ptr %11, align 4, !tbaa !15
  %80 = fdiv float %78, %79
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.freqs_obj, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds ptr, ptr %83, i64 %85
  %87 = load ptr, ptr %86, align 8, !tbaa !5
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = mul i32 %88, 2
  %90 = add i32 %89, 1
  %91 = zext i32 %90 to i64
  %92 = getelementptr inbounds float, ptr %87, i64 %91
  store float %80, ptr %92, align 4, !tbaa !15
  br label %93

93:                                               ; preds = %25
  %94 = load i32, ptr %8, align 4, !tbaa !9
  %95 = add i32 %94, 1
  store i32 %95, ptr %8, align 4, !tbaa !9
  br label %19, !llvm.loop !19

96:                                               ; preds = %19
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %7, align 4, !tbaa !9
  %99 = add i32 %98, 1
  store i32 %99, ptr %7, align 4, !tbaa !9
  br label %12, !llvm.loop !21

100:                                              ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

; Function Attrs: nounwind
declare float @sqrtf(float noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"any pointer", !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, !10, i64 0}
!12 = !{!"freqs_obj", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !16, i64 4}
!18 = !{!"freq2freq_phasor_obj", !10, i64 0, !16, i64 4}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @freq2freq_phasor_process(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge29, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.not30 = icmp eq i32 %6, 0
  %7 = getelementptr i8, ptr %0, i64 4
  br i1 %.not30, label %._crit_edge29, label %.preheader.lr.ph.split.us

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = load ptr, ptr %8, align 8, !tbaa !12
  %wide.trip.count36 = zext i32 %4 to i64
  %wide.trip.count = zext i32 %6 to i64
  %12 = add nsw i64 %wide.trip.count, -1
  %scevgep41 = getelementptr i8, ptr %0, i64 8
  %13 = shl nuw nsw i64 %wide.trip.count, 3
  %min.iters.check = icmp ult i32 %6, 4
  %14 = icmp ugt i64 %12, 4294967295
  %mul.result = shl nsw i64 %12, 3
  %mul.result39 = shl nsw i64 %12, 3
  %n.vec = and i64 %wide.trip.count, 4294967292
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %._crit_edge.us ], [ 0, %.preheader.lr.ph.split.us ]
  %15 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv33
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv33
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.preheader.us
  %19 = getelementptr i8, ptr %18, i64 %mul.result
  %20 = icmp ult ptr %19, %18
  %scevgep = getelementptr i8, ptr %18, i64 4
  %21 = getelementptr i8, ptr %scevgep, i64 %mul.result39
  %22 = icmp ult ptr %21, %scevgep
  %23 = or i1 %20, %14
  %24 = or i1 %22, %23
  br i1 %24, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %scevgep42 = getelementptr i8, ptr %18, i64 %13
  %scevgep43 = getelementptr i8, ptr %16, i64 %13
  %bound0 = icmp ult ptr %7, %scevgep42
  %bound1 = icmp ult ptr %18, %scevgep41
  %found.conflict = and i1 %bound0, %bound1
  %bound044 = icmp ult ptr %18, %scevgep43
  %bound145 = icmp ult ptr %16, %scevgep42
  %found.conflict46 = and i1 %bound044, %bound145
  %conflict.rdx = or i1 %found.conflict, %found.conflict46
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %invariant.gep = getelementptr i8, ptr %18, i64 -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %25 = trunc i64 %index to i32
  %26 = shl i32 %25, 1
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds float, ptr %16, i64 %27
  %wide.vec = load <8 x float>, ptr %28, align 4, !tbaa !14
  %strided.vec = shufflevector <8 x float> %wide.vec, <8 x float> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec47 = shufflevector <8 x float> %wide.vec, <8 x float> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %29 = or disjoint i32 %26, 1
  %30 = zext i32 %29 to i64
  %31 = fmul <8 x float> %wide.vec, %wide.vec
  %32 = shufflevector <8 x float> %31, <8 x float> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %33 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %strided.vec, <4 x float> %strided.vec, <4 x float> %32)
  %34 = tail call <4 x float> @llvm.sqrt.v4f32(<4 x float> %33)
  %35 = load float, ptr %7, align 4, !tbaa !16, !alias.scope !18, !noalias !21
  %broadcast.splatinsert = insertelement <4 x float> poison, float %35, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  %36 = fadd <4 x float> %broadcast.splat, %34
  %37 = fdiv <4 x float> %strided.vec, %36
  %38 = fdiv <4 x float> %strided.vec47, %36
  %gep = getelementptr float, ptr %invariant.gep, i64 %30
  %interleaved.vec = shufflevector <4 x float> %37, <4 x float> %38, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>
  store <8 x float> %interleaved.vec, ptr %gep, align 4, !tbaa !14
  %index.next = add nuw i64 %index, 4
  %39 = icmp eq i64 %index.next, %n.vec
  br i1 %39, label %middle.block, label %vector.body, !llvm.loop !23

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %vector.scevcheck ], [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %40 = shl nuw i64 %indvars.iv, 1
  %41 = and i64 %40, 4294967294
  %42 = getelementptr inbounds float, ptr %16, i64 %41
  %43 = load float, ptr %7, align 4, !tbaa !16
  %44 = getelementptr inbounds float, ptr %18, i64 %41
  %45 = load <2 x float>, ptr %42, align 4, !tbaa !14
  %46 = fmul <2 x float> %45, %45
  %47 = extractelement <2 x float> %46, i64 1
  %48 = extractelement <2 x float> %45, i64 0
  %49 = tail call float @llvm.fmuladd.f32(float %48, float %48, float %47)
  %sqrt.us = tail call float @llvm.sqrt.f32(float %49)
  %50 = fadd float %43, %sqrt.us
  %51 = insertelement <2 x float> poison, float %50, i64 0
  %52 = shufflevector <2 x float> %51, <2 x float> poison, <2 x i32> zeroinitializer
  %53 = fdiv <2 x float> %45, %52
  store <2 x float> %53, ptr %44, align 4, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !27

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge29, label %.preheader.us, !llvm.loop !28

._crit_edge29:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %3
  ret void
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.sqrt.v4f32(<4 x float>) #2

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"freqs_obj", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = !{!17, !15, i64 4}
!17 = !{!"freq2freq_phasor_obj", !7, i64 0, !15, i64 4}
!18 = !{!19}
!19 = distinct !{!19, !20}
!20 = distinct !{!20, !"LVerDomain"}
!21 = !{!22}
!22 = distinct !{!22, !20}
!23 = distinct !{!23, !24, !25, !26}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!"llvm.loop.isvectorized", i32 1}
!26 = !{!"llvm.loop.unroll.runtime.disable"}
!27 = distinct !{!27, !24, !25}
!28 = distinct !{!28, !24}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass