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

; 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] }>
%"class.android::ResXMLTree" = type <{ %"class.android::ResXMLParser.base", [4 x i8], %"class.std::shared_ptr", i32, [4 x i8], ptr, ptr, i64, ptr, %"class.android::ResStringPool", ptr, i64, ptr, ptr, i32, [4 x i8] }>
%"class.android::ResXMLParser.base" = type <{ ptr, i32, [4 x i8], ptr, ptr, i32 }>
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.android::ResStringPool" = type <{ ptr, i32, [4 x i8], ptr, ptr, i64, %"class.std::mutex", ptr, ptr, ptr, ptr, i32, [4 x i8], ptr, i32, [4 x i8] }>
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

; 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 i32 @_ZNK7android12ResXMLParser18getAttributeNameIDEm(ptr noundef nonnull align 8 dereferenceable(36), i64 noundef) #1 align 2

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

14:                                               ; preds = %2
  %15 = load i32, ptr %6, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %"class.android::ResXMLParser", ptr %9, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds %"class.android::ResXMLTree", ptr %18, i32 0, i32 11
  %20 = load i64, ptr %19, align 8, !tbaa !16
  %21 = icmp ult i64 %16, %20
  br i1 %21, label %22, label %46

22:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %23 = getelementptr inbounds %"class.android::ResXMLParser", ptr %9, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds %"class.android::ResXMLTree", ptr %24, i32 0, i32 10
  %26 = load ptr, ptr %25, align 8, !tbaa !24
  %27 = load i32, ptr %6, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !11
  store i32 %30, ptr %7, align 4, !tbaa !11
  %31 = getelementptr inbounds %"class.android::ResXMLParser", ptr %9, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = getelementptr inbounds %"class.android::ResXMLTree", ptr %32, i32 0, i32 2
  %34 = call noundef zeroext i1 @_ZStneIKN7android15DynamicRefTableEEbRKSt10shared_ptrIT_EDn(ptr noundef nonnull align 8 dereferenceable(16) %33, ptr null) #4
  br i1 %34, label %35, label %44

35:                                               ; preds = %22
  %36 = getelementptr inbounds %"class.android::ResXMLParser", ptr %9, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = getelementptr inbounds %"class.android::ResXMLTree", ptr %37, i32 0, i32 2
  %39 = call noundef ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %38) #4
  %40 = load ptr, ptr %39, align 8, !tbaa !25
  %41 = getelementptr inbounds ptr, ptr %40, i64 2
  %42 = load ptr, ptr %41, align 8
  %43 = call noundef i32 %42(ptr noundef nonnull align 8 dereferenceable(313) %39, ptr noundef %7)
  br label %44

44:                                               ; preds = %35, %22
  %45 = load i32, ptr %7, align 4, !tbaa !11
  store i32 %45, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %47

46:                                               ; preds = %14, %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %47

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneIKN7android15DynamicRefTableEEbRKSt10shared_ptrIT_EDn(ptr noundef nonnull align 8 dereferenceable(16), ptr) #3

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

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 = { inlinehint 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 #4 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN7android12ResXMLParserE", !6, i64 0, !15, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!15 = !{!"_ZTSN7android12ResXMLParser12event_code_tE", !7, i64 0}
!16 = !{!17, !10, i64 240}
!17 = !{!"_ZTSN7android10ResXMLTreeE", !14, i64 0, !18, i64 40, !12, i64 56, !6, i64 64, !6, i64 72, !10, i64 80, !6, i64 88, !21, i64 96, !6, i64 232, !10, i64 240, !6, i64 248, !6, i64 256, !15, i64 264}
!18 = !{!"_ZTSSt10shared_ptrIKN7android15DynamicRefTableEE", !19, i64 0}
!19 = !{!"_ZTSSt12__shared_ptrIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !20, i64 8}
!20 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0}
!21 = !{!"_ZTSN7android13ResStringPoolE", !12, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !22, i64 40, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !6, i64 120, !12, i64 128}
!22 = !{!"_ZTSSt5mutex", !23, i64 0}
!23 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!24 = !{!17, !6, i64 232}
!25 = !{!26, !26, i64 0}
!26 = !{!"vtable pointer", !8, 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 i32 @_ZNK7android12ResXMLParser18getAttributeNameIDEm(ptr noundef nonnull align 8 dereferenceable(36), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7android12ResXMLParser21getAttributeNameResIDEm(ptr noundef nonnull align 8 dereferenceable(36) %0, i64 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i32, align 4
  %4 = tail call noundef i32 @_ZNK7android12ResXMLParser18getAttributeNameIDEm(ptr noundef nonnull align 8 dereferenceable(36) %0, i64 noundef %1)
  %5 = icmp sgt i32 %4, -1
  br i1 %5, label %6, label %29

6:                                                ; preds = %2
  %7 = zext nneg i32 %4 to i64
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 240
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %11 = icmp ugt i64 %10, %7
  br i1 %11, label %12, label %29

12:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %13 = getelementptr inbounds i8, ptr %8, i64 232
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  %15 = getelementptr inbounds i32, ptr %14, i64 %7
  %16 = load i32, ptr %15, align 4, !tbaa !22
  store i32 %16, ptr %3, align 4, !tbaa !22
  %17 = getelementptr inbounds i8, ptr %8, i64 40
  %18 = tail call noundef zeroext i1 @_ZStneIKN7android15DynamicRefTableEEbRKSt10shared_ptrIT_EDn(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr null) #4
  br i1 %18, label %19, label %27

19:                                               ; preds = %12
  %20 = load ptr, ptr %0, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 40
  %22 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %21) #4
  %23 = load ptr, ptr %22, align 8, !tbaa !23
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8
  %26 = call noundef i32 %25(ptr noundef nonnull align 8 dereferenceable(313) %22, ptr noundef nonnull %3)
  %.pre = load i32, ptr %3, align 4, !tbaa !22
  br label %27

27:                                               ; preds = %19, %12
  %28 = phi i32 [ %.pre, %19 ], [ %16, %12 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  br label %29

29:                                               ; preds = %2, %6, %27
  %.0 = phi i32 [ %28, %27 ], [ 0, %6 ], [ 0, %2 ]
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneIKN7android15DynamicRefTableEEbRKSt10shared_ptrIT_EDn(ptr noundef nonnull align 8 dereferenceable(16), ptr) local_unnamed_addr #3

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

attributes #0 = { mustprogress 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 = { inlinehint 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 #4 = { 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, !7, i64 0}
!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 = !{!13, !17, i64 240}
!13 = !{!"_ZTSN7android10ResXMLTreeE", !6, i64 0, !14, i64 40, !11, i64 56, !7, i64 64, !7, i64 72, !17, i64 80, !7, i64 88, !18, i64 96, !7, i64 232, !17, i64 240, !7, i64 248, !7, i64 256, !10, i64 264}
!14 = !{!"_ZTSSt10shared_ptrIKN7android15DynamicRefTableEE", !15, i64 0}
!15 = !{!"_ZTSSt12__shared_ptrIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2EE", !7, i64 0, !16, i64 8}
!16 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !7, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!"_ZTSN7android13ResStringPoolE", !11, i64 8, !7, i64 16, !7, i64 24, !17, i64 32, !19, i64 40, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !11, i64 112, !7, i64 120, !11, i64 128}
!19 = !{!"_ZTSSt5mutex", !20, i64 0}
!20 = !{!"_ZTSSt12__mutex_base", !8, i64 0}
!21 = !{!13, !7, i64 232}
!22 = !{!11, !11, i64 0}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass