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

/* Variables and functions */
int /*<<< orphan*/ RIPEMD160(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ SHA256(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ i2o_ECPublicKey(int /*<<< orphan*/ *, unsigned char **);
int /*<<< orphan*/ vg_b58_encode_check(unsigned char *, int, char *);
void vg_encode_address(const EC_KEY *pkey, int addrtype, char *result) {
  unsigned char eckey_buf[128], *pend;
  unsigned char binres[21] = {
      0,
  };
  unsigned char hash1[32];
  pend = eckey_buf;
  i2o_ECPublicKey((EC_KEY *)pkey, &pend);
  binres[0] = addrtype;
  SHA256(eckey_buf, pend - eckey_buf, hash1);
  RIPEMD160(hash1, sizeof(hash1), &binres[1]);
  vg_b58_encode_check(binres, sizeof(binres), result);
}


x86 assembly (clang, -O0):
<vg_encode_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1040 <memset@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xa8(%rbp),%rsi
call   1060 <i2o_ECPublicKey@plt>
mov    -0xc(%rbp),%eax
mov    %al,-0xc0(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rax
lea    -0xa0(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
lea    -0xe0(%rbp),%rdx
call   1030 <SHA256@plt>
lea    -0xe0(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
add    $0x1,%rdx
mov    $0x20,%esi
call   1050 <RIPEMD160@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x15,%esi
call   1070 <vg_b58_encode_check@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_encode_address>:
push   %rbp
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x1d(%rsp)
lea    0x50(%rsp),%rbx
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1050 <i2o_ECPublicKey@plt>
mov    %bpl,0x10(%rsp)
mov    0x8(%rsp),%esi
sub    %ebx,%esi
lea    0x30(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1030 <SHA256@plt>
lea    0x11(%rsp),%rdx
mov    %rbp,%rdi
mov    $0x20,%esi
call   1040 <RIPEMD160@plt>
lea    0x10(%rsp),%rdi
mov    $0x15,%esi
mov    %r14,%rdx
call   1060 <vg_b58_encode_check@plt>
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @vg_encode_address(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca i8*
%9 = alloca [21 x i8]
%10 = alloca [32 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = bitcast [21 x i8]* %9 to i8*
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
store i8* %12, i8** %8
%13 = load i32*, i32** %4
%14 = call i32 @i2o_ECPublicKey(i32* %13, i8** %8)
%15 = load i32, i32* %5
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [21 x i8], [21 x i8]* %9, i64 0, i64 0
store i8 %16, i8* %17
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%19 = load i8*, i8** %8
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%26 = call i32 @SHA256(i8* %18, i32 %24, i8* %25)
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%28 = getelementptr inbounds [21 x i8], [21 x i8]* %9, i64 0, i64 1
%29 = call i32 @RIPEMD160(i8* %27, i32 32, i8* %28)
%30 = getelementptr inbounds [21 x i8], [21 x i8]* %9, i64 0, i64 0
%31 = load i8*, i8** %6
%32 = call i32 @vg_b58_encode_check(i8* %30, i32 21, i8* %31)
ret void
}

LLVM IR (-O2):
define void @vg_encode_address(i32* %0, i32 %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = alloca i8*
%6 = alloca [21 x i8]
%7 = alloca [32 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%9 = bitcast i8** %5 to i8*
%10 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
store i8* %8, i8** %5
%12 = call i32 @i2o_ECPublicKey(i32* %0, i8** %5)
%13 = trunc i32 %1 to i8
store i8 %13, i8* %10
%14 = load i8*, i8** %5
%15 = ptrtoint i8* %14 to i64
%16 = ptrtoint [128 x i8]* %4 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i32 @SHA256(i8* %8, i32 %18, i8* %11)
%20 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 1
%21 = call i32 @RIPEMD160(i8* %11, i32 32, i8* %20)
%22 = call i32 @vg_b58_encode_check(i8* %10, i32 21, i8* %2)
ret void
}