; LLVM IR from aws/s2n-tls :: tests/unit (s2n_client_supported_versions_extension_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"

; Function Attrs: nounwind uwtable
define dso_local i32 @write_test_supported_versions_list(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  br label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i8, ptr %7, align 1, !tbaa !9
  %13 = zext i8 %12 to i32
  %14 = mul nsw i32 %13, 2
  %15 = trunc i32 %14 to i8
  %16 = call i32 @s2n_stuffer_write_uint8(ptr noundef %11, i8 noundef zeroext %15)
  %17 = icmp sgt i32 %16, -1
  br i1 %17, label %19, label %18

18:                                               ; preds = %10
  store i32 -1, ptr %4, align 4
  br label %64

19:                                               ; preds = %10
  br label %20

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !10
  br label %21

21:                                               ; preds = %58, %20
  %22 = load i64, ptr %8, align 8, !tbaa !10
  %23 = load i8, ptr %7, align 1, !tbaa !9
  %24 = zext i8 %23 to i64
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 4, ptr %9, align 4
  br label %61

27:                                               ; preds = %21
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i64, ptr %8, align 8, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = zext i8 %33 to i32
  %35 = sdiv i32 %34, 10
  %36 = trunc i32 %35 to i8
  %37 = call i32 @s2n_stuffer_write_uint8(ptr noundef %29, i8 noundef zeroext %36)
  %38 = icmp sgt i32 %37, -1
  br i1 %38, label %40, label %39

39:                                               ; preds = %28
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %61

40:                                               ; preds = %28
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !10
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = zext i8 %48 to i32
  %50 = srem i32 %49, 10
  %51 = trunc i32 %50 to i8
  %52 = call i32 @s2n_stuffer_write_uint8(ptr noundef %44, i8 noundef zeroext %51)
  %53 = icmp sgt i32 %52, -1
  br i1 %53, label %55, label %54

54:                                               ; preds = %43
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %61

55:                                               ; preds = %43
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %8, align 8, !tbaa !10
  %60 = add i64 %59, 1
  store i64 %60, ptr %8, align 8, !tbaa !10
  br label %21, !llvm.loop !12

61:                                               ; preds = %54, %39, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %62 = load i32, ptr %9, align 4
  switch i32 %62, label %66 [
    i32 4, label %63
    i32 1, label %64
  ]

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

64:                                               ; preds = %63, %61, %18
  %65 = load i32, ptr %4, align 4
  ret i32 %65

66:                                               ; preds = %61
  unreachable
}

declare i32 @s2n_stuffer_write_uint8(ptr noundef, i8 noundef zeroext) #1

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

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

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 range(i32 -1, 1) i32 @write_test_supported_versions_list(ptr noundef %0, ptr nocapture noundef readonly %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = shl i8 %2, 1
  %5 = tail call i32 @s2n_stuffer_write_uint8(ptr noundef %0, i8 noundef zeroext %4) #2
  %6 = icmp sgt i32 %5, -1
  br i1 %6, label %.preheader, label %._crit_edge

.preheader:                                       ; preds = %3
  %7 = zext i8 %2 to i64
  %.not14.not = icmp eq i8 %2, 0
  br i1 %.not14.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %8 = load i8, ptr %1, align 1, !tbaa !5
  %9 = udiv i8 %8, 10
  %10 = tail call i32 @s2n_stuffer_write_uint8(ptr noundef %0, i8 noundef zeroext %9) #2
  %11 = icmp sgt i32 %10, -1
  br i1 %11, label %.lr.ph23, label %._crit_edge

12:                                               ; preds = %.lr.ph23
  %13 = add nuw nsw i64 %.0121522, 1
  %.not = icmp ult i64 %13, %7
  %exitcond.not = icmp eq i64 %13, %7
  br i1 %exitcond.not, label %._crit_edge.loopexit.loopexit, label %.lr.ph, !llvm.loop !8

.lr.ph:                                           ; preds = %12
  %14 = getelementptr inbounds i8, ptr %1, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = udiv i8 %15, 10
  %17 = tail call i32 @s2n_stuffer_write_uint8(ptr noundef %0, i8 noundef zeroext %16) #2
  %18 = icmp sgt i32 %17, -1
  br i1 %18, label %.lr.ph23, label %._crit_edge.loopexit.loopexit, !llvm.loop !8

.lr.ph23:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.0121522 = phi i64 [ %13, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.not1621 = phi i1 [ %.not, %.lr.ph ], [ true, %.lr.ph.preheader ]
  %19 = getelementptr inbounds i8, ptr %1, i64 %.0121522
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = urem i8 %20, 10
  %22 = tail call i32 @s2n_stuffer_write_uint8(ptr noundef %0, i8 noundef zeroext %21) #2
  %23 = icmp sgt i32 %22, -1
  br i1 %23, label %12, label %._crit_edge.loopexit.loopexit

._crit_edge.loopexit.loopexit:                    ; preds = %.lr.ph23, %.lr.ph, %12
  %.not.lcssa.ph.ph = phi i1 [ %.not, %12 ], [ %.not, %.lr.ph ], [ %.not1621, %.lr.ph23 ]
  %24 = sext i1 %.not.lcssa.ph.ph to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %._crit_edge.loopexit.loopexit, %.preheader, %3
  %.1 = phi i32 [ -1, %3 ], [ 0, %.preheader ], [ -1, %.lr.ph.preheader ], [ %24, %._crit_edge.loopexit.loopexit ]
  ret i32 %.1
}

declare i32 @s2n_stuffer_write_uint8(ptr noundef, i8 noundef zeroext) local_unnamed_addr #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 = { "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 }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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