; LLVM IR from TobiasKozel/VAE :: external/tracy/common/TracySocket.ll (ZN5tracy6Socket12RecvBufferedEPvii)

; 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.tracy::Socket" = type <{ ptr, ptr, %"struct.std::atomic", i32, ptr, ptr, i32, [4 x i8] }>
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i32 }

; 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 uwtable
define dso_local noundef i32 @_ZN5tracy6Socket12RecvBufferedEPvii(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp sle i32 %13, %15
  br i1 %16, label %17, label %33

17:                                               ; preds = %4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %18, ptr align 1 %20, i64 %22, i1 false)
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = sext i32 %23 to i64
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  store ptr %27, ptr %24, align 8, !tbaa !15
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = sub nsw i32 %30, %28
  store i32 %31, ptr %29, align 4, !tbaa !11
  %32 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %32, ptr %5, align 4
  br label %96

33:                                               ; preds = %4
  %34 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %48

37:                                               ; preds = %33
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = sext i32 %42 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %38, ptr align 1 %40, i64 %43, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %44 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !11
  store i32 %45, ptr %10, align 4, !tbaa !9
  %46 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  store i32 0, ptr %46, align 4, !tbaa !11
  %47 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %47, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %96

48:                                               ; preds = %33
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp sge i32 %49, 131072
  br i1 %50, label %51, label %56

51:                                               ; preds = %48
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = call noundef i32 @_ZN5tracy6Socket4RecvEPvii(ptr noundef nonnull align 8 dereferenceable(44) %12, ptr noundef %52, i32 noundef %53, i32 noundef %54)
  store i32 %55, ptr %5, align 4
  br label %96

56:                                               ; preds = %48
  %57 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = call noundef i32 @_ZN5tracy6Socket4RecvEPvii(ptr noundef nonnull align 8 dereferenceable(44) %12, ptr noundef %58, i32 noundef 131072, i32 noundef %59)
  %61 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  store i32 %60, ptr %61, align 4, !tbaa !11
  %62 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = icmp sle i32 %63, 0
  br i1 %64, label %65, label %68

65:                                               ; preds = %56
  %66 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %67 = load i32, ptr %66, align 4, !tbaa !11
  store i32 %67, ptr %5, align 4
  br label %96

68:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %71 = load i32, ptr %70, align 4, !tbaa !11
  %72 = icmp slt i32 %69, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %68
  %74 = load i32, ptr %8, align 4, !tbaa !9
  br label %78

75:                                               ; preds = %68
  %76 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %77 = load i32, ptr %76, align 4, !tbaa !11
  br label %78

78:                                               ; preds = %75, %73
  %79 = phi i32 [ %74, %73 ], [ %77, %75 ]
  store i32 %79, ptr %11, align 4, !tbaa !9
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !16
  %83 = load i32, ptr %11, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %80, ptr align 1 %82, i64 %84, i1 false)
  %85 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !16
  %87 = load i32, ptr %11, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i8, ptr %86, i64 %88
  %90 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 1
  store ptr %89, ptr %90, align 8, !tbaa !15
  %91 = load i32, ptr %11, align 4, !tbaa !9
  %92 = getelementptr inbounds %"class.tracy::Socket", ptr %12, i32 0, i32 3
  %93 = load i32, ptr %92, align 4, !tbaa !11
  %94 = sub nsw i32 %93, %91
  store i32 %94, ptr %92, align 4, !tbaa !11
  %95 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %95, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %96

96:                                               ; preds = %78, %65, %51, %37, %17
  %97 = load i32, ptr %5, align 4
  ret i32 %97
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!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, !10, i64 20}
!12 = !{!"_ZTSN5tracy6SocketE", !6, i64 0, !6, i64 8, !13, i64 16, !10, i64 20, !6, i64 24, !6, i64 32, !10, i64 40}
!13 = !{!"_ZTSSt6atomicIiE", !14, i64 0}
!14 = !{!"_ZTSSt13__atomic_baseIiE", !10, i64 0}
!15 = !{!12, !6, i64 8}
!16 = !{!12, !6, 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 uwtable
define dso_local noundef i32 @_ZN5tracy6Socket12RecvBufferedEPvii(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp slt i32 %6, %2
  br i1 %.not, label %15, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = sext i32 %2 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 %9, i64 %10, i1 false)
  %11 = load ptr, ptr %8, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %11, i64 %10
  store ptr %12, ptr %8, align 8, !tbaa !13
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sub nsw i32 %13, %2
  store i32 %14, ptr %5, align 4, !tbaa !5
  br label %38

15:                                               ; preds = %4
  %16 = icmp sgt i32 %6, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = zext nneg i32 %6 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 %19, i64 %20, i1 false)
  %21 = load i32, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %38

22:                                               ; preds = %15
  %23 = icmp sgt i32 %2, 131071
  br i1 %23, label %24, label %26

24:                                               ; preds = %22
  %25 = tail call noundef i32 @_ZN5tracy6Socket4RecvEPvii(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3)
  br label %38

26:                                               ; preds = %22
  %27 = load ptr, ptr %0, align 8, !tbaa !14
  %28 = tail call noundef i32 @_ZN5tracy6Socket4RecvEPvii(ptr noundef nonnull align 8 dereferenceable(44) %0, ptr noundef %27, i32 noundef 131072, i32 noundef %3)
  store i32 %28, ptr %5, align 4, !tbaa !5
  %29 = icmp slt i32 %28, 1
  br i1 %29, label %38, label %30

30:                                               ; preds = %26
  %. = tail call i32 @llvm.smin.i32(i32 %28, i32 %2)
  %31 = load ptr, ptr %0, align 8, !tbaa !14
  %32 = sext i32 %. to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 %31, i64 %32, i1 false)
  %33 = load ptr, ptr %0, align 8, !tbaa !14
  %34 = getelementptr inbounds i8, ptr %33, i64 %32
  %35 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %34, ptr %35, align 8, !tbaa !13
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sub nsw i32 %36, %.
  store i32 %37, ptr %5, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %26, %30, %24, %17, %7
  %.0 = phi i32 [ %2, %7 ], [ %21, %17 ], [ %25, %24 ], [ %., %30 ], [ %28, %26 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN5tracy6Socket4RecvEPvii(ptr noundef nonnull align 8 dereferenceable(44), ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !12, i64 20}
!6 = !{!"_ZTSN5tracy6SocketE", !7, i64 0, !7, i64 8, !10, i64 16, !12, i64 20, !7, i64 24, !7, i64 32, !12, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6atomicIiE", !11, i64 0}
!11 = !{!"_ZTSSt13__atomic_baseIiE", !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 0}


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