; LLVM IR from pandax381/microps :: tcp (tcp_receive)

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

%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.tcp_pcb = type { i32, i32, %struct.ip_endpoint, %struct.ip_endpoint, %struct.anon, i32, %struct.anon.0, i32, i16, i16, [65535 x i8], %struct.sched_ctx, %struct.queue_head, %struct.timeval, ptr, %struct.queue_head }
%struct.ip_endpoint = type { i32, i16 }
%struct.anon = type { i32, i32, i16, i16, i32, i32 }
%struct.anon.0 = type { i32, i16, i16 }
%struct.sched_ctx = type { %union.pthread_cond_t, i32, i32 }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%struct.timeval = type { i64, i64 }
%struct.queue_head = type { ptr, ptr, i32 }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@mutex = external hidden global %union.pthread_mutex_t, align 8
@.str.9 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [19 x i8], align 1
@__func__.tcp_receive = external hidden unnamed_addr constant [12 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare i32 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mutex_lock(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mutex_unlock(ptr noundef) #3

declare i32 @sched_sleep(ptr noundef, ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden ptr @tcp_pcb_get(i32 noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i64 @tcp_receive(i32 noundef %0, ptr noundef %1, i64 noundef %2) #5 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = 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) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %12 = call i32 @mutex_lock(ptr noundef @mutex)
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = call ptr @tcp_pcb_get(i32 noundef %13)
  store ptr %14, ptr %8, align 8, !tbaa !9
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %21, label %17

17:                                               ; preds = %3
  %18 = load ptr, ptr @stderr, align 8, !tbaa !9
  %19 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %18, i32 noundef 69, ptr noundef @.str.1, i32 noundef 1296, ptr noundef @__func__.tcp_receive, ptr noundef @.str.12)
  %20 = call i32 @mutex_unlock(ptr noundef @mutex)
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %113

21:                                               ; preds = %3
  br label %22

22:                                               ; preds = %53, %21
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.tcp_pcb, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !13
  switch i32 %25, label %70 [
    i32 1, label %26
    i32 2, label %30
    i32 3, label %30
    i32 4, label %30
    i32 5, label %34
    i32 6, label %34
    i32 7, label %34
    i32 10, label %55
    i32 8, label %66
    i32 11, label %66
    i32 9, label %66
  ]

26:                                               ; preds = %22
  %27 = load ptr, ptr @stderr, align 8, !tbaa !9
  %28 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %27, i32 noundef 69, ptr noundef @.str.1, i32 noundef 1303, ptr noundef @__func__.tcp_receive, ptr noundef @.str.23)
  %29 = call i32 @mutex_unlock(ptr noundef @mutex)
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %113

30:                                               ; preds = %22, %22, %22
  %31 = load ptr, ptr @stderr, align 8, !tbaa !9
  %32 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %31, i32 noundef 69, ptr noundef @.str.1, i32 noundef 1310, ptr noundef @__func__.tcp_receive, ptr noundef @.str.25)
  %33 = call i32 @mutex_unlock(ptr noundef @mutex)
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %113

34:                                               ; preds = %22, %22, %22
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.tcp_pcb, ptr %35, i32 0, i32 6
  %37 = getelementptr inbounds %struct.anon.0, ptr %36, i32 0, i32 1
  %38 = load i16, ptr %37, align 4, !tbaa !22
  %39 = zext i16 %38 to i64
  %40 = sub i64 65535, %39
  store i64 %40, ptr %9, align 8, !tbaa !11
  %41 = load i64, ptr %9, align 8, !tbaa !11
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %54, label %43

43:                                               ; preds = %34
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.tcp_pcb, ptr %44, i32 0, i32 11
  %46 = call i32 @sched_sleep(ptr noundef %45, ptr noundef @mutex, ptr noundef null)
  %47 = icmp eq i32 %46, -1
  br i1 %47, label %48, label %53

48:                                               ; preds = %43
  %49 = load ptr, ptr @stderr, align 8, !tbaa !9
  %50 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %49, i32 noundef 68, ptr noundef @.str.1, i32 noundef 1319, ptr noundef @__func__.tcp_receive, ptr noundef @.str.9)
  %51 = call i32 @mutex_unlock(ptr noundef @mutex)
  %52 = call ptr @__errno_location() #7
  store i32 4, ptr %52, align 4, !tbaa !5
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %113

53:                                               ; preds = %43
  br label %22

54:                                               ; preds = %34
  br label %77

55:                                               ; preds = %22
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.tcp_pcb, ptr %56, i32 0, i32 6
  %58 = getelementptr inbounds %struct.anon.0, ptr %57, i32 0, i32 1
  %59 = load i16, ptr %58, align 4, !tbaa !22
  %60 = zext i16 %59 to i64
  %61 = sub i64 65535, %60
  store i64 %61, ptr %9, align 8, !tbaa !11
  %62 = load i64, ptr %9, align 8, !tbaa !11
  %63 = icmp ne i64 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %55
  br label %77

65:                                               ; preds = %55
  br label %66

66:                                               ; preds = %65, %22, %22, %22
  %67 = load ptr, ptr @stderr, align 8, !tbaa !9
  %68 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %67, i32 noundef 68, ptr noundef @.str.1, i32 noundef 1336, ptr noundef @__func__.tcp_receive, ptr noundef @.str.27)
  %69 = call i32 @mutex_unlock(ptr noundef @mutex)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %113

70:                                               ; preds = %22
  %71 = load ptr, ptr @stderr, align 8, !tbaa !9
  %72 = load ptr, ptr %8, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.tcp_pcb, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !13
  %75 = call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %71, i32 noundef 69, ptr noundef @.str.1, i32 noundef 1340, ptr noundef @__func__.tcp_receive, ptr noundef @.str.28, i32 noundef %74)
  %76 = call i32 @mutex_unlock(ptr noundef @mutex)
  store i64 -1, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %113

77:                                               ; preds = %64, %54
  %78 = load i64, ptr %7, align 8, !tbaa !11
  %79 = load i64, ptr %9, align 8, !tbaa !11
  %80 = icmp ult i64 %78, %79
  br i1 %80, label %81, label %83

81:                                               ; preds = %77
  %82 = load i64, ptr %7, align 8, !tbaa !11
  br label %85

83:                                               ; preds = %77
  %84 = load i64, ptr %9, align 8, !tbaa !11
  br label %85

85:                                               ; preds = %83, %81
  %86 = phi i64 [ %82, %81 ], [ %84, %83 ]
  store i64 %86, ptr %10, align 8, !tbaa !11
  %87 = load ptr, ptr %6, align 8, !tbaa !9
  %88 = load ptr, ptr %8, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.tcp_pcb, ptr %88, i32 0, i32 10
  %90 = getelementptr inbounds [65535 x i8], ptr %89, i64 0, i64 0
  %91 = load i64, ptr %10, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %87, ptr align 8 %90, i64 %91, i1 false)
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.tcp_pcb, ptr %92, i32 0, i32 10
  %94 = getelementptr inbounds [65535 x i8], ptr %93, i64 0, i64 0
  %95 = load ptr, ptr %8, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.tcp_pcb, ptr %95, i32 0, i32 10
  %97 = getelementptr inbounds [65535 x i8], ptr %96, i64 0, i64 0
  %98 = load i64, ptr %10, align 8, !tbaa !11
  %99 = getelementptr inbounds i8, ptr %97, i64 %98
  %100 = load i64, ptr %9, align 8, !tbaa !11
  %101 = load i64, ptr %10, align 8, !tbaa !11
  %102 = sub i64 %100, %101
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %94, ptr align 1 %99, i64 %102, i1 false)
  %103 = load i64, ptr %10, align 8, !tbaa !11
  %104 = load ptr, ptr %8, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.tcp_pcb, ptr %104, i32 0, i32 6
  %106 = getelementptr inbounds %struct.anon.0, ptr %105, i32 0, i32 1
  %107 = load i16, ptr %106, align 4, !tbaa !22
  %108 = zext i16 %107 to i64
  %109 = add i64 %108, %103
  %110 = trunc i64 %109 to i16
  store i16 %110, ptr %106, align 4, !tbaa !22
  %111 = call i32 @mutex_unlock(ptr noundef @mutex)
  %112 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %112, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %113

113:                                              ; preds = %85, %70, %66, %48, %30, %26, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %114 = load i64, ptr %4, align 8
  ret i64 %114
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!14, !6, i64 0}
!14 = !{!"tcp_pcb", !6, i64 0, !6, i64 4, !15, i64 8, !15, i64 16, !17, i64 24, !6, i64 44, !18, i64 48, !6, i64 56, !16, i64 60, !16, i64 62, !7, i64 64, !19, i64 65600, !20, i64 65656, !21, i64 65680, !10, i64 65696, !20, i64 65704}
!15 = !{!"ip_endpoint", !6, i64 0, !16, i64 4}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 4, !16, i64 8, !16, i64 10, !6, i64 12, !6, i64 16}
!18 = !{!"", !6, i64 0, !16, i64 4, !16, i64 6}
!19 = !{!"sched_ctx", !7, i64 0, !6, i64 48, !6, i64 52}
!20 = !{!"queue_head", !10, i64 0, !10, i64 8, !6, i64 16}
!21 = !{!"timeval", !12, i64 0, !12, i64 8}
!22 = !{!14, !16, i64 52}


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

%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@mutex = external hidden global %union.pthread_mutex_t, align 8
@.str.9 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [19 x i8], align 1
@__func__.tcp_receive = external hidden unnamed_addr constant [12 x i8], align 1

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

declare i32 @lprintf(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

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

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

declare i32 @sched_sleep(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden ptr @tcp_pcb_get(i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i64 @tcp_receive(i32 noundef %0, ptr nocapture noundef writeonly %1, i64 noundef %2) local_unnamed_addr #4 {
  %4 = tail call i32 @mutex_lock(ptr noundef nonnull @mutex)
  %5 = tail call ptr @tcp_pcb_get(i32 noundef %0)
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %8, label %.preheader

.preheader:                                       ; preds = %3
  %6 = getelementptr inbounds i8, ptr %5, i64 52
  %7 = getelementptr inbounds i8, ptr %5, i64 65600
  br label %12

8:                                                ; preds = %3
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %9, i32 noundef 69, ptr noundef nonnull @.str.1, i32 noundef 1296, ptr noundef nonnull @__func__.tcp_receive, ptr noundef nonnull @.str.12) #6
  %11 = tail call i32 @mutex_unlock(ptr noundef nonnull @mutex)
  br label %49

12:                                               ; preds = %.preheader, %24
  %13 = load i32, ptr %5, align 8, !tbaa !9
  switch i32 %13, label %37 [
    i32 1, label %14
    i32 2, label %18
    i32 3, label %18
    i32 4, label %18
    i32 5, label %22
    i32 6, label %22
    i32 7, label %22
    i32 10, label %32
    i32 8, label %.loopexit
    i32 11, label %.loopexit
    i32 9, label %.loopexit
  ]

14:                                               ; preds = %12
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %15, i32 noundef 69, ptr noundef nonnull @.str.1, i32 noundef 1303, ptr noundef nonnull @__func__.tcp_receive, ptr noundef nonnull @.str.23) #6
  %17 = tail call i32 @mutex_unlock(ptr noundef nonnull @mutex)
  br label %49

18:                                               ; preds = %12, %12, %12
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %19, i32 noundef 69, ptr noundef nonnull @.str.1, i32 noundef 1310, ptr noundef nonnull @__func__.tcp_receive, ptr noundef nonnull @.str.25) #6
  %21 = tail call i32 @mutex_unlock(ptr noundef nonnull @mutex)
  br label %49

22:                                               ; preds = %12, %12, %12
  %23 = load i16, ptr %6, align 4, !tbaa !20
  %.not28 = icmp eq i16 %23, -1
  br i1 %.not28, label %24, label %.loopexit29

24:                                               ; preds = %22
  %25 = tail call i32 @sched_sleep(ptr noundef nonnull %7, ptr noundef nonnull @mutex, ptr noundef null) #6
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %12

27:                                               ; preds = %24
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %28, i32 noundef 68, ptr noundef nonnull @.str.1, i32 noundef 1319, ptr noundef nonnull @__func__.tcp_receive, ptr noundef nonnull @.str.9) #6
  %30 = tail call i32 @mutex_unlock(ptr noundef nonnull @mutex)
  %31 = tail call ptr @__errno_location() #7
  store i32 4, ptr %31, align 4, !tbaa !21
  br label %49

32:                                               ; preds = %12
  %33 = load i16, ptr %6, align 4, !tbaa !20
  %.not27 = icmp eq i16 %33, -1
  br i1 %.not27, label %.loopexit, label %.loopexit29

.loopexit:                                        ; preds = %12, %12, %12, %32
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %34, i32 noundef 68, ptr noundef nonnull @.str.1, i32 noundef 1336, ptr noundef nonnull @__func__.tcp_receive, ptr noundef nonnull @.str.27) #6
  %36 = tail call i32 @mutex_unlock(ptr noundef nonnull @mutex)
  br label %49

37:                                               ; preds = %12
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = tail call i32 (ptr, i32, ptr, i32, ptr, ptr, ...) @lprintf(ptr noundef %38, i32 noundef 69, ptr noundef nonnull @.str.1, i32 noundef 1340, ptr noundef nonnull @__func__.tcp_receive, ptr noundef nonnull @.str.28, i32 noundef %13) #6
  %40 = tail call i32 @mutex_unlock(ptr noundef nonnull @mutex)
  br label %49

.loopexit29:                                      ; preds = %22, %32
  %.024.in.in = phi i16 [ %33, %32 ], [ %23, %22 ]
  %.024.in = xor i16 %.024.in.in, -1
  %.024 = zext i16 %.024.in to i64
  %41 = tail call i64 @llvm.umin.i64(i64 %.024, i64 %2)
  %42 = getelementptr inbounds i8, ptr %5, i64 64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr nonnull align 8 %42, i64 %41, i1 false)
  %43 = getelementptr inbounds i8, ptr %42, i64 %41
  %44 = sub nsw i64 %.024, %41
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %42, ptr nonnull align 1 %43, i64 %44, i1 false)
  %45 = load i16, ptr %6, align 4, !tbaa !20
  %46 = trunc nuw i64 %41 to i16
  %47 = add i16 %45, %46
  store i16 %47, ptr %6, align 4, !tbaa !20
  %48 = tail call i32 @mutex_unlock(ptr noundef nonnull @mutex)
  br label %49

49:                                               ; preds = %.loopexit29, %37, %.loopexit, %27, %18, %14, %8
  %.0 = phi i64 [ -1, %37 ], [ 0, %.loopexit ], [ %41, %.loopexit29 ], [ -1, %27 ], [ -1, %18 ], [ -1, %14 ], [ -1, %8 ]
  ret i64 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #5

attributes #0 = { mustprogress nocallback nofree 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 = { 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 = { 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 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { 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, !11, i64 0}
!10 = !{!"tcp_pcb", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !14, i64 24, !11, i64 44, !15, i64 48, !11, i64 56, !13, i64 60, !13, i64 62, !7, i64 64, !16, i64 65600, !17, i64 65656, !18, i64 65680, !6, i64 65696, !17, i64 65704}
!11 = !{!"int", !7, i64 0}
!12 = !{!"ip_endpoint", !11, i64 0, !13, i64 4}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !11, i64 0, !11, i64 4, !13, i64 8, !13, i64 10, !11, i64 12, !11, i64 16}
!15 = !{!"", !11, i64 0, !13, i64 4, !13, i64 6}
!16 = !{!"sched_ctx", !7, i64 0, !11, i64 48, !11, i64 52}
!17 = !{!"queue_head", !6, i64 0, !6, i64 8, !11, i64 16}
!18 = !{!"timeval", !19, i64 0, !19, i64 8}
!19 = !{!"long", !7, i64 0}
!20 = !{!10, !13, i64 52}
!21 = !{!11, !11, i64 0}


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