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

/* Variables and functions */
scalar_t__ vg_decode_privkey(char const *, int /*<<< orphan*/ *, int *);
scalar_t__ vg_decode_privkey_compressed(char const *, int /*<<< orphan*/ *,
                                        int *);
int vg_pkcs8_decode_privkey(int /*<<< orphan*/ *, char const *, char const *);
int vg_protect_decode_privkey(int /*<<< orphan*/ *, int *, char const *,
                              char const *);
int vg_decode_privkey_any(EC_KEY *pkey, int *addrtype, const char *input,
                          const char *pass) {
  int res;
  if (vg_decode_privkey(input, pkey, addrtype))
    return 1;
  if (vg_decode_privkey_compressed(input, pkey, addrtype))
    return 1;
  if (vg_protect_decode_privkey(pkey, addrtype, input, NULL)) {
    if (!pass)
      return -1;
    return vg_protect_decode_privkey(pkey, addrtype, input, pass);
  }
  res = vg_pkcs8_decode_privkey(pkey, input, pass);
  if (res > 0) {
    *addrtype = 128;
  }
  return res;
}


x86 assembly (clang, -O0):
<vg_decode_privkey_any>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <vg_decode_privkey@plt>
cmp    $0x0,%rax
je     117f <vg_decode_privkey_any+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    1226 <vg_decode_privkey_any+0xe6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <vg_decode_privkey_compressed@plt>
cmp    $0x0,%rax
je     11a6 <vg_decode_privkey_any+0x66>
movl   $0x1,-0x4(%rbp)
jmp    1226 <vg_decode_privkey_any+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <vg_protect_decode_privkey@plt>
cmp    $0x0,%eax
je     11f8 <vg_decode_privkey_any+0xb8>
cmpq   $0x0,-0x28(%rbp)
jne    11db <vg_decode_privkey_any+0x9b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <vg_decode_privkey_any+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <vg_protect_decode_privkey@plt>
mov    %eax,-0x4(%rbp)
jmp    1226 <vg_decode_privkey_any+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <vg_pkcs8_decode_privkey@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    1220 <vg_decode_privkey_any+0xe0>
mov    -0x18(%rbp),%rax
movl   $0x80,(%rax)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_decode_privkey_any>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <vg_decode_privkey@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    117f <vg_decode_privkey_any+0x3f>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <vg_decode_privkey_compressed@plt>
test   %rax,%rax
je     118a <vg_decode_privkey_any+0x4a>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1050 <vg_protect_decode_privkey@plt>
test   %eax,%eax
je     11bc <vg_decode_privkey_any+0x7c>
test   %r14,%r14
je     11d9 <vg_decode_privkey_any+0x99>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <vg_protect_decode_privkey@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <vg_pkcs8_decode_privkey@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    117f <vg_decode_privkey_any+0x3f>
movl   $0x80,(%r15)
jmp    117f <vg_decode_privkey_any+0x3f>
mov    $0xffffffff,%ebp
jmp    117f <vg_decode_privkey_any+0x3f>

LLVM IR (-O0):
define i32 @vg_decode_privkey_any(i32* %0, i32* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %8
%12 = load i32*, i32** %6
%13 = load i32*, i32** %7
%14 = call i64 @vg_decode_privkey(i8* %11, i32* %12, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 1, i32* %5
br label %51
17: ; preds = %4
%18 = load i8*, i8** %8
%19 = load i32*, i32** %6
%20 = load i32*, i32** %7
%21 = call i64 @vg_decode_privkey_compressed(i8* %18, i32* %19, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %5
br label %51
24: ; preds = %17
%25 = load i32*, i32** %6
%26 = load i32*, i32** %7
%27 = load i8*, i8** %8
%28 = call i32 @vg_protect_decode_privkey(i32* %25, i32* %26, i8* %27, i8* null)
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %24
%31 = load i8*, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %30
store i32 -1, i32* %5
br label %51
34: ; preds = %30
%35 = load i32*, i32** %6
%36 = load i32*, i32** %7
%37 = load i8*, i8** %8
%38 = load i8*, i8** %9
%39 = call i32 @vg_protect_decode_privkey(i32* %35, i32* %36, i8* %37, i8* %38)
store i32 %39, i32* %5
br label %51
40: ; preds = %24
%41 = load i32*, i32** %6
%42 = load i8*, i8** %8
%43 = load i8*, i8** %9
%44 = call i32 @vg_pkcs8_decode_privkey(i32* %41, i8* %42, i8* %43)
store i32 %44, i32* %10
%45 = load i32, i32* %10
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = load i32*, i32** %7
store i32 128, i32* %48
br label %49
49: ; preds = %47, %40
%50 = load i32, i32* %10
store i32 %50, i32* %5
br label %51
51: ; preds = %49, %34, %33, %23, %16
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
define i32 @vg_decode_privkey_any(i32* %0, i32* %1, i8* %2, i8* %3) {
%5 = tail call i64 @vg_decode_privkey(i8* %2, i32* %0, i32* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = tail call i64 @vg_decode_privkey_compressed(i8* %2, i32* %0, i32* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = tail call i32 @vg_protect_decode_privkey(i32* %0, i32* %1, i8* %2, i8* null)
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = icmp eq i8* %3, null
br i1 %14, label %21, label %15
15: ; preds = %13
%16 = tail call i32 @vg_protect_decode_privkey(i32* %0, i32* %1, i8* %2, i8* %3)
br label %21
17: ; preds = %10
%18 = tail call i32 @vg_pkcs8_decode_privkey(i32* %0, i8* %2, i8* %3)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 128, i32* %1
br label %21
21: ; preds = %17, %20, %13, %7, %4, %15
%22 = phi i32 [ %16, %15 ], [ 1, %4 ], [ 1, %7 ], [ -1, %13 ], [ %18, %20 ], [ %18, %17 ]
ret i32 %22
}