#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 uint8_t;
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int BRBase58CheckDecode(int *, int, char const *);
size_t _BRBCashAddrEncode(char *, char const *, int *, int);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
size_t BRBCashAddrEncode(char *bCashAddr55, const char *bitcoinAddr) {
  uint8_t data[21], ver = 0;
  const char *hrp = NULL;
  assert(bCashAddr55 != NULL);
  assert(bitcoinAddr != NULL);
  if (BRBase58CheckDecode(data, sizeof(data), bitcoinAddr) != 21)
    return 0;
  if (data[0] == 0)
    ver = 0x00, hrp = "bitcoincash";
  if (data[0] == 5)
    ver = 0x08, hrp = "bitcoincash";
  if (data[0] == 111)
    ver = 0x00, hrp = "bchtest";
  if (data[0] == 196)
    ver = 0x08, hrp = "bchtest";
  data[0] = ver;
  return _BRBCashAddrEncode(bCashAddr55, hrp, data, 21);
}


x86 assembly (clang, -O0):
<BRBCashAddrEncode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x74(%rbp)
movq   $0x0,-0x80(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x54,%esi
call   1050 <BRBase58CheckDecode@plt>
cmp    $0x15,%eax
je     119e <BRBCashAddrEncode+0x6e>
movq   $0x0,-0x8(%rbp)
jmp    1231 <BRBCashAddrEncode+0x101>
cmpl   $0x0,-0x70(%rbp)
jne    11ba <BRBCashAddrEncode+0x8a>
movl   $0x0,-0x74(%rbp)
lea    0xe4a(%rip),%rax
mov    %rax,-0x80(%rbp)
cmpl   $0x5,-0x70(%rbp)
jne    11d6 <BRBCashAddrEncode+0xa6>
movl   $0x8,-0x74(%rbp)
lea    0xe2e(%rip),%rax
mov    %rax,-0x80(%rbp)
cmpl   $0x6f,-0x70(%rbp)
jne    11f2 <BRBCashAddrEncode+0xc2>
movl   $0x0,-0x74(%rbp)
lea    0xe1e(%rip),%rax
mov    %rax,-0x80(%rbp)
cmpl   $0xc4,-0x70(%rbp)
jne    1211 <BRBCashAddrEncode+0xe1>
movl   $0x8,-0x74(%rbp)
lea    0xdff(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x80(%rbp),%rsi
lea    -0x70(%rbp),%rdx
mov    $0x15,%ecx
call   1030 <_BRBCashAddrEncode@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BRBCashAddrEncode>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    %rsp,%rdi
mov    $0x54,%esi
mov    %rbx,%rdx
call   1050 <BRBase58CheckDecode@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x15,%ecx
jne    11cd <BRBCashAddrEncode+0x9d>
mov    (%rsp),%ecx
test   %ecx,%ecx
lea    0xe82(%rip),%rdx
mov    $0x0,%esi
cmove  %rdx,%rsi
xor    %edi,%edi
cmp    $0x5,%ecx
sete   %dil
cmove  %rdx,%rsi
shl    $0x3,%edi
cmp    $0x6f,%ecx
cmove  %eax,%edi
lea    0xe68(%rip),%rax
cmove  %rax,%rsi
cmp    $0xc4,%ecx
mov    $0x8,%ecx
cmovne %edi,%ecx
cmove  %rax,%rsi
mov    %ecx,(%rsp)
mov    %rsp,%rdx
mov    %r14,%rdi
mov    $0x15,%ecx
call   1030 <_BRBCashAddrEncode@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"bitcoincash\00"
@.str.1 = [8 x i8] c"bchtest\00"
define i64 @BRBCashAddrEncode(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [21 x i32]
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
store i8* null, i8** %8
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = call i32 @BRBase58CheckDecode(i32* %17, i32 84, i8* %18)
%20 = icmp ne i32 %19, 21
br i1 %20, label %21, label %22
21: ; preds = %2
store i64 0, i64* %3
br label %49
22: ; preds = %2
%23 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %7
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %8
br label %27
27: ; preds = %26, %22
%28 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 5
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 8, i32* %7
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %8
br label %32
32: ; preds = %31, %27
%33 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, 111
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 0, i32* %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %37
37: ; preds = %36, %32
%38 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%39 = load i32, i32* %38
%40 = icmp eq i32 %39, 196
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 8, i32* %7
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %42
42: ; preds = %41, %37
%43 = load i32, i32* %7
%44 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
store i32 %43, i32* %44
%45 = load i8*, i8** %4
%46 = load i8*, i8** %8
%47 = getelementptr inbounds [21 x i32], [21 x i32]* %6, i64 0, i64 0
%48 = call i64 @_BRBCashAddrEncode(i8* %45, i8* %46, i32* %47, i32 21)
store i64 %48, i64* %3
br label %49
49: ; preds = %42, %21
%50 = load i64, i64* %3
ret i64 %50
}

LLVM IR (-O2):
@.str = [12 x i8] c"bitcoincash\00"
@.str.1 = [8 x i8] c"bchtest\00"
define i64 @BRBCashAddrEncode(i8* %0, i8* %1) {
%3 = alloca [21 x i32]
%4 = bitcast [21 x i32]* %3 to i8*
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp ne i8* %1, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = getelementptr inbounds [21 x i32], [21 x i32]* %3, i64 0, i64 0
%12 = call i32 @BRBase58CheckDecode(i32* %11, i32 84, i8* %1)
%13 = icmp eq i32 %12, 21
br i1 %13, label %14, label %28
14: ; preds = %2
%15 = load i32, i32* %11
%16 = icmp eq i32 %15, 0
%17 = icmp eq i32 %15, 5
%18 = select i1 %17, i32 8, i32 0
%19 = or i1 %17, %16
%20 = select i1 %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* null
%21 = icmp eq i32 %15, 111
%22 = select i1 %21, i32 0, i32 %18
%23 = icmp eq i32 %15, 196
%24 = select i1 %23, i32 8, i32 %22
%25 = or i1 %23, %21
%26 = select i1 %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %20
store i32 %24, i32* %11
%27 = call i64 @_BRBCashAddrEncode(i8* %0, i8* %26, i32* %11, i32 21)
br label %28
28: ; preds = %2, %14
%29 = phi i64 [ %27, %14 ], [ 0, %2 ]
ret i64 %29
}