; LLVM IR from bondhugula/pluto :: examples/dct (dct)

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

@cos1 = external dso_local global [1024 x [1037 x double]], align 16
@block = external dso_local global [1024 x [1067 x double]], align 16
@temp2d = external dso_local global [1024 x [1047 x double]], align 16
@sum2 = external dso_local global [1024 x [1024 x double]], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @init_array() #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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @init_array()
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %64, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 1024
  br i1 %12, label %13, label %67

13:                                               ; preds = %10
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %60, %13
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 1024
  br i1 %16, label %17, label %63

17:                                               ; preds = %14
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1024 x [1047 x double]], ptr @temp2d, i64 0, i64 %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1047 x double], ptr %20, i64 0, i64 %22
  store double 0.000000e+00, ptr %23, align 8, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %56, %17
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 1024
  br i1 %26, label %27, label %59

27:                                               ; preds = %24
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1024 x [1047 x double]], ptr @temp2d, i64 0, i64 %29
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1047 x double], ptr %30, i64 0, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1024 x [1067 x double]], ptr @block, i64 0, i64 %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1067 x double], ptr %37, i64 0, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !9
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1024 x [1037 x double]], ptr @cos1, i64 0, i64 %43
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1037 x double], ptr %44, i64 0, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !9
  %49 = call double @llvm.fmuladd.f64(double %41, double %48, double %34)
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1024 x [1047 x double]], ptr @temp2d, i64 0, i64 %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1047 x double], ptr %52, i64 0, i64 %54
  store double %49, ptr %55, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %27
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %4, align 4, !tbaa !5
  br label %24, !llvm.loop !11

59:                                               ; preds = %24
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !13

63:                                               ; preds = %14
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !14

67:                                               ; preds = %10
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %135, %67
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = icmp slt i32 %69, 1024
  br i1 %70, label %71, label %138

71:                                               ; preds = %68
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %131, %71
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = icmp slt i32 %73, 1024
  br i1 %74, label %75, label %134

75:                                               ; preds = %72
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1024 x [1024 x double]], ptr @sum2, i64 0, i64 %77
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1024 x double], ptr %78, i64 0, i64 %80
  store double 0.000000e+00, ptr %81, align 8, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %114, %75
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = icmp slt i32 %83, 1024
  br i1 %84, label %85, label %117

85:                                               ; preds = %82
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [1024 x [1024 x double]], ptr @sum2, i64 0, i64 %87
  %89 = load i32, ptr %3, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [1024 x double], ptr %88, i64 0, i64 %90
  %92 = load double, ptr %91, align 8, !tbaa !9
  %93 = load i32, ptr %2, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [1024 x [1037 x double]], ptr @cos1, i64 0, i64 %94
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [1037 x double], ptr %95, i64 0, i64 %97
  %99 = load double, ptr %98, align 8, !tbaa !9
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [1024 x [1047 x double]], ptr @temp2d, i64 0, i64 %101
  %103 = load i32, ptr %3, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [1047 x double], ptr %102, i64 0, i64 %104
  %106 = load double, ptr %105, align 8, !tbaa !9
  %107 = call double @llvm.fmuladd.f64(double %99, double %106, double %92)
  %108 = load i32, ptr %2, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [1024 x [1024 x double]], ptr @sum2, i64 0, i64 %109
  %111 = load i32, ptr %3, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [1024 x double], ptr %110, i64 0, i64 %112
  store double %107, ptr %113, align 8, !tbaa !9
  br label %114

114:                                              ; preds = %85
  %115 = load i32, ptr %4, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %4, align 4, !tbaa !5
  br label %82, !llvm.loop !15

117:                                              ; preds = %82
  %118 = load i32, ptr %2, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [1024 x [1024 x double]], ptr @sum2, i64 0, i64 %119
  %121 = load i32, ptr %3, align 4, !tbaa !5
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [1024 x double], ptr %120, i64 0, i64 %122
  %124 = load double, ptr %123, align 8, !tbaa !9
  %125 = load i32, ptr %2, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [1024 x [1067 x double]], ptr @block, i64 0, i64 %126
  %128 = load i32, ptr %3, align 4, !tbaa !5
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds [1067 x double], ptr %127, i64 0, i64 %129
  store double %124, ptr %130, align 8, !tbaa !9
  br label %131

131:                                              ; preds = %117
  %132 = load i32, ptr %3, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %3, align 4, !tbaa !5
  br label %72, !llvm.loop !16

134:                                              ; preds = %72
  br label %135

135:                                              ; preds = %134
  %136 = load i32, ptr %2, align 4, !tbaa !5
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr %2, align 4, !tbaa !5
  br label %68, !llvm.loop !17

138:                                              ; preds = %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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

@cos1 = external dso_local local_unnamed_addr global [1024 x [1037 x double]], align 16
@block = external dso_local local_unnamed_addr global [1024 x [1067 x double]], align 16
@temp2d = external dso_local local_unnamed_addr global [1024 x [1047 x double]], align 16
@sum2 = external dso_local local_unnamed_addr global [1024 x [1024 x double]], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @init_array() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @init_array()
  br label %.preheader41

.preheader41:                                     ; preds = %0, %16
  %indvars.iv56 = phi i64 [ 0, %0 ], [ %indvars.iv.next57, %16 ]
  br label %1

1:                                                ; preds = %.preheader41, %15
  %indvars.iv52 = phi i64 [ 0, %.preheader41 ], [ %indvars.iv.next53, %15 ]
  %2 = getelementptr inbounds [1024 x [1047 x double]], ptr @temp2d, i64 0, i64 %indvars.iv56, i64 %indvars.iv52
  br label %3

3:                                                ; preds = %3, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.1, %3 ]
  %4 = phi double [ 0.000000e+00, %1 ], [ %14, %3 ]
  %5 = getelementptr inbounds [1024 x [1067 x double]], ptr @block, i64 0, i64 %indvars.iv56, i64 %indvars.iv
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds [1024 x [1037 x double]], ptr @cos1, i64 0, i64 %indvars.iv52, i64 %indvars.iv
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = tail call double @llvm.fmuladd.f64(double %6, double %8, double %4)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %10 = getelementptr inbounds [1024 x [1067 x double]], ptr @block, i64 0, i64 %indvars.iv56, i64 %indvars.iv.next
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds [1024 x [1037 x double]], ptr @cos1, i64 0, i64 %indvars.iv52, i64 %indvars.iv.next
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %11, double %13, double %9)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 1024
  br i1 %exitcond.not.1, label %15, label %3, !llvm.loop !9

15:                                               ; preds = %3
  store double %14, ptr %2, align 8, !tbaa !5
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next53, 1024
  br i1 %exitcond55.not, label %16, label %1, !llvm.loop !11

16:                                               ; preds = %15
  %indvars.iv.next57 = add nuw nsw i64 %indvars.iv56, 1
  %exitcond59.not = icmp eq i64 %indvars.iv.next57, 1024
  br i1 %exitcond59.not, label %.preheader, label %.preheader41, !llvm.loop !12

.preheader:                                       ; preds = %16, %33
  %indvars.iv68 = phi i64 [ %indvars.iv.next69, %33 ], [ 0, %16 ]
  br label %17

17:                                               ; preds = %.preheader, %31
  %indvars.iv64 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next65, %31 ]
  %18 = getelementptr inbounds [1024 x [1024 x double]], ptr @sum2, i64 0, i64 %indvars.iv68, i64 %indvars.iv64
  br label %19

19:                                               ; preds = %19, %17
  %indvars.iv60 = phi i64 [ 0, %17 ], [ %indvars.iv.next61.1, %19 ]
  %20 = phi double [ 0.000000e+00, %17 ], [ %30, %19 ]
  %21 = getelementptr inbounds [1024 x [1037 x double]], ptr @cos1, i64 0, i64 %indvars.iv68, i64 %indvars.iv60
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds [1024 x [1047 x double]], ptr @temp2d, i64 0, i64 %indvars.iv60, i64 %indvars.iv64
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = tail call double @llvm.fmuladd.f64(double %22, double %24, double %20)
  %indvars.iv.next61 = or disjoint i64 %indvars.iv60, 1
  %26 = getelementptr inbounds [1024 x [1037 x double]], ptr @cos1, i64 0, i64 %indvars.iv68, i64 %indvars.iv.next61
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds [1024 x [1047 x double]], ptr @temp2d, i64 0, i64 %indvars.iv.next61, i64 %indvars.iv64
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = tail call double @llvm.fmuladd.f64(double %27, double %29, double %25)
  %indvars.iv.next61.1 = add nuw nsw i64 %indvars.iv60, 2
  %exitcond63.not.1 = icmp eq i64 %indvars.iv.next61.1, 1024
  br i1 %exitcond63.not.1, label %31, label %19, !llvm.loop !13

31:                                               ; preds = %19
  store double %30, ptr %18, align 8, !tbaa !5
  %32 = getelementptr inbounds [1024 x [1067 x double]], ptr @block, i64 0, i64 %indvars.iv68, i64 %indvars.iv64
  store double %30, ptr %32, align 8, !tbaa !5
  %indvars.iv.next65 = add nuw nsw i64 %indvars.iv64, 1
  %exitcond67.not = icmp eq i64 %indvars.iv.next65, 1024
  br i1 %exitcond67.not, label %33, label %17, !llvm.loop !14

33:                                               ; preds = %31
  %indvars.iv.next69 = add nuw nsw i64 %indvars.iv68, 1
  %exitcond71.not = icmp eq i64 %indvars.iv.next69, 1024
  br i1 %exitcond71.not, label %34, label %.preheader, !llvm.loop !15

34:                                               ; preds = %33
  ret i32 0
}

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 = { mustprogress 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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