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

; 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_blob = type { ptr, i32, i32, i8 }
%struct.s2n_socket_write_io_context = type { i32, i8, i32 }

@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.75 = external hidden unnamed_addr constant [91 x i8], align 1

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

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

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

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

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

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

declare i32 @s2n_calculate_stacktrace() #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_connection_set_write_fd(ptr noundef %0, i32 noundef %1) #5 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.s2n_blob, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #6
  call void @llvm.memset.p0.i64(ptr align 8 %6, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %46, label %13

13:                                               ; preds = %10
  br label %14

14:                                               ; preds = %13
  br label %15

15:                                               ; preds = %14
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %17 = getelementptr inbounds %struct.s2n_debug_info, ptr %16, i32 0, i32 0
  store ptr @.str.75, ptr %17, align 8, !tbaa !11
  %18 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %19 = getelementptr inbounds %struct.s2n_debug_info, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %20, i64 21
  %22 = call ptr @strrchr(ptr noundef %21, i32 noundef 47) #7
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %31

24:                                               ; preds = %15
  %25 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %26 = getelementptr inbounds %struct.s2n_debug_info, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %27, i64 21
  %29 = call ptr @strrchr(ptr noundef %28, i32 noundef 47) #7
  %30 = getelementptr inbounds i8, ptr %29, i64 1
  br label %36

31:                                               ; preds = %15
  %32 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %33 = getelementptr inbounds %struct.s2n_debug_info, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %34, i64 21
  br label %36

36:                                               ; preds = %31, %24
  %37 = phi ptr [ %30, %24 ], [ %35, %31 ]
  %38 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %39 = getelementptr inbounds %struct.s2n_debug_info, ptr %38, i32 0, i32 1
  store ptr %37, ptr %39, align 8, !tbaa !13
  %40 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %40, align 4, !tbaa !9
  %41 = call i32 @s2n_calculate_stacktrace()
  br label %42

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %110

44:                                               ; No predecessors!
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45, %10
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = call i32 @s2n_alloc(ptr noundef %6, i32 noundef 12)
  %51 = icmp sgt i32 %50, -1
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %110

53:                                               ; preds = %49
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  %56 = getelementptr inbounds %struct.s2n_blob, ptr %6, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.s2n_socket_write_io_context, ptr %59, i32 0, i32 0
  store i32 %58, ptr %60, align 4, !tbaa !16
  br label %61

61:                                               ; preds = %55
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = call i32 @s2n_connection_set_send_cb(ptr noundef %62, ptr noundef @s2n_socket_write)
  %64 = icmp sgt i32 %63, -1
  br i1 %64, label %66, label %65

65:                                               ; preds = %61
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %110

66:                                               ; preds = %61
  br label %67

67:                                               ; preds = %66
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = call i32 @s2n_connection_set_send_ctx(ptr noundef %70, ptr noundef %71)
  %73 = icmp sgt i32 %72, -1
  br i1 %73, label %75, label %74

74:                                               ; preds = %69
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %110

75:                                               ; preds = %69
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load i32, ptr %78, align 8
  %80 = and i32 %79, -257
  %81 = or i32 %80, 256
  store i32 %81, ptr %78, align 8
  br label %82

82:                                               ; preds = %77
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = call i32 @s2n_socket_write_snapshot(ptr noundef %83)
  %85 = icmp sgt i32 %84, -1
  br i1 %85, label %87, label %86

86:                                               ; preds = %82
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %110

87:                                               ; preds = %82
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #6
  store i8 0, ptr %9, align 1, !tbaa !18
  %90 = load i32, ptr %5, align 4, !tbaa !9
  %91 = call i32 @s2n_socket_is_ipv6(i32 noundef %90, ptr noundef %9)
  %92 = icmp eq i32 0, %91
  br i1 %92, label %93, label %105

93:                                               ; preds = %89
  %94 = load i8, ptr %9, align 1, !tbaa !18
  %95 = zext i8 %94 to i32
  %96 = icmp ne i32 %95, 0
  %97 = zext i1 %96 to i64
  %98 = select i1 %96, i32 1, i32 0
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = load i32, ptr %99, align 8
  %101 = and i32 %98, 1
  %102 = shl i32 %101, 5
  %103 = and i32 %100, -33
  %104 = or i32 %103, %102
  store i32 %104, ptr %99, align 8
  br label %105

105:                                              ; preds = %93, %89
  %106 = load ptr, ptr %4, align 8, !tbaa !5
  %107 = load i32, ptr %106, align 8
  %108 = and i32 %107, -129
  %109 = or i32 %108, 0
  store i32 %109, ptr %106, align 8
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #6
  br label %110

110:                                              ; preds = %105, %86, %74, %65, %52, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #6
  %111 = load i32, ptr %3, align 4
  ret i32 %111
}

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

declare i32 @s2n_socket_write_snapshot(ptr noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !6, i64 0}
!15 = !{!"s2n_blob", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!16 = !{!17, !10, i64 0}
!17 = !{!"s2n_socket_write_io_context", !10, i64 0, !10, i64 4, !10, i64 8}
!18 = !{!7, !7, i64 0}


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

@_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.75 = external hidden unnamed_addr constant [91 x i8], align 1

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

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

declare i32 @s2n_alloc(ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

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

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_connection_set_write_fd(ptr noundef %0, i32 noundef %1) local_unnamed_addr #5 {
  %3 = alloca %struct.s2n_blob, align 8
  %4 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %13

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

13:                                               ; preds = %2
  %14 = call i32 @s2n_alloc(ptr noundef nonnull %3, i32 noundef 12) #6
  %15 = icmp sgt i32 %14, -1
  br i1 %15, label %16, label %39

16:                                               ; preds = %13
  %17 = load ptr, ptr %3, align 8, !tbaa !13
  store i32 %1, ptr %17, align 4, !tbaa !15
  %18 = call i32 @s2n_connection_set_send_cb(ptr noundef nonnull %0, ptr noundef nonnull @s2n_socket_write)
  %19 = icmp sgt i32 %18, -1
  br i1 %19, label %20, label %39

20:                                               ; preds = %16
  %21 = call i32 @s2n_connection_set_send_ctx(ptr noundef nonnull %0, ptr noundef nonnull %17)
  %22 = icmp sgt i32 %21, -1
  br i1 %22, label %23, label %39

23:                                               ; preds = %20
  %24 = load i32, ptr %0, align 8
  %25 = or i32 %24, 256
  store i32 %25, ptr %0, align 8
  %26 = call i32 @s2n_socket_write_snapshot(ptr noundef nonnull %0) #6
  %27 = icmp sgt i32 %26, -1
  br i1 %27, label %28, label %39

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #6
  store i8 0, ptr %4, align 1, !tbaa !17
  %29 = call i32 @s2n_socket_is_ipv6(i32 noundef %1, ptr noundef nonnull %4) #6
  %30 = icmp eq i32 %29, 0
  %.pre = load i32, ptr %0, align 8
  br i1 %30, label %31, label %36

31:                                               ; preds = %28
  %32 = load i8, ptr %4, align 1, !tbaa !17
  %.not14.not = icmp eq i8 %32, 0
  %33 = select i1 %.not14.not, i32 0, i32 32
  %34 = and i32 %.pre, -33
  %35 = or disjoint i32 %34, %33
  br label %36

36:                                               ; preds = %31, %28
  %37 = phi i32 [ %35, %31 ], [ %.pre, %28 ]
  %38 = and i32 %37, -129
  store i32 %38, ptr %0, align 8
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #6
  br label %39

39:                                               ; preds = %23, %20, %16, %13, %36, %5
  %.0 = phi i32 [ 0, %36 ], [ -1, %5 ], [ -1, %13 ], [ -1, %16 ], [ -1, %20 ], [ -1, %23 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #6
  ret i32 %.0
}

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

declare i32 @s2n_socket_write_snapshot(ptr noundef) local_unnamed_addr #2

declare i32 @s2n_socket_is_ipv6(i32 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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, !7, i64 0}
!14 = !{!"s2n_blob", !7, i64 0, !12, i64 8, !12, i64 12, !12, i64 16}
!15 = !{!16, !12, i64 0}
!16 = !{!"s2n_socket_write_io_context", !12, i64 0, !12, i64 4, !12, i64 8}
!17 = !{!8, !8, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass