; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1159. Structure of a Binary Tree (30).ll (Z9TraversalP8TreeNode)

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

@is_full = external dso_local global i8, align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9TraversalP8TreeNode(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 = icmp ne ptr %3, null
  br i1 %4, label %6, label %5

5:                                                ; preds = %1
  br label %49

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.TreeNode, ptr %7, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %20

11:                                               ; preds = %6
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TreeNode, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.TreeNode, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = add nsw i32 %16, 1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TreeNode, ptr %18, i32 0, i32 1
  store i32 %17, ptr %19, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %11, %6
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TreeNode, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %31

25:                                               ; preds = %20
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TreeNode, ptr %26, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i8 0, ptr @is_full, align 1, !tbaa !15
  br label %31

31:                                               ; preds = %30, %25, %20
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.TreeNode, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = icmp ne ptr %34, null
  br i1 %35, label %42, label %36

36:                                               ; preds = %31
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TreeNode, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i8 0, ptr @is_full, align 1, !tbaa !15
  br label %42

42:                                               ; preds = %41, %36, %31
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TreeNode, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  call void @_Z9TraversalP8TreeNode(ptr noundef %45)
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TreeNode, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  call void @_Z9TraversalP8TreeNode(ptr noundef %48)
  br label %49

49:                                               ; preds = %42, %5
  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, !6, i64 8}
!10 = !{!"_ZTS8TreeNode", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"bool", !7, 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"

@is_full = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z9TraversalP8TreeNode(ptr noundef %0) local_unnamed_addr #0 {
  %.not16 = icmp eq ptr %0, null
  br i1 %.not16, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.thread
  %.tr17 = phi ptr [ %16, %.thread ], [ %0, %1 ]
  %2 = getelementptr inbounds i8, ptr %.tr17, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not11 = icmp eq ptr %3, null
  br i1 %.not11, label %9, label %4

4:                                                ; preds = %.lr.ph
  %5 = getelementptr inbounds i8, ptr %3, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = add nsw i32 %6, 1
  %8 = getelementptr inbounds i8, ptr %.tr17, i64 4
  store i32 %7, ptr %8, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %4, %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.tr17, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not12 = icmp eq ptr %11, null
  %12 = getelementptr inbounds i8, ptr %.tr17, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %.not15 = icmp eq ptr %13, null
  %14 = xor i1 %.not12, %.not15
  br i1 %14, label %.thread.sink.split, label %.thread

.thread.sink.split:                               ; preds = %9
  store i8 0, ptr @is_full, align 1, !tbaa !14
  br label %.thread

.thread:                                          ; preds = %9, %.thread.sink.split
  tail call void @_Z9TraversalP8TreeNode(ptr noundef %11)
  %15 = getelementptr inbounds i8, ptr %.tr17, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %.thread, %1
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !10, i64 8}
!6 = !{!"_ZTS8TreeNode", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 24}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass