; LLVM IR from aws/s2n-tls :: tls (s2n_ktls_io)

; 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.s2n_debug_info = type { ptr, ptr }
%struct.s2n_result = type { i32 }
%struct.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }

@s2n_sendmsg_fn = external dso_local global ptr, align 8
@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.19 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [88 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #1

declare i32 @s2n_calculate_stacktrace() #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_ktls_set_control_data(ptr noundef, ptr noundef, i64 noundef, i32 noundef, i8 noundef zeroext) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_ktls_sendmsg(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %7 = alloca %struct.s2n_result, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %struct.msghdr, align 8
  %15 = alloca [24 x i8], align 16
  %16 = alloca %struct.s2n_result, align 4
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i8 %1, ptr %9, align 1, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !10
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %6
  %21 = load ptr, ptr %13, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %55, label %23

23:                                               ; preds = %20
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %27 = getelementptr inbounds %struct.s2n_debug_info, ptr %26, i32 0, i32 0
  store ptr @.str.19, ptr %27, align 8, !tbaa !12
  %28 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %29 = getelementptr inbounds %struct.s2n_debug_info, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = getelementptr inbounds i8, ptr %30, i64 21
  %32 = call ptr @strrchr(ptr noundef %31, i32 noundef 47) #8
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %41

34:                                               ; preds = %25
  %35 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %36 = getelementptr inbounds %struct.s2n_debug_info, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = getelementptr inbounds i8, ptr %37, i64 21
  %39 = call ptr @strrchr(ptr noundef %38, i32 noundef 47) #8
  %40 = getelementptr inbounds i8, ptr %39, i64 1
  br label %46

41:                                               ; preds = %25
  %42 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %43 = getelementptr inbounds %struct.s2n_debug_info, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  %45 = getelementptr inbounds i8, ptr %44, i64 21
  br label %46

46:                                               ; preds = %41, %34
  %47 = phi ptr [ %40, %34 ], [ %45, %41 ]
  %48 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %49 = getelementptr inbounds %struct.s2n_debug_info, ptr %48, i32 0, i32 1
  store ptr %47, ptr %49, align 8, !tbaa !14
  %50 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %50, align 4, !tbaa !15
  %51 = call i32 @s2n_calculate_stacktrace()
  br label %52

52:                                               ; preds = %46
  %53 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 -1, ptr %53, align 4, !tbaa !17
  br label %193

54:                                               ; No predecessors!
  br label %55

55:                                               ; preds = %54, %20
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %92, label %60

60:                                               ; preds = %57
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %64 = getelementptr inbounds %struct.s2n_debug_info, ptr %63, i32 0, i32 0
  store ptr @.str.20, ptr %64, align 8, !tbaa !12
  %65 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %66 = getelementptr inbounds %struct.s2n_debug_info, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !12
  %68 = getelementptr inbounds i8, ptr %67, i64 21
  %69 = call ptr @strrchr(ptr noundef %68, i32 noundef 47) #8
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %78

71:                                               ; preds = %62
  %72 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %73 = getelementptr inbounds %struct.s2n_debug_info, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !12
  %75 = getelementptr inbounds i8, ptr %74, i64 21
  %76 = call ptr @strrchr(ptr noundef %75, i32 noundef 47) #8
  %77 = getelementptr inbounds i8, ptr %76, i64 1
  br label %83

78:                                               ; preds = %62
  %79 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %80 = getelementptr inbounds %struct.s2n_debug_info, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !12
  %82 = getelementptr inbounds i8, ptr %81, i64 21
  br label %83

83:                                               ; preds = %78, %71
  %84 = phi ptr [ %77, %71 ], [ %82, %78 ]
  %85 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %86 = getelementptr inbounds %struct.s2n_debug_info, ptr %85, i32 0, i32 1
  store ptr %84, ptr %86, align 8, !tbaa !14
  %87 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %87, align 4, !tbaa !15
  %88 = call i32 @s2n_calculate_stacktrace()
  br label %89

89:                                               ; preds = %83
  %90 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 -1, ptr %90, align 4, !tbaa !17
  br label %193

91:                                               ; No predecessors!
  br label %92

92:                                               ; preds = %91, %57
  br label %93

93:                                               ; preds = %92
  br label %94

94:                                               ; preds = %93
  %95 = load ptr, ptr %10, align 8, !tbaa !5
  %96 = icmp ne ptr %95, null
  br i1 %96, label %132, label %97

97:                                               ; preds = %94
  %98 = load i64, ptr %11, align 8, !tbaa !10
  %99 = icmp eq i64 %98, 0
  br i1 %99, label %132, label %100

100:                                              ; preds = %97
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101
  %103 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %104 = getelementptr inbounds %struct.s2n_debug_info, ptr %103, i32 0, i32 0
  store ptr @.str.21, ptr %104, align 8, !tbaa !12
  %105 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %106 = getelementptr inbounds %struct.s2n_debug_info, ptr %105, i32 0, i32 0
  %107 = load ptr, ptr %106, align 8, !tbaa !12
  %108 = getelementptr inbounds i8, ptr %107, i64 21
  %109 = call ptr @strrchr(ptr noundef %108, i32 noundef 47) #8
  %110 = icmp ne ptr %109, null
  br i1 %110, label %111, label %118

111:                                              ; preds = %102
  %112 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %113 = getelementptr inbounds %struct.s2n_debug_info, ptr %112, i32 0, i32 0
  %114 = load ptr, ptr %113, align 8, !tbaa !12
  %115 = getelementptr inbounds i8, ptr %114, i64 21
  %116 = call ptr @strrchr(ptr noundef %115, i32 noundef 47) #8
  %117 = getelementptr inbounds i8, ptr %116, i64 1
  br label %123

118:                                              ; preds = %102
  %119 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %120 = getelementptr inbounds %struct.s2n_debug_info, ptr %119, i32 0, i32 0
  %121 = load ptr, ptr %120, align 8, !tbaa !12
  %122 = getelementptr inbounds i8, ptr %121, i64 21
  br label %123

123:                                              ; preds = %118, %111
  %124 = phi ptr [ %117, %111 ], [ %122, %118 ]
  %125 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %126 = getelementptr inbounds %struct.s2n_debug_info, ptr %125, i32 0, i32 1
  store ptr %124, ptr %126, align 8, !tbaa !14
  %127 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %127, align 4, !tbaa !15
  %128 = call i32 @s2n_calculate_stacktrace()
  br label %129

129:                                              ; preds = %123
  %130 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 -1, ptr %130, align 4, !tbaa !17
  br label %193

131:                                              ; No predecessors!
  br label %132

132:                                              ; preds = %131, %97, %94
  br label %133

133:                                              ; preds = %132
  %134 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 2, ptr %134, align 4, !tbaa !15
  %135 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 0, ptr %135, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 56, ptr %14) #9
  %136 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 0
  store ptr null, ptr %136, align 8, !tbaa !19
  %137 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 1
  store i32 0, ptr %137, align 8, !tbaa !21
  %138 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 2
  %139 = load ptr, ptr %10, align 8, !tbaa !5
  %140 = ptrtoint ptr %139 to i64
  %141 = inttoptr i64 %140 to ptr
  store ptr %141, ptr %138, align 8, !tbaa !22
  %142 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 3
  %143 = load i64, ptr %11, align 8, !tbaa !10
  store i64 %143, ptr %142, align 8, !tbaa !23
  %144 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 4
  store ptr null, ptr %144, align 8, !tbaa !24
  %145 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 5
  store i64 0, ptr %145, align 8, !tbaa !25
  %146 = getelementptr inbounds %struct.msghdr, ptr %14, i32 0, i32 6
  store i32 0, ptr %146, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 24, ptr %15) #9
  call void @llvm.memset.p0.i64(ptr align 16 %15, i8 0, i64 24, i1 false)
  br label %147

147:                                              ; preds = %133
  %148 = getelementptr inbounds [24 x i8], ptr %15, i64 0, i64 0
  %149 = load i8, ptr %9, align 1, !tbaa !9
  %150 = call i32 @s2n_ktls_set_control_data(ptr noundef %14, ptr noundef %148, i64 noundef 24, i32 noundef 0, i8 noundef zeroext %149)
  %151 = getelementptr inbounds %struct.s2n_result, ptr %16, i32 0, i32 0
  store i32 %150, ptr %151, align 4
  %152 = getelementptr inbounds %struct.s2n_result, ptr %16, i32 0, i32 0
  %153 = load i32, ptr %152, align 4
  %154 = call zeroext i1 @s2n_result_is_ok(i32 %153)
  br i1 %154, label %157, label %155

155:                                              ; preds = %147
  %156 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 -1, ptr %156, align 4, !tbaa !17
  store i32 1, ptr %17, align 4
  br label %192

157:                                              ; preds = %147
  br label %158

158:                                              ; preds = %157
  br label %159

159:                                              ; preds = %158
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #9
  store i64 0, ptr %18, align 8, !tbaa !10
  br label %160

160:                                              ; preds = %172, %159
  %161 = call ptr @__errno_location() #10
  store i32 0, ptr %161, align 4, !tbaa !15
  %162 = load ptr, ptr @s2n_sendmsg_fn, align 8, !tbaa !5
  %163 = load ptr, ptr %8, align 8, !tbaa !5
  %164 = call i64 %162(ptr noundef %163, ptr noundef %14)
  store i64 %164, ptr %18, align 8, !tbaa !10
  br label %165

165:                                              ; preds = %160
  %166 = load i64, ptr %18, align 8, !tbaa !10
  %167 = icmp slt i64 %166, 0
  br i1 %167, label %168, label %172

168:                                              ; preds = %165
  %169 = call ptr @__errno_location() #10
  %170 = load i32, ptr %169, align 4, !tbaa !15
  %171 = icmp eq i32 %170, 4
  br label %172

172:                                              ; preds = %168, %165
  %173 = phi i1 [ false, %165 ], [ %171, %168 ]
  br i1 %173, label %160, label %174, !llvm.loop !27

174:                                              ; preds = %172
  br label %175

175:                                              ; preds = %174
  %176 = load i64, ptr %18, align 8, !tbaa !10
  %177 = call i32 @s2n_io_check_write_result(i64 noundef %176)
  %178 = getelementptr inbounds %struct.s2n_result, ptr %19, i32 0, i32 0
  store i32 %177, ptr %178, align 4
  %179 = getelementptr inbounds %struct.s2n_result, ptr %19, i32 0, i32 0
  %180 = load i32, ptr %179, align 4
  %181 = call zeroext i1 @s2n_result_is_ok(i32 %180)
  br i1 %181, label %184, label %182

182:                                              ; preds = %175
  %183 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 -1, ptr %183, align 4, !tbaa !17
  store i32 1, ptr %17, align 4
  br label %191

184:                                              ; preds = %175
  br label %185

185:                                              ; preds = %184
  br label %186

186:                                              ; preds = %185
  %187 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %187, align 4, !tbaa !15
  %188 = load i64, ptr %18, align 8, !tbaa !10
  %189 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %188, ptr %189, align 8, !tbaa !10
  %190 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 0, ptr %190, align 4, !tbaa !17
  store i32 1, ptr %17, align 4
  br label %191

191:                                              ; preds = %186, %182
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #9
  br label %192

192:                                              ; preds = %191, %155
  call void @llvm.lifetime.end.p0(i64 24, ptr %15) #9
  call void @llvm.lifetime.end.p0(i64 56, ptr %14) #9
  br label %193

193:                                              ; preds = %192, %129, %89, %52
  %194 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  %195 = load i32, ptr %194, align 4
  ret i32 %195
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) #6

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

declare i32 @s2n_io_check_write_result(i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind willreturn memory(read) "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 = { "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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { 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 #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind }
attributes #10 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!14 = !{!13, !6, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !16, i64 0}
!18 = !{!"", !16, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"msghdr", !6, i64 0, !16, i64 8, !6, i64 16, !11, i64 24, !6, i64 32, !11, i64 40, !16, i64 48}
!21 = !{!20, !16, i64 8}
!22 = !{!20, !6, i64 16}
!23 = !{!20, !11, i64 24}
!24 = !{!20, !6, i64 32}
!25 = !{!20, !11, i64 40}
!26 = !{!20, !16, i64 48}
!27 = distinct !{!27, !28}
!28 = !{!"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.s2n_debug_info = type { ptr, ptr }
%struct.msghdr = type { ptr, i32, ptr, i64, ptr, i64, i32 }

@s2n_sendmsg_fn = external dso_local local_unnamed_addr global ptr, align 8
@_s2n_debug_info = external thread_local local_unnamed_addr global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4
@.str.19 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [88 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strrchr(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_ktls_set_control_data(ptr noundef, ptr noundef, i64 noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_ktls_sendmsg(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i64 noundef %3, ptr noundef writeonly %4, ptr noundef writeonly %5) local_unnamed_addr #3 {
  %7 = alloca %struct.msghdr, align 8
  %8 = alloca [24 x i8], align 16
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %9, label %17

9:                                                ; preds = %6
  %10 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.19, ptr %10, align 8, !tbaa !5
  %11 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.19, i64 21), i32 noundef 47) #8
  %.not21 = icmp eq ptr %11, null
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  %13 = select i1 %.not21, ptr getelementptr inbounds (i8, ptr @.str.19, i64 21), ptr %12
  %14 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %13, ptr %14, align 8, !tbaa !10
  %15 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %15, align 4, !tbaa !11
  %16 = tail call i32 @s2n_calculate_stacktrace() #9
  br label %56

17:                                               ; preds = %6
  %.not22 = icmp eq ptr %4, null
  br i1 %.not22, label %18, label %26

18:                                               ; preds = %17
  %19 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.20, ptr %19, align 8, !tbaa !5
  %20 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.20, i64 21), i32 noundef 47) #8
  %.not23 = icmp eq ptr %20, null
  %21 = getelementptr inbounds i8, ptr %20, i64 1
  %22 = select i1 %.not23, ptr getelementptr inbounds (i8, ptr @.str.20, i64 21), ptr %21
  %23 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr %22, ptr %23, align 8, !tbaa !10
  %24 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %24, align 4, !tbaa !11
  %25 = tail call i32 @s2n_calculate_stacktrace() #9
  br label %56

26:                                               ; preds = %17
  %27 = icmp ne ptr %2, null
  %28 = icmp eq i64 %3, 0
  %or.cond = or i1 %27, %28
  br i1 %or.cond, label %37, label %29

29:                                               ; preds = %26
  %30 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.21, ptr %30, align 8, !tbaa !5
  %31 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.21, i64 21), i32 noundef 47) #8
  %.not24 = icmp eq ptr %31, null
  %32 = getelementptr inbounds i8, ptr %31, i64 1
  %33 = select i1 %.not24, ptr getelementptr inbounds (i8, ptr @.str.21, i64 21), ptr %32
  %34 = getelementptr inbounds i8, ptr %30, i64 8
  store ptr %33, ptr %34, align 8, !tbaa !10
  %35 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %35, align 4, !tbaa !11
  %36 = tail call i32 @s2n_calculate_stacktrace() #9
  br label %56

37:                                               ; preds = %26
  store i32 2, ptr %4, align 4, !tbaa !11
  store i64 0, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %7) #9
  store ptr null, ptr %7, align 8, !tbaa !15
  %38 = getelementptr inbounds i8, ptr %7, i64 8
  store i32 0, ptr %38, align 8, !tbaa !17
  %39 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %2, ptr %39, align 8, !tbaa !18
  %40 = getelementptr inbounds i8, ptr %7, i64 24
  store i64 %3, ptr %40, align 8, !tbaa !19
  %41 = getelementptr inbounds i8, ptr %7, i64 32
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %41, i8 0, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %8) #9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %8, i8 0, i64 24, i1 false)
  %42 = call i32 @s2n_ktls_set_control_data(ptr noundef nonnull %7, ptr noundef nonnull %8, i64 noundef 24, i32 noundef 0, i8 noundef zeroext %1)
  %43 = call zeroext i1 @s2n_result_is_ok(i32 %42)
  br i1 %43, label %.preheader, label %55

.preheader:                                       ; preds = %37
  %44 = tail call ptr @__errno_location() #10
  br label %45

45:                                               ; preds = %.preheader, %49
  store i32 0, ptr %44, align 4, !tbaa !11
  %46 = load ptr, ptr @s2n_sendmsg_fn, align 8, !tbaa !20
  %47 = call i64 %46(ptr noundef %0, ptr noundef nonnull %7) #9
  %48 = icmp slt i64 %47, 0
  br i1 %48, label %49, label %.critedge

49:                                               ; preds = %45
  %50 = load i32, ptr %44, align 4, !tbaa !11
  %51 = icmp eq i32 %50, 4
  br i1 %51, label %45, label %.critedge, !llvm.loop !21

.critedge:                                        ; preds = %45, %49
  %52 = call i32 @s2n_io_check_write_result(i64 noundef %47) #9
  %53 = call zeroext i1 @s2n_result_is_ok(i32 %52)
  br i1 %53, label %54, label %55

54:                                               ; preds = %.critedge
  store i32 0, ptr %4, align 4, !tbaa !11
  store i64 %47, ptr %5, align 8, !tbaa !13
  br label %55

55:                                               ; preds = %54, %.critedge, %37
  %.sroa.016.1 = phi i32 [ -1, %37 ], [ 0, %54 ], [ -1, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %8) #9
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %7) #9
  br label %56

56:                                               ; preds = %55, %29, %18, %9
  %.sroa.016.2 = phi i32 [ %.sroa.016.1, %55 ], [ -1, %29 ], [ -1, %18 ], [ -1, %9 ]
  ret i32 %.sroa.016.2
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) local_unnamed_addr #6

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

declare i32 @s2n_io_check_write_result(i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { "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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { 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 #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind }
attributes #10 = { 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, !7, i64 0}
!6 = !{!"s2n_debug_info", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"msghdr", !7, i64 0, !12, i64 8, !7, i64 16, !14, i64 24, !7, i64 32, !14, i64 40, !12, i64 48}
!17 = !{!16, !12, i64 8}
!18 = !{!16, !7, i64 16}
!19 = !{!16, !14, i64 24}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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