; LLVM IR from facebook/redex :: libresource/ResourceTypes.ll (ZNK7android12ResXMLParser12indexOfClassEv)

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

%"class.android::ResXMLParser" = type <{ ptr, i32, [4 x i8], ptr, ptr, i32, [4 x i8] }>
%"struct.android::ResXMLTree_attrExt" = type { %"struct.android::ResStringPool_ref", %"struct.android::ResStringPool_ref", i16, i16, i16, i16, i16, i16 }
%"struct.android::ResStringPool_ref" = type { 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 i64 @_ZNK7android12ResXMLParser12indexOfClassEv(ptr noundef nonnull align 8 dereferenceable(36) %0) #1 align 2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.android::ResXMLParser", ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 258
  br i1 %9, label %10, label %25

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %11 = getelementptr inbounds %"class.android::ResXMLParser", ptr %6, i32 0, i32 4
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds %"struct.android::ResXMLTree_attrExt", ptr %12, i32 0, i32 6
  %14 = load i16, ptr %13, align 4, !tbaa !14
  %15 = zext i16 %14 to i64
  store i64 %15, ptr %4, align 8, !tbaa !18
  %16 = load i64, ptr %4, align 8, !tbaa !18
  %17 = icmp sgt i64 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %10
  %19 = load i64, ptr %4, align 8, !tbaa !18
  %20 = sub nsw i64 %19, 1
  store i64 %20, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %22

21:                                               ; preds = %10
  store i32 0, ptr %5, align 4
  br label %22

22:                                               ; preds = %21, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %23 = load i32, ptr %5, align 4
  switch i32 %23, label %28 [
    i32 0, label %24
    i32 1, label %26
  ]

24:                                               ; preds = %22
  br label %25

25:                                               ; preds = %24, %1
  store i64 -2, ptr %2, align 8
  br label %26

26:                                               ; preds = %25, %22
  %27 = load i64, ptr %2, align 8
  ret i64 %27

28:                                               ; preds = %22
  unreachable
}

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, !11, i64 8}
!10 = !{!"_ZTSN7android12ResXMLParserE", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!11 = !{!"_ZTSN7android12ResXMLParser12event_code_tE", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 24}
!14 = !{!15, !17, i64 16}
!15 = !{!"_ZTSN7android18ResXMLTree_attrExtE", !16, i64 0, !16, i64 4, !17, i64 8, !17, i64 10, !17, i64 12, !17, i64 14, !17, i64 16, !17, i64 18}
!16 = !{!"_ZTSN7android17ResStringPool_refE", !12, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !7, i64 0}


; 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 willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZNK7android12ResXMLParser12indexOfClassEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(36) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 258
  br i1 %4, label %5, label %12

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load i16, ptr %8, align 4, !tbaa !13
  %.not.not = icmp eq i16 %9, 0
  %10 = zext i16 %9 to i64
  %11 = add nsw i64 %10, -1
  br i1 %.not.not, label %12, label %13

12:                                               ; preds = %5, %1
  br label %13

13:                                               ; preds = %5, %12
  %.1 = phi i64 [ %11, %5 ], [ -2, %12 ]
  ret i64 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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 8}
!6 = !{!"_ZTSN7android12ResXMLParserE", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN7android12ResXMLParser12event_code_tE", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!14, !16, i64 16}
!14 = !{!"_ZTSN7android18ResXMLTree_attrExtE", !15, i64 0, !15, i64 4, !16, i64 8, !16, i64 10, !16, i64 12, !16, i64 14, !16, i64 16, !16, i64 18}
!15 = !{!"_ZTSN7android17ResStringPool_refE", !11, i64 0}
!16 = !{!"short", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass