; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x16-Trie/144. 最长异或值路径.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"

@head = external dso_local global [100010 x i32], align 16
@ver = external dso_local global [200020 x i32], align 16
@edge = external dso_local global [200020 x i32], align 16
@Next = external dso_local global [200020 x i32], align 16
@d = external dso_local global [100010 x i32], 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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, 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
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %12
  store i32 %10, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %7, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %42, %3
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = xor i32 %19, -1
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %47

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200020 x i32], ptr @ver, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200020 x i32], ptr @edge, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %9, align 4, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = icmp ne i32 %32, %33
  br i1 %34, label %35, label %41

35:                                               ; preds = %23
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = xor i32 %38, %39
  call void @_Z3dfsiii(i32 noundef %36, i32 noundef %37, i32 noundef %40)
  br label %41

41:                                               ; preds = %35, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [200020 x i32], ptr @Next, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr %7, align 4, !tbaa !5
  br label %18, !llvm.loop !9

47:                                               ; preds = %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 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"}


; 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 [100010 x i32], align 16
@ver = external dso_local local_unnamed_addr global [200020 x i32], align 16
@edge = external dso_local local_unnamed_addr global [200020 x i32], align 16
@Next = external dso_local local_unnamed_addr global [200020 x i32], align 16
@d = external dso_local local_unnamed_addr global [100010 x i32], 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 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [100010 x i32], ptr @d, i64 0, i64 %4
  store i32 %2, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %4
  %.015 = load i32, ptr %6, align 4, !tbaa !5
  %.not16 = icmp eq i32 %.015, -1
  br i1 %.not16, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %14, %3
  ret void

.lr.ph:                                           ; preds = %3, %14
  %.017 = phi i32 [ %.0, %14 ], [ %.015, %3 ]
  %7 = sext i32 %.017 to i64
  %8 = getelementptr inbounds [200020 x i32], ptr @ver, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not14 = icmp eq i32 %9, %1
  br i1 %.not14, label %14, label %10

10:                                               ; preds = %.lr.ph
  %11 = getelementptr inbounds [200020 x i32], ptr @edge, i64 0, i64 %7
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = xor i32 %12, %2
  tail call void @_Z3dfsiii(i32 noundef %9, i32 noundef %0, i32 noundef %13)
  br label %14

14:                                               ; preds = %10, %.lr.ph
  %15 = getelementptr inbounds [200020 x i32], ptr @Next, i64 0, i64 %7
  %.0 = load i32, ptr %15, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

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


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