; LLVM IR from bondhugula/pluto :: examples/heat-1d (heat-1d)

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

%struct.timeval = type { i64, i64 }

@.str = external hidden unnamed_addr constant [51 x i8], align 1
@A = external dso_local global [2 x [1600002 x double]], align 16

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.timeval, align 8
  %13 = alloca %struct.timeval, align 8
  %14 = alloca %struct.timeval, align 8
  %15 = alloca double, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 1024, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 -1, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  store double 0.000000e+00, ptr %15, align 8, !tbaa !11
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef 1600000, i64 noundef 1000)
  call void @srand(i32 noundef 42) #5
  store i64 1, ptr %7, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %27, %2
  %18 = load i64, ptr %7, align 8, !tbaa !13
  %19 = icmp slt i64 %18, 1600001
  br i1 %19, label %20, label %30

20:                                               ; preds = %17
  %21 = call i32 @rand() #5
  %22 = srem i32 %21, 1024
  %23 = sitofp i32 %22 to double
  %24 = fmul double 1.000000e+00, %23
  %25 = load i64, ptr %7, align 8, !tbaa !13
  %26 = getelementptr inbounds [1600002 x double], ptr @A, i64 0, i64 %25
  store double %24, ptr %26, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %20
  %28 = load i64, ptr %7, align 8, !tbaa !13
  %29 = add nsw i64 %28, 1
  store i64 %29, ptr %7, align 8, !tbaa !13
  br label %17, !llvm.loop !15

30:                                               ; preds = %17
  store i64 0, ptr %6, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %72, %30
  %32 = load i64, ptr %6, align 8, !tbaa !13
  %33 = icmp slt i64 %32, 1000
  br i1 %33, label %34, label %75

34:                                               ; preds = %31
  store i64 1, ptr %7, align 8, !tbaa !13
  br label %35

35:                                               ; preds = %68, %34
  %36 = load i64, ptr %7, align 8, !tbaa !13
  %37 = icmp slt i64 %36, 1600001
  br i1 %37, label %38, label %71

38:                                               ; preds = %35
  %39 = load i64, ptr %6, align 8, !tbaa !13
  %40 = srem i64 %39, 2
  %41 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %40
  %42 = load i64, ptr %7, align 8, !tbaa !13
  %43 = add nsw i64 %42, 1
  %44 = getelementptr inbounds [1600002 x double], ptr %41, i64 0, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load i64, ptr %6, align 8, !tbaa !13
  %47 = srem i64 %46, 2
  %48 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %47
  %49 = load i64, ptr %7, align 8, !tbaa !13
  %50 = getelementptr inbounds [1600002 x double], ptr %48, i64 0, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %51, double %45)
  %53 = load i64, ptr %6, align 8, !tbaa !13
  %54 = srem i64 %53, 2
  %55 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %54
  %56 = load i64, ptr %7, align 8, !tbaa !13
  %57 = sub nsw i64 %56, 1
  %58 = getelementptr inbounds [1600002 x double], ptr %55, i64 0, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !11
  %60 = fadd double %52, %59
  %61 = fmul double 2.500000e-01, %60
  %62 = load i64, ptr %6, align 8, !tbaa !13
  %63 = add nsw i64 %62, 1
  %64 = srem i64 %63, 2
  %65 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %64
  %66 = load i64, ptr %7, align 8, !tbaa !13
  %67 = getelementptr inbounds [1600002 x double], ptr %65, i64 0, i64 %66
  store double %61, ptr %67, align 8, !tbaa !11
  br label %68

68:                                               ; preds = %38
  %69 = load i64, ptr %7, align 8, !tbaa !13
  %70 = add nsw i64 %69, 1
  store i64 %70, ptr %7, align 8, !tbaa !13
  br label %35, !llvm.loop !17

71:                                               ; preds = %35
  br label %72

72:                                               ; preds = %71
  %73 = load i64, ptr %6, align 8, !tbaa !13
  %74 = add nsw i64 %73, 1
  store i64 %74, ptr %6, align 8, !tbaa !13
  br label %31, !llvm.loop !18

75:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  ret i32 0
}

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @rand() #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 #3 = { nounwind "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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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

@.str = external hidden unnamed_addr constant [51 x i8], align 1
@A = external dso_local local_unnamed_addr global [2 x [1600002 x double]], align 16

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef 1600000, i64 noundef 1000)
  tail call void @srand(i32 noundef 42) #5
  br label %4

4:                                                ; preds = %2, %4
  %.01517 = phi i64 [ 1, %2 ], [ %9, %4 ]
  %5 = tail call i32 @rand() #5
  %6 = srem i32 %5, 1024
  %7 = sitofp i32 %6 to double
  %8 = getelementptr inbounds [1600002 x double], ptr @A, i64 0, i64 %.01517
  store double %7, ptr %8, align 8, !tbaa !5
  %9 = add nuw nsw i64 %.01517, 1
  %exitcond.not = icmp eq i64 %9, 1600001
  br i1 %exitcond.not, label %.preheader, label %4, !llvm.loop !9

.preheader:                                       ; preds = %4, %middle.block
  %.019 = phi i64 [ %56, %middle.block ], [ 0, %4 ]
  %10 = and i64 %.019, 1
  %11 = xor i64 %10, 1
  %.phi.trans.insert = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %10, i64 1
  %.pre = load double, ptr %.phi.trans.insert, align 8, !tbaa !5
  %12 = and i64 %.019, 1
  %13 = xor i64 %12, 1
  %14 = mul nuw nsw i64 %13, 12800016
  %15 = trunc i64 %.019 to i1
  %16 = select i1 %15, i64 12800016, i64 0
  %17 = sub nsw i64 %14, %16
  %18 = add nsw i64 %14, -8
  %19 = sub nsw i64 %18, %16
  %diff.check = icmp ult i64 %19, 32
  %diff.check22 = icmp ult i64 %17, 32
  %conflict.rdx = or i1 %diff.check, %diff.check22
  br i1 %conflict.rdx, label %scalar.ph, label %vector.ph

vector.ph:                                        ; preds = %.preheader
  %vector.recur.init = insertelement <2 x double> poison, double %.pre, i64 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <2 x double> [ %vector.recur.init, %vector.ph ], [ %wide.load23, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %20 = or disjoint i64 %index, 2
  %21 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %10, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load = load <2 x double>, ptr %21, align 16, !tbaa !5
  %wide.load23 = load <2 x double>, ptr %22, align 16, !tbaa !5
  %23 = shufflevector <2 x double> %vector.recur, <2 x double> %wide.load, <2 x i32> <i32 1, i32 2>
  %24 = shufflevector <2 x double> %wide.load, <2 x double> %wide.load23, <2 x i32> <i32 1, i32 2>
  %25 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %23, <2 x double> <double -2.000000e+00, double -2.000000e+00>, <2 x double> %wide.load)
  %26 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %24, <2 x double> <double -2.000000e+00, double -2.000000e+00>, <2 x double> %wide.load23)
  %27 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %10, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %wide.load24 = load <2 x double>, ptr %27, align 16, !tbaa !5
  %wide.load25 = load <2 x double>, ptr %28, align 16, !tbaa !5
  %29 = fadd <2 x double> %25, %wide.load24
  %30 = fadd <2 x double> %26, %wide.load25
  %31 = fmul <2 x double> %29, <double 2.500000e-01, double 2.500000e-01>
  %32 = fmul <2 x double> %30, <double 2.500000e-01, double 2.500000e-01>
  %33 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %11, i64 %offset.idx
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  store <2 x double> %31, ptr %33, align 8, !tbaa !5
  store <2 x double> %32, ptr %34, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %35 = icmp eq i64 %index.next, 1600000
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !11

scalar.ph:                                        ; preds = %.preheader, %scalar.ph
  %36 = phi double [ %49, %scalar.ph ], [ %.pre, %.preheader ]
  %.118 = phi i64 [ %47, %scalar.ph ], [ 1, %.preheader ]
  %37 = add nuw nsw i64 %.118, 1
  %38 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %10, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = tail call double @llvm.fmuladd.f64(double %36, double -2.000000e+00, double %39)
  %41 = add nsw i64 %.118, -1
  %42 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %10, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = fadd double %40, %43
  %45 = fmul double %44, 2.500000e-01
  %46 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %11, i64 %.118
  store double %45, ptr %46, align 8, !tbaa !5
  %47 = add nuw nsw i64 %.118, 2
  %48 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %10, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !5
  %50 = tail call double @llvm.fmuladd.f64(double %39, double -2.000000e+00, double %49)
  %51 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %10, i64 %.118
  %52 = load double, ptr %51, align 8, !tbaa !5
  %53 = fadd double %50, %52
  %54 = fmul double %53, 2.500000e-01
  %55 = getelementptr inbounds [2 x [1600002 x double]], ptr @A, i64 0, i64 %11, i64 %37
  store double %54, ptr %55, align 8, !tbaa !5
  %exitcond20.not.1 = icmp eq i64 %47, 1600001
  br i1 %exitcond20.not.1, label %middle.block, label %scalar.ph, !llvm.loop !14

middle.block:                                     ; preds = %vector.body, %scalar.ph
  %56 = add nuw nsw i64 %.019, 1
  %exitcond21.not = icmp eq i64 %56, 1000
  br i1 %exitcond21.not, label %57, label %.preheader, !llvm.loop !15

57:                                               ; preds = %middle.block
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #2

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

; 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>) #4

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 = { nofree nounwind "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 #2 = { nounwind "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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"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, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10, !12}
!15 = distinct !{!15, !10}


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