; 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 i64 @ft_iterator_parent(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.ft_iterator, ptr %3, i32 0, i32 1
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = and i64 %5, 1
  %7 = icmp ne i64 %6, 0
  br i1 %7, label %8, label %24

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ft_iterator, ptr %9, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = udiv i64 %11, 2
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ft_iterator, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = sub i64 %15, %12
  store i64 %16, ptr %14, align 8, !tbaa !13
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ft_iterator, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = sub i64 %19, 1
  %21 = udiv i64 %20, 2
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ft_iterator, ptr %22, i32 0, i32 1
  store i64 %21, ptr %23, align 8, !tbaa !9
  br label %37

24:                                               ; preds = %1
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ft_iterator, ptr %25, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = udiv i64 %27, 2
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ft_iterator, ptr %29, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !13
  %32 = add i64 %31, %28
  store i64 %32, ptr %30, align 8, !tbaa !13
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ft_iterator, ptr %33, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = udiv i64 %35, 2
  store i64 %36, ptr %34, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %24, %8
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ft_iterator, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !12
  %41 = mul i64 %40, 2
  store i64 %41, ptr %39, align 8, !tbaa !12
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ft_iterator, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !13
  ret i64 %44
}

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

!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, !11, i64 8}
!10 = !{!"ft_iterator", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !11, i64 0}


; 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 willreturn memory(argmem: readwrite) uwtable
define dso_local i64 @ft_iterator_parent(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = and i64 %3, 1
  %.not = icmp ne i64 %4, 0
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i64, ptr %5, align 8, !tbaa !10
  %7 = lshr i64 %6, 1
  %8 = load i64, ptr %0, align 8, !tbaa !11
  %9 = sub nsw i64 0, %7
  %.sink.p = select i1 %.not, i64 %9, i64 %7
  %.sink = add i64 %8, %.sink.p
  %10 = sext i1 %.not to i64
  %storemerge.in = add nsw i64 %3, %10
  store i64 %.sink, ptr %0, align 8
  %storemerge = lshr i64 %storemerge.in, 1
  store i64 %storemerge, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = shl i64 %6, 1
  store i64 %12, ptr %11, align 8, !tbaa !10
  ret i64 %.sink
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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" }

!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 8}
!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 16}
!11 = !{!6, !7, i64 0}


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