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

; 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.conn_settings = type { i16, i32, i32, ptr, ptr, ptr, ptr, [10 x ptr], i64 }

@.str.72 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.76 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.77 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.78 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @handle_connection(i32 noundef %0, ptr noundef %1, ptr noundef byval(%struct.conn_settings) align 8 %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = call ptr @s2n_connection_new(i32 noundef 0)
  store ptr %10, ptr %7, align 8, !tbaa !9
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %17, label %13

13:                                               ; preds = %3
  call void @print_s2n_error(ptr noundef @.str.72)
  br label %14

14:                                               ; preds = %13
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %123

15:                                               ; No predecessors!
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16, %3
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = call i32 @s2n_setup_server_connection(ptr noundef %19, i32 noundef %20, ptr noundef %21, ptr noundef byval(%struct.conn_settings) align 8 %2)
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %18
  call void @print_s2n_error(ptr noundef @.str.73)
  call void @exit(i32 noundef 1) #5
  unreachable

25:                                               ; preds = %18
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds %struct.conn_settings, ptr %2, i32 0, i32 6
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = icmp ne ptr %29, null
  br i1 %30, label %51, label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = call i32 @negotiate(ptr noundef %32, i32 noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %51

36:                                               ; preds = %31
  %37 = load i16, ptr %2, align 8
  %38 = and i16 %37, 1
  %39 = zext i16 %38 to i32
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %36
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = call i32 @s2n_connection_client_cert_used(ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @print_s2n_error(ptr noundef @.str.74)
  br label %46

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

47:                                               ; preds = %46, %36
  br label %48

48:                                               ; preds = %47
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %123

49:                                               ; No predecessors!
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50, %31, %27
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  %54 = call i32 @s2n_connection_free_handshake(ptr noundef %53)
  %55 = icmp slt i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  call void @print_s2n_error(ptr noundef @.str.75)
  call void @exit(i32 noundef 1) #5
  unreachable

57:                                               ; preds = %52
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  %60 = load i16, ptr %2, align 8
  %61 = lshr i16 %60, 10
  %62 = and i16 %61, 1
  %63 = zext i16 %62 to i32
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %70

65:                                               ; preds = %59
  %66 = load ptr, ptr %7, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.conn_settings, ptr %2, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !14
  %69 = call i32 @https(ptr noundef %66, i32 noundef %68)
  br label %81

70:                                               ; preds = %59
  %71 = load i16, ptr %2, align 8
  %72 = lshr i16 %71, 2
  %73 = and i16 %72, 1
  %74 = zext i16 %73 to i32
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %80, label %76

76:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  store i8 0, ptr %9, align 1, !tbaa !15
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = call i32 @echo(ptr noundef %77, i32 noundef %78, ptr noundef %9)
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  br label %80

80:                                               ; preds = %76, %70
  br label %81

81:                                               ; preds = %80, %65
  %82 = getelementptr inbounds %struct.conn_settings, ptr %2, i32 0, i32 5
  %83 = load ptr, ptr %82, align 8, !tbaa !17
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %96

85:                                               ; preds = %81
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr %7, align 8, !tbaa !9
  %88 = getelementptr inbounds %struct.conn_settings, ptr %2, i32 0, i32 5
  %89 = load ptr, ptr %88, align 8, !tbaa !17
  %90 = call i32 @s2n_connection_serialize_out(ptr noundef %87, ptr noundef %89)
  %91 = icmp slt i32 %90, 0
  br i1 %91, label %92, label %93

92:                                               ; preds = %86
  call void @print_s2n_error(ptr noundef @.str.76)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %123

93:                                               ; preds = %86
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94
  br label %106

96:                                               ; preds = %81
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr %7, align 8, !tbaa !9
  %99 = load i32, ptr %5, align 4, !tbaa !5
  %100 = call i32 @wait_for_shutdown(ptr noundef %98, i32 noundef %99)
  %101 = icmp slt i32 %100, 0
  br i1 %101, label %102, label %103

102:                                              ; preds = %97
  call void @print_s2n_error(ptr noundef @.str.77)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %123

103:                                              ; preds = %97
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104
  br label %106

106:                                              ; preds = %105, %95
  br label %107

107:                                              ; preds = %106
  %108 = load ptr, ptr %7, align 8, !tbaa !9
  %109 = call i32 @s2n_connection_wipe(ptr noundef %108)
  %110 = icmp slt i32 %109, 0
  br i1 %110, label %111, label %112

111:                                              ; preds = %107
  call void @print_s2n_error(ptr noundef @.str.78)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %123

112:                                              ; preds = %107
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %7, align 8, !tbaa !9
  %117 = call i32 @s2n_connection_free(ptr noundef %116)
  %118 = icmp slt i32 %117, 0
  br i1 %118, label %119, label %120

119:                                              ; preds = %115
  call void @print_s2n_error(ptr noundef @.str.79)
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %123

120:                                              ; preds = %115
  br label %121

121:                                              ; preds = %120
  br label %122

122:                                              ; preds = %121
  store i32 0, ptr %4, align 4
  store i32 1, ptr %8, align 4
  br label %123

123:                                              ; preds = %122, %119, %111, %102, %92, %48, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %124 = load i32, ptr %4, align 4
  ret i32 %124
}

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

declare ptr @s2n_connection_new(i32 noundef) #3

declare void @print_s2n_error(ptr noundef) #3

declare i32 @s2n_setup_server_connection(ptr noundef, i32 noundef, ptr noundef, ptr noundef byval(%struct.conn_settings) align 8) #3

declare i32 @negotiate(ptr noundef, i32 noundef) #3

declare i32 @s2n_connection_client_cert_used(ptr noundef) #3

declare i32 @s2n_connection_free_handshake(ptr noundef) #3

declare i32 @https(ptr noundef, i32 noundef) #3

declare i32 @echo(ptr noundef, i32 noundef, ptr noundef) #3

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

declare i32 @s2n_connection_serialize_out(ptr noundef, ptr noundef) #3

declare i32 @wait_for_shutdown(ptr noundef, i32 noundef) #3

declare i32 @s2n_connection_wipe(ptr noundef) #3

declare i32 @s2n_connection_free(ptr noundef) #3

attributes #0 = { noreturn 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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, !10, i64 40}
!12 = !{!"conn_settings", !6, i64 0, !6, i64 0, !6, i64 0, !6, i64 0, !6, i64 0, !6, i64 0, !6, i64 0, !6, i64 0, !6, i64 1, !6, i64 1, !6, i64 1, !6, i64 4, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !13, i64 128}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{!16, !16, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!12, !10, i64 32}


; 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.conn_settings = type { i16, i32, i32, ptr, ptr, ptr, ptr, [10 x ptr], i64 }

@.str.72 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.73 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.76 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.77 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.78 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @handle_connection(i32 noundef %0, ptr noundef %1, ptr noundef byval(%struct.conn_settings) align 8 %2) local_unnamed_addr #1 {
  %4 = alloca i8, align 1
  %5 = tail call ptr @s2n_connection_new(i32 noundef 0) #4
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %6, label %7

6:                                                ; preds = %3
  tail call void @print_s2n_error(ptr noundef nonnull @.str.72) #4
  br label %56

7:                                                ; preds = %3
  %8 = tail call i32 @s2n_setup_server_connection(ptr noundef nonnull %5, i32 noundef %0, ptr noundef %1, ptr noundef nonnull byval(%struct.conn_settings) align 8 %2) #4
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  tail call void @print_s2n_error(ptr noundef nonnull @.str.73) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %2, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %.not18 = icmp eq ptr %13, null
  br i1 %.not18, label %14, label %22

14:                                               ; preds = %11
  %15 = tail call i32 @negotiate(ptr noundef nonnull %5, i32 noundef %0) #4
  %.not19 = icmp eq i32 %15, 0
  br i1 %.not19, label %22, label %16

16:                                               ; preds = %14
  %17 = load i16, ptr %2, align 8
  %18 = and i16 %17, 1
  %.not20 = icmp eq i16 %18, 0
  br i1 %.not20, label %56, label %19

19:                                               ; preds = %16
  %20 = tail call i32 @s2n_connection_client_cert_used(ptr noundef nonnull %5) #4
  %.not21 = icmp eq i32 %20, 0
  br i1 %.not21, label %21, label %56

21:                                               ; preds = %19
  tail call void @print_s2n_error(ptr noundef nonnull @.str.74) #4
  br label %56

22:                                               ; preds = %11, %14
  %23 = tail call i32 @s2n_connection_free_handshake(ptr noundef nonnull %5) #4
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  tail call void @print_s2n_error(ptr noundef nonnull @.str.75) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

26:                                               ; preds = %22
  %27 = load i16, ptr %2, align 8
  %28 = and i16 %27, 1024
  %.not22 = icmp eq i16 %28, 0
  br i1 %.not22, label %33, label %29

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %2, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = tail call i32 @https(ptr noundef nonnull %5, i32 noundef %31) #4
  br label %37

33:                                               ; preds = %26
  %34 = and i16 %27, 4
  %.not23 = icmp eq i16 %34, 0
  br i1 %.not23, label %35, label %37

35:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #4
  store i8 0, ptr %4, align 1, !tbaa !13
  %36 = call i32 @echo(ptr noundef nonnull %5, i32 noundef %0, ptr noundef nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #4
  br label %37

37:                                               ; preds = %33, %35, %29
  %38 = getelementptr inbounds i8, ptr %2, i64 32
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %.not24 = icmp eq ptr %39, null
  br i1 %.not24, label %44, label %40

40:                                               ; preds = %37
  %41 = call i32 @s2n_connection_serialize_out(ptr noundef nonnull %5, ptr noundef nonnull %39) #4
  %42 = icmp slt i32 %41, 0
  br i1 %42, label %43, label %48

43:                                               ; preds = %40
  call void @print_s2n_error(ptr noundef nonnull @.str.76) #4
  br label %56

44:                                               ; preds = %37
  %45 = call i32 @wait_for_shutdown(ptr noundef nonnull %5, i32 noundef %0) #4
  %46 = icmp slt i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  call void @print_s2n_error(ptr noundef nonnull @.str.77) #4
  br label %56

48:                                               ; preds = %40, %44
  %49 = call i32 @s2n_connection_wipe(ptr noundef nonnull %5) #4
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  call void @print_s2n_error(ptr noundef nonnull @.str.78) #4
  br label %56

52:                                               ; preds = %48
  %53 = call i32 @s2n_connection_free(ptr noundef nonnull %5) #4
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  call void @print_s2n_error(ptr noundef nonnull @.str.79) #4
  br label %56

56:                                               ; preds = %52, %19, %21, %16, %55, %51, %47, %43, %6
  %.0 = phi i32 [ -1, %43 ], [ -1, %51 ], [ -1, %55 ], [ -1, %47 ], [ -1, %6 ], [ -1, %16 ], [ -1, %21 ], [ -1, %19 ], [ 0, %52 ]
  ret i32 %.0
}

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

declare ptr @s2n_connection_new(i32 noundef) local_unnamed_addr #3

declare void @print_s2n_error(ptr noundef) local_unnamed_addr #3

declare i32 @s2n_setup_server_connection(ptr noundef, i32 noundef, ptr noundef, ptr noundef byval(%struct.conn_settings) align 8) local_unnamed_addr #3

declare i32 @negotiate(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @s2n_connection_client_cert_used(ptr noundef) local_unnamed_addr #3

declare i32 @s2n_connection_free_handshake(ptr noundef) local_unnamed_addr #3

declare i32 @https(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @echo(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @s2n_connection_serialize_out(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @wait_for_shutdown(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @s2n_connection_wipe(ptr noundef) local_unnamed_addr #3

declare i32 @s2n_connection_free(ptr noundef) local_unnamed_addr #3

attributes #0 = { noreturn 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 #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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, !10, i64 40}
!6 = !{!"conn_settings", !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !7, i64 1, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !8, i64 48, !11, i64 128}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!6, !10, i64 32}


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