; LLVM IR from ippeb/ACM-ICPC :: algebra/bignum/bignum.ll (Z6assignR6bignumS0_)

; 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.bignum = type { [12 x i64], 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: mustprogress nounwind uwtable
define dso_local void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(104) %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.bignum, ptr %7, i32 0, i32 1
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.bignum, ptr %10, i32 0, i32 1
  store i32 %9, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %12

12:                                               ; preds = %31, %2
  %13 = load i32, ptr %5, align 4, !tbaa !12
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.bignum, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp slt i32 %13, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %34

19:                                               ; preds = %12
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.bignum, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %5, align 4, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [12 x i64], ptr %21, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.bignum, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %5, align 4, !tbaa !12
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [12 x i64], ptr %27, i64 0, i64 %29
  store i64 %25, ptr %30, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %19
  %32 = load i32, ptr %5, align 4, !tbaa !12
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !12
  br label %12, !llvm.loop !15

34:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.bignum, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !9
  store i32 %37, ptr %6, align 4, !tbaa !12
  br label %38

38:                                               ; preds = %48, %34
  %39 = load i32, ptr %6, align 4, !tbaa !12
  %40 = icmp slt i32 %39, 12
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %51

42:                                               ; preds = %38
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.bignum, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %6, align 4, !tbaa !12
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [12 x i64], ptr %44, i64 0, i64 %46
  store i64 0, ptr %47, align 8, !tbaa !13
  br label %48

48:                                               ; preds = %42
  %49 = load i32, ptr %6, align 4, !tbaa !12
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %6, align 4, !tbaa !12
  br label %38, !llvm.loop !17

51:                                               ; preds = %41
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind 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, !11, i64 96}
!10 = !{!"_ZTS6bignum", !7, i64 0, !11, i64 96}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z6assignR6bignumS0_(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(104) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(104) %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 96
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 %4, ptr %5, align 8, !tbaa !5
  %6 = icmp sgt i32 %4, 0
  br i1 %6, label %.lr.ph.preheader, label %.lr.ph17.preheader

.lr.ph.preheader:                                 ; preds = %2
  %7 = ptrtoint ptr %0 to i64
  %8 = ptrtoint ptr %1 to i64
  %wide.trip.count = zext nneg i32 %4 to i64
  %min.iters.check = icmp ult i32 %4, 6
  %9 = sub i64 %7, %8
  %diff.check = icmp ult i64 %9, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader23, label %vector.ph

.lr.ph.preheader23:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader23, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader23 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader23 ]
  %10 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv.prol
  %11 = load i64, ptr %10, align 8, !tbaa !10
  %12 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv.prol
  store i64 %11, ptr %12, align 8, !tbaa !10
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !12

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader23
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader23 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %13 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %14 = icmp ugt i64 %13, -4
  br i1 %14, label %.preheader, label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %15 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %wide.load = load <2 x i64>, ptr %15, align 8, !tbaa !10
  %wide.load22 = load <2 x i64>, ptr %16, align 8, !tbaa !10
  %17 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  store <2 x i64> %wide.load, ptr %17, align 8, !tbaa !10
  store <2 x i64> %wide.load22, ptr %18, align 8, !tbaa !10
  %index.next = add nuw i64 %index, 4
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.preheader, label %.lr.ph.preheader23

.preheader:                                       ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block
  %20 = icmp slt i32 %4, 12
  br i1 %20, label %.lr.ph17.preheader, label %._crit_edge

.lr.ph17.preheader:                               ; preds = %2, %.preheader
  %21 = sext i32 %4 to i64
  %22 = shl nsw i64 %21, 3
  %scevgep = getelementptr i8, ptr %0, i64 %22
  %23 = sub i32 11, %4
  %24 = zext i32 %23 to i64
  %25 = shl nuw nsw i64 %24, 3
  %26 = add nuw nsw i64 %25, 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %scevgep, i8 0, i64 %26, i1 false), !tbaa !10
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %27 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv
  %28 = load i64, ptr %27, align 8, !tbaa !10
  %29 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv
  store i64 %28, ptr %29, align 8, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv.next
  %31 = load i64, ptr %30, align 8, !tbaa !10
  %32 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv.next
  store i64 %31, ptr %32, align 8, !tbaa !10
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %33 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv.next.1
  %34 = load i64, ptr %33, align 8, !tbaa !10
  %35 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv.next.1
  store i64 %34, ptr %35, align 8, !tbaa !10
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %36 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv.next.2
  %37 = load i64, ptr %36, align 8, !tbaa !10
  %38 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv.next.2
  store i64 %37, ptr %38, align 8, !tbaa !10
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %.preheader, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph17.preheader, %.preheader
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 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, !9, i64 96}
!6 = !{!"_ZTS6bignum", !7, i64 0, !9, i64 96}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}


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