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

; 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
declare dso_local void @_ZN4bignC2EPKc(ptr noundef nonnull align 4 dereferenceable(4004), ptr noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZmlRK4bignS1_(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 i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  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 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !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 %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.bign, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.bign, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = add nsw i32 %12, %15
  %17 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  store i32 %16, ptr %17, align 4, !tbaa !11
  %18 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %19 = getelementptr inbounds [1000 x i32], ptr %18, i64 0, i64 0
  store i32 0, ptr %19, align 4, !tbaa !14
  store i32 1, ptr %7, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %30, %3
  %21 = load i32, ptr %7, align 4, !tbaa !14
  %22 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = icmp sle i32 %21, %23
  br i1 %24, label %25, label %33

25:                                               ; preds = %20
  %26 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %27 = load i32, ptr %7, align 4, !tbaa !14
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000 x i32], ptr %26, i64 0, i64 %28
  store i32 0, ptr %29, align 4, !tbaa !14
  br label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %7, align 4, !tbaa !14
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %7, align 4, !tbaa !14
  br label %20, !llvm.loop !15

33:                                               ; preds = %20
  store i32 1, ptr %8, align 4, !tbaa !14
  br label %34

34:                                               ; preds = %97, %33
  %35 = load i32, ptr %8, align 4, !tbaa !14
  %36 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = icmp sle i32 %35, %37
  br i1 %38, label %39, label %100

39:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %40 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %40, ptr %9, align 8, !tbaa !9
  %41 = load i32, ptr %8, align 4, !tbaa !14
  %42 = add nsw i32 %41, 1
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.bign, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = sub nsw i32 %42, %45
  store i32 %46, ptr %7, align 4, !tbaa !14
  %47 = load i32, ptr %7, align 4, !tbaa !14
  %48 = icmp slt i32 %47, 1
  br i1 %48, label %49, label %50

49:                                               ; preds = %39
  store i32 1, ptr %7, align 4, !tbaa !14
  br label %50

50:                                               ; preds = %49, %39
  br label %51

51:                                               ; preds = %84, %50
  %52 = load i32, ptr %7, align 4, !tbaa !14
  %53 = load i32, ptr %8, align 4, !tbaa !14
  %54 = icmp sle i32 %52, %53
  br i1 %54, label %55, label %61

55:                                               ; preds = %51
  %56 = load i32, ptr %7, align 4, !tbaa !14
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.bign, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 4, !tbaa !11
  %60 = icmp sle i32 %56, %59
  br label %61

61:                                               ; preds = %55, %51
  %62 = phi i1 [ false, %51 ], [ %60, %55 ]
  br i1 %62, label %63, label %87

63:                                               ; preds = %61
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.bign, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %7, align 4, !tbaa !14
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1000 x i32], ptr %65, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !14
  %70 = sext i32 %69 to i64
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.bign, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %8, align 4, !tbaa !14
  %74 = add nsw i32 %73, 1
  %75 = load i32, ptr %7, align 4, !tbaa !14
  %76 = sub nsw i32 %74, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1000 x i32], ptr %72, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !14
  %80 = sext i32 %79 to i64
  %81 = mul nsw i64 %70, %80
  %82 = load i64, ptr %9, align 8, !tbaa !9
  %83 = add nsw i64 %82, %81
  store i64 %83, ptr %9, align 8, !tbaa !9
  br label %84

84:                                               ; preds = %63
  %85 = load i32, ptr %7, align 4, !tbaa !14
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %7, align 4, !tbaa !14
  br label %51, !llvm.loop !17

87:                                               ; preds = %61
  %88 = load i64, ptr %9, align 8, !tbaa !9
  %89 = sdiv i64 %88, 100000000
  store i64 %89, ptr %6, align 8, !tbaa !9
  %90 = load i64, ptr %9, align 8, !tbaa !9
  %91 = srem i64 %90, 100000000
  %92 = trunc i64 %91 to i32
  %93 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %94 = load i32, ptr %8, align 4, !tbaa !14
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [1000 x i32], ptr %93, i64 0, i64 %95
  store i32 %92, ptr %96, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %97

97:                                               ; preds = %87
  %98 = load i32, ptr %8, align 4, !tbaa !14
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %8, align 4, !tbaa !14
  br label %34, !llvm.loop !18

100:                                              ; preds = %34
  br label %101

101:                                              ; preds = %116, %100
  %102 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %103 = load i32, ptr %102, align 4, !tbaa !11
  %104 = icmp sgt i32 %103, 1
  br i1 %104, label %105, label %114

105:                                              ; preds = %101
  %106 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %107 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %108 = load i32, ptr %107, align 4, !tbaa !11
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [1000 x i32], ptr %106, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !14
  %112 = icmp ne i32 %111, 0
  %113 = xor i1 %112, true
  br label %114

114:                                              ; preds = %105, %101
  %115 = phi i1 [ false, %101 ], [ %113, %105 ]
  br i1 %115, label %116, label %120

116:                                              ; preds = %114
  %117 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %118 = load i32, ptr %117, align 4, !tbaa !11
  %119 = add nsw i32 %118, -1
  store i32 %119, ptr %117, align 4, !tbaa !11
  br label %101, !llvm.loop !19

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

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 = !{!"long long", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS4bign", !13, i64 0, !7, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


; 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
declare dso_local void @_ZN4bignC2EPKc(ptr noundef nonnull align 4 dereferenceable(4004), ptr noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZmlRK4bignS1_(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 = load i32, ptr %1, align 4
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = add i32 %5, %4
  store i32 %6, ptr %0, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 0, ptr %7, align 4, !tbaa !10
  %.not34 = icmp slt i32 %6, 1
  br i1 %.not34, label %.critedge2, label %.lr.ph45

.lr.ph45:                                         ; preds = %3
  %scevgep = getelementptr inbounds i8, ptr %0, i64 8
  %8 = add nsw i32 %6, -1
  %9 = zext nneg i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = add nuw nsw i64 %10, 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %scevgep, i8 0, i64 %11, i1 false), !tbaa !10
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  %13 = getelementptr inbounds i8, ptr %2, i64 4
  %14 = sub i32 2, %5
  %15 = sext i32 %4 to i64
  %16 = add nuw i32 %6, 1
  %wide.trip.count = zext i32 %16 to i64
  br label %17

17:                                               ; preds = %.lr.ph45, %.critedge
  %indvars.iv52 = phi i64 [ 1, %.lr.ph45 ], [ %indvars.iv.next53, %.critedge ]
  %indvars.iv = phi i32 [ %14, %.lr.ph45 ], [ %indvars.iv.next, %.critedge ]
  %.02843 = phi i64 [ 0, %.lr.ph45 ], [ %32, %.critedge ]
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %indvars = trunc i64 %indvars.iv.next53 to i32
  %18 = sub nsw i32 %indvars, %5
  %19 = trunc i64 %indvars.iv.next53 to i32
  %20 = sub i32 %19, %5
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %20, i32 1)
  %21 = sext i32 %18 to i64
  %.not3236 = icmp slt i64 %indvars.iv52, %21
  %.not3337 = icmp sgt i32 %spec.store.select, %4
  %or.cond38 = or i1 %.not3236, %.not3337
  br i1 %or.cond38, label %.critedge, label %.lr.ph41.preheader

.lr.ph41.preheader:                               ; preds = %17
  %smax = tail call i32 @llvm.smax.i32(i32 %indvars.iv, i32 1)
  %22 = zext nneg i32 %smax to i64
  br label %.lr.ph41

.lr.ph41:                                         ; preds = %.lr.ph41.preheader, %.lr.ph41
  %indvars.iv49 = phi i64 [ %22, %.lr.ph41.preheader ], [ %indvars.iv.next50, %.lr.ph41 ]
  %.040 = phi i64 [ %.02843, %.lr.ph41.preheader ], [ %31, %.lr.ph41 ]
  %23 = getelementptr inbounds [1000 x i32], ptr %12, i64 0, i64 %indvars.iv49
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = sext i32 %24 to i64
  %26 = sub nsw i64 %indvars.iv.next53, %indvars.iv49
  %27 = getelementptr inbounds [1000 x i32], ptr %13, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !10
  %29 = sext i32 %28 to i64
  %30 = mul nsw i64 %29, %25
  %31 = add nsw i64 %30, %.040
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %.not32 = icmp uge i64 %indvars.iv49, %indvars.iv52
  %.not33 = icmp sge i64 %indvars.iv49, %15
  %or.cond = or i1 %.not32, %.not33
  br i1 %or.cond, label %.critedge, label %.lr.ph41, !llvm.loop !11

.critedge:                                        ; preds = %.lr.ph41, %17
  %.0.lcssa = phi i64 [ %.02843, %17 ], [ %31, %.lr.ph41 ]
  %32 = sdiv i64 %.0.lcssa, 100000000
  %33 = srem i64 %.0.lcssa, 100000000
  %34 = trunc nsw i64 %33 to i32
  %35 = getelementptr inbounds [1000 x i32], ptr %7, i64 0, i64 %indvars.iv52
  store i32 %34, ptr %35, align 4, !tbaa !10
  %indvars.iv.next = add i32 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next53, %wide.trip.count
  br i1 %exitcond.not, label %thread-pre-split, label %17, !llvm.loop !13

thread-pre-split:                                 ; preds = %.critedge
  %.not = icmp eq i32 %6, 1
  br i1 %.not, label %.critedge2, label %.lr.ph46

.lr.ph46:                                         ; preds = %thread-pre-split, %40
  %36 = phi i32 [ %41, %40 ], [ %6, %thread-pre-split ]
  %37 = zext nneg i32 %36 to i64
  %38 = getelementptr inbounds [1000 x i32], ptr %7, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !10
  %.not31 = icmp eq i32 %39, 0
  br i1 %.not31, label %40, label %.critedge2

40:                                               ; preds = %.lr.ph46
  %41 = add nsw i32 %36, -1
  store i32 %41, ptr %0, align 4, !tbaa !5
  %42 = icmp sgt i32 %36, 2
  br i1 %42, label %.lr.ph46, label %.critedge2, !llvm.loop !14

.critedge2:                                       ; preds = %.lr.ph46, %40, %3, %thread-pre-split
  ret void
}

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

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

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) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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


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