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

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

@POW10 = external dso_local global [20 x i64], align 16

; 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
declare dso_local void @_Z11zerojustifyR6bignum(ptr noundef nonnull align 8 dereferenceable(104)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4initR6bignum(ptr noundef nonnull align 8 dereferenceable(104)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104)) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3subR6bignumS0_S0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(104) %1, ptr noundef nonnull align 8 dereferenceable(104) %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.bignum, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 104, ptr %7) #4
  call void @_Z4initR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %7)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.bignum, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.bignum, ptr %13, i32 0, i32 1
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %14)
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.bignum, ptr %7, i32 0, i32 1
  store i32 %16, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %54, %3
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = getelementptr inbounds %struct.bignum, ptr %7, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = icmp slt i32 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %57

24:                                               ; preds = %18
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.bignum, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [12 x i64], ptr %26, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.bignum, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [12 x i64], ptr %32, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !13
  %37 = sub nsw i64 %30, %36
  %38 = load i64, ptr %9, align 8, !tbaa !13
  %39 = sub nsw i64 %37, %38
  store i64 %39, ptr %8, align 8, !tbaa !13
  %40 = load i64, ptr %8, align 8, !tbaa !13
  %41 = load i64, ptr getelementptr inbounds ([20 x i64], ptr @POW10, i64 0, i64 9), align 8, !tbaa !13
  %42 = add nsw i64 %40, %41
  %43 = load i64, ptr getelementptr inbounds ([20 x i64], ptr @POW10, i64 0, i64 9), align 8, !tbaa !13
  %44 = srem i64 %42, %43
  %45 = getelementptr inbounds %struct.bignum, ptr %7, i32 0, i32 0
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [12 x i64], ptr %45, i64 0, i64 %47
  store i64 %44, ptr %48, align 8, !tbaa !13
  %49 = load i64, ptr %8, align 8, !tbaa !13
  %50 = icmp slt i64 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %24
  store i64 1, ptr %9, align 8, !tbaa !13
  br label %53

52:                                               ; preds = %24
  store i64 0, ptr %9, align 8, !tbaa !13
  br label %53

53:                                               ; preds = %52, %51
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %10, align 4, !tbaa !9
  br label %18, !llvm.loop !15

57:                                               ; preds = %23
  call void @_Z11zerojustifyR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %7)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %58, ptr noundef nonnull align 8 dereferenceable(104) %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 104, ptr %7) #4
  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 = { inlinehint 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 #3 = { 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 #4 = { 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 96}
!12 = !{!"_ZTS6bignum", !7, i64 0, !10, i64 96}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.bignum = type { [12 x i64], i32 }

@POW10 = external dso_local local_unnamed_addr global [20 x i64], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11zerojustifyR6bignum(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4initR6bignum(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3subR6bignumS0_S0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(104) %1, ptr noundef nonnull align 8 dereferenceable(104) %2) local_unnamed_addr #1 {
  %4 = alloca %struct.bignum, align 8
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %4) #3
  call void @_Z4initR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %4)
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = getelementptr inbounds i8, ptr %1, i64 96
  %7 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %4, i64 96
  store i32 %8, ptr %9, align 8, !tbaa !9
  %10 = icmp sgt i32 %8, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @POW10, i64 72), align 8, !tbaa !11
  %wide.trip.count = zext nneg i32 %8 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %12 = icmp eq i32 %8, 1
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %22

._crit_edge.loopexit.unr-lcssa:                   ; preds = %22, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %22 ]
  %.012.neg13.unr = phi i64 [ 0, %.lr.ph ], [ %.lobit.1, %22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %13 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv.unr
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv.unr
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = sub nsw i64 %14, %16
  %18 = add i64 %17, %.012.neg13.unr
  %19 = add nsw i64 %18, %11
  %20 = srem i64 %19, %11
  %21 = getelementptr inbounds [12 x i64], ptr %4, i64 0, i64 %indvars.iv.unr
  store i64 %20, ptr %21, align 8, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %3
  call void @_Z11zerojustifyR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %4)
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %2, ptr noundef nonnull align 8 dereferenceable(104) %4)
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %4) #3
  ret void

22:                                               ; preds = %22, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %22 ]
  %.012.neg13 = phi i64 [ 0, %.lr.ph.new ], [ %.lobit.1, %22 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %22 ]
  %23 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = sub nsw i64 %24, %26
  %28 = add i64 %27, %.012.neg13
  %29 = add nsw i64 %28, %11
  %30 = srem i64 %29, %11
  %31 = getelementptr inbounds [12 x i64], ptr %4, i64 0, i64 %indvars.iv
  store i64 %30, ptr %31, align 8, !tbaa !11
  %.lobit = ashr i64 %28, 63
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %32 = getelementptr inbounds [12 x i64], ptr %0, i64 0, i64 %indvars.iv.next
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds [12 x i64], ptr %1, i64 0, i64 %indvars.iv.next
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = sub nsw i64 %33, %35
  %37 = add i64 %36, %.lobit
  %38 = add nsw i64 %37, %11
  %39 = srem i64 %38, %11
  %40 = getelementptr inbounds [12 x i64], ptr %4, i64 0, i64 %indvars.iv.next
  store i64 %39, ptr %40, align 8, !tbaa !11
  %.lobit.1 = ashr i64 %37, 63
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %22, !llvm.loop !13
}

attributes #0 = { mustprogress 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 = { inlinehint 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 #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 96}
!10 = !{!"_ZTS6bignum", !7, i64 0, !6, i64 96}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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