#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_DSA_PARAMGEN_MD;
int /*<<< orphan*/ EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS;
int EVP_PKEY_CTX_ctrl(int /*<<< orphan*/ *, int /*<<< orphan*/,
                      int /*<<< orphan*/, int /*<<< orphan*/, int, void *);
int EVP_PKEY_CTX_set_dsa_paramgen_bits(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ EVP_PKEY_DSA;
int /*<<< orphan*/ EVP_PKEY_OP_PARAMGEN;
scalar_t__ EVP_get_digestbyname(char const *);
int atoi(char const *);
scalar_t__ strcmp(char const *, char *);
int pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value) {
  if (strcmp(type, "dsa_paramgen_bits") == 0) {
    int nbits;
    nbits = atoi(value);
    return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits);
  }
  if (strcmp(type, "dsa_paramgen_q_bits") == 0) {
    int qbits = atoi(value);
    return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
                             EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, qbits, NULL);
  }
  if (strcmp(type, "dsa_paramgen_md") == 0) {
    return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
                             EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0,
                             (void *)EVP_get_digestbyname(value));
  }
  return -2;
}


x86 assembly (clang, -O0):
<pkey_dsa_ctrl_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    119e <pkey_dsa_ctrl_str+0x4e>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <EVP_PKEY_CTX_set_dsa_paramgen_bits@plt>
mov    %eax,-0x4(%rbp)
jmp    126f <pkey_dsa_ctrl_str+0x11f>
mov    -0x18(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11f9 <pkey_dsa_ctrl_str+0xa9>
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
mov    0x2df7(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1040 <EVP_PKEY_CTX_ctrl@plt>
mov    %eax,-0x4(%rbp)
jmp    126f <pkey_dsa_ctrl_str+0x11f>
mov    -0x18(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1268 <pkey_dsa_ctrl_str+0x118>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <EVP_get_digestbyname@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    %rax,%r9
xor    %r8d,%r8d
call   1040 <EVP_PKEY_CTX_ctrl@plt>
mov    %eax,-0x4(%rbp)
jmp    126f <pkey_dsa_ctrl_str+0x11f>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkey_dsa_ctrl_str>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11ab <pkey_dsa_ctrl_str+0x5b>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11c5 <pkey_dsa_ctrl_str+0x75>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11f3 <pkey_dsa_ctrl_str+0xa3>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    %r14,%rdi
mov    %eax,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <EVP_PKEY_CTX_set_dsa_paramgen_bits@plt>
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    0x2e1c(%rip),%rcx
mov    (%rcx),%esi
mov    0x2deb(%rip),%rcx
mov    (%rcx),%edx
mov    0x2df2(%rip),%rcx
mov    (%rcx),%ecx
mov    %r14,%rdi
mov    %eax,%r8d
xor    %r9d,%r9d
jmp    1227 <pkey_dsa_ctrl_str+0xd7>
mov    0x2df6(%rip),%rax
mov    (%rax),%r12d
mov    0x2dc4(%rip),%rax
mov    (%rax),%ebp
mov    0x2deb(%rip),%rax
mov    (%rax),%ebx
mov    %r15,%rdi
call   1050 <EVP_get_digestbyname@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %r8d,%r8d
mov    %rax,%r9
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <EVP_PKEY_CTX_ctrl@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"dsa_paramgen_bits\00"
@.str.1 = [20 x i8] c"dsa_paramgen_q_bits\00"
@EVP_PKEY_DSA = global i32 0
@EVP_PKEY_OP_PARAMGEN = global i32 0
@EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS = global i32 0
@.str.2 = [16 x i8] c"dsa_paramgen_md\00"
@EVP_PKEY_CTRL_DSA_PARAMGEN_MD = global i32 0
define i32 @pkey_dsa_ctrl_str(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %6
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %8
%16 = load i32*, i32** %5
%17 = load i32, i32* %8
%18 = call i32 @EVP_PKEY_CTX_set_dsa_paramgen_bits(i32* %16, i32 %17)
store i32 %18, i32* %4
br label %46
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i8*, i8** %7
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %9
%26 = load i32*, i32** %5
%27 = load i32, i32* @EVP_PKEY_DSA
%28 = load i32, i32* @EVP_PKEY_OP_PARAMGEN
%29 = load i32, i32* @EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS
%30 = load i32, i32* %9
%31 = call i32 @EVP_PKEY_CTX_ctrl(i32* %26, i32 %27, i32 %28, i32 %29, i32 %30, i8* null)
store i32 %31, i32* %4
br label %46
32: ; preds = %19
%33 = load i8*, i8** %6
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i32*, i32** %5
%38 = load i32, i32* @EVP_PKEY_DSA
%39 = load i32, i32* @EVP_PKEY_OP_PARAMGEN
%40 = load i32, i32* @EVP_PKEY_CTRL_DSA_PARAMGEN_MD
%41 = load i8*, i8** %7
%42 = call i64 @EVP_get_digestbyname(i8* %41)
%43 = inttoptr i64 %42 to i8*
%44 = call i32 @EVP_PKEY_CTX_ctrl(i32* %37, i32 %38, i32 %39, i32 %40, i32 0, i8* %43)
store i32 %44, i32* %4
br label %46
45: ; preds = %32
store i32 -2, i32* %4
br label %46
46: ; preds = %45, %36, %23, %13
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@.str = [18 x i8] c"dsa_paramgen_bits\00"
@.str.1 = [20 x i8] c"dsa_paramgen_q_bits\00"
@EVP_PKEY_DSA = global i32 0
@EVP_PKEY_OP_PARAMGEN = global i32 0
@EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS = global i32 0
@.str.2 = [16 x i8] c"dsa_paramgen_md\00"
@EVP_PKEY_CTRL_DSA_PARAMGEN_MD = global i32 0
define i32 @pkey_dsa_ctrl_str(i32* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @atoi(i8* %2)
%8 = tail call i32 @EVP_PKEY_CTX_set_dsa_paramgen_bits(i32* %0, i32 %7)
br label %28
9: ; preds = %3
%10 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = tail call i32 @atoi(i8* %2)
%14 = load i32, i32* @EVP_PKEY_DSA
%15 = load i32, i32* @EVP_PKEY_OP_PARAMGEN
%16 = load i32, i32* @EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS
%17 = tail call i32 @EVP_PKEY_CTX_ctrl(i32* %0, i32 %14, i32 %15, i32 %16, i32 %13, i8* null)
br label %28
18: ; preds = %9
%19 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* @EVP_PKEY_DSA
%23 = load i32, i32* @EVP_PKEY_OP_PARAMGEN
%24 = load i32, i32* @EVP_PKEY_CTRL_DSA_PARAMGEN_MD
%25 = tail call i64 @EVP_get_digestbyname(i8* %2)
%26 = inttoptr i64 %25 to i8*
%27 = tail call i32 @EVP_PKEY_CTX_ctrl(i32* %0, i32 %22, i32 %23, i32 %24, i32 0, i8* %26)
br label %28
28: ; preds = %18, %21, %12, %6
%29 = phi i32 [ %8, %6 ], [ %17, %12 ], [ %27, %21 ], [ -2, %18 ]
ret i32 %29
}