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

; 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 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.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6BigNumC2EPKc(ptr noundef nonnull align 4 dereferenceable(2004) %0, ptr noundef %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %12 = getelementptr inbounds %class.BigNum, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [500 x i32], ptr %12, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 4 %13, i8 0, i64 2000, i1 false)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #5
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = sdiv i32 %17, 4
  %19 = getelementptr inbounds %class.BigNum, ptr %11, i32 0, i32 1
  store i32 %18, ptr %19, align 4, !tbaa !11
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = srem i32 %20, 4
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %2
  %24 = getelementptr inbounds %class.BigNum, ptr %11, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %24, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %23, %2
  store i32 0, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = sub nsw i32 %28, 1
  store i32 %29, ptr %9, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %68, %27
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %33, label %71

33:                                               ; preds = %30
  store i32 0, ptr %5, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sub nsw i32 %34, 4
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %33
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %39, %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %41 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %41, ptr %10, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %58, %40
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %61

47:                                               ; preds = %42
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = mul nsw i32 %48, 10
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = sext i8 %54 to i32
  %56 = add nsw i32 %49, %55
  %57 = sub nsw i32 %56, 48
  store i32 %57, ptr %5, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %47
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %10, align 4, !tbaa !9
  br label %42, !llvm.loop !14

61:                                               ; preds = %46
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = getelementptr inbounds %class.BigNum, ptr %11, i32 0, i32 0
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !9
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds [500 x i32], ptr %63, i64 0, i64 %66
  store i32 %62, ptr %67, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %61
  %69 = load i32, ptr %9, align 4, !tbaa !9
  %70 = sub nsw i32 %69, 4
  store i32 %70, ptr %9, align 4, !tbaa !9
  br label %30, !llvm.loop !16

71:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { nounwind willreturn memory(read) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

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

; Function Attrs: mustprogress nofree nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN6BigNumC2EPKc(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(2004) %0, ptr nocapture noundef readonly %1) unnamed_addr #1 align 2 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(2000) %0, i8 0, i64 2000, i1 false)
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %4 = trunc i64 %3 to i32
  %5 = sdiv i32 %4, 4
  %6 = getelementptr inbounds i8, ptr %0, i64 2000
  %7 = and i32 %4, 3
  %.not = icmp ne i32 %7, 0
  %8 = zext i1 %.not to i32
  %spec.select = add nsw i32 %5, %8
  store i32 %spec.select, ptr %6, align 4, !tbaa !5
  %9 = icmp sgt i32 %4, 0
  br i1 %9, label %.lr.ph27.preheader, label %._crit_edge28

.lr.ph27.preheader:                               ; preds = %2
  %10 = shl i64 %3, 32
  %sext = add nsw i64 %10, -4294967296
  %11 = ashr exact i64 %sext, 32
  br label %.lr.ph27

.lr.ph27:                                         ; preds = %.lr.ph27.preheader, %._crit_edge
  %indvars.iv32 = phi i64 [ 0, %.lr.ph27.preheader ], [ %indvars.iv.next33, %._crit_edge ]
  %indvars.iv30 = phi i64 [ %11, %.lr.ph27.preheader ], [ %indvars.iv.next31, %._crit_edge ]
  %12 = trunc nuw nsw i64 %indvars.iv30 to i32
  %umax = tail call i32 @llvm.umax.i32(i32 %12, i32 3)
  %indvars.iv.next31 = add nsw i64 %indvars.iv30, -4
  %spec.store.select = add nsw i32 %umax, -3
  %13 = sext i32 %spec.store.select to i64
  %.not2021 = icmp slt i64 %indvars.iv30, %13
  br i1 %.not2021, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph27
  %14 = sext i32 %umax to i64
  %15 = add nsw i64 %14, -3
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph27
  %.018.lcssa = phi i32 [ 0, %.lr.ph27 ], [ %23, %.lr.ph ]
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %16 = getelementptr inbounds [500 x i32], ptr %0, i64 0, i64 %indvars.iv32
  store i32 %.018.lcssa, ptr %16, align 4, !tbaa !10
  %17 = icmp sgt i64 %indvars.iv30, 3
  br i1 %17, label %.lr.ph27, label %._crit_edge28, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %15, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.01822 = phi i32 [ 0, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %18 = mul nsw i32 %.01822, 10
  %19 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %20 = load i8, ptr %19, align 1, !tbaa !13
  %21 = sext i8 %20 to i32
  %22 = add i32 %18, -48
  %23 = add i32 %22, %21
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %.not20.not = icmp slt i64 %indvars.iv, %indvars.iv30
  br i1 %.not20.not, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge28:                                    ; preds = %._crit_edge, %2
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nofree nounwind memory(argmem: readwrite) 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 nofree nounwind willreturn memory(argmem: read) "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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