; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (quadrature)

; 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.adaptive_integration_tree_node = type { double, double, ptr, ptr, i32, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @reduce_tree(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %5, i32 0, i32 4
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %23

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = call i32 @burn_tree(ptr noundef %13)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %15, i32 0, i32 6
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = call i32 @burn_tree(ptr noundef %17)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %19, i32 0, i32 5
  store ptr null, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %21, i32 0, i32 6
  store ptr null, ptr %22, align 8, !tbaa !15
  br label %41

23:                                               ; preds = %2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %24, i32 0, i32 4
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp sgt i32 %26, %27
  br i1 %28, label %29, label %40

29:                                               ; preds = %23
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = call i32 @reduce_tree(ptr noundef %32, i32 noundef %33)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.adaptive_integration_tree_node, ptr %35, i32 0, i32 6
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = call i32 @reduce_tree(ptr noundef %37, i32 noundef %38)
  br label %40

40:                                               ; preds = %29, %23
  br label %41

41:                                               ; preds = %40, %10
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @burn_tree(ptr noundef) #0

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"adaptive_integration_tree_node", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !6, i64 40}
!15 = !{!12, !6, i64 48}


; 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 noundef i32 @reduce_tree(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, %1
  br i1 %.not, label %tailrecurse._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %5 = icmp sgt i32 %4, %1
  br i1 %5, label %tailrecurse.peel, label %.loopexit

tailrecurse.peel:                                 ; preds = %.lr.ph.preheader
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = tail call i32 @reduce_tree(ptr noundef %7, i32 noundef %1)
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %10, i64 32
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = icmp eq i32 %12, %1
  br i1 %13, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %tailrecurse.peel, %2
  %.tr.lcssa = phi ptr [ %0, %2 ], [ %10, %tailrecurse.peel ], [ %26, %tailrecurse ]
  %14 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = tail call i32 @burn_tree(ptr noundef %15)
  %17 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 48
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = tail call i32 @burn_tree(ptr noundef %18)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %14, i8 0, i64 16, i1 false)
  br label %.loopexit

.lr.ph:                                           ; preds = %tailrecurse.peel, %tailrecurse
  %20 = phi i32 [ %28, %tailrecurse ], [ %12, %tailrecurse.peel ]
  %.tr19 = phi ptr [ %26, %tailrecurse ], [ %10, %tailrecurse.peel ]
  %21 = icmp sgt i32 %20, %1
  br i1 %21, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %.lr.ph
  %22 = getelementptr inbounds i8, ptr %.tr19, i64 40
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = tail call i32 @reduce_tree(ptr noundef %23, i32 noundef %1)
  %25 = getelementptr inbounds i8, ptr %.tr19, i64 48
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %26, i64 32
  %28 = load i32, ptr %27, align 8, !tbaa !5
  %29 = icmp eq i32 %28, %1
  br i1 %29, label %tailrecurse._crit_edge, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph.preheader, %tailrecurse._crit_edge
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @burn_tree(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !11, i64 32}
!6 = !{!"adaptive_integration_tree_node", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !10, i64 40, !10, i64 48}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 40}
!13 = !{!6, !10, i64 48}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass