; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5728.ll (Z8GetEulerv)

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

@phi = external dso_local global [10000005 x i32], align 16
@sum = external dso_local global [10000005 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8GetEulerv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.memset.p0.i64(ptr align 16 @phi, i8 0, i64 40000020, i1 false)
  store i32 1, ptr getelementptr inbounds ([10000005 x i32], ptr @phi, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 2, ptr %1, align 4, !tbaa !5
  br label %5

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

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

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %50, label %15

15:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %16 = load i32, ptr %1, align 4, !tbaa !5
  store i32 %16, ptr %3, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %45, %15
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = icmp sle i32 %18, 10000000
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %17
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %32, label %27

27:                                               ; preds = %21
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %27, %21
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = sdiv i32 %36, %37
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = mul nsw i32 %38, %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %43
  store i32 %41, ptr %44, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %32
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !9

49:                                               ; preds = %20
  br label %50

50:                                               ; preds = %49, %9
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !11

54:                                               ; preds = %8
  store i64 1, ptr getelementptr inbounds ([10000005 x i64], ptr @sum, i64 0, i64 1), align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %75, %54
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = icmp sle i32 %56, 10000000
  br i1 %57, label %59, label %58

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

59:                                               ; preds = %55
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = sub nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10000005 x i64], ptr @sum, i64 0, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !12
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = add nsw i64 %64, %69
  %71 = srem i64 %70, 1000000007
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [10000005 x i64], ptr @sum, i64 0, i64 %73
  store i64 %71, ptr %74, align 8, !tbaa !12
  br label %75

75:                                               ; preds = %59
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %4, align 4, !tbaa !5
  br label %55, !llvm.loop !14

78:                                               ; preds = %58
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !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"

@phi = external dso_local local_unnamed_addr global [10000005 x i32], align 16
@sum = external dso_local local_unnamed_addr global [10000005 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z8GetEulerv() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40000020) @phi, i8 0, i64 40000020, i1 false)
  store i32 1, ptr getelementptr inbounds (i8, ptr @phi, i64 4), align 4, !tbaa !5
  br label %2

1:                                                ; preds = %.loopexit
  store i64 1, ptr getelementptr inbounds (i8, ptr @sum, i64 8), align 8, !tbaa !9
  br label %16

2:                                                ; preds = %0, %.loopexit
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %.loopexit ]
  %3 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %indvars.iv
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %2
  %5 = trunc nuw nsw i64 %indvars.iv to i32
  %6 = trunc i64 %indvars.iv to i32
  %7 = add i32 %6, -1
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %indvars.iv26 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next27, %8 ]
  %9 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %indvars.iv26
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not21 = icmp eq i32 %10, 0
  %11 = trunc nuw nsw i64 %indvars.iv26 to i32
  %spec.select = select i1 %.not21, i32 %11, i32 %10
  %12 = sdiv i32 %spec.select, %5
  %13 = mul nsw i32 %12, %7
  store i32 %13, ptr %9, align 4, !tbaa !5
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, %indvars.iv
  %14 = icmp ult i64 %indvars.iv.next27, 10000001
  br i1 %14, label %8, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %8, %2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 10000001
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !13

15:                                               ; preds = %16
  ret void

16:                                               ; preds = %24, %1
  %17 = phi i64 [ 1, %1 ], [ %29, %24 ]
  %indvars.iv30 = phi i64 [ 2, %1 ], [ %indvars.iv.next31.1, %24 ]
  %18 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %indvars.iv30
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = add nsw i64 %17, %20
  %22 = srem i64 %21, 1000000007
  %23 = getelementptr inbounds [10000005 x i64], ptr @sum, i64 0, i64 %indvars.iv30
  store i64 %22, ptr %23, align 16, !tbaa !9
  %exitcond33.not = icmp eq i64 %indvars.iv30, 10000000
  br i1 %exitcond33.not, label %15, label %24, !llvm.loop !14

24:                                               ; preds = %16
  %indvars.iv.next31 = or disjoint i64 %indvars.iv30, 1
  %25 = getelementptr inbounds [10000005 x i32], ptr @phi, i64 0, i64 %indvars.iv.next31
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = add nsw i64 %22, %27
  %29 = srem i64 %28, 1000000007
  %30 = getelementptr inbounds [10000005 x i64], ptr @sum, i64 0, i64 %indvars.iv.next31
  store i64 %29, ptr %30, align 8, !tbaa !9
  %indvars.iv.next31.1 = add nuw nsw i64 %indvars.iv30, 2
  br label %16
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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}


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