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

/* Variables and functions */
#define ASN1_PKEY_CTRL_DEFAULT_MD_NID 130
#define ASN1_PKEY_CTRL_PKCS7_ENCRYPT 129
#define ASN1_PKEY_CTRL_PKCS7_SIGN 128
int /*<<< orphan*/ NID_rsaEncryption;
int NID_sha1;
int /*<<< orphan*/ OBJ_nid2obj(int /*<<< orphan*/);
int /*<<< orphan*/ PKCS7_RECIP_INFO_get0_alg(void *, int /*<<< orphan*/ **);
int /*<<< orphan*/ PKCS7_SIGNER_INFO_get0_algs(void *, int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ *,
                                               int /*<<< orphan*/ **);
int /*<<< orphan*/ V_ASN1_NULL;
int /*<<< orphan*/ X509_ALGOR_set0(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/, int /*<<< orphan*/);
int rsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) {
  X509_ALGOR *alg = NULL;
  switch (op) {
  case ASN1_PKEY_CTRL_PKCS7_SIGN:
    if (arg1 == 0)
      PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, NULL, &alg);
    break;
  case ASN1_PKEY_CTRL_PKCS7_ENCRYPT:
    if (arg1 == 0)
      PKCS7_RECIP_INFO_get0_alg(arg2, &alg);
    break;
  case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
    *(int *)arg2 = NID_sha1;
    return 1;
  default:
    return -2;
  }
  if (alg)
    X509_ALGOR_set0(alg, OBJ_nid2obj(NID_rsaEncryption), V_ASN1_NULL, 0);
  return 1;
}


x86 assembly (clang, -O0):
<rsa_pkey_ctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x80,%eax
je     119b <rsa_pkey_ctrl+0x5b>
jmp    1175 <rsa_pkey_ctrl+0x35>
mov    -0x34(%rbp),%eax
sub    $0x81,%eax
je     11bf <rsa_pkey_ctrl+0x7f>
jmp    1188 <rsa_pkey_ctrl+0x48>
mov    -0x34(%rbp),%eax
sub    $0x82,%eax
je     11dc <rsa_pkey_ctrl+0x9c>
jmp    11f7 <rsa_pkey_ctrl+0xb7>
cmpq   $0x0,-0x20(%rbp)
jne    11ba <rsa_pkey_ctrl+0x7a>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x30(%rbp),%rcx
mov    %rdx,%rsi
call   1050 <PKCS7_SIGNER_INFO_get0_algs@plt>
jmp    1203 <rsa_pkey_ctrl+0xc3>
cmpq   $0x0,-0x20(%rbp)
jne    11d7 <rsa_pkey_ctrl+0x97>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <PKCS7_RECIP_INFO_get0_alg@plt>
jmp    1203 <rsa_pkey_ctrl+0xc3>
mov    0x2ded(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1241 <rsa_pkey_ctrl+0x101>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1241 <rsa_pkey_ctrl+0x101>
cmpq   $0x0,-0x30(%rbp)
je     123a <rsa_pkey_ctrl+0xfa>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1030 <OBJ_nid2obj@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1040 <X509_ALGOR_set0@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsa_pkey_ctrl>:
push   %r14
push   %rbx
push   %rax
movq   $0x0,(%rsp)
cmp    $0x82,%esi
je     1187 <rsa_pkey_ctrl+0x47>
cmp    $0x81,%esi
je     1199 <rsa_pkey_ctrl+0x59>
mov    $0xfffffffe,%ebx
cmp    $0x80,%esi
jne    11df <rsa_pkey_ctrl+0x9f>
mov    $0x1,%ebx
test   %rdx,%rdx
jne    11df <rsa_pkey_ctrl+0x9f>
mov    %rsp,%rax
mov    %rcx,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %rax,%rcx
call   1050 <PKCS7_SIGNER_INFO_get0_algs@plt>
jmp    11ae <rsa_pkey_ctrl+0x6e>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rcx)
mov    $0x1,%ebx
jmp    11df <rsa_pkey_ctrl+0x9f>
mov    $0x1,%ebx
test   %rdx,%rdx
jne    11df <rsa_pkey_ctrl+0x9f>
mov    %rsp,%rsi
mov    %rcx,%rdi
call   1060 <PKCS7_RECIP_INFO_get0_alg@plt>
mov    (%rsp),%r14
mov    $0x1,%ebx
test   %r14,%r14
je     11df <rsa_pkey_ctrl+0x9f>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1030 <OBJ_nid2obj@plt>
mov    0x2e07(%rip),%rcx
mov    (%rcx),%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %ecx,%ecx
call   1040 <X509_ALGOR_set0@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@NID_sha1 = global i32 0
@NID_rsaEncryption = global i32 0
@V_ASN1_NULL = global i32 0
define i32 @rsa_pkey_ctrl(i32* %0, i32 %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32*
store i32* %0, i32** %6
store i32 %1, i32* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i32* null, i32** %10
%11 = load i32, i32* %7
switch i32 %11, label %30 [
i32 128, label %12
i32 129, label %19
i32 130, label %26
]
12: ; preds = %4
%13 = load i64, i64* %8
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8*, i8** %9
%17 = call i32 @PKCS7_SIGNER_INFO_get0_algs(i8* %16, i32* null, i32* null, i32** %10)
br label %18
18: ; preds = %15, %12
br label %31
19: ; preds = %4
%20 = load i64, i64* %8
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %9
%24 = call i32 @PKCS7_RECIP_INFO_get0_alg(i8* %23, i32** %10)
br label %25
25: ; preds = %22, %19
br label %31
26: ; preds = %4
%27 = load i32, i32* @NID_sha1
%28 = load i8*, i8** %9
%29 = bitcast i8* %28 to i32*
store i32 %27, i32* %29
store i32 1, i32* %5
br label %41
30: ; preds = %4
store i32 -2, i32* %5
br label %41
31: ; preds = %25, %18
%32 = load i32*, i32** %10
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = load i32*, i32** %10
%36 = load i32, i32* @NID_rsaEncryption
%37 = call i32 @OBJ_nid2obj(i32 %36)
%38 = load i32, i32* @V_ASN1_NULL
%39 = call i32 @X509_ALGOR_set0(i32* %35, i32 %37, i32 %38, i32 0)
br label %40
40: ; preds = %34, %31
store i32 1, i32* %5
br label %41
41: ; preds = %40, %30, %26
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@NID_sha1 = global i32 0
@NID_rsaEncryption = global i32 0
@V_ASN1_NULL = global i32 0
define i32 @rsa_pkey_ctrl(i32* nocapture readnone %0, i32 %1, i64 %2, i8* %3) {
%5 = alloca i32*
%6 = bitcast i32** %5 to i8*
store i32* null, i32** %5
switch i32 %1, label %26 [
i32 128, label %7
i32 129, label %11
i32 130, label %15
]
7: ; preds = %4
%8 = icmp eq i64 %2, 0
br i1 %8, label %9, label %26
9: ; preds = %7
%10 = call i32 @PKCS7_SIGNER_INFO_get0_algs(i8* %3, i32* null, i32* null, i32** %5)
br label %18
11: ; preds = %4
%12 = icmp eq i64 %2, 0
br i1 %12, label %13, label %26
13: ; preds = %11
%14 = call i32 @PKCS7_RECIP_INFO_get0_alg(i8* %3, i32** %5)
br label %18
15: ; preds = %4
%16 = load i32, i32* @NID_sha1
%17 = bitcast i8* %3 to i32*
store i32 %16, i32* %17
br label %26
18: ; preds = %13, %9
%19 = load i32*, i32** %5
%20 = icmp eq i32* %19, null
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i32, i32* @NID_rsaEncryption
%23 = call i32 @OBJ_nid2obj(i32 %22)
%24 = load i32, i32* @V_ASN1_NULL
%25 = call i32 @X509_ALGOR_set0(i32* %19, i32 %23, i32 %24, i32 0)
br label %26
26: ; preds = %7, %11, %18, %21, %4, %15
%27 = phi i32 [ 1, %15 ], [ -2, %4 ], [ 1, %21 ], [ 1, %18 ], [ 1, %11 ], [ 1, %7 ]
ret i32 %27
}