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

/* Variables and functions */
int /*<<< orphan*/ EVP_PKEY_CTRL_SET_MAC_KEY;
int /*<<< orphan*/ free(unsigned char *);
int pkey_hmac_ctrl(int /*<<< orphan*/ *, int /*<<< orphan*/, long,
                   unsigned char *);
int /*<<< orphan*/ strcmp(char const *, char *);
unsigned char *string_to_hex(char const *, long *);
int pkey_hmac_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) {
  if (!value) {
    return 0;
  }
  if (!strcmp(type, "key")) {
    void *p = (void *)value;
    return pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, -1, p);
  }
  if (!strcmp(type, "hexkey")) {
    unsigned char *key;
    int r;
    long keylen;
    key = string_to_hex(value, &keylen);
    if (!key)
      return 0;
    r = pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
    free(key);
    return r;
  }
  return -2;
}


x86 assembly (clang, -O0):
<pkey_hmac_ctrl_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <pkey_hmac_ctrl_str+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    122a <pkey_hmac_ctrl_str+0xea>
mov    -0x18(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b1 <pkey_hmac_ctrl_str+0x71>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%rcx
mov    $0xffffffffffffffff,%rdx
call   1040 <pkey_hmac_ctrl@plt>
mov    %eax,-0x4(%rbp)
jmp    122a <pkey_hmac_ctrl_str+0xea>
mov    -0x18(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1223 <pkey_hmac_ctrl_str+0xe3>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <string_to_hex@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f2 <pkey_hmac_ctrl_str+0xb2>
movl   $0x0,-0x4(%rbp)
jmp    122a <pkey_hmac_ctrl_str+0xea>
mov    -0x10(%rbp),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <pkey_hmac_ctrl@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122a <pkey_hmac_ctrl_str+0xea>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkey_hmac_ctrl_str>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdx,%rdx
je     11bb <pkey_hmac_ctrl_str+0x7b>
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xea6(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c8 <pkey_hmac_ctrl_str+0x88>
lea    0xe90(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
mov    $0xfffffffe,%ebp
test   %eax,%eax
jne    11bd <pkey_hmac_ctrl_str+0x7d>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <string_to_hex@plt>
test   %rax,%rax
je     11bb <pkey_hmac_ctrl_str+0x7b>
mov    %rax,%rbx
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1040 <pkey_hmac_ctrl@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11bd <pkey_hmac_ctrl_str+0x7d>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
mov    $0xffffffffffffffff,%rdx
mov    %rbx,%rcx
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <pkey_hmac_ctrl@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"key\00"
@EVP_PKEY_CTRL_SET_MAC_KEY = global i32 0
@.str.1 = [7 x i8] c"hexkey\00"
define i32 @pkey_hmac_ctrl_str(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 0, i32* %4
br label %45
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %15
%20 = load i8*, i8** %7
store i8* %20, i8** %8
%21 = load i32*, i32** %5
%22 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%23 = load i8*, i8** %8
%24 = call i32 @pkey_hmac_ctrl(i32* %21, i32 %22, i64 -1, i8* %23)
store i32 %24, i32* %4
br label %45
25: ; preds = %15
%26 = load i8*, i8** %6
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %44, label %29
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = call i8* @string_to_hex(i8* %30, i64* %11)
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %29
store i32 0, i32* %4
br label %45
35: ; preds = %29
%36 = load i32*, i32** %5
%37 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%38 = load i64, i64* %11
%39 = load i8*, i8** %9
%40 = call i32 @pkey_hmac_ctrl(i32* %36, i32 %37, i64 %38, i8* %39)
store i32 %40, i32* %10
%41 = load i8*, i8** %9
%42 = call i32 @free(i8* %41)
%43 = load i32, i32* %10
store i32 %43, i32* %4
br label %45
44: ; preds = %25
store i32 -2, i32* %4
br label %45
45: ; preds = %44, %35, %34, %19, %14
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [4 x i8] c"key\00"
@EVP_PKEY_CTRL_SET_MAC_KEY = global i32 0
@.str.1 = [7 x i8] c"hexkey\00"
define i32 @pkey_hmac_ctrl_str(i32* %0, i8* nocapture %1, i8* %2) {
%4 = alloca i64
%5 = icmp eq i8* %2, null
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%11 = tail call i32 @pkey_hmac_ctrl(i32* %0, i32 %10, i64 -1, i8* %2)
br label %26
12: ; preds = %6
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = bitcast i64* %4 to i8*
%17 = call i8* @string_to_hex(i8* %2, i64* %4)
%18 = icmp eq i8* %17, null
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = load i32, i32* @EVP_PKEY_CTRL_SET_MAC_KEY
%21 = load i64, i64* %4
%22 = call i32 @pkey_hmac_ctrl(i32* %0, i32 %20, i64 %21, i8* %17)
%23 = call i32 @free(i8* %17)
br label %24
24: ; preds = %15, %19
%25 = phi i32 [ %22, %19 ], [ 0, %15 ]
br label %26
26: ; preds = %12, %3, %24, %9
%27 = phi i32 [ %25, %24 ], [ %11, %9 ], [ 0, %3 ], [ -2, %12 ]
ret i32 %27
}