; LLVM IR from aws/s2n-tls :: crypto (s2n_hmac)

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

@_s2n_debug_info = external thread_local global %struct.s2n_debug_info, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [87 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: nounwind uwtable
define dso_local i32 @s2n_hmac_hash_alg(i32 noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %2
  %7 = load ptr, ptr %5, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %40, 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.2, ptr %13, align 8, !tbaa !11
  %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 !11
  %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 !11
  %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 !11
  %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 !13
  %36 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653249, ptr %36, align 4, !tbaa !5
  %37 = call i32 @s2n_calculate_stacktrace()
  br label %38

38:                                               ; preds = %32
  store i32 -1, ptr %3, align 4
  br label %93

39:                                               ; No predecessors!
  br label %40

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

41:                                               ; preds = %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %42, label %61 [
    i32 0, label %43
    i32 1, label %45
    i32 2, label %47
    i32 3, label %49
    i32 4, label %51
    i32 5, label %53
    i32 6, label %55
    i32 7, label %57
    i32 8, label %59
  ]

43:                                               ; preds = %41
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 0, ptr %44, align 4, !tbaa !5
  br label %92

45:                                               ; preds = %41
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 1, ptr %46, align 4, !tbaa !5
  br label %92

47:                                               ; preds = %41
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 2, ptr %48, align 4, !tbaa !5
  br label %92

49:                                               ; preds = %41
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 3, ptr %50, align 4, !tbaa !5
  br label %92

51:                                               ; preds = %41
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 4, ptr %52, align 4, !tbaa !5
  br label %92

53:                                               ; preds = %41
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 5, ptr %54, align 4, !tbaa !5
  br label %92

55:                                               ; preds = %41
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 6, ptr %56, align 4, !tbaa !5
  br label %92

57:                                               ; preds = %41
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 1, ptr %58, align 4, !tbaa !5
  br label %92

59:                                               ; preds = %41
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 2, ptr %60, align 4, !tbaa !5
  br label %92

61:                                               ; preds = %41
  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.3, ptr %65, align 8, !tbaa !11
  %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 !11
  %69 = getelementptr inbounds i8, ptr %68, i64 21
  %70 = call ptr @strrchr(ptr noundef %69, i32 noundef 47) #4
  %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 !11
  %76 = getelementptr inbounds i8, ptr %75, i64 21
  %77 = call ptr @strrchr(ptr noundef %76, i32 noundef 47) #4
  %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 !11
  %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 !13
  %88 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653214, ptr %88, align 4, !tbaa !5
  %89 = call i32 @s2n_calculate_stacktrace()
  br label %90

90:                                               ; preds = %84
  store i32 -1, ptr %3, align 4
  br label %93

91:                                               ; No predecessors!
  br label %92

92:                                               ; preds = %91, %59, %57, %55, %53, %51, %49, %47, %45, %43
  store i32 0, ptr %3, align 4
  br label %93

93:                                               ; preds = %92, %90, %38
  %94 = load i32, ptr %3, align 4
  ret i32 %94
}

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 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"s2n_debug_info", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}


; 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.2 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [87 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: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_hmac_hash_alg(i32 noundef %0, ptr noundef writeonly %1) local_unnamed_addr #3 {
  %.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.2, ptr %4, align 8, !tbaa !5
  %5 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.2, i64 21), i32 noundef 47) #4
  %.not14 = icmp eq ptr %5, null
  %6 = getelementptr inbounds i8, ptr %5, i64 1
  %7 = select i1 %.not14, ptr getelementptr inbounds (i8, ptr @.str.2, 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 402653249, ptr %9, align 4, !tbaa !11
  %10 = tail call i32 @s2n_calculate_stacktrace() #5
  br label %29

11:                                               ; preds = %2
  switch i32 %0, label %21 [
    i32 0, label %12
    i32 1, label %13
    i32 2, label %14
    i32 3, label %15
    i32 4, label %16
    i32 5, label %17
    i32 6, label %18
    i32 7, label %19
    i32 8, label %20
  ]

12:                                               ; preds = %11
  store i32 0, ptr %1, align 4, !tbaa !11
  br label %29

13:                                               ; preds = %11
  store i32 1, ptr %1, align 4, !tbaa !11
  br label %29

14:                                               ; preds = %11
  store i32 2, ptr %1, align 4, !tbaa !11
  br label %29

15:                                               ; preds = %11
  store i32 3, ptr %1, align 4, !tbaa !11
  br label %29

16:                                               ; preds = %11
  store i32 4, ptr %1, align 4, !tbaa !11
  br label %29

17:                                               ; preds = %11
  store i32 5, ptr %1, align 4, !tbaa !11
  br label %29

18:                                               ; preds = %11
  store i32 6, ptr %1, align 4, !tbaa !11
  br label %29

19:                                               ; preds = %11
  store i32 1, ptr %1, align 4, !tbaa !11
  br label %29

20:                                               ; preds = %11
  store i32 2, ptr %1, align 4, !tbaa !11
  br label %29

21:                                               ; preds = %11
  %22 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  store ptr @.str.3, ptr %22, align 8, !tbaa !5
  %23 = tail call ptr @strrchr(ptr noundef nonnull dereferenceable(1) getelementptr inbounds (i8, ptr @.str.3, i64 21), i32 noundef 47) #4
  %.not15 = icmp eq ptr %23, null
  %24 = getelementptr inbounds i8, ptr %23, i64 1
  %25 = select i1 %.not15, ptr getelementptr inbounds (i8, ptr @.str.3, i64 21), ptr %24
  %26 = getelementptr inbounds i8, ptr %22, i64 8
  store ptr %25, ptr %26, align 8, !tbaa !10
  %27 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653214, ptr %27, align 4, !tbaa !11
  %28 = tail call i32 @s2n_calculate_stacktrace() #5
  br label %29

29:                                               ; preds = %12, %13, %14, %15, %16, %17, %18, %19, %20, %21, %3
  %.0 = phi i32 [ -1, %21 ], [ -1, %3 ], [ 0, %20 ], [ 0, %19 ], [ 0, %18 ], [ 0, %17 ], [ 0, %16 ], [ 0, %15 ], [ 0, %14 ], [ 0, %13 ], [ 0, %12 ]
  ret i32 %.0
}

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 = { 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 = { 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}


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