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

/* Variables and functions */
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ *EVP_PKEY_CTX_get_app_data(int /*<<< orphan*/ *);
int EVP_PKEY_CTX_get_keygen_info(int /*<<< orphan*/ *, int /*<<< orphan*/);
int genpkey_cb(EVP_PKEY_CTX *ctx) {
  char c = '*';
  BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
  int p;
  p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
  if (p == 0)
    c = '.';
  if (p == 1)
    c = '+';
  if (p == 2)
    c = '*';
  if (p == 3)
    c = '\n';
  BIO_write(b, &c, 1);
  (void)BIO_flush(b);
  return 1;
}


x86 assembly (clang, -O0):
<genpkey_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x2a,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <EVP_PKEY_CTX_get_app_data@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <EVP_PKEY_CTX_get_keygen_info@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1179 <genpkey_cb+0x39>
movb   $0x2e,-0x9(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1187 <genpkey_cb+0x47>
movb   $0x2b,-0x9(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    1195 <genpkey_cb+0x55>
movb   $0x2a,-0x9(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jne    11a3 <genpkey_cb+0x63>
movb   $0xa,-0x9(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1050 <BIO_write@plt>
mov    -0x18(%rbp),%rdi
call   1060 <BIO_flush@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genpkey_cb>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x2a,0x7(%rsp)
call   1040 <EVP_PKEY_CTX_get_app_data@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <EVP_PKEY_CTX_get_keygen_info@plt>
cmp    $0x3,%eax
ja     118f <genpkey_cb+0x4f>
mov    %eax,%eax
lea    0xe94(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x2e,0x7(%rsp)
jmp    118f <genpkey_cb+0x4f>
movb   $0x2b,0x7(%rsp)
jmp    118f <genpkey_cb+0x4f>
movb   $0x2a,0x7(%rsp)
jmp    118f <genpkey_cb+0x4f>
movb   $0xa,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1050 <BIO_write@plt>
mov    %r14,%rdi
call   1060 <BIO_flush@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @genpkey_cb(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %2
store i8 42, i8* %3
%6 = load i32*, i32** %2
%7 = call i32* @EVP_PKEY_CTX_get_app_data(i32* %6)
store i32* %7, i32** %4
%8 = load i32*, i32** %2
%9 = call i32 @EVP_PKEY_CTX_get_keygen_info(i32* %8, i32 0)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i8 46, i8* %3
br label %13
13: ; preds = %12, %1
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %13
store i8 43, i8* %3
br label %17
17: ; preds = %16, %13
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %21
20: ; preds = %17
store i8 42, i8* %3
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 3
br i1 %23, label %24, label %25
24: ; preds = %21
store i8 10, i8* %3
br label %25
25: ; preds = %24, %21
%26 = load i32*, i32** %4
%27 = call i32 @BIO_write(i32* %26, i8* %3, i32 1)
%28 = load i32*, i32** %4
%29 = call i32 @BIO_flush(i32* %28)
ret i32 1
}

LLVM IR (-O2):
define i32 @genpkey_cb(i32* %0) {
%2 = alloca i8
store i8 42, i8* %2
%3 = tail call i32* @EVP_PKEY_CTX_get_app_data(i32* %0)
%4 = tail call i32 @EVP_PKEY_CTX_get_keygen_info(i32* %0, i32 0)
switch i32 %4, label %9 [
i32 0, label %5
i32 1, label %6
i32 2, label %7
i32 3, label %8
]
5: ; preds = %1
store i8 46, i8* %2
br label %9
6: ; preds = %1
store i8 43, i8* %2
br label %9
7: ; preds = %1
store i8 42, i8* %2
br label %9
8: ; preds = %1
store i8 10, i8* %2
br label %9
9: ; preds = %7, %6, %5, %1, %8
%10 = call i32 @BIO_write(i32* %3, i8* %2, i32 1)
%11 = call i32 @BIO_flush(i32* %3)
ret i32 1
}