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

/* Variables and functions */
int /*<<< orphan*/ cash_decode(char *, int /*<<< orphan*/ *, size_t *,
                               char const *);
int /*<<< orphan*/ convert_bits(int /*<<< orphan*/ *, size_t *, int,
                                int /*<<< orphan*/ *, size_t, int,
                                int /*<<< orphan*/);
scalar_t__ strncmp(char const *, char *, int);
int cash_addr_decode(uint8_t *witdata, size_t *witdata_len, const char *hrp,
                     const char *addr) {
  uint8_t data[104];
  char hrp_actual[20 + 1];
  size_t data_len;
  if (!cash_decode(hrp_actual, data, &data_len, addr))
    return 0;
  if (data_len == 0 || data_len > 104)
    return 0;
  if (strncmp(hrp, hrp_actual, 20 + 1) != 0)
    return 0;
  *witdata_len = 0;
  if (!convert_bits(witdata, witdata_len, 8, data, data_len, 5, 0))
    return 0;
  if (*witdata_len < 2 || *witdata_len > 65)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<cash_addr_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x200,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x1f0(%rbp),%rdi
lea    -0x1d0(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    -0x1f8(%rbp),%rdx
call   1040 <cash_decode@plt>
cmp    $0x0,%eax
jne    117e <cash_addr_decode+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    124f <cash_addr_decode+0x11f>
cmpq   $0x0,-0x1f8(%rbp)
je     119a <cash_addr_decode+0x6a>
cmpq   $0x68,-0x1f8(%rbp)
68
jbe    11a6 <cash_addr_decode+0x76>
movl   $0x0,-0x4(%rbp)
jmp    124f <cash_addr_decode+0x11f>
mov    -0x20(%rbp),%rdi
lea    -0x1f0(%rbp),%rsi
mov    $0x15,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11d1 <cash_addr_decode+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    124f <cash_addr_decode+0x11f>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x1d0(%rbp),%rcx
mov    -0x1f8(%rbp),%r8
mov    $0x8,%edx
mov    $0x5,%r9d
xor    %eax,%eax
movl   $0x0,(%rsp)
call   1050 <convert_bits@plt>
cmp    $0x0,%eax
jne    1220 <cash_addr_decode+0xf0>
movl   $0x0,-0x4(%rbp)
jmp    124f <cash_addr_decode+0x11f>
mov    -0x18(%rbp),%rax
cmpq   $0x2,(%rax)
jb     123c <cash_addr_decode+0x10c>
mov    -0x18(%rbp),%rax
cmpq   $0x41,(%rax)
jbe    1248 <cash_addr_decode+0x118>
movl   $0x0,-0x4(%rbp)
jmp    124f <cash_addr_decode+0x11f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x200,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cash_addr_decode>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1d8,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
lea    0x30(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <cash_decode@plt>
xor    %ebx,%ebx
test   %eax,%eax
je     11c9 <cash_addr_decode+0x99>
mov    0x8(%rsp),%rax
add    $0xffffffffffffff97,%rax
cmp    $0xffffffffffffff98,%rax
jb     11c9 <cash_addr_decode+0x99>
lea    0x10(%rsp),%rsi
mov    %r12,%rdi
mov    $0x15,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c9 <cash_addr_decode+0x99>
movq   $0x0,(%r14)
mov    0x8(%rsp),%r8
movl   $0x0,(%rsp)
lea    0x30(%rsp),%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
mov    $0x5,%r9d
call   1050 <convert_bits@plt>
test   %eax,%eax
je     11c9 <cash_addr_decode+0x99>
mov    (%r14),%rax
add    $0xfffffffffffffffe,%rax
xor    %ebx,%ebx
cmp    $0x40,%rax
setb   %bl
mov    %ebx,%eax
add    $0x1d8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @cash_addr_decode(i32* %0, i64* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [104 x i32]
%11 = alloca [21 x i8]
%12 = alloca i64
store i32* %0, i32** %6
store i64* %1, i64** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%13 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%14 = getelementptr inbounds [104 x i32], [104 x i32]* %10, i64 0, i64 0
%15 = load i8*, i8** %9
%16 = call i32 @cash_decode(i8* %13, i32* %14, i64* %12, i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %4
store i32 0, i32* %5
br label %51
19: ; preds = %4
%20 = load i64, i64* %12
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i64, i64* %12
%24 = icmp ugt i64 %23, 104
br i1 %24, label %25, label %26
25: ; preds = %22, %19
store i32 0, i32* %5
br label %51
26: ; preds = %22
%27 = load i8*, i8** %8
%28 = getelementptr inbounds [21 x i8], [21 x i8]* %11, i64 0, i64 0
%29 = call i64 @strncmp(i8* %27, i8* %28, i32 21)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 0, i32* %5
br label %51
32: ; preds = %26
%33 = load i64*, i64** %7
store i64 0, i64* %33
%34 = load i32*, i32** %6
%35 = load i64*, i64** %7
%36 = getelementptr inbounds [104 x i32], [104 x i32]* %10, i64 0, i64 0
%37 = load i64, i64* %12
%38 = call i32 @convert_bits(i32* %34, i64* %35, i32 8, i32* %36, i64 %37, i32 5, i32 0)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %32
store i32 0, i32* %5
br label %51
41: ; preds = %32
%42 = load i64*, i64** %7
%43 = load i64, i64* %42
%44 = icmp ult i64 %43, 2
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = load i64*, i64** %7
%47 = load i64, i64* %46
%48 = icmp ugt i64 %47, 65
br i1 %48, label %49, label %50
49: ; preds = %45, %41
store i32 0, i32* %5
br label %51
50: ; preds = %45
store i32 1, i32* %5
br label %51
51: ; preds = %50, %49, %40, %31, %25, %18
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
define i32 @cash_addr_decode(i32* %0, i64* %1, i8* %2, i8* %3) {
%5 = alloca [104 x i32]
%6 = alloca [21 x i8]
%7 = alloca i64
%8 = bitcast [104 x i32]* %5 to i8*
%9 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%10 = bitcast i64* %7 to i8*
%11 = getelementptr inbounds [104 x i32], [104 x i32]* %5, i64 0, i64 0
%12 = call i32 @cash_decode(i8* %9, i32* %11, i64* %7, i8* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %4
%15 = load i64, i64* %7
%16 = add i64 %15, -105
%17 = icmp ult i64 %16, -104
br i1 %17, label %30, label %18
18: ; preds = %14
%19 = call i64 @strncmp(i8* %2, i8* %9, i32 21)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %18
store i64 0, i64* %1
%22 = load i64, i64* %7
%23 = call i32 @convert_bits(i32* %0, i64* %1, i32 8, i32* %11, i64 %22, i32 5, i32 0)
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = load i64, i64* %1
%27 = add i64 %26, -2
%28 = icmp ult i64 %27, 64
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %25, %21, %18, %14, %4
%31 = phi i32 [ 0, %4 ], [ 0, %14 ], [ 0, %18 ], [ 0, %21 ], [ %29, %25 ]
ret i32 %31
}