#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*/ EC_F_PKEY_EC_CTRL_STR;
int /*<<< orphan*/ EC_R_INVALID_CURVE;
int EC_curve_nist2nid(char const *);
int /*<<< orphan*/ ECerr(int /*<<< orphan*/, int /*<<< orphan*/);
int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(int /*<<< orphan*/ *, int);
int NID_undef;
int OBJ_ln2nid(char const *);
int OBJ_sn2nid(char const *);
int /*<<< orphan*/ strcmp(char const *, char *);
int pkey_ec_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) {
  if (!strcmp(type, "ec_paramgen_curve")) {
    int nid;
    nid = EC_curve_nist2nid(value);
    if (nid == NID_undef)
      nid = OBJ_sn2nid(value);
    if (nid == NID_undef)
      nid = OBJ_ln2nid(value);
    if (nid == NID_undef) {
      ECerr(EC_F_PKEY_EC_CTRL_STR, EC_R_INVALID_CURVE);
      return 0;
    }
    return EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid);
  }
  return -2;
}


x86 assembly (clang, -O0):
<pkey_ec_ctrl_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    121e <pkey_ec_ctrl_str+0xbe>
mov    -0x20(%rbp),%rdi
call   1060 <EC_curve_nist2nid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%eax
jne    11b7 <pkey_ec_ctrl_str+0x57>
mov    -0x20(%rbp),%rdi
call   1030 <OBJ_sn2nid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%eax
jne    11d5 <pkey_ec_ctrl_str+0x75>
mov    -0x20(%rbp),%rdi
call   1050 <OBJ_ln2nid@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2df1(%rip),%rcx
cmp    (%rcx),%eax
jne    120a <pkey_ec_ctrl_str+0xaa>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1080 <ECerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1225 <pkey_ec_ctrl_str+0xc5>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <EVP_PKEY_CTX_set_ec_paramgen_curve_nid@plt>
mov    %eax,-0x4(%rbp)
jmp    1225 <pkey_ec_ctrl_str+0xc5>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkey_ec_ctrl_str>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xe8b(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
test   %ecx,%ecx
jne    11bf <pkey_ec_ctrl_str+0x5f>
mov    %rbx,%rdi
call   1060 <EC_curve_nist2nid@plt>
mov    0x2e39(%rip),%r15
mov    (%r15),%ecx
cmp    %ecx,%eax
je     11c5 <pkey_ec_ctrl_str+0x65>
cmp    %ecx,%eax
je     11d4 <pkey_ec_ctrl_str+0x74>
cmp    %ecx,%eax
jne    11e3 <pkey_ec_ctrl_str+0x83>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1080 <ECerr@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1030 <OBJ_sn2nid@plt>
mov    (%r15),%ecx
cmp    %ecx,%eax
jne    11a2 <pkey_ec_ctrl_str+0x42>
mov    %rbx,%rdi
call   1050 <OBJ_ln2nid@plt>
mov    (%r15),%ecx
cmp    %ecx,%eax
je     11a6 <pkey_ec_ctrl_str+0x46>
mov    %r14,%rdi
mov    %eax,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <EVP_PKEY_CTX_set_ec_paramgen_curve_nid@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"ec_paramgen_curve\00"
@NID_undef = global i32 0
@EC_F_PKEY_EC_CTRL_STR = global i32 0
@EC_R_INVALID_CURVE = global i32 0
define i32 @pkey_ec_ctrl_str(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %6
%10 = call i32 @strcmp(i8* %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %40, label %12
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = call i32 @EC_curve_nist2nid(i8* %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = load i32, i32* @NID_undef
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i8*, i8** %7
%20 = call i32 @OBJ_sn2nid(i8* %19)
store i32 %20, i32* %8
br label %21
21: ; preds = %18, %12
%22 = load i32, i32* %8
%23 = load i32, i32* @NID_undef
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %7
%27 = call i32 @OBJ_ln2nid(i8* %26)
store i32 %27, i32* %8
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %8
%30 = load i32, i32* @NID_undef
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* @EC_F_PKEY_EC_CTRL_STR
%34 = load i32, i32* @EC_R_INVALID_CURVE
%35 = call i32 @ECerr(i32 %33, i32 %34)
store i32 0, i32* %4
br label %41
36: ; preds = %28
%37 = load i32*, i32** %5
%38 = load i32, i32* %8
%39 = call i32 @EVP_PKEY_CTX_set_ec_paramgen_curve_nid(i32* %37, i32 %38)
store i32 %39, i32* %4
br label %41
40: ; preds = %3
store i32 -2, i32* %4
br label %41
41: ; preds = %40, %36, %32
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@.str = [18 x i8] c"ec_paramgen_curve\00"
@NID_undef = global i32 0
@EC_F_PKEY_EC_CTRL_STR = global i32 0
@EC_R_INVALID_CURVE = global i32 0
define i32 @pkey_ec_ctrl_str(i32* %0, i8* nocapture %1, i8* %2) {
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = tail call i32 @EC_curve_nist2nid(i8* %2)
%8 = load i32, i32* @NID_undef
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i32 @OBJ_sn2nid(i8* %2)
%12 = load i32, i32* @NID_undef
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ %12, %10 ], [ %8, %6 ]
%15 = phi i32 [ %11, %10 ], [ %7, %6 ]
%16 = icmp eq i32 %15, %14
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = tail call i32 @OBJ_ln2nid(i8* %2)
%19 = load i32, i32* @NID_undef
br label %20
20: ; preds = %17, %13
%21 = phi i32 [ %19, %17 ], [ %14, %13 ]
%22 = phi i32 [ %18, %17 ], [ %15, %13 ]
%23 = icmp eq i32 %22, %21
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* @EC_F_PKEY_EC_CTRL_STR
%26 = load i32, i32* @EC_R_INVALID_CURVE
%27 = tail call i32 @ECerr(i32 %25, i32 %26)
br label %30
28: ; preds = %20
%29 = tail call i32 @EVP_PKEY_CTX_set_ec_paramgen_curve_nid(i32* %0, i32 %22)
br label %30
30: ; preds = %3, %24, %28
%31 = phi i32 [ 0, %24 ], [ %29, %28 ], [ -2, %3 ]
ret i32 %31
}