; LLVM IR from facebook/redex :: libresource/LocaleData.ll (ZN7android13findAncestorsEPjPljPKcPKjm)

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

; 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 @_ZN7android10findParentEjPKc(i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN7android13findAncestorsEPjPljPKcPKjm(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) #1 {
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i64 %5, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %18 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %18, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  store i64 0, ptr %15, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %56, %6
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load i32, ptr %14, align 4, !tbaa !9
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %15, align 8, !tbaa !11
  %26 = getelementptr inbounds i32, ptr %24, i64 %25
  store i32 %23, ptr %26, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %22, %19
  %28 = load i64, ptr %15, align 8, !tbaa !11
  %29 = add i64 %28, 1
  store i64 %29, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  store i64 0, ptr %16, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %47, %27
  %31 = load i64, ptr %16, align 8, !tbaa !11
  %32 = load i64, ptr %13, align 8, !tbaa !11
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 4, ptr %17, align 4
  br label %50

35:                                               ; preds = %30
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = load i64, ptr %16, align 8, !tbaa !11
  %38 = getelementptr inbounds i32, ptr %36, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = load i32, ptr %14, align 4, !tbaa !9
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %35
  %43 = load i64, ptr %16, align 8, !tbaa !11
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %43, ptr %44, align 8, !tbaa !11
  %45 = load i64, ptr %15, align 8, !tbaa !11
  store i64 %45, ptr %7, align 8
  store i32 1, ptr %17, align 4
  br label %50

46:                                               ; preds = %35
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %16, align 8, !tbaa !11
  %49 = add i64 %48, 1
  store i64 %49, ptr %16, align 8, !tbaa !11
  br label %30, !llvm.loop !13

50:                                               ; preds = %42, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  %51 = load i32, ptr %17, align 4
  switch i32 %51, label %62 [
    i32 4, label %52
  ]

52:                                               ; preds = %50
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = call noundef i32 @_ZN7android10findParentEjPKc(i32 noundef %53, ptr noundef %54)
  store i32 %55, ptr %14, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %52
  %57 = load i32, ptr %14, align 4, !tbaa !9
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %19, label %59, !llvm.loop !15

59:                                               ; preds = %56
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 -1, ptr %60, align 8, !tbaa !11
  %61 = load i64, ptr %15, align 8, !tbaa !11
  store i64 %61, ptr %7, align 8
  store i32 1, ptr %17, align 4
  br label %62

62:                                               ; preds = %59, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  %63 = load i64, ptr %7, align 8
  ret i64 %63
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN7android13findAncestorsEPjPljPKcPKjm(ptr noundef writeonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, ptr noundef %3, ptr nocapture noundef readonly %4, i64 noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  %.not2733.not = icmp eq i64 %5, 0
  br i1 %.not2733.not, label %.split, label %.split.us

.split.us:                                        ; preds = %6
  br i1 %.not, label %.lr.ph.us.us, label %.lr.ph.us

.lr.ph.us.us:                                     ; preds = %.split.us, %._crit_edge.us.us
  %.023.us.us = phi i32 [ %14, %._crit_edge.us.us ], [ %2, %.split.us ]
  %.022.us.us = phi i64 [ %7, %._crit_edge.us.us ], [ 0, %.split.us ]
  %7 = add i64 %.022.us.us, 1
  br label %8

8:                                                ; preds = %12, %.lr.ph.us.us
  %.02134.us.us = phi i64 [ 0, %.lr.ph.us.us ], [ %13, %12 ]
  %9 = getelementptr inbounds i32, ptr %4, i64 %.02134.us.us
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, %.023.us.us
  br i1 %11, label %.thread, label %12

12:                                               ; preds = %8
  %13 = add nuw i64 %.02134.us.us, 1
  %exitcond57.not = icmp eq i64 %13, %5
  br i1 %exitcond57.not, label %._crit_edge.us.us, label %8, !llvm.loop !9

._crit_edge.us.us:                                ; preds = %12
  %14 = tail call noundef i32 @_ZN7android10findParentEjPKc(i32 noundef %.023.us.us, ptr noundef %3)
  %.not28.us.us = icmp eq i32 %14, 0
  br i1 %.not28.us.us, label %.thread, label %.lr.ph.us.us, !llvm.loop !11

.lr.ph.us:                                        ; preds = %.split.us, %._crit_edge.us
  %.023.us = phi i32 [ %23, %._crit_edge.us ], [ %2, %.split.us ]
  %.022.us = phi i64 [ %16, %._crit_edge.us ], [ 0, %.split.us ]
  %15 = getelementptr inbounds i32, ptr %0, i64 %.022.us
  store i32 %.023.us, ptr %15, align 4, !tbaa !5
  %16 = add i64 %.022.us, 1
  br label %17

17:                                               ; preds = %.lr.ph.us, %21
  %.02134.us = phi i64 [ 0, %.lr.ph.us ], [ %22, %21 ]
  %18 = getelementptr inbounds i32, ptr %4, i64 %.02134.us
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = icmp eq i32 %19, %.023.us
  br i1 %20, label %.thread, label %21

21:                                               ; preds = %17
  %22 = add nuw i64 %.02134.us, 1
  %exitcond.not = icmp eq i64 %22, %5
  br i1 %exitcond.not, label %._crit_edge.us, label %17, !llvm.loop !9

._crit_edge.us:                                   ; preds = %21
  %23 = tail call noundef i32 @_ZN7android10findParentEjPKc(i32 noundef %.023.us, ptr noundef %3)
  %.not28.us = icmp eq i32 %23, 0
  br i1 %.not28.us, label %.thread, label %.lr.ph.us, !llvm.loop !11

.split:                                           ; preds = %6
  br i1 %.not, label %.split.split.us, label %.split.split

.split.split.us:                                  ; preds = %.split, %.split.split.us
  %.023.us37 = phi i32 [ %25, %.split.split.us ], [ %2, %.split ]
  %.022.us38 = phi i64 [ %24, %.split.split.us ], [ 0, %.split ]
  %24 = add i64 %.022.us38, 1
  %25 = tail call noundef i32 @_ZN7android10findParentEjPKc(i32 noundef %.023.us37, ptr noundef %3)
  %.not28.us39 = icmp eq i32 %25, 0
  br i1 %.not28.us39, label %.thread, label %.split.split.us, !llvm.loop !11

.split.split:                                     ; preds = %.split, %.split.split
  %.023 = phi i32 [ %28, %.split.split ], [ %2, %.split ]
  %.022 = phi i64 [ %27, %.split.split ], [ 0, %.split ]
  %26 = getelementptr inbounds i32, ptr %0, i64 %.022
  store i32 %.023, ptr %26, align 4, !tbaa !5
  %27 = add i64 %.022, 1
  %28 = tail call noundef i32 @_ZN7android10findParentEjPKc(i32 noundef %.023, ptr noundef %3)
  %.not28 = icmp eq i32 %28, 0
  br i1 %.not28, label %.thread, label %.split.split, !llvm.loop !11

.thread:                                          ; preds = %._crit_edge.us, %17, %._crit_edge.us.us, %8, %.split.split, %.split.split.us
  %29 = phi i64 [ %24, %.split.split.us ], [ %27, %.split.split ], [ %7, %8 ], [ %7, %._crit_edge.us.us ], [ %16, %17 ], [ %16, %._crit_edge.us ]
  %storemerge = phi i64 [ -1, %.split.split.us ], [ -1, %.split.split ], [ %.02134.us.us, %8 ], [ -1, %._crit_edge.us.us ], [ %.02134.us, %17 ], [ -1, %._crit_edge.us ]
  store i64 %storemerge, ptr %1, align 8, !tbaa !12
  ret i64 %29
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass