; LLVM IR from aws/s2n-tls :: tests/unit (s2n_server_hello_retry_test)

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

@s2n_use_color_in_output = external dso_local global i8, align 1
@test_count = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [101 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [86 x i8], align 1
@s2n_errno = external thread_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [59 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: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

declare i32 @s2n_print_stacktrace(ptr noundef) #2

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

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

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_client_hello_poll_cb(ptr noundef %0, ptr noundef %1) #6 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  store ptr null, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.client_hello_context, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %15, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.client_hello_context, ptr %18, i32 0, i32 2
  %20 = load i8, ptr %19, align 4, !tbaa !13, !range !14, !noundef !15
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %85

22:                                               ; preds = %12
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr @test_count, align 4, !tbaa !16
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @test_count, align 4, !tbaa !16
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call i32 @s2n_client_hello_cb_done(ptr noundef %26)
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %82

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %32 = call ptr @__errno_location() #8
  %33 = load i32, ptr %32, align 4, !tbaa !16
  store i32 %33, ptr %8, align 4, !tbaa !16
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = call i32 @s2n_print_stacktrace(ptr noundef %34)
  %36 = load i8, ptr @s2n_use_color_in_output, align 1, !tbaa !17, !range !14, !noundef !15
  %37 = trunc i8 %36 to i1
  br i1 %37, label %38, label %60

38:                                               ; preds = %31
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call i32 @fileno(ptr noundef %39) #7
  %41 = call i32 @isatty(i32 noundef %40) #7
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %60

43:                                               ; preds = %38
  %44 = load i32, ptr %8, align 4, !tbaa !16
  %45 = call ptr @__errno_location() #8
  store i32 %44, ptr %45, align 4, !tbaa !16
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = load i32, ptr @test_count, align 4, !tbaa !16
  %48 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = call ptr @s2n_strerror(i32 noundef %49, ptr noundef @.str.3)
  %51 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %52 = load i32, ptr %51, align 4, !tbaa !16
  %53 = call ptr @s2n_strerror_debug(i32 noundef %52, ptr noundef @.str.3)
  %54 = call ptr @__errno_location() #8
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = call ptr @strerror(i32 noundef %55) #7
  %57 = call ptr @__errno_location() #8
  %58 = load i32, ptr %57, align 4, !tbaa !16
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str, i32 noundef %47, ptr noundef @.str.9, ptr noundef @.str.2, i32 noundef 90, ptr noundef %50, ptr noundef %53, ptr noundef %56, i32 noundef %58) #7
  br label %77

60:                                               ; preds = %38, %31
  %61 = load i32, ptr %8, align 4, !tbaa !16
  %62 = call ptr @__errno_location() #8
  store i32 %61, ptr %62, align 4, !tbaa !16
  %63 = load ptr, ptr @stderr, align 8, !tbaa !5
  %64 = load i32, ptr @test_count, align 4, !tbaa !16
  %65 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %66 = load i32, ptr %65, align 4, !tbaa !16
  %67 = call ptr @s2n_strerror(i32 noundef %66, ptr noundef @.str.3)
  %68 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %69 = load i32, ptr %68, align 4, !tbaa !16
  %70 = call ptr @s2n_strerror_debug(i32 noundef %69, ptr noundef @.str.3)
  %71 = call ptr @__errno_location() #8
  %72 = load i32, ptr %71, align 4, !tbaa !16
  %73 = call ptr @strerror(i32 noundef %72) #7
  %74 = call ptr @__errno_location() #8
  %75 = load i32, ptr %74, align 4, !tbaa !16
  %76 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %63, ptr noundef @.str.4, i32 noundef %64, ptr noundef @.str.9, ptr noundef @.str.2, i32 noundef 90, ptr noundef %67, ptr noundef %70, ptr noundef %73, i32 noundef %75) #7
  br label %77

77:                                               ; preds = %60, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  call void @exit(i32 noundef 1) #9
  unreachable

80:                                               ; No predecessors!
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81, %23
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

85:                                               ; preds = %12
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

86:                                               ; preds = %85, %84, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %87 = load i32, ptr %3, align 4
  ret i32 %87
}

declare i32 @s2n_client_hello_cb_done(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 "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 speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { 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 }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"client_hello_context", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!11, !11, i64 0}
!17 = !{!12, !12, 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"

@s2n_use_color_in_output = external dso_local local_unnamed_addr global i8, align 1
@test_count = external dso_local local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [101 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [86 x i8], align 1
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [59 x i8], align 1

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

declare i32 @s2n_print_stacktrace(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fileno(ptr nocapture noundef) local_unnamed_addr #3

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

declare ptr @s2n_strerror(i32 noundef, ptr noundef) local_unnamed_addr #1

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

declare ptr @s2n_strerror_debug(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_client_hello_poll_cb(ptr noundef %0, ptr noundef %1) local_unnamed_addr #6 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %39, label %4

4:                                                ; preds = %2
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr %1, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i8, ptr %7, align 4, !tbaa !11, !range !12, !noundef !13
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %10, label %39

10:                                               ; preds = %4
  %11 = load i32, ptr @test_count, align 4, !tbaa !14
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @test_count, align 4, !tbaa !14
  %13 = tail call i32 @s2n_client_hello_cb_done(ptr noundef %0) #7
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %39

15:                                               ; preds = %10
  %16 = tail call ptr @__errno_location() #8
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = load ptr, ptr @stderr, align 8, !tbaa !15
  %19 = tail call i32 @s2n_print_stacktrace(ptr noundef %18) #7
  %20 = load i8, ptr @s2n_use_color_in_output, align 1, !tbaa !17, !range !12, !noundef !13
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %22, label %26

22:                                               ; preds = %15
  %23 = load ptr, ptr @stderr, align 8, !tbaa !15
  %24 = tail call i32 @fileno(ptr noundef %23) #7
  %25 = tail call i32 @isatty(i32 noundef %24) #7
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %26, label %27

26:                                               ; preds = %22, %15
  br label %27

27:                                               ; preds = %22, %26
  %.str.4.sink = phi ptr [ @.str.4, %26 ], [ @.str, %22 ]
  store i32 %17, ptr %16, align 4, !tbaa !14
  %28 = load ptr, ptr @stderr, align 8, !tbaa !15
  %29 = load i32, ptr @test_count, align 4, !tbaa !14
  %30 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = tail call ptr @s2n_strerror(i32 noundef %31, ptr noundef nonnull @.str.3) #7
  %33 = load i32, ptr %30, align 4, !tbaa !14
  %34 = tail call ptr @s2n_strerror_debug(i32 noundef %33, ptr noundef nonnull @.str.3) #7
  %35 = load i32, ptr %16, align 4, !tbaa !14
  %36 = tail call ptr @strerror(i32 noundef %35) #7
  %37 = load i32, ptr %16, align 4, !tbaa !14
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull %.str.4.sink, i32 noundef %29, ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.2, i32 noundef 90, ptr noundef %32, ptr noundef %34, ptr noundef %36, i32 noundef %37) #9
  tail call void @exit(i32 noundef 1) #10
  unreachable

39:                                               ; preds = %4, %10, %2
  %.0 = phi i32 [ -1, %2 ], [ 0, %10 ], [ 0, %4 ]
  ret i32 %.0
}

declare i32 @s2n_client_hello_cb_done(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { 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 }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { cold nounwind }
attributes #10 = { 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, !7, i64 0}
!6 = !{!"client_hello_context", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!10, !10, i64 0}


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