; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/rodinia-knn-1-tiling (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: mustprogress nounwind uwtable
declare dso_local void @load(i32 noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @compute_dist(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @store(i32 noundef, ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @workload(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [2 x float], align 4
  %8 = alloca [1024 x float], align 16
  %9 = alloca [512 x float], align 16
  %10 = alloca i32, align 4
  %11 = alloca i32, 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
  br label %12

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  br label %13

13:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4096, ptr %8) #2
  br label %14

14:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 2048, ptr %9) #2
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %30, %16
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 2
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %33

21:                                               ; preds = %17
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %22, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [2 x float], ptr %7, i64 0, i64 %28
  store float %26, ptr %29, align 4, !tbaa !11
  br label %30

30:                                               ; preds = %21
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %10, align 4, !tbaa !9
  br label %17, !llvm.loop !13

33:                                               ; preds = %20
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %50, %35
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 2048
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %53

40:                                               ; preds = %36
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds [1024 x float], ptr %8, i64 0, i64 0
  call void @load(i32 noundef %41, ptr noundef %42, ptr noundef %43)
  %44 = getelementptr inbounds [2 x float], ptr %7, i64 0, i64 0
  %45 = getelementptr inbounds [1024 x float], ptr %8, i64 0, i64 0
  %46 = getelementptr inbounds [512 x float], ptr %9, i64 0, i64 0
  call void @compute_dist(ptr noundef %44, ptr noundef %45, ptr noundef %46)
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = getelementptr inbounds [512 x float], ptr %9, i64 0, i64 0
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @store(i32 noundef %47, ptr noundef %48, ptr noundef %49)
  br label %50

50:                                               ; preds = %40
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %11, align 4, !tbaa !9
  br label %36, !llvm.loop !15

53:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 2048, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4096, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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}


; 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 uwtable
declare dso_local void @load(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @compute_dist(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @store(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @workload(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
.preheader.preheader:
  %3 = alloca [2 x float], align 8
  %4 = alloca [1024 x float], align 16
  %5 = alloca [512 x float], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %5) #2
  %6 = load i64, ptr %0, align 4, !tbaa !5
  store i64 %6, ptr %3, align 8, !tbaa !5
  br label %.preheader

7:                                                ; preds = %.preheader
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret void

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.012 = phi i32 [ %8, %.preheader ], [ 0, %.preheader.preheader ]
  call void @load(i32 noundef %.012, ptr noundef %1, ptr noundef nonnull %4)
  call void @compute_dist(ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  call void @store(i32 noundef %.012, ptr noundef nonnull %5, ptr noundef %2)
  %8 = add nuw nsw i32 %.012, 1
  %exitcond.not = icmp eq i32 %8, 2048
  br i1 %exitcond.not, label %7, label %.preheader, !llvm.loop !9
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass