; LLVM IR from facebook/redex :: libredex/TypeUtil.ll (ZN4type15get_array_levelEPK7DexType)

; 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 nounwind uwtable
declare dso_local noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4type15get_array_levelEPK7DexType(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16) %5)
  %7 = call noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %20, %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i32 1
  store ptr %10, ptr %3, align 8, !tbaa !5
  %11 = load i8, ptr %9, align 1, !tbaa !11
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %12, 91
  br i1 %13, label %14, label %18

14:                                               ; preds = %8
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = add i32 %15, 1
  store i32 %16, ptr %4, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br label %18

18:                                               ; preds = %14, %8
  %19 = phi i1 [ false, %8 ], [ %17, %14 ]
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  br label %8, !llvm.loop !12

21:                                               ; preds = %18
  %22 = load i32, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i32 %22
}

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 = { 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 #3 = { 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 = !{!7, !7, i64 0}
!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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN4type15get_array_levelEPK7DexType(ptr noundef nonnull %0) local_unnamed_addr #0 {
  %2 = tail call noundef ptr @_ZNK7DexType8get_nameEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %3 = tail call noundef ptr @_ZNK9DexString5c_strEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  br label %4

4:                                                ; preds = %19, %1
  %.03 = phi ptr [ %3, %1 ], [ %20, %19 ]
  %.0 = phi i32 [ 0, %1 ], [ %21, %19 ]
  %5 = load i8, ptr %.03, align 1, !tbaa !5
  %6 = icmp eq i8 %5, 91
  br i1 %6, label %7, label %.critedge

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %.03, i64 1
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = icmp eq i8 %9, 91
  br i1 %10, label %11, label %.critedge.split.loop.exit10

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %.03, i64 2
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = icmp eq i8 %13, 91
  br i1 %14, label %15, label %.critedge.split.loop.exit8

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %.03, i64 3
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = icmp eq i8 %17, 91
  br i1 %18, label %19, label %.critedge.split.loop.exit6

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %.03, i64 4
  %21 = add i32 %.0, 4
  %.not.3 = icmp eq i32 %21, 0
  br i1 %.not.3, label %.critedge, label %4, !llvm.loop !8

.critedge.split.loop.exit6:                       ; preds = %15
  %22 = or disjoint i32 %.0, 3
  br label %.critedge

.critedge.split.loop.exit8:                       ; preds = %11
  %23 = or disjoint i32 %.0, 2
  br label %.critedge

.critedge.split.loop.exit10:                      ; preds = %7
  %24 = or disjoint i32 %.0, 1
  br label %.critedge

.critedge:                                        ; preds = %4, %19, %.critedge.split.loop.exit10, %.critedge.split.loop.exit8, %.critedge.split.loop.exit6
  %.1 = phi i32 [ %22, %.critedge.split.loop.exit6 ], [ %23, %.critedge.split.loop.exit8 ], [ %24, %.critedge.split.loop.exit10 ], [ 0, %19 ], [ %.0, %4 ]
  ret i32 %.1
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass