; 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_state__ = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i64, i64, i8 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_init(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_init_key(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_update(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_final(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @blake2b(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca [1 x %struct.blake2b_state__], align 16
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i64 %5, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 248, ptr %14) #2
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = icmp eq ptr null, %16
  br i1 %17, label %18, label %22

18:                                               ; preds = %6
  %19 = load i64, ptr %11, align 8, !tbaa !9
  %20 = icmp ugt i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

22:                                               ; preds = %18, %6
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

26:                                               ; preds = %22
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = icmp eq ptr null, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %26
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = icmp ugt i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

33:                                               ; preds = %29, %26
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %33
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = icmp ugt i64 %37, 64
  br i1 %38, label %39, label %40

39:                                               ; preds = %36, %33
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

40:                                               ; preds = %36
  %41 = load i64, ptr %13, align 8, !tbaa !9
  %42 = icmp ugt i64 %41, 64
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

44:                                               ; preds = %40
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = icmp ugt i64 %45, 0
  br i1 %46, label %47, label %56

47:                                               ; preds = %44
  %48 = getelementptr inbounds [1 x %struct.blake2b_state__], ptr %14, i64 0, i64 0
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i64, ptr %13, align 8, !tbaa !9
  %52 = call i32 @blake2b_init_key(ptr noundef %48, i64 noundef %49, ptr noundef %50, i64 noundef %51)
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %47
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

55:                                               ; preds = %47
  br label %63

56:                                               ; preds = %44
  %57 = getelementptr inbounds [1 x %struct.blake2b_state__], ptr %14, i64 0, i64 0
  %58 = load i64, ptr %9, align 8, !tbaa !9
  %59 = call i32 @blake2b_init(ptr noundef %57, i64 noundef %58)
  %60 = icmp slt i32 %59, 0
  br i1 %60, label %61, label %62

61:                                               ; preds = %56
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

62:                                               ; preds = %56
  br label %63

63:                                               ; preds = %62, %55
  %64 = getelementptr inbounds [1 x %struct.blake2b_state__], ptr %14, i64 0, i64 0
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load i64, ptr %11, align 8, !tbaa !9
  %67 = call i32 @blake2b_update(ptr noundef %64, ptr noundef %65, i64 noundef %66)
  %68 = getelementptr inbounds [1 x %struct.blake2b_state__], ptr %14, i64 0, i64 0
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load i64, ptr %9, align 8, !tbaa !9
  %71 = call i32 @blake2b_final(ptr noundef %68, ptr noundef %69, i64 noundef %70)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %72

72:                                               ; preds = %63, %61, %54, %43, %39, %32, %25, %21
  call void @llvm.lifetime.end.p0(i64 248, ptr %14) #2
  %73 = load i32, ptr %7, align 4
  ret i32 %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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}


; 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_state__ = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i64, i64, i8 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_init(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_init_key(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @blake2b_final(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @blake2b(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #1 {
  %7 = alloca [1 x %struct.blake2b_state__], align 16
  call void @llvm.lifetime.start.p0(i64 248, ptr nonnull %7) #2
  %8 = icmp eq ptr %2, null
  %9 = icmp ne i64 %3, 0
  %or.cond = and i1 %8, %9
  %10 = icmp eq ptr %0, null
  %or.cond25 = or i1 %10, %or.cond
  br i1 %or.cond25, label %26, label %11

11:                                               ; preds = %6
  %12 = icmp eq ptr %4, null
  %13 = icmp ne i64 %5, 0
  %or.cond3 = and i1 %12, %13
  %14 = add i64 %1, -65
  %or.cond5 = icmp ult i64 %14, -64
  %or.cond26 = or i1 %or.cond5, %or.cond3
  %15 = icmp ugt i64 %5, 64
  %or.cond27 = or i1 %15, %or.cond26
  br i1 %or.cond27, label %26, label %16

16:                                               ; preds = %11
  br i1 %13, label %17, label %20

17:                                               ; preds = %16
  %18 = call i32 @blake2b_init_key(ptr noundef nonnull %7, i64 noundef %1, ptr noundef %4, i64 noundef %5)
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %26, label %23

20:                                               ; preds = %16
  %21 = call i32 @blake2b_init(ptr noundef nonnull %7, i64 noundef %1)
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %26, label %23

23:                                               ; preds = %20, %17
  %24 = call i32 @blake2b_update(ptr noundef nonnull %7, ptr noundef %2, i64 noundef %3)
  %25 = call i32 @blake2b_final(ptr noundef nonnull %7, ptr noundef nonnull %0, i64 noundef %1)
  br label %26

26:                                               ; preds = %20, %17, %11, %6, %23
  %.0 = phi i32 [ 0, %23 ], [ -1, %6 ], [ -1, %11 ], [ -1, %17 ], [ -1, %20 ]
  call void @llvm.lifetime.end.p0(i64 248, ptr nonnull %7) #2
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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)"}


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