; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/1134（高精度卡特兰数）.ll (ZNK6BigNumdvERKi)

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

%class.BigNum = type { [500 x i32], i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6BigNumC2Ev(ptr noundef nonnull align 4 dereferenceable(2004)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6BigNumdvERKi(ptr dead_on_unwind noalias writable sret(%class.BigNum) align 4 %0, ptr noundef nonnull align 4 dereferenceable(2004) %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8
  call void @_ZN6BigNumC2Ev(ptr noundef nonnull align 4 dereferenceable(2004) %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds %class.BigNum, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = sub nsw i32 %11, 1
  store i32 %12, ptr %7, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %49, %3
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %16, label %52

16:                                               ; preds = %13
  %17 = getelementptr inbounds %class.BigNum, ptr %9, i32 0, i32 0
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [500 x i32], ptr %17, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = mul nsw i32 %22, 10000
  %24 = add nsw i32 %21, %23
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = sdiv i32 %24, %26
  %28 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [500 x i32], ptr %28, i64 0, i64 %30
  store i32 %27, ptr %31, align 4, !tbaa !9
  %32 = getelementptr inbounds %class.BigNum, ptr %9, i32 0, i32 0
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [500 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = mul nsw i32 %37, 10000
  %39 = add nsw i32 %36, %38
  %40 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [500 x i32], ptr %40, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = mul nsw i32 %44, %46
  %48 = sub nsw i32 %39, %47
  store i32 %48, ptr %8, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %16
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !13

52:                                               ; preds = %13
  %53 = getelementptr inbounds %class.BigNum, ptr %9, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 1
  store i32 %54, ptr %55, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %71, %52
  %57 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %58 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !11
  %60 = sub nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [500 x i32], ptr %57, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = icmp eq i32 %63, 0
  br i1 %64, label %65, label %69

65:                                               ; preds = %56
  %66 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = icmp sgt i32 %67, 1
  br label %69

69:                                               ; preds = %65, %56
  %70 = phi i1 [ false, %56 ], [ %68, %65 ]
  br i1 %70, label %71, label %75

71:                                               ; preds = %69
  %72 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !11
  %74 = add nsw i32 %73, -1
  store i32 %74, ptr %72, align 4, !tbaa !11
  br label %56, !llvm.loop !15

75:                                               ; preds = %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 2000}
!12 = !{!"_ZTS6BigNum", !7, i64 0, !10, i64 2000}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

%class.BigNum = type { [500 x i32], i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6BigNumC2Ev(ptr noundef nonnull align 4 dereferenceable(2004)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK6BigNumdvERKi(ptr dead_on_unwind noalias nonnull writable sret(%class.BigNum) align 4 %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(2004) %1, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4) %2) local_unnamed_addr #0 align 2 {
  tail call void @_ZN6BigNumC2Ev(ptr noundef nonnull align 4 dereferenceable(2004) %0)
  %4 = getelementptr inbounds i8, ptr %1, i64 2000
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %7 = load i32, ptr %2, align 4, !tbaa !10
  %8 = zext nneg i32 %5 to i64
  %xtraiter = and i64 %8, 1
  %9 = icmp eq i32 %5, 1
  br i1 %9, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %8, 2147483646
  br label %10

10:                                               ; preds = %10, %.lr.ph.new
  %indvars.iv = phi i64 [ %8, %.lr.ph.new ], [ %indvars.iv.next.1, %10 ]
  %.013 = phi i32 [ 0, %.lr.ph.new ], [ %.recomposed18, %10 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %10 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %11 = getelementptr inbounds [500 x i32], ptr %1, i64 0, i64 %indvars.iv.next
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = mul nsw i32 %.013, 10000
  %14 = add nsw i32 %12, %13
  %15 = sdiv i32 %14, %7
  %16 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %indvars.iv.next
  store i32 %15, ptr %16, align 4, !tbaa !10
  %17 = mul nsw i32 %15, %7
  %.recomposed = srem i32 %14, %7
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, -2
  %18 = getelementptr inbounds [500 x i32], ptr %1, i64 0, i64 %indvars.iv.next.1
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = mul nsw i32 %.recomposed, 10000
  %21 = add nsw i32 %19, %20
  %22 = sdiv i32 %21, %7
  %23 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %indvars.iv.next.1
  store i32 %22, ptr %23, align 4, !tbaa !10
  %24 = mul nsw i32 %22, %7
  %.recomposed18 = srem i32 %21, %7
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %10, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %10
  %25 = mul nsw i32 %.recomposed18, 10000
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph
  %indvars.iv.unr = phi i64 [ %8, %.lr.ph ], [ %indvars.iv.next.1, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.013.unr = phi i32 [ 0, %.lr.ph ], [ %25, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %indvars.iv.next.epil = add nsw i64 %indvars.iv.unr, -1
  %26 = getelementptr inbounds [500 x i32], ptr %1, i64 0, i64 %indvars.iv.next.epil
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = add nsw i32 %27, %.013.unr
  %29 = sdiv i32 %28, %7
  %30 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %indvars.iv.next.epil
  store i32 %29, ptr %30, align 4, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %3
  %31 = getelementptr inbounds i8, ptr %0, i64 2000
  %32 = sext i32 %5 to i64
  br label %33

33:                                               ; preds = %33, %._crit_edge
  %indvars.iv15 = phi i64 [ %indvars.iv.next16, %33 ], [ %32, %._crit_edge ]
  %34 = trunc nsw i64 %indvars.iv15 to i32
  store i32 %34, ptr %31, align 4, !tbaa !5
  %indvars.iv.next16 = add nsw i64 %indvars.iv15, -1
  %35 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %indvars.iv.next16
  %36 = load i32, ptr %35, align 4, !tbaa !10
  %37 = icmp eq i32 %36, 0
  %38 = icmp sgt i64 %indvars.iv15, 1
  %39 = and i1 %38, %37
  br i1 %39, label %33, label %40, !llvm.loop !13

40:                                               ; preds = %33
  ret void
}

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

!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, !9, i64 2000}
!6 = !{!"_ZTS6BigNum", !7, i64 0, !9, i64 2000}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,DivRemPairsPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass