; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/1695 (容斥原理).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"

@euler = external dso_local global [100010 x i64], align 16
@num = external dso_local global [100010 x i32], align 16
@p = external dso_local global [100010 x [20 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4initv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i64 1, ptr getelementptr inbounds ([100010 x i64], ptr @euler, 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 %4

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

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

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

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

16:                                               ; preds = %58, %14
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 100010
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %16
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %32, label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %30
  store i64 %28, ptr %31, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %26, %20
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = load i32, ptr %1, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %36, %39
  %41 = load i32, ptr %1, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = sdiv i64 %40, %42
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %45
  store i64 %43, ptr %46, align 8, !tbaa !5
  %47 = load i32, ptr %1, align 4, !tbaa !9
  %48 = load i32, ptr %3, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100010 x [20 x i32]], ptr @p, i64 0, i64 %49
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100010 x i32], ptr @num, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %53, align 4, !tbaa !9
  %56 = sext i32 %54 to i64
  %57 = getelementptr inbounds [20 x i32], ptr %50, i64 0, i64 %56
  store i32 %47, ptr %57, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %32
  %59 = load i32, ptr %1, align 4, !tbaa !9
  %60 = load i32, ptr %3, align 4, !tbaa !9
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %3, align 4, !tbaa !9
  br label %16, !llvm.loop !11

62:                                               ; preds = %19
  br label %63

63:                                               ; preds = %62, %8
  %64 = load i32, ptr %1, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !5
  %69 = load i32, ptr %1, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !5
  %73 = add nsw i64 %72, %68
  store i64 %73, ptr %71, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %63
  %75 = load i32, ptr %1, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %1, align 4, !tbaa !9
  br label %4, !llvm.loop !13

77:                                               ; preds = %7
  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"}
!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"

@euler = external dso_local local_unnamed_addr global [100010 x i64], align 16
@num = external dso_local local_unnamed_addr global [100010 x i32], align 16
@p = external dso_local local_unnamed_addr global [100010 x [20 x i32]], 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 @euler, i64 8), align 8, !tbaa !5
  br label %2

1:                                                ; preds = %.loopexit
  ret void

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

.lr.ph:                                           ; preds = %2
  %6 = trunc nuw nsw i64 %indvars.iv to i32
  br label %7

7:                                                ; preds = %.lr.ph, %7
  %indvars.iv24 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next25, %7 ]
  %8 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %indvars.iv24
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %.not20 = icmp eq i64 %9, 0
  %spec.select = select i1 %.not20, i64 %indvars.iv24, i64 %9
  %10 = mul nsw i64 %spec.select, %5
  %11 = sdiv i64 %10, %indvars.iv
  store i64 %11, ptr %8, align 8, !tbaa !5
  %12 = getelementptr inbounds [100010 x i32], ptr @num, i64 0, i64 %indvars.iv24
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !9
  %15 = sext i32 %13 to i64
  %16 = getelementptr inbounds [100010 x [20 x i32]], ptr @p, i64 0, i64 %indvars.iv24, i64 %15
  store i32 %6, ptr %16, align 4, !tbaa !9
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, %indvars.iv
  %17 = icmp ult i64 %indvars.iv.next25, 100010
  br i1 %17, label %7, label %.loopexit.loopexit, !llvm.loop !11

.loopexit.loopexit:                               ; preds = %7
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %2, %.loopexit.loopexit
  %18 = phi i64 [ %.pre, %.loopexit.loopexit ], [ %4, %2 ]
  %19 = getelementptr inbounds [100010 x i64], ptr @euler, i64 0, i64 %5
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = add nsw i64 %18, %20
  store i64 %21, ptr %3, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100010
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !13
}

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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass