; 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 }
%struct.s2n_result = type { i32 }
%struct.s2n_hmac_state = type { i32, i16, i32, i16, i8, %struct.s2n_hash_state, %struct.s2n_hash_state, %struct.s2n_hash_state, %struct.s2n_hash_state, [128 x i8], [64 x i8] }
%struct.s2n_hash_state = type { ptr, i32, i8, i64, %union.anon }
%union.anon = type { %struct.s2n_hash_evp_digest }
%struct.s2n_hash_evp_digest = type { %struct.s2n_evp_digest, %struct.s2n_evp_digest }
%struct.s2n_evp_digest = 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.9 = external hidden unnamed_addr constant [88 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: nounwind uwtable
define dso_local i32 @s2n_hmac_state_validate(ptr noundef %0) #4 {
  %2 = alloca %struct.s2n_result, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.s2n_result, align 4
  %5 = alloca %struct.s2n_result, align 4
  %6 = alloca %struct.s2n_result, align 4
  %7 = alloca %struct.s2n_result, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %43, label %11

11:                                               ; preds = %8
  br label %12

12:                                               ; preds = %11
  br label %13

13:                                               ; preds = %12
  %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
  store ptr @.str.9, ptr %15, align 8, !tbaa !9
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %17 = getelementptr inbounds %struct.s2n_debug_info, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 21
  %20 = call ptr @strrchr(ptr noundef %19, i32 noundef 47) #5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %29

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

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

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

40:                                               ; preds = %34
  %41 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %41, align 4, !tbaa !14
  br label %94

42:                                               ; No predecessors!
  br label %43

43:                                               ; preds = %42, %8
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.s2n_hmac_state, ptr %46, i32 0, i32 5
  %48 = call i32 @s2n_hash_state_validate(ptr noundef %47)
  %49 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 %48, ptr %49, align 4
  %50 = getelementptr inbounds %struct.s2n_result, ptr %4, 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 = %45
  %54 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %54, align 4, !tbaa !14
  br label %94

55:                                               ; preds = %45
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.s2n_hmac_state, ptr %58, i32 0, i32 6
  %60 = call i32 @s2n_hash_state_validate(ptr noundef %59)
  %61 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  store i32 %60, ptr %61, align 4
  %62 = getelementptr inbounds %struct.s2n_result, ptr %5, i32 0, i32 0
  %63 = load i32, ptr %62, align 4
  %64 = call zeroext i1 @s2n_result_is_ok(i32 %63)
  br i1 %64, label %67, label %65

65:                                               ; preds = %57
  %66 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %66, align 4, !tbaa !14
  br label %94

67:                                               ; preds = %57
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.s2n_hmac_state, ptr %70, i32 0, i32 7
  %72 = call i32 @s2n_hash_state_validate(ptr noundef %71)
  %73 = getelementptr inbounds %struct.s2n_result, ptr %6, i32 0, i32 0
  store i32 %72, ptr %73, align 4
  %74 = getelementptr inbounds %struct.s2n_result, ptr %6, i32 0, i32 0
  %75 = load i32, ptr %74, align 4
  %76 = call zeroext i1 @s2n_result_is_ok(i32 %75)
  br i1 %76, label %79, label %77

77:                                               ; preds = %69
  %78 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %78, align 4, !tbaa !14
  br label %94

79:                                               ; preds = %69
  br label %80

80:                                               ; preds = %79
  br label %81

81:                                               ; preds = %80
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.s2n_hmac_state, ptr %82, i32 0, i32 8
  %84 = call i32 @s2n_hash_state_validate(ptr noundef %83)
  %85 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  store i32 %84, ptr %85, align 4
  %86 = getelementptr inbounds %struct.s2n_result, ptr %7, i32 0, i32 0
  %87 = load i32, ptr %86, align 4
  %88 = call zeroext i1 @s2n_result_is_ok(i32 %87)
  br i1 %88, label %91, label %89

89:                                               ; preds = %81
  %90 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 -1, ptr %90, align 4, !tbaa !14
  br label %94

91:                                               ; preds = %81
  br label %92

92:                                               ; preds = %91
  %93 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  store i32 0, ptr %93, align 4, !tbaa !14
  br label %94

94:                                               ; preds = %92, %89, %77, %65, %53, %40
  %95 = getelementptr inbounds %struct.s2n_result, ptr %2, i32 0, i32 0
  %96 = load i32, ptr %95, align 4
  ret i32 %96
}

declare i32 @s2n_hash_state_validate(ptr noundef) #2

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


; 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.9 = external hidden unnamed_addr constant [88 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: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_hmac_state_validate(ptr noundef %0) local_unnamed_addr #4 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %10

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

10:                                               ; preds = %1
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = tail call i32 @s2n_hash_state_validate(ptr noundef nonnull %11) #6
  %13 = tail call zeroext i1 @s2n_result_is_ok(i32 %12)
  br i1 %13, label %14, label %26

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 72
  %16 = tail call i32 @s2n_hash_state_validate(ptr noundef nonnull %15) #6
  %17 = tail call zeroext i1 @s2n_result_is_ok(i32 %16)
  br i1 %17, label %18, label %26

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %0, i64 128
  %20 = tail call i32 @s2n_hash_state_validate(ptr noundef nonnull %19) #6
  %21 = tail call zeroext i1 @s2n_result_is_ok(i32 %20)
  br i1 %21, label %22, label %26

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %0, i64 184
  %24 = tail call i32 @s2n_hash_state_validate(ptr noundef nonnull %23) #6
  %25 = tail call zeroext i1 @s2n_result_is_ok(i32 %24)
  %not. = xor i1 %25, true
  %. = sext i1 %not. to i32
  br label %26

26:                                               ; preds = %22, %18, %14, %10, %2
  %.sroa.08.0 = phi i32 [ -1, %2 ], [ -1, %10 ], [ -1, %14 ], [ -1, %18 ], [ %., %22 ]
  ret i32 %.sroa.08.0
}

declare i32 @s2n_hash_state_validate(ptr noundef) local_unnamed_addr #2

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 = { 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 willreturn memory(read) }
attributes #6 = { 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,SROAPass,SimplifyCFGPass,TailCallElimPass