#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*/ u_char;
struct sshbuf {
  int dummy;
};
typedef int /*<<< orphan*/ EC_POINT;
typedef int /*<<< orphan*/ EC_GROUP;
typedef int /*<<< orphan*/ BN_CTX;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
size_t EC_POINT_point2oct(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int /*<<< orphan*/,
                          int /*<<< orphan*/ *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ POINT_CONVERSION_UNCOMPRESSED;
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, size_t);
int sshbuf_put_string(struct sshbuf *, int /*<<< orphan*/ *, size_t);
int sshbuf_put_ec(struct sshbuf *buf, const EC_POINT *v, const EC_GROUP *g) {
  u_char d[((528 * 2 / 8) + 1)];
  BN_CTX *bn_ctx;
  size_t len;
  int ret;
  if ((bn_ctx = BN_CTX_new()) == NULL)
    return -2;
  if ((len = EC_POINT_point2oct(g, v, POINT_CONVERSION_UNCOMPRESSED, NULL, 0,
                                bn_ctx)) > ((528 * 2 / 8) + 1)) {
    BN_CTX_free(bn_ctx);
    return -10;
  }
  if (EC_POINT_point2oct(g, v, POINT_CONVERSION_UNCOMPRESSED, d, len, bn_ctx) !=
      len) {
    BN_CTX_free(bn_ctx);
    return -1;
  }
  BN_CTX_free(bn_ctx);
  ret = sshbuf_put_string(buf, d, len);
  bzero(d, len);
  return ret;
}


x86 assembly (clang, -O0):
<sshbuf_put_ec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1050 <BN_CTX_new@plt>
mov    %rax,-0x248(%rbp)
cmp    $0x0,%rax
jne    118b <sshbuf_put_ec+0x3b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1270 <sshbuf_put_ec+0x120>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    -0x248(%rbp),%r9
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1060 <EC_POINT_point2oct@plt>
mov    %rax,-0x250(%rbp)
cmp    $0x85,%rax
jbe    11db <sshbuf_put_ec+0x8b>
mov    -0x248(%rbp),%rdi
call   1040 <BN_CTX_free@plt>
movl   $0xfffffff6,-0x4(%rbp)
jmp    1270 <sshbuf_put_ec+0x120>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
lea    -0x240(%rbp),%rcx
mov    -0x250(%rbp),%r8
mov    -0x248(%rbp),%r9
call   1060 <EC_POINT_point2oct@plt>
cmp    -0x250(%rbp),%rax
je     122b <sshbuf_put_ec+0xdb>
mov    -0x248(%rbp),%rdi
call   1040 <BN_CTX_free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <sshbuf_put_ec+0x120>
mov    -0x248(%rbp),%rdi
call   1040 <BN_CTX_free@plt>
mov    -0x10(%rbp),%rdi
lea    -0x240(%rbp),%rsi
mov    -0x250(%rbp),%rdx
call   1030 <sshbuf_put_string@plt>
mov    %eax,-0x254(%rbp)
lea    -0x240(%rbp),%rdi
mov    -0x250(%rbp),%rsi
call   1070 <bzero@plt>
mov    -0x254(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_put_ec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <BN_CTX_new@plt>
test   %rax,%rax
je     119d <sshbuf_put_ec+0x5d>
mov    %rax,%rbx
mov    0x2e70(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %rax,%r9
call   1060 <EC_POINT_point2oct@plt>
cmp    $0x86,%rax
jb     11a4 <sshbuf_put_ec+0x64>
mov    %rbx,%rdi
call   1040 <BN_CTX_free@plt>
mov    $0xfffffff6,%eax
jmp    11e1 <sshbuf_put_ec+0xa1>
mov    $0xfffffffe,%eax
jmp    11e1 <sshbuf_put_ec+0xa1>
mov    %rax,%r13
mov    0x0(%rbp),%edx
mov    %rsp,%rcx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%r8
mov    %rbx,%r9
call   1060 <EC_POINT_point2oct@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <BN_CTX_free@plt>
mov    $0xffffffff,%eax
cmp    %r13,%r15
jne    11e1 <sshbuf_put_ec+0xa1>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    %r13,%rdx
call   1030 <sshbuf_put_string@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
define i32 @sshbuf_put_ec(%struct.sshbuf* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.sshbuf*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [133 x i32]
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
store %struct.sshbuf* %0, %struct.sshbuf** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%12 = call i32* (...) @BN_CTX_new()
store i32* %12, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -2, i32* %4
br label %49
15: ; preds = %3
%16 = load i32*, i32** %7
%17 = load i32*, i32** %6
%18 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%19 = load i32*, i32** %9
%20 = call i64 @EC_POINT_point2oct(i32* %16, i32* %17, i32 %18, i32* null, i64 0, i32* %19)
store i64 %20, i64* %10
%21 = icmp ugt i64 %20, 133
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32*, i32** %9
%24 = call i32 @BN_CTX_free(i32* %23)
store i32 -10, i32* %4
br label %49
25: ; preds = %15
%26 = load i32*, i32** %7
%27 = load i32*, i32** %6
%28 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%29 = getelementptr inbounds [133 x i32], [133 x i32]* %8, i64 0, i64 0
%30 = load i64, i64* %10
%31 = load i32*, i32** %9
%32 = call i64 @EC_POINT_point2oct(i32* %26, i32* %27, i32 %28, i32* %29, i64 %30, i32* %31)
%33 = load i64, i64* %10
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = load i32*, i32** %9
%37 = call i32 @BN_CTX_free(i32* %36)
store i32 -1, i32* %4
br label %49
38: ; preds = %25
%39 = load i32*, i32** %9
%40 = call i32 @BN_CTX_free(i32* %39)
%41 = load %struct.sshbuf*, %struct.sshbuf** %5
%42 = getelementptr inbounds [133 x i32], [133 x i32]* %8, i64 0, i64 0
%43 = load i64, i64* %10
%44 = call i32 @sshbuf_put_string(%struct.sshbuf* %41, i32* %42, i64 %43)
store i32 %44, i32* %11
%45 = getelementptr inbounds [133 x i32], [133 x i32]* %8, i64 0, i64 0
%46 = load i64, i64* %10
%47 = call i32 @bzero(i32* %45, i64 %46)
%48 = load i32, i32* %11
store i32 %48, i32* %4
br label %49
49: ; preds = %38, %35, %22, %14
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
define i32 @sshbuf_put_ec(%struct.sshbuf* %0, i32* %1, i32* %2) {
%4 = alloca [133 x i32]
%5 = bitcast [133 x i32]* %4 to i8*
%6 = tail call i32* (...) @BN_CTX_new()
%7 = icmp eq i32* %6, null
br i1 %7, label %22, label %8
8: ; preds = %3
%9 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%10 = tail call i64 @EC_POINT_point2oct(i32* %2, i32* %1, i32 %9, i32* null, i64 0, i32* %6)
%11 = icmp ugt i64 %10, 133
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @BN_CTX_free(i32* %6)
br label %22
14: ; preds = %8
%15 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%16 = getelementptr inbounds [133 x i32], [133 x i32]* %4, i64 0, i64 0
%17 = call i64 @EC_POINT_point2oct(i32* %2, i32* %1, i32 %15, i32* %16, i64 %10, i32* %6)
%18 = icmp eq i64 %17, %10
%19 = call i32 @BN_CTX_free(i32* %6)
br i1 %18, label %20, label %22
20: ; preds = %14
%21 = call i32 @sshbuf_put_string(%struct.sshbuf* %0, i32* %16, i64 %10)
br label %22
22: ; preds = %14, %3, %20, %12
%23 = phi i32 [ -10, %12 ], [ %21, %20 ], [ -2, %3 ], [ -1, %14 ]
ret i32 %23
}