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

/* Variables and functions */
int /*<<< orphan*/ BN_bin2bn(unsigned char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_clear_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int vg_b58_decode_check(char const *, unsigned char *, int);
int vg_set_privkey(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int vg_decode_privkey_compressed(const char *b58encoded, EC_KEY *pkey,
                                 int *addrtype) {
  BIGNUM *bnpriv;
  unsigned char ecpriv[48];
  int res;
  res = vg_b58_decode_check(b58encoded, ecpriv, sizeof(ecpriv));
  if (res != 34)
    return 0;
  bnpriv = BN_new();
  BN_bin2bn(ecpriv + 1, res - 2, bnpriv);
  res = vg_set_privkey(bnpriv, pkey);
  BN_clear_free(bnpriv);
  *addrtype = ecpriv[0];
  return 1;
}


x86 assembly (clang, -O0):
<vg_decode_privkey_compressed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x30,%edx
call   1050 <vg_b58_decode_check@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x22,-0x64(%rbp)
je     118f <vg_decode_privkey_compressed+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11db <vg_decode_privkey_compressed+0x8b>
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
add    $0x1,%rdi
mov    -0x64(%rbp),%esi
sub    $0x2,%esi
mov    -0x28(%rbp),%rdx
call   1040 <BN_bin2bn@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <vg_set_privkey@plt>
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <BN_clear_free@plt>
movzbl -0x60(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_decode_privkey_compressed>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rsp,%rsi
mov    $0x30,%edx
call   1050 <vg_b58_decode_check@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x22,%ecx
jne    11b0 <vg_decode_privkey_compressed+0x60>
xor    %eax,%eax
call   1030 <BN_new@plt>
mov    %rax,%rbx
lea    0x1(%rsp),%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1040 <BN_bin2bn@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <vg_set_privkey@plt>
mov    %rbx,%rdi
call   1070 <BN_clear_free@plt>
movzbl (%rsp),%eax
mov    %eax,(%r14)
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @vg_decode_privkey_compressed(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [48 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%11 = load i8*, i8** %5
%12 = getelementptr inbounds [48 x i8], [48 x i8]* %9, i64 0, i64 0
%13 = call i32 @vg_b58_decode_check(i8* %11, i8* %12, i32 48)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp ne i32 %14, 34
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %34
17: ; preds = %3
%18 = call i32* (...) @BN_new()
store i32* %18, i32** %8
%19 = getelementptr inbounds [48 x i8], [48 x i8]* %9, i64 0, i64 0
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i32, i32* %10
%22 = sub nsw i32 %21, 2
%23 = load i32*, i32** %8
%24 = call i32 @BN_bin2bn(i8* %20, i32 %22, i32* %23)
%25 = load i32*, i32** %8
%26 = load i32*, i32** %6
%27 = call i32 @vg_set_privkey(i32* %25, i32* %26)
store i32 %27, i32* %10
%28 = load i32*, i32** %8
%29 = call i32 @BN_clear_free(i32* %28)
%30 = getelementptr inbounds [48 x i8], [48 x i8]* %9, i64 0, i64 0
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = load i32*, i32** %7
store i32 %32, i32* %33
store i32 1, i32* %4
br label %34
34: ; preds = %17, %16
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
define i32 @vg_decode_privkey_compressed(i8* %0, i32* %1, i32* nocapture writeonly %2) {
%4 = alloca [48 x i8]
%5 = getelementptr inbounds [48 x i8], [48 x i8]* %4, i64 0, i64 0
%6 = call i32 @vg_b58_decode_check(i8* %0, i8* %5, i32 48)
%7 = icmp eq i32 %6, 34
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = call i32* (...) @BN_new()
%10 = getelementptr inbounds [48 x i8], [48 x i8]* %4, i64 0, i64 1
%11 = call i32 @BN_bin2bn(i8* %10, i32 32, i32* %9)
%12 = call i32 @vg_set_privkey(i32* %9, i32* %1)
%13 = call i32 @BN_clear_free(i32* %9)
%14 = load i8, i8* %5
%15 = zext i8 %14 to i32
store i32 %15, i32* %2
br label %16
16: ; preds = %3, %8
%17 = phi i32 [ 1, %8 ], [ 0, %3 ]
ret i32 %17
}