#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*/ const uint8_t;

/* Variables and functions */
char *bbp_base58(int /*<<< orphan*/ const *, size_t);
int /*<<< orphan*/ bbp_hash256(int /*<<< orphan*/ const *,
                               int /*<<< orphan*/ const *, size_t);
int /*<<< orphan*/ const *calloc(size_t, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ const *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ const *,
                          int /*<<< orphan*/ const *, int);
char *bbp_base58check(const uint8_t *bytes, size_t len) {
  size_t check_len;
  uint8_t *check;
  uint8_t digest[32];
  char *str;
  check_len = len + 4;
  check = calloc(check_len, sizeof(char));
  bbp_hash256(digest, bytes, len);
  memcpy(check, bytes, len);
  memcpy(check + len, digest, 4);
  str = bbp_base58(check, check_len);
  free(check);
  return str;
}


x86 assembly (clang, -O0):
<bbp_base58check>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <bbp_hash256@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <bbp_base58@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0xa8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbp_base58check>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x4(%rsi),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
mov    %rsp,%r13
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <bbp_hash256@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
lea    (%r12,%rbx,4),%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <bbp_base58@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @bbp_base58check(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32*
%7 = alloca [32 x i32]
%8 = alloca i8*
store i32* %0, i32** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = add i64 %9, 4
store i64 %10, i64* %5
%11 = load i64, i64* %5
%12 = call i32* @calloc(i64 %11, i32 1)
store i32* %12, i32** %6
%13 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = load i64, i64* %4
%16 = call i32 @bbp_hash256(i32* %13, i32* %14, i64 %15)
%17 = load i32*, i32** %6
%18 = load i32*, i32** %3
%19 = load i64, i64* %4
%20 = trunc i64 %19 to i32
%21 = call i32 @memcpy(i32* %17, i32* %18, i32 %20)
%22 = load i32*, i32** %6
%23 = load i64, i64* %4
%24 = getelementptr inbounds i32, i32* %22, i64 %23
%25 = getelementptr inbounds [32 x i32], [32 x i32]* %7, i64 0, i64 0
%26 = call i32 @memcpy(i32* %24, i32* %25, i32 4)
%27 = load i32*, i32** %6
%28 = load i64, i64* %5
%29 = call i8* @bbp_base58(i32* %27, i64 %28)
store i8* %29, i8** %8
%30 = load i32*, i32** %6
%31 = call i32 @free(i32* %30)
%32 = load i8*, i8** %8
ret i8* %32
}

LLVM IR (-O2):
define i8* @bbp_base58check(i32* %0, i64 %1) {
%3 = alloca [32 x i32]
%4 = bitcast [32 x i32]* %3 to i8*
%5 = add i64 %1, 4
%6 = tail call i32* @calloc(i64 %5, i32 1)
%7 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%8 = call i32 @bbp_hash256(i32* %7, i32* %0, i64 %1)
%9 = trunc i64 %1 to i32
%10 = call i32 @memcpy(i32* %6, i32* %0, i32 %9)
%11 = getelementptr inbounds i32, i32* %6, i64 %1
%12 = call i32 @memcpy(i32* %11, i32* %7, i32 4)
%13 = call i8* @bbp_base58(i32* %6, i64 %5)
%14 = call i32 @free(i32* %6)
ret i8* %13
}