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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @store(i32 noundef, 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 [1024 x float], align 16
  %10 = alloca [512 x float], align 16
  %11 = alloca [512 x float], align 16
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = 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 %17

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

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

19:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4096, ptr %9) #2
  br label %20

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 2048, ptr %10) #2
  br label %21

21:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 2048, ptr %11) #2
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %37, %23
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 2
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %40

28:                                               ; preds = %24
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %29, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !11
  %34 = load i32, ptr %12, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [2 x float], ptr %7, i64 0, i64 %35
  store float %33, ptr %36, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %28
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %12, align 4, !tbaa !9
  br label %24, !llvm.loop !13

40:                                               ; preds = %27
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %104, %42
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = icmp slt i32 %44, 2050
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %107

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = icmp sge i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %47
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = icmp slt i32 %51, 2048
  br label %53

53:                                               ; preds = %50, %47
  %54 = phi i1 [ false, %47 ], [ %52, %50 ]
  %55 = zext i1 %54 to i32
  store i32 %55, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = icmp sge i32 %56, 1
  br i1 %57, label %58, label %61

58:                                               ; preds = %53
  %59 = load i32, ptr %13, align 4, !tbaa !9
  %60 = icmp slt i32 %59, 2049
  br label %61

61:                                               ; preds = %58, %53
  %62 = phi i1 [ false, %53 ], [ %60, %58 ]
  %63 = zext i1 %62 to i32
  store i32 %63, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %64 = load i32, ptr %13, align 4, !tbaa !9
  %65 = icmp sge i32 %64, 2
  br i1 %65, label %66, label %69

66:                                               ; preds = %61
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = icmp slt i32 %67, 2050
  br label %69

69:                                               ; preds = %66, %61
  %70 = phi i1 [ false, %61 ], [ %68, %66 ]
  %71 = zext i1 %70 to i32
  store i32 %71, ptr %16, align 4, !tbaa !9
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = srem i32 %72, 2
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %89

75:                                               ; preds = %69
  %76 = load i32, ptr %14, align 4, !tbaa !9
  %77 = load i32, ptr %13, align 4, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds [1024 x float], ptr %8, i64 0, i64 0
  call void @load(i32 noundef %76, i32 noundef %77, ptr noundef %78, ptr noundef %79)
  %80 = load i32, ptr %15, align 4, !tbaa !9
  %81 = getelementptr inbounds [2 x float], ptr %7, i64 0, i64 0
  %82 = getelementptr inbounds [1024 x float], ptr %9, i64 0, i64 0
  %83 = getelementptr inbounds [512 x float], ptr %11, i64 0, i64 0
  call void @compute(i32 noundef %80, ptr noundef %81, ptr noundef %82, ptr noundef %83)
  %84 = load i32, ptr %16, align 4, !tbaa !9
  %85 = load i32, ptr %13, align 4, !tbaa !9
  %86 = sub nsw i32 %85, 2
  %87 = getelementptr inbounds [512 x float], ptr %10, i64 0, i64 0
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  call void @store(i32 noundef %84, i32 noundef %86, ptr noundef %87, ptr noundef %88)
  br label %103

89:                                               ; preds = %69
  %90 = load i32, ptr %14, align 4, !tbaa !9
  %91 = load i32, ptr %13, align 4, !tbaa !9
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds [1024 x float], ptr %9, i64 0, i64 0
  call void @load(i32 noundef %90, i32 noundef %91, ptr noundef %92, ptr noundef %93)
  %94 = load i32, ptr %15, align 4, !tbaa !9
  %95 = getelementptr inbounds [2 x float], ptr %7, i64 0, i64 0
  %96 = getelementptr inbounds [1024 x float], ptr %8, i64 0, i64 0
  %97 = getelementptr inbounds [512 x float], ptr %10, i64 0, i64 0
  call void @compute(i32 noundef %94, ptr noundef %95, ptr noundef %96, ptr noundef %97)
  %98 = load i32, ptr %16, align 4, !tbaa !9
  %99 = load i32, ptr %13, align 4, !tbaa !9
  %100 = sub nsw i32 %99, 2
  %101 = getelementptr inbounds [512 x float], ptr %11, i64 0, i64 0
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  call void @store(i32 noundef %98, i32 noundef %100, ptr noundef %101, ptr noundef %102)
  br label %103

103:                                              ; preds = %89, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %13, align 4, !tbaa !9
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %13, align 4, !tbaa !9
  br label %43, !llvm.loop !15

107:                                              ; preds = %46
  call void @llvm.lifetime.end.p0(i64 2048, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 2048, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4096, 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, 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(i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @store(i32 noundef, 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 [1024 x float], align 16
  %6 = alloca [512 x float], align 16
  %7 = 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 4096, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %7) #2
  %8 = load i64, ptr %0, align 4, !tbaa !5
  store i64 %8, ptr %3, align 8, !tbaa !5
  br label %.preheader

9:                                                ; preds = %23
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4096, 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, %23
  %.02729 = phi i32 [ %24, %23 ], [ 0, %.preheader.preheader ]
  %10 = icmp ult i32 %.02729, 2048
  %11 = zext i1 %10 to i32
  %12 = icmp ne i32 %.02729, 0
  %13 = icmp ne i32 %.02729, 2049
  %14 = and i1 %12, %13
  %15 = zext i1 %14 to i32
  %16 = icmp ugt i32 %.02729, 1
  %17 = zext i1 %16 to i32
  %18 = and i32 %.02729, 1
  %19 = icmp eq i32 %18, 0
  %20 = add nsw i32 %.02729, -2
  br i1 %19, label %21, label %22

21:                                               ; preds = %.preheader
  call void @load(i32 noundef %11, i32 noundef %.02729, ptr noundef %1, ptr noundef nonnull %4)
  call void @compute(i32 noundef %15, ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef nonnull %7)
  br label %23

22:                                               ; preds = %.preheader
  call void @load(i32 noundef %11, i32 noundef %.02729, ptr noundef %1, ptr noundef nonnull %5)
  call void @compute(i32 noundef %15, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %6)
  br label %23

23:                                               ; preds = %22, %21
  %.sink = phi ptr [ %7, %22 ], [ %6, %21 ]
  call void @store(i32 noundef %17, i32 noundef %20, ptr noundef nonnull %.sink, ptr noundef %2)
  %24 = add nuw nsw i32 %.02729, 1
  %exitcond.not = icmp eq i32 %24, 2050
  br i1 %exitcond.not, label %9, 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