; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LONG/NOV15/SMPLSUM (A)

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

@dp = external dso_local global [10000000 x i64], align 16

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

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

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

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

11:                                               ; preds = %25, %9
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 10000000
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = mul nsw i32 %16, %17
  %19 = sext i32 %18 to i64
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10000000 x i64], ptr @dp, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = add nsw i64 %23, %19
  store i64 %24, ptr %22, align 8, !tbaa !9
  br label %25

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

29:                                               ; preds = %14
  br label %30

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

33:                                               ; preds = %8
  ret i32 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

attributes #0 = { mustprogress norecurse 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}


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

@dp = external dso_local local_unnamed_addr global [10000000 x i64], align 16

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

.preheader:                                       ; preds = %9, %0
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next.1, %9 ]
  %1 = mul nuw nsw i64 %indvars.iv, %indvars.iv
  br label %10

2:                                                ; preds = %9
  ret i32 0

.preheader.1:                                     ; preds = %10
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %3 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  br label %4

4:                                                ; preds = %4, %.preheader.1
  %indvars.iv12.1 = phi i64 [ %indvars.iv.next, %.preheader.1 ], [ %indvars.iv.next13.1, %4 ]
  %5 = getelementptr inbounds [10000000 x i64], ptr @dp, i64 0, i64 %indvars.iv12.1
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = add nsw i64 %6, %3
  store i64 %7, ptr %5, align 8, !tbaa !5
  %indvars.iv.next13.1 = add nuw nsw i64 %indvars.iv12.1, %indvars.iv.next
  %8 = icmp ult i64 %indvars.iv.next13.1, 10000000
  br i1 %8, label %4, label %9, !llvm.loop !9

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

10:                                               ; preds = %.preheader, %10
  %indvars.iv12 = phi i64 [ %indvars.iv, %.preheader ], [ %indvars.iv.next13, %10 ]
  %11 = getelementptr inbounds [10000000 x i64], ptr @dp, i64 0, i64 %indvars.iv12
  %12 = load i64, ptr %11, align 16, !tbaa !5
  %13 = add nsw i64 %12, %1
  store i64 %13, ptr %11, align 16, !tbaa !5
  %indvars.iv.next13 = add nuw nsw i64 %indvars.iv12, %indvars.iv
  %14 = icmp ult i64 %indvars.iv.next13, 10000000
  br i1 %14, label %10, label %.preheader.1, !llvm.loop !9
}

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}


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