; 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_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_tls13_label_finished = external dso_local constant %struct.s2n_blob, align 8
@zero_length_blob = external hidden constant %struct.s2n_blob, align 8

declare i32 @s2n_hkdf_expand_label(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_tls13_derive_finished_key(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.s2n_tls13_keys, ptr %9, i32 0, i32 7
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.s2n_tls13_keys, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call i32 @s2n_hkdf_expand_label(ptr noundef %10, i32 noundef %13, ptr noundef %14, ptr noundef @s2n_tls13_label_finished, ptr noundef @zero_length_blob, ptr noundef %15)
  %17 = icmp sgt i32 %16, -1
  br i1 %17, label %19, label %18

18:                                               ; preds = %8
  store i32 -1, ptr %4, align 4
  br label %21

19:                                               ; preds = %8
  br label %20

20:                                               ; preds = %19
  store i32 0, ptr %4, align 4
  br label %21

21:                                               ; preds = %20, %18
  %22 = load i32, ptr %4, align 4
  ret i32 %22
}

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

!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, !11, i64 0}
!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}


; 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_blob = type { ptr, i32, i32, i8 }

@s2n_tls13_label_finished = external dso_local constant %struct.s2n_blob, align 8
@zero_length_blob = external hidden constant %struct.s2n_blob, align 8

declare i32 @s2n_hkdf_expand_label(ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @s2n_tls13_derive_finished_key(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 160
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = tail call i32 @s2n_hkdf_expand_label(ptr noundef nonnull %4, i32 noundef %5, ptr noundef %1, ptr noundef nonnull @s2n_tls13_label_finished, ptr noundef nonnull @zero_length_blob, ptr noundef %2) #2
  %.lobit = ashr i32 %6, 31
  ret i32 %.lobit
}

attributes #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 = { 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 #2 = { 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_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}


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