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

/* Variables and functions */
int /*<<< orphan*/ strncat(char *, char *, int);
void encodeblock(unsigned char in[], char b64str[], int len) {
  char b64[] =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  unsigned char out[5];
  out[0] = b64[in[0] >> 2];
  out[1] = b64[((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)];
  out[2] =
      (unsigned char)(len > 1
                          ? b64[((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)]
                          : '=');
  out[3] = (unsigned char)(len > 2 ? b64[in[2] & 0x3f] : '=');
  out[4] = '\0';
  strncat((char *)b64str, (char *)out, sizeof(out));
}


x86 assembly (clang, -O0):
<encodeblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xec2(%rip),%rsi
mov    $0x41,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
sar    $0x2,%eax
cltq
mov    -0x60(%rbp,%rax,1),%al
mov    %al,-0x65(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x3,%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
or     %ecx,%eax
cltq
mov    -0x60(%rbp,%rax,1),%al
mov    %al,-0x64(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11be <encodeblock+0x9e>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
and    $0xf,%eax
shl    $0x2,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
and    $0xc0,%ecx
sar    $0x6,%ecx
or     %ecx,%eax
cltq
movsbl -0x60(%rbp,%rax,1),%eax
mov    %eax,-0x6c(%rbp)
jmp    11cb <encodeblock+0xab>
mov    $0x3d,%eax
mov    %eax,-0x6c(%rbp)
jmp    11cb <encodeblock+0xab>
mov    -0x6c(%rbp),%eax
mov    %al,-0x63(%rbp)
cmpl   $0x2,-0x14(%rbp)
jle    11f5 <encodeblock+0xd5>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x3f,%eax
cltq
movsbl -0x60(%rbp,%rax,1),%eax
mov    %eax,-0x70(%rbp)
jmp    1202 <encodeblock+0xe2>
mov    $0x3d,%eax
mov    %eax,-0x70(%rbp)
jmp    1202 <encodeblock+0xe2>
mov    -0x70(%rbp),%eax
mov    %al,-0x62(%rbp)
movb   $0x0,-0x61(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x65(%rbp),%rsi
mov    $0x5,%edx
call   1030 <strncat@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeblock>:
push   %rax
mov    %rsi,%r8
movzbl (%rdi),%eax
mov    %rax,%rsi
shr    $0x2,%rsi
lea    0xedb(%rip),%r9
mov    (%rsi,%r9,1),%cl
mov    %cl,0x3(%rsp)
shl    $0x4,%eax
and    $0x30,%eax
movzbl 0x1(%rdi),%esi
mov    %rsi,%rcx
shr    $0x4,%rcx
or     %rax,%rcx
mov    (%r9,%rcx,1),%al
mov    %al,0x4(%rsp)
cmp    $0x1,%edx
jle    1178 <encodeblock+0x68>
and    $0xf,%esi
movzbl 0x2(%rdi),%edi
mov    %rdi,%rax
shr    $0x6,%rax
lea    (%rax,%rsi,4),%rax
mov    (%r9,%rax,1),%al
mov    %al,0x5(%rsp)
mov    $0x3d,%al
cmp    $0x2,%edx
je     117f <encodeblock+0x6f>
and    $0x3f,%edi
mov    (%rdi,%r9,1),%al
jmp    117f <encodeblock+0x6f>
movb   $0x3d,0x5(%rsp)
mov    $0x3d,%al
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x3(%rsp),%rsi
mov    %r8,%rdi
mov    $0x5,%edx
call   1030 <strncat@plt>
pop    %rax
ret

LLVM IR (-O0):
@__const.encodeblock.b64 = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define void @encodeblock(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [65 x i8]
%8 = alloca [5 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = bitcast [65 x i8]* %7 to i8*
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = ashr i32 %13, 2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
store i8 %17, i8* %18
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = and i32 %22, 3
%24 = shl i32 %23, 4
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = and i32 %28, 240
%30 = ashr i32 %29, 4
%31 = or i32 %24, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 1
store i8 %34, i8* %35
%36 = load i32, i32* %6
%37 = icmp sgt i32 %36, 1
br i1 %37, label %38, label %56
38: ; preds = %3
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = and i32 %42, 15
%44 = shl i32 %43, 2
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = and i32 %48, 192
%50 = ashr i32 %49, 6
%51 = or i32 %44, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
br label %57
56: ; preds = %3
br label %57
57: ; preds = %56, %38
%58 = phi i32 [ %55, %38 ], [ 61, %56 ]
%59 = trunc i32 %58 to i8
%60 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 2
store i8 %59, i8* %60
%61 = load i32, i32* %6
%62 = icmp sgt i32 %61, 2
br i1 %62, label %63, label %73
63: ; preds = %57
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i64 2
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = and i32 %67, 63
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
br label %74
73: ; preds = %57
br label %74
74: ; preds = %73, %63
%75 = phi i32 [ %72, %63 ], [ 61, %73 ]
%76 = trunc i32 %75 to i8
%77 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 3
store i8 %76, i8* %77
%78 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 4
store i8 0, i8* %78
%79 = load i8*, i8** %5
%80 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%81 = call i32 @strncat(i8* %79, i8* %80, i32 5)
ret void
}

LLVM IR (-O2):
@__const.encodeblock.b64 = [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\00"
define void @encodeblock(i8* nocapture %0, i8* %1, i32 %2) {
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%6 = load i8, i8* %0
%7 = lshr i8 %6, 2
%8 = zext i8 %7 to i64
%9 = getelementptr inbounds [65 x i8], [65 x i8]* @__const.encodeblock.b64, i64 0, i64 %8
%10 = load i8, i8* %9
store i8 %10, i8* %5
%11 = shl i8 %6, 4
%12 = and i8 %11, 48
%13 = getelementptr inbounds i8, i8* %0, i64 1
%14 = load i8, i8* %13
%15 = lshr i8 %14, 4
%16 = or i8 %15, %12
%17 = zext i8 %16 to i64
%18 = getelementptr inbounds [65 x i8], [65 x i8]* @__const.encodeblock.b64, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
store i8 %19, i8* %20
%21 = icmp sgt i32 %2, 1
br i1 %21, label %24, label %22
22: ; preds = %3
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
store i8 61, i8* %23
br label %41
24: ; preds = %3
%25 = shl i8 %14, 2
%26 = and i8 %25, 60
%27 = getelementptr inbounds i8, i8* %0, i64 2
%28 = load i8, i8* %27
%29 = lshr i8 %28, 6
%30 = or i8 %29, %26
%31 = zext i8 %30 to i64
%32 = getelementptr inbounds [65 x i8], [65 x i8]* @__const.encodeblock.b64, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 2
store i8 %33, i8* %34
%35 = icmp eq i32 %2, 2
br i1 %35, label %41, label %36
36: ; preds = %24
%37 = and i8 %28, 63
%38 = zext i8 %37 to i64
%39 = getelementptr inbounds [65 x i8], [65 x i8]* @__const.encodeblock.b64, i64 0, i64 %38
%40 = load i8, i8* %39
br label %41
41: ; preds = %22, %24, %36
%42 = phi i8 [ %40, %36 ], [ 61, %24 ], [ 61, %22 ]
%43 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 3
store i8 %42, i8* %43
%44 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %44
%45 = call i32 @strncat(i8* %1, i8* %5, i32 5)
ret void
}