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

; 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::DynamicRefTable" = type <{ ptr, i8, [256 x i8], [7 x i8], %"class.android::KeyedVector", i8, [7 x i8] }>
%"class.android::KeyedVector" = type { %"class.android::SortedVector" }
%"class.android::SortedVector" = type { %"class.android::SortedVectorImpl" }
%"class.android::SortedVectorImpl" = type { %"class.android::VectorImpl" }
%"class.android::VectorImpl" = type { ptr, ptr, i64, i32, i64 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.114 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.115 = external hidden unnamed_addr constant [20 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
define dso_local noundef i32 @_ZNK7android15DynamicRefTable16lookupResourceIdEPj(ptr noundef nonnull align 8 dereferenceable(313) %0, ptr noundef %1) unnamed_addr #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %13, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = lshr i32 %14, 24
  %16 = sub i32 %15, 1
  %17 = add i32 %16, 1
  %18 = zext i32 %17 to i64
  store i64 %18, ptr %7, align 8, !tbaa !11
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %117

22:                                               ; preds = %2
  %23 = load i64, ptr %7, align 8, !tbaa !11
  %24 = icmp eq i64 %23, 127
  br i1 %24, label %25, label %30

25:                                               ; preds = %22
  %26 = getelementptr inbounds %"class.android::DynamicRefTable", ptr %11, i32 0, i32 5
  %27 = load i8, ptr %26, align 8, !tbaa !13, !range !20, !noundef !21
  %28 = trunc i8 %27 to i1
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %117

30:                                               ; preds = %25, %22
  %31 = load i64, ptr %7, align 8, !tbaa !11
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %40, label %33

33:                                               ; preds = %30
  %34 = load i64, ptr %7, align 8, !tbaa !11
  %35 = icmp eq i64 %34, 127
  br i1 %35, label %36, label %50

36:                                               ; preds = %33
  %37 = getelementptr inbounds %"class.android::DynamicRefTable", ptr %11, i32 0, i32 5
  %38 = load i8, ptr %37, align 8, !tbaa !13, !range !20, !noundef !21
  %39 = trunc i8 %38 to i1
  br i1 %39, label %40, label %50

40:                                               ; preds = %36, %30
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = and i32 16777215, %42
  %44 = getelementptr inbounds %"class.android::DynamicRefTable", ptr %11, i32 0, i32 1
  %45 = load i8, ptr %44, align 8, !tbaa !22
  %46 = zext i8 %45 to i32
  %47 = shl i32 %46, 24
  %48 = or i32 %43, %47
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %48, ptr %49, align 4, !tbaa !9
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %117

50:                                               ; preds = %36, %33
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %51 = getelementptr inbounds %"class.android::DynamicRefTable", ptr %11, i32 0, i32 2
  %52 = load i64, ptr %7, align 8, !tbaa !11
  %53 = getelementptr inbounds [256 x i8], ptr %51, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !23
  store i8 %54, ptr %9, align 1, !tbaa !23
  %55 = load i8, ptr %9, align 1, !tbaa !23
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %108

58:                                               ; preds = %50
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str) #3
  %62 = load ptr, ptr @stderr, align 8, !tbaa !5
  %63 = getelementptr inbounds %"class.android::DynamicRefTable", ptr %11, i32 0, i32 1
  %64 = load i8, ptr %63, align 8, !tbaa !22
  %65 = zext i8 %64 to i32
  %66 = load i64, ptr %7, align 8, !tbaa !11
  %67 = trunc i64 %66 to i8
  %68 = zext i8 %67 to i32
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.114, i32 noundef %65, i32 noundef %68) #3
  %70 = load ptr, ptr @stderr, align 8, !tbaa !5
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.2) #3
  br label %72

72:                                               ; preds = %59
  br label %73

73:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %74

74:                                               ; preds = %104, %73
  %75 = load i64, ptr %10, align 8, !tbaa !11
  %76 = icmp ult i64 %75, 256
  br i1 %76, label %78, label %77

77:                                               ; preds = %74
  store i32 4, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %107

78:                                               ; preds = %74
  %79 = getelementptr inbounds %"class.android::DynamicRefTable", ptr %11, i32 0, i32 2
  %80 = load i64, ptr %10, align 8, !tbaa !11
  %81 = getelementptr inbounds [256 x i8], ptr %79, i64 0, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !23
  %83 = zext i8 %82 to i32
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %103

85:                                               ; preds = %78
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str) #3
  %89 = load ptr, ptr @stderr, align 8, !tbaa !5
  %90 = load i64, ptr %10, align 8, !tbaa !11
  %91 = trunc i64 %90 to i8
  %92 = zext i8 %91 to i32
  %93 = getelementptr inbounds %"class.android::DynamicRefTable", ptr %11, i32 0, i32 2
  %94 = load i64, ptr %10, align 8, !tbaa !11
  %95 = getelementptr inbounds [256 x i8], ptr %93, i64 0, i64 %94
  %96 = load i8, ptr %95, align 1, !tbaa !23
  %97 = zext i8 %96 to i32
  %98 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %89, ptr noundef @.str.115, i32 noundef %92, i32 noundef %97) #3
  %99 = load ptr, ptr @stderr, align 8, !tbaa !5
  %100 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %99, ptr noundef @.str.2) #3
  br label %101

101:                                              ; preds = %86
  br label %102

102:                                              ; preds = %101
  br label %103

103:                                              ; preds = %102, %78
  br label %104

104:                                              ; preds = %103
  %105 = load i64, ptr %10, align 8, !tbaa !11
  %106 = add i64 %105, 1
  store i64 %106, ptr %10, align 8, !tbaa !11
  br label %74, !llvm.loop !24

107:                                              ; preds = %77
  store i32 -2147483648, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %116

108:                                              ; preds = %50
  %109 = load i32, ptr %6, align 4, !tbaa !9
  %110 = and i32 %109, 16777215
  %111 = load i8, ptr %9, align 1, !tbaa !23
  %112 = zext i8 %111 to i32
  %113 = shl i32 %112, 24
  %114 = or i32 %110, %113
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %114, ptr %115, align 4, !tbaa !9
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %116

116:                                              ; preds = %108, %107
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  br label %117

117:                                              ; preds = %116, %40, %29, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %118 = load i32, ptr %3, align 4
  ret i32 %118
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !19, i64 312}
!14 = !{!"_ZTSN7android15DynamicRefTableE", !7, i64 8, !7, i64 9, !15, i64 272, !19, i64 312}
!15 = !{!"_ZTSN7android11KeyedVectorINS_8String16EhEE", !16, i64 0}
!16 = !{!"_ZTSN7android12SortedVectorINS_16key_value_pair_tINS_8String16EhEEEE", !17, i64 0}
!17 = !{!"_ZTSN7android16SortedVectorImplE", !18, i64 0}
!18 = !{!"_ZTSN7android10VectorImplE", !6, i64 8, !12, i64 16, !10, i64 24, !12, i64 32}
!19 = !{!"bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!14, !7, i64 8}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.114 = external hidden unnamed_addr constant [70 x i8], align 1
@.str.115 = external hidden unnamed_addr constant [20 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 nofree nounwind uwtable
define dso_local noundef range(i32 -2147483648, 1) i32 @_ZNK7android15DynamicRefTable16lookupResourceIdEPj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(313) %0, ptr nocapture noundef %1) unnamed_addr #1 align 2 {
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = lshr i32 %3, 24
  %5 = zext nneg i32 %4 to i64
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = icmp eq i32 %4, 127
  br i1 %7, label %8, label %.thread

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 312
  %10 = load i8, ptr %9, align 8, !tbaa !9, !range !18, !noundef !19
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %13, label %.loopexit

.thread:                                          ; preds = %6
  %12 = icmp ult i32 %3, 16777216
  br i1 %12, label %13, label %.thread25

13:                                               ; preds = %8, %.thread
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i8, ptr %14, align 8, !tbaa !20
  br label %.loopexit.sink.split

.thread25:                                        ; preds = %.thread
  %16 = getelementptr inbounds i8, ptr %0, i64 9
  %17 = getelementptr inbounds [256 x i8], ptr %16, i64 0, i64 %5
  %18 = load i8, ptr %17, align 1, !tbaa !21
  %19 = icmp eq i8 %18, 0
  br i1 %19, label %20, label %.loopexit.sink.split

20:                                               ; preds = %.thread25
  %21 = load ptr, ptr @stderr, align 8, !tbaa !22
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str) #2
  %23 = load ptr, ptr @stderr, align 8, !tbaa !22
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load i8, ptr %24, align 8, !tbaa !20
  %26 = zext i8 %25 to i32
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.114, i32 noundef %26, i32 noundef %4) #2
  %28 = load ptr, ptr @stderr, align 8, !tbaa !22
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.2) #2
  br label %30

30:                                               ; preds = %20, %43
  %.026 = phi i64 [ 0, %20 ], [ %44, %43 ]
  %31 = getelementptr inbounds [256 x i8], ptr %16, i64 0, i64 %.026
  %32 = load i8, ptr %31, align 1, !tbaa !21
  %.not24 = icmp eq i8 %32, 0
  br i1 %.not24, label %43, label %33

33:                                               ; preds = %30
  %34 = load ptr, ptr @stderr, align 8, !tbaa !22
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str) #2
  %36 = load ptr, ptr @stderr, align 8, !tbaa !22
  %37 = trunc nuw i64 %.026 to i32
  %38 = load i8, ptr %31, align 1, !tbaa !21
  %39 = zext i8 %38 to i32
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.115, i32 noundef %37, i32 noundef %39) #2
  %41 = load ptr, ptr @stderr, align 8, !tbaa !22
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str.2) #2
  br label %43

43:                                               ; preds = %30, %33
  %44 = add nuw nsw i64 %.026, 1
  %exitcond.not = icmp eq i64 %44, 256
  br i1 %exitcond.not, label %.loopexit, label %30, !llvm.loop !23

.loopexit.sink.split:                             ; preds = %.thread25, %13
  %.sink.in = phi i8 [ %15, %13 ], [ %18, %.thread25 ]
  %.sink28 = and i32 %3, 16777215
  %.sink = zext i8 %.sink.in to i32
  %45 = shl nuw i32 %.sink, 24
  %46 = or disjoint i32 %45, %.sink28
  store i32 %46, ptr %1, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %43, %.loopexit.sink.split, %8, %2
  %.1 = phi i32 [ 0, %2 ], [ 0, %8 ], [ 0, %.loopexit.sink.split ], [ -2147483648, %43 ]
  ret i32 %.1
}

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 nofree 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !17, i64 312}
!10 = !{!"_ZTSN7android15DynamicRefTableE", !7, i64 8, !7, i64 9, !11, i64 272, !17, i64 312}
!11 = !{!"_ZTSN7android11KeyedVectorINS_8String16EhEE", !12, i64 0}
!12 = !{!"_ZTSN7android12SortedVectorINS_16key_value_pair_tINS_8String16EhEEEE", !13, i64 0}
!13 = !{!"_ZTSN7android16SortedVectorImplE", !14, i64 0}
!14 = !{!"_ZTSN7android10VectorImplE", !15, i64 8, !16, i64 16, !6, i64 24, !16, i64 32}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!10, !7, i64 8}
!21 = !{!7, !7, i64 0}
!22 = !{!15, !15, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ADCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass