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

; 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_debug_info = type { ptr, ptr }
%struct.s2n_result = type { i32 }

@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [96 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strrchr(ptr noundef, i32 noundef) #1

declare i32 @s2n_calculate_stacktrace() #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_stuffer_read_uint16_hex(ptr noundef %0, ptr noundef %1) #5 {
  %3 = alloca %struct.s2n_result, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.s2n_result, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %44, label %12

12:                                               ; preds = %9
  br label %13

13:                                               ; preds = %12
  br label %14

14:                                               ; preds = %13
  %15 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %16 = getelementptr inbounds %struct.s2n_debug_info, ptr %15, i32 0, i32 0
  store ptr @.str.3, ptr %16, align 8, !tbaa !9
  %17 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %18 = getelementptr inbounds %struct.s2n_debug_info, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %19, i64 21
  %21 = call ptr @strrchr(ptr noundef %20, i32 noundef 47) #6
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %30

23:                                               ; preds = %14
  %24 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %25 = getelementptr inbounds %struct.s2n_debug_info, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i64 21
  %28 = call ptr @strrchr(ptr noundef %27, i32 noundef 47) #6
  %29 = getelementptr inbounds i8, ptr %28, i64 1
  br label %35

30:                                               ; preds = %14
  %31 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %32 = getelementptr inbounds %struct.s2n_debug_info, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %33, i64 21
  br label %35

35:                                               ; preds = %30, %23
  %36 = phi ptr [ %29, %23 ], [ %34, %30 ]
  %37 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %38 = getelementptr inbounds %struct.s2n_debug_info, ptr %37, i32 0, i32 1
  store ptr %36, ptr %38, align 8, !tbaa !11
  %39 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %39, align 4, !tbaa !12
  %40 = call i32 @s2n_calculate_stacktrace()
  br label %41

41:                                               ; preds = %35
  %42 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %42, align 4, !tbaa !14
  br label %103

43:                                               ; No predecessors!
  br label %44

44:                                               ; preds = %43, %9
  br label %45

45:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  store i64 0, ptr %6, align 8, !tbaa !16
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call i32 @s2n_stuffer_hex_read_n_bytes(ptr noundef %47, i8 noundef zeroext 2, ptr noundef %6)
  %49 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 %48, ptr %49, align 4
  %50 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  %51 = load i32, ptr %50, align 4
  %52 = call zeroext i1 @s2n_result_is_ok(i32 %51)
  br i1 %52, label %55, label %53

53:                                               ; preds = %46
  %54 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %54, align 4, !tbaa !14
  store i32 1, ptr %8, align 4
  br label %102

55:                                               ; preds = %46
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %6, align 8, !tbaa !16
  %60 = icmp ule i64 %59, 65535
  br i1 %60, label %95, label %61

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  %64 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %65 = getelementptr inbounds %struct.s2n_debug_info, ptr %64, i32 0, i32 0
  store ptr @.str.4, ptr %65, align 8, !tbaa !9
  %66 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %67 = getelementptr inbounds %struct.s2n_debug_info, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %68, i64 21
  %70 = call ptr @strrchr(ptr noundef %69, i32 noundef 47) #6
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %79

72:                                               ; preds = %63
  %73 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %74 = getelementptr inbounds %struct.s2n_debug_info, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !9
  %76 = getelementptr inbounds i8, ptr %75, i64 21
  %77 = call ptr @strrchr(ptr noundef %76, i32 noundef 47) #6
  %78 = getelementptr inbounds i8, ptr %77, i64 1
  br label %84

79:                                               ; preds = %63
  %80 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %81 = getelementptr inbounds %struct.s2n_debug_info, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !9
  %83 = getelementptr inbounds i8, ptr %82, i64 21
  br label %84

84:                                               ; preds = %79, %72
  %85 = phi ptr [ %78, %72 ], [ %83, %79 ]
  %86 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %87 = getelementptr inbounds %struct.s2n_debug_info, ptr %86, i32 0, i32 1
  store ptr %85, ptr %87, align 8, !tbaa !11
  %88 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653194, ptr %88, align 4, !tbaa !12
  %89 = call i32 @s2n_calculate_stacktrace()
  br label %90

90:                                               ; preds = %84
  br label %91

91:                                               ; preds = %90
  %92 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %92, align 4, !tbaa !14
  store i32 1, ptr %8, align 4
  br label %102

93:                                               ; No predecessors!
  br label %94

94:                                               ; preds = %93
  br label %95

95:                                               ; preds = %94, %58
  br label %96

96:                                               ; preds = %95
  br label %97

97:                                               ; preds = %96
  %98 = load i64, ptr %6, align 8, !tbaa !16
  %99 = trunc i64 %98 to i16
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  store i16 %99, ptr %100, align 2, !tbaa !18
  %101 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 0, ptr %101, align 4, !tbaa !14
  store i32 1, ptr %8, align 4
  br label %102

102:                                              ; preds = %97, %91, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %103

103:                                              ; preds = %102, %41
  %104 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  %105 = load i32, ptr %104, align 4
  ret i32 %105
}

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_stuffer_hex_read_n_bytes(ptr noundef, i8 noundef zeroext, ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nounwind willreturn memory(read) "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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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, !6, i64 0}
!10 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"", !13, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"short", !7, 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"

%struct.s2n_debug_info = type { ptr, ptr }

@_s2n_debug_info = external thread_local local_unnamed_addr global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [96 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [96 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strrchr(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_stuffer_read_uint16_hex(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #5 {
  %3 = alloca i64, align 8
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %4, label %12

4:                                                ; preds = %2
  %5 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.3, ptr %5, align 8, !tbaa !5
  %6 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.3, i64 21), i32 noundef 47) #6
  %.not7 = icmp eq ptr %6, null
  %7 = getelementptr inbounds i8, ptr %6, i64 1
  %8 = select i1 %.not7, ptr getelementptr inbounds (i8, ptr @.str.3, i64 21), ptr %7
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !10
  %10 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %10, align 4, !tbaa !11
  %11 = tail call i32 @s2n_calculate_stacktrace() #7
  br label %29

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  store i64 0, ptr %3, align 8, !tbaa !13
  %13 = call i32 @s2n_stuffer_hex_read_n_bytes(ptr noundef %0, i8 noundef zeroext 2, ptr noundef nonnull %3)
  %14 = call zeroext i1 @s2n_result_is_ok(i32 %13)
  br i1 %14, label %15, label %28

15:                                               ; preds = %12
  %16 = load i64, ptr %3, align 8, !tbaa !13
  %17 = icmp ult i64 %16, 65536
  br i1 %17, label %26, label %18

18:                                               ; preds = %15
  %19 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.4, ptr %19, align 8, !tbaa !5
  %20 = call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.4, i64 21), i32 noundef 47) #6
  %.not8 = icmp eq ptr %20, null
  %21 = getelementptr inbounds i8, ptr %20, i64 1
  %22 = select i1 %.not8, ptr getelementptr inbounds (i8, ptr @.str.4, i64 21), ptr %21
  %23 = getelementptr inbounds i8, ptr %19, i64 8
  store ptr %22, ptr %23, align 8, !tbaa !10
  %24 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653194, ptr %24, align 4, !tbaa !11
  %25 = call i32 @s2n_calculate_stacktrace() #7
  br label %28

26:                                               ; preds = %15
  %27 = trunc nuw i64 %16 to i16
  store i16 %27, ptr %1, align 2, !tbaa !15
  br label %28

28:                                               ; preds = %12, %26, %18
  %.sroa.03.0 = phi i32 [ 0, %26 ], [ -1, %18 ], [ -1, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  br label %29

29:                                               ; preds = %28, %4
  %.sroa.03.1 = phi i32 [ %.sroa.03.0, %28 ], [ -1, %4 ]
  ret i32 %.sroa.03.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @s2n_stuffer_hex_read_n_bytes(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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, !7, i64 0}
!6 = !{!"s2n_debug_info", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !8, i64 0}


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