#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_CTX;
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ ENGINE;

/* Variables and functions */
int /*<<< orphan*/ EVP_PKEY_CTRL_SET_MAC_KEY;
scalar_t__ EVP_PKEY_CTX_ctrl(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                             int /*<<< orphan*/, int, void *);
int /*<<< orphan*/ EVP_PKEY_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_CTX_new_id(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_OP_KEYGEN;
scalar_t__ EVP_PKEY_keygen(int /*<<< orphan*/ *, int /*<<< orphan*/ **);
scalar_t__ EVP_PKEY_keygen_init(int /*<<< orphan*/ *);
EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key,
                               int keylen) {
  EVP_PKEY_CTX *mac_ctx = NULL;
  EVP_PKEY *mac_key = NULL;
  mac_ctx = EVP_PKEY_CTX_new_id(type, e);
  if (!mac_ctx)
    return NULL;
  if (EVP_PKEY_keygen_init(mac_ctx) <= 0)
    goto merr;
  if (EVP_PKEY_CTX_ctrl(mac_ctx, -1, EVP_PKEY_OP_KEYGEN,
                        EVP_PKEY_CTRL_SET_MAC_KEY, keylen, (void *)key) <= 0)
    goto merr;
  if (EVP_PKEY_keygen(mac_ctx, &mac_key) <= 0)
    goto merr;
merr:
  EVP_PKEY_CTX_free(mac_ctx);
  return mac_key;
}


x86 assembly (clang, -O0):
<EVP_PKEY_new_mac_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <EVP_PKEY_CTX_new_id@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119e <EVP_PKEY_new_mac_key+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    121f <EVP_PKEY_new_mac_key+0xcf>
mov    -0x30(%rbp),%rdi
call   1060 <EVP_PKEY_keygen_init@plt>
cmp    $0x0,%rax
jg     11b6 <EVP_PKEY_new_mac_key+0x66>
jmp    120e <EVP_PKEY_new_mac_key+0xbe>
mov    -0x30(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
mov    0x2e0e(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    $0xffffffff,%esi
call   1040 <EVP_PKEY_CTX_ctrl@plt>
cmp    $0x0,%rax
jg     11ed <EVP_PKEY_new_mac_key+0x9d>
jmp    120e <EVP_PKEY_new_mac_key+0xbe>
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <EVP_PKEY_keygen@plt>
cmp    $0x0,%rax
jg     1209 <EVP_PKEY_new_mac_key+0xb9>
jmp    120e <EVP_PKEY_new_mac_key+0xbe>
jmp    120e <EVP_PKEY_new_mac_key+0xbe>
mov    -0x30(%rbp),%rdi
call   1070 <EVP_PKEY_CTX_free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EVP_PKEY_new_mac_key>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %rdx,%r14
movq   $0x0,0x8(%rsp)
call   1050 <EVP_PKEY_CTX_new_id@plt>
test   %rax,%rax
je     11c6 <EVP_PKEY_new_mac_key+0x76>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <EVP_PKEY_keygen_init@plt>
test   %rax,%rax
jle    11b7 <EVP_PKEY_new_mac_key+0x67>
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    0x2e48(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    %ebp,%r8d
mov    %r14,%r9
call   1040 <EVP_PKEY_CTX_ctrl@plt>
test   %rax,%rax
jle    11b7 <EVP_PKEY_new_mac_key+0x67>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <EVP_PKEY_keygen@plt>
mov    %rbx,%rdi
call   1070 <EVP_PKEY_CTX_free@plt>
mov    0x8(%rsp),%rax
jmp    11c8 <EVP_PKEY_new_mac_key+0x78>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EVP_PKEY_OP_KEYGEN = global i32 0
@EVP_PKEY_CTRL_SET_MAC_KEY = global i32 0
define i32* @EVP_PKEY_new_mac_key(i32 %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i32 %0, i32* %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32* null, i32** %10
store i32* null, i32** %11
%12 = load i32, i32* %6
%13 = load i32*, i32** %7
%14 = call i32* @EVP_PKEY_CTX_new_id(i32 %12, i32* %13)
store i32* %14, i32** %10
%15 = load i32*, i32** %10
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %4
store i32* null, i32** %5
br label %42
18: ; preds = %4
%19 = load i32*, i32** %10
%20 = call i64 @EVP_PKEY_keygen_init(i32* %19)
%21 = icmp sle i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %38
23: ; preds = %18
%24 = load i32*, i32** %10
%25 = load i32, i32* @EVP_PKEY_OP_KEYGEN
%26 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%27 = load i32, i32* %9
%28 = load i8*, i8** %8
%29 = call i64 @EVP_PKEY_CTX_ctrl(i32* %24, i32 -1, i32 %25, i32 %26, i32 %27, i8* %28)
%30 = icmp sle i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %23
br label %38
32: ; preds = %23
%33 = load i32*, i32** %10
%34 = call i64 @EVP_PKEY_keygen(i32* %33, i32** %11)
%35 = icmp sle i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
br label %38
37: ; preds = %32
br label %38
38: ; preds = %37, %36, %31, %22
%39 = load i32*, i32** %10
%40 = call i32 @EVP_PKEY_CTX_free(i32* %39)
%41 = load i32*, i32** %11
store i32* %41, i32** %5
br label %42
42: ; preds = %38, %17
%43 = load i32*, i32** %5
ret i32* %43
}

LLVM IR (-O2):
@EVP_PKEY_OP_KEYGEN = global i32 0
@EVP_PKEY_CTRL_SET_MAC_KEY = global i32 0
define i32* @EVP_PKEY_new_mac_key(i32 %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = bitcast i32** %5 to i8*
store i32* null, i32** %5
%7 = tail call i32* @EVP_PKEY_CTX_new_id(i32 %0, i32* %1)
%8 = icmp eq i32* %7, null
br i1 %8, label %22, label %9
9: ; preds = %4
%10 = tail call i64 @EVP_PKEY_keygen_init(i32* %7)
%11 = icmp slt i64 %10, 1
br i1 %11, label %19, label %12
12: ; preds = %9
%13 = load i32, i32* @EVP_PKEY_OP_KEYGEN
%14 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%15 = tail call i64 @EVP_PKEY_CTX_ctrl(i32* %7, i32 -1, i32 %13, i32 %14, i32 %3, i8* %2)
%16 = icmp slt i64 %15, 1
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i64 @EVP_PKEY_keygen(i32* %7, i32** %5)
br label %19
19: ; preds = %17, %12, %9
%20 = call i32 @EVP_PKEY_CTX_free(i32* %7)
%21 = load i32*, i32** %5
br label %22
22: ; preds = %4, %19
%23 = phi i32* [ %21, %19 ], [ null, %4 ]
ret i32* %23
}