; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto (blake2b)

; 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.blake2b_param__ = type { i8, i8, i8, i8, i32, i32, i32, i8, i8, [14 x i8], [16 x i8], [16 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @tc_blake2b_Init(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca [1 x %struct.blake2b_param__], align 16
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #5
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 64, i1 false)
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = icmp ugt i64 %11, 64
  br i1 %12, label %13, label %14

13:                                               ; preds = %10, %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

14:                                               ; preds = %10
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = trunc i64 %15 to i8
  %17 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %18 = getelementptr inbounds %struct.blake2b_param__, ptr %17, i32 0, i32 0
  store i8 %16, ptr %18, align 16, !tbaa !11
  %19 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %20 = getelementptr inbounds %struct.blake2b_param__, ptr %19, i32 0, i32 1
  store i8 0, ptr %20, align 1, !tbaa !14
  %21 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %22 = getelementptr inbounds %struct.blake2b_param__, ptr %21, i32 0, i32 2
  store i8 1, ptr %22, align 2, !tbaa !15
  %23 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %24 = getelementptr inbounds %struct.blake2b_param__, ptr %23, i32 0, i32 3
  store i8 1, ptr %24, align 1, !tbaa !16
  %25 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %26 = getelementptr inbounds %struct.blake2b_param__, ptr %25, i32 0, i32 4
  call void @store32(ptr noundef %26, i32 noundef 0)
  %27 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %28 = getelementptr inbounds %struct.blake2b_param__, ptr %27, i32 0, i32 5
  call void @store32(ptr noundef %28, i32 noundef 0)
  %29 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %30 = getelementptr inbounds %struct.blake2b_param__, ptr %29, i32 0, i32 6
  call void @store32(ptr noundef %30, i32 noundef 0)
  %31 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %32 = getelementptr inbounds %struct.blake2b_param__, ptr %31, i32 0, i32 7
  store i8 0, ptr %32, align 16, !tbaa !17
  %33 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %34 = getelementptr inbounds %struct.blake2b_param__, ptr %33, i32 0, i32 8
  store i8 0, ptr %34, align 1, !tbaa !18
  %35 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %36 = getelementptr inbounds %struct.blake2b_param__, ptr %35, i32 0, i32 9
  %37 = getelementptr inbounds [14 x i8], ptr %36, i64 0, i64 0
  call void @memzero(ptr noundef %37, i64 noundef 14)
  %38 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %39 = getelementptr inbounds %struct.blake2b_param__, ptr %38, i32 0, i32 10
  %40 = getelementptr inbounds [16 x i8], ptr %39, i64 0, i64 0
  call void @memzero(ptr noundef %40, i64 noundef 16)
  %41 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %42 = getelementptr inbounds %struct.blake2b_param__, ptr %41, i32 0, i32 11
  %43 = getelementptr inbounds [16 x i8], ptr %42, i64 0, i64 0
  call void @memzero(ptr noundef %43, i64 noundef 16)
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %6, i64 0, i64 0
  %46 = call i32 @blake2b_init_param(ptr noundef %44, ptr noundef %45)
  store i32 %46, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

47:                                               ; preds = %14, %13
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #5
  %48 = load i32, ptr %3, align 4
  ret i32 %48
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store32(ptr noundef, i32 noundef) #3

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

; Function Attrs: nounwind uwtable
declare hidden i32 @blake2b_init_param(ptr noundef, ptr noundef) #0

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { "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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"blake2b_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !13, i64 4, !13, i64 8, !13, i64 12, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !7, i64 1}
!15 = !{!12, !7, i64 2}
!16 = !{!12, !7, i64 3}
!17 = !{!12, !7, i64 16}
!18 = !{!12, !7, i64 17}


; 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.blake2b_param__ = type { i8, i8, i8, i8, i32, i32, i32, i8, i8, [14 x i8], [16 x i8], [16 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @tc_blake2b_Init(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [1 x %struct.blake2b_param__], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %3, i8 0, i64 64, i1 false)
  %4 = add i64 %1, -65
  %or.cond = icmp ult i64 %4, -64
  br i1 %or.cond, label %18, label %5

5:                                                ; preds = %2
  %6 = trunc nuw nsw i64 %1 to i8
  store i8 %6, ptr %3, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 1, ptr %7, align 2, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 1, ptr %8, align 1, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %3, i64 4
  call void @store32(ptr noundef nonnull %9, i32 noundef 0)
  %10 = getelementptr inbounds i8, ptr %3, i64 8
  call void @store32(ptr noundef nonnull %10, i32 noundef 0)
  %11 = getelementptr inbounds i8, ptr %3, i64 12
  call void @store32(ptr noundef nonnull %11, i32 noundef 0)
  %12 = getelementptr inbounds i8, ptr %3, i64 16
  store i8 0, ptr %12, align 16, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %3, i64 17
  store i8 0, ptr %13, align 1, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %3, i64 18
  call void @memzero(ptr noundef nonnull %14, i64 noundef 14) #5
  %15 = getelementptr inbounds i8, ptr %3, i64 32
  call void @memzero(ptr noundef nonnull %15, i64 noundef 16) #5
  %16 = getelementptr inbounds i8, ptr %3, i64 48
  call void @memzero(ptr noundef nonnull %16, i64 noundef 16) #5
  %17 = call i32 @blake2b_init_param(ptr noundef %0, ptr noundef nonnull %3)
  br label %18

18:                                               ; preds = %2, %5
  %.0 = phi i32 [ %17, %5 ], [ -1, %2 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #5
  ret i32 %.0
}

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store32(ptr noundef, i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare hidden i32 @blake2b_init_param(ptr noundef, ptr noundef) local_unnamed_addr #0

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

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { "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 #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, !7, i64 0}
!6 = !{!"blake2b_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 4, !9, i64 8, !9, i64 12, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !7, i64 2}
!11 = !{!6, !7, i64 3}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !7, i64 17}


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