; LLVM IR from TobiasKozel/VAE :: external/tracy/libbacktrace (alloc)

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

%"struct.tracy::backtrace_vector" = type { ptr, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5tracy21backtrace_vector_growEPNS_15backtrace_stateEmPFvPvPKciES2_PNS_16backtrace_vectorE(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %17, i32 0, i32 2
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp ugt i64 %16, %19
  br i1 %20, label %21, label %86

21:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = mul i64 32, %27
  store i64 %28, ptr %13, align 8, !tbaa !9
  br label %45

29:                                               ; preds = %21
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !13
  %33 = icmp uge i64 %32, 4096
  br i1 %33, label %34, label %39

34:                                               ; preds = %29
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = add i64 %37, 4096
  store i64 %38, ptr %13, align 8, !tbaa !9
  br label %44

39:                                               ; preds = %29
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !13
  %43 = mul i64 2, %42
  store i64 %43, ptr %13, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %39, %34
  br label %45

45:                                               ; preds = %44, %26
  %46 = load i64, ptr %13, align 8, !tbaa !9
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !13
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = add i64 %49, %50
  %52 = icmp ult i64 %46, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %45
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !13
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = add i64 %56, %57
  store i64 %58, ptr %13, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %53, %45
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load i64, ptr %13, align 8, !tbaa !9
  %64 = call noundef ptr @_ZN5tracyL13tracy_reallocEPvm(ptr noundef %62, i64 noundef %63)
  store ptr %64, ptr %14, align 8, !tbaa !5
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = icmp eq ptr %65, null
  br i1 %66, label %67, label %72

67:                                               ; preds = %59
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = call ptr @__errno_location() #5
  %71 = load i32, ptr %70, align 4, !tbaa !15
  call void %68(ptr noundef %69, ptr noundef @.str.1, i32 noundef %71)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %83

72:                                               ; preds = %59
  %73 = load ptr, ptr %14, align 8, !tbaa !5
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %74, i32 0, i32 0
  store ptr %73, ptr %75, align 8, !tbaa !14
  %76 = load i64, ptr %13, align 8, !tbaa !9
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %77, i32 0, i32 1
  %79 = load i64, ptr %78, align 8, !tbaa !13
  %80 = sub i64 %76, %79
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %81, i32 0, i32 2
  store i64 %80, ptr %82, align 8, !tbaa !11
  store i32 0, ptr %15, align 4
  br label %83

83:                                               ; preds = %72, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %84 = load i32, ptr %15, align 4
  switch i32 %84, label %105 [
    i32 0, label %85
  ]

85:                                               ; preds = %83
  br label %86

86:                                               ; preds = %85, %5
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !14
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %90, i32 0, i32 1
  %92 = load i64, ptr %91, align 8, !tbaa !13
  %93 = getelementptr inbounds i8, ptr %89, i64 %92
  store ptr %93, ptr %12, align 8, !tbaa !5
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  %96 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %95, i32 0, i32 1
  %97 = load i64, ptr %96, align 8, !tbaa !13
  %98 = add i64 %97, %94
  store i64 %98, ptr %96, align 8, !tbaa !13
  %99 = load i64, ptr %8, align 8, !tbaa !9
  %100 = load ptr, ptr %11, align 8, !tbaa !5
  %101 = getelementptr inbounds %"struct.tracy::backtrace_vector", ptr %100, i32 0, i32 2
  %102 = load i64, ptr %101, align 8, !tbaa !11
  %103 = sub i64 %102, %99
  store i64 %103, ptr %101, align 8, !tbaa !11
  %104 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %104, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %105

105:                                              ; preds = %86, %83
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %106 = load ptr, ptr %6, align 8
  ret ptr %106
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN5tracyL13tracy_reallocEPvm(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(none) "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 }
attributes #5 = { nounwind 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 = !{!"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, !10, i64 16}
!12 = !{!"_ZTSN5tracy16backtrace_vectorE", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN5tracy21backtrace_vector_growEPNS_15backtrace_stateEmPFvPvPKciES2_PNS_16backtrace_vectorE(ptr nocapture noundef readnone %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3, ptr nocapture noundef %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %4, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp ult i64 %7, %1
  br i1 %8, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %5
  %.pre = load ptr, ptr %4, align 8, !tbaa !11
  %.phi.trans.insert = getelementptr inbounds i8, ptr %4, i64 8
  %.pre37 = load i64, ptr %.phi.trans.insert, align 8, !tbaa !12
  br label %30

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = shl i64 %1, 5
  br label %21

15:                                               ; preds = %9
  %16 = icmp ugt i64 %11, 4095
  br i1 %16, label %17, label %19

17:                                               ; preds = %15
  %18 = add i64 %11, 4096
  br label %21

19:                                               ; preds = %15
  %20 = shl nuw nsw i64 %11, 1
  br label %21

21:                                               ; preds = %17, %19, %13
  %.031 = phi i64 [ %14, %13 ], [ %18, %17 ], [ %20, %19 ]
  %22 = add i64 %11, %1
  %spec.select = tail call i64 @llvm.umax.i64(i64 %.031, i64 %22)
  %23 = load ptr, ptr %4, align 8, !tbaa !11
  %24 = tail call noundef ptr @_ZN5tracyL13tracy_reallocEPvm(ptr noundef %23, i64 noundef %spec.select)
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %.thread, label %27

.thread:                                          ; preds = %21
  %25 = tail call ptr @__errno_location() #4
  %26 = load i32, ptr %25, align 4, !tbaa !13
  tail call void %2(ptr noundef %3, ptr noundef nonnull @.str.1, i32 noundef %26)
  br label %38

27:                                               ; preds = %21
  store ptr %24, ptr %4, align 8, !tbaa !11
  %28 = load i64, ptr %10, align 8, !tbaa !12
  %29 = sub i64 %spec.select, %28
  br label %30

30:                                               ; preds = %._crit_edge, %27
  %31 = phi i64 [ %7, %._crit_edge ], [ %29, %27 ]
  %32 = phi i64 [ %.pre37, %._crit_edge ], [ %28, %27 ]
  %33 = phi ptr [ %.pre, %._crit_edge ], [ %24, %27 ]
  %34 = getelementptr inbounds i8, ptr %4, i64 8
  %35 = getelementptr inbounds i8, ptr %33, i64 %32
  %36 = add i64 %32, %1
  store i64 %36, ptr %34, align 8, !tbaa !12
  %37 = sub i64 %31, %1
  store i64 %37, ptr %6, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %.thread, %30
  %.1 = phi ptr [ %35, %30 ], [ null, %.thread ]
  ret ptr %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN5tracyL13tracy_reallocEPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #3

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind 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, !10, i64 16}
!6 = !{!"_ZTSN5tracy16backtrace_vectorE", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !8, i64 0}


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