; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1127. ZigZagging on a Tree (30) .ll (Z3dfsRiiiii)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@in = external dso_local global %"class.std::vector", align 8
@post = external dso_local global %"class.std::vector", align 8
@tree = external dso_local global [35 x [2 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp sgt i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %5
  br label %63

16:                                               ; preds = %5
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %17, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %29, %16
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @in, i64 noundef %21) #3
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @post, i64 noundef %25) #3
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = icmp ne i32 %23, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %19
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !11

32:                                               ; preds = %19
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [35 x [2 x i32]], ptr @tree, i64 0, i64 %35
  %37 = getelementptr inbounds [2 x i32], ptr %36, i64 0, i64 0
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = sub nsw i32 %39, 1
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = sub nsw i32 %43, %44
  %46 = add nsw i32 %42, %45
  %47 = sub nsw i32 %46, 1
  call void @_Z3dfsRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %37, i32 noundef %38, i32 noundef %40, i32 noundef %41, i32 noundef %47)
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [35 x [2 x i32]], ptr @tree, i64 0, i64 %50
  %52 = getelementptr inbounds [2 x i32], ptr %51, i64 0, i64 1
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = sub nsw i32 %57, %58
  %60 = add nsw i32 %56, %59
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = sub nsw i32 %61, 1
  call void @_Z3dfsRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %52, i32 noundef %54, i32 noundef %55, i32 noundef %60, i32 noundef %62)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %63

63:                                               ; preds = %32, %15
  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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 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 = { mustprogress 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@in = external dso_local global %"class.std::vector", align 8
@post = external dso_local global %"class.std::vector", align 8
@tree = external dso_local global [35 x [2 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsRiiiii(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %1, %2
  br i1 %6, label %tailrecurse._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %7 = sext i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse
  %indvars.iv32 = phi i64 [ %7, %.lr.ph.preheader ], [ %indvars.iv.next33, %tailrecurse ]
  %.tr2428 = phi i32 [ %3, %.lr.ph.preheader ], [ %20, %tailrecurse ]
  %.tr2227 = phi i32 [ %1, %.lr.ph.preheader ], [ %25, %tailrecurse ]
  %.tr26 = phi ptr [ %0, %.lr.ph.preheader ], [ %24, %tailrecurse ]
  %8 = trunc nsw i64 %indvars.iv32 to i32
  store i32 %8, ptr %.tr26, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %9, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %9 ], [ 0, %.lr.ph ]
  %10 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @in, i64 noundef %indvars.iv) #1
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @post, i64 noundef %indvars.iv32) #1
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not = icmp eq i32 %11, %13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %tailrecurse, label %9, !llvm.loop !9

tailrecurse:                                      ; preds = %9
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  %15 = load i32, ptr %.tr26, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [35 x [2 x i32]], ptr @tree, i64 0, i64 %16
  %18 = add nsw i32 %14, -1
  %19 = sub nsw i32 %14, %.tr2227
  %20 = add nsw i32 %19, %.tr2428
  %21 = add nsw i32 %20, -1
  tail call void @_Z3dfsRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %17, i32 noundef %.tr2227, i32 noundef %18, i32 noundef %.tr2428, i32 noundef %21)
  %22 = load i32, ptr %.tr26, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [35 x [2 x i32]], ptr @tree, i64 0, i64 %23, i64 1
  %25 = add nuw nsw i32 %14, 1
  %indvars.iv.next33 = add nsw i64 %indvars.iv32, -1
  %.not30 = icmp slt i32 %14, %2
  br i1 %.not30, label %.lr.ph, label %tailrecurse._crit_edge

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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