#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 decode_chunk(char *, char *, int);
int B32_decode(char *source, char *destination, int size_source,
               int size_destination) {
  int chunks, reminder, size_reminder, i;
  if (size_destination < (((size_source * 5) / 8) + 5)) {
    return -1;
  }
  chunks = size_source / 8;
  reminder = size_source % 8;
  for (i = 0; i < chunks; i++) {
    if (decode_chunk(source + (i * 8), destination + (i * 5), 8) != 5) {
      return -1;
    }
  }
  if (reminder > 0) {
    size_reminder = decode_chunk(source + (chunks * 8),
                                 destination + (chunks * 5), reminder);
    if (size_reminder < 0)
      return -1;
  } else {
    size_reminder = 0;
  }
  return (int)((chunks * 5) + size_reminder);
}


x86 assembly (clang, -O0):
<B32_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
imul   $0x5,-0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    $0x5,%ecx
cmp    %ecx,%eax
jge    1154 <B32_decode+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <B32_decode+0x11e>
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d1 <B32_decode+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
imul   $0x5,-0x30(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x8,%edx
call   1030 <decode_chunk@plt>
cmp    $0x5,%eax
je     11be <B32_decode+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <B32_decode+0x11e>
jmp    11c3 <B32_decode+0xb3>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1177 <B32_decode+0x67>
cmpl   $0x0,-0x28(%rbp)
jle    121d <B32_decode+0x10d>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
imul   $0x5,-0x24(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x28(%rbp),%edx
call   1030 <decode_chunk@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1218 <B32_decode+0x108>
movl   $0xffffffff,-0x4(%rbp)
jmp    122e <B32_decode+0x11e>
jmp    1224 <B32_decode+0x114>
movl   $0x0,-0x2c(%rbp)
imul   $0x5,-0x24(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<B32_decode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r13d
lea    0x0(%r13,%r13,4),%eax
lea    0x7(%r13,%r13,4),%edx
test   %eax,%eax
cmovns %eax,%edx
sar    $0x3,%edx
add    $0x5,%edx
mov    $0xffffffff,%ebx
cmp    %ecx,%edx
jg     11f4 <B32_decode+0xe4>
mov    %rdi,0x8(%rsp)
mov    %rsi,0x10(%rsp)
lea    0x7(%r13),%r15d
test   %r13d,%r13d
cmovns %r13d,%r15d
mov    %r15d,%r14d
sar    $0x3,%r14d
cmp    $0x8,%r13d
jl     11a3 <B32_decode+0x93>
mov    %r14d,%r12d
mov    0x8(%rsp),%rbp
mov    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <decode_chunk@plt>
cmp    $0x5,%eax
jne    11e3 <B32_decode+0xd3>
add    $0x5,%rbx
add    $0x8,%rbp
add    $0xffffffffffffffff,%r12
jne    1180 <B32_decode+0x70>
and    $0xfffffff8,%r15d
sub    %r15d,%r13d
test   %r13d,%r13d
jle    11ea <B32_decode+0xda>
lea    0x0(,%r14,8),%eax
cltq
mov    0x8(%rsp),%rdi
add    %rax,%rdi
lea    (%r14,%r14,4),%ebp
movslq %ebp,%rax
mov    0x10(%rsp),%rsi
add    %rax,%rsi
mov    %r13d,%edx
call   1030 <decode_chunk@plt>
test   %eax,%eax
mov    $0xffffffff,%ebx
jns    11f0 <B32_decode+0xe0>
jmp    11f4 <B32_decode+0xe4>
mov    $0xffffffff,%ebx
jmp    11f4 <B32_decode+0xe4>
lea    (%r14,%r14,4),%ebp
xor    %eax,%eax
add    %eax,%ebp
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @B32_decode(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%14 = load i32, i32* %9
%15 = load i32, i32* %8
%16 = mul nsw i32 %15, 5
%17 = sdiv i32 %16, 8
%18 = add nsw i32 %17, 5
%19 = icmp slt i32 %14, %18
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 -1, i32* %5
br label %74
21: ; preds = %4
%22 = load i32, i32* %8
%23 = sdiv i32 %22, 8
store i32 %23, i32* %10
%24 = load i32, i32* %8
%25 = srem i32 %24, 8
store i32 %25, i32* %11
store i32 0, i32* %13
br label %26
26: ; preds = %45, %21
%27 = load i32, i32* %13
%28 = load i32, i32* %10
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %48
30: ; preds = %26
%31 = load i8*, i8** %6
%32 = load i32, i32* %13
%33 = mul nsw i32 %32, 8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8*, i8** %7
%37 = load i32, i32* %13
%38 = mul nsw i32 %37, 5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = call i32 @decode_chunk(i8* %35, i8* %40, i32 8)
%42 = icmp ne i32 %41, 5
br i1 %42, label %43, label %44
43: ; preds = %30
store i32 -1, i32* %5
br label %74
44: ; preds = %30
br label %45
45: ; preds = %44
%46 = load i32, i32* %13
%47 = add nsw i32 %46, 1
store i32 %47, i32* %13
br label %26
48: ; preds = %26
%49 = load i32, i32* %11
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %68
51: ; preds = %48
%52 = load i8*, i8** %6
%53 = load i32, i32* %10
%54 = mul nsw i32 %53, 8
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = load i8*, i8** %7
%58 = load i32, i32* %10
%59 = mul nsw i32 %58, 5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i32, i32* %11
%63 = call i32 @decode_chunk(i8* %56, i8* %61, i32 %62)
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %51
store i32 -1, i32* %5
br label %74
67: ; preds = %51
br label %69
68: ; preds = %48
store i32 0, i32* %12
br label %69
69: ; preds = %68, %67
%70 = load i32, i32* %10
%71 = mul nsw i32 %70, 5
%72 = load i32, i32* %12
%73 = add nsw i32 %71, %72
store i32 %73, i32* %5
br label %74
74: ; preds = %69, %66, %43, %20
%75 = load i32, i32* %5
ret i32 %75
}

LLVM IR (-O2):
define i32 @B32_decode(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = mul nsw i32 %2, 5
%6 = sdiv i32 %5, 8
%7 = add nsw i32 %6, 5
%8 = icmp sgt i32 %7, %3
br i1 %8, label %43, label %9
9: ; preds = %4
%10 = sdiv i32 %2, 8
%11 = srem i32 %2, 8
%12 = icmp sgt i32 %2, 7
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = zext i32 %10 to i64
br label %17
15: ; preds = %17
%16 = icmp eq i64 %25, %14
br i1 %16, label %26, label %17
17: ; preds = %13, %15
%18 = phi i64 [ 0, %13 ], [ %25, %15 ]
%19 = shl nsw i64 %18, 3
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = mul nuw nsw i64 %18, 5
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = tail call i32 @decode_chunk(i8* %20, i8* %22, i32 8)
%24 = icmp eq i32 %23, 5
%25 = add nuw nsw i64 %18, 1
br i1 %24, label %15, label %43
26: ; preds = %15, %9
%27 = icmp sgt i32 %11, 0
br i1 %27, label %30, label %28
28: ; preds = %26
%29 = mul nsw i32 %10, 5
br label %39
30: ; preds = %26
%31 = shl nsw i32 %10, 3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = mul nsw i32 %10, 5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %1, i64 %35
%37 = tail call i32 @decode_chunk(i8* %33, i8* %36, i32 %11)
%38 = icmp slt i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %28, %30
%40 = phi i32 [ %29, %28 ], [ %34, %30 ]
%41 = phi i32 [ 0, %28 ], [ %37, %30 ]
%42 = add nsw i32 %41, %40
br label %43
43: ; preds = %17, %30, %4, %39
%44 = phi i32 [ %42, %39 ], [ -1, %4 ], [ -1, %30 ], [ -1, %17 ]
ret i32 %44
}