; 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_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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @s2n_hmac_digest(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_hmac_digest_two_compression_rounds(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, 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 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = call i32 @s2n_hmac_digest(ptr noundef %11, ptr noundef %12, i32 noundef %13)
  %15 = icmp sgt i32 %14, -1
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  store i32 -1, ptr %4, align 4
  br label %62

17:                                               ; preds = %10
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.s2n_hmac_state, ptr %19, i32 0, i32 1
  %21 = load i16, ptr %20, align 4, !tbaa !11
  %22 = zext i16 %21 to i32
  %23 = icmp eq i32 %22, 128
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 17, i32 9
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %8, align 1, !tbaa !16
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s2n_hmac_state, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !17
  %30 = zext i32 %29 to i64
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s2n_hmac_state, ptr %31, i32 0, i32 1
  %33 = load i16, ptr %32, align 4, !tbaa !11
  %34 = zext i16 %33 to i32
  %35 = load i8, ptr %8, align 1, !tbaa !16
  %36 = zext i8 %35 to i32
  %37 = sub nsw i32 %34, %36
  %38 = sext i32 %37 to i64
  %39 = icmp sgt i64 %30, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %18
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %61

41:                                               ; preds = %18
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s2n_hmac_state, ptr %43, i32 0, i32 5
  %45 = call i32 @s2n_hash_reset(ptr noundef %44)
  %46 = icmp sgt i32 %45, -1
  br i1 %46, label %48, label %47

47:                                               ; preds = %42
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %61

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s2n_hmac_state, ptr %51, i32 0, i32 5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.s2n_hmac_state, ptr %53, i32 0, i32 9
  %55 = getelementptr inbounds [128 x i8], ptr %54, i64 0, i64 0
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.s2n_hmac_state, ptr %56, i32 0, i32 1
  %58 = load i16, ptr %57, align 4, !tbaa !11
  %59 = zext i16 %58 to i32
  %60 = call i32 @s2n_hash_update(ptr noundef %52, ptr noundef %55, i32 noundef %59)
  store i32 %60, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %61

61:                                               ; preds = %50, %47, %40
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  br label %62

62:                                               ; preds = %61, %16
  %63 = load i32, ptr %4, align 4
  ret i32 %63
}

declare i32 @s2n_hash_reset(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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, !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, !13, i64 4}
!12 = !{!"s2n_hmac_state", !10, i64 0, !13, i64 4, !10, i64 8, !13, i64 12, !7, i64 14, !14, i64 16, !14, i64 72, !14, i64 128, !14, i64 184, !7, i64 240, !7, i64 368}
!13 = !{!"short", !7, i64 0}
!14 = !{!"s2n_hash_state", !6, i64 0, !10, i64 8, !7, i64 12, !15, i64 16, !7, i64 24}
!15 = !{!"long", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!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"

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @s2n_hmac_digest_two_compression_rounds(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @s2n_hmac_digest(ptr noundef %0, ptr noundef %1, i32 noundef %2)
  %5 = icmp sgt i32 %4, -1
  br i1 %5, label %6, label %25

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i16, ptr %7, align 4, !tbaa !5
  %9 = zext i16 %8 to i64
  %10 = icmp eq i16 %8, 128
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %13 = zext i32 %12 to i64
  %.neg = select i1 %10, i64 -17, i64 -9
  %14 = add nsw i64 %.neg, %9
  %15 = icmp slt i64 %14, %13
  br i1 %15, label %25, label %16

16:                                               ; preds = %6
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = tail call i32 @s2n_hash_reset(ptr noundef nonnull %17) #2
  %19 = icmp sgt i32 %18, -1
  br i1 %19, label %20, label %25

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %0, i64 240
  %22 = load i16, ptr %7, align 4, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = tail call i32 @s2n_hash_update(ptr noundef nonnull %17, ptr noundef nonnull %21, i32 noundef %23) #2
  br label %25

25:                                               ; preds = %20, %6, %16, %3
  %.1 = phi i32 [ -1, %3 ], [ %24, %20 ], [ 0, %6 ], [ -1, %16 ]
  ret i32 %.1
}

declare i32 @s2n_hash_reset(ptr noundef) local_unnamed_addr #0

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, !10, i64 4}
!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}
!14 = !{!6, !7, i64 8}


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