; LLVM IR from facebook/redex :: libresource (Visitor)

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

%"struct.android::ResStringPool_header" = type { %"struct.android::ResChunk_header", i32, i32, i32, i32, i32 }
%"struct.android::ResChunk_header" = type { i16, i16, i32 }
%"struct.android::ResStringPool_span" = type { %"struct.android::ResStringPool_ref", i32, i32 }
%"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 uwtable
define dso_local noundef zeroext i1 @_ZN4arsc20StringPoolRefVisitor20visit_global_stringsEPN7android20ResStringPool_headerE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8
  br label %13

13:                                               ; preds = %2
  br label %14

14:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.android::ResStringPool_header", ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.android::ResStringPool_header", ptr %18, i32 0, i32 5
  %20 = load i32, ptr %19, align 4, !tbaa !15
  store i32 %20, ptr %7, align 4, !tbaa !14
  %21 = load i32, ptr %6, align 4, !tbaa !14
  %22 = icmp ugt i32 %21, 0
  br i1 %22, label %23, label %91

23:                                               ; preds = %14
  %24 = load i32, ptr %7, align 4, !tbaa !14
  %25 = icmp ugt i32 %24, 0
  br i1 %25, label %26, label %91

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.android::ResStringPool_header", ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %"struct.android::ResChunk_header", ptr %29, i32 0, i32 1
  %31 = load i16, ptr %30, align 2, !tbaa !16
  %32 = zext i16 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %27, i64 %33
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.android::ResStringPool_header", ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !17
  %38 = zext i32 %37 to i64
  %39 = mul i64 %38, 4
  %40 = getelementptr inbounds i8, ptr %34, i64 %39
  store ptr %40, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !18
  br label %41

41:                                               ; preds = %82, %26
  %42 = load i64, ptr %9, align 8, !tbaa !18
  %43 = load i32, ptr %6, align 4, !tbaa !14
  %44 = zext i32 %43 to i64
  %45 = icmp ult i64 %42, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %41
  store i32 4, ptr %10, align 4
  br label %85

47:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !14
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %48, i64 %50
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %52, align 4, !tbaa !14
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %51, i64 %54
  store ptr %55, ptr %11, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %73, %47
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.android::ResStringPool_span", ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %"struct.android::ResStringPool_ref", ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !20
  %61 = icmp ne i32 %60, -1
  br i1 %61, label %62, label %76

62:                                               ; preds = %56
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.android::ResStringPool_span", ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %12, align 8, !tbaa !23
  %69 = getelementptr inbounds ptr, ptr %68, i64 19
  %70 = load ptr, ptr %69, align 8
  %71 = call noundef zeroext i1 %70(ptr noundef nonnull align 8 dereferenceable(24) %12, ptr noundef %67)
  br i1 %71, label %73, label %72

72:                                               ; preds = %65
  store i1 false, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %79

73:                                               ; preds = %65
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = getelementptr inbounds %"struct.android::ResStringPool_span", ptr %74, i32 1
  store ptr %75, ptr %11, align 8, !tbaa !5
  br label %56, !llvm.loop !25

76:                                               ; preds = %56
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds i32, ptr %77, i32 1
  store ptr %78, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %10, align 4
  br label %79

79:                                               ; preds = %76, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %80 = load i32, ptr %10, align 4
  switch i32 %80, label %85 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81
  %83 = load i64, ptr %9, align 8, !tbaa !18
  %84 = add i64 %83, 1
  store i64 %84, ptr %9, align 8, !tbaa !18
  br label %41, !llvm.loop !27

85:                                               ; preds = %79, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %86 = load i32, ptr %10, align 4
  switch i32 %86, label %88 [
    i32 4, label %87
  ]

87:                                               ; preds = %85
  store i32 0, ptr %10, align 4
  br label %88

88:                                               ; preds = %87, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %89 = load i32, ptr %10, align 4
  switch i32 %89, label %92 [
    i32 0, label %90
  ]

90:                                               ; preds = %88
  br label %91

91:                                               ; preds = %90, %23, %14
  store i1 true, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %92

92:                                               ; preds = %91, %88
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %93 = load i1, ptr %3, align 1
  ret i1 %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !13, i64 12}
!10 = !{!"_ZTSN7android20ResStringPool_headerE", !11, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24}
!11 = !{!"_ZTSN7android15ResChunk_headerE", !12, i64 0, !12, i64 2, !13, i64 4}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!10, !13, i64 24}
!16 = !{!10, !12, i64 2}
!17 = !{!10, !13, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!21, !13, i64 0}
!21 = !{!"_ZTSN7android18ResStringPool_spanE", !22, i64 0, !13, i64 4, !13, i64 8}
!22 = !{!"_ZTSN7android17ResStringPool_refE", !13, i64 0}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !8, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


; 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 zeroext i1 @_ZN4arsc20StringPoolRefVisitor20visit_global_stringsEPN7android20ResStringPool_headerE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 12
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load i32, ptr %5, align 4, !tbaa !12
  %7 = icmp ne i32 %4, 0
  %8 = icmp ne i32 %6, 0
  %or.cond = select i1 %7, i1 %8, i1 false
  br i1 %or.cond, label %9, label %.critedge

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

22:                                               ; preds = %9, %._crit_edge
  %.02539 = phi i64 [ 0, %9 ], [ %35, %._crit_edge ]
  %.02638 = phi ptr [ %18, %9 ], [ %34, %._crit_edge ]
  %23 = load i32, ptr %.02638, align 4, !tbaa !15
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %21, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %.not36 = icmp eq i32 %26, -1
  br i1 %.not36, label %._crit_edge, label %.lr.ph

27:                                               ; preds = %.lr.ph
  %28 = getelementptr inbounds i8, ptr %.037, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !16
  %.not = icmp eq i32 %29, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !19

.lr.ph:                                           ; preds = %22, %27
  %.037 = phi ptr [ %28, %27 ], [ %25, %22 ]
  %30 = load ptr, ptr %0, align 8, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %30, i64 152
  %32 = load ptr, ptr %31, align 8
  %33 = tail call noundef zeroext i1 %32(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %.037)
  br i1 %33, label %27, label %.critedge

._crit_edge:                                      ; preds = %27, %22
  %34 = getelementptr inbounds i8, ptr %.02638, i64 4
  %35 = add nuw nsw i64 %.02539, 1
  %exitcond.not = icmp eq i64 %35, %19
  br i1 %exitcond.not, label %.critedge, label %22, !llvm.loop !23

.critedge:                                        ; preds = %._crit_edge, %.lr.ph, %2
  %.3 = phi i1 [ true, %2 ], [ false, %.lr.ph ], [ true, %._crit_edge ]
  ret i1 %.3
}

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, !11, i64 12}
!6 = !{!"_ZTSN7android20ResStringPool_headerE", !7, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!7 = !{!"_ZTSN7android15ResChunk_headerE", !8, i64 0, !8, i64 2, !11, i64 4}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!6, !11, i64 24}
!13 = !{!6, !8, i64 2}
!14 = !{!6, !11, i64 8}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"_ZTSN7android18ResStringPool_spanE", !18, i64 0, !11, i64 4, !11, i64 8}
!18 = !{!"_ZTSN7android17ResStringPool_refE", !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !10, i64 0}
!23 = distinct !{!23, !20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass