; 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_skip_whitespace(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 i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca %struct.s2n_result, 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
  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 %122

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
  br label %40

40:                                               ; preds = %84, %36
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.s2n_stuffer, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.s2n_stuffer, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !12
  %47 = sub i32 %43, %46
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %85

49:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s2n_stuffer, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.s2n_blob, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.s2n_stuffer, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !12
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %53, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !18
  store i8 %59, ptr %9, align 1, !tbaa !18
  %60 = load i8, ptr %9, align 1, !tbaa !18
  %61 = zext i8 %60 to i32
  %62 = icmp eq i32 %61, 32
  br i1 %62, label %75, label %63

63:                                               ; preds = %49
  %64 = load i8, ptr %9, align 1, !tbaa !18
  %65 = zext i8 %64 to i32
  %66 = icmp eq i32 %65, 9
  br i1 %66, label %75, label %67

67:                                               ; preds = %63
  %68 = load i8, ptr %9, align 1, !tbaa !18
  %69 = zext i8 %68 to i32
  %70 = icmp eq i32 %69, 10
  br i1 %70, label %75, label %71

71:                                               ; preds = %67
  %72 = load i8, ptr %9, align 1, !tbaa !18
  %73 = zext i8 %72 to i32
  %74 = icmp eq i32 %73, 13
  br i1 %74, label %75, label %80

75:                                               ; preds = %71, %67, %63, %49
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.s2n_stuffer, ptr %76, i32 0, i32 1
  %78 = load i32, ptr %77, align 8, !tbaa !12
  %79 = add i32 %78, 1
  store i32 %79, ptr %77, align 8, !tbaa !12
  br label %81

80:                                               ; preds = %71
  store i32 5, ptr %10, align 4
  br label %82

81:                                               ; preds = %75
  store i32 0, ptr %10, align 4
  br label %82

82:                                               ; preds = %81, %80
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #5
  %83 = load i32, ptr %10, align 4
  switch i32 %83, label %124 [
    i32 0, label %84
    i32 5, label %85
  ]

84:                                               ; preds = %82
  br label %40, !llvm.loop !19

85:                                               ; preds = %82, %40
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %95

88:                                               ; preds = %85
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.s2n_stuffer, ptr %89, i32 0, i32 1
  %91 = load i32, ptr %90, align 8, !tbaa !12
  %92 = load i32, ptr %8, align 4, !tbaa !15
  %93 = sub i32 %91, %92
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %93, ptr %94, align 4, !tbaa !15
  br label %95

95:                                               ; preds = %88, %85
  br label %96

96:                                               ; preds = %95
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = call i32 @s2n_stuffer_validate(ptr noundef %97)
  %99 = getelementptr inbounds %struct.s2n_result, ptr %12, i32 0, i32 0
  store i32 %98, ptr %99, align 4
  %100 = getelementptr inbounds %struct.s2n_result, ptr %12, i32 0, i32 0
  %101 = load i32, ptr %100, align 4
  %102 = call zeroext i1 @s2n_result_is_ok(i32 %101)
  %103 = xor i1 %102, true
  %104 = xor i1 %103, true
  %105 = zext i1 %104 to i32
  %106 = sext i32 %105 to i64
  %107 = call i64 @llvm.expect.i64(i64 %106, i64 1)
  %108 = icmp ne i64 %107, 0
  br i1 %108, label %109, label %111

109:                                              ; preds = %96
  %110 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  store i32 0, ptr %110, align 4, !tbaa !9
  br label %113

111:                                              ; preds = %96
  %112 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  store i32 -1, ptr %112, align 4, !tbaa !9
  br label %113

113:                                              ; preds = %111, %109
  %114 = getelementptr inbounds %struct.s2n_result, ptr %11, i32 0, i32 0
  %115 = load i32, ptr %114, align 4
  %116 = call zeroext i1 @s2n_result_is_ok(i32 %115)
  br i1 %116, label %118, label %117

117:                                              ; preds = %113
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %121

118:                                              ; preds = %113
  br label %119

119:                                              ; preds = %118
  br label %120

120:                                              ; preds = %119
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %121

121:                                              ; preds = %120, %117
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %122

122:                                              ; preds = %121, %34
  %123 = load i32, ptr %3, align 4
  ret i32 %123

124:                                              ; preds = %82
  unreachable
}

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}
!16 = !{!13, !11, i64 28}
!17 = !{!13, !6, i64 0}
!18 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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: 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 range(i32 -1, 1) i32 @s2n_stuffer_skip_whitespace(ptr noundef %0, ptr noundef writeonly %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 %26

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 28
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %.not36 = icmp eq i32 %10, %8
  br i1 %.not36, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %11 = load ptr, ptr %0, align 8, !tbaa !13
  br label %12

12:                                               ; preds = %.lr.ph, %17
  %13 = phi i32 [ %8, %.lr.ph ], [ %18, %17 ]
  %14 = zext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %11, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !14
  switch i8 %16, label %.thread [
    i8 32, label %17
    i8 13, label %17
    i8 10, label %17
    i8 9, label %17
  ]

17:                                               ; preds = %12, %12, %12, %12
  %18 = add i32 %13, 1
  store i32 %18, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i32 %10, %18
  br i1 %.not, label %.thread, label %12

.thread:                                          ; preds = %17, %12, %6
  %19 = phi i32 [ %8, %6 ], [ %10, %17 ], [ %13, %12 ]
  %.not30 = icmp eq ptr %1, null
  br i1 %.not30, label %22, label %20

20:                                               ; preds = %.thread
  %21 = sub i32 %19, %8
  store i32 %21, ptr %1, align 4, !tbaa !15
  br label %22

22:                                               ; preds = %.thread, %20
  %23 = tail call i32 @s2n_stuffer_validate(ptr noundef nonnull %0) #3
  %24 = tail call zeroext i1 @s2n_result_is_ok(i32 %23)
  %not.34 = xor i1 %24, true
  %.31 = sext i1 %not.34 to i32
  %25 = tail call zeroext i1 @s2n_result_is_ok(i32 %.31)
  %not.35 = xor i1 %25, true
  %.0 = sext i1 %not.35 to i32
  br label %26

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

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}
!12 = !{!6, !11, i64 28}
!13 = !{!6, !8, i64 0}
!14 = !{!9, !9, i64 0}
!15 = !{!11, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass