; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1110. Complete Binary Tree (25).ll (Z3dfsii)

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

@a = external dso_local global [100 x %struct.node], align 16
@maxn = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr @maxn, align 4, !tbaa !5
  %7 = icmp sgt i32 %5, %6
  br i1 %7, label %8, label %11

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %9, ptr @maxn, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %10, ptr @ans, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %8, %2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100 x %struct.node], ptr @a, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.node, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = icmp ne i32 %16, -1
  br i1 %17, label %18, label %26

18:                                               ; preds = %11
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100 x %struct.node], ptr @a, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = mul nsw i32 %24, 2
  call void @_Z3dfsii(i32 noundef %23, i32 noundef %25)
  br label %26

26:                                               ; preds = %18, %11
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100 x %struct.node], ptr @a, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = icmp ne i32 %31, -1
  br i1 %32, label %33, label %42

33:                                               ; preds = %26
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100 x %struct.node], ptr @a, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.node, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = mul nsw i32 %39, 2
  %41 = add nsw i32 %40, 1
  call void @_Z3dfsii(i32 noundef %38, i32 noundef %41)
  br label %42

42:                                               ; preds = %33, %26
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}


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

%struct.node = type { i32, i32 }

@a = external dso_local local_unnamed_addr global [100 x %struct.node], align 16
@maxn = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.pre13 = load i32, ptr @maxn, align 4, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %17, %2
  %3 = phi i32 [ %.pre13, %2 ], [ %14, %17 ]
  %.tr = phi i32 [ %0, %2 ], [ %16, %17 ]
  %.tr12 = phi i32 [ %1, %2 ], [ %19, %17 ]
  %4 = icmp slt i32 %3, %.tr12
  br i1 %4, label %5, label %6

5:                                                ; preds = %tailrecurse
  store i32 %.tr12, ptr @maxn, align 4, !tbaa !5
  store i32 %.tr, ptr @ans, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %5, %tailrecurse
  %7 = phi i32 [ %.tr12, %5 ], [ %3, %tailrecurse ]
  %8 = sext i32 %.tr to i64
  %9 = getelementptr inbounds [100 x %struct.node], ptr @a, i64 0, i64 %8
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %.not = icmp eq i32 %10, -1
  br i1 %.not, label %13, label %11

11:                                               ; preds = %6
  %12 = shl nsw i32 %.tr12, 1
  tail call void @_Z3dfsii(i32 noundef %10, i32 noundef %12)
  %.pre = load i32, ptr @maxn, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %11, %6
  %14 = phi i32 [ %.pre, %11 ], [ %7, %6 ]
  %15 = getelementptr inbounds i8, ptr %9, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %.not11 = icmp eq i32 %16, -1
  br i1 %.not11, label %20, label %17

17:                                               ; preds = %13
  %18 = shl nsw i32 %.tr12, 1
  %19 = or disjoint i32 %18, 1
  br label %tailrecurse

20:                                               ; preds = %13
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}


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