; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/高精度/大整数类.ll (ZplRK4bignS1_)

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

%struct.bign = type { i32, [1000 x i32] }

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; 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 @_ZplRK4bignS1_(ptr dead_on_unwind noalias writable sret(%struct.bign) align 4 %0, ptr noundef nonnull align 4 dereferenceable(4004) %1, ptr noundef nonnull align 4 dereferenceable(4004) %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !5
  call void @_ZN4bignC2EPKc(ptr noundef nonnull align 4 dereferenceable(4004) %0, ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %84, %3
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.bign, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = icmp sle i32 %8, %11
  br i1 %12, label %26, label %13

13:                                               ; preds = %7
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.bign, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp sle i32 %14, %17
  br i1 %18, label %26, label %19

19:                                               ; preds = %13
  %20 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1000 x i32], ptr %20, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br label %26

26:                                               ; preds = %19, %13, %7
  %27 = phi i1 [ true, %13 ], [ true, %7 ], [ %25, %19 ]
  br i1 %27, label %28, label %87

28:                                               ; preds = %26
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.bign, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = icmp sle i32 %29, %32
  br i1 %33, label %34, label %47

34:                                               ; preds = %28
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.bign, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1000 x i32], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = add nsw i32 %45, %40
  store i32 %46, ptr %44, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %34, %28
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.bign, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = icmp sle i32 %48, %51
  br i1 %52, label %53, label %66

53:                                               ; preds = %47
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.bign, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000 x i32], ptr %55, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1000 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = add nsw i32 %64, %59
  store i32 %65, ptr %63, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %53, %47
  %67 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1000 x i32], ptr %67, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sdiv i32 %71, 100000000
  %73 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1000 x i32], ptr %73, i64 0, i64 %76
  store i32 %72, ptr %77, align 4, !tbaa !9
  %78 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1000 x i32], ptr %78, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = srem i32 %82, 100000000
  store i32 %83, ptr %81, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %66
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %6, align 4, !tbaa !9
  br label %7, !llvm.loop !13

87:                                               ; preds = %26
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = sub nsw i32 %88, 1
  %90 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  store i32 %89, ptr %90, align 4, !tbaa !11
  %91 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = icmp eq i32 %92, 0
  br i1 %93, label %94, label %96

94:                                               ; preds = %87
  %95 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  store i32 1, ptr %95, align 4, !tbaa !11
  br label %96

96:                                               ; preds = %94, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4bignC2EPKc(ptr noundef nonnull align 4 dereferenceable(4004), ptr noundef) unnamed_addr #1 align 2

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS4bign", !10, i64 0, !7, i64 4}
!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"

%struct.bign = type { i32, [1000 x i32] }

@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZplRK4bignS1_(ptr dead_on_unwind noalias nonnull writable sret(%struct.bign) align 4 %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4004) %1, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4004) %2) local_unnamed_addr #0 {
  tail call void @_ZN4bignC2EPKc(ptr noundef nonnull align 4 dereferenceable(4004) %0, ptr noundef nonnull @.str.2)
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = getelementptr inbounds i8, ptr %2, i64 4
  %9 = sext i32 %5 to i64
  %10 = sext i32 %6 to i64
  br label %11

11:                                               ; preds = %28, %3
  %indvars.iv = phi i64 [ %indvars.iv.next, %28 ], [ 1, %3 ]
  %.not = icmp sgt i64 %indvars.iv, %9
  %.not19 = icmp sgt i64 %indvars.iv, %10
  %or.cond = select i1 %.not, i1 %.not19, i1 false
  br i1 %or.cond, label %12, label %.critedge

12:                                               ; preds = %11
  %13 = getelementptr inbounds [1000 x i32], ptr %4, i64 0, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %.not20 = icmp eq i32 %14, 0
  br i1 %.not20, label %34, label %.critedge

.critedge:                                        ; preds = %11, %12
  br i1 %.not, label %21, label %15

15:                                               ; preds = %.critedge
  %16 = getelementptr inbounds [1000 x i32], ptr %7, i64 0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !10
  %18 = getelementptr inbounds [1000 x i32], ptr %4, i64 0, i64 %indvars.iv
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = add nsw i32 %19, %17
  store i32 %20, ptr %18, align 4, !tbaa !10
  br label %21

21:                                               ; preds = %15, %.critedge
  br i1 %.not19, label %._crit_edge, label %22

._crit_edge:                                      ; preds = %21
  %.phi.trans.insert = getelementptr inbounds [1000 x i32], ptr %4, i64 0, i64 %indvars.iv
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  br label %28

22:                                               ; preds = %21
  %23 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = getelementptr inbounds [1000 x i32], ptr %4, i64 0, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !10
  %27 = add nsw i32 %26, %24
  br label %28

28:                                               ; preds = %._crit_edge, %22
  %29 = phi i32 [ %.pre, %._crit_edge ], [ %27, %22 ]
  %30 = getelementptr inbounds [1000 x i32], ptr %4, i64 0, i64 %indvars.iv
  %31 = sdiv i32 %29, 100000000
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = getelementptr inbounds [1000 x i32], ptr %4, i64 0, i64 %indvars.iv.next
  store i32 %31, ptr %32, align 4, !tbaa !10
  %33 = srem i32 %29, 100000000
  store i32 %33, ptr %30, align 4, !tbaa !10
  br label %11, !llvm.loop !11

34:                                               ; preds = %12
  %35 = trunc nuw nsw i64 %indvars.iv to i32
  %36 = add nsw i32 %35, -1
  %spec.select = tail call i32 @llvm.umax.i32(i32 %36, i32 1)
  store i32 %spec.select, ptr %0, align 4, !tbaa !5
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4bignC2EPKc(ptr noundef nonnull align 4 dereferenceable(4004), ptr noundef) unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.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, !7, i64 0}
!6 = !{!"_ZTS4bign", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass