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

; 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 @_ZmiRK4bignS1_(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
  %7 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %6, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %61, %3
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %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 = icmp sle i32 %9, %12
  br i1 %13, label %14, label %64

14:                                               ; preds = %8
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.bign, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000 x i32], ptr %16, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sub nsw i32 %20, %21
  %23 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1000 x i32], ptr %23, i64 0, i64 %25
  store i32 %22, ptr %26, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.bign, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = icmp sle i32 %27, %30
  br i1 %31, label %32, label %45

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

45:                                               ; preds = %32, %14
  %46 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1000 x i32], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = icmp slt i32 %50, 0
  br i1 %51, label %52, label %59

52:                                               ; preds = %45
  store i32 1, ptr %7, align 4, !tbaa !9
  %53 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1000 x i32], ptr %53, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = add nsw i32 %57, 100000000
  store i32 %58, ptr %56, align 4, !tbaa !9
  br label %60

59:                                               ; preds = %45
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %59, %52
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !9
  br label %8, !llvm.loop !13

64:                                               ; preds = %8
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.bign, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  store i32 %67, ptr %68, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %84, %64
  %70 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %71 = load i32, ptr %70, align 4, !tbaa !11
  %72 = icmp sgt i32 %71, 1
  br i1 %72, label %73, label %82

73:                                               ; preds = %69
  %74 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %75 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %76 = load i32, ptr %75, align 4, !tbaa !11
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1000 x i32], ptr %74, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = icmp ne i32 %79, 0
  %81 = xor i1 %80, true
  br label %82

82:                                               ; preds = %73, %69
  %83 = phi i1 [ false, %69 ], [ %81, %73 ]
  br i1 %83, label %84, label %88

84:                                               ; preds = %82
  %85 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %86 = load i32, ptr %85, align 4, !tbaa !11
  %87 = add nsw i32 %86, -1
  store i32 %87, ptr %85, align 4, !tbaa !11
  br label %69, !llvm.loop !15

88:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, 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 = !{!"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"}
!15 = distinct !{!15, !14}


; 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 @_ZmiRK4bignS1_(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, !tbaa !5
  %.not20 = icmp slt i32 %4, 1
  br i1 %.not20, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 4
  %9 = sext i32 %7 to i64
  %10 = add nuw i32 %4, 1
  %wide.trip.count = zext i32 %10 to i64
  br label %12

.preheader:                                       ; preds = %26
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %.not = icmp eq i32 %4, 1
  br i1 %.not, label %.critedge, label %.lr.ph24

12:                                               ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %.0.neg22 = phi i32 [ 0, %.lr.ph ], [ %.1.neg, %26 ]
  %13 = getelementptr inbounds [1000 x i32], ptr %5, i64 0, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = add i32 %14, %.0.neg22
  %16 = getelementptr inbounds [1000 x i32], ptr %6, i64 0, i64 %indvars.iv
  store i32 %15, ptr %16, align 4, !tbaa !10
  %.not19 = icmp sgt i64 %indvars.iv, %9
  br i1 %.not19, label %21, label %17

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

21:                                               ; preds = %17, %12
  %22 = phi i32 [ %20, %17 ], [ %15, %12 ]
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  %25 = add nsw i32 %22, 100000000
  store i32 %25, ptr %16, align 4, !tbaa !10
  br label %26

26:                                               ; preds = %21, %24
  %.1.neg = phi i32 [ -1, %24 ], [ 0, %21 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %12, !llvm.loop !11

.lr.ph24:                                         ; preds = %.preheader, %30
  %storemerge23 = phi i32 [ %31, %30 ], [ %4, %.preheader ]
  %27 = zext nneg i32 %storemerge23 to i64
  %28 = getelementptr inbounds [1000 x i32], ptr %11, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !10
  %.not18 = icmp eq i32 %29, 0
  br i1 %.not18, label %30, label %.critedge

30:                                               ; preds = %.lr.ph24
  %31 = add nsw i32 %storemerge23, -1
  %32 = icmp sgt i32 %storemerge23, 2
  br i1 %32, label %.lr.ph24, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph24, %30, %3, %.preheader
  %storemerge.lcssa = phi i32 [ %4, %.preheader ], [ %4, %3 ], [ 1, %30 ], [ %storemerge23, %.lr.ph24 ]
  store i32 %storemerge.lcssa, ptr %0, align 4, !tbaa !5
  ret void
}

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

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


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