; LLVM IR from qc-tum/chemtensor :: src/tensor (su2_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"

%struct.su2_tree_node = type { i32, [2 x ptr] }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_tree_node_is_leaf(ptr noundef) #1

; 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 zeroext i1 @su2_tree_equal_topology(ptr noalias noundef %0, ptr noalias noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %9)
  %11 = zext i1 %10 to i8
  store i8 %11, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %12)
  %14 = zext i1 %13 to i8
  store i8 %14, ptr %7, align 1, !tbaa !9
  %15 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i32
  %18 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %19 = trunc i8 %18 to i1
  %20 = zext i1 %19 to i32
  %21 = icmp ne i32 %17, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %49

23:                                               ; preds = %2
  %24 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %49

27:                                               ; preds = %23
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.su2_tree_node, ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds [2 x ptr], ptr %29, i64 0, i64 0
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.su2_tree_node, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds [2 x ptr], ptr %33, i64 0, i64 0
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = call zeroext i1 @su2_tree_equal_topology(ptr noundef %31, ptr noundef %35)
  br i1 %36, label %37, label %47

37:                                               ; preds = %27
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.su2_tree_node, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds [2 x ptr], ptr %39, i64 0, i64 1
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.su2_tree_node, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds [2 x ptr], ptr %43, i64 0, i64 1
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = call zeroext i1 @su2_tree_equal_topology(ptr noundef %41, ptr noundef %45)
  br label %47

47:                                               ; preds = %37, %27
  %48 = phi i1 [ false, %27 ], [ %46, %37 ]
  store i1 %48, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %49

49:                                               ; preds = %47, %26, %22
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %50 = load i1, ptr %3, align 1
  ret i1 %50
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


; 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: inlinehint nounwind uwtable
declare hidden zeroext i1 @su2_tree_node_is_leaf(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @su2_tree_equal_topology(ptr noalias noundef %0, ptr noalias noundef %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %0)
  %4 = tail call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %1)
  %brmerge14 = or i1 %3, %4
  br i1 %brmerge14, label %.split.loop.exit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse
  %.tr916 = phi ptr [ %13, %tailrecurse ], [ %1, %2 ]
  %.tr15 = phi ptr [ %11, %tailrecurse ], [ %0, %2 ]
  %5 = getelementptr inbounds i8, ptr %.tr15, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %.tr916, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call zeroext i1 @su2_tree_equal_topology(ptr noundef %6, ptr noundef %8)
  br i1 %9, label %tailrecurse, label %.split.loop.exit10

tailrecurse:                                      ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.tr15, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.tr916, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = tail call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %11)
  %15 = tail call zeroext i1 @su2_tree_node_is_leaf(ptr noundef %13)
  %brmerge = or i1 %14, %15
  br i1 %brmerge, label %.split.loop.exit, label %.lr.ph

.split.loop.exit:                                 ; preds = %tailrecurse, %2
  %.lcssa13 = phi i1 [ %4, %2 ], [ %15, %tailrecurse ]
  %.lcssa12 = phi i1 [ %3, %2 ], [ %14, %tailrecurse ]
  %16 = xor i1 %.lcssa12, %.lcssa13
  %not..le = xor i1 %16, true
  br label %.split.loop.exit10

.split.loop.exit10:                               ; preds = %.lr.ph, %.split.loop.exit
  %.0 = phi i1 [ %not..le, %.split.loop.exit ], [ false, %.lr.ph ]
  ret i1 %.0
}

attributes #0 = { inlinehint 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 = { 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"}


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