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

; 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_blob = type { ptr, i32, i32, i8 }
%struct.s2n_tls13_keys = type { i32, i32, i8, %struct.s2n_blob, %struct.s2n_blob, [48 x i8], [48 x i8], %struct.s2n_hmac_state }
%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.6 = external hidden unnamed_addr constant [94 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

declare i32 @s2n_blob_init(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_tls13_calculate_finished_mac(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca [48 x i8], align 16
  %12 = alloca i32, align 4
  %13 = alloca %struct.s2n_blob, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.s2n_tls13_keys, ptr %14, i32 0, i32 2
  %16 = load i8, ptr %15, align 8, !tbaa !9
  %17 = zext i8 %16 to i64
  store i64 %17, ptr %10, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 48, ptr %11) #6
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 48, i1 false)
  br label %18

18:                                               ; preds = %4
  %19 = load i64, ptr %10, align 8, !tbaa !17
  %20 = icmp ule i64 %19, 48
  br i1 %20, label %54, label %21

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  %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
  store ptr @.str.6, ptr %25, align 8, !tbaa !18
  %26 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %27 = getelementptr inbounds %struct.s2n_debug_info, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %28, i64 21
  %30 = call ptr @strrchr(ptr noundef %29, i32 noundef 47) #7
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %39

32:                                               ; preds = %23
  %33 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %34 = getelementptr inbounds %struct.s2n_debug_info, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds i8, ptr %35, i64 21
  %37 = call ptr @strrchr(ptr noundef %36, i32 noundef 47) #7
  %38 = getelementptr inbounds i8, ptr %37, i64 1
  br label %44

39:                                               ; preds = %23
  %40 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %41 = getelementptr inbounds %struct.s2n_debug_info, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = getelementptr inbounds i8, ptr %42, i64 21
  br label %44

44:                                               ; preds = %39, %32
  %45 = phi ptr [ %38, %32 ], [ %43, %39 ]
  %46 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @_s2n_debug_info)
  %47 = getelementptr inbounds %struct.s2n_debug_info, ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !20
  %48 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  store i32 402653194, ptr %48, align 4, !tbaa !21
  %49 = call i32 @s2n_calculate_stacktrace()
  br label %50

50:                                               ; preds = %44
  br label %51

51:                                               ; preds = %50
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %94

52:                                               ; No predecessors!
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53, %18
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #6
  call void @llvm.memset.p0.i64(ptr align 8 %13, i8 0, i64 24, i1 false)
  br label %57

57:                                               ; preds = %56
  %58 = getelementptr inbounds [48 x i8], ptr %11, i64 0, i64 0
  %59 = load i64, ptr %10, align 8, !tbaa !17
  %60 = trunc i64 %59 to i32
  %61 = call i32 @s2n_blob_init(ptr noundef %13, ptr noundef %58, i32 noundef %60)
  %62 = icmp sgt i32 %61, -1
  br i1 %62, label %64, label %63

63:                                               ; preds = %57
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %93

64:                                               ; preds = %57
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.s2n_blob, ptr %13, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !22
  %71 = getelementptr inbounds %struct.s2n_blob, ptr %13, i32 0, i32 1
  %72 = load i32, ptr %71, align 8, !tbaa !23
  %73 = call i32 @s2n_hash_digest(ptr noundef %68, ptr noundef %70, i32 noundef %72)
  %74 = icmp sgt i32 %73, -1
  br i1 %74, label %76, label %75

75:                                               ; preds = %67
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %93

76:                                               ; preds = %67
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.s2n_tls13_keys, ptr %80, i32 0, i32 7
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.s2n_tls13_keys, ptr %82, i32 0, i32 0
  %84 = load i32, ptr %83, align 8, !tbaa !24
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = call i32 @s2n_hkdf_extract(ptr noundef %81, i32 noundef %84, ptr noundef %85, ptr noundef %13, ptr noundef %86)
  %88 = icmp sgt i32 %87, -1
  br i1 %88, label %90, label %89

89:                                               ; preds = %79
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %93

90:                                               ; preds = %79
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %93

93:                                               ; preds = %92, %89, %75, %63
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #6
  br label %94

94:                                               ; preds = %93, %51
  call void @llvm.lifetime.end.p0(i64 48, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  %95 = load i32, ptr %5, align 4
  ret i32 %95
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

declare i32 @s2n_hash_digest(ptr noundef, ptr noundef, i32 noundef) #2

declare i32 @s2n_hkdf_extract(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { 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, !7, i64 8}
!10 = !{!"s2n_tls13_keys", !11, i64 0, !11, i64 4, !7, i64 8, !12, i64 16, !12, i64 40, !7, i64 64, !7, i64 112, !13, i64 160}
!11 = !{!"int", !7, i64 0}
!12 = !{!"s2n_blob", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16}
!13 = !{!"s2n_hmac_state", !11, i64 0, !14, i64 4, !11, i64 8, !14, i64 12, !7, i64 14, !15, i64 16, !15, i64 72, !15, i64 128, !15, i64 184, !7, i64 240, !7, i64 368}
!14 = !{!"short", !7, i64 0}
!15 = !{!"s2n_hash_state", !6, i64 0, !11, i64 8, !7, i64 12, !16, i64 16, !7, i64 24}
!16 = !{!"long", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"s2n_debug_info", !6, i64 0, !6, i64 8}
!20 = !{!19, !6, i64 8}
!21 = !{!11, !11, i64 0}
!22 = !{!12, !6, i64 0}
!23 = !{!12, !11, i64 8}
!24 = !{!10, !11, 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 }
%struct.s2n_blob = type { ptr, i32, i32, i8 }

@_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.6 = external hidden unnamed_addr constant [94 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

declare i32 @s2n_blob_init(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_tls13_calculate_finished_mac(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca [48 x i8], align 16
  %6 = alloca %struct.s2n_blob, align 8
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i8, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %5) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) %5, i8 0, i64 48, i1 false)
  %9 = icmp ult i8 %8, 49
  br i1 %9, label %18, label %10

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

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, i8 0, i64 24, i1 false)
  %19 = zext nneg i8 %8 to i32
  %20 = call i32 @s2n_blob_init(ptr noundef nonnull %6, ptr noundef nonnull %5, i32 noundef %19) #6
  %21 = icmp sgt i32 %20, -1
  br i1 %21, label %22, label %32

22:                                               ; preds = %18
  %23 = load ptr, ptr %6, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %6, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !21
  %26 = call i32 @s2n_hash_digest(ptr noundef %2, ptr noundef %23, i32 noundef %25) #6
  %27 = icmp sgt i32 %26, -1
  br i1 %27, label %28, label %32

28:                                               ; preds = %22
  %29 = getelementptr inbounds i8, ptr %0, i64 160
  %30 = load i32, ptr %0, align 8, !tbaa !22
  %31 = call i32 @s2n_hkdf_extract(ptr noundef nonnull %29, i32 noundef %30, ptr noundef %1, ptr noundef nonnull %6, ptr noundef %3) #6
  %.lobit = ashr i32 %31, 31
  br label %32

32:                                               ; preds = %28, %22, %18
  %.0 = phi i32 [ -1, %18 ], [ -1, %22 ], [ %.lobit, %28 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #6
  br label %33

33:                                               ; preds = %32, %10
  %.1 = phi i32 [ %.0, %32 ], [ -1, %10 ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %5) #6
  ret i32 %.1
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

declare i32 @s2n_hash_digest(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @s2n_hkdf_extract(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { 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, !8, i64 8}
!6 = !{!"s2n_tls13_keys", !7, i64 0, !7, i64 4, !8, i64 8, !10, i64 16, !10, i64 40, !8, i64 64, !8, i64 112, !12, i64 160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"s2n_blob", !11, i64 0, !7, i64 8, !7, i64 12, !7, i64 16}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"s2n_hmac_state", !7, i64 0, !13, i64 4, !7, i64 8, !13, i64 12, !8, i64 14, !14, i64 16, !14, i64 72, !14, i64 128, !14, i64 184, !8, i64 240, !8, i64 368}
!13 = !{!"short", !8, i64 0}
!14 = !{!"s2n_hash_state", !11, i64 0, !7, i64 8, !8, i64 12, !15, i64 16, !8, i64 24}
!15 = !{!"long", !8, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"s2n_debug_info", !11, i64 0, !11, i64 8}
!18 = !{!17, !11, i64 8}
!19 = !{!7, !7, i64 0}
!20 = !{!10, !11, i64 0}
!21 = !{!10, !7, i64 8}
!22 = !{!6, !7, i64 0}


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