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

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

@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1

; 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: 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) #1

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

24:                                               ; preds = %6
  store i32 0, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %68

25:                                               ; preds = %6
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %25
  %29 = load ptr, ptr %13, align 8, !tbaa !9
  %30 = call i32 @RAND_bytes(ptr noundef %29, i32 noundef 8)
  %31 = icmp ne i32 %30, 1
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  store i32 0, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %68

33:                                               ; preds = %28
  br label %34

34:                                               ; preds = %33, %25
  %35 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = load ptr, ptr %13, align 8, !tbaa !9
  %38 = call i32 @gost_kdftree2012_256(ptr noundef %35, i64 noundef 64, ptr noundef %36, i64 noundef 32, ptr noundef @.str.2, i64 noundef 8, ptr noundef %37, i64 noundef 8, i64 noundef 1)
  %39 = icmp sle i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %34
  store i32 0, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %68

41:                                               ; preds = %34
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  %44 = getelementptr inbounds i8, ptr %43, i64 32
  %45 = call ptr @EVP_PKEY_new_mac_key(i32 noundef %42, ptr noundef null, ptr noundef %44, i32 noundef 32)
  store ptr %45, ptr %17, align 8, !tbaa !9
  %46 = load ptr, ptr %17, align 8, !tbaa !9
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %49

48:                                               ; preds = %41
  br label %64

49:                                               ; preds = %41
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  %51 = load ptr, ptr %16, align 8, !tbaa !9
  %52 = call i32 @EVP_DigestInit_ex(ptr noundef %50, ptr noundef %51, ptr noundef null)
  %53 = icmp sle i32 %52, 0
  br i1 %53, label %60, label %54

54:                                               ; preds = %49
  %55 = load ptr, ptr %11, align 8, !tbaa !9
  %56 = load ptr, ptr %16, align 8, !tbaa !9
  %57 = load ptr, ptr %17, align 8, !tbaa !9
  %58 = call i32 @EVP_DigestSignInit(ptr noundef %55, ptr noundef null, ptr noundef %56, ptr noundef null, ptr noundef %57)
  %59 = icmp sle i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %54, %49
  br label %64

61:                                               ; preds = %54
  %62 = load ptr, ptr %12, align 8, !tbaa !9
  %63 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %62, ptr align 16 %63, i64 32, i1 false)
  store i32 1, ptr %14, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %61, %60, %48
  %65 = load ptr, ptr %17, align 8, !tbaa !9
  call void @EVP_PKEY_free(ptr noundef %65)
  %66 = getelementptr inbounds [64 x i8], ptr %15, i64 0, i64 0
  call void @OPENSSL_cleanse(ptr noundef %66, i64 noundef 64)
  %67 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %67, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %68

68:                                               ; preds = %64, %40, %32, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %69 = load i32, ptr %7, align 4
  ret i32 %69
}

declare ptr @EVP_get_digestbyname(ptr noundef) #3

declare ptr @OBJ_nid2sn(i32 noundef) #3

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

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

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

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

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

declare void @EVP_PKEY_free(ptr noundef) #3

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1

; 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: 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) #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @gost2015_acpkm_omac_init(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr nocapture noundef writeonly %4, ptr noundef %5) local_unnamed_addr #2 {
  %7 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %7) #4
  %8 = tail call ptr @OBJ_nid2sn(i32 noundef %0) #4
  %9 = tail call ptr @EVP_get_digestbyname(ptr noundef %8) #4
  %10 = icmp eq ptr %9, null
  br i1 %10, label %29, label %11

11:                                               ; preds = %6
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %14, label %12

12:                                               ; preds = %11
  %13 = tail call i32 @RAND_bytes(ptr noundef %5, i32 noundef 8) #4
  %.not19 = icmp eq i32 %13, 1
  br i1 %.not19, label %14, label %29

14:                                               ; preds = %12, %11
  %15 = call i32 @gost_kdftree2012_256(ptr noundef nonnull %7, i64 noundef 64, ptr noundef %2, i64 noundef 32, ptr noundef nonnull @.str.2, i64 noundef 8, ptr noundef %5, i64 noundef 8, i64 noundef 1) #4
  %16 = icmp slt i32 %15, 1
  br i1 %16, label %29, label %17

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %7, i64 32
  %19 = call ptr @EVP_PKEY_new_mac_key(i32 noundef %0, ptr noundef null, ptr noundef nonnull %18, i32 noundef 32) #4
  %20 = icmp eq ptr %19, null
  br i1 %20, label %28, label %21

21:                                               ; preds = %17
  %22 = call i32 @EVP_DigestInit_ex(ptr noundef %3, ptr noundef nonnull %9, ptr noundef null) #4
  %23 = icmp slt i32 %22, 1
  br i1 %23, label %28, label %24

24:                                               ; preds = %21
  %25 = call i32 @EVP_DigestSignInit(ptr noundef %3, ptr noundef null, ptr noundef nonnull %9, ptr noundef null, ptr noundef nonnull %19) #4
  %26 = icmp slt i32 %25, 1
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %4, ptr noundef nonnull align 16 dereferenceable(32) %7, i64 32, i1 false)
  br label %28

28:                                               ; preds = %21, %24, %17, %27
  %.016 = phi i32 [ 0, %17 ], [ 0, %21 ], [ 0, %24 ], [ 1, %27 ]
  call void @EVP_PKEY_free(ptr noundef %19) #4
  call void @OPENSSL_cleanse(ptr noundef nonnull %7, i64 noundef 64) #4
  br label %29

29:                                               ; preds = %14, %12, %6, %28
  %.0 = phi i32 [ %.016, %28 ], [ 0, %6 ], [ 0, %12 ], [ 0, %14 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %7) #4
  ret i32 %.0
}

declare ptr @EVP_get_digestbyname(ptr noundef) local_unnamed_addr #3

declare ptr @OBJ_nid2sn(i32 noundef) local_unnamed_addr #3

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

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

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

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

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

declare void @EVP_PKEY_free(ptr noundef) local_unnamed_addr #3

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) local_unnamed_addr #3

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


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