; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/Random/CNPIIM/A.ll (Z3prev)

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

@ans = external dso_local global [6250001 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prev() #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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 6250001, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %29, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %32

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %12 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %12, ptr %4, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %24, %11
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %28

18:                                               ; preds = %13
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %21, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %13, !llvm.loop !11

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !13

32:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %49, %32
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %52

38:                                               ; preds = %33
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = add nsw i64 %47, %43
  store i64 %48, ptr %46, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %38
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !14

52:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

@ans = external dso_local local_unnamed_addr global [6250001 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3prev() local_unnamed_addr #0 {
  br label %.preheader16

.preheader16:                                     ; preds = %6, %0
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.1, %6 ]
  br label %7

.preheader16.1:                                   ; preds = %7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %1

1:                                                ; preds = %1, %.preheader16.1
  %indvars.iv20.1 = phi i64 [ %indvars.iv.next, %.preheader16.1 ], [ %indvars.iv.next21.1, %1 ]
  %2 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %indvars.iv20.1
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = add nsw i64 %3, 1
  store i64 %4, ptr %2, align 8, !tbaa !5
  %indvars.iv.next21.1 = add nuw nsw i64 %indvars.iv20.1, %indvars.iv.next
  %5 = icmp ult i64 %indvars.iv.next21.1, 6250001
  br i1 %5, label %1, label %6, !llvm.loop !9

6:                                                ; preds = %1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 6250001
  br i1 %exitcond.not.1, label %.preheader.preheader, label %.preheader16, !llvm.loop !11

.preheader.preheader:                             ; preds = %6
  %.pre = load i64, ptr @ans, align 16, !tbaa !5
  br label %.preheader

7:                                                ; preds = %.preheader16, %7
  %indvars.iv20 = phi i64 [ %indvars.iv, %.preheader16 ], [ %indvars.iv.next21, %7 ]
  %8 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %indvars.iv20
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = add nsw i64 %9, 1
  store i64 %10, ptr %8, align 8, !tbaa !5
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, %indvars.iv
  %11 = icmp ult i64 %indvars.iv.next21, 6250001
  br i1 %11, label %7, label %.preheader16.1, !llvm.loop !9

12:                                               ; preds = %.preheader
  ret void

.preheader:                                       ; preds = %.preheader, %.preheader.preheader
  %13 = phi i64 [ %.pre, %.preheader.preheader ], [ %28, %.preheader ]
  %indvars.iv24 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next25.4, %.preheader ]
  %14 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %indvars.iv24
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i64 %15, %13
  store i64 %16, ptr %14, align 8, !tbaa !5
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %17 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next25
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = add nsw i64 %18, %16
  store i64 %19, ptr %17, align 8, !tbaa !5
  %indvars.iv.next25.1 = add nuw nsw i64 %indvars.iv24, 2
  %20 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next25.1
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = add nsw i64 %21, %19
  store i64 %22, ptr %20, align 8, !tbaa !5
  %indvars.iv.next25.2 = add nuw nsw i64 %indvars.iv24, 3
  %23 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next25.2
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = add nsw i64 %24, %22
  store i64 %25, ptr %23, align 8, !tbaa !5
  %indvars.iv.next25.3 = add nuw nsw i64 %indvars.iv24, 4
  %26 = getelementptr inbounds [6250001 x i64], ptr @ans, i64 0, i64 %indvars.iv.next25.3
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = add nsw i64 %27, %25
  store i64 %28, ptr %26, align 8, !tbaa !5
  %indvars.iv.next25.4 = add nuw nsw i64 %indvars.iv24, 5
  %exitcond27.not.4 = icmp eq i64 %indvars.iv.next25.4, 6250001
  br i1 %exitcond27.not.4, label %12, label %.preheader, !llvm.loop !12
}

attributes #0 = { mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass