; LLVM IR from ADJA/algos :: Graphs/LCAHLD.ll (Z3lcaii)

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

@p = external dso_local global [105000 x i32], align 16
@chain = external dso_local global [105000 x i32], align 16
@chainRoot = external dso_local global [105000 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z8isParentii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3lcaii(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
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %31, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [105000 x i32], ptr @chain, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %13, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = call noundef zeroext i1 @_Z8isParentii(i32 noundef %17, i32 noundef %18)
  br i1 %19, label %20, label %21

20:                                               ; preds = %9
  store i32 3, ptr %7, align 4
  br label %29

21:                                               ; preds = %9
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [105000 x i32], ptr @p, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %4, align 4, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %29

29:                                               ; preds = %21, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %30 = load i32, ptr %7, align 4
  switch i32 %30, label %66 [
    i32 0, label %31
    i32 3, label %32
  ]

31:                                               ; preds = %29
  br label %9, !llvm.loop !9

32:                                               ; preds = %29
  br label %33

33:                                               ; preds = %55, %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [105000 x i32], ptr @chain, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %8, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = call noundef zeroext i1 @_Z8isParentii(i32 noundef %41, i32 noundef %42)
  br i1 %43, label %44, label %45

44:                                               ; preds = %33
  store i32 5, ptr %7, align 4
  br label %53

45:                                               ; preds = %33
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [105000 x i32], ptr @p, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %53

53:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %54 = load i32, ptr %7, align 4
  switch i32 %54, label %66 [
    i32 0, label %55
    i32 5, label %56
  ]

55:                                               ; preds = %53
  br label %33, !llvm.loop !11

56:                                               ; preds = %53
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = call noundef zeroext i1 @_Z8isParentii(i32 noundef %57, i32 noundef %58)
  br i1 %59, label %60, label %62

60:                                               ; preds = %56
  %61 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %61, ptr %3, align 4
  br label %64

62:                                               ; preds = %56
  %63 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %63, ptr %3, align 4
  br label %64

64:                                               ; preds = %62, %60
  %65 = load i32, ptr %3, align 4
  ret i32 %65

66:                                               ; preds = %53, %29
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"

@p = external dso_local local_unnamed_addr global [105000 x i32], align 16
@chain = external dso_local local_unnamed_addr global [105000 x i32], align 16
@chainRoot = external dso_local local_unnamed_addr global [105000 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z8isParentii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3lcaii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [105000 x i32], ptr @chain, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call noundef zeroext i1 @_Z8isParentii(i32 noundef %8, i32 noundef %1)
  br i1 %9, label %.preheader, label %.lr.ph29

.lr.ph29:                                         ; preds = %2, %.lr.ph29
  %10 = phi ptr [ %19, %.lr.ph29 ], [ %7, %2 ]
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [105000 x i32], ptr @p, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [105000 x i32], ptr @chain, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = tail call noundef zeroext i1 @_Z8isParentii(i32 noundef %20, i32 noundef %1)
  br i1 %21, label %.preheader, label %.lr.ph29

.preheader:                                       ; preds = %.lr.ph29, %2
  %.016.lcssa = phi i32 [ %0, %2 ], [ %14, %.lr.ph29 ]
  %22 = sext i32 %1 to i64
  %23 = getelementptr inbounds [105000 x i32], ptr @chain, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = tail call noundef zeroext i1 @_Z8isParentii(i32 noundef %27, i32 noundef %.016.lcssa)
  br i1 %28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %29 = phi ptr [ %38, %.lr.ph ], [ %26, %.preheader ]
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [105000 x i32], ptr @p, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [105000 x i32], ptr @chain, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [105000 x i32], ptr @chainRoot, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = tail call noundef zeroext i1 @_Z8isParentii(i32 noundef %39, i32 noundef %.016.lcssa)
  br i1 %40, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.018.lcssa = phi i32 [ %1, %.preheader ], [ %33, %.lr.ph ]
  %41 = tail call noundef zeroext i1 @_Z8isParentii(i32 noundef %.016.lcssa, i32 noundef %.018.lcssa)
  %.117..119 = select i1 %41, i32 %.016.lcssa, i32 %.018.lcssa
  ret i32 %.117..119
}

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

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


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