; LLVM IR from uNetworking/uSockets :: src (context)

; 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.us_socket_context_options_t = type { ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.us_socket_context_t = type { ptr, i32, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [8 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local i32 @default_is_low_prio_handler(ptr noundef) #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
define dso_local ptr @us_create_socket_context(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef byval(%struct.us_socket_context_options_t) align 8 %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %16

12:                                               ; preds = %4
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = call ptr @us_internal_create_ssl_socket_context(ptr noundef %13, i32 noundef %14, ptr noundef byval(%struct.us_socket_context_options_t) align 8 %3)
  store ptr %15, ptr %5, align 8
  br label %45

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = add i64 144, %18
  %20 = call noalias ptr @malloc(i64 noundef %19) #5
  store ptr %20, ptr %9, align 8, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !9
  %22 = load ptr, ptr %9, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.us_socket_context_t, ptr %22, i32 0, i32 0
  store ptr %21, ptr %23, align 16, !tbaa !11
  %24 = load ptr, ptr %9, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.us_socket_context_t, ptr %24, i32 0, i32 4
  store ptr null, ptr %25, align 16, !tbaa !13
  %26 = load ptr, ptr %9, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.us_socket_context_t, ptr %26, i32 0, i32 5
  store ptr null, ptr %27, align 8, !tbaa !14
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.us_socket_context_t, ptr %28, i32 0, i32 6
  store ptr null, ptr %29, align 16, !tbaa !15
  %30 = load ptr, ptr %9, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.us_socket_context_t, ptr %30, i32 0, i32 8
  store ptr null, ptr %31, align 16, !tbaa !16
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.us_socket_context_t, ptr %32, i32 0, i32 18
  store ptr @default_is_low_prio_handler, ptr %33, align 16, !tbaa !17
  %34 = load ptr, ptr %9, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.us_socket_context_t, ptr %34, i32 0, i32 2
  store i8 0, ptr %35, align 4, !tbaa !18
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.us_socket_context_t, ptr %36, i32 0, i32 3
  store i8 0, ptr %37, align 1, !tbaa !19
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.us_socket_context_t, ptr %38, i32 0, i32 1
  store i32 0, ptr %39, align 8, !tbaa !20
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.us_socket_context_t, ptr %40, i32 0, i32 9
  store ptr null, ptr %41, align 8, !tbaa !21
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = load ptr, ptr %9, align 8, !tbaa !9
  call void @us_internal_loop_link(ptr noundef %42, ptr noundef %43)
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %44, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %45

45:                                               ; preds = %16, %12
  %46 = load ptr, ptr %5, align 8
  ret ptr %46
}

declare ptr @us_internal_create_ssl_socket_context(ptr noundef, i32 noundef, ptr noundef byval(%struct.us_socket_context_options_t) align 8) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

declare void @us_internal_loop_link(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync 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 = { nounwind allocsize(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 }
attributes #5 = { nounwind allocsize(0) }

!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, !10, i64 0}
!12 = !{!"us_socket_context_t", !10, i64 0, !6, i64 8, !7, i64 12, !7, i64 13, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !10, i64 32}
!16 = !{!12, !10, i64 48}
!17 = !{!12, !10, i64 128}
!18 = !{!12, !7, i64 12}
!19 = !{!12, !7, i64 13}
!20 = !{!12, !6, i64 8}
!21 = !{!12, !10, i64 56}


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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @us_create_socket_context(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef byval(%struct.us_socket_context_options_t) align 8 %3) local_unnamed_addr #0 {
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %7, label %5

5:                                                ; preds = %4
  %6 = tail call ptr @us_internal_create_ssl_socket_context(ptr noundef %1, i32 noundef %2, ptr noundef nonnull byval(%struct.us_socket_context_options_t) align 8 %3) #4
  br label %18

7:                                                ; preds = %4
  %8 = sext i32 %2 to i64
  %9 = add nsw i64 %8, 144
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #5
  store ptr %1, ptr %10, align 16, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = getelementptr inbounds i8, ptr %10, i64 48
  store ptr null, ptr %12, align 16, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %10, i64 128
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %11, i8 0, i64 24, i1 false)
  store ptr @default_is_low_prio_handler, ptr %13, align 16, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %10, i64 12
  store i8 0, ptr %14, align 4, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %10, i64 13
  store i8 0, ptr %15, align 1, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %10, i64 8
  store i32 0, ptr %16, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %10, i64 56
  store ptr null, ptr %17, align 8, !tbaa !16
  tail call void @us_internal_loop_link(ptr noundef %1, ptr noundef nonnull %10) #4
  br label %18

18:                                               ; preds = %7, %5
  %.0 = phi ptr [ %6, %5 ], [ %10, %7 ]
  ret ptr %.0
}

declare ptr @us_internal_create_ssl_socket_context(ptr noundef, i32 noundef, ptr noundef byval(%struct.us_socket_context_options_t) align 8) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare void @us_internal_loop_link(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"us_socket_context_t", !7, i64 0, !10, i64 8, !8, i64 12, !8, i64 13, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 48}
!12 = !{!6, !7, i64 128}
!13 = !{!6, !8, i64 12}
!14 = !{!6, !8, i64 13}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !7, i64 56}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass