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

/* Variables and functions */
int /*<<< orphan*/ EC_KEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_new_by_curve_name(int /*<<< orphan*/);
int EVP_read_pw_string(char *, int, char *, int);
int /*<<< orphan*/ NID_secp256k1;
int /*<<< orphan*/ OPENSSL_cleanse(char *, int);
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ vg_check_password_complexity(char const *, int);
int vg_decode_privkey_any(int /*<<< orphan*/ *, int *, char const *, char *);
int /*<<< orphan*/ vg_encode_address(int /*<<< orphan*/ *, int, char *);
int /*<<< orphan*/ vg_encode_privkey(int /*<<< orphan*/ *, int, char *);
int vg_pkcs8_encode_privkey(char *, int, int /*<<< orphan*/ *, char const *);
int vg_protect_encode_privkey(char *, int /*<<< orphan*/ *, int, int,
                              char const *);
int main(int argc, char **argv) {
  char pwbuf[128];
  char ecprot[128];
  char pbuf[1024];
  const char *key_in;
  const char *pass_in = NULL;
  EC_KEY *pkey;
  int parameter_group = -1;
  int privtype, addrtype;
  int pkcs8 = 0;
  int pass_prompt = 0;
  int opt;
  int res;
  while ((opt = getopt(argc, argv, "8E:e")) != -1) {
    switch (opt) {
    case '8':
      pkcs8 = 1;
      break;
    case 'E':
      if (pass_prompt) {
        usage(argv[0]);
        return 1;
      }
      pass_in = optarg;
      if (!vg_check_password_complexity(pass_in, 1))
        fprintf(stderr, "WARNING: Using weak password\n");
      break;
    case 'e':
      if (pass_in) {
        usage(argv[0]);
        return 1;
      }
      pass_prompt = 1;
      break;
    default:
      usage(argv[0]);
      return 1;
    }
  }
  if (optind >= argc) {
    res = fread(pbuf, 1, sizeof(pbuf) - 1, stdin);
    pbuf[res] = '\0';
    key_in = pbuf;
  } else {
    key_in = argv[optind];
  }
  OpenSSL_add_all_algorithms();
  pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
  res = vg_decode_privkey_any(pkey, &privtype, key_in, NULL);
  if (res < 0) {
    if (EVP_read_pw_string(pwbuf, sizeof(pwbuf), "Enter import password:", 0) ||
        !vg_decode_privkey_any(pkey, &privtype, key_in, pwbuf))
      return 1;
  }
  if (!res) {
    fprintf(stderr, "ERROR: Unrecognized key format\n");
    return 1;
  }
  if (pass_prompt) {
    res = EVP_read_pw_string(pwbuf, sizeof(pwbuf), "Enter password:", 1);
    if (res)
      return 1;
    pass_in = pwbuf;
    if (!vg_check_password_complexity(pwbuf, 1))
      fprintf(stderr, "WARNING: Using weak password\n");
  }
  switch (privtype) {
  case 128:
    addrtype = 0;
    break;
  case 239:
    addrtype = 111;
    break;
  default:
    addrtype = 0;
    break;
  }
  if (pkcs8) {
    res = vg_pkcs8_encode_privkey(pbuf, sizeof(pbuf), pkey, pass_in);
    if (!res) {
      fprintf(stderr, "ERROR: Could not encode private key\n");
      return 1;
    }
    printf("%s", pbuf);
  } else if (pass_in) {
    res = vg_protect_encode_privkey(ecprot, pkey, privtype, parameter_group,
                                    pass_in);
    if (!res) {
      fprintf(stderr, "ERROR: could not password-protect "
                      "private key\n");
      return 1;
    }
    vg_encode_address(pkey, addrtype, pwbuf);
    printf("Address: %s\n", pwbuf);
    printf("Protkey: %s\n", ecprot);
  } else {
    vg_encode_address(pkey, addrtype, ecprot);
    printf("Address: %s\n", ecprot);
    vg_encode_privkey(pkey, privtype, ecprot);
    printf("Privkey: %s\n", ecprot);
  }
  OPENSSL_cleanse(pwbuf, sizeof(pwbuf));
  EC_KEY_free(pkey);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x520(%rbp)
movl   $0xffffffff,-0x52c(%rbp)
ff ff ff
movl   $0x0,-0x538(%rbp)
movl   $0x0,-0x53c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdb0(%rip),%rdx
call   10f0 <getopt@plt>
mov    %eax,-0x540(%rbp)
cmp    $0xffffffff,%eax
je     1371 <main+0x171>
mov    -0x540(%rbp),%eax
mov    %eax,-0x548(%rbp)
sub    $0x38,%eax
je     12a6 <main+0xa6>
jmp    127e <main+0x7e>
mov    -0x548(%rbp),%eax
sub    $0x45,%eax
je     12b5 <main+0xb5>
jmp    1292 <main+0x92>
mov    -0x548(%rbp),%eax
sub    $0x65,%eax
je     131f <main+0x11f>
jmp    1354 <main+0x154>
movl   $0x1,-0x538(%rbp)
jmp    136c <main+0x16c>
cmpl   $0x0,-0x53c(%rbp)
je     12da <main+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
mov    0x2d17(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x520(%rbp)
mov    -0x520(%rbp),%rdi
mov    $0x1,%esi
call   1110 <vg_check_password_complexity@plt>
cmp    $0x0,%eax
jne    131a <main+0x11a>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xcf0(%rip),%rsi
call   1090 <fprintf@plt>
jmp    136c <main+0x16c>
cmpq   $0x0,-0x520(%rbp)
je     1345 <main+0x145>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
movl   $0x1,-0x53c(%rbp)
jmp    136c <main+0x16c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
jmp    1242 <main+0x42>
mov    0x2c60(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     13ca <main+0x1ca>
lea    -0x510(%rbp),%rdi
mov    0x2c4f(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x3ff,%edx
call   1040 <fread@plt>
mov    %eax,-0x544(%rbp)
movslq -0x544(%rbp),%rax
movb   $0x0,-0x510(%rbp,%rax,1)
lea    -0x510(%rbp),%rax
mov    %rax,-0x518(%rbp)
jmp    13e3 <main+0x1e3>
mov    -0x10(%rbp),%rax
mov    0x2c03(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x518(%rbp)
mov    $0x0,%al
call   10a0 <OpenSSL_add_all_algorithms@plt>
mov    0x2bcf(%rip),%rax
mov    (%rax),%edi
call   1120 <EC_KEY_new_by_curve_name@plt>
mov    %rax,-0x528(%rbp)
mov    -0x528(%rbp),%rdi
mov    -0x518(%rbp),%rdx
lea    -0x530(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   10b0 <vg_decode_privkey_any@plt>
mov    %eax,-0x544(%rbp)
cmpl   $0x0,-0x544(%rbp)
jge    148e <main+0x28e>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
lea    0xbe0(%rip),%rdx
xor    %ecx,%ecx
call   10c0 <EVP_read_pw_string@plt>
cmp    $0x0,%eax
jne    147d <main+0x27d>
mov    -0x528(%rbp),%rdi
mov    -0x518(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    -0x530(%rbp),%rsi
call   10b0 <vg_decode_privkey_any@plt>
cmp    $0x0,%eax
jne    1489 <main+0x289>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
jmp    148e <main+0x28e>
cmpl   $0x0,-0x544(%rbp)
jne    14bc <main+0x2bc>
mov    0x2b26(%rip),%rax
mov    (%rax),%edi
lea    0xb8f(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
cmpl   $0x0,-0x53c(%rbp)
je     1547 <main+0x347>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
lea    0xb7e(%rip),%rdx
mov    $0x1,%ecx
call   10c0 <EVP_read_pw_string@plt>
mov    %eax,-0x544(%rbp)
cmpl   $0x0,-0x544(%rbp)
je     1505 <main+0x305>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
lea    -0x90(%rbp),%rax
mov    %rax,-0x520(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x1,%esi
call   1110 <vg_check_password_complexity@plt>
cmp    $0x0,%eax
jne    1542 <main+0x342>
mov    0x2a94(%rip),%rax
mov    (%rax),%edi
lea    0xac8(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1547 <main+0x347>
mov    -0x530(%rbp),%eax
mov    %eax,-0x54c(%rbp)
sub    $0x80,%eax
je     1579 <main+0x379>
jmp    1563 <main+0x363>
mov    -0x54c(%rbp),%eax
sub    $0xef,%eax
je     1588 <main+0x388>
jmp    1597 <main+0x397>
movl   $0x0,-0x534(%rbp)
jmp    15a1 <main+0x3a1>
movl   $0x6f,-0x534(%rbp)
jmp    15a1 <main+0x3a1>
movl   $0x0,-0x534(%rbp)
cmpl   $0x0,-0x538(%rbp)
je     1619 <main+0x419>
lea    -0x510(%rbp),%rdi
mov    -0x528(%rbp),%rdx
mov    -0x520(%rbp),%rcx
mov    $0x400,%esi
call   1100 <vg_pkcs8_encode_privkey@plt>
mov    %eax,-0x544(%rbp)
cmpl   $0x0,-0x544(%rbp)
jne    1601 <main+0x401>
mov    0x29e1(%rip),%rax
mov    (%rax),%edi
lea    0xa7a(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
lea    -0x510(%rbp),%rsi
lea    0xa80(%rip),%rdi
call   1060 <printf@plt>
jmp    1722 <main+0x522>
cmpq   $0x0,-0x520(%rbp)
je     16c5 <main+0x4c5>
lea    -0x110(%rbp),%rdi
mov    -0x528(%rbp),%rsi
mov    -0x530(%rbp),%edx
mov    -0x52c(%rbp),%ecx
mov    -0x520(%rbp),%r8
call   1050 <vg_protect_encode_privkey@plt>
mov    %eax,-0x544(%rbp)
cmpl   $0x0,-0x544(%rbp)
jne    1681 <main+0x481>
mov    0x2961(%rip),%rax
mov    (%rax),%edi
lea    0xa22(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1746 <main+0x546>
mov    -0x528(%rbp),%rdi
mov    -0x534(%rbp),%esi
lea    -0x90(%rbp),%rdx
call   1030 <vg_encode_address@plt>
lea    -0x90(%rbp),%rsi
lea    0xa19(%rip),%rdi
call   1060 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xa13(%rip),%rdi
call   1060 <printf@plt>
jmp    171d <main+0x51d>
mov    -0x528(%rbp),%rdi
mov    -0x534(%rbp),%esi
lea    -0x110(%rbp),%rdx
call   1030 <vg_encode_address@plt>
lea    -0x110(%rbp),%rsi
lea    0x9d5(%rip),%rdi
call   1060 <printf@plt>
mov    -0x528(%rbp),%rdi
mov    -0x530(%rbp),%esi
lea    -0x110(%rbp),%rdx
call   1080 <vg_encode_privkey@plt>
lea    -0x110(%rbp),%rsi
lea    0x9c3(%rip),%rdi
call   1060 <printf@plt>
jmp    1722 <main+0x522>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1070 <OPENSSL_cleanse@plt>
mov    -0x528(%rbp),%rdi
call   10e0 <EC_KEY_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r15d,%r15d
lea    0xde0(%rip),%r14
xor    %r13d,%r13d
xor    %r12d,%r12d
mov    %r13d,%ecx
nopl   0x0(%rax)
mov    %ecx,%r13d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10f0 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x38,%eax
je     1230 <main+0x30>
cmp    $0xffffffff,%eax
je     12ca <main+0xca>
cmp    $0x65,%eax
je     1290 <main+0x90>
cmp    $0x45,%eax
jne    12bd <main+0xbd>
test   %r12d,%r12d
jne    12bd <main+0xbd>
mov    0x2d93(%rip),%rax
mov    (%rax),%r15
mov    %r15,%rdi
mov    $0x1,%esi
call   1110 <vg_check_password_complexity@plt>
mov    $0x0,%r12d
test   %eax,%eax
jne    1226 <main+0x26>
jmp    12a3 <main+0xa3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r12d
test   %r15,%r15
mov    $0x0,%r15d
je     1226 <main+0x26>
jmp    12bd <main+0xbd>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1223 <main+0x23>
mov    (%rbx),%rdi
call   10d0 <usage@plt>
jmp    152a <main+0x32a>
mov    0x2d07(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    12de <main+0xde>
mov    (%rbx,%rax,8),%rbx
jmp    130b <main+0x10b>
lea    0x110(%rsp),%rbx
mov    0x2cf3(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3ff,%edx
call   1040 <fread@plt>
cltq
movb   $0x0,0x110(%rsp,%rax,1)
xor    %eax,%eax
call   10a0 <OpenSSL_add_all_algorithms@plt>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
call   1120 <EC_KEY_new_by_curve_name@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   10b0 <vg_decode_privkey_any@plt>
test   %eax,%eax
js     13f3 <main+0x1f3>
je     143a <main+0x23a>
test   %r12d,%r12d
je     1399 <main+0x199>
lea    0xd0b(%rip),%rdx
lea    0x10(%rsp),%r15
mov    $0x1,%ebp
mov    %r15,%rdi
mov    $0x80,%esi
mov    $0x1,%ecx
call   10c0 <EVP_read_pw_string@plt>
test   %eax,%eax
jne    152f <main+0x32f>
mov    %r15,%rdi
mov    $0x1,%esi
call   1110 <vg_check_password_complexity@plt>
test   %eax,%eax
jne    1399 <main+0x199>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    0xc71(%rip),%rsi
call   1090 <fprintf@plt>
mov    0xc(%rsp),%edx
xor    %eax,%eax
cmp    $0xef,%edx
mov    $0x6f,%ebx
cmovne %eax,%ebx
cmp    $0x80,%edx
cmove  %eax,%ebx
test   %r13d,%r13d
je     144f <main+0x24f>
lea    0x110(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1100 <vg_pkcs8_encode_privkey@plt>
test   %eax,%eax
je     14a6 <main+0x2a6>
lea    0xca9(%rip),%rdi
lea    0x110(%rsp),%rsi
jmp    14f5 <main+0x2f5>
lea    0xc29(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
xor    %ecx,%ecx
call   10c0 <EVP_read_pw_string@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    152f <main+0x32f>
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rdx
call   10b0 <vg_decode_privkey_any@plt>
test   %eax,%eax
jne    1343 <main+0x143>
jmp    152f <main+0x32f>
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
lea    0xbf0(%rip),%rsi
jmp    1525 <main+0x325>
test   %r15,%r15
je     14b8 <main+0x2b8>
lea    0x90(%rsp),%rdi
mov    %r14,%rsi
mov    $0xffffffff,%ecx
mov    %r15,%r8
call   1050 <vg_protect_encode_privkey@plt>
test   %eax,%eax
je     1515 <main+0x315>
lea    0x10(%rsp),%rbp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
call   1030 <vg_encode_address@plt>
lea    0xc34(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
lea    0xc32(%rip),%rdi
lea    0x90(%rsp),%rsi
jmp    14f5 <main+0x2f5>
mov    0x2b1b(%rip),%rax
mov    (%rax),%edi
lea    0xbb4(%rip),%rsi
jmp    1525 <main+0x325>
lea    0x90(%rsp),%rbp
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
call   1030 <vg_encode_address@plt>
lea    0xbed(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
mov    %rbp,%rdx
call   1080 <vg_encode_privkey@plt>
lea    0xbe9(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
call   1070 <OPENSSL_cleanse@plt>
mov    %r14,%rdi
call   10e0 <EC_KEY_free@plt>
xor    %ebp,%ebp
jmp    152f <main+0x32f>
mov    0x2aac(%rip),%rax
mov    (%rax),%edi
lea    0xb6d(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"8E:e\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [30 x i8] c"WARNING: Using weak password\0A\00"
@optind = global i32 0
@stdin = global i32 0
@NID_secp256k1 = global i32 0
@.str.2 = [23 x i8] c"Enter import password:\00"
@.str.3 = [32 x i8] c"ERROR: Unrecognized key format\0A\00"
@.str.4 = [16 x i8] c"Enter password:\00"
@.str.5 = [37 x i8] c"ERROR: Could not encode private key\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [47 x i8] c"ERROR: could not password-protect private key\0A\00"
@.str.8 = [13 x i8] c"Address: %s\0A\00"
@.str.9 = [13 x i8] c"Protkey: %s\0A\00"
@.str.10 = [13 x i8] c"Privkey: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i32 -1, i32* %12
store i32 0, i32* %15
store i32 0, i32* %16
br label %19
19: ; preds = %58, %2
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %17
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %59
24: ; preds = %19
%25 = load i32, i32* %17
switch i32 %25, label %53 [
i32 56, label %26
i32 69, label %27
i32 101, label %44
]
26: ; preds = %24
store i32 1, i32* %15
br label %58
27: ; preds = %24
%28 = load i32, i32* %16
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @usage(i8* %33)
store i32 1, i32* %3
br label %186
35: ; preds = %27
%36 = load i8*, i8** @optarg
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = call i32 @vg_check_password_complexity(i8* %37, i32 1)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %40, %35
br label %58
44: ; preds = %24
%45 = load i8*, i8** %10
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @usage(i8* %50)
store i32 1, i32* %3
br label %186
52: ; preds = %44
store i32 1, i32* %16
br label %58
53: ; preds = %24
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = call i32 @usage(i8* %56)
store i32 1, i32* %3
br label %186
58: ; preds = %52, %43, %26
br label %19
59: ; preds = %19
%60 = load i32, i32* @optind
%61 = load i32, i32* %4
%62 = icmp sge i32 %60, %61
br i1 %62, label %63, label %71
63: ; preds = %59
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = load i32, i32* @stdin
%66 = call i32 @fread(i8* %64, i32 1, i32 1023, i32 %65)
store i32 %66, i32* %18
%67 = load i32, i32* %18
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %68
store i8 0, i8* %69
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8* %70, i8** %9
br label %77
71: ; preds = %59
%72 = load i8**, i8*** %5
%73 = load i32, i32* @optind
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
store i8* %76, i8** %9
br label %77
77: ; preds = %71, %63
%78 = call i32 (...) @OpenSSL_add_all_algorithms()
%79 = load i32, i32* @NID_secp256k1
%80 = call i32* @EC_KEY_new_by_curve_name(i32 %79)
store i32* %80, i32** %11
%81 = load i32*, i32** %11
%82 = load i8*, i8** %9
%83 = call i32 @vg_decode_privkey_any(i32* %81, i32* %13, i8* %82, i8* null)
store i32 %83, i32* %18
%84 = load i32, i32* %18
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %98
86: ; preds = %77
%87 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%88 = call i32 @EVP_read_pw_string(i8* %87, i32 128, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0)
%89 = icmp ne i32 %88, 0
br i1 %89, label %96, label %90
90: ; preds = %86
%91 = load i32*, i32** %11
%92 = load i8*, i8** %9
%93 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%94 = call i32 @vg_decode_privkey_any(i32* %91, i32* %13, i8* %92, i8* %93)
%95 = icmp ne i32 %94, 0
br i1 %95, label %97, label %96
96: ; preds = %90, %86
store i32 1, i32* %3
br label %186
97: ; preds = %90
br label %98
98: ; preds = %97, %77
%99 = load i32, i32* %18
%100 = icmp ne i32 %99, 0
br i1 %100, label %104, label %101
101: ; preds = %98
%102 = load i32, i32* @stderr
%103 = call i32 @fprintf(i32 %102, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %186
104: ; preds = %98
%105 = load i32, i32* %16
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %122
107: ; preds = %104
%108 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%109 = call i32 @EVP_read_pw_string(i8* %108, i32 128, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 1)
store i32 %109, i32* %18
%110 = load i32, i32* %18
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %107
store i32 1, i32* %3
br label %186
113: ; preds = %107
%114 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
store i8* %114, i8** %10
%115 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%116 = call i32 @vg_check_password_complexity(i8* %115, i32 1)
%117 = icmp ne i32 %116, 0
br i1 %117, label %121, label %118
118: ; preds = %113
%119 = load i32, i32* @stderr
%120 = call i32 @fprintf(i32 %119, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %121
121: ; preds = %118, %113
br label %122
122: ; preds = %121, %104
%123 = load i32, i32* %13
switch i32 %123, label %126 [
i32 128, label %124
i32 239, label %125
]
124: ; preds = %122
store i32 0, i32* %14
br label %127
125: ; preds = %122
store i32 111, i32* %14
br label %127
126: ; preds = %122
store i32 0, i32* %14
br label %127
127: ; preds = %126, %125, %124
%128 = load i32, i32* %15
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %143
130: ; preds = %127
%131 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%132 = load i32*, i32** %11
%133 = load i8*, i8** %10
%134 = call i32 @vg_pkcs8_encode_privkey(i8* %131, i32 1024, i32* %132, i8* %133)
store i32 %134, i32* %18
%135 = load i32, i32* %18
%136 = icmp ne i32 %135, 0
br i1 %136, label %140, label %137
137: ; preds = %130
%138 = load i32, i32* @stderr
%139 = call i32 @fprintf(i32 %138, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %186
140: ; preds = %130
%141 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%142 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %141)
br label %181
143: ; preds = %127
%144 = load i8*, i8** %10
%145 = icmp ne i8* %144, null
br i1 %145, label %146, label %167
146: ; preds = %143
%147 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%148 = load i32*, i32** %11
%149 = load i32, i32* %13
%150 = load i32, i32* %12
%151 = load i8*, i8** %10
%152 = call i32 @vg_protect_encode_privkey(i8* %147, i32* %148, i32 %149, i32 %150, i8* %151)
store i32 %152, i32* %18
%153 = load i32, i32* %18
%154 = icmp ne i32 %153, 0
br i1 %154, label %158, label %155
155: ; preds = %146
%156 = load i32, i32* @stderr
%157 = call i32 @fprintf(i32 %156, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %186
158: ; preds = %146
%159 = load i32*, i32** %11
%160 = load i32, i32* %14
%161 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%162 = call i32 @vg_encode_address(i32* %159, i32 %160, i8* %161)
%163 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%164 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* %163)
%165 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%166 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* %165)
br label %180
167: ; preds = %143
%168 = load i32*, i32** %11
%169 = load i32, i32* %14
%170 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%171 = call i32 @vg_encode_address(i32* %168, i32 %169, i8* %170)
%172 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%173 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* %172)
%174 = load i32*, i32** %11
%175 = load i32, i32* %13
%176 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%177 = call i32 @vg_encode_privkey(i32* %174, i32 %175, i8* %176)
%178 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%179 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %178)
br label %180
180: ; preds = %167, %158
br label %181
181: ; preds = %180, %140
%182 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%183 = call i32 @OPENSSL_cleanse(i8* %182, i32 128)
%184 = load i32*, i32** %11
%185 = call i32 @EC_KEY_free(i32* %184)
store i32 0, i32* %3
br label %186
186: ; preds = %181, %155, %137, %112, %101, %96, %53, %47, %30
%187 = load i32, i32* %3
ret i32 %187
}

LLVM IR (-O2):
@.str = [5 x i8] c"8E:e\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [30 x i8] c"WARNING: Using weak password\0A\00"
@optind = global i32 0
@stdin = global i32 0
@NID_secp256k1 = global i32 0
@.str.2 = [23 x i8] c"Enter import password:\00"
@.str.3 = [32 x i8] c"ERROR: Unrecognized key format\0A\00"
@.str.4 = [16 x i8] c"Enter password:\00"
@.str.5 = [37 x i8] c"ERROR: Could not encode private key\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [47 x i8] c"ERROR: could not password-protect private key\0A\00"
@.str.8 = [13 x i8] c"Address: %s\0A\00"
@.str.9 = [13 x i8] c"Protkey: %s\0A\00"
@.str.10 = [13 x i8] c"Privkey: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
br label %11
11: ; preds = %27, %2
%12 = phi i8* [ null, %2 ], [ %28, %27 ]
%13 = phi i32 [ 0, %2 ], [ %16, %27 ]
%14 = phi i32 [ 0, %2 ], [ %29, %27 ]
br label %15
15: ; preds = %11, %15
%16 = phi i32 [ 1, %15 ], [ %13, %11 ]
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %17, label %38 [
i32 -1, label %41
i32 56, label %15
i32 69, label %18
i32 101, label %33
]
18: ; preds = %15
%19 = icmp eq i32 %14, 0
br i1 %19, label %23, label %20
20: ; preds = %18
%21 = load i8*, i8** %1
%22 = tail call i32 @usage(i8* %21)
br label %119
23: ; preds = %18
%24 = load i8*, i8** @optarg
%25 = tail call i32 @vg_check_password_complexity(i8* %24, i32 1)
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %23, %30, %33
%28 = phi i8* [ null, %33 ], [ %24, %30 ], [ %24, %23 ]
%29 = phi i32 [ 1, %33 ], [ 0, %30 ], [ 0, %23 ]
br label %11
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %27
33: ; preds = %15
%34 = icmp eq i8* %12, null
br i1 %34, label %27, label %35
35: ; preds = %33
%36 = load i8*, i8** %1
%37 = tail call i32 @usage(i8* %36)
br label %119
38: ; preds = %15
%39 = load i8*, i8** %1
%40 = tail call i32 @usage(i8* %39)
br label %119
41: ; preds = %15
%42 = load i32, i32* @optind
%43 = icmp slt i32 %42, %0
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = load i32, i32* @stdin
%46 = call i32 @fread(i8* %9, i32 1, i32 1023, i32 %45)
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %47
store i8 0, i8* %48
br label %53
49: ; preds = %41
%50 = sext i32 %42 to i64
%51 = getelementptr inbounds i8*, i8** %1, i64 %50
%52 = load i8*, i8** %51
br label %53
53: ; preds = %49, %44
%54 = phi i8* [ %9, %44 ], [ %52, %49 ]
%55 = call i32 (...) @OpenSSL_add_all_algorithms()
%56 = load i32, i32* @NID_secp256k1
%57 = call i32* @EC_KEY_new_by_curve_name(i32 %56)
%58 = call i32 @vg_decode_privkey_any(i32* %57, i32* %6, i8* %54, i8* null)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %53
%61 = call i32 @EVP_read_pw_string(i8* %7, i32 128, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0)
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %119
63: ; preds = %60
%64 = call i32 @vg_decode_privkey_any(i32* %57, i32* %6, i8* %54, i8* %7)
%65 = icmp eq i32 %64, 0
br i1 %65, label %119, label %71
66: ; preds = %53
%67 = icmp eq i32 %58, 0
br i1 %67, label %68, label %71
68: ; preds = %66
%69 = load i32, i32* @stderr
%70 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %119
71: ; preds = %63, %66
%72 = icmp eq i32 %14, 0
br i1 %72, label %82, label %73
73: ; preds = %71
%74 = call i32 @EVP_read_pw_string(i8* %7, i32 128, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 1)
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %119
76: ; preds = %73
%77 = call i32 @vg_check_password_complexity(i8* %7, i32 1)
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %82
82: ; preds = %76, %79, %71
%83 = phi i8* [ %7, %76 ], [ %7, %79 ], [ %12, %71 ]
%84 = load i32, i32* %6
%85 = icmp eq i32 %84, 239
%86 = select i1 %85, i32 111, i32 0
%87 = icmp eq i32 %84, 128
%88 = select i1 %87, i32 0, i32 %86
%89 = icmp eq i32 %16, 0
br i1 %89, label %98, label %90
90: ; preds = %82
%91 = call i32 @vg_pkcs8_encode_privkey(i8* %9, i32 1024, i32* %57, i8* %83)
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %119
96: ; preds = %90
%97 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %9)
br label %116
98: ; preds = %82
%99 = icmp eq i8* %83, null
br i1 %99, label %110, label %100
100: ; preds = %98
%101 = call i32 @vg_protect_encode_privkey(i8* %8, i32* %57, i32 %84, i32 -1, i8* %83)
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i32, i32* @stderr
%105 = call i32 @fprintf(i32 %104, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
br label %119
106: ; preds = %100
%107 = call i32 @vg_encode_address(i32* %57, i32 %88, i8* %7)
%108 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* %7)
%109 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* %8)
br label %116
110: ; preds = %98
%111 = call i32 @vg_encode_address(i32* %57, i32 %88, i8* %8)
%112 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* %8)
%113 = load i32, i32* %6
%114 = call i32 @vg_encode_privkey(i32* %57, i32 %113, i8* %8)
%115 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %8)
br label %116
116: ; preds = %106, %110, %96
%117 = call i32 @OPENSSL_cleanse(i8* %7, i32 128)
%118 = call i32 @EC_KEY_free(i32* %57)
br label %119
119: ; preds = %73, %60, %63, %116, %103, %93, %68, %38, %35, %20
%120 = phi i32 [ 1, %38 ], [ 1, %35 ], [ 1, %20 ], [ 0, %116 ], [ 1, %93 ], [ 1, %103 ], [ 1, %68 ], [ 1, %63 ], [ 1, %60 ], [ 1, %73 ]
ret i32 %120
}