; LLVM IR from xtruan/FlipBIP :: lib/crypto (blake2b)

; 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 }
%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 @blake2b_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
  store i64 0, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  call void @blake2b_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 8, %14
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  %17 = call i64 @load64(ptr noundef %16)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.__blake2b_state, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = getelementptr inbounds [8 x i64], ptr %19, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = xor i64 %22, %17
  store i64 %23, ptr %21, align 8, !tbaa !9
  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 !11

27:                                               ; preds = %9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.blake2b_param__, ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = zext i8 %30 to i64
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.__blake2b_state, ptr %32, i32 0, i32 5
  store i64 %31, ptr %33, align 8, !tbaa !16
  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 @blake2b_init0(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @load64(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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !7, i64 0}
!14 = !{!"blake2b_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !15, i64 4, !15, i64 8, !15, i64 12, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !10, i64 232}
!17 = !{!"__blake2b_state", !7, i64 0, !7, i64 64, !7, i64 80, !7, i64 96, !10, i64 224, !10, i64 232, !7, i64 240}


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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @load64(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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"blake2b_param__", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 4, !11, i64 8, !11, i64 12, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 32, !7, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 232}
!13 = !{!"__blake2b_state", !7, i64 0, !7, i64 64, !7, i64 80, !7, i64 96, !6, i64 224, !6, i64 232, !7, i64 240}


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