; 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 }

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

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

6:                                                ; preds = %2
  %7 = load ptr, ptr %5, align 8, !tbaa !8
  %8 = icmp ne ptr %7, null
  br i1 %8, label %41, label %9

9:                                                ; preds = %6
  br label %10

10:                                               ; preds = %9
  br label %11

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

20:                                               ; preds = %11
  %21 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %22 = getelementptr inbounds %struct.s2n_debug_info, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !10
  %24 = getelementptr inbounds i8, ptr %23, i64 21
  %25 = call ptr @strrchr(ptr noundef %24, i32 noundef 47) #4
  %26 = getelementptr inbounds i8, ptr %25, i64 1
  br label %32

27:                                               ; preds = %11
  %28 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %29 = getelementptr inbounds %struct.s2n_debug_info, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !10
  %31 = getelementptr inbounds i8, ptr %30, i64 21
  br label %32

32:                                               ; preds = %27, %20
  %33 = phi ptr [ %26, %20 ], [ %31, %27 ]
  %34 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %35 = getelementptr inbounds %struct.s2n_debug_info, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !12
  %36 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653193, ptr %36, align 4, !tbaa !13
  %37 = call i32 @s2n_calculate_stacktrace()
  br label %38

38:                                               ; preds = %32
  %39 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %39, align 4, !tbaa !15
  br label %87

40:                                               ; No predecessors!
  br label %41

41:                                               ; preds = %40, %6
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  %44 = load i8, ptr %4, align 1, !tbaa !5
  %45 = zext i8 %44 to i64
  %46 = icmp ult i64 %45, 16
  br i1 %46, label %79, label %47

47:                                               ; preds = %43
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %51 = getelementptr inbounds %struct.s2n_debug_info, ptr %50, i32 0, i32 0
  store ptr @.str.1, ptr %51, align 8, !tbaa !10
  %52 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %53 = getelementptr inbounds %struct.s2n_debug_info, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !10
  %55 = getelementptr inbounds i8, ptr %54, i64 21
  %56 = call ptr @strrchr(ptr noundef %55, i32 noundef 47) #4
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %65

58:                                               ; preds = %49
  %59 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %60 = getelementptr inbounds %struct.s2n_debug_info, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !10
  %62 = getelementptr inbounds i8, ptr %61, i64 21
  %63 = call ptr @strrchr(ptr noundef %62, i32 noundef 47) #4
  %64 = getelementptr inbounds i8, ptr %63, i64 1
  br label %70

65:                                               ; preds = %49
  %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 !10
  %69 = getelementptr inbounds i8, ptr %68, i64 21
  br label %70

70:                                               ; preds = %65, %58
  %71 = phi ptr [ %64, %58 ], [ %69, %65 ]
  %72 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %73 = getelementptr inbounds %struct.s2n_debug_info, ptr %72, i32 0, i32 1
  store ptr %71, ptr %73, align 8, !tbaa !12
  %74 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653270, ptr %74, align 4, !tbaa !13
  %75 = call i32 @s2n_calculate_stacktrace()
  br label %76

76:                                               ; preds = %70
  %77 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 -1, ptr %77, align 4, !tbaa !15
  br label %87

78:                                               ; No predecessors!
  br label %79

79:                                               ; preds = %78, %43
  br label %80

80:                                               ; preds = %79
  %81 = load i8, ptr %4, align 1, !tbaa !5
  %82 = zext i8 %81 to i64
  %83 = getelementptr inbounds [16 x i8], ptr @value_to_hex, i64 0, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !5
  %85 = load ptr, ptr %5, align 8, !tbaa !8
  store i8 %84, ptr %85, align 1, !tbaa !5
  %86 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  store i32 0, ptr %86, align 4, !tbaa !15
  br label %87

87:                                               ; preds = %80, %76, %38
  %88 = getelementptr inbounds %struct.s2n_result, ptr %3, i32 0, i32 0
  %89 = load i32, ptr %88, align 4
  ret i32 %89
}

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

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

declare i32 @s2n_calculate_stacktrace() #3

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 speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 willreturn memory(read) }

!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 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !9, i64 0}
!11 = !{!"s2n_debug_info", !9, i64 0, !9, i64 8}
!12 = !{!11, !9, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !6, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"", !14, 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 }

@.str = external hidden unnamed_addr constant [95 x i8], align 1
@_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.1 = external hidden unnamed_addr constant [95 x i8], align 1
@value_to_hex = external hidden local_unnamed_addr constant [16 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_hex_digit(i8 noundef zeroext %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %11

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

11:                                               ; preds = %2
  %12 = icmp ult i8 %0, 16
  br i1 %12, label %21, label %13

13:                                               ; preds = %11
  %14 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.1, ptr %14, align 8, !tbaa !5
  %15 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.1, i64 21), i32 noundef 47) #4
  %.not7 = icmp eq ptr %15, null
  %16 = getelementptr inbounds i8, ptr %15, i64 1
  %17 = select i1 %.not7, ptr getelementptr inbounds (i8, ptr @.str.1, i64 21), ptr %16
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %17, ptr %18, align 8, !tbaa !10
  %19 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653270, ptr %19, align 4, !tbaa !11
  %20 = tail call i32 @s2n_calculate_stacktrace() #5
  br label %25

21:                                               ; preds = %11
  %22 = zext nneg i8 %0 to i64
  %23 = getelementptr inbounds [16 x i8], ptr @value_to_hex, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !13
  store i8 %24, ptr %1, align 1, !tbaa !13
  br label %25

25:                                               ; preds = %21, %13, %3
  %.sroa.0.0 = phi i32 [ 0, %21 ], [ -1, %13 ], [ -1, %3 ]
  ret i32 %.sroa.0.0
}

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

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

declare i32 @s2n_calculate_stacktrace() local_unnamed_addr #3

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 speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { "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 willreturn memory(read) }
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, !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 = !{!8, !8, i64 0}


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