; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1099. Build A Binary Search Tree (30).ll (Z3dfsiii)

; 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, i32, i32, i32 }

@cnt = external dso_local global i32, align 4
@b = external dso_local global [100 x i32], align 16
@a = external dso_local global [110 x %struct.node], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.node, align 4
  %8 = alloca %struct.node, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %10
  %12 = getelementptr inbounds %struct.node, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %48

15:                                               ; preds = %3
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.node, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %22, label %48

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 20, ptr %7) #3
  %23 = getelementptr inbounds %struct.node, ptr %7, i32 0, i32 0
  %24 = load i32, ptr @cnt, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @cnt, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [100 x i32], ptr @b, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %23, align 4, !tbaa !12
  %29 = getelementptr inbounds %struct.node, ptr %7, i32 0, i32 1
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !9
  store i32 %34, ptr %29, align 4, !tbaa !9
  %35 = getelementptr inbounds %struct.node, ptr %7, i32 0, i32 2
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !11
  store i32 %40, ptr %35, align 4, !tbaa !11
  %41 = getelementptr inbounds %struct.node, ptr %7, i32 0, i32 3
  %42 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %42, ptr %41, align 4, !tbaa !13
  %43 = getelementptr inbounds %struct.node, ptr %7, i32 0, i32 4
  %44 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %44, ptr %43, align 4, !tbaa !14
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %46
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %47, ptr align 4 %7, i64 20, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 20, ptr %7) #3
  br label %110

48:                                               ; preds = %15, %3
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = icmp ne i32 %53, -1
  br i1 %54, label %55, label %66

55:                                               ; preds = %48
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = mul nsw i32 %61, 2
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  call void @_Z3dfsiii(i32 noundef %60, i32 noundef %63, i32 noundef %65)
  br label %66

66:                                               ; preds = %55, %48
  call void @llvm.lifetime.start.p0(i64 20, ptr %8) #3
  %67 = getelementptr inbounds %struct.node, ptr %8, i32 0, i32 0
  %68 = load i32, ptr @cnt, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr @cnt, align 4, !tbaa !5
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds [100 x i32], ptr @b, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  store i32 %72, ptr %67, align 4, !tbaa !12
  %73 = getelementptr inbounds %struct.node, ptr %8, i32 0, i32 1
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %75
  %77 = getelementptr inbounds %struct.node, ptr %76, i32 0, i32 1
  %78 = load i32, ptr %77, align 4, !tbaa !9
  store i32 %78, ptr %73, align 4, !tbaa !9
  %79 = getelementptr inbounds %struct.node, ptr %8, i32 0, i32 2
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.node, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 4, !tbaa !11
  store i32 %84, ptr %79, align 4, !tbaa !11
  %85 = getelementptr inbounds %struct.node, ptr %8, i32 0, i32 3
  %86 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %86, ptr %85, align 4, !tbaa !13
  %87 = getelementptr inbounds %struct.node, ptr %8, i32 0, i32 4
  %88 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %88, ptr %87, align 4, !tbaa !14
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %90
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %91, ptr align 4 %8, i64 20, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 20, ptr %8) #3
  %92 = load i32, ptr %4, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %93
  %95 = getelementptr inbounds %struct.node, ptr %94, i32 0, i32 2
  %96 = load i32, ptr %95, align 4, !tbaa !11
  %97 = icmp ne i32 %96, -1
  br i1 %97, label %98, label %109

98:                                               ; preds = %66
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %100
  %102 = getelementptr inbounds %struct.node, ptr %101, i32 0, i32 2
  %103 = load i32, ptr %102, align 4, !tbaa !11
  %104 = load i32, ptr %5, align 4, !tbaa !5
  %105 = mul nsw i32 %104, 2
  %106 = add nsw i32 %105, 2
  %107 = load i32, ptr %6, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  call void @_Z3dfsiii(i32 noundef %103, i32 noundef %106, i32 noundef %108)
  br label %109

109:                                              ; preds = %98, %66
  br label %110

110:                                              ; preds = %109, %22
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 12}
!14 = !{!10, !6, i64 16}
!15 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5}


; 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, i32, i32, i32 }

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

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %28, %3
  %.tr = phi i32 [ %0, %3 ], [ %22, %28 ]
  %.tr27 = phi i32 [ %1, %3 ], [ %30, %28 ]
  %.tr28 = phi i32 [ %2, %3 ], [ %31, %28 ]
  %4 = sext i32 %.tr to i64
  %5 = getelementptr inbounds [110 x %struct.node], ptr @a, i64 0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %9, label %18

9:                                                ; preds = %tailrecurse
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  %11 = load i32, ptr %10, align 4, !tbaa !10
  %12 = icmp eq i32 %11, -1
  %.pre35 = load i32, ptr @cnt, align 4, !tbaa !11
  br i1 %12, label %13, label %.thread

13:                                               ; preds = %9
  %14 = add nsw i32 %.pre35, 1
  store i32 %14, ptr @cnt, align 4, !tbaa !11
  %15 = sext i32 %.pre35 to i64
  %16 = getelementptr inbounds [100 x i32], ptr @b, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !11
  store i32 %17, ptr %5, align 4, !tbaa !11
  %.sroa.64.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %.tr27, ptr %.sroa.64.0..sroa_idx, align 4, !tbaa !11
  %.sroa.75.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %.tr28, ptr %.sroa.75.0..sroa_idx, align 4, !tbaa !11
  br label %.loopexit

18:                                               ; preds = %tailrecurse
  %19 = shl nsw i32 %.tr27, 1
  %20 = or disjoint i32 %19, 1
  %21 = add nsw i32 %.tr28, 1
  tail call void @_Z3dfsiii(i32 noundef %7, i32 noundef %20, i32 noundef %21)
  %.pre = load i32, ptr @cnt, align 4, !tbaa !11
  %.phi.trans.insert = getelementptr inbounds i8, ptr %5, i64 8
  %.pre36 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  br label %.thread

.thread:                                          ; preds = %9, %18
  %22 = phi i32 [ %11, %9 ], [ %.pre36, %18 ]
  %23 = phi i32 [ %.pre35, %9 ], [ %.pre, %18 ]
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @cnt, align 4, !tbaa !11
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [100 x i32], ptr @b, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !11
  store i32 %27, ptr %5, align 4, !tbaa !11
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %.tr27, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !11
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %.tr28, ptr %.sroa.7.0..sroa_idx, align 4, !tbaa !11
  %.not26 = icmp eq i32 %22, -1
  br i1 %.not26, label %.loopexit, label %28

28:                                               ; preds = %.thread
  %29 = shl nsw i32 %.tr27, 1
  %30 = add nsw i32 %29, 2
  %31 = add nsw i32 %.tr28, 1
  br label %tailrecurse

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


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