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

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

; 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

declare i32 @s2n_stuffer_validate(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

; 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_stuffer_peek_check_for_str(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.s2n_result, align 4
  %7 = alloca %struct.s2n_result, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.s2n_result, align 4
  %11 = alloca %struct.s2n_result, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i32 @s2n_stuffer_validate(ptr noundef %14)
  %16 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 %15, ptr %16, align 4
  %17 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  %18 = load i32, ptr %17, align 4
  %19 = call zeroext i1 @s2n_result_is_ok(i32 %18)
  %20 = xor i1 %19, true
  %21 = xor i1 %20, true
  %22 = zext i1 %21 to i32
  %23 = sext i32 %22 to i64
  %24 = call i64 @llvm.expect.i64(i64 %23, i64 1)
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %13
  %27 = getelementptr inbounds %struct.s2n_result, ptr %6, i32 0, i32 0
  store i32 0, ptr %27, align 4, !tbaa !9
  br label %30

28:                                               ; preds = %13
  %29 = getelementptr inbounds %struct.s2n_result, ptr %6, i32 0, i32 0
  store i32 -1, ptr %29, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %28, %26
  %31 = getelementptr inbounds %struct.s2n_result, ptr %6, i32 0, i32 0
  %32 = load i32, ptr %31, align 4
  %33 = call zeroext i1 @s2n_result_is_ok(i32 %32)
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 -1, ptr %3, align 4
  br label %73

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.s2n_stuffer, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !12
  store i32 %39, ptr %8, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call i32 @s2n_stuffer_read_expected_str(ptr noundef %40, ptr noundef %41)
  store i32 %42, ptr %9, align 4, !tbaa !15
  %43 = load i32, ptr %8, align 4, !tbaa !15
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.s2n_stuffer, ptr %44, i32 0, i32 1
  store i32 %43, ptr %45, align 8, !tbaa !12
  br label %46

46:                                               ; preds = %36
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call i32 @s2n_stuffer_validate(ptr noundef %47)
  %49 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  store i32 %48, ptr %49, align 4
  %50 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  %51 = load i32, ptr %50, align 4
  %52 = call zeroext i1 @s2n_result_is_ok(i32 %51)
  %53 = xor i1 %52, true
  %54 = xor i1 %53, true
  %55 = zext i1 %54 to i32
  %56 = sext i32 %55 to i64
  %57 = call i64 @llvm.expect.i64(i64 %56, i64 1)
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %46
  %60 = getelementptr inbounds %struct.s2n_result, ptr %10, i32 0, i32 0
  store i32 0, ptr %60, align 4, !tbaa !9
  br label %63

61:                                               ; preds = %46
  %62 = getelementptr inbounds %struct.s2n_result, ptr %10, i32 0, i32 0
  store i32 -1, ptr %62, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %61, %59
  %64 = getelementptr inbounds %struct.s2n_result, ptr %10, i32 0, i32 0
  %65 = load i32, ptr %64, align 4
  %66 = call zeroext i1 @s2n_result_is_ok(i32 %65)
  br i1 %66, label %68, label %67

67:                                               ; preds = %63
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %72

68:                                               ; preds = %63
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %9, align 4, !tbaa !15
  store i32 %71, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %72

72:                                               ; preds = %70, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %73

73:                                               ; preds = %72, %34
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

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

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 = { "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 willreturn memory(none) }
attributes #4 = { 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 #5 = { 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 = !{!"", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 24}
!13 = !{!"s2n_stuffer", !14, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 36, !11, i64 36}
!14 = !{!"s2n_blob", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!15 = !{!11, !11, 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"

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

declare i32 @s2n_stuffer_validate(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_stuffer_peek_check_for_str(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = tail call i32 @s2n_stuffer_validate(ptr noundef %0) #3
  %4 = tail call zeroext i1 @s2n_result_is_ok(i32 %3)
  %not. = xor i1 %4, true
  %. = sext i1 %not. to i32
  %5 = tail call zeroext i1 @s2n_result_is_ok(i32 %.)
  br i1 %5, label %6, label %13

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = tail call i32 @s2n_stuffer_read_expected_str(ptr noundef %0, ptr noundef %1)
  store i32 %8, ptr %7, align 8, !tbaa !5
  %10 = tail call i32 @s2n_stuffer_validate(ptr noundef %0) #3
  %11 = tail call zeroext i1 @s2n_result_is_ok(i32 %10)
  %not.12 = xor i1 %11, true
  %.11 = sext i1 %not.12 to i32
  %12 = tail call zeroext i1 @s2n_result_is_ok(i32 %.11)
  %.0 = select i1 %12, i32 %9, i32 -1
  br label %13

13:                                               ; preds = %2, %6
  %.1 = phi i32 [ %.0, %6 ], [ -1, %2 ]
  ret i32 %.1
}

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

attributes #0 = { 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 #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 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 = { 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, !11, i64 24}
!6 = !{!"s2n_stuffer", !7, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 36, !11, i64 36}
!7 = !{!"s2n_blob", !8, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}


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