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

; 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.ddump_data = type { i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.dex_header = type { [8 x i8], i32, [20 x i8], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; 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
define dso_local noundef zeroext i1 @_Z19find_typeid_for_idxP10ddump_datajPt(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.ddump_data, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ddump_data, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds %struct.dex_header, ptr %16, i32 0, i32 12
  %18 = load i32, ptr %17, align 1, !tbaa !15
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %13, i64 %19
  store ptr %20, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %41, %3
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ddump_data, ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = getelementptr inbounds %struct.dex_header, ptr %25, i32 0, i32 11
  %27 = load i32, ptr %26, align 1, !tbaa !17
  %28 = icmp ult i32 %22, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %21
  store i32 2, ptr %10, align 4
  br label %44

30:                                               ; preds = %21
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds i32, ptr %31, i32 1
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load i32, ptr %31, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = trunc i32 %37 to i16
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 %38, ptr %39, align 2, !tbaa !18
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %44

40:                                               ; preds = %30
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %9, align 4, !tbaa !9
  br label %21, !llvm.loop !20

44:                                               ; preds = %36, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %45 = load i32, ptr %10, align 4
  switch i32 %45, label %47 [
    i32 2, label %46
  ]

46:                                               ; preds = %44
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %47

47:                                               ; preds = %46, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %48 = load i1, ptr %4, align 1
  ret i1 %48
}

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 = !{!"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, !6, i64 16}
!12 = !{!"_ZTS10ddump_data", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!16, !10, i64 68}
!16 = !{!"_ZTS10dex_header", !7, i64 0, !10, i64 8, !7, i64 12, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108}
!17 = !{!16, !10, i64 64}
!18 = !{!19, !19, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z19find_typeid_for_idxP10ddump_datajPt(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 64
  %7 = load i32, ptr %6, align 1, !tbaa !11
  %.not16.not = icmp eq i32 %7, 0
  br i1 %.not16.not, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %5, i64 68
  %11 = load i32, ptr %10, align 1, !tbaa !15
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %9, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !16
  %15 = icmp eq i32 %14, %1
  br i1 %15, label %20, label %.lr.ph28

.lr.ph:                                           ; preds = %.lr.ph28
  %16 = getelementptr inbounds i8, ptr %.0111727, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !16
  %18 = icmp eq i32 %17, %1
  br i1 %18, label %.lr.ph._crit_edge, label %.lr.ph28, !llvm.loop !17

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.not.le = icmp ult i32 %21, %7
  %19 = trunc i32 %21 to i16
  br label %20

20:                                               ; preds = %.lr.ph._crit_edge, %.lr.ph.preheader
  %.not19.lcssa = phi i1 [ %.not.le, %.lr.ph._crit_edge ], [ true, %.lr.ph.preheader ]
  %.01018.lcssa = phi i16 [ %19, %.lr.ph._crit_edge ], [ 0, %.lr.ph.preheader ]
  store i16 %.01018.lcssa, ptr %2, align 2, !tbaa !19
  br label %.critedge

.lr.ph28:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0111727 = phi ptr [ %16, %.lr.ph ], [ %13, %.lr.ph.preheader ]
  %.0101826 = phi i32 [ %21, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %21 = add nuw i32 %.0101826, 1
  %exitcond.not = icmp eq i32 %21, %7
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !17

.critedge:                                        ; preds = %.lr.ph28, %3, %20
  %.not14 = phi i1 [ %.not19.lcssa, %20 ], [ false, %3 ], [ false, %.lr.ph28 ]
  ret i1 %.not14
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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, !10, i64 32}
!6 = !{!"_ZTS10ddump_data", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !13, i64 64}
!12 = !{!"_ZTS10dex_header", !8, i64 0, !13, i64 8, !8, i64 12, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !13, i64 72, !13, i64 76, !13, i64 80, !13, i64 84, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108}
!13 = !{!"int", !8, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!12, !13, i64 68}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !20, i64 0}
!20 = !{!"short", !8, i64 0}


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