#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 unsigned char uint8_t;
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*/ memcpy(unsigned char **, char *, int);
int /*<<< orphan*/ vg_b58_encode_check(unsigned char *, int, char *);
void vg_encode_multiscript_address(const EC_POINT *ppoint,
                                   const EC_GROUP *pgroup, int addrtype,
                                   int compressed, char *result, int prehashlen,
                                   int nrsignkeys, int nrkeys, char *script) {
  int key_len;
  key_len = compressed ? 33 : 65;
  int loc, len, i;
  unsigned char script_buf[69 + prehashlen];
  unsigned char *eckey_buf = script_buf + prehashlen + 1;
  unsigned char binres[21] = {
      0,
  };
  unsigned char hash1[32];
  memcpy(&script_buf, script, prehashlen);
  script_buf[0] = (uint8_t)nrsignkeys + 0x50;
  script_buf[prehashlen] = key_len;
  script_buf[prehashlen + key_len + 1] = (uint8_t)nrkeys + 0x50 + 1;
  script_buf[prehashlen + key_len + 2] = 0xae;
  EC_POINT_point2oct(pgroup, ppoint,
                     compressed ? POINT_CONVERSION_COMPRESSED
                                : POINT_CONVERSION_UNCOMPRESSED,
                     eckey_buf, key_len, NULL);
  binres[0] = addrtype;
  SHA256(script_buf, prehashlen + key_len + 3, hash1);
  RIPEMD160(hash1, sizeof(hash1), &binres[1]);
  vg_b58_encode_check(binres, sizeof(binres), result);
}


x86 assembly (clang, -O0):
<vg_encode_multiscript_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x18(%rbp),%eax
test   %eax,%eax
sete   %al
movzbl %al,%eax
shl    $0x5,%eax
add    $0x21,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x45,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x40(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0xa8(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x48(%rbp)
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1040 <memset@plt>
mov    -0xa8(%rbp),%rdi
mov    0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0xa8(%rbp),%rax
mov    0x10(%rbp),%ecx
movzbl %cl,%ecx
add    $0x50,%ecx
mov    %cl,(%rax)
mov    -0x28(%rbp),%ecx
mov    %cl,%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x18(%rbp),%ecx
movzbl %cl,%ecx
add    $0x50,%ecx
add    $0x1,%ecx
mov    %cl,%dl
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0xae,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x98(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     127e <vg_encode_multiscript_address+0x11e>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
jmp    128d <vg_encode_multiscript_address+0x12d>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x98(%rbp),%rsi
mov    -0xa0(%rbp),%rdi
mov    -0xac(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    -0x28(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%r9d
call   1070 <EC_POINT_point2oct@plt>
mov    -0xa8(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    %al,-0x70(%rbp)
mov    -0x24(%rbp),%esi
add    -0x28(%rbp),%esi
add    $0x3,%esi
lea    -0x90(%rbp),%rdx
call   1030 <SHA256@plt>
lea    -0x90(%rbp),%rdi
lea    -0x70(%rbp),%rdx
add    $0x1,%rdx
mov    $0x20,%esi
call   1060 <RIPEMD160@plt>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x15,%esi
call   1080 <vg_b58_encode_check@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_encode_multiscript_address>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r8,-0x58(%rbp)
mov    %edx,-0x30(%rbp)
mov    %rsi,-0x48(%rbp)
mov    %rdi,-0x50(%rbp)
mov    0x20(%rbp),%rsi
xor    %r13d,%r13d
test   %ecx,%ecx
sete   %r13b
jne    1188 <vg_encode_multiscript_address+0x38>
mov    0x2e52(%rip),%rax
jmp    118f <vg_encode_multiscript_address+0x3f>
mov    0x2e59(%rip),%rax
mov    %rax,-0x38(%rbp)
shl    $0x5,%r13d
lea    0x21(%r13),%eax
mov    %eax,-0x2c(%rbp)
lea    0x45(%r9),%r12d
mov    %rsp,%rbx
add    $0xf,%r12
and    $0xfffffffffffffff0,%r12
mov    %rbx,%r14
sub    %r12,%r14
mov    %r14,%rsp
movslq %r9d,%r15
lea    (%r14,%r15,1),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x70(%rbp)
movq   $0x0,-0x63(%rbp)
neg    %r12
mov    %r14,%rdi
mov    %r15d,%edx
call   1040 <memcpy@plt>
mov    0x10(%rbp),%al
add    $0x50,%al
mov    %al,(%rbx,%r12,1)
mov    -0x2c(%rbp),%r8d
mov    %r8b,(%r15,%r14,1)
mov    0x18(%rbp),%cl
add    $0x51,%cl
lea    (%r15,%r13,1),%eax
add    $0x21,%eax
cltq
mov    %cl,0x1(%rax,%r14,1)
movb   $0xae,0x2(%rax,%r14,1)
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x40(%rbp),%rcx
xor    %r9d,%r9d
call   1060 <EC_POINT_point2oct@plt>
mov    -0x30(%rbp),%eax
mov    %al,-0x70(%rbp)
lea    (%r15,%r13,1),%esi
add    $0x24,%esi
lea    -0x90(%rbp),%rbx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1030 <SHA256@plt>
lea    -0x6f(%rbp),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1050 <RIPEMD160@plt>
lea    -0x70(%rbp),%rdi
mov    $0x15,%esi
mov    -0x58(%rbp),%rdx
call   1070 <vg_b58_encode_check@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
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_multiscript_address(i32* %0, i32* %1, i32 %2, i32 %3, i8* %4, i32 %5, i32 %6, i32 %7, i8* %8) {
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8*
%24 = alloca i64
%25 = alloca i8*
%26 = alloca [21 x i8]
%27 = alloca [32 x i8]
store i32* %0, i32** %10
store i32* %1, i32** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i8* %4, i8** %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i8* %8, i8** %18
%28 = load i32, i32* %13
%29 = icmp ne i32 %28, 0
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 33, i32 65
store i32 %31, i32* %19
%32 = load i32, i32* %15
%33 = add nsw i32 69, %32
%34 = zext i32 %33 to i64
%35 = call i8* @llvm.stacksave()
store i8* %35, i8** %23
%36 = alloca i8, i64 %34
store i64 %34, i64* %24
%37 = load i32, i32* %15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** %25
%41 = bitcast [21 x i8]* %26 to i8*
%42 = bitcast i8* %36 to i8**
%43 = load i8*, i8** %18
%44 = load i32, i32* %15
%45 = call i32 @memcpy(i8** %42, i8* %43, i32 %44)
%46 = load i32, i32* %16
%47 = trunc i32 %46 to i8
%48 = zext i8 %47 to i32
%49 = add nsw i32 %48, 80
%50 = trunc i32 %49 to i8
%51 = getelementptr inbounds i8, i8* %36, i64 0
store i8 %50, i8* %51
%52 = load i32, i32* %19
%53 = trunc i32 %52 to i8
%54 = load i32, i32* %15
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %36, i64 %55
store i8 %53, i8* %56
%57 = load i32, i32* %17
%58 = trunc i32 %57 to i8
%59 = zext i8 %58 to i32
%60 = add nsw i32 %59, 80
%61 = add nsw i32 %60, 1
%62 = trunc i32 %61 to i8
%63 = load i32, i32* %15
%64 = load i32, i32* %19
%65 = add nsw i32 %63, %64
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %36, i64 %67
store i8 %62, i8* %68
%69 = load i32, i32* %15
%70 = load i32, i32* %19
%71 = add nsw i32 %69, %70
%72 = add nsw i32 %71, 2
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %36, i64 %73
store i8 -82, i8* %74
%75 = load i32*, i32** %11
%76 = load i32*, i32** %10
%77 = load i32, i32* %13
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %9
%80 = load i32, i32* @POINT_CONVERSION_COMPRESSED
br label %83
81: ; preds = %9
%82 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
br label %83
83: ; preds = %81, %79
%84 = phi i32 [ %80, %79 ], [ %82, %81 ]
%85 = load i8*, i8** %25
%86 = load i32, i32* %19
%87 = call i32 @EC_POINT_point2oct(i32* %75, i32* %76, i32 %84, i8* %85, i32 %86, i32* null)
%88 = load i32, i32* %12
%89 = trunc i32 %88 to i8
%90 = getelementptr inbounds [21 x i8], [21 x i8]* %26, i64 0, i64 0
store i8 %89, i8* %90
%91 = load i32, i32* %15
%92 = load i32, i32* %19
%93 = add nsw i32 %91, %92
%94 = add nsw i32 %93, 3
%95 = getelementptr inbounds [32 x i8], [32 x i8]* %27, i64 0, i64 0
%96 = call i32 @SHA256(i8* %36, i32 %94, i8* %95)
%97 = getelementptr inbounds [32 x i8], [32 x i8]* %27, i64 0, i64 0
%98 = getelementptr inbounds [21 x i8], [21 x i8]* %26, i64 0, i64 1
%99 = call i32 @RIPEMD160(i8* %97, i32 32, i8* %98)
%100 = getelementptr inbounds [21 x i8], [21 x i8]* %26, i64 0, i64 0
%101 = load i8*, i8** %14
%102 = call i32 @vg_b58_encode_check(i8* %100, i32 21, i8* %101)
%103 = load i8*, i8** %23
ret void
}

LLVM IR (-O2):
@POINT_CONVERSION_COMPRESSED = global i32 0
@POINT_CONVERSION_UNCOMPRESSED = global i32 0
define void @vg_encode_multiscript_address(i32* %0, i32* %1, i32 %2, i32 %3, i8* %4, i32 %5, i32 %6, i32 %7, i8* %8) {
%10 = alloca [21 x i8]
%11 = alloca [32 x i8]
%12 = icmp eq i32 %3, 0
%13 = select i1 %12, i32 65, i32 33
%14 = add nsw i32 %5, 69
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
%17 = sext i32 %5 to i64
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 0
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%22 = bitcast i8* %16 to i8**
%23 = call i32 @memcpy(i8** %22, i8* %8, i32 %5)
%24 = trunc i32 %6 to i8
%25 = add i8 %24, 80
store i8 %25, i8* %16
%26 = trunc i32 %13 to i8
store i8 %26, i8* %18
%27 = trunc i32 %7 to i8
%28 = add i8 %27, 81
%29 = add nsw i32 %13, %5
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %16, i64 %31
store i8 %28, i8* %32
%33 = add nsw i32 %29, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %16, i64 %34
store i8 -82, i8* %35
%36 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%37 = load i32, i32* @POINT_CONVERSION_UNCOMPRESSED
%38 = select i1 %12, i32 %37, i32 %36
%39 = call i32 @EC_POINT_point2oct(i32* %1, i32* %0, i32 %38, i8* %19, i32 %13, i32* null)
%40 = trunc i32 %2 to i8
store i8 %40, i8* %20
%41 = add nsw i32 %29, 3
%42 = call i32 @SHA256(i8* %16, i32 %41, i8* %21)
%43 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 1
%44 = call i32 @RIPEMD160(i8* %21, i32 32, i8* %43)
%45 = call i32 @vg_b58_encode_check(i8* %20, i32 21, i8* %4)
ret void
}