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

; 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 uwtable
define dso_local void @_ZNK6BigNumplERKS_(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(2004) %2) #1 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 @_ZN6BigNumC1ERKS_(ptr noundef nonnull align 4 dereferenceable(2004) %0, ptr noundef nonnull align 4 dereferenceable(2004) %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.BigNum, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.BigNum, ptr %9, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp sgt i32 %12, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.BigNum, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !9
  br label %23

20:                                               ; preds = %3
  %21 = getelementptr inbounds %class.BigNum, ptr %9, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %20, %16
  %24 = phi i32 [ %19, %16 ], [ %22, %20 ]
  store i32 %24, ptr %8, align 4, !tbaa !12
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %63, %23
  %26 = load i32, ptr %7, align 4, !tbaa !12
  %27 = load i32, ptr %8, align 4, !tbaa !12
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %66

29:                                               ; preds = %25
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.BigNum, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %7, align 4, !tbaa !12
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [500 x i32], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %37 = load i32, ptr %7, align 4, !tbaa !12
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [500 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !12
  %41 = add nsw i32 %40, %35
  store i32 %41, ptr %39, align 4, !tbaa !12
  %42 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %43 = load i32, ptr %7, align 4, !tbaa !12
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [500 x i32], ptr %42, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = icmp sgt i32 %46, 9999
  br i1 %47, label %48, label %62

48:                                               ; preds = %29
  %49 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %50 = load i32, ptr %7, align 4, !tbaa !12
  %51 = add nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [500 x i32], ptr %49, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !12
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %53, align 4, !tbaa !12
  %56 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %57 = load i32, ptr %7, align 4, !tbaa !12
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [500 x i32], ptr %56, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !12
  %61 = sub nsw i32 %60, 10000
  store i32 %61, ptr %59, align 4, !tbaa !12
  br label %62

62:                                               ; preds = %48, %29
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %7, align 4, !tbaa !12
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !12
  br label %25, !llvm.loop !13

66:                                               ; preds = %25
  %67 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 0
  %68 = load i32, ptr %8, align 4, !tbaa !12
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [500 x i32], ptr %67, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !12
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %77

73:                                               ; preds = %66
  %74 = load i32, ptr %8, align 4, !tbaa !12
  %75 = add nsw i32 %74, 1
  %76 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 1
  store i32 %75, ptr %76, align 4, !tbaa !9
  br label %80

77:                                               ; preds = %66
  %78 = load i32, ptr %8, align 4, !tbaa !12
  %79 = getelementptr inbounds %class.BigNum, ptr %0, i32 0, i32 1
  store i32 %78, ptr %79, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %77, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

declare void @_ZN6BigNumC1ERKS_(ptr, ptr)

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

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

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

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %. to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph._crit_edge
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %15, %.lr.ph._crit_edge ]
  %9 = getelementptr inbounds [500 x i32], ptr %2, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = add nsw i32 %12, %10
  store i32 %13, ptr %11, align 4, !tbaa !10
  %14 = icmp sgt i32 %13, 9999
  %15 = add nuw nsw i64 %indvars.iv, 1
  br i1 %14, label %16, label %.lr.ph._crit_edge

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %15
  %18 = load i32, ptr %17, align 4, !tbaa !10
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %17, align 4, !tbaa !10
  %20 = add nsw i32 %13, -10000
  store i32 %20, ptr %11, align 4, !tbaa !10
  br label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %16
  %exitcond.not = icmp eq i64 %15, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph._crit_edge, %3
  %21 = sext i32 %. to i64
  %22 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !10
  %.not = icmp ne i32 %23, 0
  %24 = zext i1 %.not to i32
  %spec.select = add nsw i32 %., %24
  %25 = getelementptr inbounds i8, ptr %0, i64 2000
  store i32 %spec.select, ptr %25, align 4
  ret void
}

declare void @_ZN6BigNumC1ERKS_(ptr, ptr) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass