; LLVM IR from gost-engine/engine :: gost_gost2015 (gost2015_final_call)

; 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @gost2015_final_call(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [16 x i8], align 16
  %13 = alloca i32, align 4
  %14 = alloca [16 x i8], align 16
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %15 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %15, i8 0, i64 16, i1 false)
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = call i32 @EVP_CIPHER_CTX_is_encrypting(ptr noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %32

19:                                               ; preds = %5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  %22 = call i32 @EVP_DigestSignFinal(ptr noundef %20, ptr noundef %21, ptr noundef %9)
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = call i32 %23(ptr noundef %24, ptr noundef %25, ptr noundef %26, i64 noundef %27)
  %29 = icmp sle i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %19
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %57

31:                                               ; preds = %19
  br label %56

32:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #4
  %33 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %33, i8 0, i64 16, i1 false)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  %36 = call i32 @EVP_DigestSignFinal(ptr noundef %34, ptr noundef %35, ptr noundef %9)
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = call i32 %37(ptr noundef %38, ptr noundef %39, ptr noundef %40, i64 noundef %41)
  %43 = icmp sle i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %32
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %53

45:                                               ; preds = %32
  %46 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %47 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = call i32 @CRYPTO_memcmp(ptr noundef %46, ptr noundef %47, i64 noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %45
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %53

52:                                               ; preds = %45
  store i32 0, ptr %13, align 4
  br label %53

53:                                               ; preds = %52, %51, %44
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  %54 = load i32, ptr %13, align 4
  switch i32 %54, label %57 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55, %31
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %57

57:                                               ; preds = %56, %53, %30
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  %58 = load i32, ptr %6, align 4
  ret i32 %58
}

; 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

declare i32 @EVP_CIPHER_CTX_is_encrypting(ptr noundef) #3

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

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

; 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 = { 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 = { 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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @gost2015_final_call(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %6 = alloca i64, align 8
  %7 = alloca [16 x i8], align 16
  %8 = alloca [16 x i8], align 16
  store i64 %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  %9 = tail call i32 @EVP_CIPHER_CTX_is_encrypting(ptr noundef %0) #4
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %15, label %10

10:                                               ; preds = %5
  %11 = call i32 @EVP_DigestSignFinal(ptr noundef %1, ptr noundef nonnull %7, ptr noundef nonnull %6) #4
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = call i32 %4(ptr noundef %0, ptr noundef %3, ptr noundef nonnull %7, i64 noundef %12) #4
  %14 = icmp slt i32 %13, 1
  br i1 %14, label %24, label %23

15:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  %16 = call i32 @EVP_DigestSignFinal(ptr noundef %1, ptr noundef nonnull %7, ptr noundef nonnull %6) #4
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = call i32 %4(ptr noundef %0, ptr noundef nonnull %8, ptr noundef %3, i64 noundef %17) #4
  %19 = icmp slt i32 %18, 1
  br i1 %19, label %.critedge, label %20

20:                                               ; preds = %15
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = call i32 @CRYPTO_memcmp(ptr noundef nonnull %8, ptr noundef nonnull %7, i64 noundef %21) #4
  %.not11 = icmp eq i32 %22, 0
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #4
  br i1 %.not11, label %23, label %24

23:                                               ; preds = %20, %10
  br label %24

.critedge:                                        ; preds = %15
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #4
  br label %24

24:                                               ; preds = %.critedge, %10, %20, %23
  %.1 = phi i32 [ 0, %23 ], [ -1, %20 ], [ -1, %10 ], [ -1, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret i32 %.1
}

; 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

declare i32 @EVP_CIPHER_CTX_is_encrypting(ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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