; LLVM IR from jgaeddert/liquid-dsp :: src/dotprod/src (dotprod_crcf)

; 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.dotprod_crcf_s = type { ptr, i32 }

; 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 allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @dotprod_crcf_recreate_rev(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.dotprod_crcf_s, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp ne i32 %10, %11
  br i1 %12, label %13, label %28

13:                                               ; preds = %3
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.dotprod_crcf_s, ptr %15, i32 0, i32 1
  store i32 %14, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.dotprod_crcf_s, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.dotprod_crcf_s, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = mul i64 %23, 4
  %25 = call ptr @realloc(ptr noundef %19, i64 noundef %24) #3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.dotprod_crcf_s, ptr %26, i32 0, i32 0
  store ptr %25, ptr %27, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %13, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %48, %28
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp ult i32 %30, %31
  br i1 %32, label %33, label %51

33:                                               ; preds = %29
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sub i32 %35, %36
  %38 = sub i32 %37, 1
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %34, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !14
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.dotprod_crcf_s, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %44, i64 %46
  store float %41, ptr %47, align 4, !tbaa !14
  br label %48

48:                                               ; preds = %33
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = add i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !9
  br label %29, !llvm.loop !16

51:                                               ; preds = %29
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret ptr %52
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 = { 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 allocsize(1) }
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 8}
!12 = !{!"dotprod_crcf_s", !6, i64 0, !10, i64 8}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @dotprod_crcf_recreate_rev(ptr noundef returned %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, %2
  br i1 %.not, label %11, label %6

6:                                                ; preds = %3
  store i32 %2, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %0, align 8, !tbaa !11
  %8 = zext i32 %2 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = tail call ptr @realloc(ptr noundef %7, i64 noundef %9) #2
  store ptr %10, ptr %0, align 8, !tbaa !11
  br label %11

11:                                               ; preds = %6, %3
  %.not17 = icmp eq i32 %2, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %12 = load ptr, ptr %0, align 8, !tbaa !11
  %wide.trip.count = zext i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 32
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph
  %13 = add nsw i64 %wide.trip.count, -1
  %14 = add i32 %2, -1
  %15 = trunc i64 %13 to i32
  %16 = icmp ult i32 %14, %15
  %17 = icmp ugt i64 %13, 4294967295
  %18 = or i1 %16, %17
  br i1 %18, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %19 = shl nuw nsw i64 %wide.trip.count, 2
  %scevgep = getelementptr i8, ptr %12, i64 %19
  %20 = add i32 %2, -1
  %21 = zext i32 %20 to i64
  %22 = shl nuw nsw i64 %21, 2
  %23 = add nuw nsw i64 %22, 4
  %24 = sub nsw i64 %23, %19
  %scevgep19 = getelementptr i8, ptr %1, i64 %24
  %25 = getelementptr i8, ptr %1, i64 %22
  %scevgep20 = getelementptr i8, ptr %25, i64 4
  %bound0 = icmp ult ptr %12, %scevgep20
  %bound1 = icmp ult ptr %scevgep19, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = trunc i64 %index to i32
  %27 = xor i32 %26, -1
  %28 = add i32 %27, %2
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds float, ptr %1, i64 %29
  %31 = getelementptr inbounds i8, ptr %30, i64 -12
  %32 = getelementptr inbounds i8, ptr %30, i64 -28
  %wide.load = load <4 x float>, ptr %31, align 4, !tbaa !12, !alias.scope !14
  %reverse = shufflevector <4 x float> %wide.load, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load21 = load <4 x float>, ptr %32, align 4, !tbaa !12, !alias.scope !14
  %reverse22 = shufflevector <4 x float> %wide.load21, <4 x float> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %33 = getelementptr inbounds float, ptr %12, i64 %index
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  store <4 x float> %reverse, ptr %33, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  store <4 x float> %reverse22, ptr %34, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  %index.next = add nuw i64 %index, 8
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %vector.scevcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %36 = trunc nuw i64 %indvars.iv.prol to i32
  %37 = xor i32 %36, -1
  %38 = add i32 %37, %2
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %1, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !12
  %42 = getelementptr inbounds float, ptr %12, i64 %indvars.iv.prol
  store float %41, ptr %42, align 4, !tbaa !12
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !23

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %43 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %44 = icmp ugt i64 %43, -4
  br i1 %44, label %._crit_edge, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %45 = trunc nuw i64 %indvars.iv to i32
  %46 = xor i32 %45, -1
  %47 = add i32 %46, %2
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %1, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !12
  %51 = getelementptr inbounds float, ptr %12, i64 %indvars.iv
  store float %50, ptr %51, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %52 = trunc nuw i64 %indvars.iv.next to i32
  %53 = xor i32 %52, -1
  %54 = add i32 %53, %2
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds float, ptr %1, i64 %55
  %57 = load float, ptr %56, align 4, !tbaa !12
  %58 = getelementptr inbounds float, ptr %12, i64 %indvars.iv.next
  store float %57, ptr %58, align 4, !tbaa !12
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %59 = trunc nuw i64 %indvars.iv.next.1 to i32
  %60 = xor i32 %59, -1
  %61 = add i32 %60, %2
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %1, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !12
  %65 = getelementptr inbounds float, ptr %12, i64 %indvars.iv.next.1
  store float %64, ptr %65, align 4, !tbaa !12
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %66 = trunc nuw i64 %indvars.iv.next.2 to i32
  %67 = xor i32 %66, -1
  %68 = add i32 %67, %2
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds float, ptr %1, i64 %69
  %71 = load float, ptr %70, align 4, !tbaa !12
  %72 = getelementptr inbounds float, ptr %12, i64 %indvars.iv.next.2
  store float %71, ptr %72, align 4, !tbaa !12
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !25

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %11
  ret ptr %0
}

attributes #0 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 allocsize(1) }

!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, !10, i64 8}
!6 = !{!"dotprod_crcf_s", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!15}
!15 = distinct !{!15, !16}
!16 = distinct !{!16, !"LVerDomain"}
!17 = !{!18}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.unroll.disable"}
!25 = distinct !{!25, !20, !21}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass