; 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::ResTable_overlayable_policy_header" = type { %"struct.android::ResChunk_header", i32, i32 }
%"struct.android::ResChunk_header" = type { i16, i16, 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 @_ZN4arsc20ResourceTableVisitor24visit_overlayable_policyEPN7android16ResTable_packageEPNS1_27ResTable_overlayable_headerEPNS1_34ResTable_overlayable_policy_headerEPj(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) unnamed_addr #1 align 2 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8
  br label %16

16:                                               ; preds = %5
  br label %17

17:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.android::ResTable_overlayable_policy_header", ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %12, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  store i64 0, ptr %13, align 8, !tbaa !16
  br label %21

21:                                               ; preds = %42, %17
  %22 = load i64, ptr %13, align 8, !tbaa !16
  %23 = load i32, ptr %12, align 4, !tbaa !15
  %24 = zext i32 %23 to i64
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 4, ptr %14, align 4
  br label %47

27:                                               ; preds = %21
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = load i32, ptr %34, align 4, !tbaa !15
  %36 = load ptr, ptr %15, align 8, !tbaa !18
  %37 = getelementptr inbounds ptr, ptr %36, i64 15
  %38 = load ptr, ptr %37, align 8
  %39 = call noundef zeroext i1 %38(ptr noundef nonnull align 8 dereferenceable(24) %15, ptr noundef %31, ptr noundef %32, ptr noundef %33, i32 noundef %35)
  br i1 %39, label %41, label %40

40:                                               ; preds = %30
  store i1 false, ptr %6, align 1
  store i32 1, ptr %14, align 4
  br label %47

41:                                               ; preds = %30
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %13, align 8, !tbaa !16
  %44 = add i64 %43, 1
  store i64 %44, ptr %13, align 8, !tbaa !16
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds i32, ptr %45, i32 1
  store ptr %46, ptr %11, align 8, !tbaa !5
  br label %21, !llvm.loop !20

47:                                               ; preds = %40, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %48 = load i32, ptr %14, align 4
  switch i32 %48, label %50 [
    i32 4, label %49
  ]

49:                                               ; preds = %47
  store i1 true, ptr %6, align 1
  store i32 1, ptr %14, align 4
  br label %50

50:                                               ; preds = %49, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %51 = load i1, ptr %6, align 1
  ret i1 %51
}

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 = !{!"_ZTSN7android34ResTable_overlayable_policy_headerE", !11, i64 0, !14, i64 8, !13, i64 12}
!11 = !{!"_ZTSN7android15ResChunk_headerE", !12, i64 0, !12, i64 2, !13, i64 4}
!12 = !{!"short", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN7android34ResTable_overlayable_policy_header11PolicyFlagsE", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; 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 @_ZN4arsc20ResourceTableVisitor24visit_overlayable_policyEPN7android16ResTable_packageEPNS1_27ResTable_overlayable_headerEPNS1_34ResTable_overlayable_policy_headerEPj(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr nocapture noundef readonly %4) unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %3, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %.not14 = icmp eq i32 %7, 0
  br i1 %.not14, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %9 = load i32, ptr %4, align 4, !tbaa !13
  %10 = load ptr, ptr %0, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %10, i64 120
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef zeroext i1 %12(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %9)
  br i1 %13, label %.lr.ph22, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph22
  %14 = getelementptr inbounds i8, ptr %.0131521, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = load ptr, ptr %0, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 120
  %18 = load ptr, ptr %17, align 8
  %19 = tail call noundef zeroext i1 %18(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %15)
  br i1 %19, label %.lr.ph22, label %.critedge.loopexit, !llvm.loop !16

.lr.ph22:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0131521 = phi ptr [ %14, %.lr.ph ], [ %4, %.lr.ph.preheader ]
  %.0111620 = phi i64 [ %20, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %20 = add nuw nsw i64 %.0111620, 1
  %exitcond = icmp eq i64 %20, %8
  br i1 %exitcond, label %.critedge.loopexit, label %.lr.ph, !llvm.loop !16

.critedge.loopexit:                               ; preds = %.lr.ph, %.lr.ph22
  %.not.le = icmp uge i64 %20, %8
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph.preheader, %5
  %.not.lcssa = phi i1 [ true, %5 ], [ false, %.lr.ph.preheader ], [ %.not.le, %.critedge.loopexit ]
  ret i1 %.not.lcssa
}

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 = !{!"_ZTSN7android34ResTable_overlayable_policy_headerE", !7, i64 0, !12, i64 8, !11, i64 12}
!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 = !{!"_ZTSN7android34ResTable_overlayable_policy_header11PolicyFlagsE", !9, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass