; LLVM IR from openanolis/openssl :: doc/designs/ddd (ddd-05-mem-nonblocking)

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

@main.tx_msg = 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 [29 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [12 x i8], align 1
@stdout = external global ptr, align 8

; 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_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 i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca [2048 x i8], align 16
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca %struct.addrinfo, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  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 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 -1, ptr %7, align 4, !tbaa !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 8, ptr %9) #5
  store ptr @main.tx_msg, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2048, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 299, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 2000, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store ptr null, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %15) #5
  call void @llvm.memset.p0.i64(ptr align 8 %15, i8 0, i64 48, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store ptr null, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store ptr null, ptr %17, align 8, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 3
  br i1 %19, label %20, label %26

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

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

34:                                               ; preds = %26
  %35 = load ptr, ptr @stderr, align 8, !tbaa !9
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.2) #5
  br label %173

37:                                               ; preds = %26
  %38 = getelementptr inbounds %struct.addrinfo, ptr %15, i32 0, i32 1
  store i32 2, ptr %38, align 4, !tbaa !11
  %39 = getelementptr inbounds %struct.addrinfo, ptr %15, i32 0, i32 2
  store i32 1, ptr %39, align 8, !tbaa !13
  %40 = getelementptr inbounds %struct.addrinfo, ptr %15, i32 0, i32 0
  store i32 1, ptr %40, align 8, !tbaa !14
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  %42 = getelementptr inbounds ptr, ptr %41, i64 1
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds ptr, ptr %44, i64 2
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = call i32 @getaddrinfo(ptr noundef %43, ptr noundef %46, ptr noundef %15, ptr noundef %16)
  store i32 %47, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %37
  %51 = load ptr, ptr @stderr, align 8, !tbaa !9
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str.3) #5
  br label %173

53:                                               ; preds = %37
  %54 = call ptr @signal(i32 noundef 13, ptr noundef inttoptr (i64 1 to ptr)) #5
  %55 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 6) #5
  store i32 %55, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = icmp slt i32 %56, 0
  br i1 %57, label %58, label %61

58:                                               ; preds = %53
  %59 = load ptr, ptr @stderr, align 8, !tbaa !9
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str.4) #5
  br label %173

61:                                               ; preds = %53
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = load ptr, ptr %16, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.addrinfo, ptr %63, i32 0, i32 5
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  %66 = load ptr, ptr %16, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.addrinfo, ptr %66, i32 0, i32 4
  %68 = load i32, ptr %67, align 8, !tbaa !16
  %69 = call i32 @connect(i32 noundef %62, ptr noundef %65, i32 noundef %68)
  store i32 %69, ptr %6, align 4, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %72, label %75

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

75:                                               ; preds = %61
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = call i32 (i32, i32, ...) @fcntl(i32 noundef %76, i32 noundef 4, i32 noundef 2048)
  store i32 %77, ptr %6, align 4, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = icmp slt i32 %78, 0
  br i1 %79, label %80, label %83

80:                                               ; preds = %75
  %81 = load ptr, ptr @stderr, align 8, !tbaa !9
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str.6) #5
  br label %173

83:                                               ; preds = %75
  %84 = load ptr, ptr %17, align 8, !tbaa !9
  %85 = load ptr, ptr %5, align 8, !tbaa !9
  %86 = getelementptr inbounds ptr, ptr %85, i64 1
  %87 = load ptr, ptr %86, align 8, !tbaa !9
  %88 = call ptr @new_conn(ptr noundef %84, ptr noundef %87)
  store ptr %88, ptr %14, align 8, !tbaa !9
  %89 = load ptr, ptr %14, align 8, !tbaa !9
  %90 = icmp eq ptr %89, null
  br i1 %90, label %91, label %94

91:                                               ; preds = %83
  %92 = load ptr, ptr @stderr, align 8, !tbaa !9
  %93 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %92, ptr noundef @.str.7) #5
  br label %173

94:                                               ; preds = %83
  br label %95

95:                                               ; preds = %136, %94
  %96 = load i32, ptr %12, align 4, !tbaa !5
  %97 = icmp ne i32 %96, 0
  br i1 %97, label %98, label %137

98:                                               ; preds = %95
  %99 = load ptr, ptr %14, align 8, !tbaa !9
  %100 = load ptr, ptr %9, align 8, !tbaa !9
  %101 = load i32, ptr %12, align 4, !tbaa !5
  %102 = call i32 @tx(ptr noundef %99, ptr noundef %100, i32 noundef %101)
  store i32 %102, ptr %11, align 4, !tbaa !5
  %103 = load i32, ptr %11, align 4, !tbaa !5
  %104 = icmp sgt i32 %103, 0
  br i1 %104, label %105, label %113

105:                                              ; preds = %98
  %106 = load i32, ptr %11, align 4, !tbaa !5
  %107 = load ptr, ptr %9, align 8, !tbaa !9
  %108 = sext i32 %106 to i64
  %109 = getelementptr inbounds i8, ptr %107, i64 %108
  store ptr %109, ptr %9, align 8, !tbaa !9
  %110 = load i32, ptr %11, align 4, !tbaa !5
  %111 = load i32, ptr %12, align 4, !tbaa !5
  %112 = sub nsw i32 %111, %110
  store i32 %112, ptr %12, align 4, !tbaa !5
  br label %136

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

116:                                              ; preds = %113
  %117 = load ptr, ptr @stderr, align 8, !tbaa !9
  %118 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %117, ptr noundef @.str.8) #5
  br label %135

119:                                              ; preds = %113
  %120 = load i32, ptr %11, align 4, !tbaa !5
  %121 = icmp eq i32 %120, -2
  br i1 %121, label %122, label %134

122:                                              ; preds = %119
  %123 = load ptr, ptr %14, align 8, !tbaa !9
  %124 = load i32, ptr %7, align 4, !tbaa !5
  %125 = load ptr, ptr %14, align 8, !tbaa !9
  %126 = call i32 @get_conn_pending_tx(ptr noundef %125)
  %127 = load i32, ptr %13, align 4, !tbaa !5
  %128 = call i32 @pump(ptr noundef %123, i32 noundef %124, i32 noundef %126, i32 noundef %127)
  %129 = icmp ne i32 %128, 1
  br i1 %129, label %130, label %133

130:                                              ; preds = %122
  %131 = load ptr, ptr @stderr, align 8, !tbaa !9
  %132 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %131, ptr noundef @.str.9) #5
  br label %173

133:                                              ; preds = %122
  br label %134

134:                                              ; preds = %133, %119
  br label %135

135:                                              ; preds = %134, %116
  br label %136

136:                                              ; preds = %135, %105
  br label %95, !llvm.loop !17

137:                                              ; preds = %95
  br label %138

138:                                              ; preds = %171, %137
  %139 = load ptr, ptr %14, align 8, !tbaa !9
  %140 = getelementptr inbounds [2048 x i8], ptr %10, i64 0, i64 0
  %141 = call i32 @rx(ptr noundef %139, ptr noundef %140, i32 noundef 2048)
  store i32 %141, ptr %11, align 4, !tbaa !5
  %142 = load i32, ptr %11, align 4, !tbaa !5
  %143 = icmp sgt i32 %142, 0
  br i1 %143, label %144, label %150

144:                                              ; preds = %138
  %145 = getelementptr inbounds [2048 x i8], ptr %10, i64 0, i64 0
  %146 = load i32, ptr %11, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = load ptr, ptr @stdout, align 8, !tbaa !9
  %149 = call i64 @fwrite(ptr noundef %145, i64 noundef 1, i64 noundef %147, ptr noundef %148)
  br label %171

150:                                              ; preds = %138
  %151 = load i32, ptr %11, align 4, !tbaa !5
  %152 = icmp eq i32 %151, -1
  br i1 %152, label %153, label %154

153:                                              ; preds = %150
  br label %172

154:                                              ; preds = %150
  %155 = load i32, ptr %11, align 4, !tbaa !5
  %156 = icmp eq i32 %155, -2
  br i1 %156, label %157, label %169

157:                                              ; preds = %154
  %158 = load ptr, ptr %14, align 8, !tbaa !9
  %159 = load i32, ptr %7, align 4, !tbaa !5
  %160 = load ptr, ptr %14, align 8, !tbaa !9
  %161 = call i32 @get_conn_pending_rx(ptr noundef %160)
  %162 = load i32, ptr %13, align 4, !tbaa !5
  %163 = call i32 @pump(ptr noundef %158, i32 noundef %159, i32 noundef %161, i32 noundef %162)
  %164 = icmp ne i32 %163, 1
  br i1 %164, label %165, label %168

165:                                              ; preds = %157
  %166 = load ptr, ptr @stderr, align 8, !tbaa !9
  %167 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %166, ptr noundef @.str.9) #5
  br label %173

168:                                              ; preds = %157
  br label %169

169:                                              ; preds = %168, %154
  br label %170

170:                                              ; preds = %169
  br label %171

171:                                              ; preds = %170, %144
  br label %138

172:                                              ; preds = %153
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %173

173:                                              ; preds = %172, %165, %130, %91, %80, %72, %58, %50, %34, %20
  %174 = load ptr, ptr %14, align 8, !tbaa !9
  %175 = icmp ne ptr %174, null
  br i1 %175, label %176, label %178

176:                                              ; preds = %173
  %177 = load ptr, ptr %14, align 8, !tbaa !9
  call void @teardown(ptr noundef %177)
  br label %178

178:                                              ; preds = %176, %173
  %179 = load ptr, ptr %17, align 8, !tbaa !9
  %180 = icmp ne ptr %179, null
  br i1 %180, label %181, label %183

181:                                              ; preds = %178
  %182 = load ptr, ptr %17, align 8, !tbaa !9
  call void @teardown_ctx(ptr noundef %182)
  br label %183

183:                                              ; preds = %181, %178
  %184 = load ptr, ptr %16, align 8, !tbaa !9
  %185 = icmp ne ptr %184, null
  br i1 %185, label %186, label %188

186:                                              ; preds = %183
  %187 = load ptr, ptr %16, align 8, !tbaa !9
  call void @freeaddrinfo(ptr noundef %187) #5
  br label %188

188:                                              ; preds = %186, %183
  %189 = load i32, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  ret i32 %189
}

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

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

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

declare i32 @getaddrinfo(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare ptr @signal(i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #3

declare i32 @connect(i32 noundef, ptr noundef, i32 noundef) #4

declare i32 @fcntl(i32 noundef, i32 noundef, ...) #4

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

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

; Function Attrs: nounwind
declare void @freeaddrinfo(ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 4}
!12 = !{!"addrinfo", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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.addrinfo = type { i32, i32, i32, i32, i32, ptr, ptr, ptr }

@main.tx_msg = 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 [29 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [12 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8

; 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_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.addrinfo, align 8
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #6
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %6, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  store ptr null, ptr %5, align 8, !tbaa !5
  %7 = icmp slt i32 %0, 3
  br i1 %7, label %8, label %12

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

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

18:                                               ; preds = %12
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.2) #7
  br label %.thread.thread75.thread

21:                                               ; preds = %12
  %22 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 2, ptr %22, align 4, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 1, ptr %23, align 8, !tbaa !12
  store i32 1, ptr %4, align 8, !tbaa !13
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %1, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = call i32 @getaddrinfo(ptr noundef %24, ptr noundef %26, ptr noundef nonnull %4, ptr noundef nonnull %5) #6
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %21
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str.3) #7
  br label %.thread.thread75

32:                                               ; preds = %21
  %33 = call ptr @signal(i32 noundef 13, ptr noundef nonnull inttoptr (i64 1 to ptr)) #6
  %34 = call i32 @socket(i32 noundef 2, i32 noundef 1, i32 noundef 6) #6
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %32
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef nonnull @.str.4) #7
  br label %.thread.thread75

39:                                               ; preds = %32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 24
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = getelementptr inbounds i8, ptr %40, i64 16
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = call i32 @connect(i32 noundef %34, ptr noundef %42, i32 noundef %44) #6
  %46 = icmp slt i32 %45, 0
  br i1 %46, label %47, label %50

47:                                               ; preds = %39
  %48 = load ptr, ptr @stderr, align 8, !tbaa !5
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef nonnull @.str.5) #7
  br label %.thread.thread75

50:                                               ; preds = %39
  %51 = call i32 (i32, i32, ...) @fcntl(i32 noundef %34, i32 noundef 4, i32 noundef 2048) #6
  %52 = icmp slt i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %50
  %54 = load ptr, ptr @stderr, align 8, !tbaa !5
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef nonnull @.str.6) #7
  br label %.thread.thread75

56:                                               ; preds = %50
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = call ptr @new_conn(ptr noundef nonnull %16, ptr noundef %57)
  %59 = icmp eq ptr %58, null
  br i1 %59, label %60, label %.preheader79

60:                                               ; preds = %56
  %61 = load ptr, ptr @stderr, align 8, !tbaa !5
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef nonnull @.str.7) #7
  br label %.thread.thread75

.preheader79:                                     ; preds = %56, %76
  %.04481 = phi i32 [ %.1, %76 ], [ 299, %56 ]
  %.04580 = phi ptr [ %.146, %76 ], [ @main.tx_msg, %56 ]
  %63 = call i32 @tx(ptr noundef nonnull %58, ptr noundef %.04580, i32 noundef %.04481)
  %64 = icmp sgt i32 %63, 0
  br i1 %64, label %65, label %69

65:                                               ; preds = %.preheader79
  %66 = zext nneg i32 %63 to i64
  %67 = getelementptr inbounds i8, ptr %.04580, i64 %66
  %68 = sub nsw i32 %.04481, %63
  br label %76

69:                                               ; preds = %.preheader79
  switch i32 %63, label %76 [
    i32 -1, label %70
    i32 -2, label %73
  ]

70:                                               ; preds = %69
  %71 = load ptr, ptr @stderr, align 8, !tbaa !5
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef nonnull @.str.8) #7
  br label %76

73:                                               ; preds = %69
  %74 = call i32 @get_conn_pending_tx(ptr noundef nonnull %58)
  %75 = call i32 @pump(ptr noundef nonnull %58, i32 noundef %34, i32 noundef %74, i32 noundef 2000)
  %.not58 = icmp eq i32 %75, 1
  br i1 %.not58, label %76, label %.thread.sink.split

76:                                               ; preds = %69, %70, %73, %65
  %.146 = phi ptr [ %67, %65 ], [ %.04580, %70 ], [ %.04580, %73 ], [ %.04580, %69 ]
  %.1 = phi i32 [ %68, %65 ], [ %.04481, %70 ], [ %.04481, %73 ], [ %.04481, %69 ]
  %.not = icmp eq i32 %.1, 0
  br i1 %.not, label %.preheader, label %.preheader79, !llvm.loop !16

.preheader:                                       ; preds = %76, %.preheader.backedge
  %77 = call i32 @rx(ptr noundef nonnull %58, ptr noundef nonnull %3, i32 noundef 2048)
  %78 = icmp sgt i32 %77, 0
  br i1 %78, label %79, label %83

79:                                               ; preds = %.preheader
  %80 = zext nneg i32 %77 to i64
  %81 = load ptr, ptr @stdout, align 8, !tbaa !5
  %82 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 1, i64 noundef %80, ptr noundef %81)
  br label %.preheader.backedge

83:                                               ; preds = %.preheader
  switch i32 %77, label %.preheader.backedge [
    i32 -1, label %.thread
    i32 -2, label %84
  ]

.preheader.backedge:                              ; preds = %83, %84, %79
  br label %.preheader

84:                                               ; preds = %83
  %85 = call i32 @get_conn_pending_rx(ptr noundef nonnull %58)
  %86 = call i32 @pump(ptr noundef nonnull %58, i32 noundef %34, i32 noundef %85, i32 noundef 2000)
  %.not57 = icmp eq i32 %86, 1
  br i1 %.not57, label %.preheader.backedge, label %.thread.sink.split

.thread.sink.split:                               ; preds = %73, %84
  %87 = load ptr, ptr @stderr, align 8, !tbaa !5
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef nonnull @.str.9) #7
  br label %.thread

.thread:                                          ; preds = %83, %.thread.sink.split
  %.047 = phi i32 [ 1, %.thread.sink.split ], [ 0, %83 ]
  call void @teardown(ptr noundef nonnull %58)
  br label %.thread.thread75

.thread.thread75:                                 ; preds = %60, %53, %47, %36, %29, %.thread
  %.0476672 = phi i32 [ %.047, %.thread ], [ 1, %60 ], [ 1, %53 ], [ 1, %47 ], [ 1, %36 ], [ 1, %29 ]
  call void @teardown_ctx(ptr noundef nonnull %16)
  %.pre = load ptr, ptr %5, align 8, !tbaa !5
  %.not61 = icmp eq ptr %.pre, null
  br i1 %.not61, label %.thread.thread75.thread, label %89

89:                                               ; preds = %.thread.thread75
  call void @freeaddrinfo(ptr noundef nonnull %.pre) #6
  br label %.thread.thread75.thread

.thread.thread75.thread:                          ; preds = %8, %18, %89, %.thread.thread75
  %.047667384 = phi i32 [ %.0476672, %89 ], [ %.0476672, %.thread.thread75 ], [ 1, %18 ], [ 1, %8 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %3) #6
  ret i32 %.047667384
}

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

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

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

declare i32 @getaddrinfo(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #5

declare i32 @connect(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

declare i32 @fcntl(i32 noundef, i32 noundef, ...) local_unnamed_addr #4

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

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @freeaddrinfo(ptr noundef) local_unnamed_addr #5

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #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 "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 = { 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 4}
!10 = !{!"addrinfo", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !11, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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