; LLVM IR from wuzhouhui/leetcode :: 235_lca (lowestCommonAncestor)

; 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.link_node = type { ptr, ptr, ptr }

@pathp = external hidden global ptr, align 8
@pathq = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @lowestCommonAncestor(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @init()
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  call void @trav(ptr noundef %10, ptr noundef %11, ptr noundef %12)
  %13 = load ptr, ptr @pathp, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %18, label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr @pathq, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %3
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %51

19:                                               ; preds = %15
  %20 = load ptr, ptr @pathp, align 8, !tbaa !5
  store ptr %20, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr @pathq, align 8, !tbaa !5
  store ptr %21, ptr %9, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %43, %19
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %28

25:                                               ; preds = %22
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br label %28

28:                                               ; preds = %25, %22
  %29 = phi i1 [ false, %22 ], [ %27, %25 ]
  br i1 %29, label %30, label %50

30:                                               ; preds = %28
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.link_node, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.link_node, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = icmp ne ptr %33, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %30
  br label %50

39:                                               ; preds = %30
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.link_node, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  store ptr %42, ptr %7, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %39
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.link_node, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  store ptr %46, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.link_node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  store ptr %49, ptr %9, align 8, !tbaa !5
  br label %22, !llvm.loop !12

50:                                               ; preds = %38, %28
  br label %51

51:                                               ; preds = %50, %18
  %52 = load ptr, ptr @pathp, align 8, !tbaa !5
  call void @clean(ptr noundef %52)
  %53 = load ptr, ptr @pathq, align 8, !tbaa !5
  call void @clean(ptr noundef %53)
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %54
}

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

; Function Attrs: nounwind uwtable
declare hidden void @init() #0

; Function Attrs: nounwind uwtable
declare hidden void @trav(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @clean(ptr noundef) #0

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

attributes #0 = { 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"link_node", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@pathp = external hidden local_unnamed_addr global ptr, align 8
@pathq = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @lowestCommonAncestor(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  tail call void @init()
  tail call void @trav(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %4 = load ptr, ptr @pathp, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  %6 = load ptr, ptr @pathq, align 8
  %7 = icmp eq ptr %6, null
  %or.cond = select i1 %5, i1 true, i1 %7
  br i1 %or.cond, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %3
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %6, align 8, !tbaa !9
  %.not20 = icmp eq ptr %8, %9
  br i1 %.not20, label %.lr.ph, label %.loopexit

.preheader:                                       ; preds = %.lr.ph
  %10 = load ptr, ptr %14, align 8, !tbaa !9
  %11 = load ptr, ptr %16, align 8, !tbaa !9
  %.not = icmp eq ptr %10, %11
  br i1 %.not, label %.lr.ph, label %.loopexit, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader.preheader, %.preheader
  %12 = phi ptr [ %10, %.preheader ], [ %8, %.preheader.preheader ]
  %.0121822 = phi ptr [ %14, %.preheader ], [ %4, %.preheader.preheader ]
  %.01921 = phi ptr [ %16, %.preheader ], [ %6, %.preheader.preheader ]
  %13 = getelementptr inbounds i8, ptr %.0121822, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %.01921, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp ne ptr %14, null
  %18 = icmp ne ptr %16, null
  %19 = select i1 %17, i1 %18, i1 false
  br i1 %19, label %.preheader, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.preheader, %.lr.ph, %.preheader.preheader, %3
  %.1 = phi ptr [ null, %3 ], [ undef, %.preheader.preheader ], [ %12, %.lr.ph ], [ %12, %.preheader ]
  tail call void @clean(ptr noundef %4)
  %20 = load ptr, ptr @pathq, align 8, !tbaa !5
  tail call void @clean(ptr noundef %20)
  ret ptr %.1
}

; Function Attrs: nounwind uwtable
declare hidden void @init() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @trav(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @clean(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"link_node", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 8}


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