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

; 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 }
%"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
define dso_local noundef i32 @_ZNK7android12ResXMLParser18getAttributeNameIDEm(ptr noundef nonnull align 8 dereferenceable(36) %0, i64 noundef %1) #1 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
  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
  %10 = getelementptr inbounds %"class.android::ResXMLParser", ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp eq i32 %11, 258
  br i1 %12, label %13, label %45

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

22:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.android::ResXMLTree_attrExt", ptr %24, i32 0, i32 2
  %26 = load i16, ptr %25, align 4, !tbaa !20
  %27 = zext i16 %26 to i32
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %23, i64 %28
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.android::ResXMLTree_attrExt", ptr %30, i32 0, i32 3
  %32 = load i16, ptr %31, align 2, !tbaa !21
  %33 = zext i16 %32 to i64
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = mul i64 %33, %34
  %36 = getelementptr inbounds i8, ptr %29, i64 %35
  store ptr %36, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.android::ResXMLTree_attribute", ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %"struct.android::ResStringPool_ref", ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !22
  store i32 %40, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %42

41:                                               ; preds = %13
  store i32 0, ptr %8, align 4
  br label %42

42:                                               ; preds = %41, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %43 = load i32, ptr %8, align 4
  switch i32 %43, label %48 [
    i32 0, label %44
    i32 1, label %46
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44, %2
  store i32 -1, ptr %3, align 4
  br label %46

46:                                               ; preds = %45, %42
  %47 = load i32, ptr %3, align 4
  ret i32 %47

48:                                               ; preds = %42
  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, !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 = !{!23, !14, i64 4}
!23 = !{!"_ZTSN7android20ResXMLTree_attributeE", !18, i64 0, !18, i64 4, !18, i64 8, !24, i64 12}
!24 = !{!"_ZTSN7android9Res_valueE", !19, i64 0, !7, i64 2, !7, i64 3, !14, i64 4}


; 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 i32 @_ZNK7android12ResXMLParser18getAttributeNameIDEm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(36) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 258
  br i1 %5, label %6, label %.thread

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

13:                                               ; preds = %6
  %14 = getelementptr inbounds i8, ptr %8, i64 8
  %15 = load i16, ptr %14, align 4, !tbaa !17
  %16 = zext i16 %15 to i64
  %17 = getelementptr inbounds i8, ptr %8, i64 %16
  %18 = getelementptr inbounds i8, ptr %8, i64 10
  %19 = load i16, ptr %18, align 2, !tbaa !18
  %20 = zext i16 %19 to i64
  %21 = mul nuw nsw i64 %20, %1
  %22 = getelementptr inbounds i8, ptr %17, i64 %21
  %23 = getelementptr inbounds i8, ptr %22, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !19
  br label %.thread

.thread:                                          ; preds = %6, %2, %13
  %.1 = phi i32 [ %24, %13 ], [ -1, %2 ], [ -1, %6 ]
  ret i32 %.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 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 = !{!20, !11, i64 4}
!20 = !{!"_ZTSN7android20ResXMLTree_attributeE", !15, i64 0, !15, i64 4, !15, i64 8, !21, i64 12}
!21 = !{!"_ZTSN7android9Res_valueE", !16, i64 0, !8, i64 2, !8, i64 3, !11, i64 4}


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