; LLVM IR from gost-engine/engine :: gost_ec_sign (gost_ec_compute_public)

; 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 = external hidden unnamed_addr constant [67 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

declare void @ERR_GOST_error(i32 noundef, i32 noundef, ptr noundef, i32 noundef) #1

declare void @BN_CTX_start(ptr noundef) #1

declare ptr @EC_POINT_new(ptr noundef) #1

declare void @EC_POINT_free(ptr noundef) #1

declare void @BN_CTX_end(ptr noundef) #1

declare void @BN_CTX_free(ptr noundef) #1

declare ptr @BN_CTX_secure_new() #1

declare ptr @EC_KEY_get0_group(ptr noundef) #1

declare ptr @EC_KEY_get0_private_key(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @gost_ec_point_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @gost_ec_compute_public(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call ptr @EC_KEY_get0_group(ptr noundef %13)
  br label %16

15:                                               ; preds = %1
  br label %16

16:                                               ; preds = %15, %12
  %17 = phi ptr [ %14, %12 ], [ null, %15 ]
  store ptr %17, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @ERR_GOST_error(i32 noundef 107, i32 noundef 119, ptr noundef @.str, i32 noundef 458)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %63

21:                                               ; preds = %16
  %22 = call ptr @BN_CTX_secure_new()
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @ERR_GOST_error(i32 noundef 107, i32 noundef 786688, ptr noundef @.str, i32 noundef 464)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %63

26:                                               ; preds = %21
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BN_CTX_start(ptr noundef %27)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = call ptr @EC_KEY_get0_private_key(ptr noundef %28)
  store ptr %29, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %33, label %32

32:                                               ; preds = %26
  call void @ERR_GOST_error(i32 noundef 107, i32 noundef 524304, ptr noundef @.str, i32 noundef 471)
  br label %54

33:                                               ; preds = %26
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = call ptr @EC_POINT_new(ptr noundef %34)
  store ptr %35, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %39, label %38

38:                                               ; preds = %33
  call void @ERR_GOST_error(i32 noundef 107, i32 noundef 786688, ptr noundef @.str, i32 noundef 477)
  br label %54

39:                                               ; preds = %33
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call i32 @gost_ec_point_mul(ptr noundef %40, ptr noundef %41, ptr noundef %42, ptr noundef null, ptr noundef null, ptr noundef %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %47, label %46

46:                                               ; preds = %39
  call void @ERR_GOST_error(i32 noundef 107, i32 noundef 524304, ptr noundef @.str, i32 noundef 482)
  br label %54

47:                                               ; preds = %39
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call i32 @EC_KEY_set_public_key(ptr noundef %48, ptr noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %47
  call void @ERR_GOST_error(i32 noundef 107, i32 noundef 524304, ptr noundef @.str, i32 noundef 486)
  br label %54

53:                                               ; preds = %47
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %53, %52, %46, %38, %32
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @EC_POINT_free(ptr noundef %58)
  br label %59

59:                                               ; preds = %57, %54
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BN_CTX_end(ptr noundef %60)
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BN_CTX_free(ptr noundef %61)
  %62 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %62, ptr %2, align 4
  store i32 1, ptr %9, align 4
  br label %63

63:                                               ; preds = %59, %25, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %64 = load i32, ptr %2, align 4
  ret i32 %64
}

declare i32 @EC_KEY_set_public_key(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = !{!"int", !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 = external hidden unnamed_addr constant [67 x i8], align 1

declare void @ERR_GOST_error(i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @BN_CTX_start(ptr noundef) local_unnamed_addr #0

declare ptr @EC_POINT_new(ptr noundef) local_unnamed_addr #0

declare void @EC_POINT_free(ptr noundef) local_unnamed_addr #0

declare void @BN_CTX_end(ptr noundef) local_unnamed_addr #0

declare void @BN_CTX_free(ptr noundef) local_unnamed_addr #0

declare ptr @BN_CTX_secure_new() local_unnamed_addr #0

declare ptr @EC_KEY_get0_group(ptr noundef) local_unnamed_addr #0

declare ptr @EC_KEY_get0_private_key(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @gost_ec_compute_public(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread, label %2

2:                                                ; preds = %1
  %3 = tail call ptr @EC_KEY_get0_group(ptr noundef nonnull %0) #2
  %.not27 = icmp eq ptr %3, null
  br i1 %.not27, label %.thread, label %4

.thread:                                          ; preds = %1, %2
  tail call void @ERR_GOST_error(i32 noundef 107, i32 noundef 119, ptr noundef nonnull @.str, i32 noundef 458) #2
  br label %19

4:                                                ; preds = %2
  %5 = tail call ptr @BN_CTX_secure_new() #2
  %.not28 = icmp eq ptr %5, null
  br i1 %.not28, label %6, label %7

6:                                                ; preds = %4
  tail call void @ERR_GOST_error(i32 noundef 107, i32 noundef 786688, ptr noundef nonnull @.str, i32 noundef 464) #2
  br label %19

7:                                                ; preds = %4
  tail call void @BN_CTX_start(ptr noundef nonnull %5) #2
  %8 = tail call ptr @EC_KEY_get0_private_key(ptr noundef nonnull %0) #2
  %.not29 = icmp eq ptr %8, null
  br i1 %.not29, label %9, label %10

9:                                                ; preds = %7
  tail call void @ERR_GOST_error(i32 noundef 107, i32 noundef 524304, ptr noundef nonnull @.str, i32 noundef 471) #2
  br label %18

10:                                               ; preds = %7
  %11 = tail call ptr @EC_POINT_new(ptr noundef nonnull %3) #2
  %.not30 = icmp eq ptr %11, null
  br i1 %.not30, label %12, label %13

12:                                               ; preds = %10
  tail call void @ERR_GOST_error(i32 noundef 107, i32 noundef 786688, ptr noundef nonnull @.str, i32 noundef 477) #2
  br label %18

13:                                               ; preds = %10
  %14 = tail call i32 @gost_ec_point_mul(ptr noundef nonnull %3, ptr noundef nonnull %11, ptr noundef nonnull %8, ptr noundef null, ptr noundef null, ptr noundef nonnull %5)
  %.not31 = icmp eq i32 %14, 0
  br i1 %.not31, label %.sink.split, label %15

15:                                               ; preds = %13
  %16 = tail call i32 @EC_KEY_set_public_key(ptr noundef nonnull %0, ptr noundef nonnull %11) #2
  %.not32 = icmp eq i32 %16, 0
  br i1 %.not32, label %.sink.split, label %17

.sink.split:                                      ; preds = %15, %13
  %.sink = phi i32 [ 482, %13 ], [ 486, %15 ]
  tail call void @ERR_GOST_error(i32 noundef 107, i32 noundef 524304, ptr noundef nonnull @.str, i32 noundef %.sink) #2
  br label %17

17:                                               ; preds = %.sink.split, %15
  %.0.ph = phi i32 [ 1, %15 ], [ 0, %.sink.split ]
  tail call void @EC_POINT_free(ptr noundef nonnull %11) #2
  br label %18

18:                                               ; preds = %9, %12, %17
  %.041 = phi i32 [ %.0.ph, %17 ], [ 0, %12 ], [ 0, %9 ]
  tail call void @BN_CTX_end(ptr noundef nonnull %5) #2
  tail call void @BN_CTX_free(ptr noundef nonnull %5) #2
  br label %19

19:                                               ; preds = %18, %6, %.thread
  %.021 = phi i32 [ %.041, %18 ], [ 0, %6 ], [ 0, %.thread ]
  ret i32 %.021
}

declare i32 @EC_KEY_set_public_key(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { 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: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass