#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 uint32_t;
typedef int int32_t;

/* Variables and functions */
int codetovalue(char const);
int decode4to3(const char *src, uint8_t *dest) {
  uint32_t b32 = 0;
  int32_t bits;
  int i;
  for (i = 0; i < 4; i++) {
    bits = codetovalue(src[i]);
    if (bits < 0) {
      return bits;
    }
    b32 <<= 6;
    b32 |= bits;
  }
  dest[0] = (b32 >> 16) & 0xFF;
  dest[1] = (b32 >> 8) & 0xFF;
  dest[2] = b32 & 0xFF;
  return 0;
}


x86 assembly (clang, -O0):
<decode4to3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1181 <decode4to3+0x71>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <codetovalue@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1161 <decode4to3+0x51>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <decode4to3+0xad>
mov    -0x1c(%rbp),%eax
shl    $0x6,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112e <decode4to3+0x1e>
mov    -0x1c(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode4to3>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <codetovalue@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1196 <decode4to3+0x86>
movsbl 0x1(%rbx),%edi
call   1030 <codetovalue@plt>
mov    %eax,%r15d
test   %eax,%eax
js     118a <decode4to3+0x7a>
movsbl 0x2(%rbx),%edi
call   1030 <codetovalue@plt>
mov    %eax,%r12d
test   %eax,%eax
js     118f <decode4to3+0x7f>
movsbl 0x3(%rbx),%edi
call   1030 <codetovalue@plt>
test   %eax,%eax
js     1194 <decode4to3+0x84>
shl    $0xc,%ebp
shl    $0x6,%r15d
or     %ebp,%r15d
or     %r15d,%r12d
shl    $0x6,%r12d
or     %r12d,%eax
mov    %eax,%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
mov    %ecx,(%r14)
movzbl %ah,%ecx
mov    %ecx,0x4(%r14)
movzbl %al,%eax
mov    %eax,0x8(%r14)
xor    %ebp,%ebp
jmp    1196 <decode4to3+0x86>
mov    %r15d,%ebp
jmp    1196 <decode4to3+0x86>
mov    %r12d,%ebp
jmp    1196 <decode4to3+0x86>
mov    %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @decode4to3(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %29, %2
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = call i32 @codetovalue(i8 signext %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = load i32, i32* %7
store i32 %22, i32* %3
br label %47
23: ; preds = %12
%24 = load i32, i32* %6
%25 = shl i32 %24, 6
store i32 %25, i32* %6
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = or i32 %27, %26
store i32 %28, i32* %6
br label %29
29: ; preds = %23
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %9
32: ; preds = %9
%33 = load i32, i32* %6
%34 = ashr i32 %33, 16
%35 = and i32 %34, 255
%36 = load i32*, i32** %5
%37 = getelementptr inbounds i32, i32* %36, i64 0
store i32 %35, i32* %37
%38 = load i32, i32* %6
%39 = ashr i32 %38, 8
%40 = and i32 %39, 255
%41 = load i32*, i32** %5
%42 = getelementptr inbounds i32, i32* %41, i64 1
store i32 %40, i32* %42
%43 = load i32, i32* %6
%44 = and i32 %43, 255
%45 = load i32*, i32** %5
%46 = getelementptr inbounds i32, i32* %45, i64 2
store i32 %44, i32* %46
store i32 0, i32* %3
br label %47
47: ; preds = %32, %21
%48 = load i32, i32* %3
ret i32 %48
}

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