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

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_get0_group(int /*<<< orphan*/ *);
int EC_KEY_set_public_key(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_POINT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_POINT_new(int /*<<< orphan*/);
int get_ec(int /*<<< orphan*/ const *, size_t, int /*<<< orphan*/ *,
           int /*<<< orphan*/);
scalar_t__ sshbuf_get_string_direct(struct sshbuf *, int /*<<< orphan*/ *,
                                    int /*<<< orphan*/ *);
int sshbuf_peek_string_direct(struct sshbuf *, int /*<<< orphan*/ const **,
                              size_t *);
int sshbuf_get_eckey(struct sshbuf *buf, EC_KEY *v) {
  EC_POINT *pt = EC_POINT_new(EC_KEY_get0_group(v));
  int r;
  const u_char *d;
  size_t len;
  if (pt == NULL) {
    ;
    return -2;
  }
  if ((r = sshbuf_peek_string_direct(buf, &d, &len)) < 0) {
    EC_POINT_free(pt);
    return r;
  }
  if ((r = get_ec(d, len, pt, EC_KEY_get0_group(v))) != 0) {
    EC_POINT_free(pt);
    return r;
  }
  if (EC_KEY_set_public_key(v, pt) != 1) {
    EC_POINT_free(pt);
    return -2;
  }
  EC_POINT_free(pt);
  if (sshbuf_get_string_direct(buf, NULL, NULL) != 0) {
    ;
    ;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_get_eckey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <EC_KEY_get0_group@plt>
mov    %eax,%edi
call   1090 <EC_POINT_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <sshbuf_get_eckey+0x3b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1291 <sshbuf_get_eckey+0x121>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <sshbuf_peek_string_direct@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11dc <sshbuf_get_eckey+0x6c>
mov    -0x20(%rbp),%rdi
call   1080 <EC_POINT_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1291 <sshbuf_get_eckey+0x121>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <EC_KEY_get0_group@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
call   1060 <get_ec@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     1230 <sshbuf_get_eckey+0xc0>
mov    -0x20(%rbp),%rdi
call   1080 <EC_POINT_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1291 <sshbuf_get_eckey+0x121>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <EC_KEY_set_public_key@plt>
cmp    $0x1,%eax
je     125b <sshbuf_get_eckey+0xeb>
mov    -0x20(%rbp),%rdi
call   1080 <EC_POINT_free@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1291 <sshbuf_get_eckey+0x121>
mov    -0x20(%rbp),%rdi
call   1080 <EC_POINT_free@plt>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1070 <sshbuf_get_string_direct@plt>
cmp    $0x0,%rax
je     128a <sshbuf_get_eckey+0x11a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1291 <sshbuf_get_eckey+0x121>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_get_eckey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <EC_KEY_get0_group@plt>
mov    %eax,%edi
call   1090 <EC_POINT_new@plt>
mov    $0xfffffffe,%r15d
test   %rax,%rax
je     11ea <sshbuf_get_eckey+0x7a>
mov    %rax,%rbx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1040 <sshbuf_peek_string_direct@plt>
test   %eax,%eax
js     11dd <sshbuf_get_eckey+0x6d>
mov    0x10(%rsp),%rbp
mov    0x8(%rsp),%r13
mov    %r12,%rdi
call   1050 <EC_KEY_get0_group@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <get_ec@plt>
test   %eax,%eax
je     11fc <sshbuf_get_eckey+0x8c>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <EC_POINT_free@plt>
mov    %ebp,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <EC_KEY_set_public_key@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <EC_POINT_free@plt>
cmp    $0x1,%ebp
jne    11ea <sshbuf_get_eckey+0x7a>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <sshbuf_get_string_direct@plt>
neg    %rax
sbb    %r15d,%r15d
jmp    11ea <sshbuf_get_eckey+0x7a>

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get_eckey(%struct.sshbuf* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.sshbuf*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
store %struct.sshbuf* %0, %struct.sshbuf** %4
store i32* %1, i32** %5
%10 = load i32*, i32** %5
%11 = call i32 @EC_KEY_get0_group(i32* %10)
%12 = call i32* @EC_POINT_new(i32 %11)
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -2, i32* %3
br label %52
16: ; preds = %2
%17 = load %struct.sshbuf*, %struct.sshbuf** %4
%18 = call i32 @sshbuf_peek_string_direct(%struct.sshbuf* %17, i32** %8, i64* %9)
store i32 %18, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = call i32 @EC_POINT_free(i32* %21)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %52
24: ; preds = %16
%25 = load i32*, i32** %8
%26 = load i64, i64* %9
%27 = load i32*, i32** %6
%28 = load i32*, i32** %5
%29 = call i32 @EC_KEY_get0_group(i32* %28)
%30 = call i32 @get_ec(i32* %25, i64 %26, i32* %27, i32 %29)
store i32 %30, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %24
%33 = load i32*, i32** %6
%34 = call i32 @EC_POINT_free(i32* %33)
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %52
36: ; preds = %24
%37 = load i32*, i32** %5
%38 = load i32*, i32** %6
%39 = call i32 @EC_KEY_set_public_key(i32* %37, i32* %38)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32*, i32** %6
%43 = call i32 @EC_POINT_free(i32* %42)
store i32 -2, i32* %3
br label %52
44: ; preds = %36
%45 = load i32*, i32** %6
%46 = call i32 @EC_POINT_free(i32* %45)
%47 = load %struct.sshbuf*, %struct.sshbuf** %4
%48 = call i64 @sshbuf_get_string_direct(%struct.sshbuf* %47, i32* null, i32* null)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %44
store i32 -1, i32* %3
br label %52
51: ; preds = %44
store i32 0, i32* %3
br label %52
52: ; preds = %51, %50, %41, %32, %20, %15
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get_eckey(%struct.sshbuf* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = tail call i32 @EC_KEY_get0_group(i32* %1)
%6 = tail call i32* @EC_POINT_new(i32 %5)
%7 = bitcast i32** %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = icmp eq i32* %6, null
br i1 %9, label %31, label %10
10: ; preds = %2
%11 = call i32 @sshbuf_peek_string_direct(%struct.sshbuf* %0, i32** %3, i64* %4)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @EC_POINT_free(i32* %6)
br label %31
15: ; preds = %10
%16 = load i32*, i32** %3
%17 = load i64, i64* %4
%18 = call i32 @EC_KEY_get0_group(i32* %1)
%19 = call i32 @get_ec(i32* %16, i64 %17, i32* %6, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = call i32 @EC_POINT_free(i32* %6)
br label %31
23: ; preds = %15
%24 = call i32 @EC_KEY_set_public_key(i32* %1, i32* %6)
%25 = icmp eq i32 %24, 1
%26 = call i32 @EC_POINT_free(i32* %6)
br i1 %25, label %27, label %31
27: ; preds = %23
%28 = call i64 @sshbuf_get_string_direct(%struct.sshbuf* %0, i32* null, i32* null)
%29 = icmp ne i64 %28, 0
%30 = sext i1 %29 to i32
br label %31
31: ; preds = %23, %27, %2, %21, %13
%32 = phi i32 [ %11, %13 ], [ %19, %21 ], [ -2, %2 ], [ %30, %27 ], [ -2, %23 ]
ret i32 %32
}