#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;

/* Variables and functions */
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_p2sh(unsigned char *redeemscript, int lenght, int addrtype,
                    char *result) {
  unsigned char binres[21] = {
      0,
  };
  unsigned char hash1[32];
  binres[0] = addrtype;
  SHA256(redeemscript, lenght, hash1);
  RIPEMD160(hash1, sizeof(hash1), &binres[1]);
  vg_b58_encode_check(binres, sizeof(binres), result);
}


x86 assembly (clang, -O0):
<vg_encode_p2sh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%eax
mov    %al,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x50(%rbp),%rdx
call   1030 <SHA256@plt>
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rdx
add    $0x1,%rdx
mov    $0x20,%esi
call   1050 <RIPEMD160@plt>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x15,%esi
call   1060 <vg_b58_encode_check@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vg_encode_p2sh>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0xd(%rsp)
mov    %dl,(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,%rdx
call   1030 <SHA256@plt>
lea    0x1(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <RIPEMD160@plt>
mov    %rsp,%rdi
mov    $0x15,%esi
mov    %r14,%rdx
call   1050 <vg_b58_encode_check@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @vg_encode_p2sh(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [21 x i8]
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%9 = trunc i32 %2 to i8
store i8 %9, i8* %7
%10 = call i32 @SHA256(i8* %0, i32 %1, i8* %8)
%11 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 1
%12 = call i32 @RIPEMD160(i8* %8, i32 32, i8* %11)
%13 = call i32 @vg_b58_encode_check(i8* %7, i32 21, i8* %3)
ret void
}