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

; 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.timeval = type { i64, i64 }
%struct.ntttcp_test_endpoint = type { i32, ptr, i32, i32, %struct.timeval, %struct.timeval, i32, i32, i8, ptr, ptr, ptr, i8, ptr, i32, [8 x i32] }
%struct.ntttcp_test = type { i8, i8, i8, i8, i8, i8, i8, ptr, i32, i32, ptr, i32, i32, i8, i32, i32, i32, i32, i64, i64, i64, i64, i32, i32, i32, i8, ptr, ptr, i8, ptr, i8, ptr, i8, ptr, i8, i8 }
%struct.ntttcp_stream_client = type { ptr, i32, i32, ptr, i32, i32, i32, i64, i64, i64, i8, i8, i8, i8, i8, i32, i32, i64 }

; Function Attrs: nounwind uwtable
define dso_local void @check_bandwidth_limit(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.timeval, align 8
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = icmp eq i32 %9, 2
  br i1 %10, label %18, label %11

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = getelementptr inbounds %struct.ntttcp_test, ptr %14, i32 0, i32 20
  %16 = load i64, ptr %15, align 8, !tbaa !16
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %11, %1
  br label %78

19:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !18
  %20 = call i32 @gettimeofday(ptr noundef %3, ptr noundef null) #4
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %21, i32 0, i32 4
  %23 = call double @get_time_diff(ptr noundef %3, ptr noundef %22)
  store double %23, ptr %4, align 8, !tbaa !19
  store i32 0, ptr %6, align 4, !tbaa !18
  br label %24

24:                                               ; preds = %74, %19
  %25 = load i32, ptr %6, align 4, !tbaa !18
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %26, i32 0, i32 7
  %28 = load i32, ptr %27, align 4, !tbaa !21
  %29 = icmp ult i32 %25, %28
  br i1 %29, label %30, label %77

30:                                               ; preds = %24
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %31, i32 0, i32 9
  %33 = load ptr, ptr %32, align 8, !tbaa !22
  %34 = load i32, ptr %6, align 4, !tbaa !18
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ntttcp_stream_client, ptr %37, i32 0, i32 17
  %39 = load i64, ptr %38, align 8, !tbaa !23
  %40 = uitofp i64 %39 to double
  %41 = load double, ptr %4, align 8, !tbaa !19
  %42 = fdiv double %40, %41
  %43 = fptoui double %42 to i64
  store i64 %43, ptr %5, align 8, !tbaa !25
  %44 = load i64, ptr %5, align 8, !tbaa !25
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %45, i32 0, i32 9
  %47 = load ptr, ptr %46, align 8, !tbaa !22
  %48 = load i32, ptr %6, align 4, !tbaa !18
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds ptr, ptr %47, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ntttcp_stream_client, ptr %51, i32 0, i32 8
  %53 = load i64, ptr %52, align 8, !tbaa !26
  %54 = icmp ugt i64 %44, %53
  br i1 %54, label %55, label %64

55:                                               ; preds = %30
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %56, i32 0, i32 9
  %58 = load ptr, ptr %57, align 8, !tbaa !22
  %59 = load i32, ptr %6, align 4, !tbaa !18
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds ptr, ptr %58, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.ntttcp_stream_client, ptr %62, i32 0, i32 10
  store i8 1, ptr %63, align 8, !tbaa !27
  br label %73

64:                                               ; preds = %30
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ntttcp_test_endpoint, ptr %65, i32 0, i32 9
  %67 = load ptr, ptr %66, align 8, !tbaa !22
  %68 = load i32, ptr %6, align 4, !tbaa !18
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds ptr, ptr %67, i64 %69
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ntttcp_stream_client, ptr %71, i32 0, i32 10
  store i8 0, ptr %72, align 8, !tbaa !27
  br label %73

73:                                               ; preds = %64, %55
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %6, align 4, !tbaa !18
  %76 = add i32 %75, 1
  store i32 %76, ptr %6, align 4, !tbaa !18
  br label %24, !llvm.loop !28

77:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  br label %78

78:                                               ; preds = %77, %18
  ret void
}

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

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #2

declare double @get_time_diff(ptr noundef, ptr noundef) #3

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

attributes #0 = { 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 "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 }

!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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"ntttcp_test_endpoint", !11, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !12, i64 24, !12, i64 40, !11, i64 56, !11, i64 60, !14, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !14, i64 96, !6, i64 104, !11, i64 112, !7, i64 116}
!11 = !{!"int", !7, i64 0}
!12 = !{!"timeval", !13, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!17, !13, i64 80}
!17 = !{!"ntttcp_test", !14, i64 0, !14, i64 1, !14, i64 2, !14, i64 3, !14, i64 4, !14, i64 5, !14, i64 6, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !11, i64 32, !11, i64 36, !14, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !11, i64 96, !11, i64 100, !11, i64 104, !14, i64 108, !6, i64 112, !6, i64 120, !14, i64 128, !6, i64 136, !14, i64 144, !6, i64 152, !14, i64 160, !6, i64 168, !14, i64 176, !14, i64 177}
!18 = !{!11, !11, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !7, i64 0}
!21 = !{!10, !11, i64 60}
!22 = !{!10, !6, i64 72}
!23 = !{!24, !13, i64 80}
!24 = !{!"ntttcp_stream_client", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !14, i64 64, !14, i64 65, !14, i64 66, !14, i64 67, !14, i64 68, !11, i64 72, !11, i64 76, !13, i64 80}
!25 = !{!13, !13, i64 0}
!26 = !{!24, !13, i64 48}
!27 = !{!24, !14, i64 64}
!28 = distinct !{!28, !29}
!29 = !{!"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"

%struct.timeval = type { i64, i64 }

; Function Attrs: nounwind uwtable
define dso_local void @check_bandwidth_limit(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.timeval, align 8
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %54, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %7, i64 80
  %9 = load i64, ptr %8, align 8, !tbaa !15
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %54, label %11

11:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  %12 = call i32 @gettimeofday(ptr noundef nonnull %2, ptr noundef null) #4
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = call double @get_time_diff(ptr noundef nonnull %2, ptr noundef nonnull %13) #4
  %15 = getelementptr inbounds i8, ptr %0, i64 60
  %16 = load i32, ptr %15, align 4, !tbaa !17
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %wide.trip.count = zext i32 %16 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %19 = icmp eq i32 %16, 1
  br i1 %19, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %20

20:                                               ; preds = %20, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %20 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %20 ]
  %21 = getelementptr inbounds ptr, ptr %18, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %22, i64 80
  %24 = load i64, ptr %23, align 8, !tbaa !20
  %25 = uitofp i64 %24 to double
  %26 = fdiv double %25, %14
  %27 = fptoui double %26 to i64
  %28 = getelementptr inbounds i8, ptr %22, i64 48
  %29 = load i64, ptr %28, align 8, !tbaa !22
  %30 = icmp ult i64 %29, %27
  %spec.select = zext i1 %30 to i8
  %31 = getelementptr inbounds i8, ptr %22, i64 64
  store i8 %spec.select, ptr %31, align 8
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %32 = getelementptr inbounds ptr, ptr %18, i64 %indvars.iv.next
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds i8, ptr %33, i64 80
  %35 = load i64, ptr %34, align 8, !tbaa !20
  %36 = uitofp i64 %35 to double
  %37 = fdiv double %36, %14
  %38 = fptoui double %37 to i64
  %39 = getelementptr inbounds i8, ptr %33, i64 48
  %40 = load i64, ptr %39, align 8, !tbaa !22
  %41 = icmp ult i64 %40, %38
  %spec.select.1 = zext i1 %41 to i8
  %42 = getelementptr inbounds i8, ptr %33, i64 64
  store i8 %spec.select.1, ptr %42, align 8
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %20, !llvm.loop !23

._crit_edge.loopexit.unr-lcssa:                   ; preds = %20, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %20 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %43 = getelementptr inbounds ptr, ptr %18, i64 %indvars.iv.unr
  %44 = load ptr, ptr %43, align 8, !tbaa !19
  %45 = getelementptr inbounds i8, ptr %44, i64 80
  %46 = load i64, ptr %45, align 8, !tbaa !20
  %47 = uitofp i64 %46 to double
  %48 = fdiv double %47, %14
  %49 = fptoui double %48 to i64
  %50 = getelementptr inbounds i8, ptr %44, i64 48
  %51 = load i64, ptr %50, align 8, !tbaa !22
  %52 = icmp ult i64 %51, %49
  %spec.select.epil = zext i1 %52 to i8
  %53 = getelementptr inbounds i8, ptr %44, i64 64
  store i8 %spec.select.epil, ptr %53, align 8
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  br label %54

54:                                               ; preds = %1, %5, %._crit_edge
  ret void
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

declare double @get_time_diff(ptr noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 }

!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, !7, i64 0}
!6 = !{!"ntttcp_test_endpoint", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !11, i64 24, !11, i64 40, !7, i64 56, !7, i64 60, !13, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !13, i64 96, !10, i64 104, !7, i64 112, !8, i64 116}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"timeval", !12, i64 0, !12, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!16, !12, i64 80}
!16 = !{!"ntttcp_test", !13, i64 0, !13, i64 1, !13, i64 2, !13, i64 3, !13, i64 4, !13, i64 5, !13, i64 6, !10, i64 8, !7, i64 16, !7, i64 20, !10, i64 24, !7, i64 32, !7, i64 36, !13, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !7, i64 96, !7, i64 100, !7, i64 104, !13, i64 108, !10, i64 112, !10, i64 120, !13, i64 128, !10, i64 136, !13, i64 144, !10, i64 152, !13, i64 160, !10, i64 168, !13, i64 176, !13, i64 177}
!17 = !{!6, !7, i64 60}
!18 = !{!6, !10, i64 72}
!19 = !{!10, !10, i64 0}
!20 = !{!21, !12, i64 80}
!21 = !{!"ntttcp_stream_client", !10, i64 0, !7, i64 8, !7, i64 12, !10, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !13, i64 64, !13, i64 65, !13, i64 66, !13, i64 67, !13, i64 68, !7, i64 72, !7, i64 76, !12, i64 80}
!22 = !{!21, !12, i64 48}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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