; LLVM IR from turi-code/SFrame :: oss_src/rpc/dc_tcp_comm.ll (ZN8graphlab7dc_impl11dc_tcp_comm10sendtosockEiPKcm)

; 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.6 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [13 x i8], align 1
@__func__._ZN8graphlab7dc_impl11dc_tcp_comm10sendtosockEiPKcm = external hidden unnamed_addr constant [11 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare noundef nonnull align 8 dereferenceable(896) ptr @_Z13global_loggerv() #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11file_logger13get_log_levelEv(ptr noundef nonnull align 8 dereferenceable(896)) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN19log_stream_dispatchILb1EE4execEiPKcS2_ib(i32 noundef, ptr noundef, ptr noundef, i32 noundef, i1 noundef zeroext) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPKc(ptr noundef nonnull align 8 dereferenceable(896), ptr noundef) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPFRSoS0_E(ptr noundef nonnull align 8 dereferenceable(896), ptr noundef) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #3

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsIPcEERS_T_(ptr noundef nonnull align 8 dereferenceable(896), ptr noundef) #5 align 2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #6

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8graphlab7dc_impl11dc_tcp_comm10sendtosockEiPKcm(ptr noundef nonnull align 8 dereferenceable(833) %0, i32 noundef %1, ptr noundef %2, i64 noundef %3) #5 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !11
  %13 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %14

14:                                               ; preds = %50, %4
  %15 = load i64, ptr %10, align 8, !tbaa !11
  %16 = load i64, ptr %9, align 8, !tbaa !11
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %51

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = load i64, ptr %10, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  %23 = load i64, ptr %9, align 8, !tbaa !11
  %24 = load i64, ptr %10, align 8, !tbaa !11
  %25 = sub i64 %23, %24
  %26 = call i64 @send(i32 noundef %19, ptr noundef %22, i64 noundef %25, i32 noundef 0)
  store i64 %26, ptr %11, align 8, !tbaa !11
  %27 = load i64, ptr %11, align 8, !tbaa !11
  %28 = icmp slt i64 %27, 0
  br i1 %28, label %29, label %44

29:                                               ; preds = %18
  %30 = call noundef nonnull align 8 dereferenceable(896) ptr @_Z13global_loggerv()
  %31 = call noundef i32 @_ZN11file_logger13get_log_levelEv(ptr noundef nonnull align 8 dereferenceable(896) %30)
  %32 = icmp sge i32 6, %31
  br i1 %32, label %33, label %41

33:                                               ; preds = %29
  %34 = call noundef nonnull align 8 dereferenceable(896) ptr @_ZN19log_stream_dispatchILb1EE4execEiPKcS2_ib(i32 noundef 6, ptr noundef @.str.6, ptr noundef @__func__._ZN8graphlab7dc_impl11dc_tcp_comm10sendtosockEiPKcm, i32 noundef 363, i1 noundef zeroext true)
  %35 = call noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPKc(ptr noundef nonnull align 8 dereferenceable(896) %34, ptr noundef @.str.18)
  %36 = call ptr @__errno_location() #8
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = call ptr @strerror(i32 noundef %37) #7
  %39 = call noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsIPcEERS_T_(ptr noundef nonnull align 8 dereferenceable(896) %35, ptr noundef %38)
  %40 = call noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPFRSoS0_E(ptr noundef nonnull align 8 dereferenceable(896) %39, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %41

41:                                               ; preds = %33, %29
  %42 = call ptr @__errno_location() #8
  %43 = load i32, ptr %42, align 4, !tbaa !9
  store i32 %43, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %48

44:                                               ; preds = %18
  %45 = load i64, ptr %11, align 8, !tbaa !11
  %46 = load i64, ptr %10, align 8, !tbaa !11
  %47 = add i64 %46, %45
  store i64 %47, ptr %10, align 8, !tbaa !11
  store i32 0, ptr %12, align 4
  br label %48

48:                                               ; preds = %44, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  %49 = load i32, ptr %12, align 4
  switch i32 %49, label %52 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %14, !llvm.loop !13

51:                                               ; preds = %14
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %52

52:                                               ; preds = %51, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  %53 = load i32, ptr %5, align 4
  ret i32 %53
}

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { inlinehint 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 = { 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 #5 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { 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 = !{!"int", !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"

@.str.6 = external hidden unnamed_addr constant [78 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [13 x i8], align 1
@__func__._ZN8graphlab7dc_impl11dc_tcp_comm10sendtosockEiPKcm = external hidden unnamed_addr constant [11 x i8], align 1

declare noundef nonnull align 8 dereferenceable(896) ptr @_Z13global_loggerv() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11file_logger13get_log_levelEv(ptr noundef nonnull align 8 dereferenceable(896)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN19log_stream_dispatchILb1EE4execEiPKcS2_ib(i32 noundef, ptr noundef, ptr noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPKc(ptr noundef nonnull align 8 dereferenceable(896), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPFRSoS0_E(ptr noundef nonnull align 8 dereferenceable(896), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsIPcEERS_T_(ptr noundef nonnull align 8 dereferenceable(896), ptr noundef) local_unnamed_addr #4 align 2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8graphlab7dc_impl11dc_tcp_comm10sendtosockEiPKcm(ptr nocapture noundef nonnull readnone align 8 dereferenceable(833) %0, i32 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #4 align 2 {
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

5:                                                ; preds = %.lr.ph
  %6 = add i64 %10, %.01319
  %7 = icmp ult i64 %6, %3
  br i1 %7, label %.lr.ph, label %.loopexit, !llvm.loop !5

.lr.ph:                                           ; preds = %4, %5
  %.01319 = phi i64 [ %6, %5 ], [ 0, %4 ]
  %8 = getelementptr inbounds i8, ptr %2, i64 %.01319
  %9 = sub i64 %3, %.01319
  %10 = tail call i64 @send(i32 noundef %1, ptr noundef %8, i64 noundef %9, i32 noundef 0)
  %11 = icmp sgt i64 %10, -1
  br i1 %11, label %5, label %12

12:                                               ; preds = %.lr.ph
  %13 = tail call noundef nonnull align 8 dereferenceable(896) ptr @_Z13global_loggerv()
  %14 = tail call noundef i32 @_ZN11file_logger13get_log_levelEv(ptr noundef nonnull align 8 dereferenceable(896) %13)
  %15 = icmp slt i32 %14, 7
  br i1 %15, label %16, label %..thread_crit_edge

..thread_crit_edge:                               ; preds = %12
  %.pre = tail call ptr @__errno_location() #6
  br label %.thread

16:                                               ; preds = %12
  %17 = tail call noundef nonnull align 8 dereferenceable(896) ptr @_ZN19log_stream_dispatchILb1EE4execEiPKcS2_ib(i32 noundef 6, ptr noundef nonnull @.str.6, ptr noundef nonnull @__func__._ZN8graphlab7dc_impl11dc_tcp_comm10sendtosockEiPKcm, i32 noundef 363, i1 noundef zeroext true)
  %18 = tail call noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPKc(ptr noundef nonnull align 8 dereferenceable(896) %17, ptr noundef nonnull @.str.18)
  %19 = tail call ptr @__errno_location() #6
  %20 = load i32, ptr %19, align 4, !tbaa !7
  %21 = tail call ptr @strerror(i32 noundef %20) #7
  %22 = tail call noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsIPcEERS_T_(ptr noundef nonnull align 8 dereferenceable(896) %18, ptr noundef %21)
  %23 = tail call noundef nonnull align 8 dereferenceable(896) ptr @_ZN11file_loggerlsEPFRSoS0_E(ptr noundef nonnull align 8 dereferenceable(896) %22, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %.thread

.thread:                                          ; preds = %..thread_crit_edge, %16
  %.pre-phi = phi ptr [ %.pre, %..thread_crit_edge ], [ %19, %16 ]
  %24 = load i32, ptr %.pre-phi, align 4, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %5, %4, %.thread
  %.2 = phi i32 [ %24, %.thread ], [ 0, %4 ], [ 0, %5 ]
  ret i32 %.2
}

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

attributes #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 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 = { inlinehint 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 = { 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 #4 = { 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 #5 = { 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 #6 = { nounwind willreturn memory(none) }
attributes #7 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass