#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 */
int /*<<< orphan*/ EC_KEY_generate_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_KEY_get0_group(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_KEY_get0_public_key(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_KEY_new_by_curve_name(int /*<<< orphan*/);
int /*<<< orphan*/ NID_secp256k1;
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int atoi(char *);
int /*<<< orphan*/ i2o_ECPublicKey(int /*<<< orphan*/ *, unsigned char **);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ vg_encode_address(int /*<<< orphan*/, int /*<<< orphan*/,
                                     int /*<<< orphan*/, char *);
int /*<<< orphan*/ vg_encode_privkey(int /*<<< orphan*/ *, int, char *);
int main(int argc, char **argv) {
  char ecprot[128];
  char pbuf[1024];
  EC_KEY *pkey;
  unsigned char *pend = (unsigned char *)pbuf;
  int count = argc > 1 ? atoi(argv[1]) : 1;
  OpenSSL_add_all_algorithms();
  while (count-- > 0) {
    pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
    EC_KEY_generate_key(pkey);
    i2o_ECPublicKey(pkey, &pend);
    vg_encode_address(EC_KEY_get0_public_key(pkey), EC_KEY_get0_group(pkey), 0,
                      ecprot);
    printf("Address: %s\n", ecprot);
    vg_encode_privkey(pkey, 128, ecprot);
    printf("Privkey: %s\n\n", ecprot);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x490(%rbp),%rax
mov    %rax,-0x4a0(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11e9 <main+0x49>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x4a8(%rbp)
jmp    11f9 <main+0x59>
mov    $0x1,%eax
mov    %eax,-0x4a8(%rbp)
jmp    11f9 <main+0x59>
mov    -0x4a8(%rbp),%eax
mov    %eax,-0x4a4(%rbp)
mov    $0x0,%al
call   1080 <OpenSSL_add_all_algorithms@plt>
mov    -0x4a4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4a4(%rbp)
cmp    $0x0,%eax
jle    12d1 <main+0x131>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10c0 <EC_KEY_new_by_curve_name@plt>
mov    %rax,-0x498(%rbp)
mov    -0x498(%rbp),%rdi
call   1070 <EC_KEY_generate_key@plt>
mov    -0x498(%rbp),%rdi
lea    -0x4a0(%rbp),%rsi
call   10a0 <i2o_ECPublicKey@plt>
mov    -0x498(%rbp),%rdi
call   1040 <EC_KEY_get0_public_key@plt>
mov    %eax,-0x4ac(%rbp)
mov    -0x498(%rbp),%rdi
call   1090 <EC_KEY_get0_group@plt>
mov    -0x4ac(%rbp),%edi
mov    %eax,%esi
lea    -0x90(%rbp),%rcx
xor    %edx,%edx
call   1030 <vg_encode_address@plt>
lea    -0x90(%rbp),%rsi
lea    0xd64(%rip),%rdi
call   1050 <printf@plt>
mov    -0x498(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x80,%esi
call   1060 <vg_encode_privkey@plt>
lea    -0x90(%rbp),%rsi
lea    0xd46(%rip),%rdi
call   1050 <printf@plt>
jmp    120c <main+0x6c>
mov    -0x4(%rbp),%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x498,%rsp
lea    0x90(%rsp),%rax
mov    %rax,0x8(%rsp)
cmp    $0x1,%edi
jle    11de <main+0x3e>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <OpenSSL_add_all_algorithms@plt>
test   %ebx,%ebx
jg     11ea <main+0x4a>
jmp    1276 <main+0xd6>
xor    %eax,%eax
call   1080 <OpenSSL_add_all_algorithms@plt>
mov    $0x1,%ebx
add    $0x1,%ebx
lea    0x10(%rsp),%r15
lea    0xe07(%rip),%r12
lea    0xe0d(%rip),%r13
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   10c0 <EC_KEY_new_by_curve_name@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <EC_KEY_generate_key@plt>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   10a0 <i2o_ECPublicKey@plt>
mov    %rbp,%rdi
call   1040 <EC_KEY_get0_public_key@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1090 <EC_KEY_get0_group@plt>
mov    %r14d,%edi
mov    %eax,%esi
xor    %edx,%edx
mov    %r15,%rcx
call   1030 <vg_encode_address@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r15,%rdx
call   1060 <vg_encode_privkey@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1200 <main+0x60>
xor    %eax,%eax
add    $0x498,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NID_secp256k1 = global i32 0
@.str = [13 x i8] c"Address: %s\0A\00"
@.str.1 = [14 x i8] c"Privkey: %s\0A\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 [1024 x i8]
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8* %11, i8** %9
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
br label %20
19: ; preds = %2
br label %20
20: ; preds = %19, %14
%21 = phi i32 [ %18, %14 ], [ 1, %19 ]
store i32 %21, i32* %10
%22 = call i32 (...) @OpenSSL_add_all_algorithms()
br label %23
23: ; preds = %27, %20
%24 = load i32, i32* %10
%25 = add nsw i32 %24, -1
store i32 %25, i32* %10
%26 = icmp sgt i32 %24, 0
br i1 %26, label %27, label %47
27: ; preds = %23
%28 = load i32, i32* @NID_secp256k1
%29 = call i32* @EC_KEY_new_by_curve_name(i32 %28)
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = call i32 @EC_KEY_generate_key(i32* %30)
%32 = load i32*, i32** %8
%33 = call i32 @i2o_ECPublicKey(i32* %32, i8** %9)
%34 = load i32*, i32** %8
%35 = call i32 @EC_KEY_get0_public_key(i32* %34)
%36 = load i32*, i32** %8
%37 = call i32 @EC_KEY_get0_group(i32* %36)
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%39 = call i32 @vg_encode_address(i32 %35, i32 %37, i32 0, i8* %38)
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %8
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%44 = call i32 @vg_encode_privkey(i32* %42, i32 128, i8* %43)
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %45)
br label %23
47: ; preds = %23
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@NID_secp256k1 = global i32 0
@.str = [13 x i8] c"Address: %s\0A\00"
@.str.1 = [14 x i8] c"Privkey: %s\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
store i8* %7, i8** %5
%9 = icmp sgt i32 %0, 1
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 (...) @OpenSSL_add_all_algorithms()
br label %18
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
%16 = call i32 (...) @OpenSSL_add_all_algorithms()
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %34
18: ; preds = %10, %12
%19 = phi i32 [ %15, %12 ], [ 1, %10 ]
br label %20
20: ; preds = %18, %20
%21 = phi i32 [ %22, %20 ], [ %19, %18 ]
%22 = add nsw i32 %21, -1
%23 = load i32, i32* @NID_secp256k1
%24 = call i32* @EC_KEY_new_by_curve_name(i32 %23)
%25 = call i32 @EC_KEY_generate_key(i32* %24)
%26 = call i32 @i2o_ECPublicKey(i32* %24, i8** %5)
%27 = call i32 @EC_KEY_get0_public_key(i32* %24)
%28 = call i32 @EC_KEY_get0_group(i32* %24)
%29 = call i32 @vg_encode_address(i32 %27, i32 %28, i32 0, i8* %6)
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %6)
%31 = call i32 @vg_encode_privkey(i32* %24, i32 128, i8* %6)
%32 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%33 = icmp ugt i32 %21, 1
br i1 %33, label %20, label %34
34: ; preds = %20, %12
ret i32 0
}