; LLVM IR from facebook/redex :: libresource/String16.ll (ZN7android8String169makeLowerEv)

; 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::String16" = type { ptr }

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7android12SharedBuffer4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7android8String169makeLowerEv(ptr noundef nonnull align 8 dereferenceable(8) %0) #2 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %12 = call noundef i64 @_ZNK7android8String164sizeEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  store i64 %12, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %13 = call noundef ptr @_ZNK7android8String166stringEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  store ptr %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %60, %1
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  store i32 2, ptr %8, align 4
  br label %63

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #4
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds i16, ptr %20, i64 %21
  %23 = load i16, ptr %22, align 2, !tbaa !11
  store i16 %23, ptr %9, align 2, !tbaa !11
  %24 = load i16, ptr %9, align 2, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = icmp sge i32 %25, 65
  br i1 %26, label %27, label %56

27:                                               ; preds = %19
  %28 = load i16, ptr %9, align 2, !tbaa !11
  %29 = zext i16 %28 to i32
  %30 = icmp sle i32 %29, 90
  br i1 %30, label %31, label %56

31:                                               ; preds = %27
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %47, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %35 = call noundef ptr @_ZN7android8String164editEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  store ptr %35, ptr %10, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 -12, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %44

39:                                               ; preds = %34
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = call noundef ptr @_ZN7android12SharedBuffer4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %40)
  store ptr %41, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %42, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %"class.android::String16", ptr %11, i32 0, i32 0
  store ptr %42, ptr %43, align 8, !tbaa !13
  store i32 0, ptr %8, align 4
  br label %44

44:                                               ; preds = %39, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %45 = load i32, ptr %8, align 4
  switch i32 %45, label %57 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46, %31
  %48 = load i16, ptr %9, align 2, !tbaa !11
  %49 = trunc i16 %48 to i8
  %50 = sext i8 %49 to i32
  %51 = call i32 @tolower(i32 noundef %50) #5
  %52 = trunc i32 %51 to i16
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds i16, ptr %53, i64 %54
  store i16 %52, ptr %55, align 2, !tbaa !11
  br label %56

56:                                               ; preds = %47, %27, %19
  store i32 0, ptr %8, align 4
  br label %57

57:                                               ; preds = %56, %44
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #4
  %58 = load i32, ptr %8, align 4
  switch i32 %58, label %63 [
    i32 0, label %59
  ]

59:                                               ; preds = %57
  br label %60

60:                                               ; preds = %59
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %7, align 8, !tbaa !9
  br label %14, !llvm.loop !15

63:                                               ; preds = %57, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %64 = load i32, ptr %8, align 4
  switch i32 %64, label %66 [
    i32 2, label %65
  ]

65:                                               ; preds = %63
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %66

66:                                               ; preds = %65, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %67 = load i32, ptr %2, align 4
  ret i32 %67
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #3 = { nounwind willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"char16_t", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN7android8String16E", !6, 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7android12SharedBuffer4dataEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7android8String169makeLowerEv(ptr noundef nonnull align 8 dereferenceable(8) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef i64 @_ZNK7android8String164sizeEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %3 = tail call noundef ptr @_ZNK7android8String166stringEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %.not3847.not = icmp eq i64 %2, 0
  br i1 %.not3847.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %17
  %.02250 = phi ptr [ %.426.ph, %17 ], [ %3, %1 ]
  %.03049 = phi i64 [ %18, %17 ], [ 0, %1 ]
  %.03148 = phi ptr [ %.435.ph, %17 ], [ null, %1 ]
  %4 = getelementptr inbounds i16, ptr %.02250, i64 %.03049
  %5 = load i16, ptr %4, align 2, !tbaa !5
  %6 = add i16 %5, -65
  %or.cond = icmp ult i16 %6, 26
  br i1 %or.cond, label %7, label %17

7:                                                ; preds = %.lr.ph
  %.not = icmp eq ptr %.03148, null
  br i1 %.not, label %8, label %12

8:                                                ; preds = %7
  %9 = tail call noundef ptr @_ZN7android8String164editEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %.not37.not = icmp eq ptr %9, null
  br i1 %.not37.not, label %._crit_edge, label %10

10:                                               ; preds = %8
  %11 = tail call noundef ptr @_ZN7android12SharedBuffer4dataEv(ptr noundef nonnull align 8 dereferenceable(24) %9)
  store ptr %11, ptr %0, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %10, %7
  %.233 = phi ptr [ %.03148, %7 ], [ %11, %10 ]
  %.224 = phi ptr [ %.02250, %7 ], [ %11, %10 ]
  %13 = zext nneg i16 %5 to i32
  %14 = tail call i32 @tolower(i32 noundef %13) #3
  %15 = trunc i32 %14 to i16
  %16 = getelementptr inbounds i16, ptr %.233, i64 %.03049
  store i16 %15, ptr %16, align 2, !tbaa !5
  br label %17

17:                                               ; preds = %12, %.lr.ph
  %.435.ph = phi ptr [ %.03148, %.lr.ph ], [ %.233, %12 ]
  %.426.ph = phi ptr [ %.02250, %.lr.ph ], [ %.224, %12 ]
  %18 = add nuw i64 %.03049, 1
  %exitcond.not = icmp eq i64 %18, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %17, %8, %1
  %spec.select = phi i32 [ 0, %1 ], [ -12, %8 ], [ 0, %17 ]
  ret i32 %spec.select
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) local_unnamed_addr #2

attributes #0 = { inlinehint 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 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 nofree nounwind willreturn memory(read) "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 willreturn memory(read) }

!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 = !{!"char16_t", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSN7android8String16E", !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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