#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 char uint8_t;

/* Variables and functions */
int unmap(char const);
size_t decode_chunk(const uint8_t in[4], uint8_t out[3]) {
  out[0] = (uint8_t)(((unmap(in[0]) << 2)) | unmap(in[1]) >> 4);
  out[1] = (uint8_t)(((unmap(in[1]) << 4) & 0xF0) | unmap(in[2]) >> 2);
  out[2] = (uint8_t)(((unmap(in[2]) << 6) & 0xC0) | unmap(in[3]));
  return 1 + (in[2] != '=') + ((in[2] != '=') && (in[3] != '='));
}


x86 assembly (clang, -O0):
<decode_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <unmap@plt>
shl    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <unmap@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
sar    $0x4,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <unmap@plt>
shl    $0x4,%eax
and    $0xf0,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <unmap@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
sar    $0x2,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <unmap@plt>
shl    $0x6,%eax
and    $0xc0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <unmap@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x3d,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%ecx
xor    %eax,%eax
cmp    $0x3d,%ecx
mov    %al,-0x11(%rbp)
je     11fe <decode_chunk+0xee>
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x3d,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x11(%rbp),%cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
cltq
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_chunk>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <unmap@plt>
mov    %eax,%ebp
shl    $0x2,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <unmap@plt>
shr    $0x4,%eax
or     %ebp,%eax
mov    %al,(%r14)
movsbl 0x1(%rbx),%edi
call   1030 <unmap@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x2(%rbx),%edi
call   1030 <unmap@plt>
shr    $0x2,%eax
or     %ebp,%eax
mov    %al,0x1(%r14)
movsbl 0x2(%rbx),%edi
call   1030 <unmap@plt>
mov    %eax,%ebp
shl    $0x6,%ebp
movsbl 0x3(%rbx),%edi
call   1030 <unmap@plt>
or     %ebp,%eax
mov    %al,0x2(%r14)
mov    $0x1,%eax
cmpb   $0x3d,0x2(%rbx)
je     118d <decode_chunk+0x7d>
xor    %eax,%eax
cmpb   $0x3d,0x3(%rbx)
sete   %al
xor    $0x3,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @decode_chunk(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = tail call i32 @unmap(i8 signext %3)
%5 = shl i32 %4, 2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call i32 @unmap(i8 signext %7)
%9 = lshr i32 %8, 4
%10 = or i32 %9, %5
%11 = trunc i32 %10 to i8
store i8 %11, i8* %1
%12 = load i8, i8* %6
%13 = tail call i32 @unmap(i8 signext %12)
%14 = shl i32 %13, 4
%15 = getelementptr inbounds i8, i8* %0, i64 2
%16 = load i8, i8* %15
%17 = tail call i32 @unmap(i8 signext %16)
%18 = lshr i32 %17, 2
%19 = or i32 %18, %14
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %20, i8* %21
%22 = load i8, i8* %15
%23 = tail call i32 @unmap(i8 signext %22)
%24 = shl i32 %23, 6
%25 = getelementptr inbounds i8, i8* %0, i64 3
%26 = load i8, i8* %25
%27 = tail call i32 @unmap(i8 signext %26)
%28 = or i32 %27, %24
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %29, i8* %30
%31 = load i8, i8* %15
%32 = icmp eq i8 %31, 61
br i1 %32, label %37, label %33
33: ; preds = %2
%34 = load i8, i8* %25
%35 = icmp eq i8 %34, 61
%36 = select i1 %35, i64 2, i64 3
br label %37
37: ; preds = %33, %2
%38 = phi i64 [ %36, %33 ], [ 1, %2 ]
ret i64 %38
}