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

; 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: mustprogress uwtable
define dso_local noundef i32 @_ZN7android12ResXMLParser4nextEv(ptr noundef nonnull align 8 dereferenceable(36) %0) #0 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  %5 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 1
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %24

8:                                                ; preds = %1
  %9 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds %"class.android::ResXMLTree", ptr %10, i32 0, i32 12
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 3
  store ptr %12, ptr %13, align 8, !tbaa !23
  %14 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds %"class.android::ResXMLTree", ptr %15, i32 0, i32 13
  %17 = load ptr, ptr %16, align 8, !tbaa !24
  %18 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 4
  store ptr %17, ptr %18, align 8, !tbaa !25
  %19 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds %"class.android::ResXMLTree", ptr %20, i32 0, i32 14
  %22 = load i32, ptr %21, align 8, !tbaa !26
  %23 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 1
  store i32 %22, ptr %23, align 8, !tbaa !9
  store i32 %22, ptr %2, align 4
  br label %34

24:                                               ; preds = %1
  %25 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = icmp sge i32 %26, 256
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = call noundef i32 @_ZN7android12ResXMLParser8nextNodeEv(ptr noundef nonnull align 8 dereferenceable(36) %4)
  store i32 %29, ptr %2, align 4
  br label %34

30:                                               ; preds = %24
  br label %31

31:                                               ; preds = %30
  %32 = getelementptr inbounds %"class.android::ResXMLParser", ptr %4, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !9
  store i32 %33, ptr %2, align 4
  br label %34

34:                                               ; preds = %31, %28, %8
  %35 = load i32, ptr %2, align 4
  ret i32 %35
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7android12ResXMLParser8nextNodeEv(ptr noundef nonnull align 8 dereferenceable(36)) #0 align 2

attributes #0 = { 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" }

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


; 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 uwtable
define dso_local noundef i32 @_ZN7android12ResXMLParser4nextEv(ptr noundef nonnull 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, 0
  br i1 %4, label %5, label %12

5:                                                ; preds = %1
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %6, i64 248
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load <2 x ptr>, ptr %7, align 8, !tbaa !13
  store <2 x ptr> %9, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %6, i64 264
  %11 = load i32, ptr %10, align 8, !tbaa !14
  store i32 %11, ptr %2, align 8, !tbaa !5
  br label %16

12:                                               ; preds = %1
  %13 = icmp sgt i32 %3, 255
  br i1 %13, label %14, label %16

14:                                               ; preds = %12
  %15 = tail call noundef i32 @_ZN7android12ResXMLParser8nextNodeEv(ptr noundef nonnull align 8 dereferenceable(36) %0)
  br label %16

16:                                               ; preds = %12, %14, %5
  %.0 = phi i32 [ %11, %5 ], [ %15, %14 ], [ %3, %12 ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7android12ResXMLParser8nextNodeEv(ptr noundef nonnull align 8 dereferenceable(36)) local_unnamed_addr #0 align 2

attributes #0 = { 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" }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass