; 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_header" = type { %"struct.android::ResChunk_header", [256 x i16], [256 x i16] }
%"struct.android::ResChunk_header" = type { i16, i16, i32 }
%"struct.android::ResTable_overlayable_policy_header" = type { %"struct.android::ResChunk_header", i32, i32 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [81 x i8], align 1

; 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4arsc11VisitorBase15get_file_offsetEPKv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4arsc20ResourceTableVisitor5validEPKN7android27ResTable_overlayable_headerEPKNS1_34ResTable_overlayable_policy_headerE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2) #3 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %18, label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %3
  store i1 false, ptr %4, align 1
  br label %80

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.android::ResTable_overlayable_header", ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %"struct.android::ResChunk_header", ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %23, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.android::ResTable_overlayable_policy_header", ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %"struct.android::ResChunk_header", ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 4, !tbaa !15
  store i32 %27, ptr %9, align 4, !tbaa !14
  %28 = load i32, ptr %8, align 4, !tbaa !14
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.android::ResTable_overlayable_header", ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %"struct.android::ResChunk_header", ptr %30, i32 0, i32 1
  %32 = load i16, ptr %31, align 2, !tbaa !18
  %33 = zext i16 %32 to i32
  %34 = load i32, ptr %9, align 4, !tbaa !14
  %35 = add i32 %33, %34
  %36 = icmp ult i32 %28, %35
  br i1 %36, label %37, label %49

37:                                               ; preds = %19
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str) #4
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call noundef i64 @_ZN4arsc11VisitorBase15get_file_offsetEPKv(ptr noundef nonnull align 8 dereferenceable(24) %12, ptr noundef %42)
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str.9, i64 noundef %43) #4
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.5) #4
  br label %47

47:                                               ; preds = %38
  br label %48

48:                                               ; preds = %47
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %79

49:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.android::ResTable_overlayable_policy_header", ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !19
  %53 = zext i32 %52 to i64
  %54 = mul i64 %53, 4
  store i64 %54, ptr %11, align 8, !tbaa !20
  %55 = load i32, ptr %9, align 4, !tbaa !14
  %56 = zext i32 %55 to i64
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.android::ResTable_overlayable_policy_header", ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %"struct.android::ResChunk_header", ptr %58, i32 0, i32 1
  %60 = load i16, ptr %59, align 2, !tbaa !22
  %61 = zext i16 %60 to i64
  %62 = load i64, ptr %11, align 8, !tbaa !20
  %63 = add i64 %61, %62
  %64 = icmp ne i64 %56, %63
  br i1 %64, label %65, label %77

65:                                               ; preds = %49
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str) #4
  %69 = load ptr, ptr @stderr, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = call noundef i64 @_ZN4arsc11VisitorBase15get_file_offsetEPKv(ptr noundef nonnull align 8 dereferenceable(24) %12, ptr noundef %70)
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef @.str.10, i64 noundef %71) #4
  %73 = load ptr, ptr @stderr, align 8, !tbaa !5
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef @.str.5) #4
  br label %75

75:                                               ; preds = %66
  br label %76

76:                                               ; preds = %75
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %78

77:                                               ; preds = %49
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %78

78:                                               ; preds = %77, %76
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %79

79:                                               ; preds = %78, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %80

80:                                               ; preds = %79, %18
  %81 = load i1, ptr %4, align 1
  ret i1 %81
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 #3 = { 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 #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, !13, i64 4}
!10 = !{!"_ZTSN7android27ResTable_overlayable_headerE", !11, i64 0, !7, i64 8, !7, i64 520}
!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 = !{!16, !13, i64 4}
!16 = !{!"_ZTSN7android34ResTable_overlayable_policy_headerE", !11, i64 0, !17, i64 8, !13, i64 12}
!17 = !{!"_ZTSN7android34ResTable_overlayable_policy_header11PolicyFlagsE", !7, i64 0}
!18 = !{!10, !12, i64 2}
!19 = !{!16, !13, i64 12}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}
!22 = !{!16, !12, i64 2}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [81 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4arsc11VisitorBase15get_file_offsetEPKv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN4arsc20ResourceTableVisitor5validEPKN7android27ResTable_overlayable_headerEPKNS1_34ResTable_overlayable_policy_headerE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = icmp eq ptr %1, null
  %5 = icmp eq ptr %2, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %33, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %1, i64 2
  %12 = load i16, ptr %11, align 2, !tbaa !15
  %13 = zext i16 %12 to i32
  %14 = add i32 %10, %13
  %15 = icmp ult i32 %8, %14
  br i1 %15, label %.sink.split, label %16

16:                                               ; preds = %6
  %17 = getelementptr inbounds i8, ptr %2, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !16
  %19 = zext i32 %18 to i64
  %20 = shl nuw nsw i64 %19, 2
  %21 = zext i32 %10 to i64
  %22 = getelementptr inbounds i8, ptr %2, i64 2
  %23 = load i16, ptr %22, align 2, !tbaa !17
  %24 = zext i16 %23 to i64
  %25 = add nuw nsw i64 %20, %24
  %.not = icmp eq i64 %25, %21
  br i1 %.not, label %33, label %.sink.split

.sink.split:                                      ; preds = %16, %6
  %.sink18 = phi ptr [ %1, %6 ], [ %2, %16 ]
  %.str.9.sink = phi ptr [ @.str.9, %6 ], [ @.str.10, %16 ]
  %26 = load ptr, ptr @stderr, align 8, !tbaa !18
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str) #2
  %28 = load ptr, ptr @stderr, align 8, !tbaa !18
  %29 = tail call noundef i64 @_ZN4arsc11VisitorBase15get_file_offsetEPKv(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %.sink18)
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull %.str.9.sink, i64 noundef %29) #2
  %31 = load ptr, ptr @stderr, align 8, !tbaa !18
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.5) #2
  br label %33

33:                                               ; preds = %.sink.split, %16, %3
  %.2 = phi i1 [ false, %3 ], [ true, %16 ], [ false, %.sink.split ]
  ret i1 %.2
}

attributes #0 = { nofree nounwind "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 #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 = { cold 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, !11, i64 4}
!6 = !{!"_ZTSN7android27ResTable_overlayable_headerE", !7, i64 0, !9, i64 8, !9, i64 520}
!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 = !{!13, !11, i64 4}
!13 = !{!"_ZTSN7android34ResTable_overlayable_policy_headerE", !7, i64 0, !14, i64 8, !11, i64 12}
!14 = !{!"_ZTSN7android34ResTable_overlayable_policy_header11PolicyFlagsE", !9, i64 0}
!15 = !{!6, !8, i64 2}
!16 = !{!13, !11, i64 12}
!17 = !{!13, !8, i64 2}
!18 = !{!19, !19, i64 0}
!19 = !{!"any pointer", !9, i64 0}


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