; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/rodinia-knn-4-doublebuffer (knn)

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

; 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: mustprogress nounwind uwtable
define dso_local void @compute(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %76

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  br label %18

18:                                               ; preds = %17
  br label %19

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

20:                                               ; preds = %72, %19
  %21 = load i32, ptr %11, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 512
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %20
  br label %25

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

26:                                               ; preds = %68, %25
  %27 = load i32, ptr %13, align 4, !tbaa !5
  %28 = icmp slt i32 %27, 2
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %71

30:                                               ; preds = %26
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  br label %31

31:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %57, %31
  %33 = load i32, ptr %14, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 2
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  store i32 12, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %60

36:                                               ; preds = %32
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = load i32, ptr %13, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = mul nsw i32 %40, 2
  %42 = load i32, ptr %14, align 4, !tbaa !5
  %43 = add nsw i32 %41, %42
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %37, i64 %44
  %46 = load float, ptr %45, align 4, !tbaa !11
  %47 = load ptr, ptr %6, align 8, !tbaa !9
  %48 = load i32, ptr %14, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds float, ptr %47, i64 %49
  %51 = load float, ptr %50, align 4, !tbaa !11
  %52 = fsub float %46, %51
  store float %52, ptr %10, align 4, !tbaa !11
  %53 = load float, ptr %10, align 4, !tbaa !11
  %54 = load float, ptr %10, align 4, !tbaa !11
  %55 = load float, ptr %9, align 4, !tbaa !11
  %56 = call float @llvm.fmuladd.f32(float %53, float %54, float %55)
  store float %56, ptr %9, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %36
  %58 = load i32, ptr %14, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %14, align 4, !tbaa !5
  br label %32, !llvm.loop !13

60:                                               ; preds = %35
  %61 = load float, ptr %9, align 4, !tbaa !11
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  %63 = load i32, ptr %11, align 4, !tbaa !5
  %64 = load i32, ptr %13, align 4, !tbaa !5
  %65 = add nsw i32 %63, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds float, ptr %62, i64 %66
  store float %61, ptr %67, align 4, !tbaa !11
  br label %68

68:                                               ; preds = %60
  %69 = load i32, ptr %13, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %13, align 4, !tbaa !5
  br label %26, !llvm.loop !15

71:                                               ; preds = %29
  br label %72

72:                                               ; preds = %71
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = add nsw i32 %73, 2
  store i32 %74, ptr %11, align 4, !tbaa !5
  br label %20, !llvm.loop !16

75:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %76

76:                                               ; preds = %75, %4
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @compute(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %.loopexit, label %.preheader22.preheader

.preheader22.preheader:                           ; preds = %4
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %scevgep = getelementptr i8, ptr %3, i64 2048
  %scevgep31 = getelementptr i8, ptr %2, i64 4096
  %scevgep32 = getelementptr i8, ptr %1, i64 8
  %bound0 = icmp ugt ptr %scevgep31, %3
  %bound1 = icmp ugt ptr %scevgep, %2
  %found.conflict = and i1 %bound0, %bound1
  %bound033 = icmp ugt ptr %scevgep32, %3
  %bound134 = icmp ugt ptr %scevgep, %1
  %found.conflict35 = and i1 %bound033, %bound134
  %conflict.rdx = or i1 %found.conflict, %found.conflict35
  br i1 %conflict.rdx, label %.preheader22, label %vector.body.preheader

vector.body.preheader:                            ; preds = %.preheader22.preheader
  %invariant.gep = getelementptr i8, ptr %3, i64 -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.body.preheader ]
  %offset.idx = shl i64 %index, 1
  %.idx = shl i64 %index, 4
  %6 = getelementptr inbounds i8, ptr %2, i64 %.idx
  %wide.vec = load <16 x float>, ptr %6, align 4, !tbaa !5
  %strided.vec = shufflevector <16 x float> %wide.vec, <16 x float> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>
  %strided.vec36 = shufflevector <16 x float> %wide.vec, <16 x float> poison, <4 x i32> <i32 1, i32 5, i32 9, i32 13>
  %strided.vec37 = shufflevector <16 x float> %wide.vec, <16 x float> poison, <4 x i32> <i32 2, i32 6, i32 10, i32 14>
  %strided.vec38 = shufflevector <16 x float> %wide.vec, <16 x float> poison, <4 x i32> <i32 3, i32 7, i32 11, i32 15>
  %7 = load float, ptr %1, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert = insertelement <4 x float> poison, float %7, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  %8 = fsub <4 x float> %strided.vec, %broadcast.splat
  %9 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %8, <4 x float> %8, <4 x float> zeroinitializer)
  %10 = load float, ptr %5, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert39 = insertelement <4 x float> poison, float %10, i64 0
  %broadcast.splat40 = shufflevector <4 x float> %broadcast.splatinsert39, <4 x float> poison, <4 x i32> zeroinitializer
  %11 = fsub <4 x float> %strided.vec36, %broadcast.splat40
  %12 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %11, <4 x float> %11, <4 x float> %9)
  %13 = load float, ptr %1, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert41 = insertelement <4 x float> poison, float %13, i64 0
  %broadcast.splat42 = shufflevector <4 x float> %broadcast.splatinsert41, <4 x float> poison, <4 x i32> zeroinitializer
  %14 = fsub <4 x float> %strided.vec37, %broadcast.splat42
  %15 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %14, <4 x float> %14, <4 x float> zeroinitializer)
  %16 = load float, ptr %5, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert43 = insertelement <4 x float> poison, float %16, i64 0
  %broadcast.splat44 = shufflevector <4 x float> %broadcast.splatinsert43, <4 x float> poison, <4 x i32> zeroinitializer
  %17 = fsub <4 x float> %strided.vec38, %broadcast.splat44
  %18 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %17, <4 x float> %17, <4 x float> %15)
  %19 = or disjoint i64 %offset.idx, 1
  %gep = getelementptr float, ptr %invariant.gep, i64 %19
  %interleaved.vec = shufflevector <4 x float> %12, <4 x float> %18, <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 !5
  %index.next = add nuw i64 %index, 4
  %20 = icmp eq i64 %index.next, 256
  br i1 %20, label %.loopexit, label %vector.body, !llvm.loop !12

.preheader22:                                     ; preds = %.preheader22.preheader, %.preheader22
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader22 ], [ 0, %.preheader22.preheader ]
  %21 = shl nuw nsw i64 %indvars.iv, 1
  %22 = getelementptr inbounds float, ptr %2, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = load float, ptr %1, align 4, !tbaa !5
  %25 = fsub float %23, %24
  %26 = tail call float @llvm.fmuladd.f32(float %25, float %25, float 0.000000e+00)
  %27 = or disjoint i64 %21, 1
  %28 = getelementptr inbounds float, ptr %2, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !5
  %30 = load float, ptr %5, align 4, !tbaa !5
  %31 = fsub float %29, %30
  %32 = tail call float @llvm.fmuladd.f32(float %31, float %31, float %26)
  %33 = getelementptr inbounds float, ptr %3, i64 %indvars.iv
  store float %32, ptr %33, align 4, !tbaa !5
  %34 = shl nuw nsw i64 %indvars.iv, 1
  %35 = or disjoint i64 %34, 2
  %36 = getelementptr inbounds float, ptr %2, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = load float, ptr %1, align 4, !tbaa !5
  %39 = fsub float %37, %38
  %40 = tail call float @llvm.fmuladd.f32(float %39, float %39, float 0.000000e+00)
  %41 = or disjoint i64 %34, 3
  %42 = getelementptr inbounds float, ptr %2, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !5
  %44 = load float, ptr %5, align 4, !tbaa !5
  %45 = fsub float %43, %44
  %46 = tail call float @llvm.fmuladd.f32(float %45, float %45, float %40)
  %47 = or disjoint i64 %indvars.iv, 1
  %48 = getelementptr inbounds float, ptr %3, i64 %47
  store float %46, ptr %48, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %49 = icmp ult i64 %indvars.iv, 510
  br i1 %49, label %.preheader22, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %vector.body, %.preheader22, %4
  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 <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = distinct !{!12, !13, !14, !15}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !13, !14}


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