; LLVM IR from facebook/redex :: libredex/ApiLevelChecker.ll (ZN3api12LevelChecker10init_classEP8DexClass)

; 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.DexClass = type { ptr, ptr, ptr, ptr, %"class.std::unique_ptr", ptr, ptr, %"class.std::vector.33", %"class.std::vector.33", %"class.std::vector.38", %"class.std::vector.38", i32, i8, i8, i8, %class.ReferencedState }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.5" }
%"struct.std::_Head_base.5" = type { ptr }
%"class.std::vector.33" = type { %"struct.std::_Vector_base.34" }
%"struct.std::_Vector_base.34" = type { %"struct.std::_Vector_base<DexField *, std::allocator<DexField *>>::_Vector_impl" }
%"struct.std::_Vector_base<DexField *, std::allocator<DexField *>>::_Vector_impl" = type { %"struct.std::_Vector_base<DexField *, std::allocator<DexField *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<DexField *, std::allocator<DexField *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.38" = type { %"struct.std::_Vector_base.39" }
%"struct.std::_Vector_base.39" = type { %"struct.std::_Vector_base<DexMethod *, std::allocator<DexMethod *>>::_Vector_impl" }
%"struct.std::_Vector_base<DexMethod *, std::allocator<DexMethod *>>::_Vector_impl" = type { %"struct.std::_Vector_base<DexMethod *, std::allocator<DexMethod *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<DexMethod *, std::allocator<DexMethod *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.ReferencedState = type { %"struct.ReferencedState::InnerStruct", i32, %"struct.std::atomic" }
%"struct.ReferencedState::InnerStruct" = type <{ i8, i16, %union.anon.30 }>
%union.anon.30 = type { %struct.anon }
%struct.anon = type { i8 }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { ptr }

@_ZN3api12LevelChecker11s_min_levelE = external dso_local global i32, align 4

; 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 @_ZN3api12LevelChecker10init_classEP8DexClass(ptr noundef %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %24, %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  store i32 2, ptr %4, align 4
  br label %27

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call noundef i32 @_ZN3api12LevelChecker9get_levelI8DexClassEEiPKT_(ptr noundef %12)
  store i32 %13, ptr %5, align 4, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp ne i32 %14, -1
  br i1 %15, label %16, label %20

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.DexClass, ptr %17, i32 0, i32 15
  %19 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN15ReferencedState13set_api_levelEi(ptr noundef nonnull align 8 dereferenceable(16) %18, i32 noundef %19)
  store i32 1, ptr %4, align 4
  br label %21

20:                                               ; preds = %11
  store i32 0, ptr %4, align 4
  br label %21

21:                                               ; preds = %20, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %22 = load i32, ptr %4, align 4
  switch i32 %22, label %27 [
    i32 0, label %23
  ]

23:                                               ; preds = %21
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call noundef ptr @_ZN3api12LevelChecker15get_outer_classEPK8DexClass(ptr noundef %25)
  store ptr %26, ptr %3, align 8, !tbaa !5
  br label %7, !llvm.loop !11

27:                                               ; preds = %21, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  %28 = load i32, ptr %4, align 4
  switch i32 %28, label %34 [
    i32 2, label %29
    i32 1, label %33
  ]

29:                                               ; preds = %27
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.DexClass, ptr %30, i32 0, i32 15
  %32 = load i32, ptr @_ZN3api12LevelChecker11s_min_levelE, align 4, !tbaa !9
  call void @_ZN15ReferencedState13set_api_levelEi(ptr noundef nonnull align 8 dereferenceable(16) %31, i32 noundef %32)
  br label %33

33:                                               ; preds = %29, %27
  ret void

34:                                               ; preds = %27
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN3api12LevelChecker9get_levelI8DexClassEEiPKT_(ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN15ReferencedState13set_api_levelEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN3api12LevelChecker15get_outer_classEPK8DexClass(ptr noundef) #1 align 2

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@_ZN3api12LevelChecker11s_min_levelE = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3api12LevelChecker10init_classEP8DexClass(ptr noundef %0) local_unnamed_addr #0 align 2 {
  %.not15 = icmp eq ptr %0, null
  br i1 %.not15, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.critedge
  %.016 = phi ptr [ %3, %.critedge ], [ %0, %1 ]
  %2 = tail call noundef i32 @_ZN3api12LevelChecker9get_levelI8DexClassEEiPKT_(ptr noundef nonnull %.016)
  %.not11 = icmp eq i32 %2, -1
  br i1 %.not11, label %.critedge, label %4

.critedge:                                        ; preds = %.lr.ph
  %3 = tail call noundef ptr @_ZN3api12LevelChecker15get_outer_classEPK8DexClass(ptr noundef nonnull %.016)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

4:                                                ; preds = %.lr.ph
  %5 = getelementptr inbounds i8, ptr %0, i64 160
  tail call void @_ZN15ReferencedState13set_api_levelEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %2)
  br label %8

._crit_edge:                                      ; preds = %.critedge, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 160
  %7 = load i32, ptr @_ZN3api12LevelChecker11s_min_levelE, align 4, !tbaa !7
  tail call void @_ZN15ReferencedState13set_api_levelEi(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef %7)
  br label %8

8:                                                ; preds = %4, %._crit_edge
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN3api12LevelChecker9get_levelI8DexClassEEiPKT_(ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN15ReferencedState13set_api_levelEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN3api12LevelChecker15get_outer_classEPK8DexClass(ptr noundef) local_unnamed_addr #0 align 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


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