#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ DSA;
typedef int /*<<< orphan*/ ASN1_OBJECT;

/* Variables and functions */
int /*<<< orphan*/ ASN1_OBJECT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *DSA_new();
int /*<<< orphan*/ EVP_PKEY_assign(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_get0(int /*<<< orphan*/ *);
int /*<<< orphan*/ NID_id_GostR3410_94;
int OBJ_obj2nid(int /*<<< orphan*/ *);
int /*<<< orphan*/ *d2i_ASN1_OBJECT(int /*<<< orphan*/ **,
                                    unsigned char const **, int);
int /*<<< orphan*/ fill_GOST94_params(int /*<<< orphan*/ *, int);
int gost94_param_decode(EVP_PKEY *pkey, const unsigned char **pder,
                        int derlen) {
  ASN1_OBJECT *obj = NULL;
  DSA *dsa = EVP_PKEY_get0(pkey);
  int nid;
  if (d2i_ASN1_OBJECT(&obj, pder, derlen) == NULL) {
    return 0;
  }
  nid = OBJ_obj2nid(obj);
  ASN1_OBJECT_free(obj);
  if (!dsa) {
    dsa = DSA_new();
    if (!EVP_PKEY_assign(pkey, NID_id_GostR3410_94, dsa))
      return 0;
  }
  if (!fill_GOST94_params(dsa, nid))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<gost94_param_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <EVP_PKEY_get0@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1060 <d2i_ASN1_OBJECT@plt>
cmp    $0x0,%rax
jne    11be <gost94_param_decode+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1241 <gost94_param_decode+0xd1>
mov    -0x28(%rbp),%rdi
call   1030 <OBJ_obj2nid@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <ASN1_OBJECT_free@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1219 <gost94_param_decode+0xa9>
mov    $0x0,%al
call   1040 <DSA_new@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rdx
call   1080 <EVP_PKEY_assign@plt>
cmp    $0x0,%eax
jne    1214 <gost94_param_decode+0xa4>
movl   $0x0,-0x4(%rbp)
jmp    1241 <gost94_param_decode+0xd1>
jmp    1219 <gost94_param_decode+0xa9>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1070 <fill_GOST94_params@plt>
cmp    $0x0,%eax
jne    123a <gost94_param_decode+0xca>
movl   $0x0,-0x4(%rbp)
jmp    1241 <gost94_param_decode+0xd1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gost94_param_decode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
call   1050 <EVP_PKEY_get0@plt>
mov    %rax,%r12
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <d2i_ASN1_OBJECT@plt>
test   %rax,%rax
je     11fe <gost94_param_decode+0x8e>
mov    0x8(%rsp),%rdi
call   1030 <OBJ_obj2nid@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%rdi
call   1090 <ASN1_OBJECT_free@plt>
test   %r12,%r12
jne    11e9 <gost94_param_decode+0x79>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <DSA_new@plt>
mov    %rax,%r12
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    %r12,%rdx
call   1080 <EVP_PKEY_assign@plt>
test   %eax,%eax
je     1200 <gost94_param_decode+0x90>
mov    %r12,%rdi
mov    %r15d,%esi
call   1070 <fill_GOST94_params@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
jmp    1200 <gost94_param_decode+0x90>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NID_id_GostR3410_94 = global i32 0
define i32 @gost94_param_decode(i32* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32* %0, i32** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32* null, i32** %8
%11 = load i32*, i32** %5
%12 = call i32* @EVP_PKEY_get0(i32* %11)
store i32* %12, i32** %9
%13 = load i8**, i8*** %6
%14 = load i32, i32* %7
%15 = call i32* @d2i_ASN1_OBJECT(i32** %8, i8** %13, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %41
18: ; preds = %3
%19 = load i32*, i32** %8
%20 = call i32 @OBJ_obj2nid(i32* %19)
store i32 %20, i32* %10
%21 = load i32*, i32** %8
%22 = call i32 @ASN1_OBJECT_free(i32* %21)
%23 = load i32*, i32** %9
%24 = icmp ne i32* %23, null
br i1 %24, label %34, label %25
25: ; preds = %18
%26 = call i32* (...) @DSA_new()
store i32* %26, i32** %9
%27 = load i32*, i32** %5
%28 = load i32, i32* @NID_id_GostR3410_94
%29 = load i32*, i32** %9
%30 = call i32 @EVP_PKEY_assign(i32* %27, i32 %28, i32* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %25
store i32 0, i32* %4
br label %41
33: ; preds = %25
br label %34
34: ; preds = %33, %18
%35 = load i32*, i32** %9
%36 = load i32, i32* %10
%37 = call i32 @fill_GOST94_params(i32* %35, i32 %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %34
store i32 0, i32* %4
br label %41
40: ; preds = %34
store i32 1, i32* %4
br label %41
41: ; preds = %40, %39, %32, %17
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@NID_id_GostR3410_94 = global i32 0
define i32 @gost94_param_decode(i32* %0, i8** %1, i32 %2) {
%4 = alloca i32*
%5 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%6 = tail call i32* @EVP_PKEY_get0(i32* %0)
%7 = call i32* @d2i_ASN1_OBJECT(i32** %4, i8** %1, i32 %2)
%8 = icmp eq i32* %7, null
br i1 %8, label %25, label %9
9: ; preds = %3
%10 = load i32*, i32** %4
%11 = call i32 @OBJ_obj2nid(i32* %10)
%12 = load i32*, i32** %4
%13 = call i32 @ASN1_OBJECT_free(i32* %12)
%14 = icmp eq i32* %6, null
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = call i32* (...) @DSA_new()
%17 = load i32, i32* @NID_id_GostR3410_94
%18 = call i32 @EVP_PKEY_assign(i32* %0, i32 %17, i32* %16)
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %15, %9
%21 = phi i32* [ %6, %9 ], [ %16, %15 ]
%22 = call i32 @fill_GOST94_params(i32* %21, i32 %11)
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %20, %15, %3
%26 = phi i32 [ 0, %3 ], [ 0, %15 ], [ %24, %20 ]
ret i32 %26
}