#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 */
#define EVP_PKEY_OP_DECRYPT 132
#define EVP_PKEY_OP_DERIVE 131
#define EVP_PKEY_OP_ENCRYPT 130
#define EVP_PKEY_OP_SIGN 129
#define EVP_PKEY_OP_VERIFYRECOVER 128
int EVP_PKEY_decrypt(int /*<<< orphan*/ *, unsigned char *, size_t *,
                     unsigned char *, size_t);
int EVP_PKEY_derive(int /*<<< orphan*/ *, unsigned char *, size_t *);
int EVP_PKEY_encrypt(int /*<<< orphan*/ *, unsigned char *, size_t *,
                     unsigned char *, size_t);
int EVP_PKEY_sign(int /*<<< orphan*/ *, unsigned char *, size_t *,
                  unsigned char *, size_t);
int EVP_PKEY_verify_recover(int /*<<< orphan*/ *, unsigned char *, size_t *,
                            unsigned char *, size_t);
int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op, unsigned char *out,
             size_t *poutlen, unsigned char *in, size_t inlen) {
  int rv = 0;
  switch (pkey_op) {
  case EVP_PKEY_OP_VERIFYRECOVER:
    rv = EVP_PKEY_verify_recover(ctx, out, poutlen, in, inlen);
    break;
  case EVP_PKEY_OP_SIGN:
    rv = EVP_PKEY_sign(ctx, out, poutlen, in, inlen);
    break;
  case EVP_PKEY_OP_ENCRYPT:
    rv = EVP_PKEY_encrypt(ctx, out, poutlen, in, inlen);
    break;
  case EVP_PKEY_OP_DECRYPT:
    rv = EVP_PKEY_decrypt(ctx, out, poutlen, in, inlen);
    break;
  case EVP_PKEY_OP_DERIVE:
    rv = EVP_PKEY_derive(ctx, out, poutlen);
    break;
  }
  return rv;
}


x86 assembly (clang, -O0):
<do_keyop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x4,%eax
ja     1237 <do_keyop+0xe7>
mov    -0x40(%rbp),%rax
lea    0xe6a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <EVP_PKEY_verify_recover@plt>
mov    %eax,-0x34(%rbp)
jmp    1237 <do_keyop+0xe7>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1060 <EVP_PKEY_sign@plt>
mov    %eax,-0x34(%rbp)
jmp    1237 <do_keyop+0xe7>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1070 <EVP_PKEY_encrypt@plt>
mov    %eax,-0x34(%rbp)
jmp    1237 <do_keyop+0xe7>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1030 <EVP_PKEY_decrypt@plt>
mov    %eax,-0x34(%rbp)
jmp    1237 <do_keyop+0xe7>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <EVP_PKEY_derive@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_keyop>:
add    $0xffffff80,%esi
cmp    $0x4,%esi
ja     1179 <do_keyop+0x29>
lea    0xea1(%rip),%rax
movslq (%rax,%rsi,4),%rsi
add    %rax,%rsi
jmp    *%rsi
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
mov    %r9,%r8
jmp    1040 <EVP_PKEY_verify_recover@plt>
xor    %eax,%eax
ret
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
mov    %r9,%r8
jmp    1060 <EVP_PKEY_sign@plt>
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
mov    %r9,%r8
jmp    1070 <EVP_PKEY_encrypt@plt>
mov    %rdx,%rsi
mov    %rcx,%rdx
jmp    1050 <EVP_PKEY_derive@plt>
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8,%rcx
mov    %r9,%r8
jmp    1030 <EVP_PKEY_decrypt@plt>

LLVM IR (-O0):
define i32 @do_keyop(i32* %0, i32 %1, i8* %2, i64* %3, i8* %4, i64 %5) {
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i32* %0, i32** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i64* %3, i64** %10
store i8* %4, i8** %11
store i64 %5, i64* %12
store i32 0, i32* %13
%14 = load i32, i32* %8
switch i32 %14, label %48 [
i32 128, label %15
i32 129, label %22
i32 130, label %29
i32 132, label %36
i32 131, label %43
]
15: ; preds = %6
%16 = load i32*, i32** %7
%17 = load i8*, i8** %9
%18 = load i64*, i64** %10
%19 = load i8*, i8** %11
%20 = load i64, i64* %12
%21 = call i32 @EVP_PKEY_verify_recover(i32* %16, i8* %17, i64* %18, i8* %19, i64 %20)
store i32 %21, i32* %13
br label %48
22: ; preds = %6
%23 = load i32*, i32** %7
%24 = load i8*, i8** %9
%25 = load i64*, i64** %10
%26 = load i8*, i8** %11
%27 = load i64, i64* %12
%28 = call i32 @EVP_PKEY_sign(i32* %23, i8* %24, i64* %25, i8* %26, i64 %27)
store i32 %28, i32* %13
br label %48
29: ; preds = %6
%30 = load i32*, i32** %7
%31 = load i8*, i8** %9
%32 = load i64*, i64** %10
%33 = load i8*, i8** %11
%34 = load i64, i64* %12
%35 = call i32 @EVP_PKEY_encrypt(i32* %30, i8* %31, i64* %32, i8* %33, i64 %34)
store i32 %35, i32* %13
br label %48
36: ; preds = %6
%37 = load i32*, i32** %7
%38 = load i8*, i8** %9
%39 = load i64*, i64** %10
%40 = load i8*, i8** %11
%41 = load i64, i64* %12
%42 = call i32 @EVP_PKEY_decrypt(i32* %37, i8* %38, i64* %39, i8* %40, i64 %41)
store i32 %42, i32* %13
br label %48
43: ; preds = %6
%44 = load i32*, i32** %7
%45 = load i8*, i8** %9
%46 = load i64*, i64** %10
%47 = call i32 @EVP_PKEY_derive(i32* %44, i8* %45, i64* %46)
store i32 %47, i32* %13
br label %48
48: ; preds = %6, %43, %36, %29, %22, %15
%49 = load i32, i32* %13
ret i32 %49
}

LLVM IR (-O2):
define i32 @do_keyop(i32* %0, i32 %1, i8* %2, i64* %3, i8* %4, i64 %5) {
switch i32 %1, label %17 [
i32 128, label %7
i32 129, label %9
i32 130, label %11
i32 132, label %13
i32 131, label %15
]
7: ; preds = %6
%8 = tail call i32 @EVP_PKEY_verify_recover(i32* %0, i8* %2, i64* %3, i8* %4, i64 %5)
br label %17
9: ; preds = %6
%10 = tail call i32 @EVP_PKEY_sign(i32* %0, i8* %2, i64* %3, i8* %4, i64 %5)
br label %17
11: ; preds = %6
%12 = tail call i32 @EVP_PKEY_encrypt(i32* %0, i8* %2, i64* %3, i8* %4, i64 %5)
br label %17
13: ; preds = %6
%14 = tail call i32 @EVP_PKEY_decrypt(i32* %0, i8* %2, i64* %3, i8* %4, i64 %5)
br label %17
15: ; preds = %6
%16 = tail call i32 @EVP_PKEY_derive(i32* %0, i8* %2, i64* %3)
br label %17
17: ; preds = %6, %15, %13, %11, %9, %7
%18 = phi i32 [ 0, %6 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ]
ret i32 %18
}