; LLVM IR from ponylang/ponyc :: lib/blake2 (blake2b-ref)

; 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
declare dso_local i32 @blake2b_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 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 @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) #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, 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 @llvm.memset.p0.i64(ptr align 2 %37, i8 0, i64 14, i1 false)
  %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 @llvm.memset.p0.i64(ptr align 16 %40, i8 0, i64 16, i1 false)
  %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 @llvm.memset.p0.i64(ptr align 16 %43, i8 0, i64 16, i1 false)
  %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) #4
  %48 = load i32, ptr %3, align 4
  ret i32 %48
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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
declare dso_local 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.start.p0(i64 immarg, ptr nocapture) #1

; 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 @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) #4
  %4 = add i64 %1, -65
  %or.cond = icmp ult i64 %4, -64
  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 !10
  %8 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 1, ptr %8, align 2, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 1, ptr %9, align 1, !tbaa !12
  %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 @store32(ptr noundef nonnull %12, i32 noundef 0)
  %13 = getelementptr inbounds i8, ptr %3, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48) %13, i8 0, i64 48, i1 false)
  %14 = call i32 @blake2b_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 64, ptr nonnull %3) #4
  ret i32 %.0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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 1}
!11 = !{!6, !7, i64 2}
!12 = !{!6, !7, i64 3}


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