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

; 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZrsRSiR6BigNum(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(2004) %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [40 x i8], align 16
  %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
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 -1, ptr %6, align 4, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 0
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 0
  %16 = call i64 @strlen(ptr noundef %15) #5
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  store i32 %19, ptr %6, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %51, %2
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp sge i32 %21, 0
  br i1 %22, label %23, label %60

23:                                               ; preds = %20
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 1, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %44, %23
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 4
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp sge i32 %28, 0
  br label %30

30:                                               ; preds = %27, %24
  %31 = phi i1 [ false, %24 ], [ %29, %27 ]
  br i1 %31, label %33, label %32

32:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %51

33:                                               ; preds = %30
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [40 x i8], ptr %5, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = sub nsw i32 %38, 48
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = mul nsw i32 %39, %40
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = add nsw i32 %42, %41
  store i32 %43, ptr %9, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %33
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %11, align 4, !tbaa !9
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %6, align 4, !tbaa !9
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = mul nsw i32 %49, 10
  store i32 %50, ptr %10, align 4, !tbaa !9
  br label %24, !llvm.loop !12

51:                                               ; preds = %32
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.BigNum, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [500 x i32], ptr %54, i64 0, i64 %56
  store i32 %52, ptr %57, align 4, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %20, !llvm.loop !14

60:                                               ; preds = %20
  %61 = load i32, ptr %8, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %8, align 4, !tbaa !9
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %class.BigNum, ptr %63, i32 0, i32 1
  store i32 %61, ptr %64, align 4, !tbaa !15
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  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 40, ptr %5) #4
  ret ptr %65
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !10, i64 2000}
!16 = !{!"_ZTS6BigNum", !7, i64 0, !10, i64 2000}


; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZrsRSiR6BigNum(ptr noundef nonnull returned align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(2004) %1) local_unnamed_addr #2 {
  %3 = alloca [40 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %3)
  %5 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #5
  %6 = trunc i64 %5 to i32
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %2
  %8 = add i64 %5, 4294967295
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %16
  %indvars.iv30 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next31, %16 ]
  %.02025 = phi i64 [ %8, %.preheader.preheader ], [ %indvars.iv.next.lcssa, %16 ]
  %9 = and i64 %.02025, 4294967295
  %10 = getelementptr inbounds [40 x i8], ptr %3, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = sext i8 %11 to i32
  %13 = add nsw i32 %12, -48
  %indvars.iv.next = add nsw i64 %9, -1
  %14 = trunc i64 %.02025 to i32
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %18, label %16, !llvm.loop !8

16:                                               ; preds = %36, %27, %18, %.preheader
  %.lcssa36 = phi i32 [ %13, %.preheader ], [ %24, %18 ], [ %33, %27 ], [ %42, %36 ]
  %indvars.iv.next.lcssa = phi i64 [ %indvars.iv.next, %.preheader ], [ %indvars.iv.next.1, %18 ], [ %indvars.iv.next.2, %27 ], [ %indvars.iv.next.3, %36 ]
  %.lcssa = phi i1 [ %15, %.preheader ], [ %26, %18 ], [ %35, %27 ], [ %44, %36 ]
  %17 = getelementptr inbounds [500 x i32], ptr %1, i64 0, i64 %indvars.iv30
  store i32 %.lcssa36, ptr %17, align 4, !tbaa !10
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  br i1 %.lcssa, label %.preheader, label %._crit_edge.loopexit, !llvm.loop !12

18:                                               ; preds = %.preheader
  %19 = getelementptr inbounds [40 x i8], ptr %3, i64 0, i64 %indvars.iv.next
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = sext i8 %20 to i32
  %22 = mul nsw i32 %21, 10
  %23 = add nsw i32 %22, -480
  %24 = add nsw i32 %23, %13
  %indvars.iv.next.1 = add nsw i64 %9, -2
  %25 = trunc nuw i64 %indvars.iv.next to i32
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %27, label %16, !llvm.loop !8

27:                                               ; preds = %18
  %28 = getelementptr inbounds [40 x i8], ptr %3, i64 0, i64 %indvars.iv.next.1
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = sext i8 %29 to i32
  %31 = mul nsw i32 %30, 100
  %32 = add nsw i32 %31, -4800
  %33 = add nsw i32 %32, %24
  %indvars.iv.next.2 = add nsw i64 %9, -3
  %34 = trunc nuw i64 %indvars.iv.next.1 to i32
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %36, label %16, !llvm.loop !8

36:                                               ; preds = %27
  %37 = getelementptr inbounds [40 x i8], ptr %3, i64 0, i64 %indvars.iv.next.2
  %38 = load i8, ptr %37, align 1, !tbaa !5
  %39 = sext i8 %38 to i32
  %40 = mul nsw i32 %39, 1000
  %41 = add nsw i32 %40, -48000
  %42 = add nsw i32 %41, %33
  %indvars.iv.next.3 = add nsw i64 %9, -4
  %43 = trunc nuw i64 %indvars.iv.next.2 to i32
  %44 = icmp sgt i32 %43, 0
  br label %16

._crit_edge.loopexit:                             ; preds = %16
  %45 = trunc nuw i64 %indvars.iv.next31 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %.019.lcssa = phi i32 [ 0, %2 ], [ %45, %._crit_edge.loopexit ]
  %46 = getelementptr inbounds i8, ptr %1, i64 2000
  store i32 %.019.lcssa, ptr %46, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  ret ptr %0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull) local_unnamed_addr #3

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


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