#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 *);
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_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     116f <vg_decode_privkey_any+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    11ef <vg_decode_privkey_any+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <vg_protect_decode_privkey@plt>
cmp    $0x0,%eax
je     11c1 <vg_decode_privkey_any+0x91>
cmpq   $0x0,-0x28(%rbp)
jne    11a4 <vg_decode_privkey_any+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <vg_decode_privkey_any+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <vg_protect_decode_privkey@plt>
mov    %eax,-0x4(%rbp)
jmp    11ef <vg_decode_privkey_any+0xbf>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <vg_pkcs8_decode_privkey@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    11e9 <vg_decode_privkey_any+0xb9>
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   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
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    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     116b <vg_decode_privkey_any+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1040 <vg_protect_decode_privkey@plt>
test   %eax,%eax
je     11a0 <vg_decode_privkey_any+0x70>
test   %r14,%r14
je     11bb <vg_decode_privkey_any+0x8b>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <vg_protect_decode_privkey@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <vg_pkcs8_decode_privkey@plt>
test   %eax,%eax
jle    115f <vg_decode_privkey_any+0x2f>
movl   $0x80,(%r15)
jmp    115f <vg_decode_privkey_any+0x2f>
mov    $0xffffffff,%eax
jmp    115f <vg_decode_privkey_any+0x2f>

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 %44
17: ; preds = %4
%18 = load i32*, i32** %6
%19 = load i32*, i32** %7
%20 = load i8*, i8** %8
%21 = call i32 @vg_protect_decode_privkey(i32* %18, i32* %19, i8* %20, i8* null)
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %17
%24 = load i8*, i8** %9
%25 = icmp ne i8* %24, null
br i1 %25, label %27, label %26
26: ; preds = %23
store i32 -1, i32* %5
br label %44
27: ; preds = %23
%28 = load i32*, i32** %6
%29 = load i32*, i32** %7
%30 = load i8*, i8** %8
%31 = load i8*, i8** %9
%32 = call i32 @vg_protect_decode_privkey(i32* %28, i32* %29, i8* %30, i8* %31)
store i32 %32, i32* %5
br label %44
33: ; preds = %17
%34 = load i32*, i32** %6
%35 = load i8*, i8** %8
%36 = load i8*, i8** %9
%37 = call i32 @vg_pkcs8_decode_privkey(i32* %34, i8* %35, i8* %36)
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = load i32*, i32** %7
store i32 128, i32* %41
br label %42
42: ; preds = %40, %33
%43 = load i32, i32* %10
store i32 %43, i32* %5
br label %44
44: ; preds = %42, %27, %26, %16
%45 = load i32, i32* %5
ret i32 %45
}

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 %18
7: ; preds = %4
%8 = tail call i32 @vg_protect_decode_privkey(i32* %0, i32* %1, i8* %2, i8* null)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = icmp eq i8* %3, null
br i1 %11, label %18, label %12
12: ; preds = %10
%13 = tail call i32 @vg_protect_decode_privkey(i32* %0, i32* %1, i8* %2, i8* %3)
br label %18
14: ; preds = %7
%15 = tail call i32 @vg_pkcs8_decode_privkey(i32* %0, i8* %2, i8* %3)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 128, i32* %1
br label %18
18: ; preds = %14, %17, %10, %4, %12
%19 = phi i32 [ %13, %12 ], [ 1, %4 ], [ -1, %10 ], [ %15, %17 ], [ %15, %14 ]
ret i32 %19
}