; LLVM IR from microsoft/ntttcp-for-linux :: src (tcpstream)

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

; 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: nounwind uwtable
define dso_local i32 @n_send(i32 noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %11 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %11, ptr %9, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %41, %3
  %13 = load i64, ptr %9, align 8, !tbaa !11
  %14 = icmp ugt i64 %13, 0
  br i1 %14, label %15, label %48

15:                                               ; preds = %12
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = load i64, ptr %9, align 8, !tbaa !11
  %19 = call i64 @send(i32 noundef %16, ptr noundef %17, i64 noundef %18, i32 noundef 0)
  store i64 %19, ptr %8, align 8, !tbaa !11
  %20 = load i64, ptr %8, align 8, !tbaa !11
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %36

22:                                               ; preds = %15
  %23 = call ptr @__errno_location() #5
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 4
  br i1 %25, label %30, label %26

26:                                               ; preds = %22
  %27 = call ptr @__errno_location() #5
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 11
  br i1 %29, label %30, label %35

30:                                               ; preds = %26, %22
  %31 = load i64, ptr %7, align 8, !tbaa !11
  %32 = load i64, ptr %9, align 8, !tbaa !11
  %33 = sub i64 %31, %32
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

35:                                               ; preds = %26
  store i32 -1109, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

36:                                               ; preds = %15
  %37 = load i64, ptr %8, align 8, !tbaa !11
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i32 -1109, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

40:                                               ; preds = %36
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %8, align 8, !tbaa !11
  %43 = load i64, ptr %9, align 8, !tbaa !11
  %44 = sub i64 %43, %42
  store i64 %44, ptr %9, align 8, !tbaa !11
  %45 = load i64, ptr %8, align 8, !tbaa !11
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i64 %45
  store ptr %47, ptr %6, align 8, !tbaa !9
  br label %12, !llvm.loop !13

48:                                               ; preds = %12
  %49 = load i64, ptr %7, align 8, !tbaa !11
  %50 = trunc i64 %49 to i32
  store i32 %50, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

51:                                               ; preds = %48, %39, %35, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %52 = load i32, ptr %4, align 4
  ret i32 %52
}

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 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 = { 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @n_send(i32 noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %.not20 = icmp eq i64 %2, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %14
  %.022 = phi i64 [ %15, %14 ], [ %2, %3 ]
  %.01521 = phi ptr [ %16, %14 ], [ %1, %3 ]
  %4 = tail call i64 @send(i32 noundef %0, ptr noundef %.01521, i64 noundef %.022, i32 noundef 0) #3
  %5 = icmp slt i64 %4, 0
  br i1 %5, label %6, label %12

6:                                                ; preds = %.lr.ph
  %7 = tail call ptr @__errno_location() #4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  switch i32 %8, label %.loopexit [
    i32 4, label %9
    i32 11, label %9
  ]

9:                                                ; preds = %6, %6
  %10 = sub i64 %2, %.022
  %11 = trunc i64 %10 to i32
  br label %.loopexit

12:                                               ; preds = %.lr.ph
  %13 = icmp eq i64 %4, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %12
  %15 = sub i64 %.022, %4
  %16 = getelementptr inbounds i8, ptr %.01521, i64 %4
  %.not = icmp eq i64 %15, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %14, %3
  %17 = trunc i64 %2 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %12, %6, %._crit_edge, %9
  %.014 = phi i32 [ %11, %9 ], [ %17, %._crit_edge ], [ -1109, %6 ], [ -1109, %12 ]
  ret i32 %.014
}

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

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 = { 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 = { "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 }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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