; LLVM IR from turi-code/SFrame :: cxxtest/cxxtest/ValueTraits.ll (ZN7CxxTest13bytesToStringEPKhjjPc)

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

@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7CxxTest9byteToHexEh(i8 noundef zeroext) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef, ptr noundef) #0

; 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: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN7CxxTest13bytesToStringEPKhjjPc(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp ugt i32 %11, %12
  %14 = zext i1 %13 to i8
  store i8 %14, ptr %9, align 1, !tbaa !11
  %15 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %16 = trunc i8 %15 to i1
  br i1 %16, label %17, label %19

17:                                               ; preds = %4
  %18 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %18, ptr %6, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %17, %4
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %20, ptr noundef @.str.9)
  store ptr %21, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %34, %19
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp ult i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %39

27:                                               ; preds = %22
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !15
  %31 = call noundef ptr @_ZN7CxxTest9byteToHexEh(i8 noundef zeroext %30)
  %32 = call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %28, ptr noundef %31)
  %33 = call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %32, ptr noundef @.str.10)
  store ptr %33, ptr %8, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %27
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = add i32 %35, 1
  store i32 %36, ptr %10, align 4, !tbaa !9
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %5, align 8, !tbaa !5
  br label %22, !llvm.loop !16

39:                                               ; preds = %26
  %40 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %41 = trunc i8 %40 to i1
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %43, ptr noundef @.str.11)
  store ptr %44, ptr %8, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %42, %39
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %46, ptr noundef @.str.12)
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  ret ptr %47
}

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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7CxxTest9byteToHexEh(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN7CxxTest13bytesToStringEPKhjjPc(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp ugt i32 %1, %2
  %spec.select = tail call i32 @llvm.umin.i32(i32 %1, i32 %2)
  %6 = tail call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %3, ptr noundef nonnull @.str.9)
  %.not = icmp eq i32 %spec.select, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.014.lcssa = phi ptr [ %6, %4 ], [ %10, %.lr.ph ]
  br i1 %5, label %13, label %15

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.020 = phi i32 [ %11, %.lr.ph ], [ 0, %4 ]
  %.01319 = phi ptr [ %12, %.lr.ph ], [ %0, %4 ]
  %.01418 = phi ptr [ %10, %.lr.ph ], [ %6, %4 ]
  %7 = load i8, ptr %.01319, align 1, !tbaa !5
  %8 = tail call noundef ptr @_ZN7CxxTest9byteToHexEh(i8 noundef zeroext %7)
  %9 = tail call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %.01418, ptr noundef %8)
  %10 = tail call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %9, ptr noundef nonnull @.str.10)
  %11 = add nuw i32 %.020, 1
  %12 = getelementptr inbounds i8, ptr %.01319, i64 1
  %exitcond.not = icmp eq i32 %11, %spec.select
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

13:                                               ; preds = %._crit_edge
  %14 = tail call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %.014.lcssa, ptr noundef nonnull @.str.11)
  br label %15

15:                                               ; preds = %13, %._crit_edge
  %.1 = phi ptr [ %14, %13 ], [ %.014.lcssa, %._crit_edge ]
  %16 = tail call noundef ptr @_ZN7CxxTest10copyStringEPcPKc(ptr noundef %.1, ptr noundef nonnull @.str.12)
  ret ptr %16
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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