; LLVM IR from square/subzero :: core/trezor-crypto (blake2s)

; 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.__blake2s_state = type { [8 x i32], [2 x i32], [2 x i32], [64 x i8], i32, i8, i8 }
%struct.blake2s_param__ = type { i8, i8, i8, i8, i32, i32, i16, i8, i8, [8 x i8], [8 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2s_init_param(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  call void @blake2s_init0(ptr noundef %8)
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %24, %2
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 8
  br i1 %11, label %12, label %27

12:                                               ; preds = %9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = mul i64 %14, 4
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  %17 = call i32 @load32(ptr noundef %16)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.__blake2s_state, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = xor i32 %22, %17
  store i32 %23, ptr %21, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %12
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = add i64 %25, 1
  store i64 %26, ptr %6, align 8, !tbaa !9
  br label %9, !llvm.loop !13

27:                                               ; preds = %9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.blake2s_param__, ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 1, !tbaa !15
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.__blake2s_state, ptr %31, i32 0, i32 5
  store i8 %30, ptr %32, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 0
}

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

; Function Attrs: nounwind uwtable
declare hidden void @blake2s_init0(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @load32(ptr noundef) #2

; 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 = { 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !7, i64 0}
!16 = !{!"blake2s_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !12, i64 4, !12, i64 8, !17, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 24}
!17 = !{!"short", !7, i64 0}
!18 = !{!19, !7, i64 116}
!19 = !{!"__blake2s_state", !7, i64 0, !7, i64 32, !7, i64 40, !7, i64 48, !12, i64 112, !7, i64 116, !7, i64 117}


; 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: nounwind uwtable
define dso_local noundef i32 @blake2s_init_param(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  tail call void @blake2s_init0(ptr noundef %0)
  %3 = tail call i32 @load32(ptr noundef %1)
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %5 = xor i32 %4, %3
  store i32 %5, ptr %0, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = tail call i32 @load32(ptr noundef nonnull %6)
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = xor i32 %9, %7
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = tail call i32 @load32(ptr noundef nonnull %11)
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = xor i32 %14, %12
  store i32 %15, ptr %13, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %1, i64 12
  %17 = tail call i32 @load32(ptr noundef nonnull %16)
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = xor i32 %19, %17
  store i32 %20, ptr %18, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %1, i64 16
  %22 = tail call i32 @load32(ptr noundef nonnull %21)
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = xor i32 %24, %22
  store i32 %25, ptr %23, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %1, i64 20
  %27 = tail call i32 @load32(ptr noundef nonnull %26)
  %28 = getelementptr inbounds i8, ptr %0, i64 20
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = xor i32 %29, %27
  store i32 %30, ptr %28, align 4, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %1, i64 24
  %32 = tail call i32 @load32(ptr noundef nonnull %31)
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = xor i32 %34, %32
  store i32 %35, ptr %33, align 4, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %1, i64 28
  %37 = tail call i32 @load32(ptr noundef nonnull %36)
  %38 = getelementptr inbounds i8, ptr %0, i64 28
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = xor i32 %39, %37
  store i32 %40, ptr %38, align 4, !tbaa !5
  %41 = load i8, ptr %1, align 1, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %0, i64 116
  store i8 %41, ptr %42, align 4, !tbaa !12
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare hidden void @blake2s_init0(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @load32(ptr noundef) local_unnamed_addr #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 = { 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" }

!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"}
!9 = !{!10, !7, i64 0}
!10 = !{!"blake2s_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 4, !6, i64 8, !11, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 24}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !7, i64 116}
!13 = !{!"__blake2s_state", !7, i64 0, !7, i64 32, !7, i64 40, !7, i64 48, !6, i64 112, !7, i64 116, !7, i64 117}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass