; LLVM IR from Dev-XYS/Algorithms :: Least-Common-Ancestor(Tarjan).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.vertex = type { i32, i8 }
%struct.edge = type { i32, i32 }
%struct.qvertex = type { i32 }
%struct.qedge = type { i32, i32, i32 }

@V = external dso_local global [100000 x %struct.vertex], align 16
@E = external dso_local global [100000 x %struct.edge], align 16
@QV = external dso_local global [100000 x %struct.qvertex], align 16
@QE = external dso_local global [100000 x %struct.qedge], align 16
@ancestor = external dso_local global [100000 x i32], align 16

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z8get_rooti(i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5mergeii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3DFSii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = call noundef i32 @_Z8get_rooti(i32 noundef %8)
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100000 x i32], ptr @ancestor, i64 0, i64 %10
  store i32 %7, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.vertex, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  store i32 %16, ptr %5, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %48, %2
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %54

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.edge, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !12
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp ne i32 %26, %27
  br i1 %28, label %29, label %47

29:                                               ; preds = %21
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.edge, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !12
  %35 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3DFSii(i32 noundef %34, i32 noundef %35)
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.edge, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !12
  call void @_Z5mergeii(i32 noundef %36, i32 noundef %41)
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = call noundef i32 @_Z8get_rooti(i32 noundef %43)
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100000 x i32], ptr @ancestor, i64 0, i64 %45
  store i32 %42, ptr %46, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %29, %21
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.edge, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !14
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %17, !llvm.loop !15

54:                                               ; preds = %20
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.vertex, ptr %57, i32 0, i32 1
  store i8 1, ptr %58, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100000 x %struct.qvertex], ptr @QV, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.qvertex, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !18
  store i32 %63, ptr %6, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %96, %54
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %68, label %67

67:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %102

68:                                               ; preds = %64
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100000 x %struct.qedge], ptr @QE, i64 0, i64 %70
  %72 = getelementptr inbounds %struct.qedge, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 4, !tbaa !20
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.vertex, ptr %75, i32 0, i32 1
  %77 = load i8, ptr %76, align 4, !tbaa !17, !range !22, !noundef !23
  %78 = trunc i8 %77 to i1
  %79 = zext i1 %78 to i32
  %80 = icmp eq i32 %79, 1
  br i1 %80, label %81, label %95

81:                                               ; preds = %68
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [100000 x %struct.qedge], ptr @QE, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.qedge, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 4, !tbaa !20
  %87 = call noundef i32 @_Z8get_rooti(i32 noundef %86)
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [100000 x i32], ptr @ancestor, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [100000 x %struct.qedge], ptr @QE, i64 0, i64 %92
  %94 = getelementptr inbounds %struct.qedge, ptr %93, i32 0, i32 2
  store i32 %90, ptr %94, align 4, !tbaa !24
  br label %95

95:                                               ; preds = %81, %68
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [100000 x %struct.qedge], ptr @QE, i64 0, i64 %98
  %100 = getelementptr inbounds %struct.qedge, ptr %99, i32 0, i32 1
  %101 = load i32, ptr %100, align 4, !tbaa !25
  store i32 %101, ptr %6, align 4, !tbaa !5
  br label %64, !llvm.loop !26

102:                                              ; preds = %67
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS6vertex", !6, i64 0, !11, i64 4}
!11 = !{!"bool", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!14 = !{!13, !6, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !11, i64 4}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTS7qvertex", !6, i64 0}
!20 = !{!21, !6, i64 0}
!21 = !{!"_ZTS5qedge", !6, i64 0, !6, i64 4, !6, i64 8}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!21, !6, i64 8}
!25 = !{!21, !6, i64 4}
!26 = distinct !{!26, !16}


; 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.vertex = type { i32, i8 }
%struct.edge = type { i32, i32 }
%struct.qvertex = type { i32 }
%struct.qedge = type { i32, i32, i32 }

@V = external dso_local local_unnamed_addr global [100000 x %struct.vertex], align 16
@E = external dso_local local_unnamed_addr global [100000 x %struct.edge], align 16
@QV = external dso_local local_unnamed_addr global [100000 x %struct.qvertex], align 16
@QE = external dso_local local_unnamed_addr global [100000 x %struct.qedge], align 16
@ancestor = external dso_local local_unnamed_addr global [100000 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z8get_rooti(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5mergeii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3DFSii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i32 @_Z8get_rooti(i32 noundef %0)
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [100000 x i32], ptr @ancestor, i64 0, i64 %4
  store i32 %0, ptr %5, align 4, !tbaa !5
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %6
  %.02024 = load i32, ptr %7, align 8, !tbaa !5
  %.not25 = icmp eq i32 %.02024, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %18, %2
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  store i8 1, ptr %8, align 4, !tbaa !9
  %9 = getelementptr inbounds [100000 x %struct.qvertex], ptr @QV, i64 0, i64 %6
  %.027 = load i32, ptr %9, align 4, !tbaa !5
  %.not2228 = icmp eq i32 %.027, 0
  br i1 %.not2228, label %._crit_edge32, label %.lr.ph31

.lr.ph:                                           ; preds = %2, %18
  %.02026 = phi i32 [ %.020, %18 ], [ %.02024, %2 ]
  %10 = sext i32 %.02026 to i64
  %11 = getelementptr inbounds [100000 x %struct.edge], ptr @E, i64 0, i64 %10
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %.not23 = icmp eq i32 %12, %1
  br i1 %.not23, label %18, label %13

13:                                               ; preds = %.lr.ph
  tail call void @_Z3DFSii(i32 noundef %12, i32 noundef %0)
  %14 = load i32, ptr %11, align 8, !tbaa !12
  tail call void @_Z5mergeii(i32 noundef %0, i32 noundef %14)
  %15 = tail call noundef i32 @_Z8get_rooti(i32 noundef %0)
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100000 x i32], ptr @ancestor, i64 0, i64 %16
  store i32 %0, ptr %17, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %.lr.ph, %13
  %19 = getelementptr inbounds i8, ptr %11, i64 4
  %.020 = load i32, ptr %19, align 4, !tbaa !5
  %.not = icmp eq i32 %.020, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge32:                                    ; preds = %33, %._crit_edge
  ret void

.lr.ph31:                                         ; preds = %._crit_edge, %33
  %.029 = phi i32 [ %.0, %33 ], [ %.027, %._crit_edge ]
  %20 = sext i32 %.029 to i64
  %21 = getelementptr inbounds [100000 x %struct.qedge], ptr @QE, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100000 x %struct.vertex], ptr @V, i64 0, i64 %23, i32 1
  %25 = load i8, ptr %24, align 4, !tbaa !9, !range !18, !noundef !19
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %27, label %33

27:                                               ; preds = %.lr.ph31
  %28 = tail call noundef i32 @_Z8get_rooti(i32 noundef %22)
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100000 x i32], ptr @ancestor, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %21, i64 8
  store i32 %31, ptr %32, align 4, !tbaa !20
  br label %33

33:                                               ; preds = %.lr.ph31, %27
  %34 = getelementptr inbounds i8, ptr %21, i64 4
  %.0 = load i32, ptr %34, align 4, !tbaa !5
  %.not22 = icmp eq i32 %.0, 0
  br i1 %.not22, label %._crit_edge32, label %.lr.ph31, !llvm.loop !21
}

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, !11, i64 4}
!10 = !{!"_ZTS6vertex", !6, i64 0, !11, i64 4}
!11 = !{!"bool", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTS5qedge", !6, i64 0, !6, i64 4, !6, i64 8}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!17, !6, i64 8}
!21 = distinct !{!21, !15}


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