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

; 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::ResStringPool" = type <{ ptr, i32, [4 x i8], ptr, ptr, i64, %"class.std::mutex", ptr, ptr, ptr, ptr, i32, [4 x i8], ptr, i32, [4 x i8] }>
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"struct.android::ResStringPool_header" = type { %"struct.android::ResChunk_header", i32, i32, i32, i32, i32 }
%"struct.android::ResChunk_header" = type { i16, i16, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7android13ResStringPool6uninitEv(ptr noundef nonnull align 8 dereferenceable(132) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 1
  store i32 -19, ptr %5, align 8, !tbaa !9
  %6 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 4
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %48

9:                                                ; preds = %1
  %10 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 10
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %48

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !17
  br label %14

14:                                               ; preds = %41, %13
  %15 = load i64, ptr %3, align 8, !tbaa !17
  %16 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = getelementptr inbounds %"struct.android::ResStringPool_header", ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !18
  %20 = zext i32 %19 to i64
  %21 = icmp ult i64 %15, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %44

23:                                               ; preds = %14
  %24 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 10
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = load i64, ptr %3, align 8, !tbaa !17
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %40

30:                                               ; preds = %23
  %31 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 10
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load i64, ptr %3, align 8, !tbaa !17
  %34 = getelementptr inbounds ptr, ptr %32, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  call void @free(ptr noundef %35) #3
  %36 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 10
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load i64, ptr %3, align 8, !tbaa !17
  %39 = getelementptr inbounds ptr, ptr %37, i64 %38
  store ptr null, ptr %39, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %30, %23
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %3, align 8, !tbaa !17
  %43 = add i64 %42, 1
  store i64 %43, ptr %3, align 8, !tbaa !17
  br label %14, !llvm.loop !22

44:                                               ; preds = %22
  %45 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 10
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  call void @free(ptr noundef %46) #3
  %47 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 10
  store ptr null, ptr %47, align 8, !tbaa !16
  br label %48

48:                                               ; preds = %44, %9, %1
  %49 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !24
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %56

52:                                               ; preds = %48
  %53 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !24
  call void @free(ptr noundef %54) #3
  %55 = getelementptr inbounds %"class.android::ResStringPool", ptr %4, i32 0, i32 3
  store ptr null, ptr %55, align 8, !tbaa !24
  br label %56

56:                                               ; preds = %52, %48
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !11, i64 8}
!10 = !{!"_ZTSN7android13ResStringPoolE", !11, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !13, i64 40, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !11, i64 112, !6, i64 120, !11, i64 128}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"_ZTSSt5mutex", !14, i64 0}
!14 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !6, i64 104}
!17 = !{!12, !12, i64 0}
!18 = !{!19, !11, i64 8}
!19 = !{!"_ZTSN7android20ResStringPool_headerE", !20, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!20 = !{!"_ZTSN7android15ResChunk_headerE", !21, i64 0, !21, i64 2, !11, i64 4}
!21 = !{!"short", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!10, !6, i64 16}


; 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 nounwind uwtable
define dso_local void @_ZN7android13ResStringPool6uninitEv(ptr nocapture noundef nonnull align 8 dereferenceable(132) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 -19, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !14
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %25, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %.not7 = icmp eq ptr %7, null
  br i1 %.not7, label %25, label %.preheader

.preheader:                                       ; preds = %5
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  %9 = load i32, ptr %8, align 4, !tbaa !16
  %.not11 = icmp eq i32 %9, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %18
  %.pre12 = load ptr, ptr %6, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %10 = phi ptr [ %.pre12, %._crit_edge.loopexit ], [ %7, %.preheader ]
  tail call void @free(ptr noundef %10) #2
  store ptr null, ptr %6, align 8, !tbaa !15
  br label %25

.lr.ph:                                           ; preds = %.preheader, %18
  %11 = phi ptr [ %19, %18 ], [ %4, %.preheader ]
  %.010 = phi i64 [ %20, %18 ], [ 0, %.preheader ]
  %12 = load ptr, ptr %6, align 8, !tbaa !15
  %13 = getelementptr inbounds ptr, ptr %12, i64 %.010
  %14 = load ptr, ptr %13, align 8, !tbaa !20
  %.not9 = icmp eq ptr %14, null
  br i1 %.not9, label %18, label %15

15:                                               ; preds = %.lr.ph
  tail call void @free(ptr noundef nonnull %14) #2
  %16 = load ptr, ptr %6, align 8, !tbaa !15
  %17 = getelementptr inbounds ptr, ptr %16, i64 %.010
  store ptr null, ptr %17, align 8, !tbaa !20
  %.pre = load ptr, ptr %3, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %.lr.ph, %15
  %19 = phi ptr [ %11, %.lr.ph ], [ %.pre, %15 ]
  %20 = add nuw nsw i64 %.010, 1
  %21 = getelementptr inbounds i8, ptr %19, i64 8
  %22 = load i32, ptr %21, align 4, !tbaa !16
  %23 = zext i32 %22 to i64
  %24 = icmp ult i64 %20, %23
  br i1 %24, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !21

25:                                               ; preds = %._crit_edge, %5, %1
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  %.not8 = icmp eq ptr %27, null
  br i1 %.not8, label %29, label %28

28:                                               ; preds = %25
  tail call void @free(ptr noundef nonnull %27) #2
  store ptr null, ptr %26, align 8, !tbaa !23
  br label %29

29:                                               ; preds = %28, %25
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !7, i64 8}
!6 = !{!"_ZTSN7android13ResStringPoolE", !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !12, i64 40, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !7, i64 112, !10, i64 120, !7, i64 128}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_ZTSSt5mutex", !13, i64 0}
!13 = !{!"_ZTSSt12__mutex_base", !8, i64 0}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !10, i64 104}
!16 = !{!17, !7, i64 8}
!17 = !{!"_ZTSN7android20ResStringPool_headerE", !18, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!18 = !{!"_ZTSN7android15ResChunk_headerE", !19, i64 0, !19, i64 2, !7, i64 4}
!19 = !{!"short", !8, i64 0}
!20 = !{!10, !10, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!6, !10, i64 16}


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