; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/spcl_example_03/Example3.ll (Z9Stencil2DPKfPf)

; 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
define dso_local void @_Z9Stencil2DPKfPf(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [1000 x float], align 16
  %6 = alloca [1000 x float], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %17

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

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

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

20:                                               ; preds = %33, %19
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 1000
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %20
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds float, ptr %25, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !11
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1000 x float], ptr %5, i64 0, i64 %31
  store float %29, ptr %32, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %24
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !13

36:                                               ; preds = %23
  br label %37

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

38:                                               ; preds = %52, %37
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = icmp slt i32 %39, 1000
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %55

42:                                               ; preds = %38
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = add nsw i32 1000, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds float, ptr %43, i64 %46
  %48 = load float, ptr %47, align 4, !tbaa !11
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000 x float], ptr %6, i64 0, i64 %50
  store float %48, ptr %51, align 4, !tbaa !11
  br label %52

52:                                               ; preds = %42
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %8, align 4, !tbaa !9
  br label %38, !llvm.loop !15

55:                                               ; preds = %41
  br label %56

56:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %103, %56
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = icmp slt i32 %58, 999
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  store i32 13, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %106

61:                                               ; preds = %57
  br label %62

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

63:                                               ; preds = %99, %62
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = icmp slt i32 %64, 1000
  br i1 %65, label %67, label %66

66:                                               ; preds = %63
  store i32 17, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %102

67:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %68 = load i32, ptr %11, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1000 x float], ptr %5, i64 0, i64 %69
  %71 = load float, ptr %70, align 4, !tbaa !11
  store float %71, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [1000 x float], ptr %6, i64 0, i64 %73
  %75 = load float, ptr %74, align 4, !tbaa !11
  store float %75, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  %79 = mul nsw i32 %78, 1000
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = add nsw i32 %79, %80
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds float, ptr %76, i64 %82
  %84 = load float, ptr %83, align 4, !tbaa !11
  store float %84, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  store float 0x3FD554C980000000, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %85 = load float, ptr %12, align 4, !tbaa !11
  %86 = load float, ptr %13, align 4, !tbaa !11
  %87 = fadd float %85, %86
  %88 = load float, ptr %14, align 4, !tbaa !11
  %89 = fadd float %87, %88
  %90 = fmul float 0x3FD554C980000000, %89
  store float %90, ptr %16, align 4, !tbaa !11
  %91 = load float, ptr %16, align 4, !tbaa !11
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = mul nsw i32 %93, 1000
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = add nsw i32 %94, %95
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds float, ptr %92, i64 %97
  store float %91, ptr %98, align 4, !tbaa !11
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %99

99:                                               ; preds = %67
  %100 = load i32, ptr %11, align 4, !tbaa !9
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %11, align 4, !tbaa !9
  br label %63, !llvm.loop !16

102:                                              ; preds = %66
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %9, align 4, !tbaa !9
  br label %57, !llvm.loop !17

106:                                              ; preds = %60
  call void @llvm.lifetime.end.p0(i64 4000, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4000, ptr %5) #2
  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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !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 @_Z9Stencil2DPKfPf(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
.preheader29:
  %2 = ptrtoint ptr %0 to i64
  %3 = ptrtoint ptr %1 to i64
  %4 = alloca [1000 x float], align 16
  %5 = alloca [1000 x float], align 16
  call void @llvm.lifetime.start.p0(i64 4000, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4000, ptr nonnull %5) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000) %4, ptr noundef nonnull align 4 dereferenceable(4000) %0, i64 4000, i1 false), !tbaa !5
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 4000
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000) %5, ptr noundef nonnull align 4 dereferenceable(4000) %invariant.gep, i64 4000, i1 false), !tbaa !5
  %invariant.gep42 = getelementptr inbounds i8, ptr %0, i64 4000
  %6 = add i64 %3, -4000
  %7 = sub i64 %6, %2
  %diff.check = icmp ult i64 %7, 32
  br label %.preheader

.preheader:                                       ; preds = %.preheader29, %middle.block
  %indvars.iv37 = phi i64 [ 1, %.preheader29 ], [ %indvars.iv.next38, %middle.block ]
  %8 = mul nuw nsw i64 %indvars.iv37, 1000
  %gep43 = getelementptr inbounds float, ptr %invariant.gep42, i64 %8
  %invariant.gep41 = getelementptr inbounds float, ptr %1, i64 %8
  br i1 %diff.check, label %scalar.ph, label %vector.body

vector.body:                                      ; preds = %.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader ]
  %9 = getelementptr inbounds [1000 x float], ptr %4, i64 0, i64 %index
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %wide.load = load <4 x float>, ptr %9, align 16, !tbaa !5
  %wide.load44 = load <4 x float>, ptr %10, align 16, !tbaa !5
  %11 = getelementptr inbounds [1000 x float], ptr %5, i64 0, i64 %index
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %wide.load45 = load <4 x float>, ptr %11, align 16, !tbaa !5
  %wide.load46 = load <4 x float>, ptr %12, align 16, !tbaa !5
  %13 = getelementptr inbounds float, ptr %gep43, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load47 = load <4 x float>, ptr %13, align 4, !tbaa !5
  %wide.load48 = load <4 x float>, ptr %14, align 4, !tbaa !5
  %15 = fadd <4 x float> %wide.load, %wide.load45
  %16 = fadd <4 x float> %wide.load44, %wide.load46
  %17 = fadd <4 x float> %15, %wide.load47
  %18 = fadd <4 x float> %16, %wide.load48
  %19 = fmul <4 x float> %17, <float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000>
  %20 = fmul <4 x float> %18, <float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000>
  %21 = getelementptr inbounds float, ptr %invariant.gep41, i64 %index
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store <4 x float> %19, ptr %21, align 4, !tbaa !5
  store <4 x float> %20, ptr %22, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, 1000
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !9

24:                                               ; preds = %middle.block
  call void @llvm.lifetime.end.p0(i64 4000, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4000, ptr nonnull %4) #3
  ret void

middle.block:                                     ; preds = %vector.body, %scalar.ph
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next38, 999
  br i1 %exitcond40.not, label %24, label %.preheader, !llvm.loop !13

scalar.ph:                                        ; preds = %.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ 0, %.preheader ]
  %25 = getelementptr inbounds [1000 x float], ptr %4, i64 0, i64 %indvars.iv
  %26 = load float, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds [1000 x float], ptr %5, i64 0, i64 %indvars.iv
  %28 = load float, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds float, ptr %gep43, i64 %indvars.iv
  %30 = load float, ptr %29, align 4, !tbaa !5
  %31 = fadd float %26, %28
  %32 = fadd float %31, %30
  %33 = fmul float %32, 0x3FD554C980000000
  %gep = getelementptr inbounds float, ptr %invariant.gep41, i64 %indvars.iv
  store float %33, ptr %gep, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %34 = getelementptr inbounds [1000 x float], ptr %4, i64 0, i64 %indvars.iv.next
  %35 = load float, ptr %34, align 4, !tbaa !5
  %36 = getelementptr inbounds [1000 x float], ptr %5, i64 0, i64 %indvars.iv.next
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds float, ptr %gep43, i64 %indvars.iv.next
  %39 = load float, ptr %38, align 4, !tbaa !5
  %40 = fadd float %35, %37
  %41 = fadd float %40, %39
  %42 = fmul float %41, 0x3FD554C980000000
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep41, i64 %indvars.iv.next
  store float %42, ptr %gep.1, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 1000
  br i1 %exitcond.not.1, label %middle.block, label %scalar.ph, !llvm.loop !14
}

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass