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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_hmac_state_validate(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #2

declare i32 @s2n_hash_update(ptr noundef, ptr noundef, i32 noundef) #3

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

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i32 @s2n_hmac_state_validate(ptr noundef %11)
  %13 = getelementptr inbounds %struct.s2n_result, ptr %9, i32 0, i32 0
  store i32 %12, ptr %13, align 4
  %14 = getelementptr inbounds %struct.s2n_result, ptr %9, i32 0, i32 0
  %15 = load i32, ptr %14, align 4
  %16 = call zeroext i1 @s2n_result_is_ok(i32 %15)
  %17 = xor i1 %16, true
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = call i64 @llvm.expect.i64(i64 %20, i64 1)
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %10
  %24 = getelementptr inbounds %struct.s2n_result, ptr %8, i32 0, i32 0
  store i32 0, ptr %24, align 4, !tbaa !11
  br label %27

25:                                               ; preds = %10
  %26 = getelementptr inbounds %struct.s2n_result, ptr %8, i32 0, i32 0
  store i32 -1, ptr %26, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %25, %23
  %28 = getelementptr inbounds %struct.s2n_result, ptr %8, i32 0, i32 0
  %29 = load i32, ptr %28, align 4
  %30 = call zeroext i1 @s2n_result_is_ok(i32 %29)
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 -1, ptr %4, align 4
  br label %79

32:                                               ; preds = %27
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s2n_hmac_state, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.s2n_hmac_state, ptr %37, i32 0, i32 10
  %39 = getelementptr inbounds [64 x i8], ptr %38, i64 0, i64 0
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s2n_hmac_state, ptr %40, i32 0, i32 4
  %42 = load i8, ptr %41, align 2, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = call i32 @s2n_hash_digest(ptr noundef %36, ptr noundef %39, i32 noundef %43)
  %45 = icmp sgt i32 %44, -1
  br i1 %45, label %47, label %46

46:                                               ; preds = %34
  store i32 -1, ptr %4, align 4
  br label %79

47:                                               ; preds = %34
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.s2n_hmac_state, ptr %50, i32 0, i32 7
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.s2n_hmac_state, ptr %52, i32 0, i32 8
  %54 = call i32 @s2n_hash_copy(ptr noundef %51, ptr noundef %53)
  %55 = icmp sgt i32 %54, -1
  br i1 %55, label %57, label %56

56:                                               ; preds = %49
  store i32 -1, ptr %4, align 4
  br label %79

57:                                               ; preds = %49
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.s2n_hmac_state, ptr %60, i32 0, i32 7
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.s2n_hmac_state, ptr %62, i32 0, i32 10
  %64 = getelementptr inbounds [64 x i8], ptr %63, i64 0, i64 0
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.s2n_hmac_state, ptr %65, i32 0, i32 4
  %67 = load i8, ptr %66, align 2, !tbaa !13
  %68 = zext i8 %67 to i32
  %69 = call i32 @s2n_hash_update(ptr noundef %61, ptr noundef %64, i32 noundef %68)
  %70 = icmp sgt i32 %69, -1
  br i1 %70, label %72, label %71

71:                                               ; preds = %59
  store i32 -1, ptr %4, align 4
  br label %79

72:                                               ; preds = %59
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.s2n_hmac_state, ptr %74, i32 0, i32 7
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = call i32 @s2n_hash_digest(ptr noundef %75, ptr noundef %76, i32 noundef %77)
  store i32 %78, ptr %4, align 4
  br label %79

79:                                               ; preds = %73, %71, %56, %46, %31
  %80 = load i32, ptr %4, align 4
  ret i32 %80
}

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

declare i32 @s2n_hash_copy(ptr noundef, ptr noundef) #3

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(none) }
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" }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0}
!13 = !{!14, !7, i64 14}
!14 = !{!"s2n_hmac_state", !10, i64 0, !15, i64 4, !10, i64 8, !15, i64 12, !7, i64 14, !16, i64 16, !16, i64 72, !16, i64 128, !16, i64 184, !7, i64 240, !7, i64 368}
!15 = !{!"short", !7, i64 0}
!16 = !{!"s2n_hash_state", !6, i64 0, !10, i64 8, !7, i64 12, !17, i64 16, !7, i64 24}
!17 = !{!"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"

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @s2n_result_is_ok(i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_hmac_state_validate(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_hmac_digest(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @s2n_hmac_state_validate(ptr noundef %0)
  %5 = tail call zeroext i1 @s2n_result_is_ok(i32 %4)
  %not. = xor i1 %5, true
  %. = sext i1 %not. to i32
  %6 = tail call zeroext i1 @s2n_result_is_ok(i32 %.)
  br i1 %6, label %7, label %27

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = getelementptr inbounds i8, ptr %0, i64 368
  %10 = getelementptr inbounds i8, ptr %0, i64 14
  %11 = load i8, ptr %10, align 2, !tbaa !5
  %12 = zext i8 %11 to i32
  %13 = tail call i32 @s2n_hash_digest(ptr noundef nonnull %8, ptr noundef nonnull %9, i32 noundef %12) #3
  %14 = icmp sgt i32 %13, -1
  br i1 %14, label %15, label %27

15:                                               ; preds = %7
  %16 = getelementptr inbounds i8, ptr %0, i64 128
  %17 = getelementptr inbounds i8, ptr %0, i64 184
  %18 = tail call i32 @s2n_hash_copy(ptr noundef nonnull %16, ptr noundef nonnull %17) #3
  %19 = icmp sgt i32 %18, -1
  br i1 %19, label %20, label %27

20:                                               ; preds = %15
  %21 = load i8, ptr %10, align 2, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = tail call i32 @s2n_hash_update(ptr noundef nonnull %16, ptr noundef nonnull %9, i32 noundef %22) #3
  %24 = icmp sgt i32 %23, -1
  br i1 %24, label %25, label %27

25:                                               ; preds = %20
  %26 = tail call i32 @s2n_hash_digest(ptr noundef nonnull %16, ptr noundef %1, i32 noundef %2) #3
  br label %27

27:                                               ; preds = %20, %15, %7, %3, %25
  %.0 = phi i32 [ %26, %25 ], [ -1, %3 ], [ -1, %7 ], [ -1, %15 ], [ -1, %20 ]
  ret i32 %.0
}

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

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

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

!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 14}
!6 = !{!"s2n_hmac_state", !7, i64 0, !10, i64 4, !7, i64 8, !10, i64 12, !8, i64 14, !11, i64 16, !11, i64 72, !11, i64 128, !11, i64 184, !8, i64 240, !8, i64 368}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"s2n_hash_state", !12, i64 0, !7, i64 8, !8, i64 12, !13, i64 16, !8, i64 24}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long", !8, i64 0}


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