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

; 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.ft_iterator = type { i64, i64, i64 }

; Function Attrs: nounwind uwtable
define dso_local void @ft_iterator_seek(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ft_iterator, ptr %6, i32 0, i32 0
  store i64 %5, ptr %7, align 8, !tbaa !11
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ft_iterator, ptr %8, i32 0, i32 0
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = and i64 %10, 1
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %24

13:                                               ; preds = %2
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = call i64 @ft_offset(i64 noundef %14, i64 noundef 0)
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ft_iterator, ptr %16, i32 0, i32 1
  store i64 %15, ptr %17, align 8, !tbaa !13
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = call i64 @ft_depth(i64 noundef %18)
  %20 = add i64 %19, 1
  %21 = call i64 @ft_two_pow(i64 noundef %20)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ft_iterator, ptr %22, i32 0, i32 2
  store i64 %21, ptr %23, align 8, !tbaa !14
  br label %31

24:                                               ; preds = %2
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = udiv i64 %25, 2
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ft_iterator, ptr %27, i32 0, i32 1
  store i64 %26, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ft_iterator, ptr %29, i32 0, i32 2
  store i64 2, ptr %30, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %24, %13
  ret void
}

declare i64 @ft_offset(i64 noundef, i64 noundef) #1

declare i64 @ft_two_pow(i64 noundef) #1

declare i64 @ft_depth(i64 noundef) #1

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 = { "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, !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, !10, i64 0}
!12 = !{!"ft_iterator", !10, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 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: nounwind uwtable
define dso_local void @ft_iterator_seek(ptr nocapture noundef writeonly %0, i64 noundef %1) local_unnamed_addr #0 {
  store i64 %1, ptr %0, align 8, !tbaa !5
  %3 = and i64 %1, 1
  %.not = icmp eq i64 %3, 0
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %.not, label %10, label %5

5:                                                ; preds = %2
  %6 = tail call i64 @ft_offset(i64 noundef %1, i64 noundef 0) #2
  store i64 %6, ptr %4, align 8, !tbaa !10
  %7 = tail call i64 @ft_depth(i64 noundef %1) #2
  %8 = add i64 %7, 1
  %9 = tail call i64 @ft_two_pow(i64 noundef %8) #2
  br label %12

10:                                               ; preds = %2
  %11 = lshr exact i64 %1, 1
  store i64 %11, ptr %4, align 8, !tbaa !10
  br label %12

12:                                               ; preds = %10, %5
  %.sink = phi i64 [ 2, %10 ], [ %9, %5 ]
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %.sink, ptr %13, align 8
  ret void
}

declare i64 @ft_offset(i64 noundef, i64 noundef) local_unnamed_addr #1

declare i64 @ft_two_pow(i64 noundef) local_unnamed_addr #1

declare i64 @ft_depth(i64 noundef) local_unnamed_addr #1

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 = { "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, !7, i64 0}
!6 = !{!"ft_iterator", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass