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

/* Variables and functions */
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, char const *, ...);
int /*<<< orphan*/ BIO_puts(int /*<<< orphan*/ *, char *);
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 129
#define EVP_PKEY_EC 128
int /*<<< orphan*/ EVP_PKEY_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_get1_EC_KEY(int /*<<< orphan*/ *);
int EVP_PKEY_id(int /*<<< orphan*/ *);
char const *OBJ_nid2sn(int);
int /*<<< orphan*/ SSL_get_server_tmp_key(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/ **);
int ssl_print_tmp_key(BIO *out, SSL *s) {
  const char *cname;
  EVP_PKEY *pkey;
  EC_KEY *ec;
  int nid;
  if (!SSL_get_server_tmp_key(s, &pkey))
    return 0;
  BIO_puts(out, "Server Temp Key: ");
  switch (EVP_PKEY_id(pkey)) {
  case EVP_PKEY_DH:
    BIO_printf(out, "DH, %d bits\n", EVP_PKEY_bits(pkey));
    break;
  case EVP_PKEY_EC:
    ec = EVP_PKEY_get1_EC_KEY(pkey);
    nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
    EC_KEY_free(ec);
    if ((cname = EC_curve_nid2nist(nid)) == NULL)
      cname = OBJ_nid2sn(nid);
    BIO_printf(out, "ECDH, %s, %d bits\n", cname, EVP_PKEY_bits(pkey));
    break;
  default:
    BIO_printf(out, "%s, %d bits\n", OBJ_nid2sn(EVP_PKEY_id(pkey)),
               EVP_PKEY_bits(pkey));
  }
  EVP_PKEY_free(pkey);
  return 1;
}


x86 assembly (clang, -O0):
<ssl_print_tmp_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10e0 <SSL_get_server_tmp_key@plt>
cmp    $0x0,%eax
jne    11f2 <ssl_print_tmp_key+0x32>
movl   $0x0,-0x4(%rbp)
jmp    132c <ssl_print_tmp_key+0x16c>
mov    -0x10(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   10c0 <BIO_puts@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <EVP_PKEY_id@plt>
mov    %eax,%ecx
mov    %ecx,-0x38(%rbp)
sub    $0x80,%eax
je     125e <ssl_print_tmp_key+0x9e>
jmp    1220 <ssl_print_tmp_key+0x60>
mov    -0x38(%rbp),%eax
sub    $0x81,%eax
jne    12df <ssl_print_tmp_key+0x11f>
jmp    1233 <ssl_print_tmp_key+0x73>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <EVP_PKEY_bits@plt>
mov    -0x40(%rbp),%rdi
movslq %eax,%rdx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1040 <BIO_printf@plt>
jmp    131c <ssl_print_tmp_key+0x15c>
mov    -0x28(%rbp),%rdi
call   1060 <EVP_PKEY_get1_EC_KEY@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <EC_KEY_get0_group@plt>
mov    %eax,%edi
call   1080 <EC_GROUP_get_curve_name@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   10a0 <EC_KEY_free@plt>
mov    -0x34(%rbp),%edi
call   1090 <EC_curve_nid2nist@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12a9 <ssl_print_tmp_key+0xe9>
mov    -0x34(%rbp),%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <EVP_PKEY_bits@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1040 <BIO_printf@plt>
jmp    131c <ssl_print_tmp_key+0x15c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   10d0 <EVP_PKEY_id@plt>
mov    %eax,%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <EVP_PKEY_bits@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1040 <BIO_printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <EVP_PKEY_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_print_tmp_key>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   10e0 <SSL_get_server_tmp_key@plt>
test   %eax,%eax
je     1228 <ssl_print_tmp_key+0x68>
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <BIO_puts@plt>
mov    (%rsp),%rdi
call   10d0 <EVP_PKEY_id@plt>
cmp    $0x80,%eax
je     122f <ssl_print_tmp_key+0x6f>
cmp    $0x81,%eax
jne    1288 <ssl_print_tmp_key+0xc8>
mov    (%rsp),%rdi
call   10b0 <EVP_PKEY_bits@plt>
movslq %eax,%rdx
lea    0xdf9(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <BIO_printf@plt>
jmp    12ba <ssl_print_tmp_key+0xfa>
xor    %eax,%eax
jmp    12c8 <ssl_print_tmp_key+0x108>
mov    (%rsp),%rdi
call   1060 <EVP_PKEY_get1_EC_KEY@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <EC_KEY_get0_group@plt>
mov    %eax,%edi
call   1080 <EC_GROUP_get_curve_name@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   10a0 <EC_KEY_free@plt>
mov    %r15d,%edi
call   1090 <EC_curve_nid2nist@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1270 <ssl_print_tmp_key+0xb0>
mov    %r15d,%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,%r14
mov    (%rsp),%rdi
call   10b0 <EVP_PKEY_bits@plt>
lea    0xd9f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
jmp    12b1 <ssl_print_tmp_key+0xf1>
mov    (%rsp),%rdi
call   10d0 <EVP_PKEY_id@plt>
mov    %eax,%edi
call   1030 <OBJ_nid2sn@plt>
mov    %rax,%rbp
mov    (%rsp),%rdi
call   10b0 <EVP_PKEY_bits@plt>
lea    0xd7a(%rip),%rsi
mov    %rbx,%rdi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <BIO_printf@plt>
mov    (%rsp),%rdi
call   1050 <EVP_PKEY_free@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Server Temp Key: \00"
@.str.1 = [13 x i8] c"DH, %d bits\0A\00"
@.str.2 = [19 x i8] c"ECDH, %s, %d bits\0A\00"
@.str.3 = [13 x i8] c"%s, %d bits\0A\00"
define i32 @ssl_print_tmp_key(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
%11 = call i32 @SSL_get_server_tmp_key(i32* %10, i32** %7)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 0, i32* %3
br label %57
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = call i32 @BIO_puts(i32* %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%17 = load i32*, i32** %7
%18 = call i32 @EVP_PKEY_id(i32* %17)
switch i32 %18, label %46 [
i32 129, label %19
i32 128, label %26
]
19: ; preds = %14
%20 = load i32*, i32** %4
%21 = load i32*, i32** %7
%22 = call i32 @EVP_PKEY_bits(i32* %21)
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = call i32 (i32*, i8*, i8*, ...) @BIO_printf(i32* %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %54
26: ; preds = %14
%27 = load i32*, i32** %7
%28 = call i32* @EVP_PKEY_get1_EC_KEY(i32* %27)
store i32* %28, i32** %8
%29 = load i32*, i32** %8
%30 = call i32 @EC_KEY_get0_group(i32* %29)
%31 = call i32 @EC_GROUP_get_curve_name(i32 %30)
store i32 %31, i32* %9
%32 = load i32*, i32** %8
%33 = call i32 @EC_KEY_free(i32* %32)
%34 = load i32, i32* %9
%35 = call i8* @EC_curve_nid2nist(i32 %34)
store i8* %35, i8** %6
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %26
%38 = load i32, i32* %9
%39 = call i8* @OBJ_nid2sn(i32 %38)
store i8* %39, i8** %6
br label %40
40: ; preds = %37, %26
%41 = load i32*, i32** %4
%42 = load i8*, i8** %6
%43 = load i32*, i32** %7
%44 = call i32 @EVP_PKEY_bits(i32* %43)
%45 = call i32 (i32*, i8*, i8*, ...) @BIO_printf(i32* %41, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %42, i32 %44)
br label %54
46: ; preds = %14
%47 = load i32*, i32** %4
%48 = load i32*, i32** %7
%49 = call i32 @EVP_PKEY_id(i32* %48)
%50 = call i8* @OBJ_nid2sn(i32 %49)
%51 = load i32*, i32** %7
%52 = call i32 @EVP_PKEY_bits(i32* %51)
%53 = call i32 (i32*, i8*, i8*, ...) @BIO_printf(i32* %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %50, i32 %52)
br label %54
54: ; preds = %46, %40, %19
%55 = load i32*, i32** %7
%56 = call i32 @EVP_PKEY_free(i32* %55)
store i32 1, i32* %3
br label %57
57: ; preds = %54, %13
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [18 x i8] c"Server Temp Key: \00"
@.str.1 = [13 x i8] c"DH, %d bits\0A\00"
@.str.2 = [19 x i8] c"ECDH, %s, %d bits\0A\00"
@.str.3 = [13 x i8] c"%s, %d bits\0A\00"
define i32 @ssl_print_tmp_key(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i32 @SSL_get_server_tmp_key(i32* %1, i32** %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %42, label %7
7: ; preds = %2
%8 = call i32 @BIO_puts(i32* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%9 = load i32*, i32** %3
%10 = call i32 @EVP_PKEY_id(i32* %9)
switch i32 %10, label %32 [
i32 129, label %11
i32 128, label %17
]
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = call i32 @EVP_PKEY_bits(i32* %12)
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i8*
%16 = call i32 (i32*, i8*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %39
17: ; preds = %7
%18 = load i32*, i32** %3
%19 = call i32* @EVP_PKEY_get1_EC_KEY(i32* %18)
%20 = call i32 @EC_KEY_get0_group(i32* %19)
%21 = call i32 @EC_GROUP_get_curve_name(i32 %20)
%22 = call i32 @EC_KEY_free(i32* %19)
%23 = call i8* @EC_curve_nid2nist(i32 %21)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i8* @OBJ_nid2sn(i32 %21)
br label %27
27: ; preds = %25, %17
%28 = phi i8* [ %26, %25 ], [ %23, %17 ]
%29 = load i32*, i32** %3
%30 = call i32 @EVP_PKEY_bits(i32* %29)
%31 = call i32 (i32*, i8*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %28, i32 %30)
br label %39
32: ; preds = %7
%33 = load i32*, i32** %3
%34 = call i32 @EVP_PKEY_id(i32* %33)
%35 = call i8* @OBJ_nid2sn(i32 %34)
%36 = load i32*, i32** %3
%37 = call i32 @EVP_PKEY_bits(i32* %36)
%38 = call i32 (i32*, i8*, i8*, ...) @BIO_printf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %35, i32 %37)
br label %39
39: ; preds = %32, %27, %11
%40 = load i32*, i32** %3
%41 = call i32 @EVP_PKEY_free(i32* %40)
br label %42
42: ; preds = %2, %39
%43 = phi i32 [ 1, %39 ], [ 0, %2 ]
ret i32 %43
}