#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*/ eckey_buf;
typedef int /*<<< orphan*/ binres;
typedef int /*<<< orphan*/ EC_POINT;
typedef int /*<<< orphan*/ EC_GROUP;

/* Variables and functions */
int /*<<< orphan*/ EC_POINT_point2oct(int /*<<< orphan*/ const *,
                                      int /*<<< orphan*/ const *,
                                      int /*<<< orphan*/, unsigned char *, int,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ POINT_CONVERSION_COMPRESSED;
int /*<<< orphan*/ RIPEMD160(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ SHA256(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ vg_b58_encode_check(unsigned char *, int, char *);
void vg_encode_address_compressed(const EC_POINT *ppoint,
                                  const EC_GROUP *pgroup, int addrtype,
                                  char *result) {
  unsigned char eckey_buf[128], *pend;
  unsigned char binres[21] = {
      0,
  };
  unsigned char hash1[32];
  pend = eckey_buf;
  EC_POINT_point2oct(pgroup, ppoint, POINT_CONVERSION_COMPRESSED, eckey_buf,
                     sizeof(eckey_buf), NULL);
  pend = eckey_buf + 0x21;
  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_compressed>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1040 <memset@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
lea    -0xa0(%rbp),%rcx
mov    $0x80,%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1060 <EC_POINT_point2oct@plt>
lea    -0xa0(%rbp),%rax
add    $0x21,%rax
mov    %rax,-0xa8(%rbp)
mov    -0x14(%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    -0x20(%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_compressed>:
push   %rbp
push   %r14
push   %rbx
sub    $0xc0,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rdi,%rax
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0xd(%rsp)
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%edx
lea    0x40(%rsp),%rbx
mov    %rsi,%rdi
mov    %rax,%rsi
mov    %rbx,%rcx
mov    $0x80,%r8d
xor    %r9d,%r9d
call   1050 <EC_POINT_point2oct@plt>
mov    %bpl,(%rsp)
lea    0x20(%rsp),%rbp
mov    %rbx,%rdi
mov    $0x21,%esi
mov    %rbp,%rdx
call   1030 <SHA256@plt>
lea    0x1(%rsp),%rdx
mov    %rbp,%rdi
mov    $0x20,%esi
call   1040 <RIPEMD160@plt>
mov    %rsp,%rdi
mov    $0x15,%esi
mov    %r14,%rdx
call   1060 <vg_b58_encode_check@plt>
add    $0xc0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@POINT_CONVERSION_COMPRESSED = global i32 0
define void @vg_encode_address_compressed(i32* %0, i32* %1, i32 %2, i8* %3) {
%5 = alloca [128 x i8]
%6 = alloca [21 x i8]
%7 = alloca [32 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%12 = call i32 @EC_POINT_point2oct(i32* %1, i32* %0, i32 %11, i8* %8, i32 128, i32* null)
%13 = trunc i32 %2 to i8
store i8 %13, i8* %9
%14 = call i32 @SHA256(i8* %8, i32 33, i8* %10)
%15 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 1
%16 = call i32 @RIPEMD160(i8* %10, i32 32, i8* %15)
%17 = call i32 @vg_b58_encode_check(i8* %9, i32 21, i8* %3)
ret void
}