; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (2132)

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

@a = external dso_local global [100005 x i64], align 16
@i = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  store i64 1, ptr getelementptr inbounds ([100005 x i64], ptr @a, i64 0, i64 1), align 8, !tbaa !5
  store i64 3, ptr getelementptr inbounds ([100005 x i64], ptr @a, i64 0, i64 2), align 16, !tbaa !5
  store i64 3, ptr @i, align 8, !tbaa !5
  br label %2

2:                                                ; preds = %32, %0
  %3 = load i64, ptr @i, align 8, !tbaa !5
  %4 = icmp slt i64 %3, 100002
  br i1 %4, label %5, label %35

5:                                                ; preds = %2
  %6 = load i64, ptr @i, align 8, !tbaa !5
  %7 = srem i64 %6, 3
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %9, label %22

9:                                                ; preds = %5
  %10 = load i64, ptr @i, align 8, !tbaa !5
  %11 = sub nsw i64 %10, 1
  %12 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = load i64, ptr @i, align 8, !tbaa !5
  %15 = load i64, ptr @i, align 8, !tbaa !5
  %16 = mul nsw i64 %14, %15
  %17 = load i64, ptr @i, align 8, !tbaa !5
  %18 = mul nsw i64 %16, %17
  %19 = add nsw i64 %13, %18
  %20 = load i64, ptr @i, align 8, !tbaa !5
  %21 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %20
  store i64 %19, ptr %21, align 8, !tbaa !5
  br label %31

22:                                               ; preds = %5
  %23 = load i64, ptr @i, align 8, !tbaa !5
  %24 = sub nsw i64 %23, 1
  %25 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = load i64, ptr @i, align 8, !tbaa !5
  %28 = add nsw i64 %26, %27
  %29 = load i64, ptr @i, align 8, !tbaa !5
  %30 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %29
  store i64 %28, ptr %30, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %22, %9
  br label %32

32:                                               ; preds = %31
  %33 = load i64, ptr @i, align 8, !tbaa !5
  %34 = add nsw i64 %33, 1
  store i64 %34, ptr @i, align 8, !tbaa !5
  br label %2, !llvm.loop !9

35:                                               ; preds = %2
  br label %36

36:                                               ; preds = %44, %35
  %37 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load i64, ptr @n, align 8, !tbaa !5
  %41 = icmp sge i64 %40, 0
  br label %42

42:                                               ; preds = %39, %36
  %43 = phi i1 [ false, %36 ], [ %41, %39 ]
  br i1 %43, label %44, label %49

44:                                               ; preds = %42
  %45 = load i64, ptr @n, align 8, !tbaa !5
  %46 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %47)
  br label %36, !llvm.loop !11

49:                                               ; preds = %42
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

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


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

@a = external dso_local local_unnamed_addr global [100005 x i64], align 16
@i = external dso_local local_unnamed_addr global i64, align 8
@n = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  store i64 1, ptr getelementptr inbounds (i8, ptr @a, i64 8), align 8, !tbaa !5
  store i64 3, ptr getelementptr inbounds (i8, ptr @a, i64 16), align 16, !tbaa !5
  br label %6

.preheader:                                       ; preds = %6
  store i64 100002, ptr @i, align 8, !tbaa !5
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = icmp ne i32 %1, 0
  %3 = load i64, ptr @n, align 8
  %4 = icmp sgt i64 %3, -1
  %5 = select i1 %2, i1 %4, i1 false
  br i1 %5, label %.lr.ph, label %._crit_edge

6:                                                ; preds = %14, %0
  %7 = phi i64 [ 3, %0 ], [ %.sink.1, %14 ]
  %storemerge2 = phi i64 [ 3, %0 ], [ %20, %14 ]
  %8 = urem i64 %storemerge2, 3
  %9 = icmp eq i64 %8, 0
  %10 = mul nuw nsw i64 %storemerge2, %storemerge2
  %11 = select i1 %9, i64 %10, i64 1
  %.pn = mul nuw nsw i64 %storemerge2, %11
  %.sink = add nuw nsw i64 %7, %.pn
  %12 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %storemerge2
  store i64 %.sink, ptr %12, align 8
  %13 = add nuw nsw i64 %storemerge2, 1
  %exitcond.not = icmp eq i64 %13, 100002
  br i1 %exitcond.not, label %.preheader, label %14, !llvm.loop !9

14:                                               ; preds = %6
  %15 = urem i64 %13, 3
  %16 = icmp eq i64 %15, 0
  %17 = mul nuw nsw i64 %13, %13
  %18 = select i1 %16, i64 %17, i64 1
  %.pn.1 = mul nuw nsw i64 %13, %18
  %.sink.1 = add nuw nsw i64 %.sink, %.pn.1
  %19 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %13
  store i64 %.sink.1, ptr %19, align 8
  %20 = add nuw nsw i64 %storemerge2, 2
  br label %6

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %21 = phi i64 [ %27, %.lr.ph ], [ %3, %.preheader ]
  %22 = getelementptr inbounds [100005 x i64], ptr @a, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %23)
  %25 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %26 = icmp ne i32 %25, 0
  %27 = load i64, ptr @n, align 8
  %28 = icmp sgt i64 %27, -1
  %29 = select i1 %26, i1 %28, i1 false
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  ret i32 0
}

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

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

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

!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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass