; LLVM IR from openanolis/openssl :: doc/designs/ddd (ddd-02-conn-nonblocking-threads)

; 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.pollfd = type { i32, i16, i16 }

@main.tx_msg = external hidden global [384 x i8], align 16
@main.host_port = external hidden global [300 x i8], align 16
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@stdout = external global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_ssl_ctx() #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_conn(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @tx(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @rx(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_conn_fd(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_conn_pending_tx(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_conn_pending_rx(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @teardown(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @teardown_ctx(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [2048 x i8], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %struct.pollfd, align 4
  %15 = alloca i32, align 4
  %16 = alloca %struct.pollfd, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr @main.tx_msg, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2048, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 1, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 383, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 2000, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr null, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store ptr null, ptr %13, align 8, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 3
  br i1 %18, label %19, label %25

19:                                               ; preds = %2
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds ptr, ptr %21, i64 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str, ptr noundef %23) #5
  br label %142

25:                                               ; preds = %2
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds ptr, ptr %26, i64 1
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds ptr, ptr %29, i64 2
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef @main.host_port, i64 noundef 300, ptr noundef @.str.1, ptr noundef %28, ptr noundef %31) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds ptr, ptr %33, i64 1
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef @main.tx_msg, i64 noundef 384, ptr noundef @.str.2, ptr noundef %35) #5
  %37 = call ptr @create_ssl_ctx()
  store ptr %37, ptr %13, align 8, !tbaa !9
  %38 = load ptr, ptr %13, align 8, !tbaa !9
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %43

40:                                               ; preds = %25
  %41 = load ptr, ptr @stderr, align 8, !tbaa !9
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str.3) #5
  br label %142

43:                                               ; preds = %25
  %44 = load ptr, ptr %13, align 8, !tbaa !9
  %45 = call ptr @new_conn(ptr noundef %44, ptr noundef @main.host_port)
  store ptr %45, ptr %12, align 8, !tbaa !9
  %46 = load ptr, ptr %12, align 8, !tbaa !9
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %51

48:                                               ; preds = %43
  %49 = load ptr, ptr @stderr, align 8, !tbaa !9
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef @.str.4) #5
  br label %142

51:                                               ; preds = %43
  br label %52

52:                                               ; preds = %99, %51
  %53 = load i32, ptr %10, align 4, !tbaa !5
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %100

55:                                               ; preds = %52
  %56 = load ptr, ptr %12, align 8, !tbaa !9
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = call i32 @tx(ptr noundef %56, ptr noundef %57, i32 noundef %58)
  store i32 %59, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = icmp sgt i32 %60, 0
  br i1 %61, label %62, label %70

62:                                               ; preds = %55
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  %65 = sext i32 %63 to i64
  %66 = getelementptr inbounds i8, ptr %64, i64 %65
  store ptr %66, ptr %6, align 8, !tbaa !9
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !5
  %69 = sub nsw i32 %68, %67
  store i32 %69, ptr %10, align 4, !tbaa !5
  br label %99

70:                                               ; preds = %55
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = icmp eq i32 %71, -1
  br i1 %72, label %73, label %76

73:                                               ; preds = %70
  %74 = load ptr, ptr @stderr, align 8, !tbaa !9
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str.5) #5
  br label %98

76:                                               ; preds = %70
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = icmp eq i32 %77, -2
  br i1 %78, label %79, label %97

79:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.memset.p0.i64(ptr align 4 %14, i8 0, i64 8, i1 false)
  %80 = load ptr, ptr %12, align 8, !tbaa !9
  %81 = call i32 @get_conn_fd(ptr noundef %80)
  %82 = getelementptr inbounds %struct.pollfd, ptr %14, i32 0, i32 0
  store i32 %81, ptr %82, align 4, !tbaa !11
  %83 = load ptr, ptr %12, align 8, !tbaa !9
  %84 = call i32 @get_conn_pending_tx(ptr noundef %83)
  %85 = trunc i32 %84 to i16
  %86 = getelementptr inbounds %struct.pollfd, ptr %14, i32 0, i32 1
  store i16 %85, ptr %86, align 4, !tbaa !14
  %87 = load i32, ptr %11, align 4, !tbaa !5
  %88 = call i32 @poll(ptr noundef %14, i64 noundef 1, i32 noundef %87)
  %89 = icmp eq i32 %88, 0
  br i1 %89, label %90, label %93

90:                                               ; preds = %79
  %91 = load ptr, ptr @stderr, align 8, !tbaa !9
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %91, ptr noundef @.str.6) #5
  store i32 2, ptr %15, align 4
  br label %94

93:                                               ; preds = %79
  store i32 0, ptr %15, align 4
  br label %94

94:                                               ; preds = %93, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %95 = load i32, ptr %15, align 4
  switch i32 %95, label %154 [
    i32 0, label %96
    i32 2, label %142
  ]

96:                                               ; preds = %94
  br label %97

97:                                               ; preds = %96, %76
  br label %98

98:                                               ; preds = %97, %73
  br label %99

99:                                               ; preds = %98, %62
  br label %52, !llvm.loop !15

100:                                              ; preds = %52
  br label %101

101:                                              ; preds = %140, %100
  %102 = load ptr, ptr %12, align 8, !tbaa !9
  %103 = getelementptr inbounds [2048 x i8], ptr %7, i64 0, i64 0
  %104 = call i32 @rx(ptr noundef %102, ptr noundef %103, i32 noundef 2048)
  store i32 %104, ptr %9, align 4, !tbaa !5
  %105 = load i32, ptr %9, align 4, !tbaa !5
  %106 = icmp sgt i32 %105, 0
  br i1 %106, label %107, label %113

107:                                              ; preds = %101
  %108 = getelementptr inbounds [2048 x i8], ptr %7, i64 0, i64 0
  %109 = load i32, ptr %9, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = load ptr, ptr @stdout, align 8, !tbaa !9
  %112 = call i64 @fwrite(ptr noundef %108, i64 noundef 1, i64 noundef %110, ptr noundef %111)
  br label %140

113:                                              ; preds = %101
  %114 = load i32, ptr %9, align 4, !tbaa !5
  %115 = icmp eq i32 %114, -1
  br i1 %115, label %116, label %117

116:                                              ; preds = %113
  br label %141

117:                                              ; preds = %113
  %118 = load i32, ptr %9, align 4, !tbaa !5
  %119 = icmp eq i32 %118, -2
  br i1 %119, label %120, label %138

120:                                              ; preds = %117
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  call void @llvm.memset.p0.i64(ptr align 4 %16, i8 0, i64 8, i1 false)
  %121 = load ptr, ptr %12, align 8, !tbaa !9
  %122 = call i32 @get_conn_fd(ptr noundef %121)
  %123 = getelementptr inbounds %struct.pollfd, ptr %16, i32 0, i32 0
  store i32 %122, ptr %123, align 4, !tbaa !11
  %124 = load ptr, ptr %12, align 8, !tbaa !9
  %125 = call i32 @get_conn_pending_rx(ptr noundef %124)
  %126 = trunc i32 %125 to i16
  %127 = getelementptr inbounds %struct.pollfd, ptr %16, i32 0, i32 1
  store i16 %126, ptr %127, align 4, !tbaa !14
  %128 = load i32, ptr %11, align 4, !tbaa !5
  %129 = call i32 @poll(ptr noundef %16, i64 noundef 1, i32 noundef %128)
  %130 = icmp eq i32 %129, 0
  br i1 %130, label %131, label %134

131:                                              ; preds = %120
  %132 = load ptr, ptr @stderr, align 8, !tbaa !9
  %133 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %132, ptr noundef @.str.7) #5
  store i32 2, ptr %15, align 4
  br label %135

134:                                              ; preds = %120
  store i32 0, ptr %15, align 4
  br label %135

135:                                              ; preds = %134, %131
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  %136 = load i32, ptr %15, align 4
  switch i32 %136, label %154 [
    i32 0, label %137
    i32 2, label %142
  ]

137:                                              ; preds = %135
  br label %138

138:                                              ; preds = %137, %117
  br label %139

139:                                              ; preds = %138
  br label %140

140:                                              ; preds = %139, %107
  br label %101

141:                                              ; preds = %116
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %142

142:                                              ; preds = %141, %135, %94, %48, %40, %19
  %143 = load ptr, ptr %12, align 8, !tbaa !9
  %144 = icmp ne ptr %143, null
  br i1 %144, label %145, label %147

145:                                              ; preds = %142
  %146 = load ptr, ptr %12, align 8, !tbaa !9
  call void @teardown(ptr noundef %146)
  br label %147

147:                                              ; preds = %145, %142
  %148 = load ptr, ptr %13, align 8, !tbaa !9
  %149 = icmp ne ptr %148, null
  br i1 %149, label %150, label %152

150:                                              ; preds = %147
  %151 = load ptr, ptr %13, align 8, !tbaa !9
  call void @teardown_ctx(ptr noundef %151)
  br label %152

152:                                              ; preds = %150, %147
  %153 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %153, ptr %3, align 4
  store i32 1, ptr %15, align 4
  br label %154

154:                                              ; preds = %152, %135, %94
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %155 = load i32, ptr %3, align 4
  ret i32 %155
}

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

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) #4

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 }

!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, !6, i64 0}
!12 = !{!"pollfd", !6, i64 0, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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.pollfd = type { i32, i16, i16 }

@main.tx_msg = external hidden global [384 x i8], align 16
@main.host_port = external hidden global [300 x i8], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_ssl_ctx() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_conn(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @tx(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @rx(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_conn_fd(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_conn_pending_tx(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @get_conn_pending_rx(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @teardown(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @teardown_ctx(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [2048 x i8], align 16
  %4 = alloca %struct.pollfd, align 8
  %5 = alloca %struct.pollfd, align 8
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %3) #4
  %6 = icmp slt i32 %0, 3
  br i1 %6, label %7, label %11

7:                                                ; preds = %2
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef %9) #5
  br label %.thread63.thread

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) @main.host_port, i64 noundef 300, ptr noundef nonnull @.str.1, ptr noundef %13, ptr noundef %15) #4
  %17 = load ptr, ptr %12, align 8, !tbaa !5
  %18 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) @main.tx_msg, i64 noundef 384, ptr noundef nonnull @.str.2, ptr noundef %17) #4
  %19 = tail call ptr @create_ssl_ctx()
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %11
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.3) #5
  br label %.thread63.thread

24:                                               ; preds = %11
  %25 = tail call ptr @new_conn(ptr noundef nonnull %19, ptr noundef nonnull @main.host_port)
  %26 = icmp eq ptr %25, null
  br i1 %26, label %.thread63.thread74, label %.preheader80

.preheader80:                                     ; preds = %24
  %27 = getelementptr inbounds i8, ptr %4, i64 4
  br label %31

.thread63.thread74:                               ; preds = %24
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.4) #5
  br label %69

.preheader:                                       ; preds = %51
  %30 = getelementptr inbounds i8, ptr %5, i64 4
  br label %52

31:                                               ; preds = %.preheader80, %51
  %.04082 = phi i32 [ 383, %.preheader80 ], [ %.141, %51 ]
  %.04381 = phi ptr [ @main.tx_msg, %.preheader80 ], [ %.144, %51 ]
  %32 = call i32 @tx(ptr noundef nonnull %25, ptr noundef %.04381, i32 noundef %.04082)
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %34, label %38

34:                                               ; preds = %31
  %35 = zext nneg i32 %32 to i64
  %36 = getelementptr inbounds i8, ptr %.04381, i64 %35
  %37 = sub nsw i32 %.04082, %32
  br label %51

38:                                               ; preds = %31
  switch i32 %32, label %51 [
    i32 -1, label %39
    i32 -2, label %42
  ]

39:                                               ; preds = %38
  %40 = load ptr, ptr @stderr, align 8, !tbaa !5
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.5) #5
  br label %51

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store i64 0, ptr %4, align 8
  %43 = call i32 @get_conn_fd(ptr noundef nonnull %25)
  store i32 %43, ptr %4, align 8, !tbaa !9
  %44 = call i32 @get_conn_pending_tx(ptr noundef nonnull %25)
  %45 = trunc i32 %44 to i16
  store i16 %45, ptr %27, align 4, !tbaa !13
  %46 = call i32 @poll(ptr noundef nonnull %4, i64 noundef 1, i32 noundef 2000) #4
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %.thread

.thread:                                          ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %51

48:                                               ; preds = %42
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef nonnull @.str.6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %.thread63

51:                                               ; preds = %.thread, %38, %39, %34
  %.144 = phi ptr [ %36, %34 ], [ %.04381, %39 ], [ %.04381, %38 ], [ %.04381, %.thread ]
  %.141 = phi i32 [ %37, %34 ], [ %.04082, %39 ], [ %.04082, %38 ], [ %.04082, %.thread ]
  %.not = icmp eq i32 %.141, 0
  br i1 %.not, label %.preheader, label %31, !llvm.loop !14

52:                                               ; preds = %.backedge, %.preheader
  %53 = call i32 @rx(ptr noundef nonnull %25, ptr noundef nonnull %3, i32 noundef 2048)
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %55, label %59

55:                                               ; preds = %52
  %56 = zext nneg i32 %53 to i64
  %57 = load ptr, ptr @stdout, align 8, !tbaa !5
  %58 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 1, i64 noundef %56, ptr noundef %57)
  br label %.backedge

59:                                               ; preds = %52
  switch i32 %53, label %.backedge [
    i32 -1, label %.thread63
    i32 -2, label %60
  ]

60:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 0, ptr %5, align 8
  %61 = call i32 @get_conn_fd(ptr noundef nonnull %25)
  store i32 %61, ptr %5, align 8, !tbaa !9
  %62 = call i32 @get_conn_pending_rx(ptr noundef nonnull %25)
  %63 = trunc i32 %62 to i16
  store i16 %63, ptr %30, align 4, !tbaa !13
  %64 = call i32 @poll(ptr noundef nonnull %5, i64 noundef 1, i32 noundef 2000) #4
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %.thread60

.thread60:                                        ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %.backedge

.backedge:                                        ; preds = %.thread60, %59, %55
  br label %52

66:                                               ; preds = %60
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef nonnull @.str.7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br label %.thread63

.thread63:                                        ; preds = %59, %48, %66
  %.042 = phi i32 [ 1, %48 ], [ 1, %66 ], [ 0, %59 ]
  call void @teardown(ptr noundef nonnull %25)
  br label %69

69:                                               ; preds = %.thread63, %.thread63.thread74
  %.0426879 = phi i32 [ 1, %.thread63.thread74 ], [ %.042, %.thread63 ]
  call void @teardown_ctx(ptr noundef nonnull %19)
  br label %.thread63.thread

.thread63.thread:                                 ; preds = %7, %21, %69
  %.0426873 = phi i32 [ %.0426879, %69 ], [ 1, %21 ], [ 1, %7 ]
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %3) #4
  ret i32 %.0426873
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) 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 = { 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 }
attributes #5 = { cold 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 = !{!"pollfd", !11, i64 0, !12, i64 4, !12, i64 6}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !12, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass