; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto (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._SHA256_CTX = type { [8 x i32], i64, [16 x i32] }

@sha256_initial_hash_value = external constant [8 x i32], align 16

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

declare void @memzero(ptr noundef, i64 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

declare void @sha256_Init(ptr noundef) #1

declare void @sha256_Update(ptr noundef, ptr noundef, i64 noundef) #1

declare void @sha256_Final(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha256_prepare(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [16 x i32], align 16
  %10 = alloca %struct._SHA256_CTX, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %9) #4
  %15 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  call void @memzero(ptr noundef %15, i64 noundef 64)
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp ugt i32 %16, 64
  br i1 %17, label %18, label %23

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 104, ptr %10) #4
  call void @sha256_Init(ptr noundef %10)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  call void @sha256_Update(ptr noundef %10, ptr noundef %19, i64 noundef %21)
  %22 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  call void @sha256_Final(ptr noundef %10, ptr noundef %22)
  call void @llvm.lifetime.end.p0(i64 104, ptr %10) #4
  br label %28

23:                                               ; preds = %4
  %24 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %24, ptr align 1 %25, i64 %27, i1 false)
  br label %28

28:                                               ; preds = %23, %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %58, %28
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp slt i32 %30, 16
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %61

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  store i32 %37, ptr %13, align 4, !tbaa !9
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = lshr i32 %38, 16
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = shl i32 %40, 16
  %42 = or i32 %39, %41
  store i32 %42, ptr %13, align 4, !tbaa !9
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = and i64 %44, 4278255360
  %46 = lshr i64 %45, 8
  %47 = load i32, ptr %13, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = and i64 %48, 16711935
  %50 = shl i64 %49, 8
  %51 = or i64 %46, %50
  %52 = trunc i64 %51 to i32
  store i32 %52, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = xor i32 %53, 1549556828
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 %56
  store i32 %54, ptr %57, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %58

58:                                               ; preds = %33
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %29, !llvm.loop !11

61:                                               ; preds = %32
  %62 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sha256_Transform(ptr noundef @sha256_initial_hash_value, ptr noundef %62, ptr noundef %63)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %78, %61
  %65 = load i32, ptr %14, align 4, !tbaa !9
  %66 = icmp slt i32 %65, 16
  br i1 %66, label %68, label %67

67:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %81

68:                                               ; preds = %64
  %69 = load i32, ptr %14, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = xor i32 %72, 1549556828
  %74 = xor i32 %73, 909522486
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 %76
  store i32 %74, ptr %77, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %68
  %79 = load i32, ptr %14, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %14, align 4, !tbaa !9
  br label %64, !llvm.loop !13

81:                                               ; preds = %67
  %82 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  call void @sha256_Transform(ptr noundef @sha256_initial_hash_value, ptr noundef %82, ptr noundef %83)
  %84 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  call void @memzero(ptr noundef %84, i64 noundef 64)
  call void @llvm.lifetime.end.p0(i64 64, ptr %9) #4
  ret void
}

declare void @sha256_Transform(ptr noundef, ptr noundef, 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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._SHA256_CTX = type { [8 x i32], i64, [16 x i32] }

@sha256_initial_hash_value = external constant [8 x i32], align 16

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

declare void @memzero(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

declare void @sha256_Init(ptr noundef) local_unnamed_addr #1

declare void @sha256_Update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @sha256_Final(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @hmac_sha256_prepare(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca [16 x i32], align 16
  %6 = alloca %struct._SHA256_CTX, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #5
  call void @memzero(ptr noundef nonnull %5, i64 noundef 64) #5
  %7 = icmp ugt i32 %1, 64
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %6) #5
  call void @sha256_Init(ptr noundef nonnull %6) #5
  %9 = zext i32 %1 to i64
  call void @sha256_Update(ptr noundef nonnull %6, ptr noundef %0, i64 noundef %9) #5
  call void @sha256_Final(ptr noundef nonnull %6, ptr noundef nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %6) #5
  br label %12

10:                                               ; preds = %4
  %11 = zext nneg i32 %1 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %5, ptr align 1 %0, i64 %11, i1 false)
  br label %12

12:                                               ; preds = %10, %8
  %13 = load <4 x i32>, ptr %5, align 16, !tbaa !5
  %14 = xor <4 x i32> %13, <i32 1549556828, i32 1549556828, i32 1549556828, i32 1549556828>
  %15 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %14)
  store <4 x i32> %15, ptr %5, align 16, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %5, i64 16
  %17 = load <4 x i32>, ptr %16, align 16, !tbaa !5
  %18 = xor <4 x i32> %17, <i32 1549556828, i32 1549556828, i32 1549556828, i32 1549556828>
  %19 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %18)
  store <4 x i32> %19, ptr %16, align 16, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %5, i64 32
  %21 = load <4 x i32>, ptr %20, align 16, !tbaa !5
  %22 = xor <4 x i32> %21, <i32 1549556828, i32 1549556828, i32 1549556828, i32 1549556828>
  %23 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %22)
  store <4 x i32> %23, ptr %20, align 16, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %5, i64 48
  %25 = load <4 x i32>, ptr %24, align 16, !tbaa !5
  %26 = xor <4 x i32> %25, <i32 1549556828, i32 1549556828, i32 1549556828, i32 1549556828>
  %27 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %26)
  store <4 x i32> %27, ptr %24, align 16, !tbaa !5
  call void @sha256_Transform(ptr noundef nonnull @sha256_initial_hash_value, ptr noundef nonnull %5, ptr noundef %2) #5
  %28 = load <4 x i32>, ptr %5, align 16, !tbaa !5
  %29 = xor <4 x i32> %28, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %29, ptr %5, align 16, !tbaa !5
  %30 = load <4 x i32>, ptr %16, align 16, !tbaa !5
  %31 = xor <4 x i32> %30, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %31, ptr %16, align 16, !tbaa !5
  %32 = load <4 x i32>, ptr %20, align 16, !tbaa !5
  %33 = xor <4 x i32> %32, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %33, ptr %20, align 16, !tbaa !5
  %34 = load <4 x i32>, ptr %24, align 16, !tbaa !5
  %35 = xor <4 x i32> %34, <i32 1785358954, i32 1785358954, i32 1785358954, i32 1785358954>
  store <4 x i32> %35, ptr %24, align 16, !tbaa !5
  call void @sha256_Transform(ptr noundef nonnull @sha256_initial_hash_value, ptr noundef nonnull %5, ptr noundef %3) #5
  call void @memzero(ptr noundef nonnull %5, i64 noundef 64) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #5
  ret void
}

declare void @sha256_Transform(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>) #4

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass