; LLVM IR from Razakhel/RaZ :: extern/tracy/client/TracyCallstack.ll (ZN5tracy13NormalizePathEPKc)

; 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.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN5tracyL12tracy_mallocEm(i64 noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

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

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

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

17:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  br label %135

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %19, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i64 @strlen(ptr noundef %21) #6
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  store ptr %23, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = ptrtoint ptr %24 to i64
  %27 = ptrtoint ptr %25 to i64
  %28 = sub i64 %26, %27
  %29 = add nsw i64 %28, 1
  %30 = call noundef ptr @_ZN5tracyL12tracy_mallocEm(i64 noundef %29)
  store ptr %30, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !10
  br label %31

31:                                               ; preds = %123, %121, %18
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = icmp ult ptr %32, %33
  br i1 %34, label %35, label %124

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %36, ptr %8, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %48, %35
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = icmp ult ptr %38, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %37
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp ne i32 %44, 47
  br label %46

46:                                               ; preds = %41, %37
  %47 = phi i1 [ false, %37 ], [ %45, %41 ]
  br i1 %47, label %48, label %51

48:                                               ; preds = %46
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %8, align 8, !tbaa !5
  br label %37, !llvm.loop !12

51:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = ptrtoint ptr %52 to i64
  %55 = ptrtoint ptr %53 to i64
  %56 = sub i64 %54, %55
  store i64 %56, ptr %9, align 8, !tbaa !10
  %57 = load i64, ptr %9, align 8, !tbaa !10
  switch i64 %57, label %102 [
    i64 2, label %58
    i64 1, label %90
    i64 0, label %99
  ]

58:                                               ; preds = %51
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = call i32 @memcmp(ptr noundef %59, ptr noundef @.str.1, i64 noundef 2) #6
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %89

62:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i64, ptr %7, align 8, !tbaa !10
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  %66 = getelementptr inbounds i8, ptr %65, i64 -1
  store ptr %66, ptr %10, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %78, %62
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = icmp ugt ptr %68, %69
  br i1 %70, label %71, label %76

71:                                               ; preds = %67
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = load i8, ptr %72, align 1, !tbaa !9
  %74 = sext i8 %73 to i32
  %75 = icmp ne i32 %74, 47
  br label %76

76:                                               ; preds = %71, %67
  %77 = phi i1 [ false, %67 ], [ %75, %71 ]
  br i1 %77, label %78, label %81

78:                                               ; preds = %76
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i32 -1
  store ptr %80, ptr %10, align 8, !tbaa !5
  br label %67, !llvm.loop !14

81:                                               ; preds = %76
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = ptrtoint ptr %82 to i64
  %85 = ptrtoint ptr %83 to i64
  %86 = sub i64 %84, %85
  store i64 %86, ptr %7, align 8, !tbaa !10
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 1
  store ptr %88, ptr %4, align 8, !tbaa !5
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %121

89:                                               ; preds = %58
  br label %102

90:                                               ; preds = %51
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = load i8, ptr %91, align 1, !tbaa !9
  %93 = sext i8 %92 to i32
  %94 = icmp eq i32 %93, 46
  br i1 %94, label %95, label %98

95:                                               ; preds = %90
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i64 1
  store ptr %97, ptr %4, align 8, !tbaa !5
  store i32 2, ptr %11, align 4
  br label %121, !llvm.loop !15

98:                                               ; preds = %90
  br label %102

99:                                               ; preds = %51
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = getelementptr inbounds i8, ptr %100, i64 1
  store ptr %101, ptr %4, align 8, !tbaa !5
  store i32 2, ptr %11, align 4
  br label %121, !llvm.loop !15

102:                                              ; preds = %98, %89, %51
  %103 = load i64, ptr %7, align 8, !tbaa !10
  %104 = icmp ne i64 %103, 1
  br i1 %104, label %105, label %110

105:                                              ; preds = %102
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = load i64, ptr %7, align 8, !tbaa !10
  %108 = add i64 %107, 1
  store i64 %108, ptr %7, align 8, !tbaa !10
  %109 = getelementptr inbounds i8, ptr %106, i64 %107
  store i8 47, ptr %109, align 1, !tbaa !9
  br label %110

110:                                              ; preds = %105, %102
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  %112 = load i64, ptr %7, align 8, !tbaa !10
  %113 = getelementptr inbounds i8, ptr %111, i64 %112
  %114 = load ptr, ptr %4, align 8, !tbaa !5
  %115 = load i64, ptr %9, align 8, !tbaa !10
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %113, ptr align 1 %114, i64 %115, i1 false)
  %116 = load i64, ptr %9, align 8, !tbaa !10
  %117 = load i64, ptr %7, align 8, !tbaa !10
  %118 = add i64 %117, %116
  store i64 %118, ptr %7, align 8, !tbaa !10
  %119 = load ptr, ptr %8, align 8, !tbaa !5
  %120 = getelementptr inbounds i8, ptr %119, i64 1
  store ptr %120, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %11, align 4
  br label %121

121:                                              ; preds = %110, %99, %95, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %122 = load i32, ptr %11, align 4
  switch i32 %122, label %137 [
    i32 0, label %123
    i32 2, label %31
  ]

123:                                              ; preds = %121
  br label %31, !llvm.loop !15

124:                                              ; preds = %31
  %125 = load i64, ptr %7, align 8, !tbaa !10
  %126 = icmp eq i64 %125, 0
  br i1 %126, label %127, label %129

127:                                              ; preds = %124
  %128 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %128, ptr align 1 @.str.2, i64 2, i1 false)
  br label %133

129:                                              ; preds = %124
  %130 = load ptr, ptr %6, align 8, !tbaa !5
  %131 = load i64, ptr %7, align 8, !tbaa !10
  %132 = getelementptr inbounds i8, ptr %130, i64 %131
  store i8 0, ptr %132, align 1, !tbaa !9
  br label %133

133:                                              ; preds = %129, %127
  %134 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %134, ptr %2, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %135

135:                                              ; preds = %133, %17
  %136 = load ptr, ptr %2, align 8
  ret ptr %136

137:                                              ; preds = %121
  unreachable
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #1

; 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) #4

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


; 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.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN5tracyL12tracy_mallocEm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN5tracy13NormalizePathEPKc(ptr noundef %0) local_unnamed_addr #2 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not = icmp eq i8 %2, 47
  br i1 %.not, label %3, label %44

3:                                                ; preds = %1
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %5 = getelementptr inbounds i8, ptr %0, i64 %4
  %6 = add nsw i64 %4, 1
  %7 = tail call noundef ptr @_ZN5tracyL12tracy_mallocEm(i64 noundef %6)
  %8 = icmp sgt i64 %4, 0
  br i1 %8, label %.preheader.lr.ph, label %._crit_edge.thread

.preheader.lr.ph:                                 ; preds = %3
  %9 = ptrtoint ptr %7 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %38
  %.04857 = phi i64 [ 0, %.preheader.lr.ph ], [ %.2, %38 ]
  %.04956 = phi ptr [ %0, %.preheader.lr.ph ], [ %.150, %38 ]
  br label %10

10:                                               ; preds = %.preheader, %12
  %.04755 = phi ptr [ %.04956, %.preheader ], [ %13, %12 ]
  %11 = load i8, ptr %.04755, align 1, !tbaa !5
  %.not52 = icmp eq i8 %11, 47
  br i1 %.not52, label %.critedge, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %.04755, i64 1
  %14 = icmp ult ptr %13, %5
  br i1 %14, label %10, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %12, %10
  %.047.lcssa = phi ptr [ %13, %12 ], [ %.04755, %10 ]
  %15 = ptrtoint ptr %.047.lcssa to i64
  %16 = ptrtoint ptr %.04956 to i64
  %17 = sub i64 %15, %16
  switch i64 %17, label %31 [
    i64 2, label %18
    i64 1, label %28
    i64 0, label %38
  ], !llvm.loop !10

18:                                               ; preds = %.critedge
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(2) %.04956, ptr noundef nonnull dereferenceable(2) @.str.1, i64 2)
  %19 = icmp eq i32 %bcmp, 0
  br i1 %19, label %20, label %31

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %7, i64 %.04857
  br label %22

22:                                               ; preds = %24, %20
  %.pn = phi ptr [ %21, %20 ], [ %.0, %24 ]
  %.0 = getelementptr inbounds i8, ptr %.pn, i64 -1
  %23 = icmp ugt ptr %.0, %7
  br i1 %23, label %24, label %.critedge2

24:                                               ; preds = %22
  %25 = load i8, ptr %.0, align 1, !tbaa !5
  %.not53 = icmp eq i8 %25, 47
  br i1 %.not53, label %.critedge2, label %22, !llvm.loop !11

.critedge2:                                       ; preds = %22, %24
  %26 = ptrtoint ptr %.0 to i64
  %27 = sub i64 %26, %9
  br label %38

28:                                               ; preds = %.critedge
  %29 = load i8, ptr %.04956, align 1, !tbaa !5
  %30 = icmp eq i8 %29, 46
  br i1 %30, label %38, label %31, !llvm.loop !10

31:                                               ; preds = %28, %18, %.critedge
  %.not54 = icmp eq i64 %.04857, 1
  br i1 %.not54, label %35, label %32

32:                                               ; preds = %31
  %33 = add i64 %.04857, 1
  %34 = getelementptr inbounds i8, ptr %7, i64 %.04857
  store i8 47, ptr %34, align 1, !tbaa !5
  br label %35

35:                                               ; preds = %32, %31
  %.1 = phi i64 [ %33, %32 ], [ 1, %31 ]
  %36 = getelementptr inbounds i8, ptr %7, i64 %.1
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr nonnull align 1 %.04956, i64 %17, i1 false)
  %37 = add i64 %.1, %17
  br label %38

38:                                               ; preds = %.critedge, %28, %35, %.critedge2
  %.2 = phi i64 [ %37, %35 ], [ %27, %.critedge2 ], [ %.04857, %28 ], [ %.04857, %.critedge ]
  %.150 = getelementptr inbounds i8, ptr %.047.lcssa, i64 1
  %39 = icmp ult ptr %.150, %5
  br i1 %39, label %.preheader, label %._crit_edge

._crit_edge:                                      ; preds = %38
  %40 = icmp eq i64 %.2, 0
  br i1 %40, label %._crit_edge.thread, label %42

._crit_edge.thread:                               ; preds = %3, %._crit_edge
  %41 = load i16, ptr @.str.2, align 1
  store i16 %41, ptr %7, align 1
  br label %44

42:                                               ; preds = %._crit_edge
  %43 = getelementptr inbounds i8, ptr %7, i64 %.2
  store i8 0, ptr %43, align 1, !tbaa !5
  br label %44

44:                                               ; preds = %._crit_edge.thread, %42, %1
  %.046 = phi ptr [ null, %1 ], [ %7, %42 ], [ %7, %._crit_edge.thread ]
  ret ptr %.046
}

; 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) #3

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #4

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


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