; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5794.ll (Z4initv)

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

@all = external dso_local global [110129 x i64], align 16
@f = external dso_local global [110129 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4initv() #0 {
  %1 = alloca i32, align 4
  store i64 1, ptr getelementptr inbounds ([110129 x i64], ptr @all, i64 0, i64 1), align 8, !tbaa !5
  store i64 1, ptr @f, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds ([110129 x i64], ptr @f, i64 0, i64 1), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 2, ptr %1, align 4, !tbaa !9
  br label %2

2:                                                ; preds = %34, %0
  %3 = load i32, ptr %1, align 4, !tbaa !9
  %4 = sext i32 %3 to i64
  %5 = icmp sle i64 %4, 110119
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %37

7:                                                ; preds = %2
  %8 = load i32, ptr %1, align 4, !tbaa !9
  %9 = sub nsw i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [110129 x i64], ptr @f, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = load i32, ptr %1, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %12, %14
  %16 = srem i64 %15, 110119
  %17 = load i32, ptr %1, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [110129 x i64], ptr @f, i64 0, i64 %18
  store i64 %16, ptr %19, align 8, !tbaa !5
  %20 = load i32, ptr %1, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = srem i64 110119, %21
  %23 = getelementptr inbounds [110129 x i64], ptr @all, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = load i32, ptr %1, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = sdiv i64 110119, %26
  %28 = sub nsw i64 110119, %27
  %29 = mul nsw i64 %24, %28
  %30 = srem i64 %29, 110119
  %31 = load i32, ptr %1, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [110129 x i64], ptr @all, i64 0, i64 %32
  store i64 %30, ptr %33, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %7
  %35 = load i32, ptr %1, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %1, align 4, !tbaa !9
  br label %2, !llvm.loop !11

37:                                               ; preds = %6
  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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@all = external dso_local local_unnamed_addr global [110129 x i64], align 16
@f = external dso_local local_unnamed_addr global [110129 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  store i64 1, ptr getelementptr inbounds (i8, ptr @all, i64 8), align 8, !tbaa !5
  store i64 1, ptr @f, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @f, i64 8), align 8, !tbaa !5
  br label %2

1:                                                ; preds = %2
  ret void

2:                                                ; preds = %0, %2
  %3 = phi i64 [ 1, %0 ], [ %5, %2 ]
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %2 ]
  %4 = mul nsw i64 %3, %indvars.iv
  %5 = srem i64 %4, 110119
  %6 = getelementptr inbounds [110129 x i64], ptr @f, i64 0, i64 %indvars.iv
  store i64 %5, ptr %6, align 8, !tbaa !5
  %7 = trunc nuw nsw i64 %indvars.iv to i32
  %8 = urem i32 110119, %7
  %.zext = zext nneg i32 %8 to i64
  %9 = getelementptr inbounds [110129 x i64], ptr @all, i64 0, i64 %.zext
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = udiv i32 110119, %7
  %narrow = sub nuw nsw i32 110119, %11
  %12 = zext nneg i32 %narrow to i64
  %13 = mul nsw i64 %10, %12
  %14 = srem i64 %13, 110119
  %15 = getelementptr inbounds [110129 x i64], ptr @all, i64 0, i64 %indvars.iv
  store i64 %14, ptr %15, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 110120
  br i1 %exitcond.not, label %1, label %2, !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"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass