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

/* Variables and functions */
int get_ec(int /*<<< orphan*/ const *, size_t, int /*<<< orphan*/ *,
           int /*<<< orphan*/ const *);
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_ec(struct sshbuf *buf, EC_POINT *v, const EC_GROUP *g) {
  const u_char *d;
  size_t len;
  int r;
  if ((r = sshbuf_peek_string_direct(buf, &d, &len)) < 0)
    return r;
  if ((r = get_ec(d, len, v, g)) != 0)
    return r;
  if (sshbuf_get_string_direct(buf, NULL, NULL) != 0) {
    ;
    ;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_get_ec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <sshbuf_peek_string_direct@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    116c <sshbuf_get_ec+0x3c>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <sshbuf_get_ec+0x95>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <get_ec@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
je     1198 <sshbuf_get_ec+0x68>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <sshbuf_get_ec+0x95>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <sshbuf_get_string_direct@plt>
cmp    $0x0,%rax
je     11be <sshbuf_get_ec+0x8e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <sshbuf_get_ec+0x95>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_get_ec>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <sshbuf_peek_string_direct@plt>
test   %eax,%eax
js     117c <sshbuf_get_ec+0x4c>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1040 <get_ec@plt>
test   %eax,%eax
jne    117c <sshbuf_get_ec+0x4c>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <sshbuf_get_string_direct@plt>
neg    %rax
sbb    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get_ec(%struct.sshbuf* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.sshbuf*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
store %struct.sshbuf* %0, %struct.sshbuf** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%11 = load %struct.sshbuf*, %struct.sshbuf** %5
%12 = call i32 @sshbuf_peek_string_direct(%struct.sshbuf* %11, i32** %8, i64* %9)
store i32 %12, i32* %10
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32, i32* %10
store i32 %15, i32* %4
br label %31
16: ; preds = %3
%17 = load i32*, i32** %8
%18 = load i64, i64* %9
%19 = load i32*, i32** %6
%20 = load i32*, i32** %7
%21 = call i32 @get_ec(i32* %17, i64 %18, i32* %19, i32* %20)
store i32 %21, i32* %10
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = load i32, i32* %10
store i32 %24, i32* %4
br label %31
25: ; preds = %16
%26 = load %struct.sshbuf*, %struct.sshbuf** %5
%27 = call i64 @sshbuf_get_string_direct(%struct.sshbuf* %26, i32* null, i32* null)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %4
br label %31
30: ; preds = %25
store i32 0, i32* %4
br label %31
31: ; preds = %30, %29, %23, %14
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_get_ec(%struct.sshbuf* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = bitcast i32** %4 to i8*
%7 = bitcast i64* %5 to i8*
%8 = call i32 @sshbuf_peek_string_direct(%struct.sshbuf* %0, i32** %4, i64* %5)
%9 = icmp slt i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %3
%11 = load i32*, i32** %4
%12 = load i64, i64* %5
%13 = call i32 @get_ec(i32* %11, i64 %12, i32* %1, i32* %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = call i64 @sshbuf_get_string_direct(%struct.sshbuf* %0, i32* null, i32* null)
%17 = icmp ne i64 %16, 0
%18 = sext i1 %17 to i32
br label %19
19: ; preds = %15, %10, %3
%20 = phi i32 [ %8, %3 ], [ %13, %10 ], [ %18, %15 ]
ret i32 %20
}