; LLVM IR from facebook/redex :: service/escape-analysis (LocalPointersAnalysis)

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

; 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 void @_ZN14local_pointers30escape_heap_referenced_objectsEPK13IRInstructionPNS_20EnvironmentWithStoreE(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32) %7)
  store i16 %8, ptr %5, align 2, !tbaa !9
  %9 = load i16, ptr %5, align 2, !tbaa !9
  %10 = zext i16 %9 to i32
  %11 = icmp eq i32 %10, 54
  br i1 %11, label %20, label %12

12:                                               ; preds = %2
  %13 = load i16, ptr %5, align 2, !tbaa !9
  %14 = zext i16 %13 to i32
  %15 = icmp eq i32 %14, 82
  br i1 %15, label %20, label %16

16:                                               ; preds = %12
  %17 = load i16, ptr %5, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = icmp eq i32 %18, 68
  br i1 %19, label %20, label %28

20:                                               ; preds = %16, %12, %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call noundef i32 @_ZNK13IRInstruction3srcEt(ptr noundef nonnull align 8 dereferenceable(32) %22, i16 noundef zeroext 0)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %21, align 8, !tbaa !11
  %26 = getelementptr inbounds ptr, ptr %25, i64 7
  %27 = load ptr, ptr %26, align 8
  call void %27(ptr noundef nonnull align 8 dereferenceable(8) %21, i32 noundef %23, ptr noundef %24)
  br label %59

28:                                               ; preds = %16
  %29 = load i16, ptr %5, align 2, !tbaa !9
  %30 = zext i16 %29 to i32
  %31 = icmp eq i32 %30, 23
  br i1 %31, label %32, label %58

32:                                               ; preds = %28
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call noundef ptr @_ZNK13IRInstruction8get_typeEv(ptr noundef nonnull align 8 dereferenceable(32) %33)
  %35 = call noundef ptr @_ZN4type24get_array_component_typeEPK7DexType(ptr noundef %34)
  %36 = call noundef zeroext i1 @_ZN4type12is_primitiveEPK7DexType(ptr noundef %35)
  br i1 %36, label %58, label %37

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !13
  br label %38

38:                                               ; preds = %54, %37
  %39 = load i64, ptr %6, align 8, !tbaa !13
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = call noundef i64 @_ZNK13IRInstruction9srcs_sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %40)
  %42 = icmp ult i64 %39, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %57

44:                                               ; preds = %38
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load i64, ptr %6, align 8, !tbaa !13
  %48 = trunc i64 %47 to i16
  %49 = call noundef i32 @_ZNK13IRInstruction3srcEt(ptr noundef nonnull align 8 dereferenceable(32) %46, i16 noundef zeroext %48)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load ptr, ptr %45, align 8, !tbaa !11
  %52 = getelementptr inbounds ptr, ptr %51, i64 7
  %53 = load ptr, ptr %52, align 8
  call void %53(ptr noundef nonnull align 8 dereferenceable(8) %45, i32 noundef %49, ptr noundef %50)
  br label %54

54:                                               ; preds = %44
  %55 = load i64, ptr %6, align 8, !tbaa !13
  %56 = add i64 %55, 1
  store i64 %56, ptr %6, align 8, !tbaa !13
  br label %38, !llvm.loop !15

57:                                               ; preds = %43
  br label %58

58:                                               ; preds = %57, %32, %28
  br label %59

59:                                               ; preds = %58, %20
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

declare noundef i32 @_ZNK13IRInstruction3srcEt(ptr noundef nonnull align 8 dereferenceable(32), i16 noundef zeroext) #3

declare noundef zeroext i1 @_ZN4type12is_primitiveEPK7DexType(ptr noundef) #3

declare noundef ptr @_ZN4type24get_array_component_typeEPK7DexType(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK13IRInstruction8get_typeEv(ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

declare noundef i64 @_ZNK13IRInstruction9srcs_sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) #3

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 = { 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 = { "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, !10, i64 0}
!10 = !{!"_ZTS8IROpcode", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 void @_ZN14local_pointers30escape_heap_referenced_objectsEPK13IRInstructionPNS_20EnvironmentWithStoreE(ptr noundef nonnull %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  switch i16 %3, label %.loopexit [
    i16 82, label %4
    i16 68, label %4
    i16 54, label %4
    i16 23, label %9
  ]

4:                                                ; preds = %2, %2, %2
  %5 = tail call noundef i32 @_ZNK13IRInstruction3srcEt(ptr noundef nonnull align 8 dereferenceable(32) %0, i16 noundef zeroext 0)
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 56
  %8 = load ptr, ptr %7, align 8
  tail call void %8(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %5, ptr noundef nonnull %0)
  br label %.loopexit

9:                                                ; preds = %2
  %10 = tail call noundef ptr @_ZNK13IRInstruction8get_typeEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %11 = tail call noundef ptr @_ZN4type24get_array_component_typeEPK7DexType(ptr noundef %10)
  %12 = tail call noundef zeroext i1 @_ZN4type12is_primitiveEPK7DexType(ptr noundef %11)
  br i1 %12, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %9
  %13 = tail call noundef i64 @_ZNK13IRInstruction9srcs_sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.021 = phi i64 [ %19, %.lr.ph ], [ 0, %.preheader ]
  %14 = trunc i64 %.021 to i16
  %15 = tail call noundef i32 @_ZNK13IRInstruction3srcEt(ptr noundef nonnull align 8 dereferenceable(32) %0, i16 noundef zeroext %14)
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 56
  %18 = load ptr, ptr %17, align 8
  tail call void %18(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %15, ptr noundef nonnull %0)
  %19 = add nuw i64 %.021, 1
  %20 = tail call noundef i64 @_ZNK13IRInstruction9srcs_sizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %.lr.ph, label %.loopexit, !llvm.loop !8

.loopexit:                                        ; preds = %.lr.ph, %.preheader, %2, %9, %4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

declare noundef i32 @_ZNK13IRInstruction3srcEt(ptr noundef nonnull align 8 dereferenceable(32), i16 noundef zeroext) local_unnamed_addr #2

declare noundef zeroext i1 @_ZN4type12is_primitiveEPK7DexType(ptr noundef) local_unnamed_addr #2

declare noundef ptr @_ZN4type24get_array_component_typeEPK7DexType(ptr noundef) local_unnamed_addr #2

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

declare noundef i64 @_ZNK13IRInstruction9srcs_sizeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #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" }
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 = { "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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass