#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_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_UNCOMPRESSED;
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_script_address(const EC_POINT *ppoint, const EC_GROUP *pgroup,
                              int addrtype, char *result) {
  unsigned char script_buf[69];
  unsigned char *eckey_buf = script_buf + 2;
  unsigned char binres[21] = {
      0,
  };
  unsigned char hash1[32];
  script_buf[0] = 0x51;
  script_buf[1] = 0x41;
  script_buf[67] = 0x51;
  script_buf[68] = 0xae;
  EC_POINT_point2oct(pgroup, ppoint, POINT_CONVERSION_UNCOMPRESSED, eckey_buf,
                     65, NULL);
  binres[0] = addrtype;
  SHA256(script_buf, 69, hash1);
  RIPEMD160(hash1, sizeof(hash1), &binres[1]);
  vg_b58_encode_check(binres, sizeof(binres), result);
}


x86 assembly (clang, -O0):
<vg_encode_script_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x70(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x78(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1040 <memset@plt>
movb   $0x51,-0x70(%rbp)
movb   $0x41,-0x6f(%rbp)
movb   $0x51,-0x2d(%rbp)
movb   $0xae,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    -0x78(%rbp),%rcx
mov    $0x41,%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1060 <EC_POINT_point2oct@plt>
mov    -0x14(%rbp),%eax
mov    %al,-0x90(%rbp)
lea    -0x70(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
mov    $0x45,%esi
call   1030 <SHA256@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x90(%rbp),%rdx
add    $0x1,%rdx
mov    $0x20,%esi
call   1050 <RIPEMD160@plt>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x15,%esi
call   1070 <vg_b58_encode_check@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_encode_script_address>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rdi,%rax
lea    0x22(%rsp),%rcx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0xd(%rsp)
movw   $0x4151,0x20(%rsp)
movw   $0xae51,0x63(%rsp)
mov    0x2e65(%rip),%rdx
mov    (%rdx),%edx
mov    %rsi,%rdi
mov    %rax,%rsi
mov    $0x41,%r8d
xor    %r9d,%r9d
call   1050 <EC_POINT_point2oct@plt>
mov    %bpl,(%rsp)
lea    0x20(%rsp),%rdi
lea    0x70(%rsp),%rbp
mov    $0x45,%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    %rbx,%rdx
call   1060 <vg_b58_encode_check@plt>
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
define void @vg_encode_script_address(i32* %0, i32* %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [69 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 = getelementptr inbounds [69 x i8], [69 x i8]* %9, i64 0, i64 0
%14 = getelementptr inbounds i8, i8* %13, i64 2
store i8* %14, i8** %10
%15 = bitcast [21 x i8]* %11 to i8*
%16 = getelementptr inbounds [69 x i8], [69 x i8]* %9, i64 0, i64 0
store i8 81, i8* %16
%17 = getelementptr inbounds [69 x i8], [69 x i8]* %9, i64 0, i64 1
store i8 65, i8* %17
%18 = getelementptr inbounds [69 x i8], [69 x i8]* %9, i64 0, i64 67
store i8 81, i8* %18
%19 = getelementptr inbounds [69 x i8], [69 x i8]* %9, i64 0, i64 68
store i8 -82, i8* %19
%20 = load i32*, i32** %6
%21 = load i32*, i32** %5
%22 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%23 = load i8*, i8** %10
%24 = call i32 @EC_POINT_point2oct(i32* %20, i32* %21, i32 %22, i8* %23, i32 65, i32* null)
%25 = load i32, i32* %7
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
store i8 %26, i8* %27
%28 = getelementptr inbounds [69 x i8], [69 x i8]* %9, i64 0, i64 0
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%30 = call i32 @SHA256(i8* %28, i32 69, i8* %29)
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%32 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 1
%33 = call i32 @RIPEMD160(i8* %31, i32 32, i8* %32)
%34 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%35 = load i8*, i8** %8
%36 = call i32 @vg_b58_encode_check(i8* %34, i32 21, i8* %35)
ret void
}

LLVM IR (-O2):
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
define void @vg_encode_script_address(i32* %0, i32* %1, i32 %2, i8* %3) {
%5 = alloca [69 x i8]
%6 = alloca [21 x i8]
%7 = alloca [32 x i8]
%8 = getelementptr inbounds [69 x i8], [69 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [69 x i8], [69 x i8]* %5, i64 0, i64 2
%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 81, i8* %8
%12 = getelementptr inbounds [69 x i8], [69 x i8]* %5, i64 0, i64 1
store i8 65, i8* %12
%13 = getelementptr inbounds [69 x i8], [69 x i8]* %5, i64 0, i64 67
store i8 81, i8* %13
%14 = getelementptr inbounds [69 x i8], [69 x i8]* %5, i64 0, i64 68
store i8 -82, i8* %14
%15 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%16 = call i32 @EC_POINT_point2oct(i32* %1, i32* %0, i32 %15, i8* %9, i32 65, i32* null)
%17 = trunc i32 %2 to i8
store i8 %17, i8* %10
%18 = call i32 @SHA256(i8* %8, i32 69, i8* %11)
%19 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 1
%20 = call i32 @RIPEMD160(i8* %11, i32 32, i8* %19)
%21 = call i32 @vg_b58_encode_check(i8* %10, i32 21, i8* %3)
ret void
}