#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;

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_check_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_get1_EC_KEY(int /*<<< orphan*/ *);
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int convert_eckey_to_x962_and_print(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int extract_and_print_eckey(EVP_PKEY *pubkey, int version) {
  assert(pubkey);
  EC_KEY *eckey = EVP_PKEY_get1_EC_KEY(pubkey);
  if (!eckey) {
    fprintf(stderr, "error: EVP_PKEY_get1_EC_KEY() failed.\n");
    return 2;
  }
  if (!EC_KEY_check_key(eckey)) {
    fprintf(stderr, "error: EC_KEY_check_key() failed.\n");
    EC_KEY_free(eckey);
    return 2;
  }
  int result = convert_eckey_to_x962_and_print(eckey, version);
  EC_KEY_free(eckey);
  return result;
}


x86 assembly (clang, -O0):
<extract_and_print_eckey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <EVP_PKEY_get1_EC_KEY@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b1 <extract_and_print_eckey+0x51>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    120b <extract_and_print_eckey+0xab>
mov    -0x20(%rbp),%rdi
call   1030 <EC_KEY_check_key@plt>
cmp    $0x0,%eax
jne    11ed <extract_and_print_eckey+0x8d>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <EC_KEY_free@plt>
movl   $0x2,-0x4(%rbp)
jmp    120b <extract_and_print_eckey+0xab>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <convert_eckey_to_x962_and_print@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <EC_KEY_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_and_print_eckey>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <EVP_PKEY_get1_EC_KEY@plt>
test   %rax,%rax
je     11a1 <extract_and_print_eckey+0x41>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <EC_KEY_check_key@plt>
test   %eax,%eax
je     11b8 <extract_and_print_eckey+0x58>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <convert_eckey_to_x962_and_print@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <EC_KEY_free@plt>
mov    %ebp,%eax
jmp    11da <extract_and_print_eckey+0x7a>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11d5 <extract_and_print_eckey+0x75>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <EC_KEY_free@plt>
mov    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"error: EVP_PKEY_get1_EC_KEY() failed.\0A\00"
@.str.1 = [35 x i8] c"error: EC_KEY_check_key() failed.\0A\00"
define i32 @extract_and_print_eckey(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32*, i32** %4
%9 = call i32 @assert(i32* %8)
%10 = load i32*, i32** %4
%11 = call i32* @EVP_PKEY_get1_EC_KEY(i32* %10)
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %33
17: ; preds = %2
%18 = load i32*, i32** %6
%19 = call i32 @EC_KEY_check_key(i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32*, i32** %6
%25 = call i32 @EC_KEY_free(i32* %24)
store i32 2, i32* %3
br label %33
26: ; preds = %17
%27 = load i32*, i32** %6
%28 = load i32, i32* %5
%29 = call i32 @convert_eckey_to_x962_and_print(i32* %27, i32 %28)
store i32 %29, i32* %7
%30 = load i32*, i32** %6
%31 = call i32 @EC_KEY_free(i32* %30)
%32 = load i32, i32* %7
store i32 %32, i32* %3
br label %33
33: ; preds = %26, %21, %14
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"error: EVP_PKEY_get1_EC_KEY() failed.\0A\00"
@.str.1 = [35 x i8] c"error: EC_KEY_check_key() failed.\0A\00"
define i32 @extract_and_print_eckey(i32* %0, i32 %1) {
%3 = tail call i32 @assert(i32* %0)
%4 = tail call i32* @EVP_PKEY_get1_EC_KEY(i32* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %19
9: ; preds = %2
%10 = tail call i32 @EC_KEY_check_key(i32* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @EC_KEY_free(i32* %4)
br label %19
16: ; preds = %9
%17 = tail call i32 @convert_eckey_to_x962_and_print(i32* %4, i32 %1)
%18 = tail call i32 @EC_KEY_free(i32* %4)
br label %19
19: ; preds = %16, %12, %6
%20 = phi i32 [ %17, %16 ], [ 2, %12 ], [ 2, %6 ]
ret i32 %20
}