#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*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ *BN_bin2bn(int /*<<< orphan*/ const *, size_t,
                              int /*<<< orphan*/ *);
int sshbuf_get_bignum2_bytes_direct(struct sshbuf *,
                                    int /*<<< orphan*/ const **, size_t *);
int sshbuf_get_bignum2(struct sshbuf *buf, BIGNUM *v) {
  const u_char *d;
  size_t len;
  int r;
  if ((r = sshbuf_get_bignum2_bytes_direct(buf, &d, &len)) != 0)
    return r;
  if (v != NULL && BN_bin2bn(d, len, v) == NULL)
    return -2;
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_get_bignum2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <sshbuf_get_bignum2_bytes_direct@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     1158 <sshbuf_get_bignum2+0x38>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1191 <sshbuf_get_bignum2+0x71>
cmpq   $0x0,-0x18(%rbp)
je     118a <sshbuf_get_bignum2+0x6a>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <BN_bin2bn@plt>
cmp    $0x0,%rax
jne    118a <sshbuf_get_bignum2+0x6a>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1191 <sshbuf_get_bignum2+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_get_bignum2>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <sshbuf_get_bignum2_bytes_direct@plt>
test   %eax,%eax
jne    115d <sshbuf_get_bignum2+0x3d>
test   %rbx,%rbx
je     1154 <sshbuf_get_bignum2+0x34>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    %rbx,%rdx
call   1030 <BN_bin2bn@plt>
test   %rax,%rax
je     1158 <sshbuf_get_bignum2+0x38>
xor    %eax,%eax
jmp    115d <sshbuf_get_bignum2+0x3d>
mov    $0xfffffffe,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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