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

/* Variables and functions */
int EINVAL;
int strlen(char const *);
int base58_check(char *data, int len) {
  const char base58[] =
      "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
  int base58_len = strlen(base58);
  int i, j;
  for (i = 0; i < len; i++) {
    for (j = 0; j < base58_len; j++) {
      if (data[i] == base58[j])
        break;
    }
    if (j == base58_len)
      return -EINVAL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<base58_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x3b,%edx
call   1040 <memcpy@plt>
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11dd <base58_check+0xbd>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    11ab <base58_check+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movslq -0x5c(%rbp),%rcx
movsbl -0x50(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    1198 <base58_check+0x78>
jmp    11ab <base58_check+0x8b>
jmp    119d <base58_check+0x7d>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    116a <base58_check+0x4a>
mov    -0x5c(%rbp),%eax
cmp    -0x54(%rbp),%eax
jne    11ca <base58_check+0xaa>
xor    %eax,%eax
mov    0x2e20(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e4 <base58_check+0xc4>
jmp    11cf <base58_check+0xaf>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1157 <base58_check+0x37>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base58_check>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
movups 0xf07(%rip),%xmm0
movups %xmm0,0x2b(%rsp)
movaps 0xef0(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
call   1030 <strlen@plt>
test   %ebp,%ebp
jle    118d <base58_check+0x7d>
mov    %ebp,%ecx
mov    %eax,%edx
xor    %esi,%esi
mov    $0x0,%edi
test   %eax,%eax
jle    1180 <base58_check+0x70>
mov    (%r14,%rsi,1),%bl
xor    %edi,%edi
nopl   (%rax)
cmp    (%rsp,%rdi,1),%bl
je     1180 <base58_check+0x70>
add    $0x1,%rdi
cmp    %rdi,%rdx
jne    1170 <base58_check+0x60>
jmp    1191 <base58_check+0x81>
cmp    %eax,%edi
je     1191 <base58_check+0x81>
add    $0x1,%rsi
cmp    %rcx,%rsi
jne    115e <base58_check+0x4e>
xor    %eax,%eax
jmp    119c <base58_check+0x8c>
mov    0x2e48(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.base58_check.base58 = [59 x i8] c"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\00"
@EINVAL = global i32 0
define i32 @base58_check(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [59 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = bitcast [59 x i8]* %6 to i8*
%11 = getelementptr inbounds [59 x i8], [59 x i8]* %6, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
store i32 0, i32* %8
br label %13
13: ; preds = %48, %2
%14 = load i32, i32* %8
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %51
17: ; preds = %13
store i32 0, i32* %9
br label %18
18: ; preds = %37, %17
%19 = load i32, i32* %9
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %40
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [59 x i8], [59 x i8]* %6, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %28, %33
br i1 %34, label %35, label %36
35: ; preds = %22
br label %40
36: ; preds = %22
br label %37
37: ; preds = %36
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %18
40: ; preds = %35, %18
%41 = load i32, i32* %9
%42 = load i32, i32* %7
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i32, i32* @EINVAL
%46 = sub nsw i32 0, %45
store i32 %46, i32* %3
br label %52
47: ; preds = %40
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %13
51: ; preds = %13
store i32 0, i32* %3
br label %52
52: ; preds = %51, %44
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@__const.base58_check.base58 = [59 x i8] c"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\00"
@EINVAL = global i32 0
define i32 @base58_check(i8* nocapture %0, i32 %1) {
%3 = alloca [59 x i8]
%4 = getelementptr inbounds [59 x i8], [59 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %35
7: ; preds = %2
%8 = icmp sgt i32 %5, 0
%9 = zext i32 %1 to i64
%10 = zext i32 %5 to i64
br label %13
11: ; preds = %28
%12 = icmp eq i64 %31, %9
br i1 %12, label %35, label %13
13: ; preds = %7, %11
%14 = phi i64 [ 0, %7 ], [ %31, %11 ]
br i1 %8, label %15, label %28
15: ; preds = %13
%16 = getelementptr inbounds i8, i8* %0, i64 %14
%17 = load i8, i8* %16
br label %18
18: ; preds = %15, %23
%19 = phi i64 [ 0, %15 ], [ %24, %23 ]
%20 = getelementptr inbounds [59 x i8], [59 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %17, %21
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = add nuw nsw i64 %19, 1
%25 = icmp eq i64 %24, %10
br i1 %25, label %32, label %18
26: ; preds = %18
%27 = trunc i64 %19 to i32
br label %28
28: ; preds = %26, %13
%29 = phi i32 [ 0, %13 ], [ %27, %26 ]
%30 = icmp eq i32 %29, %5
%31 = add nuw nsw i64 %14, 1
br i1 %30, label %32, label %11
32: ; preds = %28, %23
%33 = load i32, i32* @EINVAL
%34 = sub nsw i32 0, %33
br label %35
35: ; preds = %11, %2, %32
%36 = phi i32 [ %34, %32 ], [ 0, %2 ], [ 0, %11 ]
ret i32 %36
}