; LLVM IR from DanEngelbrecht/longtail :: lib/blake2/ext (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_param__ = type { i8, i8, i8, i8, i32, i32, i16, i8, i8, [8 x i8], [8 x i8] }

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2s_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.blake2s_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 32, ptr %6) #4
  %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, 32
  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 %44

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store16(ptr noundef, i16 noundef zeroext) #3

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 = { 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 = !{!"blake2s_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !13, i64 4, !13, i64 8, !14, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !7, i64 1}
!16 = !{!12, !7, i64 2}
!17 = !{!12, !7, i64 3}
!18 = !{!12, !7, i64 14}
!19 = !{!12, !7, i64 15}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2s_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.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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2s_init(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [1 x %struct.blake2s_param__], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %4 = add i64 %1, -33
  %or.cond = icmp ult i64 %4, -32
  br i1 %or.cond, label %15, 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 1
  store i8 0, ptr %7, align 1, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 1, ptr %8, align 2, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 1, ptr %9, align 1, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %3, i64 4
  call void @store32(ptr noundef nonnull %10, i32 noundef 0)
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  call void @store32(ptr noundef nonnull %11, i32 noundef 0)
  %12 = getelementptr inbounds i8, ptr %3, i64 12
  call void @store16(ptr noundef nonnull %12, i16 noundef zeroext 0)
  %13 = getelementptr inbounds i8, ptr %3, i64 14
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(18) %13, i8 0, i64 18, i1 false)
  %14 = call i32 @blake2s_init_param(ptr noundef %0, ptr noundef nonnull %3)
  br label %15

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store16(ptr noundef, i16 noundef zeroext) local_unnamed_addr #3

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 = { 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 = !{!"blake2s_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 4, !9, i64 8, !10, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 24}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!6, !7, i64 1}
!12 = !{!6, !7, i64 2}
!13 = !{!6, !7, i64 3}


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