; LLVM IR from Water-Melon/Melon :: src (mln_connection)

; 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.mln_tcp_conn_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, 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: nounwind uwtable
define dso_local i32 @mln_tcp_conn_recv(ptr noundef nonnull %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.mln_tcp_conn_t, ptr %8, i32 0, i32 7
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = call i32 @mln_fd_is_nonblock(i32 noundef %10)
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %22

13:                                               ; preds = %2
  br label %14

14:                                               ; preds = %44, %13
  br label %15

15:                                               ; preds = %20, %14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = call i32 @mln_tcp_conn_recv_chain(ptr noundef %16, i32 noundef %17)
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  br label %15, !llvm.loop !13

21:                                               ; preds = %15
  br label %30

22:                                               ; preds = %2
  br label %23

23:                                               ; preds = %45, %22
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = call i32 @mln_tcp_conn_recv_chain(ptr noundef %24, i32 noundef %25)
  store i32 %26, ptr %6, align 4, !tbaa !9
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %53

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29, %21
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 4, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %53

34:                                               ; preds = %30
  %35 = call ptr @__errno_location() #5
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 4
  br i1 %37, label %38, label %46

38:                                               ; preds = %34
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mln_tcp_conn_t, ptr %39, i32 0, i32 7
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = call i32 @mln_fd_is_nonblock(i32 noundef %41)
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %38
  br label %14

45:                                               ; preds = %38
  br label %23

46:                                               ; preds = %34
  %47 = call ptr @__errno_location() #5
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp eq i32 %48, 11
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  store i32 2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %53

51:                                               ; preds = %46
  br label %52

52:                                               ; preds = %51
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %53

53:                                               ; preds = %52, %50, %33, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %54 = load i32, ptr %3, align 4
  ret i32 %54
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_fd_is_nonblock(i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_tcp_conn_recv_chain(ptr noundef, i32 noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 56}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}
!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: nounwind uwtable
define dso_local range(i32 2, 5) i32 @mln_tcp_conn_recv(ptr noundef nonnull %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = tail call i32 @mln_fd_is_nonblock(i32 noundef %4)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %9, label %.preheader

.preheader:                                       ; preds = %16, %2
  br label %6

6:                                                ; preds = %.preheader, %6
  %7 = tail call i32 @mln_tcp_conn_recv_chain(ptr noundef nonnull %0, i32 noundef %1)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %6, label %.loopexit, !llvm.loop !11

9:                                                ; preds = %16, %2
  %10 = tail call i32 @mln_tcp_conn_recv_chain(ptr noundef nonnull %0, i32 noundef %1)
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %20, label %.loopexit

.loopexit:                                        ; preds = %6, %9
  %.0 = phi i32 [ %10, %9 ], [ %7, %6 ]
  %12 = icmp eq i32 %.0, 0
  br i1 %12, label %20, label %13

13:                                               ; preds = %.loopexit
  %14 = tail call ptr @__errno_location() #3
  %15 = load i32, ptr %14, align 4, !tbaa !13
  switch i32 %15, label %19 [
    i32 4, label %16
    i32 11, label %20
  ]

16:                                               ; preds = %13
  %17 = load i32, ptr %3, align 8, !tbaa !5
  %18 = tail call i32 @mln_fd_is_nonblock(i32 noundef %17)
  %.not11 = icmp eq i32 %18, 0
  br i1 %.not11, label %9, label %.preheader

19:                                               ; preds = %13
  br label %20

20:                                               ; preds = %13, %.loopexit, %9, %19
  %.07 = phi i32 [ 3, %19 ], [ 2, %9 ], [ 4, %.loopexit ], [ 2, %13 ]
  ret i32 %.07
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_fd_is_nonblock(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_tcp_conn_recv_chain(ptr noundef, i32 noundef) local_unnamed_addr #1

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

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 = { inlinehint 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 = { 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 #3 = { 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 56}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !10, i64 0}


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