; 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: nounwind uwtable
define dso_local i32 @s2n_negotiate_test_server_and_client(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca %struct.s2n_result, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.s2n_result, 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 1, ptr %6) #4
  store i8 0, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %60, %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i32 @s2n_negotiate(ptr noundef %14, ptr noundef %8)
  %16 = icmp sge i32 %15, 0
  %17 = zext i1 %16 to i8
  store i8 %17, ptr %9, align 1, !tbaa !9
  br label %18

18:                                               ; preds = %13
  %19 = load i8, ptr %9, align 1, !tbaa !9, !range !13, !noundef !14
  %20 = trunc i8 %19 to i1
  %21 = load i8, ptr %6, align 1, !tbaa !9, !range !13, !noundef !14
  %22 = trunc i8 %21 to i1
  %23 = call i32 @s2n_validate_negotiate_result(i1 noundef zeroext %20, i1 noundef zeroext %22, ptr noundef %7)
  %24 = getelementptr inbounds %struct.s2n_result, ptr %10, i32 0, i32 0
  store i32 %23, ptr %24, align 4
  %25 = getelementptr inbounds %struct.s2n_result, ptr %10, i32 0, i32 0
  %26 = load i32, ptr %25, align 4
  %27 = call zeroext i1 @s2n_result_is_ok(i32 %26)
  br i1 %27, label %29, label %28

28:                                               ; preds = %18
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %50

29:                                               ; preds = %18
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call i32 @s2n_negotiate(ptr noundef %32, ptr noundef %8)
  %34 = icmp sge i32 %33, 0
  %35 = zext i1 %34 to i8
  store i8 %35, ptr %9, align 1, !tbaa !9
  br label %36

36:                                               ; preds = %31
  %37 = load i8, ptr %9, align 1, !tbaa !9, !range !13, !noundef !14
  %38 = trunc i8 %37 to i1
  %39 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %40 = trunc i8 %39 to i1
  %41 = call i32 @s2n_validate_negotiate_result(i1 noundef zeroext %38, i1 noundef zeroext %40, ptr noundef %6)
  %42 = getelementptr inbounds %struct.s2n_result, ptr %12, i32 0, i32 0
  store i32 %41, ptr %42, align 4
  %43 = getelementptr inbounds %struct.s2n_result, ptr %12, i32 0, i32 0
  %44 = load i32, ptr %43, align 4
  %45 = call zeroext i1 @s2n_result_is_ok(i32 %44)
  br i1 %45, label %47, label %46

46:                                               ; preds = %36
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %50

47:                                               ; preds = %36
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  store i32 0, ptr %11, align 4
  br label %50

50:                                               ; preds = %49, %46, %28
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  %51 = load i32, ptr %11, align 4
  switch i32 %51, label %63 [
    i32 0, label %52
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %55 = trunc i8 %54 to i1
  br i1 %55, label %56, label %60

56:                                               ; preds = %53
  %57 = load i8, ptr %6, align 1, !tbaa !9, !range !13, !noundef !14
  %58 = trunc i8 %57 to i1
  %59 = xor i1 %58, true
  br label %60

60:                                               ; preds = %56, %53
  %61 = phi i1 [ true, %53 ], [ %59, %56 ]
  br i1 %61, label %13, label %62, !llvm.loop !15

62:                                               ; preds = %60
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %63

63:                                               ; preds = %62, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  %64 = load i32, ptr %3, align 4
  ret i32 %64
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_validate_negotiate_result(i1 noundef zeroext, i1 noundef zeroext, ptr noundef) #0

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

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 = { 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 #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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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: nounwind uwtable
define dso_local noundef i32 @s2n_negotiate_test_server_and_client(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  store i8 0, ptr %3, align 1, !tbaa !5
  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 4, ptr nonnull %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %6

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_validate_negotiate_result(i1 noundef zeroext, i1 noundef zeroext, ptr noundef) local_unnamed_addr #0

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

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 = { mustprogress 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 = { 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 #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