; LLVM IR from aws/s2n-tls :: tests/testlib (s2n_test_server_client)

; 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_result = type { i32 }

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_validate_negotiate_result(i1 noundef zeroext, i1 noundef zeroext, ptr 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: nounwind uwtable
define dso_local i32 @s2n_negotiate_test_server_and_client_until_message(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca %struct.s2n_result, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca %struct.s2n_result, align 4
  %13 = alloca %struct.s2n_result, align 4
  %14 = alloca i32, align 4
  %15 = alloca %struct.s2n_result, align 4
  %16 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  store i8 0, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  store i8 0, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %74, %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = call i32 @s2n_negotiate_until_message(ptr noundef %18, ptr noundef %10, i32 noundef %19)
  %21 = getelementptr inbounds %struct.s2n_result, ptr %12, i32 0, i32 0
  store i32 %20, ptr %21, align 4
  %22 = getelementptr inbounds %struct.s2n_result, ptr %12, i32 0, i32 0
  %23 = load i32, ptr %22, align 4
  %24 = call zeroext i1 @s2n_result_is_ok(i32 %23)
  %25 = zext i1 %24 to i8
  store i8 %25, ptr %11, align 1, !tbaa !11
  br label %26

26:                                               ; preds = %17
  %27 = load i8, ptr %11, align 1, !tbaa !11, !range !13, !noundef !14
  %28 = trunc i8 %27 to i1
  %29 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %30 = trunc i8 %29 to i1
  %31 = call i32 @s2n_validate_negotiate_result(i1 noundef zeroext %28, i1 noundef zeroext %30, ptr noundef %9)
  %32 = getelementptr inbounds %struct.s2n_result, ptr %13, i32 0, i32 0
  store i32 %31, ptr %32, align 4
  %33 = getelementptr inbounds %struct.s2n_result, ptr %13, i32 0, i32 0
  %34 = load i32, ptr %33, align 4
  %35 = call zeroext i1 @s2n_result_is_ok(i32 %34)
  br i1 %35, label %38, label %36

36:                                               ; preds = %26
  %37 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %37, align 4, !tbaa !15
  store i32 1, ptr %14, align 4
  br label %64

38:                                               ; preds = %26
  br label %39

39:                                               ; preds = %38
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = call i32 @s2n_negotiate_until_message(ptr noundef %41, ptr noundef %10, i32 noundef %42)
  %44 = getelementptr inbounds %struct.s2n_result, ptr %15, i32 0, i32 0
  store i32 %43, ptr %44, align 4
  %45 = getelementptr inbounds %struct.s2n_result, ptr %15, i32 0, i32 0
  %46 = load i32, ptr %45, align 4
  %47 = call zeroext i1 @s2n_result_is_ok(i32 %46)
  %48 = zext i1 %47 to i8
  store i8 %48, ptr %11, align 1, !tbaa !11
  br label %49

49:                                               ; preds = %40
  %50 = load i8, ptr %11, align 1, !tbaa !11, !range !13, !noundef !14
  %51 = trunc i8 %50 to i1
  %52 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %53 = trunc i8 %52 to i1
  %54 = call i32 @s2n_validate_negotiate_result(i1 noundef zeroext %51, i1 noundef zeroext %53, ptr noundef %8)
  %55 = getelementptr inbounds %struct.s2n_result, ptr %16, i32 0, i32 0
  store i32 %54, ptr %55, align 4
  %56 = getelementptr inbounds %struct.s2n_result, ptr %16, i32 0, i32 0
  %57 = load i32, ptr %56, align 4
  %58 = call zeroext i1 @s2n_result_is_ok(i32 %57)
  br i1 %58, label %61, label %59

59:                                               ; preds = %49
  %60 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 -1, ptr %60, align 4, !tbaa !15
  store i32 1, ptr %14, align 4
  br label %64

61:                                               ; preds = %49
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  store i32 0, ptr %14, align 4
  br label %64

64:                                               ; preds = %63, %59, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  %65 = load i32, ptr %14, align 4
  switch i32 %65, label %78 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66
  %68 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %69 = trunc i8 %68 to i1
  br i1 %69, label %70, label %74

70:                                               ; preds = %67
  %71 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %72 = trunc i8 %71 to i1
  %73 = xor i1 %72, true
  br label %74

74:                                               ; preds = %70, %67
  %75 = phi i1 [ true, %67 ], [ %73, %70 ]
  br i1 %75, label %17, label %76, !llvm.loop !17

76:                                               ; preds = %74
  %77 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 0, ptr %77, align 4, !tbaa !15
  store i32 1, ptr %14, align 4
  br label %78

78:                                               ; preds = %76, %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  %79 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  %80 = load i32, ptr %79, align 4
  ret i32 %80
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 }

!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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_validate_negotiate_result(i1 noundef zeroext, i1 noundef zeroext, ptr 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: nounwind uwtable
define dso_local noundef i32 @s2n_negotiate_test_server_and_client_until_message(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #4
  store i8 0, ptr %4, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #4
  store i8 0, ptr %5, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %21, %3
  %8 = call i32 @s2n_negotiate_until_message(ptr noundef %1, ptr noundef nonnull %6, i32 noundef %2) #4
  %9 = call zeroext i1 @s2n_result_is_ok(i32 %8)
  %10 = load i8, ptr %4, align 1, !tbaa !5, !range !11, !noundef !12
  %11 = trunc nuw i8 %10 to i1
  %12 = call i32 @s2n_validate_negotiate_result(i1 noundef zeroext %9, i1 noundef zeroext %11, ptr noundef nonnull %5)
  %13 = call zeroext i1 @s2n_result_is_ok(i32 %12)
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %7
  %15 = call i32 @s2n_negotiate_until_message(ptr noundef %0, ptr noundef nonnull %6, i32 noundef %2) #4
  %16 = call zeroext i1 @s2n_result_is_ok(i32 %15)
  %17 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %18 = trunc nuw i8 %17 to i1
  %19 = call i32 @s2n_validate_negotiate_result(i1 noundef zeroext %16, i1 noundef zeroext %18, ptr noundef nonnull %4)
  %20 = call zeroext i1 @s2n_result_is_ok(i32 %19)
  br i1 %20, label %21, label %.critedge

21:                                               ; preds = %14
  %22 = load i8, ptr %5, align 1, !tbaa !5, !range !11, !noundef !12
  %23 = trunc nuw i8 %22 to i1
  %24 = load i8, ptr %4, align 1, !range !11
  %25 = trunc nuw i8 %24 to i1
  %26 = select i1 %23, i1 %25, i1 false
  br i1 %26, label %.critedge, label %7, !llvm.loop !13

.critedge:                                        ; preds = %7, %21, %14
  %.sroa.09.2 = phi i32 [ -1, %14 ], [ 0, %21 ], [ -1, %7 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #4
  ret i32 %.sroa.09.2
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 }

!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 = !{!"_Bool", !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 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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