#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_COMPRESSED;
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, int compressed, char *result) {
  int key_len;
  key_len = compressed ? 33 : 65;
  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] = key_len;
  script_buf[key_len + 2] = 0x51;
  script_buf[key_len + 3] = 0xae;
  EC_POINT_point2oct(pgroup, ppoint,
                     compressed ? POINT_CONVERSION_COMPRESSED
                                : POINT_CONVERSION_UNCOMPRESSED,
                     eckey_buf, key_len, NULL);
  binres[0] = addrtype;
  SHA256(script_buf, key_len + 4, 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    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x41,%eax
mov    $0x21,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x24(%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)
mov    -0x24(%rbp),%eax
mov    %al,-0x6f(%rbp)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x51,-0x70(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x3,%eax
cltq
movb   $0xae,-0x70(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xb8(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11fa <vg_encode_script_address+0xaa>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
jmp    1209 <vg_encode_script_address+0xb9>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xb8(%rbp),%rsi
mov    -0xc0(%rbp),%rdi
mov    -0xc4(%rbp),%edx
mov    -0x78(%rbp),%rcx
mov    -0x24(%rbp),%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
mov    -0x24(%rbp),%esi
add    $0x4,%esi
lea    -0xb0(%rbp),%rdx
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    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_encode_script_address>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %r8,%r14
mov    %edx,%r15d
mov    %rsi,%rax
mov    %rdi,%rsi
xor    %ebx,%ebx
test   %ecx,%ecx
sete   %bl
jne    116d <vg_encode_script_address+0x2d>
mov    0x2e6d(%rip),%rdx
jmp    1174 <vg_encode_script_address+0x34>
mov    0x2e74(%rip),%rdx
shl    $0x5,%ebx
lea    0x21(%rbx),%r8d
lea    0x22(%rsp),%rcx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0xd(%rsp)
movb   $0x51,0x20(%rsp)
mov    %r8b,0x21(%rsp)
lea    0x20(%rsp),%r12
movw   $0xae51,0x2(%r8,%r12,1)
ae
mov    (%rdx),%edx
mov    %rax,%rdi
xor    %r9d,%r9d
call   1050 <EC_POINT_point2oct@plt>
mov    %r15b,(%rsp)
add    $0x25,%ebx
lea    0x70(%rsp),%rbp
mov    %r12,%rdi
mov    %ebx,%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    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@POINT_CONVERSION_COMPRESSED = global i32 0
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
define void @vg_encode_script_address(i32* %0, i32* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [69 x i8]
%13 = alloca i8*
%14 = alloca [21 x i8]
%15 = alloca [32 x i8]
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%16 = load i32, i32* %9
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 33, i32 65
store i32 %19, i32* %11
%20 = getelementptr inbounds [69 x i8], [69 x i8]* %12, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 2
store i8* %21, i8** %13
%22 = bitcast [21 x i8]* %14 to i8*
%23 = getelementptr inbounds [69 x i8], [69 x i8]* %12, i64 0, i64 0
store i8 81, i8* %23
%24 = load i32, i32* %11
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [69 x i8], [69 x i8]* %12, i64 0, i64 1
store i8 %25, i8* %26
%27 = load i32, i32* %11
%28 = add nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [69 x i8], [69 x i8]* %12, i64 0, i64 %29
store i8 81, i8* %30
%31 = load i32, i32* %11
%32 = add nsw i32 %31, 3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [69 x i8], [69 x i8]* %12, i64 0, i64 %33
store i8 -82, i8* %34
%35 = load i32*, i32** %7
%36 = load i32*, i32** %6
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %5
%40 = load i32, i32* @POINT_CONVERSION_COMPRESSED
br label %43
41: ; preds = %5
%42 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
br label %43
43: ; preds = %41, %39
%44 = phi i32 [ %40, %39 ], [ %42, %41 ]
%45 = load i8*, i8** %13
%46 = load i32, i32* %11
%47 = call i32 @EC_POINT_point2oct(i32* %35, i32* %36, i32 %44, i8* %45, i32 %46, i32* null)
%48 = load i32, i32* %8
%49 = trunc i32 %48 to i8
%50 = getelementptr inbounds [21 x i8], [21 x i8]* %14, i64 0, i64 0
store i8 %49, i8* %50
%51 = getelementptr inbounds [69 x i8], [69 x i8]* %12, i64 0, i64 0
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 4
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%55 = call i32 @SHA256(i8* %51, i32 %53, i8* %54)
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %15, i64 0, i64 0
%57 = getelementptr inbounds [21 x i8], [21 x i8]* %14, i64 0, i64 1
%58 = call i32 @RIPEMD160(i8* %56, i32 32, i8* %57)
%59 = getelementptr inbounds [21 x i8], [21 x i8]* %14, i64 0, i64 0
%60 = load i8*, i8** %10
%61 = call i32 @vg_b58_encode_check(i8* %59, i32 21, i8* %60)
ret void
}

LLVM IR (-O2):
@POINT_CONVERSION_COMPRESSED = global i32 0
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
define void @vg_encode_script_address(i32* %0, i32* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca [69 x i8]
%7 = alloca [21 x i8]
%8 = alloca [32 x i8]
%9 = icmp eq i32 %3, 0
%10 = select i1 %9, i32 65, i32 33
%11 = getelementptr inbounds [69 x i8], [69 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [69 x i8], [69 x i8]* %6, i64 0, i64 2
%13 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
store i8 81, i8* %11
%15 = trunc i32 %10 to i8
%16 = getelementptr inbounds [69 x i8], [69 x i8]* %6, i64 0, i64 1
store i8 %15, i8* %16
%17 = or i32 %10, 2
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [69 x i8], [69 x i8]* %6, i64 0, i64 %18
store i8 81, i8* %19
%20 = add nuw nsw i32 %10, 3
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [69 x i8], [69 x i8]* %6, i64 0, i64 %21
store i8 -82, i8* %22
%23 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%24 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%25 = select i1 %9, i32 %24, i32 %23
%26 = call i32 @EC_POINT_point2oct(i32* %1, i32* %0, i32 %25, i8* %12, i32 %10, i32* null)
%27 = trunc i32 %2 to i8
store i8 %27, i8* %13
%28 = or i32 %10, 4
%29 = call i32 @SHA256(i8* %11, i32 %28, i8* %14)
%30 = getelementptr inbounds [21 x i8], [21 x i8]* %7, i64 0, i64 1
%31 = call i32 @RIPEMD160(i8* %14, i32 32, i8* %30)
%32 = call i32 @vg_b58_encode_check(i8* %13, i32 21, i8* %4)
ret void
}