; LLVM IR from bondhugula/pluto :: test (jacobi-1d-periodic-even)

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

@u = external dso_local global [2 x [1000 x i32]], align 16

; 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %66, %0
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp sle i32 %5, 999
  br i1 %6, label %7, label %69

7:                                                ; preds = %4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %62, %7
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sle i32 %9, 999
  br i1 %10, label %11, label %65

11:                                               ; preds = %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = srem i32 %13, 2
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %11
  br label %23

20:                                               ; preds = %11
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  br label %23

23:                                               ; preds = %20, %19
  %24 = phi i32 [ 999, %19 ], [ %22, %20 ]
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1000 x i32], ptr %16, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = srem i32 %29, 2
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %31
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %27, %36
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = srem i32 %39, 2
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %41
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = icmp eq i32 %43, 999
  br i1 %44, label %45, label %46

45:                                               ; preds = %23
  br label %49

46:                                               ; preds = %23
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  br label %49

49:                                               ; preds = %46, %45
  %50 = phi i32 [ 0, %45 ], [ %48, %46 ]
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1000 x i32], ptr %42, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %37, %53
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = srem i32 %55, 2
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %57
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000 x i32], ptr %58, i64 0, i64 %60
  store i32 %54, ptr %61, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %49
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

65:                                               ; preds = %8
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %3, align 4, !tbaa !5
  br label %4, !llvm.loop !11

69:                                               ; preds = %4
  %70 = load i32, ptr getelementptr inbounds ([1000 x i32], ptr getelementptr inbounds ([2 x [1000 x i32]], ptr @u, i64 0, i64 999), i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  ret i32 %70
}

; 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 = { 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 = !{!"int", !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}


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

@u = external dso_local local_unnamed_addr global [2 x [1000 x i32]], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
  br label %.peel.next

.peel.next:                                       ; preds = %.loopexit, %0
  %.016 = phi i32 [ 1, %0 ], [ %29, %.loopexit ]
  %1 = and i32 %.016, 1
  %.urem = xor i32 %1, 1
  %2 = zext nneg i32 %.urem to i64
  %3 = and i32 %.016, 1
  %4 = zext nneg i32 %3 to i64
  %5 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %2, i64 999
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %2, i64 0
  %8 = load i32, ptr %7, align 16, !tbaa !5
  %9 = add nsw i32 %8, %6
  %10 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %2, i64 1
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %9, %11
  %13 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %4, i64 0
  store i32 %12, ptr %13, align 16, !tbaa !5
  br label %14

14:                                               ; preds = %.peel.next, %14
  %indvars.iv = phi i64 [ 1, %.peel.next ], [ %indvars.iv.next, %14 ]
  %15 = shl i64 %indvars.iv, 32
  %sext = add i64 %15, -4294967296
  %16 = ashr exact i64 %sext, 32
  %17 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %2, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %2, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, %18
  %22 = icmp eq i64 %indvars.iv, 999
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = and i64 %indvars.iv.next, 4294967295
  %24 = select i1 %22, i64 0, i64 %23
  %25 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %2, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %21, %26
  %28 = getelementptr inbounds [2 x [1000 x i32]], ptr @u, i64 0, i64 %4, i64 %indvars.iv
  store i32 %27, ptr %28, align 4, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1000
  br i1 %exitcond.not, label %.loopexit, label %14, !llvm.loop !9

.loopexit:                                        ; preds = %14
  %29 = add nuw nsw i32 %.016, 1
  %exitcond19.not = icmp eq i32 %29, 1000
  br i1 %exitcond19.not, label %30, label %.peel.next, !llvm.loop !12

30:                                               ; preds = %.loopexit
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @u, i64 3996004), align 4, !tbaa !5
  ret i32 %31
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}
!12 = distinct !{!12, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass