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

; 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 }
%"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 }
%"struct.android::ResXMLTree_attribute" = type { %"struct.android::ResStringPool_ref", %"struct.android::ResStringPool_ref", %"struct.android::ResStringPool_ref", %"struct.android::Res_value" }
%"struct.android::Res_value" = type { i16, i8, i8, 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
declare dso_local noundef ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7android12ResXMLParser16getAttributeDataEm(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 ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %"class.android::ResXMLParser", ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, 258
  br i1 %13, label %14, label %80

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

23:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.android::ResXMLTree_attrExt", ptr %25, i32 0, i32 2
  %27 = load i16, ptr %26, align 4, !tbaa !20
  %28 = zext i16 %27 to i32
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %24, i64 %29
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.android::ResXMLTree_attrExt", ptr %31, i32 0, i32 3
  %33 = load i16, ptr %32, align 2, !tbaa !21
  %34 = zext i16 %33 to i64
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = mul i64 %34, %35
  %37 = getelementptr inbounds i8, ptr %30, i64 %36
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.android::ResXMLParser", ptr %10, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !22
  %40 = getelementptr inbounds %"class.android::ResXMLTree", ptr %39, i32 0, i32 2
  %41 = call noundef zeroext i1 @_ZSteqIKN7android15DynamicRefTableEEbRKSt10shared_ptrIT_EDn(ptr noundef nonnull align 8 dereferenceable(16) %40, ptr null) #4
  br i1 %41, label %50, label %42

42:                                               ; preds = %23
  %43 = getelementptr inbounds %"class.android::ResXMLParser", ptr %10, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  %45 = getelementptr inbounds %"class.android::ResXMLTree", ptr %44, i32 0, i32 2
  %46 = call noundef ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %45) #4
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.android::ResXMLTree_attribute", ptr %47, i32 0, i32 3
  %49 = call noundef zeroext i1 @_ZNK7android15DynamicRefTable14requiresLookupEPKNS_9Res_valueE(ptr noundef nonnull align 8 dereferenceable(313) %46, ptr noundef %48)
  br i1 %49, label %55, label %50

50:                                               ; preds = %42, %23
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.android::ResXMLTree_attribute", ptr %51, i32 0, i32 3
  %53 = getelementptr inbounds %"struct.android::Res_value", ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !23
  store i32 %54, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %73

55:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.android::ResXMLTree_attribute", ptr %56, i32 0, i32 3
  %58 = getelementptr inbounds %"struct.android::Res_value", ptr %57, i32 0, i32 3
  %59 = load i32, ptr %58, align 4, !tbaa !23
  store i32 %59, ptr %9, align 4, !tbaa !26
  %60 = getelementptr inbounds %"class.android::ResXMLParser", ptr %10, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !22
  %62 = getelementptr inbounds %"class.android::ResXMLTree", ptr %61, i32 0, i32 2
  %63 = call noundef ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %62) #4
  %64 = load ptr, ptr %63, align 8, !tbaa !27
  %65 = getelementptr inbounds ptr, ptr %64, i64 2
  %66 = load ptr, ptr %65, align 8
  %67 = call noundef i32 %66(ptr noundef nonnull align 8 dereferenceable(313) %63, ptr noundef %9)
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %55
  %70 = load i32, ptr %9, align 4, !tbaa !26
  store i32 %70, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %72

71:                                               ; preds = %55
  store i32 0, ptr %8, align 4
  br label %72

72:                                               ; preds = %71, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %73

73:                                               ; preds = %72, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %74 = load i32, ptr %8, align 4
  switch i32 %74, label %77 [
    i32 0, label %75
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75, %14
  store i32 0, ptr %8, align 4
  br label %77

77:                                               ; preds = %76, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %78 = load i32, ptr %8, align 4
  switch i32 %78, label %83 [
    i32 0, label %79
    i32 1, label %81
  ]

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79, %2
  store i32 0, ptr %3, align 4
  br label %81

81:                                               ; preds = %80, %77
  %82 = load i32, ptr %3, align 4
  ret i32 %82

83:                                               ; preds = %77
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7android15DynamicRefTable14requiresLookupEPKNS_9Res_valueE(ptr noundef nonnull align 8 dereferenceable(313), ptr noundef) #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, !13, i64 8}
!12 = !{!"_ZTSN7android12ResXMLParserE", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !14, i64 32}
!13 = !{!"_ZTSN7android12ResXMLParser12event_code_tE", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 24}
!16 = !{!17, !19, i64 12}
!17 = !{!"_ZTSN7android18ResXMLTree_attrExtE", !18, i64 0, !18, i64 4, !19, i64 8, !19, i64 10, !19, i64 12, !19, i64 14, !19, i64 16, !19, i64 18}
!18 = !{!"_ZTSN7android17ResStringPool_refE", !14, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!17, !19, i64 8}
!21 = !{!17, !19, i64 10}
!22 = !{!12, !6, i64 0}
!23 = !{!24, !14, i64 16}
!24 = !{!"_ZTSN7android20ResXMLTree_attributeE", !18, i64 0, !18, i64 4, !18, i64 8, !25, i64 12}
!25 = !{!"_ZTSN7android9Res_valueE", !19, i64 0, !7, i64 2, !7, i64 3, !14, i64 4}
!26 = !{!14, !14, i64 0}
!27 = !{!28, !28, i64 0}
!28 = !{!"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 ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK7android12ResXMLParser16getAttributeDataEm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(36) %0, i64 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i32, align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 258
  br i1 %6, label %7, label %46

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %9, i64 12
  %11 = load i16, ptr %10, align 4, !tbaa !13
  %12 = zext i16 %11 to i64
  %13 = icmp ugt i64 %12, %1
  br i1 %13, label %14, label %.thread19

14:                                               ; preds = %7
  %15 = getelementptr inbounds i8, ptr %9, i64 8
  %16 = load i16, ptr %15, align 4, !tbaa !17
  %17 = zext i16 %16 to i64
  %18 = getelementptr inbounds i8, ptr %9, i64 %17
  %19 = getelementptr inbounds i8, ptr %9, i64 10
  %20 = load i16, ptr %19, align 2, !tbaa !18
  %21 = zext i16 %20 to i64
  %22 = mul nuw nsw i64 %21, %1
  %23 = getelementptr inbounds i8, ptr %18, i64 %22
  %24 = load ptr, ptr %0, align 8, !tbaa !19
  %25 = getelementptr inbounds i8, ptr %24, i64 40
  %26 = tail call noundef zeroext i1 @_ZSteqIKN7android15DynamicRefTableEEbRKSt10shared_ptrIT_EDn(ptr noundef nonnull align 8 dereferenceable(16) %25, ptr null) #4
  br i1 %26, label %.thread, label %27

27:                                               ; preds = %14
  %28 = load ptr, ptr %0, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %28, i64 40
  %30 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %29) #4
  %31 = getelementptr inbounds i8, ptr %23, i64 12
  %32 = tail call noundef zeroext i1 @_ZNK7android15DynamicRefTable14requiresLookupEPKNS_9Res_valueE(ptr noundef nonnull align 8 dereferenceable(313) %30, ptr noundef nonnull %31)
  br i1 %32, label %35, label %.thread

.thread:                                          ; preds = %14, %27
  %33 = getelementptr inbounds i8, ptr %23, i64 16
  %34 = load i32, ptr %33, align 4, !tbaa !20
  br label %46

35:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %36 = getelementptr inbounds i8, ptr %23, i64 16
  %37 = load i32, ptr %36, align 4, !tbaa !20
  store i32 %37, ptr %3, align 4, !tbaa !23
  %38 = load ptr, ptr %0, align 8, !tbaa !19
  %39 = getelementptr inbounds i8, ptr %38, i64 40
  %40 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessIKN7android15DynamicRefTableELN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %39) #4
  %41 = load ptr, ptr %40, align 8, !tbaa !24
  %42 = getelementptr inbounds i8, ptr %41, i64 16
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef i32 %43(ptr noundef nonnull align 8 dereferenceable(313) %40, ptr noundef nonnull %3)
  %.not = icmp eq i32 %44, 0
  %45 = load i32, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  br i1 %.not, label %46, label %.thread19

.thread19:                                        ; preds = %7, %35
  br label %46

46:                                               ; preds = %2, %.thread19, %.thread, %35
  %.4 = phi i32 [ %45, %35 ], [ %34, %.thread ], [ 0, %.thread19 ], [ 0, %2 ]
  ret i32 %.4
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK7android15DynamicRefTable14requiresLookupEPKNS_9Res_valueE(ptr noundef nonnull align 8 dereferenceable(313), ptr noundef) 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, !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 12}
!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}
!17 = !{!14, !16, i64 8}
!18 = !{!14, !16, i64 10}
!19 = !{!6, !7, i64 0}
!20 = !{!21, !11, i64 16}
!21 = !{!"_ZTSN7android20ResXMLTree_attributeE", !15, i64 0, !15, i64 4, !15, i64 8, !22, i64 12}
!22 = !{!"_ZTSN7android9Res_valueE", !16, i64 0, !8, i64 2, !8, i64 3, !11, i64 4}
!23 = !{!11, !11, i64 0}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !9, i64 0}


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