; LLVM IR from jwerle/libhypercore-crypto :: deps/flat-tree (flat-tree)

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

; 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: nounwind uwtable
define dso_local i64 @ft_full_roots(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = and i64 %10, 1
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  br label %70

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 1, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 2, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  %15 = load i32, ptr %8, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 8
  %18 = call noalias ptr @malloc(i64 noundef %17) #5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %18, ptr %19, align 8, !tbaa !5
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = udiv i64 %20, 2
  store i64 %21, ptr %5, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %51, %14
  br label %23

23:                                               ; preds = %22
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = icmp eq i64 0, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %23
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  store i64 %28, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %70

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %35, %29
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = mul i64 %31, 2
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = icmp ule i64 %32, %33
  br i1 %34, label %35, label %38

35:                                               ; preds = %30
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = mul i64 %36, 2
  store i64 %37, ptr %6, align 8, !tbaa !9
  br label %30, !llvm.loop !13

38:                                               ; preds = %30
  %39 = load i32, ptr %9, align 4, !tbaa !11
  %40 = load i32, ptr %8, align 4, !tbaa !11
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %51

42:                                               ; preds = %38
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = add nsw i32 %43, 2
  store i32 %44, ptr %8, align 4, !tbaa !11
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = call ptr @realloc(ptr noundef %46, i64 noundef %48) #6
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %49, ptr %50, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %42, %38
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = add i64 %52, %53
  %55 = sub i64 %54, 1
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %57, i64 %59
  store i64 %55, ptr %60, align 8, !tbaa !9
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = mul i64 2, %62
  %64 = add i64 %61, %63
  store i64 %64, ptr %7, align 8, !tbaa !9
  %65 = load i64, ptr %6, align 8, !tbaa !9
  %66 = load i64, ptr %5, align 8, !tbaa !9
  %67 = sub i64 %66, %65
  store i64 %67, ptr %5, align 8, !tbaa !9
  store i64 1, ptr %6, align 8, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !11
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %9, align 4, !tbaa !11
  br label %22

70:                                               ; preds = %26, %13
  %71 = load i64, ptr %3, align 8
  ret i64 %71
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 allocsize(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 allocsize(1) "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 }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind allocsize(1) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local i64 @ft_full_roots(ptr nocapture noundef writeonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = and i64 %1, 1
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %4, label %._crit_edge

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #3
  store ptr %5, ptr %0, align 8, !tbaa !5
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %4
  %7 = lshr exact i64 %1, 1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %19
  %8 = phi ptr [ %5, %.preheader.preheader ], [ %20, %19 ]
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %19 ]
  %.02435 = phi i32 [ 2, %.preheader.preheader ], [ %.1, %19 ]
  %.02534 = phi i64 [ 0, %.preheader.preheader ], [ %24, %19 ]
  %.02833 = phi i64 [ %7, %.preheader.preheader ], [ %25, %19 ]
  br label %10

._crit_edge.loopexit:                             ; preds = %19
  %9 = and i64 %indvars.iv.next, 4294967295
  br label %._crit_edge

10:                                               ; preds = %.preheader, %10
  %.127 = phi i64 [ %11, %10 ], [ 1, %.preheader ]
  %11 = shl i64 %.127, 1
  %.not32 = icmp ugt i64 %11, %.02833
  br i1 %.not32, label %12, label %10, !llvm.loop !9

12:                                               ; preds = %10
  %13 = zext i32 %.02435 to i64
  %14 = icmp eq i64 %indvars.iv, %13
  br i1 %14, label %15, label %19

15:                                               ; preds = %12
  %16 = add nsw i32 %.02435, 2
  %17 = sext i32 %16 to i64
  %18 = tail call ptr @realloc(ptr noundef %8, i64 noundef %17) #4
  store ptr %18, ptr %0, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %15, %12
  %20 = phi ptr [ %18, %15 ], [ %8, %12 ]
  %.1 = phi i32 [ %16, %15 ], [ %.02435, %12 ]
  %21 = add i64 %.02534, -1
  %22 = add i64 %21, %.127
  %23 = getelementptr inbounds i64, ptr %20, i64 %indvars.iv
  store i64 %22, ptr %23, align 8, !tbaa !11
  %24 = add i64 %11, %.02534
  %25 = sub i64 %.02833, %.127
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = icmp eq i64 %25, 0
  br i1 %26, label %._crit_edge.loopexit, label %.preheader

._crit_edge:                                      ; preds = %4, %._crit_edge.loopexit, %2
  %.029 = phi i64 [ 0, %2 ], [ 0, %4 ], [ %9, %._crit_edge.loopexit ]
  ret i64 %.029
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
attributes #4 = { nounwind allocsize(1) }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}


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