; LLVM IR from FlorentCLMichel/palisade :: src/core/lib/utils/prng (blake2xb-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.blake2xb_state__ = type { [1 x %struct.blake2b_state__], [1 x %struct.blake2b_param__] }
%struct.blake2b_state__ = type { [8 x i64], [2 x i64], [2 x i64], [128 x i8], i64, i64, i8 }
%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 @blake2xb_init_key(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca [128 x i8], align 16
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %11 = load i64, ptr %7, align 8, !tbaa !9
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %16, label %13

13:                                               ; preds = %4
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = icmp ugt i64 %14, 4294967295
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %4
  store i32 -1, ptr %5, align 4
  br label %111

17:                                               ; preds = %13
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp ne ptr null, %18
  br i1 %19, label %20, label %24

20:                                               ; preds = %17
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = icmp ugt i64 %21, 64
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i32 -1, ptr %5, align 4
  br label %111

24:                                               ; preds = %20, %17
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp eq ptr null, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = icmp ugt i64 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 -1, ptr %5, align 4
  br label %111

31:                                               ; preds = %27, %24
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.blake2xb_state__, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds %struct.blake2b_param__, ptr %34, i32 0, i32 0
  store i8 64, ptr %35, align 8, !tbaa !11
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = trunc i64 %36 to i8
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.blake2xb_state__, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %39, i64 0, i64 0
  %41 = getelementptr inbounds %struct.blake2b_param__, ptr %40, i32 0, i32 1
  store i8 %37, ptr %41, align 1, !tbaa !14
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.blake2xb_state__, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %43, i64 0, i64 0
  %45 = getelementptr inbounds %struct.blake2b_param__, ptr %44, i32 0, i32 2
  store i8 1, ptr %45, align 2, !tbaa !15
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.blake2xb_state__, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %47, i64 0, i64 0
  %49 = getelementptr inbounds %struct.blake2b_param__, ptr %48, i32 0, i32 3
  store i8 1, ptr %49, align 1, !tbaa !16
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.blake2xb_state__, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %51, i64 0, i64 0
  %53 = getelementptr inbounds %struct.blake2b_param__, ptr %52, i32 0, i32 4
  call void @store32(ptr noundef %53, i32 noundef 0)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.blake2xb_state__, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %55, i64 0, i64 0
  %57 = getelementptr inbounds %struct.blake2b_param__, ptr %56, i32 0, i32 5
  call void @store32(ptr noundef %57, i32 noundef 0)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.blake2xb_state__, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %59, i64 0, i64 0
  %61 = getelementptr inbounds %struct.blake2b_param__, ptr %60, i32 0, i32 6
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = trunc i64 %62 to i32
  call void @store32(ptr noundef %61, i32 noundef %63)
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.blake2xb_state__, ptr %64, i32 0, i32 1
  %66 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %65, i64 0, i64 0
  %67 = getelementptr inbounds %struct.blake2b_param__, ptr %66, i32 0, i32 7
  store i8 0, ptr %67, align 8, !tbaa !17
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.blake2xb_state__, ptr %68, i32 0, i32 1
  %70 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %69, i64 0, i64 0
  %71 = getelementptr inbounds %struct.blake2b_param__, ptr %70, i32 0, i32 8
  store i8 0, ptr %71, align 1, !tbaa !18
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.blake2xb_state__, ptr %72, i32 0, i32 1
  %74 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %73, i64 0, i64 0
  %75 = getelementptr inbounds %struct.blake2b_param__, ptr %74, i32 0, i32 9
  %76 = getelementptr inbounds [14 x i8], ptr %75, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 2 %76, i8 0, i64 14, i1 false)
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.blake2xb_state__, ptr %77, i32 0, i32 1
  %79 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %78, i64 0, i64 0
  %80 = getelementptr inbounds %struct.blake2b_param__, ptr %79, i32 0, i32 10
  %81 = getelementptr inbounds [16 x i8], ptr %80, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %81, i8 0, i64 16, i1 false)
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.blake2xb_state__, ptr %82, i32 0, i32 1
  %84 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %83, i64 0, i64 0
  %85 = getelementptr inbounds %struct.blake2b_param__, ptr %84, i32 0, i32 11
  %86 = getelementptr inbounds [16 x i8], ptr %85, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %86, i8 0, i64 16, i1 false)
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.blake2xb_state__, ptr %87, i32 0, i32 0
  %89 = getelementptr inbounds [1 x %struct.blake2b_state__], ptr %88, i64 0, i64 0
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.blake2xb_state__, ptr %90, i32 0, i32 1
  %92 = getelementptr inbounds [1 x %struct.blake2b_param__], ptr %91, i64 0, i64 0
  %93 = call i32 @blake2b_init_param(ptr noundef %89, ptr noundef %92)
  %94 = icmp slt i32 %93, 0
  br i1 %94, label %95, label %96

95:                                               ; preds = %31
  store i32 -1, ptr %5, align 4
  br label %111

96:                                               ; preds = %31
  %97 = load i64, ptr %9, align 8, !tbaa !9
  %98 = icmp ugt i64 %97, 0
  br i1 %98, label %99, label %110

99:                                               ; preds = %96
  call void @llvm.lifetime.start.p0(i64 128, ptr %10) #6
  %100 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %100, i8 0, i64 128, i1 false)
  %101 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  %102 = load ptr, ptr %8, align 8, !tbaa !5
  %103 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %101, ptr align 1 %102, i64 %103, i1 false)
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.blake2xb_state__, ptr %104, i32 0, i32 0
  %106 = getelementptr inbounds [1 x %struct.blake2b_state__], ptr %105, i64 0, i64 0
  %107 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  %108 = call i32 @blake2b_update(ptr noundef %106, ptr noundef %107, i64 noundef 128)
  %109 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  call void @secure_zero_memory(ptr noundef %109, i64 noundef 128)
  call void @llvm.lifetime.end.p0(i64 128, ptr %10) #6
  br label %110

110:                                              ; preds = %99, %96
  store i32 0, ptr %5, align 4
  br label %111

111:                                              ; preds = %110, %95, %30, %23, %16
  %112 = load i32, ptr %5, align 4
  ret i32 %112
}

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

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

declare i32 @blake2b_init_param(ptr noundef, ptr noundef) #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

declare i32 @blake2b_update(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @secure_zero_memory(ptr noundef, i64 noundef) #1

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

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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @blake2xb_init_key(ptr noundef %0, i64 noundef %1, ptr noundef readonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [128 x i8], align 16
  %6 = add i64 %1, -4294967296
  %or.cond = icmp ult i64 %6, -4294967295
  br i1 %or.cond, label %32, label %7

7:                                                ; preds = %4
  %8 = icmp ne ptr %2, null
  %9 = icmp ugt i64 %3, 64
  %or.cond3 = and i1 %8, %9
  br i1 %or.cond3, label %32, label %10

10:                                               ; preds = %7
  %11 = icmp eq ptr %2, null
  %12 = icmp ne i64 %3, 0
  %or.cond5 = and i1 %11, %12
  br i1 %or.cond5, label %32, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 248
  store i8 64, ptr %14, align 8, !tbaa !5
  %15 = trunc i64 %3 to i8
  %16 = getelementptr inbounds i8, ptr %0, i64 249
  store i8 %15, ptr %16, align 1, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %0, i64 250
  store i8 1, ptr %17, align 2, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %0, i64 251
  store i8 1, ptr %18, align 1, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %0, i64 252
  tail call void @store32(ptr noundef nonnull %19, i32 noundef 0)
  %20 = getelementptr inbounds i8, ptr %0, i64 256
  tail call void @store32(ptr noundef nonnull %20, i32 noundef 0)
  %21 = getelementptr inbounds i8, ptr %0, i64 260
  %22 = trunc nuw i64 %1 to i32
  tail call void @store32(ptr noundef nonnull %21, i32 noundef %22)
  %23 = getelementptr inbounds i8, ptr %0, i64 264
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %23, i8 0, i64 48, i1 false)
  %24 = tail call i32 @blake2b_init_param(ptr noundef %0, ptr noundef nonnull %14) #6
  %25 = icmp sgt i32 %24, -1
  %brmerge.not = and i1 %12, %25
  %not. = xor i1 %25, true
  %.mux = sext i1 %not. to i32
  br i1 %brmerge.not, label %26, label %32

26:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #6
  %27 = icmp ugt i64 %3, 127
  %28 = sub i64 128, %3
  %29 = select i1 %27, i64 0, i64 %28
  %30 = getelementptr i8, ptr %5, i64 %3
  call void @llvm.memset.p0.i64(ptr align 1 %30, i8 0, i64 %29, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %5, ptr align 1 %2, i64 %3, i1 false)
  %31 = call i32 @blake2b_update(ptr noundef nonnull %0, ptr noundef nonnull %5, i64 noundef 128) #6
  call void @secure_zero_memory(ptr noundef nonnull %5, i64 noundef 128)
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #6
  br label %32

32:                                               ; preds = %13, %26, %10, %7, %4
  %.0 = phi i32 [ -1, %4 ], [ -1, %7 ], [ -1, %10 ], [ %.mux, %13 ], [ 0, %26 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @store32(ptr noundef, i32 noundef) local_unnamed_addr #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

declare i32 @blake2b_init_param(ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

declare i32 @blake2b_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @secure_zero_memory(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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" }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass