; LLVM IR from facebook/redex :: tools/common/DexCommon.ll (Z15get_type_extentP10ddump_datatRjS1_)

; 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.dex_map_item = type { i16, i16, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17get_dex_map_itemsP10ddump_dataPjPP12dex_map_item(ptr noundef, ptr noundef, ptr noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z15get_type_extentP10ddump_datatRjS1_(ptr noundef %0, i16 noundef zeroext %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_Z17get_dex_map_itemsP10ddump_dataPjPP12dex_map_item(ptr noundef %14, ptr noundef %9, ptr noundef %10)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %40, %4
  %16 = load i32, ptr %11, align 4, !tbaa !11
  %17 = load i32, ptr %9, align 4, !tbaa !11
  %18 = icmp ult i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %43

20:                                               ; preds = %15
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load i32, ptr %11, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds %struct.dex_map_item, ptr %21, i64 %23
  %25 = getelementptr inbounds %struct.dex_map_item, ptr %24, i32 0, i32 0
  %26 = load i16, ptr %25, align 1, !tbaa !13
  %27 = zext i16 %26 to i32
  %28 = load i16, ptr %6, align 2, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %39

31:                                               ; preds = %20
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i32, ptr %11, align 4, !tbaa !11
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds %struct.dex_map_item, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.dex_map_item, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 1, !tbaa !15
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %37, ptr %38, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %31, %20
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %11, align 4, !tbaa !11
  %42 = add i32 %41, 1
  store i32 %42, ptr %11, align 4, !tbaa !11
  br label %15, !llvm.loop !16

43:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %44

44:                                               ; preds = %83, %43
  %45 = load i32, ptr %12, align 4, !tbaa !11
  %46 = load i32, ptr %9, align 4, !tbaa !11
  %47 = icmp ult i32 %45, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %86

49:                                               ; preds = %44
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = load i32, ptr %12, align 4, !tbaa !11
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds %struct.dex_map_item, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.dex_map_item, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 1, !tbaa !15
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !11
  %58 = icmp ugt i32 %55, %57
  br i1 %58, label %59, label %82

59:                                               ; preds = %49
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %73, label %63

63:                                               ; preds = %59
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i32, ptr %64, align 4, !tbaa !11
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i32, ptr %12, align 4, !tbaa !11
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds %struct.dex_map_item, ptr %66, i64 %68
  %70 = getelementptr inbounds %struct.dex_map_item, ptr %69, i32 0, i32 3
  %71 = load i32, ptr %70, align 1, !tbaa !15
  %72 = icmp ugt i32 %65, %71
  br i1 %72, label %73, label %81

73:                                               ; preds = %63, %59
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = load i32, ptr %12, align 4, !tbaa !11
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds %struct.dex_map_item, ptr %74, i64 %76
  %78 = getelementptr inbounds %struct.dex_map_item, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 1, !tbaa !15
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !11
  br label %81

81:                                               ; preds = %73, %63
  br label %82

82:                                               ; preds = %81, %49
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %12, align 4, !tbaa !11
  %85 = add i32 %84, 1
  store i32 %85, ptr %12, align 4, !tbaa !11
  br label %44, !llvm.loop !18

86:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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" }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS12dex_map_item", !10, i64 0, !10, i64 2, !12, i64 4, !12, i64 8}
!15 = !{!14, !12, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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.dex_map_item = type { i16, i16, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z17get_dex_map_itemsP10ddump_dataPjPP12dex_map_item(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z15get_type_extentP10ddump_datatRjS1_(ptr noundef %0, i16 noundef zeroext %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2, ptr nocapture noundef nonnull align 4 dereferenceable(4) %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @_Z17get_dex_map_itemsP10ddump_dataPjPP12dex_map_item(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %8 = load ptr, ptr %6, align 8, !tbaa !9
  %wide.trip.count = zext i32 %7 to i64
  %9 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %wide.trip.count, 1
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %.preheader.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %19

.preheader.unr-lcssa:                             ; preds = %33, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader.unr-lcssa
  %11 = getelementptr inbounds %struct.dex_map_item, ptr %8, i64 %indvars.iv.unr
  %12 = load i16, ptr %11, align 1, !tbaa !11
  %13 = icmp eq i16 %12, %1
  br i1 %13, label %14, label %.preheader

14:                                               ; preds = %.epil.preheader
  %15 = getelementptr inbounds i8, ptr %11, i64 8
  %16 = load i32, ptr %15, align 1, !tbaa !14
  store i32 %16, ptr %2, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.epil.preheader, %14, %.preheader.unr-lcssa
  br i1 %.not, label %._crit_edge, label %.lr.ph21

.lr.ph21:                                         ; preds = %.preheader
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %wide.trip.count27 = zext i32 %7 to i64
  %xtraiter30 = and i64 %wide.trip.count27, 1
  %18 = icmp eq i64 %9, 0
  br i1 %18, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph21.new

.lr.ph21.new:                                     ; preds = %.lr.ph21
  %unroll_iter32 = and i64 %wide.trip.count27, 4294967294
  br label %42

19:                                               ; preds = %33, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %33 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %33 ]
  %20 = getelementptr inbounds %struct.dex_map_item, ptr %8, i64 %indvars.iv
  %21 = load i16, ptr %20, align 1, !tbaa !11
  %22 = icmp eq i16 %21, %1
  br i1 %22, label %23, label %26

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %20, i64 8
  %25 = load i32, ptr %24, align 1, !tbaa !14
  store i32 %25, ptr %2, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %19, %23
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %27 = getelementptr inbounds %struct.dex_map_item, ptr %8, i64 %indvars.iv.next
  %28 = load i16, ptr %27, align 1, !tbaa !11
  %29 = icmp eq i16 %28, %1
  br i1 %29, label %30, label %33

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %27, i64 8
  %32 = load i32, ptr %31, align 1, !tbaa !14
  store i32 %32, ptr %2, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %30, %26
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.unr-lcssa, label %19, !llvm.loop !15

._crit_edge.loopexit.unr-lcssa:                   ; preds = %60, %.lr.ph21
  %indvars.iv24.unr = phi i64 [ 0, %.lr.ph21 ], [ %indvars.iv.next25.1, %60 ]
  %lcmp.mod31.not = icmp eq i64 %xtraiter30, 0
  br i1 %lcmp.mod31.not, label %._crit_edge, label %.epil.preheader29

.epil.preheader29:                                ; preds = %._crit_edge.loopexit.unr-lcssa
  %34 = getelementptr inbounds %struct.dex_map_item, ptr %17, i64 %indvars.iv24.unr, i32 3
  %35 = load i32, ptr %34, align 1, !tbaa !14
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp ugt i32 %35, %36
  br i1 %37, label %38, label %._crit_edge

38:                                               ; preds = %.epil.preheader29
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = add i32 %39, -1
  %or.cond.not.epil = icmp ult i32 %40, %35
  br i1 %or.cond.not.epil, label %._crit_edge, label %41

41:                                               ; preds = %38
  store i32 %35, ptr %3, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %41, %38, %.epil.preheader29, %4, %.preheader
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  ret void

42:                                               ; preds = %60, %.lr.ph21.new
  %indvars.iv24 = phi i64 [ 0, %.lr.ph21.new ], [ %indvars.iv.next25.1, %60 ]
  %niter33 = phi i64 [ 0, %.lr.ph21.new ], [ %niter33.next.1, %60 ]
  %43 = getelementptr inbounds %struct.dex_map_item, ptr %17, i64 %indvars.iv24, i32 3
  %44 = load i32, ptr %43, align 1, !tbaa !14
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = icmp ugt i32 %44, %45
  br i1 %46, label %47, label %51

47:                                               ; preds = %42
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = add i32 %48, -1
  %or.cond.not = icmp ult i32 %49, %44
  br i1 %or.cond.not, label %51, label %50

50:                                               ; preds = %47
  store i32 %44, ptr %3, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %47, %42, %50
  %indvars.iv.next25 = or disjoint i64 %indvars.iv24, 1
  %52 = getelementptr inbounds %struct.dex_map_item, ptr %17, i64 %indvars.iv.next25, i32 3
  %53 = load i32, ptr %52, align 1, !tbaa !14
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = icmp ugt i32 %53, %54
  br i1 %55, label %56, label %60

56:                                               ; preds = %51
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = add i32 %57, -1
  %or.cond.not.1 = icmp ult i32 %58, %53
  br i1 %or.cond.not.1, label %60, label %59

59:                                               ; preds = %56
  store i32 %53, ptr %3, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %59, %56, %51
  %indvars.iv.next25.1 = add nuw nsw i64 %indvars.iv24, 2
  %niter33.next.1 = add i64 %niter33, 2
  %niter33.ncmp.1 = icmp eq i64 %niter33.next.1, %unroll_iter32
  br i1 %niter33.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %42, !llvm.loop !17
}

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" }
attributes #1 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS12dex_map_item", !13, i64 0, !13, i64 2, !6, i64 4, !6, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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