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

/* Variables and functions */
int /*<<< orphan*/ *EC_KEY_get0_group(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *EC_KEY_get0_public_key(int /*<<< orphan*/ const *);
size_t EC_POINT_point2oct(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int /*<<< orphan*/,
                          unsigned char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ POINT_CONVERSION_UNCOMPRESSED;
int /*<<< orphan*/ assert(int /*<<< orphan*/ const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int print_octets(unsigned char *, size_t, int);
int /*<<< orphan*/ stderr;
int verify_x962_octets_are_on_p256(unsigned char *, size_t);
int convert_eckey_to_x962_and_print(const EC_KEY *eckey, int version) {
  assert(eckey);
  const EC_GROUP *group = EC_KEY_get0_group(eckey);
  if (!group) {
    fprintf(stderr, "error: EC_KEY_get0_group() failed.\n");
    return 3;
  }
  const EC_POINT *pubkey_point = EC_KEY_get0_public_key(eckey);
  if (!pubkey_point) {
    fprintf(stderr, "error: EC_KEY_get0_public_key() failed.\n");
    return 3;
  }
  size_t octets_len = 256;
  unsigned char octets[256];
  octets_len =
      EC_POINT_point2oct(group, pubkey_point, POINT_CONVERSION_UNCOMPRESSED,
                         octets, octets_len, NULL);
  if (0 == octets_len) {
    fprintf(stderr, "error: EC_POINT_point2oct() failed.\n");
    return 3;
  }
  if (octets_len != 65) {
    fprintf(stderr, "error: EC_POINT_point2oct() produced %lu bytes.\n",
            (unsigned long)octets_len);
    return 3;
  }
  if (octets[0] != 0x04) {
    fprintf(stderr, "error: EC_POINT_point2oct() produced compressed data.\n");
    return 3;
  }
  int result = verify_x962_octets_are_on_p256(octets, octets_len);
  if (result != 0) {
    return result;
  }
  return print_octets(octets, octets_len, version);
}


x86 assembly (clang, -O0):
<convert_eckey_to_x962_and_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1080 <EC_KEY_get0_group@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c6 <convert_eckey_to_x962_and_print+0x56>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    130e <convert_eckey_to_x962_and_print+0x19e>
mov    -0x10(%rbp),%rdi
call   1030 <EC_KEY_get0_public_key@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1201 <convert_eckey_to_x962_and_print+0x91>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    130e <convert_eckey_to_x962_and_print+0x19e>
movq   $0x100,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
lea    -0x130(%rbp),%rcx
mov    -0x30(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1090 <EC_POINT_point2oct@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1262 <convert_eckey_to_x962_and_print+0xf2>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    130e <convert_eckey_to_x962_and_print+0x19e>
cmpq   $0x41,-0x30(%rbp)
je     1294 <convert_eckey_to_x962_and_print+0x124>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    130e <convert_eckey_to_x962_and_print+0x19e>
movzbl -0x130(%rbp),%eax
cmp    $0x4,%eax
je     12c7 <convert_eckey_to_x962_and_print+0x157>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    130e <convert_eckey_to_x962_and_print+0x19e>
lea    -0x130(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <verify_x962_octets_are_on_p256@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
je     12f8 <convert_eckey_to_x962_and_print+0x188>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    130e <convert_eckey_to_x962_and_print+0x19e>
lea    -0x130(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <print_octets@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_eckey_to_x962_and_print>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
call   1050 <assert@plt>
mov    %rbp,%rdi
call   1080 <EC_KEY_get0_group@plt>
test   %rax,%rax
je     11e0 <convert_eckey_to_x962_and_print+0x70>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <EC_KEY_get0_public_key@plt>
test   %rax,%rax
je     11f2 <convert_eckey_to_x962_and_print+0x82>
mov    0x2e36(%rip),%rcx
mov    (%rcx),%edx
mov    %rsp,%rcx
mov    $0x100,%r8d
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %r9d,%r9d
call   1090 <EC_POINT_point2oct@plt>
cmp    $0x41,%rax
je     1204 <convert_eckey_to_x962_and_print+0x94>
test   %rax,%rax
jne    122d <convert_eckey_to_x962_and_print+0xbd>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
jmp    1259 <convert_eckey_to_x962_and_print+0xe9>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
jmp    1259 <convert_eckey_to_x962_and_print+0xe9>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
jmp    1259 <convert_eckey_to_x962_and_print+0xe9>
cmpb   $0x4,(%rsp)
jne    1249 <convert_eckey_to_x962_and_print+0xd9>
mov    %rsp,%rdi
mov    $0x41,%esi
call   1040 <verify_x962_octets_are_on_p256@plt>
test   %eax,%eax
jne    1265 <convert_eckey_to_x962_and_print+0xf5>
mov    %rsp,%rdi
mov    $0x41,%esi
mov    %r14d,%edx
call   1070 <print_octets@plt>
jmp    1265 <convert_eckey_to_x962_and_print+0xf5>
mov    0x2da4(%rip),%rcx
mov    (%rcx),%edi
lea    0xe35(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1260 <convert_eckey_to_x962_and_print+0xf0>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"error: EC_KEY_get0_group() failed.\0A\00"
@.str.1 = [41 x i8] c"error: EC_KEY_get0_public_key() failed.\0A\00"
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
@.str.2 = [37 x i8] c"error: EC_POINT_point2oct() failed.\0A\00"
@.str.3 = [49 x i8] c"error: EC_POINT_point2oct() produced %lu bytes.\0A\00"
@.str.4 = [55 x i8] c"error: EC_POINT_point2oct() produced compressed data.\0A\00"
define i32 @convert_eckey_to_x962_and_print(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca [256 x i8]
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%11 = load i32*, i32** %4
%12 = call i32 @assert(i32* %11)
%13 = load i32*, i32** %4
%14 = call i32* @EC_KEY_get0_group(i32* %13)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 3, i32* %3
br label %68
20: ; preds = %2
%21 = load i32*, i32** %4
%22 = call i32* @EC_KEY_get0_public_key(i32* %21)
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
store i32 3, i32* %3
br label %68
28: ; preds = %20
store i64 256, i64* %8
%29 = load i32*, i32** %6
%30 = load i32*, i32** %7
%31 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%33 = load i64, i64* %8
%34 = call i64 @EC_POINT_point2oct(i32* %29, i32* %30, i32 %31, i8* %32, i64 %33, i32* null)
store i64 %34, i64* %8
%35 = load i64, i64* %8
%36 = icmp eq i64 0, %35
br i1 %36, label %37, label %40
37: ; preds = %28
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %3
br label %68
40: ; preds = %28
%41 = load i64, i64* %8
%42 = icmp ne i64 %41, 65
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i64, i64* %8
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %45)
store i32 3, i32* %3
br label %68
47: ; preds = %40
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp ne i32 %50, 4
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %3
br label %68
55: ; preds = %47
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%57 = load i64, i64* %8
%58 = call i32 @verify_x962_octets_are_on_p256(i8* %56, i64 %57)
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = load i32, i32* %10
store i32 %62, i32* %3
br label %68
63: ; preds = %55
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%65 = load i64, i64* %8
%66 = load i32, i32* %5
%67 = call i32 @print_octets(i8* %64, i64 %65, i32 %66)
store i32 %67, i32* %3
br label %68
68: ; preds = %63, %61, %52, %43, %37, %25, %17
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"error: EC_KEY_get0_group() failed.\0A\00"
@.str.1 = [41 x i8] c"error: EC_KEY_get0_public_key() failed.\0A\00"
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
@.str.2 = [37 x i8] c"error: EC_POINT_point2oct() failed.\0A\00"
@.str.3 = [49 x i8] c"error: EC_POINT_point2oct() produced %lu bytes.\0A\00"
@.str.4 = [55 x i8] c"error: EC_POINT_point2oct() produced compressed data.\0A\00"
define i32 @convert_eckey_to_x962_and_print(i32* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = tail call i32 @assert(i32* %0)
%5 = tail call i32* @EC_KEY_get0_group(i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %39
10: ; preds = %2
%11 = tail call i32* @EC_KEY_get0_public_key(i32* %0)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %39
16: ; preds = %10
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%19 = call i64 @EC_POINT_point2oct(i32* %5, i32* %11, i32 %18, i8* %17, i64 256, i32* null)
switch i64 %19, label %23 [
i64 0, label %20
i64 65, label %26
]
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %37
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %19)
br label %37
26: ; preds = %16
%27 = load i8, i8* %17
%28 = icmp eq i8 %27, 4
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %37
32: ; preds = %26
%33 = call i32 @verify_x962_octets_are_on_p256(i8* %17, i64 65)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @print_octets(i8* %17, i64 65, i32 %1)
br label %37
37: ; preds = %35, %32, %29, %23, %20
%38 = phi i32 [ 3, %20 ], [ 3, %23 ], [ 3, %29 ], [ %36, %35 ], [ %33, %32 ]
br label %39
39: ; preds = %13, %37, %7
%40 = phi i32 [ 3, %7 ], [ %38, %37 ], [ 3, %13 ]
ret i32 %40
}