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

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

@__const._Z4sqrtR6bignumS0_.One = 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 nounwind uwtable
declare dso_local void @_Z11zerojustifyR6bignum(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: mustprogress nounwind uwtable
declare dso_local void @_Z4baseR6bignumPc(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3addR6bignumS0_S0_x(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104), i64 noundef) #2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7shift10R6bignumi(ptr noundef nonnull align 8 dereferenceable(104), i32 noundef) #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4sqrtR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(104) %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.bignum, align 8
  %6 = alloca %struct.bignum, align 8
  %7 = alloca %struct.bignum, align 8
  %8 = alloca %struct.bignum, align 8
  %9 = alloca %struct.bignum, align 8
  %10 = alloca %struct.bignum, align 8
  %11 = alloca [2 x i8], align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 104, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 104, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 104, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 104, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 104, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 104, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %11, ptr align 1 @__const._Z4sqrtR6bignumS0_.One, i64 2, i1 false)
  %12 = getelementptr inbounds [2 x i8], ptr %11, i64 0, i64 0
  call void @_Z4baseR6bignumPc(ptr noundef nonnull align 8 dereferenceable(104) %9, ptr noundef %12)
  %13 = getelementptr inbounds [2 x i8], ptr %11, i64 0, i64 0
  call void @_Z4baseR6bignumPc(ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call noundef i32 @_Z6digitsR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %14)
  %16 = add nsw i32 %15, 1
  %17 = sdiv i32 %16, 2
  %18 = sub nsw i32 %17, 1
  call void @_Z7shift10R6bignumi(ptr noundef nonnull align 8 dereferenceable(104) %5, i32 noundef %18)
  %19 = getelementptr inbounds [2 x i8], ptr %11, i64 0, i64 0
  call void @_Z4baseR6bignumPc(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef %19)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call noundef i32 @_Z6digitsR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %20)
  %22 = add nsw i32 %21, 1
  %23 = sdiv i32 %22, 2
  call void @_Z7shift10R6bignumi(ptr noundef nonnull align 8 dereferenceable(104) %6, i32 noundef %23)
  br label %24

24:                                               ; preds = %33, %2
  %25 = call noundef i32 @_Z4compR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef nonnull align 8 dereferenceable(104) %5)
  %26 = icmp sge i32 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  call void @_Z3addR6bignumS0_S0_x(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef nonnull align 8 dereferenceable(104) %7, i64 noundef 1)
  call void @_Z4div2R6bignum(ptr noundef nonnull align 8 dereferenceable(104) %7)
  call void @_Z4multR6bignumS0_S0_(ptr noundef nonnull align 8 dereferenceable(104) %7, ptr noundef nonnull align 8 dereferenceable(104) %7, ptr noundef nonnull align 8 dereferenceable(104) %10)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = call noundef i32 @_Z4compR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %10, ptr noundef nonnull align 8 dereferenceable(104) %28)
  %30 = icmp sle i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %8, ptr noundef nonnull align 8 dereferenceable(104) %7)
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef nonnull align 8 dereferenceable(104) %7)
  call void @_Z3addR6bignumS0_S0_x(ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef nonnull align 8 dereferenceable(104) %9, ptr noundef nonnull align 8 dereferenceable(104) %5, i64 noundef 1)
  br label %33

32:                                               ; preds = %27
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef nonnull align 8 dereferenceable(104) %7)
  call void @_Z3subR6bignumS0_S0_(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef nonnull align 8 dereferenceable(104) %9, ptr noundef nonnull align 8 dereferenceable(104) %6)
  br label %33

33:                                               ; preds = %32, %31
  br label %24, !llvm.loop !9

34:                                               ; preds = %24
  call void @_Z11zerojustifyR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %8)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %35, ptr noundef nonnull align 8 dereferenceable(104) %8)
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 104, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 104, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 104, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 104, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 104, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 104, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"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 }

@__const._Z4sqrtR6bignumS0_.One = external hidden unnamed_addr constant [2 x i8], align 1

; 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 @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3addR6bignumS0_S0_x(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104), i64 noundef) local_unnamed_addr #2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7shift10R6bignumi(ptr noundef nonnull align 8 dereferenceable(104), i32 noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4sqrtR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(104) %1) local_unnamed_addr #2 {
  %3 = alloca %struct.bignum, align 8
  %4 = alloca %struct.bignum, align 8
  %5 = alloca %struct.bignum, align 8
  %6 = alloca %struct.bignum, align 8
  %7 = alloca %struct.bignum, align 8
  %8 = alloca %struct.bignum, align 8
  %9 = alloca [2 x i8], align 2
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %9) #3
  %10 = load i16, ptr @__const._Z4sqrtR6bignumS0_.One, align 1
  store i16 %10, ptr %9, align 2
  call void @_Z4baseR6bignumPc(ptr noundef nonnull align 8 dereferenceable(104) %7, ptr noundef nonnull %9)
  call void @_Z4baseR6bignumPc(ptr noundef nonnull align 8 dereferenceable(104) %3, ptr noundef nonnull %9)
  %11 = call noundef i32 @_Z6digitsR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %12 = add nsw i32 %11, 1
  %13 = sdiv i32 %12, 2
  %14 = add nsw i32 %13, -1
  call void @_Z7shift10R6bignumi(ptr noundef nonnull align 8 dereferenceable(104) %3, i32 noundef %14)
  call void @_Z4baseR6bignumPc(ptr noundef nonnull align 8 dereferenceable(104) %4, ptr noundef nonnull %9)
  %15 = call noundef i32 @_Z6digitsR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %16 = add nsw i32 %15, 1
  %17 = sdiv i32 %16, 2
  call void @_Z7shift10R6bignumi(ptr noundef nonnull align 8 dereferenceable(104) %4, i32 noundef %17)
  %18 = call noundef i32 @_Z4compR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %4, ptr noundef nonnull align 8 dereferenceable(104) %3)
  %19 = icmp sgt i32 %18, -1
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %24
  call void @_Z3addR6bignumS0_S0_x(ptr noundef nonnull align 8 dereferenceable(104) %4, ptr noundef nonnull align 8 dereferenceable(104) %3, ptr noundef nonnull align 8 dereferenceable(104) %5, i64 noundef 1)
  call void @_Z4div2R6bignum(ptr noundef nonnull align 8 dereferenceable(104) %5)
  call void @_Z4multR6bignumS0_S0_(ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef nonnull align 8 dereferenceable(104) %8)
  %20 = call noundef i32 @_Z4compR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %8, ptr noundef nonnull align 8 dereferenceable(104) %0)
  %21 = icmp slt i32 %20, 1
  br i1 %21, label %22, label %23

22:                                               ; preds = %.lr.ph
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef nonnull align 8 dereferenceable(104) %5)
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %3, ptr noundef nonnull align 8 dereferenceable(104) %5)
  call void @_Z3addR6bignumS0_S0_x(ptr noundef nonnull align 8 dereferenceable(104) %3, ptr noundef nonnull align 8 dereferenceable(104) %7, ptr noundef nonnull align 8 dereferenceable(104) %3, i64 noundef 1)
  br label %24

23:                                               ; preds = %.lr.ph
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %4, ptr noundef nonnull align 8 dereferenceable(104) %5)
  call void @_Z3subR6bignumS0_S0_(ptr noundef nonnull align 8 dereferenceable(104) %4, ptr noundef nonnull align 8 dereferenceable(104) %7, ptr noundef nonnull align 8 dereferenceable(104) %4)
  br label %24

24:                                               ; preds = %23, %22
  %25 = call noundef i32 @_Z4compR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %4, ptr noundef nonnull align 8 dereferenceable(104) %3)
  %26 = icmp sgt i32 %25, -1
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %24, %2
  call void @_Z11zerojustifyR6bignum(ptr noundef nonnull align 8 dereferenceable(104) %6)
  call void @_Z6assignR6bignumS0_(ptr noundef nonnull align 8 dereferenceable(104) %1, ptr noundef nonnull align 8 dereferenceable(104) %6)
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %3) #3
  ret void
}

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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass