; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/树算法/树的欧拉序.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"

@head = external dso_local global [210000 x i32], align 16
@nxt = external dso_local global [210000 x i32], align 16
@to = external dso_local global [210000 x i32], align 16
@seq = external dso_local global [210000 x i32], align 16
@depth = external dso_local global [210000 x i32], align 16
@anc = external dso_local global [210000 x [25 x i32]], align 16
@first = external dso_local global [210000 x i32], align 16
@last = external dso_local global [210000 x i32], align 16
@sz = 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
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr @sz, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @sz, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [210000 x i32], ptr @seq, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr @sz, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [210000 x i32], ptr @first, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [210000 x i32], ptr @head, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %21, ptr %5, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %89, %2
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %94

26:                                               ; preds = %22
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [210000 x i32], ptr @to, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp ne i32 %30, %31
  br i1 %32, label %33, label %88

33:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [210000 x i32], ptr @to, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [210000 x i32], ptr @depth, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [210000 x i32], ptr @depth, i64 0, i64 %44
  store i32 %42, ptr %45, align 4, !tbaa !5
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [210000 x [25 x i32]], ptr @anc, i64 0, i64 %48
  %50 = getelementptr inbounds [25 x i32], ptr %49, i64 0, i64 0
  store i32 %46, ptr %50, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %82, %33
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = shl i32 1, %52
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [210000 x i32], ptr @depth, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = icmp sle i32 %53, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %51
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %85

60:                                               ; preds = %51
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [210000 x [25 x i32]], ptr @anc, i64 0, i64 %62
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [25 x i32], ptr %63, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [210000 x [25 x i32]], ptr @anc, i64 0, i64 %69
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = sub nsw i32 %71, 1
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [25 x i32], ptr %70, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [210000 x [25 x i32]], ptr @anc, i64 0, i64 %77
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [25 x i32], ptr %78, i64 0, i64 %80
  store i32 %75, ptr %81, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %60
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %8, align 4, !tbaa !5
  br label %51, !llvm.loop !9

85:                                               ; preds = %59
  %86 = load i32, ptr %7, align 4, !tbaa !5
  %87 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %86, i32 noundef %87)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %88

88:                                               ; preds = %85, %26
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [210000 x i32], ptr @nxt, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  store i32 %93, ptr %5, align 4, !tbaa !5
  br label %22, !llvm.loop !11

94:                                               ; preds = %25
  %95 = load i32, ptr %3, align 4, !tbaa !5
  %96 = load i32, ptr @sz, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr @sz, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [210000 x i32], ptr @seq, i64 0, i64 %98
  store i32 %95, ptr %99, align 4, !tbaa !5
  %100 = load i32, ptr @sz, align 4, !tbaa !5
  %101 = load i32, ptr %3, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [210000 x i32], ptr @last, i64 0, i64 %102
  store i32 %100, ptr %103, align 4, !tbaa !5
  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 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 = { 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"}
!11 = distinct !{!11, !10}


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

@head = external dso_local local_unnamed_addr global [210000 x i32], align 16
@nxt = external dso_local local_unnamed_addr global [210000 x i32], align 16
@to = external dso_local local_unnamed_addr global [210000 x i32], align 16
@seq = external dso_local local_unnamed_addr global [210000 x i32], align 16
@depth = external dso_local local_unnamed_addr global [210000 x i32], align 16
@anc = external dso_local local_unnamed_addr global [210000 x [25 x i32]], align 16
@first = external dso_local local_unnamed_addr global [210000 x i32], align 16
@last = external dso_local local_unnamed_addr global [210000 x i32], align 16
@sz = 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 {
  %3 = load i32, ptr @sz, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @sz, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [210000 x i32], ptr @seq, i64 0, i64 %5
  store i32 %0, ptr %6, align 4, !tbaa !5
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [210000 x i32], ptr @first, i64 0, i64 %7
  store i32 %4, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds [210000 x i32], ptr @head, i64 0, i64 %7
  %.02430 = load i32, ptr %9, align 4, !tbaa !5
  %.not31 = icmp eq i32 %.02430, 0
  br i1 %.not31, label %._crit_edge35, label %.lr.ph34

.lr.ph34:                                         ; preds = %2
  %10 = getelementptr inbounds [210000 x i32], ptr @depth, i64 0, i64 %7
  br label %16

._crit_edge35.loopexit:                           ; preds = %34
  %.pre37 = load i32, ptr @sz, align 4, !tbaa !5
  br label %._crit_edge35

._crit_edge35:                                    ; preds = %._crit_edge35.loopexit, %2
  %11 = phi i32 [ %.pre37, %._crit_edge35.loopexit ], [ %4, %2 ]
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @sz, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [210000 x i32], ptr @seq, i64 0, i64 %13
  store i32 %0, ptr %14, align 4, !tbaa !5
  %15 = getelementptr inbounds [210000 x i32], ptr @last, i64 0, i64 %7
  store i32 %12, ptr %15, align 4, !tbaa !5
  ret void

16:                                               ; preds = %.lr.ph34, %34
  %.02432 = phi i32 [ %.02430, %.lr.ph34 ], [ %.024, %34 ]
  %17 = sext i32 %.02432 to i64
  %18 = getelementptr inbounds [210000 x i32], ptr @to, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not26 = icmp eq i32 %19, %1
  br i1 %.not26, label %34, label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %10, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %19 to i64
  %24 = getelementptr inbounds [210000 x i32], ptr @depth, i64 0, i64 %23
  store i32 %22, ptr %24, align 4, !tbaa !5
  %25 = getelementptr inbounds [210000 x [25 x i32]], ptr @anc, i64 0, i64 %23
  store i32 %0, ptr %25, align 4, !tbaa !5
  %.not2728 = icmp slt i32 %21, 1
  br i1 %.not2728, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %20
  tail call void @_Z3dfsii(i32 noundef %19, i32 noundef %0)
  br label %34

.lr.ph:                                           ; preds = %20, %.lr.ph
  %26 = phi i32 [ %30, %.lr.ph ], [ %0, %20 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %20 ]
  %27 = add nsw i64 %indvars.iv, -1
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [210000 x [25 x i32]], ptr @anc, i64 0, i64 %28, i64 %27
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = getelementptr inbounds [210000 x [25 x i32]], ptr @anc, i64 0, i64 %23, i64 %indvars.iv
  store i32 %30, ptr %31, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = trunc nuw nsw i64 %indvars.iv to i32
  %33 = shl nuw i32 2, %32
  %.not27 = icmp sgt i32 %33, %22
  br i1 %.not27, label %._crit_edge, label %.lr.ph, !llvm.loop !9

34:                                               ; preds = %16, %._crit_edge
  %35 = getelementptr inbounds [210000 x i32], ptr @nxt, i64 0, i64 %17
  %.024 = load i32, ptr %35, align 4, !tbaa !5
  %.not = icmp eq i32 %.024, 0
  br i1 %.not, label %._crit_edge35.loopexit, label %16, !llvm.loop !11
}

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


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