; LLVM IR from ahampriyanshu/algo-ds-101 :: Data-Structures/Tree/Binary-Tree/Vertical_Sum (Verticle_sum_of_Binary_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.LLNode = type { i32, ptr, ptr }
%struct.TNode = type { i32, ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z9newLLNodei(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z18verticalSumDLLUtilP5TNodeP6LLNode(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.LLNode, ptr %5, i32 0, i32 0
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.TNode, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = add nsw i32 %7, %10
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LLNode, ptr %12, i32 0, i32 0
  store i32 %11, ptr %13, align 8, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TNode, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %39

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.LLNode, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %32

23:                                               ; preds = %18
  %24 = call noundef ptr @_Z9newLLNodei(i32 noundef 0)
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LLNode, ptr %25, i32 0, i32 1
  store ptr %24, ptr %26, align 8, !tbaa !15
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LLNode, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.LLNode, ptr %30, i32 0, i32 2
  store ptr %27, ptr %31, align 8, !tbaa !16
  br label %32

32:                                               ; preds = %23, %18
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TNode, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LLNode, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  call void @_Z18verticalSumDLLUtilP5TNodeP6LLNode(ptr noundef %35, ptr noundef %38)
  br label %39

39:                                               ; preds = %32, %2
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TNode, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %65

44:                                               ; preds = %39
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.LLNode, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %58

49:                                               ; preds = %44
  %50 = call noundef ptr @_Z9newLLNodei(i32 noundef 0)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.LLNode, ptr %51, i32 0, i32 2
  store ptr %50, ptr %52, align 8, !tbaa !16
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.LLNode, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = getelementptr inbounds %struct.LLNode, ptr %56, i32 0, i32 1
  store ptr %53, ptr %57, align 8, !tbaa !15
  br label %58

58:                                               ; preds = %49, %44
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TNode, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !17
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.LLNode, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !16
  call void @_Z18verticalSumDLLUtilP5TNodeP6LLNode(ptr noundef %61, ptr noundef %64)
  br label %65

65:                                               ; preds = %58, %39
  ret void
}

attributes #0 = { mustprogress 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS6LLNode", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_ZTS5TNode", !11, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!13, !6, i64 8}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !6, i64 16}
!17 = !{!13, !6, 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: mustprogress uwtable
declare dso_local noundef ptr @_Z9newLLNodei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z18verticalSumDLLUtilP5TNodeP6LLNode(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %2
  %.tr = phi ptr [ %0, %2 ], [ %.tr.be, %tailrecurse.backedge ]
  %.tr18 = phi ptr [ %1, %2 ], [ %.tr18.be, %tailrecurse.backedge ]
  %3 = load i32, ptr %.tr18, align 8, !tbaa !5
  %4 = load i32, ptr %.tr, align 8, !tbaa !11
  %5 = add nsw i32 %4, %3
  store i32 %5, ptr %.tr18, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %.tr, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %18, label %8

8:                                                ; preds = %tailrecurse
  %9 = getelementptr inbounds i8, ptr %.tr18, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  %13 = tail call noundef ptr @_Z9newLLNodei(i32 noundef 0)
  store ptr %13, ptr %9, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %.tr18, ptr %14, align 8, !tbaa !15
  %.pre = load ptr, ptr %6, align 8, !tbaa !13
  br label %15

15:                                               ; preds = %12, %8
  %16 = phi ptr [ %13, %12 ], [ %10, %8 ]
  %17 = phi ptr [ %.pre, %12 ], [ %7, %8 ]
  tail call void @_Z18verticalSumDLLUtilP5TNodeP6LLNode(ptr noundef %17, ptr noundef nonnull %16)
  br label %18

18:                                               ; preds = %15, %tailrecurse
  %19 = getelementptr inbounds i8, ptr %.tr, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %.not17 = icmp eq ptr %20, null
  br i1 %.not17, label %28, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %.tr18, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %tailrecurse.backedge

25:                                               ; preds = %21
  %26 = tail call noundef ptr @_Z9newLLNodei(i32 noundef 0)
  store ptr %26, ptr %22, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  store ptr %.tr18, ptr %27, align 8, !tbaa !14
  %.pre19 = load ptr, ptr %19, align 8, !tbaa !16
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %25, %21
  %.tr.be = phi ptr [ %.pre19, %25 ], [ %20, %21 ]
  %.tr18.be = phi ptr [ %26, %25 ], [ %23, %21 ]
  br label %tailrecurse

28:                                               ; preds = %18
  ret void
}

attributes #0 = { mustprogress 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 0}
!6 = !{!"_ZTS6LLNode", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTS5TNode", !7, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!6, !10, i64 8}
!15 = !{!6, !10, i64 16}
!16 = !{!12, !10, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass