; LLVM IR from gulrak/filesystem :: test/filesystem_test.ll (ZN5Catch4trimENS_9StringRefE)

; 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.Catch::StringRef" = type { ptr, i64 }
%class.anon.266 = type { i8 }

; 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 nounwind uwtable
declare dso_local noundef i64 @_ZNK5Catch9StringRef4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local { ptr, i64 } @_ZN5Catch4trimENS_9StringRefE(ptr %0, i64 %1) #2 {
  %3 = alloca %"class.Catch::StringRef", align 8
  %4 = alloca %"class.Catch::StringRef", align 8
  %5 = alloca %class.anon.266, align 1
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 0
  store ptr %0, ptr %8, align 8
  %9 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 1
  store i64 %1, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %20, %2
  %11 = load i64, ptr %6, align 8, !tbaa !5
  %12 = call noundef i64 @_ZNK5Catch9StringRef4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  %13 = icmp ult i64 %11, %12
  br i1 %13, label %14, label %18

14:                                               ; preds = %10
  %15 = load i64, ptr %6, align 8, !tbaa !5
  %16 = call noundef signext i8 @_ZNK5Catch9StringRefixEm(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef %15) #4
  %17 = call noundef zeroext i1 @"_ZZN5Catch4trimENS_9StringRefEENK3$_0clEc"(ptr noundef nonnull align 1 dereferenceable(1) %5, i8 noundef signext %16)
  br label %18

18:                                               ; preds = %14, %10
  %19 = phi i1 [ false, %10 ], [ %17, %14 ]
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = add i64 %21, 1
  store i64 %22, ptr %6, align 8, !tbaa !5
  br label %10, !llvm.loop !9

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %24 = call noundef i64 @_ZNK5Catch9StringRef4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  store i64 %24, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %36, %23
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !5
  %28 = icmp ugt i64 %26, %27
  br i1 %28, label %29, label %34

29:                                               ; preds = %25
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = sub i64 %30, 1
  %32 = call noundef signext i8 @_ZNK5Catch9StringRefixEm(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef %31) #4
  %33 = call noundef zeroext i1 @"_ZZN5Catch4trimENS_9StringRefEENK3$_0clEc"(ptr noundef nonnull align 1 dereferenceable(1) %5, i8 noundef signext %32)
  br label %34

34:                                               ; preds = %29, %25
  %35 = phi i1 [ false, %25 ], [ %33, %29 ]
  br i1 %35, label %36, label %39

36:                                               ; preds = %34
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = add i64 %37, -1
  store i64 %38, ptr %7, align 8, !tbaa !5
  br label %25, !llvm.loop !11

39:                                               ; preds = %34
  %40 = load i64, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !5
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = sub i64 %41, %42
  %44 = call { ptr, i64 } @_ZNK5Catch9StringRef6substrEmm(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef %40, i64 noundef %43) #4
  %45 = getelementptr inbounds { ptr, i64 }, ptr %3, i32 0, i32 0
  %46 = extractvalue { ptr, i64 } %44, 0
  store ptr %46, ptr %45, align 8
  %47 = getelementptr inbounds { ptr, i64 }, ptr %3, i32 0, i32 1
  %48 = extractvalue { ptr, i64 } %44, 1
  store i64 %48, ptr %47, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  %49 = load { ptr, i64 }, ptr %3, align 8
  ret { ptr, i64 } %49
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZNK5Catch9StringRefixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @"_ZZN5Catch4trimENS_9StringRefEENK3$_0clEc"(ptr noundef nonnull align 1 dereferenceable(1), i8 noundef signext) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { ptr, i64 } @_ZNK5Catch9StringRef6substrEmm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i64 noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

%"class.Catch::StringRef" = type { ptr, i64 }
%class.anon.266 = type { i8 }

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local { ptr, i64 } @_ZN5Catch4trimENS_9StringRefE(ptr %0, i64 %1) local_unnamed_addr #1 {
  %3 = alloca %"class.Catch::StringRef", align 8
  %4 = alloca %class.anon.266, align 1
  store ptr %0, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 %1, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %6 = call noundef i64 @_ZNK5Catch9StringRef4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %9
  %.01213 = phi i64 [ %10, %9 ], [ 0, %2 ]
  %7 = call noundef signext i8 @_ZNK5Catch9StringRefixEm(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %.01213) #3
  %8 = call noundef zeroext i1 @"_ZZN5Catch4trimENS_9StringRefEENK3$_0clEc"(ptr noundef nonnull align 1 dereferenceable(1) %4, i8 noundef signext %7)
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %.lr.ph
  %10 = add nuw i64 %.01213, 1
  %11 = call noundef i64 @_ZNK5Catch9StringRef4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  %12 = icmp ult i64 %10, %11
  br i1 %12, label %.lr.ph, label %.critedge, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph, %9, %2
  %.012.lcssa = phi i64 [ 0, %2 ], [ %10, %9 ], [ %.01213, %.lr.ph ]
  %13 = call noundef i64 @_ZNK5Catch9StringRef4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  br label %14

14:                                               ; preds = %16, %.critedge
  %.0 = phi i64 [ %13, %.critedge ], [ %17, %16 ]
  %15 = icmp ugt i64 %.0, %.012.lcssa
  br i1 %15, label %16, label %.critedge2

16:                                               ; preds = %14
  %17 = add i64 %.0, -1
  %18 = call noundef signext i8 @_ZNK5Catch9StringRefixEm(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %17) #3
  %19 = call noundef zeroext i1 @"_ZZN5Catch4trimENS_9StringRefEENK3$_0clEc"(ptr noundef nonnull align 1 dereferenceable(1) %4, i8 noundef signext %18)
  br i1 %19, label %14, label %.critedge2, !llvm.loop !7

.critedge2:                                       ; preds = %14, %16
  %20 = sub i64 %.0, %.012.lcssa
  %21 = call { ptr, i64 } @_ZNK5Catch9StringRef6substrEmm(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %.012.lcssa, i64 noundef %20) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  ret { ptr, i64 } %21
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZNK5Catch9StringRefixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @"_ZZN5Catch4trimENS_9StringRefEENK3$_0clEc"(ptr noundef nonnull align 1 dereferenceable(1), i8 noundef signext) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { ptr, i64 } @_ZNK5Catch9StringRef6substrEmm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i64 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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