#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;
typedef int /*<<< orphan*/ EC_KEY;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                              char const *);
int EC_GROUP_get_curve_name(int /*<<< orphan*/);
int /*<<< orphan*/ EC_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_KEY_get0_group(int /*<<< orphan*/ *);
char *EC_curve_nid2nist(int);
#define EVP_PKEY_DH 130
#define EVP_PKEY_DSA 129
int EVP_PKEY_EC;
#define EVP_PKEY_RSA 128
int /*<<< orphan*/ EVP_PKEY_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_get1_EC_KEY(int /*<<< orphan*/ *);
int EVP_PKEY_id(int /*<<< orphan*/ *);
char *OBJ_nid2sn(int);
void print_key_details(BIO *out, EVP_PKEY *key) {
  int keyid = EVP_PKEY_id(key);
  if (keyid == EVP_PKEY_EC) {
    EC_KEY *ec = EVP_PKEY_get1_EC_KEY(key);
    int nid;
    const char *cname;
    nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
    EC_KEY_free(ec);
    cname = EC_curve_nid2nist(nid);
    if (!cname)
      cname = OBJ_nid2sn(nid);
    BIO_printf(out, "%d bits EC (%s)", EVP_PKEY_bits(key), cname);
  } else {
    const char *algname;
    switch (keyid) {
    case EVP_PKEY_RSA:
      algname = "RSA";
      break;
    case EVP_PKEY_DSA:
      algname = "DSA";
      break;
    case EVP_PKEY_DH:
      algname = "DH";
      break;
    default:
      algname = OBJ_nid2sn(keyid);
      break;
    }
    BIO_printf(out, "%d bits %s", EVP_PKEY_bits(key), algname);
  }
}


x86 assembly (clang, -O0):
<print_key_details>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <EVP_PKEY_id@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%eax
jne    1236 <print_key_details+0xa6>
mov    -0x10(%rbp),%rdi
call   1050 <EVP_PKEY_get1_EC_KEY@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <EC_KEY_get0_group@plt>
mov    %eax,%edi
call   1070 <EC_GROUP_get_curve_name@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <EC_KEY_free@plt>
mov    -0x24(%rbp),%edi
call   1080 <EC_curve_nid2nist@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120a <print_key_details+0x7a>
mov    -0x24(%rbp),%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <EVP_PKEY_bits@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
mov    -0x30(%rbp),%rcx
lea    0xdd4(%rip),%rsi
call   1040 <BIO_printf@plt>
jmp    12d5 <print_key_details+0x145>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x80,%eax
je     1272 <print_key_details+0xe2>
jmp    124c <print_key_details+0xbc>
mov    -0x44(%rbp),%eax
sub    $0x81,%eax
je     1282 <print_key_details+0xf2>
jmp    125f <print_key_details+0xcf>
mov    -0x44(%rbp),%eax
sub    $0x82,%eax
je     1292 <print_key_details+0x102>
jmp    12a2 <print_key_details+0x112>
lea    0xd97(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12ae <print_key_details+0x11e>
lea    0xd8b(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12ae <print_key_details+0x11e>
lea    0xd7f(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    12ae <print_key_details+0x11e>
mov    -0x14(%rbp),%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <EVP_PKEY_bits@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
mov    -0x38(%rbp),%rcx
lea    0xd4b(%rip),%rsi
call   1040 <BIO_printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_key_details>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   10b0 <EVP_PKEY_id@plt>
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%eax
jne    11fe <print_key_details+0x6e>
mov    %r15,%rdi
call   1050 <EVP_PKEY_get1_EC_KEY@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <EC_KEY_get0_group@plt>
mov    %eax,%edi
call   1070 <EC_GROUP_get_curve_name@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <EC_KEY_free@plt>
mov    %ebp,%edi
call   1080 <EC_curve_nid2nist@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ed <print_key_details+0x5d>
mov    %ebp,%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   10a0 <EVP_PKEY_bits@plt>
lea    0xe04(%rip),%rsi
jmp    1232 <print_key_details+0xa2>
lea    -0x80(%rax),%ecx
cmp    $0x3,%ecx
jae    1219 <print_key_details+0x89>
movslq %ecx,%rax
lea    0xe18(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    1223 <print_key_details+0x93>
mov    %eax,%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   10a0 <EVP_PKEY_bits@plt>
lea    0xde9(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <BIO_printf@plt>

LLVM IR (-O0):
@EVP_PKEY_EC = global i32 0
@.str = [16 x i8] c"%d bits EC (%s)\00"
@.str.1 = [4 x i8] c"RSA\00"
@.str.2 = [4 x i8] c"DSA\00"
@.str.3 = [3 x i8] c"DH\00"
@.str.4 = [11 x i8] c"%d bits %s\00"
define void @print_key_details(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32* %0, i32** %3
store i32* %1, i32** %4
%10 = load i32*, i32** %4
%11 = call i32 @EVP_PKEY_id(i32* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = load i32, i32* @EVP_PKEY_EC
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %36
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = call i32* @EVP_PKEY_get1_EC_KEY(i32* %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = call i32 @EC_KEY_get0_group(i32* %18)
%20 = call i32 @EC_GROUP_get_curve_name(i32 %19)
store i32 %20, i32* %7
%21 = load i32*, i32** %6
%22 = call i32 @EC_KEY_free(i32* %21)
%23 = load i32, i32* %7
%24 = call i8* @EC_curve_nid2nist(i32 %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %15
%28 = load i32, i32* %7
%29 = call i8* @OBJ_nid2sn(i32 %28)
store i8* %29, i8** %8
br label %30
30: ; preds = %27, %15
%31 = load i32*, i32** %3
%32 = load i32*, i32** %4
%33 = call i32 @EVP_PKEY_bits(i32* %32)
%34 = load i8*, i8** %8
%35 = call i32 @BIO_printf(i32* %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %33, i8* %34)
br label %50
36: ; preds = %2
%37 = load i32, i32* %5
switch i32 %37, label %41 [
i32 128, label %38
i32 129, label %39
i32 130, label %40
]
38: ; preds = %36
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %44
39: ; preds = %36
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %44
40: ; preds = %36
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %44
41: ; preds = %36
%42 = load i32, i32* %5
%43 = call i8* @OBJ_nid2sn(i32 %42)
store i8* %43, i8** %9
br label %44
44: ; preds = %41, %40, %39, %38
%45 = load i32*, i32** %3
%46 = load i32*, i32** %4
%47 = call i32 @EVP_PKEY_bits(i32* %46)
%48 = load i8*, i8** %9
%49 = call i32 @BIO_printf(i32* %45, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %47, i8* %48)
br label %50
50: ; preds = %44, %30
ret void
}

LLVM IR (-O2):
@EVP_PKEY_EC = global i32 0
@.str = [16 x i8] c"%d bits EC (%s)\00"
@.str.1 = [4 x i8] c"RSA\00"
@.str.2 = [4 x i8] c"DSA\00"
@.str.3 = [3 x i8] c"DH\00"
@.str.4 = [11 x i8] c"%d bits %s\00"
@reltable.print_key_details = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.print_key_details to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.print_key_details to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.print_key_details to i64)) to i32)]
define void @print_key_details(i32* %0, i32* %1) {
%3 = tail call i32 @EVP_PKEY_id(i32* %1)
%4 = load i32, i32* @EVP_PKEY_EC
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = tail call i32* @EVP_PKEY_get1_EC_KEY(i32* %1)
%8 = tail call i32 @EC_KEY_get0_group(i32* %7)
%9 = tail call i32 @EC_GROUP_get_curve_name(i32 %8)
%10 = tail call i32 @EC_KEY_free(i32* %7)
%11 = tail call i8* @EC_curve_nid2nist(i32 %9)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i8* @OBJ_nid2sn(i32 %9)
br label %15
15: ; preds = %13, %6
%16 = phi i8* [ %11, %6 ], [ %14, %13 ]
%17 = tail call i32 @EVP_PKEY_bits(i32* %1)
%18 = tail call i32 @BIO_printf(i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %16)
br label %32
19: ; preds = %2
%20 = add i32 %3, -128
%21 = icmp ult i32 %20, 3
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i8* @OBJ_nid2sn(i32 %3)
br label %28
24: ; preds = %19
%25 = sext i32 %20 to i64
%26 = shl i64 %25, 2
%27 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.print_key_details to i8*), i64 %26)
br label %28
28: ; preds = %24, %22
%29 = phi i8* [ %23, %22 ], [ %27, %24 ]
%30 = tail call i32 @EVP_PKEY_bits(i32* %1)
%31 = tail call i32 @BIO_printf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %30, i8* %29)
br label %32
32: ; preds = %28, %15
ret void
}