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

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

16:                                               ; preds = %44, %3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %47

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %21 = load i64, ptr %6, align 8, !tbaa !11
  %22 = mul nsw i64 %21, 100000000
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.bign, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1000 x i32], ptr %24, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = add nsw i64 %22, %29
  store i64 %30, ptr %8, align 8, !tbaa !11
  %31 = load i64, ptr %8, align 8, !tbaa !11
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = sdiv i64 %31, %33
  %35 = trunc i64 %34 to i32
  %36 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000 x i32], ptr %36, i64 0, i64 %38
  store i32 %35, ptr %39, align 4, !tbaa !9
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = srem i64 %40, %42
  store i64 %43, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %44

44:                                               ; preds = %20
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %7, align 4, !tbaa !9
  br label %16, !llvm.loop !15

47:                                               ; preds = %19
  br label %48

48:                                               ; preds = %63, %47
  %49 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = icmp sgt i32 %50, 1
  br i1 %51, label %52, label %61

52:                                               ; preds = %48
  %53 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 1
  %54 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000 x i32], ptr %53, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = icmp ne i32 %58, 0
  %60 = xor i1 %59, true
  br label %61

61:                                               ; preds = %52, %48
  %62 = phi i1 [ false, %48 ], [ %60, %52 ]
  br i1 %62, label %63, label %67

63:                                               ; preds = %61
  %64 = getelementptr inbounds %struct.bign, ptr %0, i32 0, i32 0
  %65 = load i32, ptr %64, align 4, !tbaa !13
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr %64, align 4, !tbaa !13
  br label %48, !llvm.loop !17

67:                                               ; preds = %61
  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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS4bign", !10, i64 0, !7, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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 @_ZdvRK4bigni(ptr dead_on_unwind noalias nonnull writable sret(%struct.bign) align 4 %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(4004) %1, i32 noundef %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
  store i32 %4, ptr %0, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = sext i32 %2 to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = zext nneg i32 %4 to i64
  br label %10

10:                                               ; preds = %.lr.ph, %10
  %indvars.iv = phi i64 [ %9, %.lr.ph ], [ %indvars.iv.next, %10 ]
  %.014 = phi i64 [ 0, %.lr.ph ], [ %19, %10 ]
  %11 = mul nsw i64 %.014, 100000000
  %12 = getelementptr inbounds [1000 x i32], ptr %6, i64 0, i64 %indvars.iv
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = sext i32 %13 to i64
  %15 = add nsw i64 %11, %14
  %16 = sdiv i64 %15, %7
  %17 = trunc i64 %16 to i32
  %18 = getelementptr inbounds [1000 x i32], ptr %8, i64 0, i64 %indvars.iv
  store i32 %17, ptr %18, align 4, !tbaa !10
  %19 = srem i64 %15, %7
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %20 = icmp ugt i64 %indvars.iv, 1
  br i1 %20, label %10, label %thread-pre-split, !llvm.loop !11

thread-pre-split:                                 ; preds = %10
  %.pr.pre = load i32, ptr %0, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 4
  %22 = icmp sgt i32 %.pr.pre, 1
  br i1 %22, label %.lr.ph15, label %.critedge

.lr.ph15:                                         ; preds = %thread-pre-split, %27
  %23 = phi i32 [ %28, %27 ], [ %.pr.pre, %thread-pre-split ]
  %24 = zext nneg i32 %23 to i64
  %25 = getelementptr inbounds [1000 x i32], ptr %21, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !10
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %27, label %.critedge

27:                                               ; preds = %.lr.ph15
  %28 = add nsw i32 %23, -1
  store i32 %28, ptr %0, align 4, !tbaa !5
  %29 = icmp sgt i32 %23, 2
  br i1 %29, label %.lr.ph15, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph15, %27, %3, %thread-pre-split
  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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass