; LLVM IR from facebook/redex :: libresource/String8.ll (ZN7android7String810appendPathEPKc)

; 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN7android7String810appendPathEPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 0
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 47
  br i1 %15, label %16, label %65

16:                                               ; preds = %2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store ptr %10, ptr %3, align 8
  br label %67

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %23 = call noundef i64 @_ZNK7android7String86lengthEv(ptr noundef nonnull align 8 dereferenceable(8) %10)
  store i64 %23, ptr %6, align 8, !tbaa !10
  %24 = load i64, ptr %6, align 8, !tbaa !10
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN7android7String811setPathNameEPKc(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef %27)
  store ptr %10, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %64

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call i64 @strlen(ptr noundef %29) #5
  %31 = trunc i64 %30 to i32
  store i32 %31, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %32 = load i64, ptr %6, align 8, !tbaa !10
  %33 = add i64 %32, 1
  %34 = load i32, ptr %8, align 4, !tbaa !12
  %35 = sext i32 %34 to i64
  %36 = add i64 %33, %35
  %37 = call noundef ptr @_ZN7android7String810lockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %10, i64 noundef %36)
  store ptr %37, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !10
  %40 = sub i64 %39, 1
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 %43, 47
  br i1 %44, label %45, label %50

45:                                               ; preds = %28
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load i64, ptr %6, align 8, !tbaa !10
  %48 = add i64 %47, 1
  store i64 %48, ptr %6, align 8, !tbaa !10
  %49 = getelementptr inbounds i8, ptr %46, i64 %47
  store i8 47, ptr %49, align 1, !tbaa !9
  br label %50

50:                                               ; preds = %45, %28
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load i64, ptr %6, align 8, !tbaa !10
  %53 = getelementptr inbounds i8, ptr %51, i64 %52
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !12
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %53, ptr align 1 %54, i64 %57, i1 false)
  %58 = load i32, ptr %8, align 4, !tbaa !12
  %59 = sext i32 %58 to i64
  %60 = load i64, ptr %6, align 8, !tbaa !10
  %61 = add i64 %60, %59
  store i64 %61, ptr %6, align 8, !tbaa !10
  %62 = load i64, ptr %6, align 8, !tbaa !10
  %63 = call noundef i32 @_ZN7android7String812unlockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %10, i64 noundef %62)
  store ptr %10, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %64

64:                                               ; preds = %50, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %67

65:                                               ; preds = %2
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN7android7String811setPathNameEPKc(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef %66)
  store ptr %10, ptr %3, align 8
  br label %67

67:                                               ; preds = %65, %64, %21
  %68 = load ptr, ptr %3, align 8
  ret ptr %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


; 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN7android7String810appendPathEPKc(ptr noundef nonnull returned align 8 dereferenceable(8) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  switch i8 %3, label %4 [
    i8 47, label %22
    i8 0, label %23
  ]

4:                                                ; preds = %2
  %5 = tail call noundef i64 @_ZNK7android7String86lengthEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  tail call void @_ZN7android7String811setPathNameEPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %1)
  br label %23

8:                                                ; preds = %4
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %10 = add i64 %5, 1
  %sext = shl i64 %9, 32
  %11 = ashr exact i64 %sext, 32
  %12 = add i64 %11, %10
  %13 = tail call noundef ptr @_ZN7android7String810lockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %12)
  %14 = getelementptr i8, ptr %13, i64 %5
  %15 = getelementptr i8, ptr %14, i64 -1
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %.not22 = icmp eq i8 %16, 47
  br i1 %.not22, label %._crit_edge, label %17

._crit_edge:                                      ; preds = %8
  %.pre = add i64 %5, %11
  br label %18

17:                                               ; preds = %8
  store i8 47, ptr %14, align 1, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge, %17
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %12, %17 ]
  %.020 = phi i64 [ %5, %._crit_edge ], [ %10, %17 ]
  %19 = getelementptr inbounds i8, ptr %13, i64 %.020
  %sext23 = add i64 %sext, 4294967296
  %20 = ashr exact i64 %sext23, 32
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %19, ptr nonnull align 1 %1, i64 %20, i1 false)
  %21 = tail call noundef i32 @_ZN7android7String812unlockBufferEm(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 noundef %.pre-phi)
  br label %23

22:                                               ; preds = %2
  tail call void @_ZN7android7String811setPathNameEPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %1)
  br label %23

23:                                               ; preds = %7, %18, %2, %22
  ret ptr %0
}

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass