; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/machsuite-md-knn (md)

; 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: nounwind uwtable
define dso_local void @md_kernel(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca double, align 8
  %22 = alloca double, align 8
  %23 = alloca double, align 8
  %24 = alloca double, align 8
  %25 = alloca double, align 8
  %26 = alloca double, align 8
  %27 = alloca double, align 8
  %28 = alloca double, align 8
  %29 = alloca double, align 8
  %30 = alloca double, align 8
  %31 = alloca i32, align 4
  %32 = alloca i32, align 4
  %33 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %29) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %30) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %31) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %32) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %33) #3
  br label %34

34:                                               ; preds = %7
  br label %35

35:                                               ; preds = %34
  store i32 0, ptr %31, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %146, %35
  %37 = load i32, ptr %31, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 256
  br i1 %38, label %39, label %149

39:                                               ; preds = %36
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = load i32, ptr %31, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  store double %44, ptr %25, align 8, !tbaa !11
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load i32, ptr %31, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  store double %49, ptr %26, align 8, !tbaa !11
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  %51 = load i32, ptr %31, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  store double %54, ptr %27, align 8, !tbaa !11
  store double 0.000000e+00, ptr %28, align 8, !tbaa !11
  store double 0.000000e+00, ptr %29, align 8, !tbaa !11
  store double 0.000000e+00, ptr %30, align 8, !tbaa !11
  br label %55

55:                                               ; preds = %39
  br label %56

56:                                               ; preds = %55
  store i32 0, ptr %32, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %127, %56
  %58 = load i32, ptr %32, align 4, !tbaa !9
  %59 = icmp slt i32 %58, 16
  br i1 %59, label %60, label %130

60:                                               ; preds = %57
  %61 = load ptr, ptr %14, align 8, !tbaa !5
  %62 = load i32, ptr %31, align 4, !tbaa !9
  %63 = mul nsw i32 %62, 16
  %64 = load i32, ptr %32, align 4, !tbaa !9
  %65 = add nsw i32 %63, %64
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %61, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !9
  store i32 %68, ptr %33, align 4, !tbaa !9
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load i32, ptr %33, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds double, ptr %69, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !11
  store double %73, ptr %22, align 8, !tbaa !11
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = load i32, ptr %33, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds double, ptr %74, i64 %76
  %78 = load double, ptr %77, align 8, !tbaa !11
  store double %78, ptr %23, align 8, !tbaa !11
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = load i32, ptr %33, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds double, ptr %79, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !11
  store double %83, ptr %24, align 8, !tbaa !11
  %84 = load double, ptr %25, align 8, !tbaa !11
  %85 = load double, ptr %22, align 8, !tbaa !11
  %86 = fsub double %84, %85
  store double %86, ptr %15, align 8, !tbaa !11
  %87 = load double, ptr %26, align 8, !tbaa !11
  %88 = load double, ptr %23, align 8, !tbaa !11
  %89 = fsub double %87, %88
  store double %89, ptr %16, align 8, !tbaa !11
  %90 = load double, ptr %27, align 8, !tbaa !11
  %91 = load double, ptr %24, align 8, !tbaa !11
  %92 = fsub double %90, %91
  store double %92, ptr %17, align 8, !tbaa !11
  %93 = load double, ptr %15, align 8, !tbaa !11
  %94 = load double, ptr %15, align 8, !tbaa !11
  %95 = load double, ptr %16, align 8, !tbaa !11
  %96 = load double, ptr %16, align 8, !tbaa !11
  %97 = fmul double %95, %96
  %98 = call double @llvm.fmuladd.f64(double %93, double %94, double %97)
  %99 = load double, ptr %17, align 8, !tbaa !11
  %100 = load double, ptr %17, align 8, !tbaa !11
  %101 = call double @llvm.fmuladd.f64(double %99, double %100, double %98)
  %102 = fdiv double 1.000000e+00, %101
  store double %102, ptr %18, align 8, !tbaa !11
  %103 = load double, ptr %18, align 8, !tbaa !11
  %104 = load double, ptr %18, align 8, !tbaa !11
  %105 = fmul double %103, %104
  %106 = load double, ptr %18, align 8, !tbaa !11
  %107 = fmul double %105, %106
  store double %107, ptr %19, align 8, !tbaa !11
  %108 = load double, ptr %19, align 8, !tbaa !11
  %109 = load double, ptr %19, align 8, !tbaa !11
  %110 = call double @llvm.fmuladd.f64(double 1.500000e+00, double %109, double -2.000000e+00)
  %111 = fmul double %108, %110
  store double %111, ptr %20, align 8, !tbaa !11
  %112 = load double, ptr %18, align 8, !tbaa !11
  %113 = load double, ptr %20, align 8, !tbaa !11
  %114 = fmul double %112, %113
  store double %114, ptr %21, align 8, !tbaa !11
  %115 = load double, ptr %15, align 8, !tbaa !11
  %116 = load double, ptr %21, align 8, !tbaa !11
  %117 = load double, ptr %28, align 8, !tbaa !11
  %118 = call double @llvm.fmuladd.f64(double %115, double %116, double %117)
  store double %118, ptr %28, align 8, !tbaa !11
  %119 = load double, ptr %16, align 8, !tbaa !11
  %120 = load double, ptr %21, align 8, !tbaa !11
  %121 = load double, ptr %29, align 8, !tbaa !11
  %122 = call double @llvm.fmuladd.f64(double %119, double %120, double %121)
  store double %122, ptr %29, align 8, !tbaa !11
  %123 = load double, ptr %17, align 8, !tbaa !11
  %124 = load double, ptr %21, align 8, !tbaa !11
  %125 = load double, ptr %30, align 8, !tbaa !11
  %126 = call double @llvm.fmuladd.f64(double %123, double %124, double %125)
  store double %126, ptr %30, align 8, !tbaa !11
  br label %127

127:                                              ; preds = %60
  %128 = load i32, ptr %32, align 4, !tbaa !9
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %32, align 4, !tbaa !9
  br label %57, !llvm.loop !13

130:                                              ; preds = %57
  %131 = load double, ptr %28, align 8, !tbaa !11
  %132 = load ptr, ptr %8, align 8, !tbaa !5
  %133 = load i32, ptr %31, align 4, !tbaa !9
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds double, ptr %132, i64 %134
  store double %131, ptr %135, align 8, !tbaa !11
  %136 = load double, ptr %29, align 8, !tbaa !11
  %137 = load ptr, ptr %9, align 8, !tbaa !5
  %138 = load i32, ptr %31, align 4, !tbaa !9
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds double, ptr %137, i64 %139
  store double %136, ptr %140, align 8, !tbaa !11
  %141 = load double, ptr %30, align 8, !tbaa !11
  %142 = load ptr, ptr %10, align 8, !tbaa !5
  %143 = load i32, ptr %31, align 4, !tbaa !9
  %144 = sext i32 %143 to i64
  %145 = getelementptr inbounds double, ptr %142, i64 %144
  store double %141, ptr %145, align 8, !tbaa !11
  br label %146

146:                                              ; preds = %130
  %147 = load i32, ptr %31, align 4, !tbaa !9
  %148 = add nsw i32 %147, 1
  store i32 %148, ptr %31, align 4, !tbaa !9
  br label %36, !llvm.loop !15

149:                                              ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %33) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %32) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %31) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %30) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %29) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret void
}

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

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

; 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 = { 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 = !{!"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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @md_kernel(ptr nocapture noundef writeonly %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5, ptr nocapture noundef readonly %6) local_unnamed_addr #0 {
  br label %8

8:                                                ; preds = %7, %46
  %indvars.iv67 = phi i64 [ 0, %7 ], [ %indvars.iv.next68, %46 ]
  %9 = getelementptr inbounds double, ptr %3, i64 %indvars.iv67
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds double, ptr %4, i64 %indvars.iv67
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %5, i64 %indvars.iv67
  %14 = load double, ptr %13, align 8, !tbaa !5
  %.idx = shl nsw i64 %indvars.iv67, 6
  %invariant.gep = getelementptr inbounds i8, ptr %6, i64 %.idx
  %15 = insertelement <2 x double> poison, double %10, i64 0
  %16 = insertelement <2 x double> %15, double %14, i64 1
  br label %17

17:                                               ; preds = %8, %17
  %indvars.iv = phi i64 [ 0, %8 ], [ %indvars.iv.next, %17 ]
  %.05859 = phi double [ 0.000000e+00, %8 ], [ %42, %17 ]
  %18 = phi <2 x double> [ zeroinitializer, %8 ], [ %45, %17 ]
  %gep = getelementptr inbounds i32, ptr %invariant.gep, i64 %indvars.iv
  %19 = load i32, ptr %gep, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %3, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %4, i64 %20
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %5, i64 %20
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fsub double %12, %24
  %28 = insertelement <2 x double> poison, double %22, i64 0
  %29 = insertelement <2 x double> %28, double %26, i64 1
  %30 = fsub <2 x double> %16, %29
  %31 = fmul double %27, %27
  %32 = extractelement <2 x double> %30, i64 0
  %33 = tail call double @llvm.fmuladd.f64(double %32, double %32, double %31)
  %34 = extractelement <2 x double> %30, i64 1
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %34, double %33)
  %36 = fdiv double 1.000000e+00, %35
  %37 = fmul double %36, %36
  %38 = fmul double %36, %37
  %39 = tail call double @llvm.fmuladd.f64(double %38, double 1.500000e+00, double -2.000000e+00)
  %40 = fmul double %38, %39
  %41 = fmul double %36, %40
  %42 = tail call double @llvm.fmuladd.f64(double %27, double %41, double %.05859)
  %43 = insertelement <2 x double> poison, double %41, i64 0
  %44 = shufflevector <2 x double> %43, <2 x double> poison, <2 x i32> zeroinitializer
  %45 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %30, <2 x double> %44, <2 x double> %18)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 16
  br i1 %exitcond.not, label %46, label %17, !llvm.loop !11

46:                                               ; preds = %17
  %47 = getelementptr inbounds double, ptr %0, i64 %indvars.iv67
  %48 = extractelement <2 x double> %45, i64 0
  store double %48, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds double, ptr %1, i64 %indvars.iv67
  store double %42, ptr %49, align 8, !tbaa !5
  %50 = getelementptr inbounds double, ptr %2, i64 %indvars.iv67
  %51 = extractelement <2 x double> %45, i64 1
  store double %51, ptr %50, align 8, !tbaa !5
  %indvars.iv.next68 = add nuw nsw i64 %indvars.iv67, 1
  %exitcond70.not = icmp eq i64 %indvars.iv.next68, 256
  br i1 %exitcond70.not, label %52, label %8, !llvm.loop !13

52:                                               ; preds = %46
  ret void
}

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

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

attributes #0 = { 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 = !{!"double", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass